Poco

class TaskManager

File Information

Library: Foundation
Package: Tasks
Header: Poco/TaskManager.h

Description

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 Summary

Member Functions: addObserver, cancelAll, count, joinAll, postNotification, removeObserver, start, taskCancelled, taskFailed, taskFinished, taskList, taskProgress, taskStarted

Types Aliases

TaskList

using TaskList = std::list < TaskPtr >;

TaskPtr

using TaskPtr = AutoPtr < Task >;

Constructors

TaskManager

TaskManager();

Creates the TaskManager, using the default ThreadPool.

TaskManager

TaskManager(
    ThreadPool & pool
);

Creates the TaskManager, using the given ThreadPool.

Destructor

~TaskManager

~TaskManager();

Destroys the TaskManager.

Member Functions

addObserver

void addObserver(
    const AbstractObserver & observer
);

Registers an observer with the NotificationCenter. Usage:

Observer<MyClass, MyNotification> obs(*this, &MyClass::handleNotification);
notificationCenter.addObserver(obs);

cancelAll

void cancelAll();

Requests cancellation of all tasks.

count inline

int count() const;

Returns the number of tasks in the internal task list.

joinAll

void joinAll();

Waits for the completion of all the threads in the TaskManager's thread pool.

Note: joinAll() will wait for ALL tasks in the TaskManager's ThreadPool to complete. If the ThreadPool has threads created by other facilities, these threads must also complete before joinAll() can return.

removeObserver

void removeObserver(
    const AbstractObserver & observer
);

Unregisters an observer with the NotificationCenter.

start

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 taskList() const;

Returns a copy of the internal task list.

postNotification protected

void postNotification(
    const Notification::Ptr & pNf
);

Posts a notification to the task manager's notification center.

taskCancelled protected

void taskCancelled(
    Task * pTask
);

taskFailed protected

void taskFailed(
    Task * pTask,
    const Exception & exc
);

taskFinished protected

void taskFinished(
    Task * pTask
);

taskProgress protected

void taskProgress(
    Task * pTask,
    float progress
);

taskStarted protected

void taskStarted(
    Task * pTask
);

Variables

MIN_PROGRESS_NOTIFICATION_INTERVAL static

static const int MIN_PROGRESS_NOTIFICATION_INTERVAL;

Securely control IoT edge devices from anywhere   Connect a Device