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
26namespace Poco {
27
28
29class Foundation_API TaskNotification: public Notification
30 /// Base class for TaskManager notifications.
31{
32public:
33 TaskNotification(Task* pTask);
34 /// Creates the TaskNotification.
35
36 Task* task() const;
37 /// Returns the subject of the notification.
38
39protected:
40 virtual ~TaskNotification();
41 /// Destroys the TaskNotification.
42
43private:
44 Task* _pTask;
45};
46
47
48class Foundation_API TaskStartedNotification: public TaskNotification
49 /// This notification is posted by the TaskManager for
50 /// every task that has been started.
51{
52public:
53 TaskStartedNotification(Task* pTask);
54
55protected:
56 ~TaskStartedNotification();
57};
58
59
60class Foundation_API TaskCancelledNotification: public TaskNotification
61 /// This notification is posted by the TaskManager for
62 /// every task that has been cancelled.
63{
64public:
65 TaskCancelledNotification(Task* pTask);
66
67protected:
68 ~TaskCancelledNotification();
69};
70
71
72class Foundation_API TaskFinishedNotification: public TaskNotification
73 /// This notification is posted by the TaskManager for
74 /// every task that has finished.
75{
76public:
77 TaskFinishedNotification(Task* pTask);
78
79protected:
80 ~TaskFinishedNotification();
81};
82
83
84class Foundation_API TaskFailedNotification: public TaskNotification
85 /// This notification is posted by the TaskManager for
86 /// every task that has failed with an exception.
87{
88public:
89 TaskFailedNotification(Task* pTask, const Exception& exc);
90
91 const Exception& reason() const;
92
93protected:
94 ~TaskFailedNotification();
95
96private:
97 Exception* _pException;
98};
99
100
101class Foundation_API TaskProgressNotification: public TaskNotification
102 /// This notification is posted by the TaskManager for
103 /// a task when its progress changes.
104{
105public:
106 TaskProgressNotification(Task* pTask, float progress);
107
108 float progress() const;
109
110protected:
111 ~TaskProgressNotification();
112
113private:
114 float _progress;
115};
116
117
118template <class C>
119class 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{
126public:
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
138protected:
139 ~TaskCustomNotification(){};
140
141private:
142 C _custom;
143};
144
145
146//
147// inlines
148//
149inline Task* TaskNotification::task() const
150{
151 return _pTask;
152}
153
154
155inline const Exception& TaskFailedNotification::reason() const
156{
157 return *_pException;
158}
159
160
161inline float TaskProgressNotification::progress() const
162{
163 return _progress;
164}
165
166
167} // namespace Poco
168
169
170#endif // Foundation_TaskNotification_INCLUDED
171