ERC CISST - cisst software

mtsTaskFromCallback Class Reference
[Multi Task Support]

#include <mtsTaskFromCallback.h>

Inheritance diagram for mtsTaskFromCallback:

Inheritance graph
[legend]
Collaboration diagram for mtsTaskFromCallback:

Collaboration graph
[legend]
List of all members.

Detailed Description

This is a task that has its thread provided by a callback from an external piece of software.

If the external package accepts a user-supplied 'void *' as the first parameter, then mtsTaskFromCallbackAdapter can be used; this class provides an adapter that expects the 'void *' parameter to contain a pointer to an instance of the mtsTaskFromCallbackAdapter class.

The mtsTaskFromCallback class can be used in all cases. The derived class must provide a callback function (e.g., a static function) and implement an alternate method to get the 'this' pointer. The user-created callback function should call RunInternal and return the data (if any).

One suggestion is to make the derived class a Singleton. The derived class should contain a (static) CustomCallbackAdapter function that has the correct signature. For example, if we create a derived class called MyCallbackClass:

static int MyCallbackClass::CustomCallbackAdapter(char *a, int b) { MyCallbackClass *obj = MyCallbackClass::GetInstance(); Avoid re-entrancy problems by creating a CallbackParms object on the stack and passing it to RunInternal, which already contains a software guard to prevent re-entrant calls. Alternatively, the data can be copied to class members, which can then be accessed inside the Run method. In this case, the CustomCallbackAdapter should handle the re-entrancy problems (e.g., if CustomCallbackAdapter is called again before the last call has finished, it could overwrite the previous values stored in the class members). MyCallbackClass::CallbackParms data(a,b); void *ret = RunInternal(static_cast<void *>(data)); Run method can use data.a and data.b and set the return value by calling mtsTask::SetThreadReturnValue. return static_cast<int>(ret); }

Definition at line 79 of file mtsTaskFromCallback.h.

Public Member Functions

Protected Types

Protected Member Functions

Protected Attributes


Constructor & Destructor Documentation

mtsTaskFromCallback::mtsTaskFromCallback ( const std::string &  name,
unsigned int  sizeStateTable = 256 
) [inline]

Create a task with name 'name' and set the state table size. The execution of this task will rely on a callback from an external thread.

Parameters:
name The name of the task
sizeStateTable The history size of the state table
Note:
See note in mtsTask regarding length of string name.
See also:
mtsTask, mtsTaskContinuous, mtsTaskPeriodic

Definition at line 113 of file mtsTaskFromCallback.h.

virtual mtsTaskFromCallback::~mtsTaskFromCallback (  )  [inline, virtual]

Default Destructor.

Definition at line 118 of file mtsTaskFromCallback.h.


Member Function Documentation

void* mtsTaskFromCallback::RunInternal ( void *  argument  )  [protected, virtual]

The member function that is passed as 'start routine' argument for thread creation.

Implements mtsTask.

void mtsTaskFromCallback::StartupInternal ( void   )  [protected, virtual]

The member funtion that is executed as soon as the thread gets created. It does some housekeeping before the user code can be executed.

Reimplemented from mtsTask.

void mtsTaskFromCallback::Start ( void   )  [virtual]

Start/resume execution of the task

Implements mtsTask.

void mtsTaskFromCallback::Suspend ( void   )  [virtual]

Suspend the execution of the task

Implements mtsTask.

virtual void* mtsTaskFromCallback::DoCallback ( void *  data = 0  )  [inline, virtual]

Hook for calling RunInternal

Definition at line 133 of file mtsTaskFromCallback.h.

References mtsTask::RunInternal().

Referenced by mtsTaskFromCallbackAdapter::CallbackAdapter().


The documentation for this class was generated from the following file:
erc-cisst-devel<at>lists.johnshopkins.edu