Difference between revisions of "CXTask"
From cxwiki
(Created page with "<div class="mw-parser-output">The CXTask class provides a mechanism for applications to request regular updates in a non-threaded manner. The application derives from CXT...") |
|||
(2 intermediate revisions by the same user not shown) | |||
Line 1: | Line 1: | ||
− | <div class="mw-parser-output">The CXTask class provides a mechanism for applications to request regular updates in a non-threaded manner. The application derives from CXTask and provides a CXTask::Idle() override which is called once per task update. Each CXTask must be registered with a CXTaskHost in order to receive updates | + | <div class="mw-parser-output"><div class="mw-parser-output"><div class="mw-parser-output"><div class="mw-parser-output">The CXTask class provides a mechanism for applications to request regular updates in a non-threaded manner. The application derives from CXTask and provides a CXTask::Idle() override which is called once per task update. Each CXTask must be registered with a CXTaskHost in order to receive updates.</div> <div class="mw-parser-output"> </div> <div class="mw-parser-output">Updates occur whenever the CXTaskHost::IdleTasks() function is called, which (with the exception of the main thread task host in an application) is NOT automatic.</div> <div class="mw-parser-output"> </div> |
− | + | = Thread Task Hosts = | |
− | <div class="mw-parser-output"> </div> <div class="mw-parser-output"> </div> | + | |
− | = | + | Each thread may have a singleton CXTaskHost object. This object is created via CXTaskHost::InitCurrentThreadTaskHost(), accessed via CXTasskHost::GetCurrentThreadTaskHost(), and finally destroyed via CXTaskHost::KillCurrentThreadTaskHost(). The thread may trigger a task update by calling CXTaskHost::GetCurrentThreadTaskHost().IdleTasks(). |
− | <div class="mw-parser-output"> </div> <div class="mw-parser-output"> | + | |
+ | == Main Thread Task Host == | ||
+ | <div class="mw-parser-output">The main thread task host is created automatically during cxsource initialisation, and is destroyed automatically during cxsource shutdown. In a standard event-driven application, the main thread task host is updated on a regular basis via the main event loop. In other processes, such as a command-line tool, the application must explicitly update the main thread task host on a regular basis.</div> | ||
+ | == Background Thread Task Hosts == | ||
+ | <div class="mw-parser-output">Background threads do not automatically receive task hosts. If they will use task host functionality, they must explicitly create, update, and destroy the thread task host as required.</div> | ||
= Additional Task Hosts = | = Additional Task Hosts = | ||
− | <div class="mw-parser-output"> </div> <div class="mw-parser-output"> </div> | + | <div class="mw-parser-output">It is also possible to create arbitrary task hosts, and update them on a custom schedule.</div> <div class="mw-parser-output"> </div> |
+ | = CXTaskHost = | ||
+ | <div class="mw-parser-output"><syntaxhighlight lang="c++">// Causes this CXTaskHost to call Idle() for each registered CXTask. | ||
+ | void IdleTasks(void); | ||
+ | |||
+ | |||
+ | // Registers the specified task with this host. A task must be registered | ||
+ | // with only one host at a time. | ||
+ | void AddTask(CXTask* task); | ||
+ | |||
+ | // Unregisters the specified task from this host. | ||
+ | void RemoveTask(CXTask* task); | ||
+ | |||
+ | |||
+ | // | ||
+ | static void InitCurrentThreadTaskHost(void); | ||
+ | |||
+ | // | ||
+ | static void KillCurrentThreadTaskHost(void); | ||
+ | |||
+ | // | ||
+ | static CXTaskHost& GetCurrentThreadTaskHost(void); | ||
+ | |||
+ | // | ||
+ | static CXTaskHost& GetThreadTaskHost(CXThreadID threadID); | ||
+ | |||
+ | // | ||
+ | static bool HasCurrentThreadTaskHost(void); | ||
+ | |||
+ | // | ||
+ | static bool HasThreadTaskHost(CXThreadID threadID);</syntaxhighlight> | ||
+ | |||
+ | | ||
+ | </div> <div class="mw-parser-output"> </div> | ||
+ | = CXTask = | ||
+ | <div class="mw-parser-output"><syntaxhighlight lang="c++">// | ||
+ | explicit CXTask(const char* taskName); | ||
+ | |||
+ | // | ||
+ | virtual void Idle(void) = 0; | ||
+ | |||
+ | // | ||
+ | CXTaskHost* GetTaskHost(void); | ||
+ | |||
+ | // | ||
+ | const char* GetDebugTaskName(void) const;</syntaxhighlight> | ||
+ | |||
+ | | ||
+ | </div> <div class="mw-parser-output"> </div> <div class="mw-parser-output"> </div> <div class="mw-parser-output"> </div> </div> </div> </div> |
Latest revision as of 23:23, 26 February 2018
The CXTask class provides a mechanism for applications to request regular updates in a non-threaded manner. The application derives from CXTask and provides a CXTask::Idle() override which is called once per task update. Each CXTask must be registered with a CXTaskHost in order to receive updates.
Updates occur whenever the CXTaskHost::IdleTasks() function is called, which (with the exception of the main thread task host in an application) is NOT automatic.
Contents
Thread Task Hosts
Each thread may have a singleton CXTaskHost object. This object is created via CXTaskHost::InitCurrentThreadTaskHost(), accessed via CXTasskHost::GetCurrentThreadTaskHost(), and finally destroyed via CXTaskHost::KillCurrentThreadTaskHost(). The thread may trigger a task update by calling CXTaskHost::GetCurrentThreadTaskHost().IdleTasks().
Main Thread Task Host
The main thread task host is created automatically during cxsource initialisation, and is destroyed automatically during cxsource shutdown. In a standard event-driven application, the main thread task host is updated on a regular basis via the main event loop. In other processes, such as a command-line tool, the application must explicitly update the main thread task host on a regular basis.
Background Thread Task Hosts
Background threads do not automatically receive task hosts. If they will use task host functionality, they must explicitly create, update, and destroy the thread task host as required.
Additional Task Hosts
It is also possible to create arbitrary task hosts, and update them on a custom schedule.
CXTaskHost
// Causes this CXTaskHost to call Idle() for each registered CXTask.
void IdleTasks(void);
// Registers the specified task with this host. A task must be registered
// with only one host at a time.
void AddTask(CXTask* task);
// Unregisters the specified task from this host.
void RemoveTask(CXTask* task);
//
static void InitCurrentThreadTaskHost(void);
//
static void KillCurrentThreadTaskHost(void);
//
static CXTaskHost& GetCurrentThreadTaskHost(void);
//
static CXTaskHost& GetThreadTaskHost(CXThreadID threadID);
//
static bool HasCurrentThreadTaskHost(void);
//
static bool HasThreadTaskHost(CXThreadID threadID);
CXTask
//
explicit CXTask(const char* taskName);
//
virtual void Idle(void) = 0;
//
CXTaskHost* GetTaskHost(void);
//
const char* GetDebugTaskName(void) const;