cisst-saw
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
Public Types | Public Member Functions | Static Public Attributes | Protected Member Functions | Protected Attributes | Friends | List of all members
mtsTask Class Referenceabstract

#include <mtsTask.h>

Inheritance diagram for mtsTask:
mtsComponent cmnGenericObject mtsTaskContinuous mtsTaskFromCallback ireTask mtsATINetFTSensor mtsCMUSphinx4 mtsKeyboard mtsOSGCameraTask mtsOSGImage mtsQtApplication mtsSartoriusSerial mtsSocketProxyClient mtsSocketProxyServer mtsTaskFromSignal mtsTaskMain mtsTaskPeriodic mtsWAM mtsTaskFromCallbackAdapter

Public Types

typedef mtsComponent BaseType
 
- Public Types inherited from mtsComponent
typedef mtsComponent ThisType
 

Public Member Functions

 mtsTask (const std::string &name, unsigned int sizeStateTable=256)
 
virtual ~mtsTask ()
 
virtual void OnStartupException (const std::exception &excp)
 
virtual void Run (void)=0
 
virtual void OnRunException (const std::exception &excp)
 
virtual void Configure (const std::string &CMN_UNUSED(filename)="")
 
void SetInitializationDelay (double delay)
 
virtual void Create (void *data)=0
 
void Create (void)
 
void Kill (void)
 
double GetAveragePeriod (void) const
 
const std::string GetDefaultStateTableName (void) const
 
mtsStateTableGetDefaultStateTable (void)
 
mtsInterfaceRequiredAddInterfaceRequiredWithoutSystemEventHandlers (const std::string &interfaceRequiredName, mtsRequiredType required=MTS_REQUIRED)
 
mtsInterfaceProvidedAddInterfaceProvidedWithoutSystemEvents (const std::string &newInterfaceName, mtsInterfaceQueueingPolicy queueingPolicy=MTS_COMPONENT_POLICY, bool isProxy=false)
 
virtual bool WaitToStart (double timeout)
 
virtual bool WaitToTerminate (double timeout)
 
virtual void WaitForWakeup (void)
 
virtual void Wakeup (void)
 
void ProcessManagerCommandsIfNotActive ()
 
bool CheckForOwnThread (void) const
 
virtual bool IsPeriodic (void) const
 
virtual bool IsOverranPeriod (void) const
 
virtual void ResetOverranPeriod (void)
 
- Public Member Functions inherited from mtsComponent
 mtsComponent (const std::string &deviceName)
 
virtual ~mtsComponent ()
 
const std::string & GetName (void) const
 
void GetName (std::string &placeHolder) const
 
void SetName (const std::string &componentName)
 
virtual void Configure (const std::string &filename="")
 
bool CreateAndWait (double timeoutInSeconds)
 
virtual void Start (void)
 
bool StartAndWait (double timeoutInSeconds)
 
virtual void Suspend (void)
 
bool KillAndWait (double timeoutInSeconds)
 
virtual void Startup (void)
 
virtual void Cleanup (void)
 
mtsInterfaceProvidedAddInterfaceProvided (const std::string &interfaceProvidedName, mtsInterfaceQueueingPolicy queueingPolicy=MTS_COMPONENT_POLICY)
 
CISST_DEPRECATED
mtsInterfaceProvided
AddProvidedInterface (const std::string &interfaceProvidedName)
 
virtual mtsInterfaceOutputAddInterfaceOutput (const std::string &interfaceOutputName)
 
bool InterfaceExists (const std::string &interfaceName, cmnLogLevel lod=CMN_LOG_LEVEL_INIT_VERBOSE) const
 
bool InterfaceProvidedOrOutputExists (const std::string &interfaceName, cmnLogLevel lod=CMN_LOG_LEVEL_INIT_VERBOSE) const
 
bool InterfaceRequiredOrInputExists (const std::string &interfaceName, cmnLogLevel lod=CMN_LOG_LEVEL_INIT_VERBOSE) const
 
mtsInterfaceProvidedGetInterfaceProvided (const std::string &interfaceProvidedName) const
 
mtsInterfaceOutputGetInterfaceOutput (const std::string &interfaceOutputName) const
 
size_t GetNumberOfInterfacesProvided (void) const
 
size_t GetNumberOfInterfacesOutput (void) const
 
bool RemoveInterfaceProvided (const std::string &interfaceProvidedName, const bool skipDisconnect=false)
 
