TaskNotification.h 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172
  1. //
  2. // TaskNotification.h
  3. //
  4. // $Id: //poco/1.4/Foundation/include/Poco/TaskNotification.h#1 $
  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. // SPDX-License-Identifier: BSL-1.0
  16. //
  17. #ifndef Foundation_TaskNotification_INCLUDED
  18. #define Foundation_TaskNotification_INCLUDED
  19. #include "Poco/Foundation.h"
  20. #include "Poco/Notification.h"
  21. #include "Poco/Task.h"
  22. namespace Poco {
  23. class Foundation_API TaskNotification: public Notification
  24. /// Base class for TaskManager notifications.
  25. {
  26. public:
  27. TaskNotification(Task* pTask);
  28. /// Creates the TaskNotification.
  29. Task* task() const;
  30. /// Returns the subject of the notification.
  31. protected:
  32. virtual ~TaskNotification();
  33. /// Destroys the TaskNotification.
  34. private:
  35. Task* _pTask;
  36. };
  37. class Foundation_API TaskStartedNotification: public TaskNotification
  38. /// This notification is posted by the TaskManager for
  39. /// every task that has been started.
  40. {
  41. public:
  42. TaskStartedNotification(Task* pTask);
  43. protected:
  44. ~TaskStartedNotification();
  45. };
  46. class Foundation_API TaskCancelledNotification: public TaskNotification
  47. /// This notification is posted by the TaskManager for
  48. /// every task that has been cancelled.
  49. {
  50. public:
  51. TaskCancelledNotification(Task* pTask);
  52. protected:
  53. ~TaskCancelledNotification();
  54. };
  55. class Foundation_API TaskFinishedNotification: public TaskNotification
  56. /// This notification is posted by the TaskManager for
  57. /// every task that has finished.
  58. {
  59. public:
  60. TaskFinishedNotification(Task* pTask);
  61. protected:
  62. ~TaskFinishedNotification();
  63. };
  64. class Foundation_API TaskFailedNotification: public TaskNotification
  65. /// This notification is posted by the TaskManager for
  66. /// every task that has failed with an exception.
  67. {
  68. public:
  69. TaskFailedNotification(Task* pTask, const Exception& exc);
  70. const Exception& reason() const;
  71. protected:
  72. ~TaskFailedNotification();
  73. private:
  74. Exception* _pException;
  75. };
  76. class Foundation_API TaskProgressNotification: public TaskNotification
  77. /// This notification is posted by the TaskManager for
  78. /// every task that has failed with an exception.
  79. {
  80. public:
  81. TaskProgressNotification(Task* pTask, float progress);
  82. float progress() const;
  83. protected:
  84. ~TaskProgressNotification();
  85. private:
  86. float _progress;
  87. };
  88. template <class C>
  89. class TaskCustomNotification: public TaskNotification
  90. /// This is a template for "custom" notification.
  91. /// Unlike other notifications, this notification
  92. /// is instantiated and posted by the task itself.
  93. /// The purpose is to provide generic notifiation
  94. /// mechanism between the task and its observer(s).
  95. {
  96. public:
  97. TaskCustomNotification(Task* pTask, const C& custom):
  98. TaskNotification(pTask),
  99. _custom(custom)
  100. {
  101. }
  102. const C& custom() const
  103. {
  104. return _custom;
  105. }
  106. protected:
  107. ~TaskCustomNotification(){};
  108. private:
  109. C _custom;
  110. };
  111. //
  112. // inlines
  113. //
  114. inline Task* TaskNotification::task() const
  115. {
  116. return _pTask;
  117. }
  118. inline const Exception& TaskFailedNotification::reason() const
  119. {
  120. return *_pException;
  121. }
  122. inline float TaskProgressNotification::progress() const
  123. {
  124. return _progress;
  125. }
  126. } // namespace Poco
  127. #endif // Foundation_TaskNotification_INCLUDED