NCBI C++ ToolKit
|
Search Toolkit Book for IAppTask
#include <gui/framework/app_task.hpp>
Public Types | |
enum | ETaskState { eInvalid = -1 , eInitial , eRunning , eBackgrounded , eCompleted , eFailed , eCanceled , eLastState } |
List of task states defining the task management FSM. More... | |
Public Member Functions | |
virtual | ~IAppTask () |
virtual void | SetListener (CEventHandler *handler)=0 |
set a Listener; this allows a taks running in background to notify the Listener (usually Task Manager) about changes in Status More... | |
virtual ETaskState | Run ()=0 |
execute the task, this function is called on the main UI thread if a task needs to execute in background it should launch a job that will execute asynchronously; then the function shall return eBackgrounded More... | |
virtual ETaskState | GetState ()=0 |
returns the current task state More... | |
virtual void | CancelBackgrounded ()=0 |
make a request to cancel backgrounded task (not called for foreground tasks) More... | |
virtual void | OnCancel ()=0 |
this will be called on pending tasks that will be removed from the queue and won't get a chance to run the purpose is to implement any cleanup procedures for the canceled task More... | |
virtual bool | IsVisible ()=0 |
returns true if the task should be visible in UI visible task shall represent operations understood by users and usually correspond to menu commands. More... | |
virtual int | GetStatusDisplayDelay ()=0 |
returns delay in seconds used for certain fast (and not very important tasks) to only show its status when it is running/pending for long enough More... | |
virtual string | GetDescr () const =0 |
returns a human-readable description of the Task (optional) More... | |
virtual string | GetStatusText () const =0 |
returns human-readable text describing the current task state More... | |
virtual IEventLogAction * | CreateEventLogAction ()=0 |
returns an action for activating task results (optional, can return NULL) More... | |
IAppTask represents an Application Task that can be executed in Application Task Manager. Application Tasks correspond to application-level commands or operations, it is recommended that various application functions are packaged as tasks. The functionality of an application can be easily extended by declaring new types of Tasks.
Tasks can consist of other tasks, the parent task can control execution of the child tasks. Such composite tasks can be used to implement complex “macro” operations or scripts – scenarios that combine atomic tasks.
Task Manager executes tasks on the main UI thread. Execution on the main UI thread guarantees that Tasks do not overlap in time what reduces risks of concurrency problems. It also ensures ability of a Task to interact with UI (show dialogs, communicate with views) which is only safe from the main UI thread.
Tasks can involve computations on background threads, in that case a task shall launch a background job and wait until it finishes or exits with “Backgrounded” status. Task Manager places backgrounded tasks aside where they can wait completion of the associated jobs running asynchronously. When background part of execution is completed a Task shall notify Task Manager, then Task Manager will schedule the Task for execution on the main UI thread. A Task can go to backgrounded state more than once.
A Task must be thread-safe relative to its IAppTask interface, i.e. any calls to IAppTask from the main UI thread should be safe even if not synchronized externaly.
Definition at line 82 of file app_task.hpp.