mtsInterfaceRequiredAddInterfaceRequired (const std::string &interfaceRequiredName, mtsRequiredType isRequired=MTS_REQUIRED)
 
CISST_DEPRECATED
mtsInterfaceRequired
AddRequiredInterface (const std::string &requiredInterfaceName)
 
virtual mtsInterfaceInputAddInterfaceInput (const std::string &interfaceInputName)
 
const mtsInterfaceProvidedGetInterfaceProvidedFor (const std::string &interfaceRequiredName)
 
mtsInterfaceRequiredGetInterfaceRequired (const std::string &interfaceRequiredName)
 
mtsInterfaceInputGetInterfaceInput (const std::string &interfaceInputName) const
 
size_t GetNumberOfInterfacesRequired (void) const
 
size_t GetNumberOfInterfacesInput (void) const
 
bool RemoveInterfaceRequired (const std::string &interfaceRequiredName, const bool skipDisconnect=false)
 
const mtsManagerComponentServicesGetManagerComponentServices (void) const
 
mtsManagerComponentServicesGetManagerComponentServices (void)
 
mtsStateTableGetStateTable (const std::string &stateTableName)
 
bool AddStateTable (mtsStateTable *existingStateTable, bool addInterfaceProvided=true)
 
void UseSeparateLogFileDefault (bool forwardToLogger=true)
 
void UseSeparateLogFileDefaultWithDate (bool forwardToLogger=true)
 
void UseSeparateLogFile (const std::string &filename, bool forwardToLogger=true)
 
cmnLogger::StreamBufTypeGetLogMultiplexer (void) const
 
bool IsRunning (void) const
 
bool CISST_DEPRECATED Running (void) const
 
bool IsStarted (void) const
 
bool IsTerminated (void) const
 
bool IsEndTask (void) const
 
const mtsComponentStateGetState (void) const
 
void GetState (mtsComponentState &state) const
 
void ToStream (std::ostream &outputStream) const
 
bool SetReplayMode (void)
 
bool SetReplayData (const std::string &stateTableName, const std::string &fileName)
 
bool SetReplayTime (const double time)
 
std::vector< std::string > GetNamesOfInterfacesProvidedOrOutput (void) const
 
std::vector< std::string > GetNamesOfInterfacesProvided (void) const
 
std::vector< std::string > GetNamesOfInterfacesOutput (void) const
 
std::vector< std::string > GetNamesOfInterfacesRequiredOrInput (void) const
 
std::vector< std::string > GetNamesOfInterfacesRequired (void) const
 
std::vector< std::string > GetNamesOfInterfacesInput (void) const
 
- Public Member Functions inherited from cmnGenericObject
virtual ~cmnGenericObject (void)
 
virtual const
cmnClassServicesBase
Services (void) const =0
 
bool ReconstructFrom (const cmnGenericObject &other)
 
std::string ToString (void) const
 
virtual void ToStreamRaw (std::ostream &outputStream, const char delimiter= ' ', bool headerOnly=false, const std::string &headerPrefix="") const
 
virtual bool FromStreamRaw (std::istream &inputStream, const char delimiter= ' ')
 
virtual void SerializeRaw (std::ostream &outputStream) const
 
virtual void DeSerializeRaw (std::istream &inputStream)
 
virtual size_t ScalarNumber (void) const
 
virtual bool ScalarNumberIsFixed (void) const
 
virtual double Scalar (const size_t CMN_UNUSED(index)) const throw (std::out_of_range)
 
virtual std::string ScalarDescription (const size_t CMN_UNUSED(index), const std::string &CMN_UNUSED(userDescription)) const
 

Static Public Attributes

static std::runtime_error UnknownException
 

Protected Member Functions

void RunEventHandler (void)
 
void ChangeStateEventHandler (const mtsComponentState &newState)
 
mtsExecutionResult RunEvent (bool check=true)
 
virtual void * RunInternal (void *argument)=0
 
void DoRunInternal (void)
 
virtual void StartupInternal (void)
 
virtual void CleanupInternal (void)
 
void Sleep (double timeInSeconds)
 
mtsStateIndex::TimeTicksType GetTick (void) const
 
virtual void SaveThreadStartData (void *data)
 
virtual void SetThreadReturnValue (void *returnValue)
 
void ChangeState (mtsComponentState::Enum newState)
 
