TaskNotification.h 3.1 KB

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