#include <mtsTaskFromCallback.h>
Inheritance diagram for mtsTaskFromCallback:


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.
| 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.
| name | The name of the task | |
| sizeStateTable | The history size of the state table |
Definition at line 113 of file mtsTaskFromCallback.h.
| virtual mtsTaskFromCallback::~mtsTaskFromCallback | ( | ) | [inline, virtual] |
Default Destructor.
Definition at line 118 of file mtsTaskFromCallback.h.
| 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().