bool WaitForState (mtsComponentState desiredState, double timeout)
 
- Protected Member Functions inherited from mtsComponent
 mtsComponent (void)
 
 mtsComponent (const mtsComponent &other)
 
void Initialize (void)
 
mtsInterfaceRequiredAddInterfaceRequiredExisting (const std::string &interfaceRequiredName, mtsInterfaceRequired *interfaceRequired)
 
mtsInterfaceRequiredAddInterfaceRequiredUsingMailbox (const std::string &interfaceRequiredName, mtsMailBox *mailBox, mtsRequiredType required)
 
mtsInterfaceProvidedAddInterfaceProvidedUsingMailbox (const std::string &interfaceProvidedName, mtsMailBox *mailBox)
 
mtsInterfaceInputAddInterfaceInputExisting (const std::string &interfaceInputName, mtsInterfaceInput *interfaceInput)
 
mtsInterfaceOutputAddInterfaceOutputExisting (const std::string &interfaceOutputName, mtsInterfaceOutput *interfaceOutput)
 
void KillSeparateLogFile (void)
 
size_t ProcessMailBoxes (InterfacesProvidedMapType &interfaces)
 
size_t ProcessQueuedCommands (void)
 
size_t ProcessQueuedEvents (void)
 
mtsInterfaceRequiredEnableDynamicComponentManagement (void)
 Enable support for dynamic component management services. More...
 
bool AddInterfaceInternal (const bool useMangerComponentServices=false)
 Add internal interfaces. More...
 
void InterfaceInternalCommands_GetEndUserInterface (const mtsEndUserInterfaceArg &argin, mtsEndUserInterfaceArg &argout)
 
void InterfaceInternalCommands_AddObserverList (const mtsEventHandlerList &argin, mtsEventHandlerList &argout)
 
void InterfaceInternalCommands_RemoveEndUserInterface (const mtsEndUserInterfaceArg &argin, mtsEndUserInterfaceArg &argout)
 
void InterfaceInternalCommands_RemoveObserverList (const mtsEventHandlerList &argin, mtsEventHandlerList &argout)
 
void InterfaceInternalCommands_ComponentCreate (const mtsDescriptionComponent &componentDescription, bool &result)
 
void InterfaceInternalCommands_ComponentStartOther (const mtsComponentStatusControl &arg)
 

Protected Attributes

osaThread Thread
 
double InitializationDelay
 
osaMutex StateChange
 
osaThreadSignal StateChangeSignal
 
mtsStateTable StateTable
 
bool OverranPeriod
 
void * ThreadStartData
 
void * ReturnValue
 
mtsCallableVoidBaseInterfaceProvidedToManagerCallable
 
mtsInterfaceRequiredExecIn
 
mtsInterfaceProvidedExecOut
 
mtsFunctionVoid RunEventInternal
 
bool RunEventCalled
 
mtsFunctionWrite ChangeStateEvent
 
- Protected Attributes inherited from mtsComponent
std::string Name
 
mtsComponentState State
 
mtsInterfaceProvidedInterfaceProvidedToManager
 
bool UseSeparateLogFileFlag
 
cmnLogger::StreamBufTypeLoDMultiplexerStreambuf
 
std::ofstream * LogFile
 
StateTableMapType StateTables
 
mtsManagerComponentServicesManagerComponentServices
 
mtsFunctionWrite EventGeneratorChangeState
 
bool ReplayMode
 
InterfacesProvidedMapType InterfacesProvided
 
InterfacesOutputMapType InterfacesOutput
 
InterfacesRequiredMapType InterfacesRequired
 
InterfacesInputMapType InterfacesInput
 

Friends

class mtsManagerLocal
 

Additional Inherited Members

- Protected Types inherited from mtsComponent
typedef cmnNamedMap
< mtsStateTable
StateTableMapType
 
typedef cmnNamedMap
< mtsInterfaceProvided
InterfacesProvidedMapType
 
typedef cmnNamedMap
< mtsInterfaceOutput
InterfacesOutputMapType
 
typedef cmnNamedMap
< mtsInterfaceRequired
InterfacesRequiredMapType
 
typedef cmnNamedMap
< mtsInterfaceInput
InterfacesInputMapType
 

Detailed Description

This class provides the base for implementing tasks that have a thread, a state table to store the state at each 'tick' (increment) of the task, and queues to receive messages (commands) from other tasks. It is derived from mtsComponent, so it also contains the provided and required interfaces, with their lists of commands.

