| 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 | |
| 16 | |
| 17 | #ifndef Foundation_TaskNotification_INCLUDED |
| 18 | #define Foundation_TaskNotification_INCLUDED |
| 19 | |
| 20 | |
| 21 | #include "Poco/Foundation.h" |
| 22 | #include "Poco/Notification.h" |
| 23 | #include "Poco/Task.h" |
| 24 | |
| 25 | |
| 26 | namespace Poco { |
| 27 | |
| 28 | |
| 29 | class Foundation_API TaskNotification: public Notification |
| 30 | /// Base class for TaskManager notifications. |
| 31 | { |
| 32 | public: |
| 33 | TaskNotification(Task* pTask); |
| 34 | /// Creates the TaskNotification. |
| 35 | |
| 36 | Task* task() const; |
| 37 | /// Returns the subject of the notification. |
| 38 | |
| 39 | protected: |
| 40 | virtual ~TaskNotification(); |
| 41 | /// Destroys the TaskNotification. |
| 42 | |
| 43 | private: |
| 44 | Task* _pTask; |
| 45 | }; |
| 46 | |
| 47 | |
| 48 | class Foundation_API TaskStartedNotification: public TaskNotification |
| 49 | /// This notification is posted by the TaskManager for |
| 50 | /// every task that has been started. |
| 51 | { |
| 52 | public: |
| 53 | TaskStartedNotification(Task* pTask); |
| 54 | |
| 55 | protected: |
| 56 | ~TaskStartedNotification(); |
| 57 | }; |
| 58 | |
| 59 | |
| 60 | class Foundation_API TaskCancelledNotification: public TaskNotification |
| 61 | /// This notification is posted by the TaskManager for |
| 62 | /// every task that has been cancelled. |
| 63 | { |
| 64 | public: |
| 65 | TaskCancelledNotification(Task* pTask); |
| 66 | |
| 67 | protected: |
| 68 | ~TaskCancelledNotification(); |
| 69 | }; |
| 70 | |
| 71 | |
| 72 | class Foundation_API TaskFinishedNotification: public TaskNotification |
| 73 | /// This notification is posted by the TaskManager for |
| 74 | /// every task that has finished. |
| 75 | { |
| 76 | public: |
| 77 | TaskFinishedNotification(Task* pTask); |
| 78 | |
| 79 | protected: |
| 80 | ~TaskFinishedNotification(); |
| 81 | }; |
| 82 | |
| 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 | |
| 91 | const Exception& reason() const; |
| 92 | |
| 93 | protected: |
| 94 | ~TaskFailedNotification(); |
| 95 | |
| 96 | private: |
| 97 | Exception* _pException; |
| 98 | }; |
| 99 | |
| 100 | |
| 101 | class Foundation_API TaskProgressNotification: public TaskNotification |
| 102 | /// This notification is posted by the TaskManager for |
| 103 | /// a task when its progress changes. |
| 104 | { |
| 105 | public: |
| 106 | TaskProgressNotification(Task* pTask, float progress); |
| 107 | |
| 108 | float progress() const; |
| 109 | |
| 110 | protected: |
| 111 | ~TaskProgressNotification(); |
| 112 | |
| 113 | private: |
| 114 | float _progress; |
| 115 | }; |
| 116 | |
| 117 | |
| 118 | template <class C> |
| 119 | class TaskCustomNotification: public TaskNotification |
| 120 | /// This is a template for "custom" notification. |
| 121 | /// Unlike other notifications, this notification |
| 122 | /// is instantiated and posted by the task itself. |
| 123 | /// The purpose is to provide generic notification |
| 124 | /// mechanism between the task and its observer(s). |
| 125 | { |
| 126 | public: |
| 127 | TaskCustomNotification(Task* pTask, const C& rCustom): |
| 128 | TaskNotification(pTask), |
| 129 | _custom(rCustom) |
| 130 | { |
| 131 | } |
| 132 | |
| 133 | const C& custom() const |
| 134 | { |
| 135 | return _custom; |
| 136 | } |
| 137 | |
| 138 | protected: |
| 139 | ~TaskCustomNotification(){}; |
| 140 | |
| 141 | private: |
| 142 | C _custom; |
| 143 | }; |
| 144 | |
| 145 | |
| 146 | // |
| 147 | // inlines |
| 148 | // |
| 149 | inline Task* TaskNotification::task() const |
| 150 | { |
| 151 | return _pTask; |
| 152 | } |
| 153 | |
| 154 | |
| 155 | inline const Exception& TaskFailedNotification::reason() const |
| 156 | { |
| 157 | return *_pException; |
| 158 | } |
| 159 | |
| 160 | |
| 161 | inline float TaskProgressNotification::progress() const |
| 162 | { |
| 163 | return _progress; |
| 164 | } |
| 165 | |
| 166 | |
| 167 | } // namespace Poco |
| 168 | |
| 169 | |
| 170 | #endif // Foundation_TaskNotification_INCLUDED |
| 171 | |