1 | // |
---|
2 | // TaskNotification.h |
---|
3 | // |
---|
4 | // $Id: //poco/1.3/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 | |
---|
38 | |
---|
39 | #ifndef Foundation_TaskNotification_INCLUDED |
---|
40 | #define Foundation_TaskNotification_INCLUDED |
---|
41 | |
---|
42 | |
---|
43 | #include "Poco/Foundation.h" |
---|
44 | #include "Poco/Notification.h" |
---|
45 | #include "Poco/Task.h" |
---|
46 | |
---|
47 | |
---|
48 | namespace Poco { |
---|
49 | |
---|
50 | |
---|
51 | class Foundation_API TaskNotification: public Notification |
---|
52 | /// Base class for TaskManager notifications. |
---|
53 | { |
---|
54 | public: |
---|
55 | TaskNotification(Task* pTask); |
---|
56 | /// Creates the TaskNotification. |
---|
57 | |
---|
58 | Task* task() const; |
---|
59 | /// Returns the subject of the notification. |
---|
60 | |
---|
61 | protected: |
---|
62 | virtual ~TaskNotification(); |
---|
63 | /// Destroys the TaskNotification. |
---|
64 | |
---|
65 | private: |
---|
66 | Task* _pTask; |
---|
67 | }; |
---|
68 | |
---|
69 | |
---|
70 | class Foundation_API TaskStartedNotification: public TaskNotification |
---|
71 | /// This notification is posted by the TaskManager for |
---|
72 | /// every task that has been started. |
---|
73 | { |
---|
74 | public: |
---|
75 | TaskStartedNotification(Task* pTask); |
---|
76 | |
---|
77 | protected: |
---|
78 | ~TaskStartedNotification(); |
---|
79 | }; |
---|
80 | |
---|
81 | |
---|
82 | class Foundation_API TaskCancelledNotification: public TaskNotification |
---|
83 | /// This notification is posted by the TaskManager for |
---|
84 | /// every task that has been cancelled. |
---|
85 | { |
---|
86 | public: |
---|
87 | TaskCancelledNotification(Task* pTask); |
---|
88 | |
---|
89 | protected: |
---|
90 | ~TaskCancelledNotification(); |
---|
91 | }; |
---|
92 | |
---|
93 | |
---|
94 | class Foundation_API TaskFinishedNotification: public TaskNotification |
---|
95 | /// This notification is posted by the TaskManager for |
---|
96 | /// every task that has finished. |
---|
97 | { |
---|
98 | public: |
---|
99 | TaskFinishedNotification(Task* pTask); |
---|
100 | |
---|
101 | protected: |
---|
102 | ~TaskFinishedNotification(); |
---|
103 | }; |
---|
104 | |
---|
105 | |
---|
106 | class Foundation_API TaskFailedNotification: public TaskNotification |
---|
107 | /// This notification is posted by the TaskManager for |
---|
108 | /// every task that has failed with an exception. |
---|
109 | { |
---|
110 | public: |
---|
111 | TaskFailedNotification(Task* pTask, const Exception& exc); |
---|
112 | |
---|
113 | const Exception& reason() const; |
---|
114 | |
---|
115 | protected: |
---|
116 | ~TaskFailedNotification(); |
---|
117 | |
---|
118 | private: |
---|
119 | Exception* _pException; |
---|
120 | }; |
---|
121 | |
---|
122 | |
---|
123 | class Foundation_API TaskProgressNotification: public TaskNotification |
---|
124 | /// This notification is posted by the TaskManager for |
---|
125 | /// every task that has failed with an exception. |
---|
126 | { |
---|
127 | public: |
---|
128 | TaskProgressNotification(Task* pTask, float progress); |
---|
129 | |
---|
130 | float progress() const; |
---|
131 | |
---|
132 | protected: |
---|
133 | ~TaskProgressNotification(); |
---|
134 | |
---|
135 | private: |
---|
136 | float _progress; |
---|
137 | }; |
---|
138 | |
---|
139 | |
---|
140 | template <class C> |
---|
141 | class TaskCustomNotification: public TaskNotification |
---|
142 | /// This is a template for "custom" notification. |
---|
143 | /// Unlike other notifications, this notification |
---|
144 | /// is instantiated and posted by the task itself. |
---|
145 | /// The purpose is to provide generic notifiation |
---|
146 | /// mechanism between the task and its observer(s). |
---|
147 | { |
---|
148 | public: |
---|
149 | TaskCustomNotification(Task* pTask, const C& custom): |
---|
150 | TaskNotification(pTask), |
---|
151 | _custom(custom) |
---|
152 | { |
---|
153 | } |
---|
154 | |
---|
155 | const C& custom() const |
---|
156 | { |
---|
157 | return _custom; |
---|
158 | } |
---|
159 | |
---|
160 | protected: |
---|
161 | ~TaskCustomNotification(){}; |
---|
162 | |
---|
163 | private: |
---|
164 | C _custom; |
---|
165 | }; |
---|
166 | |
---|
167 | |
---|
168 | // |
---|
169 | // inlines |
---|
170 | // |
---|
171 | inline Task* TaskNotification::task() const |
---|
172 | { |
---|
173 | return _pTask; |
---|
174 | } |
---|
175 | |
---|
176 | |
---|
177 | inline const Exception& TaskFailedNotification::reason() const |
---|
178 | { |
---|
179 | return *_pException; |
---|
180 | } |
---|
181 | |
---|
182 | |
---|
183 | inline float TaskProgressNotification::progress() const |
---|
184 | { |
---|
185 | return _progress; |
---|
186 | } |
---|
187 | |
---|
188 | |
---|
189 | } // namespace Poco |
---|
190 | |
---|
191 | |
---|
192 | #endif // Foundation_TaskNotification_INCLUDED |
---|