TaskNotification.h 4.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192
  1. //
  2. // TaskNotification.h
  3. //
  4. // $Id: //poco/svn/Foundation/include/Poco/TaskNotification.h#2 $
  5. //
  6. // Library: Foundation
  7. // Package: Tasks
  8. // Module: Tasks
  9. //
  10. // Definition of the TaskNotification class.
  11. //
  12. // Copyright (c) 2004-2006, Applied Informatics Software Engineering GmbH.
  13. // and Contributors.
  14. //
  15. // Permission is hereby granted, free of charge, to any person or organization
  16. // obtaining a copy of the software and accompanying documentation covered by
  17. // this license (the "Software") to use, reproduce, display, distribute,
  18. // execute, and transmit the Software, and to prepare derivative works of the
  19. // Software, and to permit third-parties to whom the Software is furnished to
  20. // do so, all subject to the following:
  21. //
  22. // The copyright notices in the Software and this entire statement, including
  23. // the above license grant, this restriction and the following disclaimer,
  24. // must be included in all copies of the Software, in whole or in part, and
  25. // all derivative works of the Software, unless such copies or derivative
  26. // works are solely in the form of machine-executable object code generated by
  27. // a source language processor.
  28. //
  29. // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
  30. // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
  31. // FITNESS FOR A PARTICULAR PURPOSE, TITLE AND NON-INFRINGEMENT. IN NO EVENT
  32. // SHALL THE COPYRIGHT HOLDERS OR ANYONE DISTRIBUTING THE SOFTWARE BE LIABLE
  33. // FOR ANY DAMAGES OR OTHER LIABILITY, WHETHER IN CONTRACT, TORT OR OTHERWISE,
  34. // ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
  35. // DEALINGS IN THE SOFTWARE.
  36. //
  37. #ifndef Foundation_TaskNotification_INCLUDED
  38. #define Foundation_TaskNotification_INCLUDED
  39. #include "Poco/Foundation.h"
  40. #include "Poco/Notification.h"
  41. #include "Poco/Task.h"
  42. namespace Poco {
  43. class Foundation_API TaskNotification: public Notification
  44. /// Base class for TaskManager notifications.
  45. {
  46. public:
  47. TaskNotification(Task* pTask);
  48. /// Creates the TaskNotification.
  49. Task* task() const;
  50. /// Returns the subject of the notification.
  51. protected:
  52. virtual ~TaskNotification();
  53. /// Destroys the TaskNotification.
  54. private:
  55. Task* _pTask;
  56. };
  57. class Foundation_API TaskStartedNotification: public TaskNotification
  58. /// This notification is posted by the TaskManager for
  59. /// every task that has been started.
  60. {
  61. public:
  62. TaskStartedNotification(Task* pTask);
  63. protected:
  64. ~TaskStartedNotification();
  65. };
  66. class Foundation_API TaskCancelledNotification: public TaskNotification
  67. /// This notification is posted by the TaskManager for
  68. /// every task that has been cancelled.
  69. {
  70. public:
  71. TaskCancelledNotification(Task* pTask);
  72. protected:
  73. ~TaskCancelledNotification();
  74. };
  75. class Foundation_API TaskFinishedNotification: public TaskNotification
  76. /// This notification is posted by the TaskManager for
  77. /// every task that has finished.
  78. {
  79. public:
  80. TaskFinishedNotification(Task* pTask);
  81. protected:
  82. ~TaskFinishedNotification();
  83. };
  84. class Foundation_API TaskFailedNotification: public TaskNotification
  85. /// This notification is posted by the TaskManager for
  86. /// every task that has failed with an exception.
  87. {
  88. public:
  89. TaskFailedNotification(Task* pTask, const Exception& exc);
  90. const Exception& reason() const;
  91. protected:
  92. ~TaskFailedNotification();
  93. private:
  94. Exception* _pException;
  95. };
  96. class Foundation_API TaskProgressNotification: public TaskNotification
  97. /// This notification is posted by the TaskManager for
  98. /// every task that has failed with an exception.
  99. {
  100. public:
  101. TaskProgressNotification(Task* pTask, float progress);
  102. float progress() const;
  103. protected:
  104. ~TaskProgressNotification();
  105. private:
  106. float _progress;
  107. };
  108. template <class C>
  109. class TaskCustomNotification: public TaskNotification
  110. /// This is a template for "custom" notification.
  111. /// Unlike other notifications, this notification
  112. /// is instantiated and posted by the task itself.
  113. /// The purpose is to provide generic notifiation
  114. /// mechanism between the task and its observer(s).
  115. {
  116. public:
  117. TaskCustomNotification(Task* pTask, const C& custom):
  118. TaskNotification(pTask),
  119. _custom(custom)
  120. {
  121. }
  122. const C& custom() const
  123. {
  124. return _custom;
  125. }
  126. protected:
  127. ~TaskCustomNotification(){};
  128. private:
  129. C _custom;
  130. };
  131. //
  132. // inlines
  133. //
  134. inline Task* TaskNotification::task() const
  135. {
  136. return _pTask;
  137. }
  138. inline const Exception& TaskFailedNotification::reason() const
  139. {
  140. return *_pException;
  141. }
  142. inline float TaskProgressNotification::progress() const
  143. {
  144. return _progress;
  145. }
  146. } // namespace Poco
  147. #endif // Foundation_TaskNotification_INCLUDED