Library: Foundation
Package: Tasks
Header: Poco/TaskManager.h
The TaskManager manages a collection of tasks and monitors their lifetime.
A TaskManager has a built-in NotificationCenter that is used to send out notifications on task progress and task states. See the TaskNotification class and its subclasses for the various events that result in a notification. To keep the number of notifications small, a TaskProgressNotification will only be sent out once in 100 milliseconds.
Member Functions: addObserver, cancelAll, count, joinAll, postNotification, removeObserver, start, taskCancelled, taskFailed, taskFinished, taskList, taskProgress, taskStarted
typedef std::list < TaskPtr > TaskList;
typedef AutoPtr < Task > TaskPtr;
TaskManager();
Creates the TaskManager, using the default ThreadPool.
TaskManager(
ThreadPool & pool
);
Creates the TaskManager, using the given ThreadPool.
~TaskManager();
Destroys the TaskManager.
void addObserver(
const AbstractObserver & observer
);
Registers an observer with the NotificationCenter. Usage:
Observer<MyClass, MyNotification> obs(*this, &MyClass::handleNotification); notificationCenter.addObserver(obs);
void cancelAll();
Requests cancellation of all tasks.
int count() const;
Returns the number of tasks in the internal task list.
void joinAll();
Waits for the completion of all the threads in the TaskManager's thread pool.
void removeObserver(
const AbstractObserver & observer
);
Unregisters an observer with the NotificationCenter.
void start(
Task * pTask
);
Starts the given task in a thread obtained from the thread pool.
The TaskManager takes ownership of the Task object and deletes it when it it finished.
TaskList taskList() const;
Returns a copy of the internal task list.
void postNotification(
Notification * pNf
);
Posts a notification to the task manager's notification center.
void taskCancelled(
Task * pTask
);
void taskFailed(
Task * pTask,
const Exception & exc
);
void taskFinished(
Task * pTask
);
void taskProgress(
Task * pTask,
float progress
);
void taskStarted(
Task * pTask
);
static const int MIN_PROGRESS_NOTIFICATION_INTERVAL;