Member Typedef Documentation

Constructor & Destructor Documentation

mtsTask::mtsTask ( const std::string &  name,
unsigned int  sizeStateTable = 256 
)

Create a task with name 'name' and set the state table size (see mtsStateTable). This is the task base class. Tasks should be derived from one of the existing derived classes: mtsTaskContinuous, mtsTaskPeriodic, mtsTaskFromCallback, and mtsTaskFromSignal.

Parameters
nameThe name for the task
sizeStateTableThe history size of the state table
Note
The full string name is maintained in the class member data (in mtsComponent base class). But, be aware that when a thread and/or thread buddy is created, only the first 6 characters of this name are used with the thread or thread buddy. This is an artifact of the 6 character limit imposed by RTAI/Linux.
See Also
mtsComponent, mtsTaskContinuous, mtsTaskPeriodic, mtsTaskFromCallback, mtsTaskFromSignal
virtual mtsTask::~mtsTask ( )
virtual

Default Destructor.

Member Function Documentation

mtsInterfaceProvided* mtsTask::AddInterfaceProvidedWithoutSystemEvents ( const std::string &  interfaceProvidedName,
mtsInterfaceQueueingPolicy  queueingPolicy = MTS_COMPONENT_POLICY,
bool  isProxy = false 
)
virtual

Method to add a bare provided interface, i.e. without all the system events. This method should not be used by regular users as it might break things like blocking commands.

This method is virtual so that mtsTask can redefine it and create a provided interface that includes queues for thread safety.

Reimplemented from mtsComponent.

Reimplemented in mtsTaskFromSignal.

mtsInterfaceRequired* mtsTask::AddInterfaceRequiredWithoutSystemEventHandlers ( const std::string &  interfaceRequiredName,
mtsRequiredType  required = MTS_REQUIRED 
)
virtual

Reimplemented from mtsComponent.

Reimplemented in mtsTaskFromSignal.

void mtsTask::ChangeState ( mtsComponentState::Enum  newState)
protected
void mtsTask::ChangeStateEventHandler ( const mtsComponentState newState)
protected

Change state event handler.

bool mtsTask::CheckForOwnThread ( void  ) const

Returns true if currently executing in thread-space of component.

virtual void mtsTask::CleanupInternal ( void  )
protectedvirtual

The member function that is executed once the task terminates. This does some cleanup work.

Reimplemented in mtsTaskPeriodic.

virtual void mtsTask::Configure ( const std::string &  CMN_UNUSEDfilename = "")
inlinevirtual

Virtual method that gets called when the task/interface needs to be configured. Should it take XML info??

Reimplemented in mtsSensableHD, mtsOpenALRecord, mtsNovintHDL, mtsComponentViewer, mtsIntuitiveDaVinci, mtsOpenALPlay, mtsSartoriusSerial, mtsTextToSpeech, and mtsKeyboard.

virtual void mtsTask::Create ( void *  data)
pure virtual
void mtsTask::Create ( void  )
inlinevirtual

Virtual method to create the components, e.g. for tasks create the required threads. For other components, place initialization code.

Reimplemented from mtsComponent.

void mtsTask::DoRunInternal ( void  )
protected

The main part of the Run loop that is the same for all derived classes. This should not be overloaded.

double mtsTask::GetAveragePeriod ( void  ) const
inline

Return the average period.

mtsStateTable* mtsTask::GetDefaultStateTable ( void  )
inline

Return a pointer to the default state table. See GetStateTable and GetDefaultStateTableName.

const std::string mtsTask::GetDefaultStateTableName ( void  ) const
inline

Return the name of this state table.

mtsStateIndex::TimeTicksType mtsTask::GetTick ( void  ) const
protected

Return the current tick count.

virtual bool mtsTask::IsOverranPeriod ( void  ) const
inlinevirtual

Return true if task overran allocated period. Note that this is not restricted to mtsTaskPeriodic. For example, an mtsTaskFromCallback can overrun if a second callback occurs before the first is finished.

virtual bool mtsTask::IsPeriodic ( void  ) const
inlinevirtual

Return true if thread is periodic.

Reimplemented in mtsTaskPeriodic.

void mtsTask::Kill ( void  )
virtual

End the task

Reimplemented from mtsComponent.

Reimplemented in mtsTaskContinuous, mtsTaskFromCallback, mtsSensableHD, mtsNovintHDL, and mtsTaskFromSignal.

virtual void mtsTask::OnRunException ( const std::exception &  excp)
virtual

Virtual method that gets called if an exception is thrown in the Run method.

virtual void mtsTask::OnStartupException ( const std::exception &  excp)
virtual

Virtual method that gets called if an exception is thrown in the Startup method. This could be moved to mtsComponent.

void mtsTask::ProcessManagerCommandsIfNotActive ( )

Conditionally process internal mailbox

virtual void mtsTask::ResetOverranPeriod ( void  )
inlinevirtual

Reset overran period flag.

virtual void mtsTask::Run ( void  )
pure virtual
mtsExecutionResult mtsTask::RunEvent ( bool  check = true)
protected
void mtsTask::RunEventHandler ( void  )
protected

Run event handler.

virtual void* mtsTask::RunInternal ( void *  argument)
protectedpure virtual

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

Implemented in mtsTaskPeriodic, mtsTaskContinuous, mtsTaskFromCallback, and mtsTaskFromSignal.

virtual void mtsTask::SaveThreadStartData ( void *  data)
protectedvirtual

Save any 'user data' that was passed to the thread start routine.

void mtsTask::SetInitializationDelay ( double  delay)

Set the initialization delay. See InitializationDelay.

virtual void mtsTask::SetThreadReturnValue ( void *  returnValue)
protectedvirtual
void mtsTask::Sleep ( double  timeInSeconds)
protected

Delay the task by the specified amount. This is a protected member function because it should only be called from within the task. Otherwise, use osaSleep.

virtual void mtsTask::StartupInternal ( void  )
protectedvirtual

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 in mtsTaskPeriodic, and mtsTaskFromCallback.

bool mtsTask::WaitForState ( mtsComponentState  desiredState,
double  timeout 
)
protectedvirtual

Helper function to wait on a state change, with specified timeout in seconds.

Reimplemented from mtsComponent.

virtual void mtsTask::WaitForWakeup ( void  )
inlinevirtual

Suspend this task until the Wakeup method is called.

virtual bool mtsTask::WaitToStart ( double  timeout)
virtual

Wait for task to start.

Parameters
timeoutThe timeout in seconds
Returns
true if task has started; false if timeout occurred before task started.
virtual bool mtsTask::WaitToTerminate ( double  timeout)
virtual

Wait for task to finish (after issuing a task Kill).

Parameters
timeoutThe timeout in seconds
Returns
true if the task terminated without timeout happening; false if timeout occured and task did not finish
virtual void mtsTask::Wakeup ( void  )
inlinevirtual

Wakeup the task.

Friends And Related Function Documentation

friend class mtsManagerLocal
friend

Member Data Documentation

mtsFunctionWrite mtsTask::ChangeStateEvent
protected

Event generator used to change state of dependent tasks.

mtsInterfaceRequired* mtsTask::ExecIn
protected

ExecIn required interface.

mtsInterfaceProvided* mtsTask::ExecOut
protected

ExecOut provided interface.

double mtsTask::InitializationDelay
protected

Delay given for the task to start. During initialization the task thread will wait for the specified delay (set by default to 3 seconds in the constructor). Increasing this delay can be useful when using mtsTaskFromCallback if the callback might take more than 3 seconds to trigger the task's Run method.

mtsCallableVoidBase* mtsTask::InterfaceProvidedToManagerCallable
protected

Callable object used when queueing.

bool mtsTask::OverranPeriod
protected

True if the task took more time to do computation than allocated time.

void* mtsTask::ReturnValue
protected

The return value for RunInternal.

bool mtsTask::RunEventCalled
protected
mtsFunctionVoid mtsTask::RunEventInternal
protected

Event generator used to pass thread of execution to another task. User code should not call this directly (call RunEvent instead).

osaMutex mtsTask::StateChange
protected

Mutex used when changing task states. Do not change this directly, use the ChangeState method instead.

osaThreadSignal mtsTask::StateChangeSignal
protected

Signal for caller to wait on task state changes.

mtsStateTable mtsTask::StateTable
protected

The state data table object to store the states of the task.

osaThread mtsTask::Thread
protected

The OS independent thread object.

void* mtsTask::ThreadStartData
protected

The data passed to the thread.

std::runtime_error mtsTask::UnknownException
static

The documentation for this class was generated from the following file: