CARMA C++
sza::util::GenericTask< Msg > Class Template Reference

All tasks will have the following functionality: More...

#include <carma/szautil/GenericTask.h>

Inheritance diagram for sza::util::GenericTask< Msg >:
sza::util::SpawnableTask< Msg >

Public Member Functions

virtual void fwdTaskMsg (Msg *msg)
 Forward a message to this task via its message queue. More...
 
void sendHeartBeatMsg ()
 Method to send a heartbeat message to this task via its message queue. More...
 
void sendRestartMsg ()
 Method to send a stop message to this task via its message queue. More...
 
void sendStopMsg ()
 Method to send a stop message to this task via its message queue. More...
 

Protected Member Functions

virtual void addHandler (Msg *msg)
 Respond to a message to add/remove a handler. More...
 
void cancelThread (unsigned order)
 Cancel the next thread with the specified order. More...
 
void cancelThreads ()
 A method to cancel threads managed by this task. More...
 
virtual void enableTimer (Msg *msg)
 Respond to a message to enable/disable a timer. More...
 
 GenericTask ()
 Protected constructor ensures that the base class cannot be instantiated. More...
 
 GenericTask (Thread *thread)
 Constructor which initializes thread_, below. More...
 
unsigned getMinCancelOrder ()
 Method to return the minimum cancel order for threads which are not yet running. More...
 
unsigned getMinStartOrder ()
 Method to return the minimum start order for threads which are not yet running. More...
 
ThreadgetThread (std::string name)
 A method to start all threads managed by this task running. More...
 
virtual void installSignal (Msg *msg)
 Respond to a message to install a signal. More...
 
virtual void installTimer (Msg *msg)
 Respond to a message to install a timer. More...
 
void pingThreads (void *arg)
 A method to ping all pingable threads managed by this task. More...
 
virtual void processMsg (Msg *msg)
 This method should be defined by each inheriting task to process its own task-specific messages. More...
 
virtual void processTaskMsg (bool *stop)
 Process a message received on our message queue. More...
 
void raise (std::string name, int sigNo)
 Raise a signal to a named thread. More...
 
virtual void respondToHeartBeat ()
 Respond to a heartbeat message. More...
 
virtual void restart (void)
 Restart this thread. More...
 
virtual void run (void)
 Force inheritors to define a run method. More...
 
void sendTaskMsg (Msg *msg)
 Send a message to this task via its message queue. More...
 
virtual void serviceMsgQ (void)
 This routine will simply block, servicing messages on the message queue. More...
 
void shutdownConnection (int fd)
 Shutdown a connection. More...
 
void startThread (void *arg, unsigned order)
 Start the next thread with the specified order. More...
 
void startThreads (void *arg)
 A method to start all threads. More...
 
bool threadsAreRunning ()
 A method to test if the threads managed by this task are running. More...
 
bool threadsNeedCancelling ()
 Return true if there are still uncancelled threads. More...
 
bool threadsNeedStarting ()
 Return true if there are still unstarted threads. More...
 
virtual ~GenericTask ()
 Making the destructor virtual ensures that the right destructor will be called for classes which inherit from GenericTask. More...
 

Protected Attributes

sza::util::FdSet fdSet_
 A set of file descriptors associated with this task. More...
 
PipeQ< Msg > msgq_
 A message queue, implemented as a pipe, by which we can communicate with this task. More...
 
Threadthread_
 If this GenericTask object was instantiated by another thread, keep a pointer to it here. More...
 
std::vector< Thread * > threads_
 A vector of Thread objects managed by this task. More...
 

Detailed Description

template<class Msg>
class sza::util::GenericTask< Msg >

All tasks will have the following functionality:

Definition at line 32 of file GenericTask.h.

Constructor & Destructor Documentation

template<class Msg >
sza::util::GenericTask< Msg >::GenericTask ( )
protected

Protected constructor ensures that the base class cannot be instantiated.

Constructor.

Definition at line 276 of file GenericTask.h.

template<class Msg >
sza::util::GenericTask< Msg >::GenericTask ( Thread thread)
protected

Constructor which initializes thread_, below.

Constructor.

Definition at line 290 of file GenericTask.h.

template<class Msg >
sza::util::GenericTask< Msg >::~GenericTask ( )
protectedvirtual

Making the destructor virtual ensures that the right destructor will be called for classes which inherit from GenericTask.

Destructor.

Definition at line 304 of file GenericTask.h.

Member Function Documentation

template<class Msg>
void sza::util::GenericTask< Msg >::addHandler ( Msg *  msg)
protectedvirtual

Respond to a message to add/remove a handler.

Send a message to the signal thread to add a handler.

Definition at line 736 of file GenericTask.h.

template<class Msg >
void sza::util::GenericTask< Msg >::cancelThread ( unsigned  order)
protected

Cancel the next thread with the specified order.

Method to cancel all threads managed by this task.

This will wait until all spawned threads have shut down, since each call to Thread::cancel() waits on the 'done' condition variable, which is signalled by each thread in its cancellation cleanup handler.

Definition at line 632 of file GenericTask.h.

template<class Msg >
void sza::util::GenericTask< Msg >::cancelThreads ( )
protected

A method to cancel threads managed by this task.

Method to cancel all threads managed by this task.

This will wait until all spawned threads have shut down, since each call to Thread::cancel() waits on the 'done' condition variable, which is signalled by each thread in its cancellation cleanup handler.

Definition at line 608 of file GenericTask.h.

template<class Msg>
void sza::util::GenericTask< Msg >::enableTimer ( Msg *  msg)
protectedvirtual

Respond to a message to enable/disable a timer.

Send a message to the master thread to install a timer.

Definition at line 730 of file GenericTask.h.

template<class Msg>
void sza::util::GenericTask< Msg >::fwdTaskMsg ( Msg *  msg)
virtual

Forward a message to this task via its message queue.

A task-independent method for forwarding a message to a task via its message queue.

A public method to forward messages to this task via its message queue. We make this virtual so that inheriting tasks can control precisely how messages from the outside world are routed.

protected method sendTaskMsg() (below) is available to inheritors to send messages to themselves.

Parameters
msgPointer to the message to be sent to this task.

Definition at line 482 of file GenericTask.h.

template<class Msg >
unsigned sza::util::GenericTask< Msg >::getMinCancelOrder ( )
protected

Method to return the minimum cancel order for threads which are not yet running.

Method to return the minimum stop order for threads which are still running.

Definition at line 577 of file GenericTask.h.

template<class Msg >
unsigned sza::util::GenericTask< Msg >::getMinStartOrder ( )
protected

Method to return the minimum start order for threads which are not yet running.

Definition at line 551 of file GenericTask.h.

template<class Msg >
Thread * sza::util::GenericTask< Msg >::getThread ( std::string  name)
protected

A method to start all threads managed by this task running.

Return a pointer to the thread of this name.

Returns: The requested pointer, or NULL on error

Definition at line 661 of file GenericTask.h.

template<class Msg>
void sza::util::GenericTask< Msg >::installSignal ( Msg *  msg)
protectedvirtual

Respond to a message to install a signal.

Definition at line 724 of file GenericTask.h.

template<class Msg>
void sza::util::GenericTask< Msg >::installTimer ( Msg *  msg)
protectedvirtual

Respond to a message to install a timer.

Definition at line 718 of file GenericTask.h.

template<class Msg >
void sza::util::GenericTask< Msg >::pingThreads ( void *  arg)
protected

A method to ping all pingable threads managed by this task.

Method to ping all threads managed by this task.

Parameters
argThe argument to be passed to the ping function specified in the Thread constructor.

Definition at line 645 of file GenericTask.h.

template<class Msg>
void sza::util::GenericTask< Msg >::processMsg ( Msg *  msg)
protectedvirtual

This method should be defined by each inheriting task to process its own task-specific messages.

Method to process a message received on the Task message * queue.

Exceptions
Exception

Reimplemented in sza::util::SpawnableTask< Msg >, sza::util::SpawnableTask< RemoteSensorMsg >, sza::util::SpawnableTask< RtdServerMsg >, sza::util::SpawnableTask< PeriodicTimerMsg >, sza::util::SpawnableTask< RtdClientMsg >, sza::util::SpawnableTask< AbsoluteTimerMsg >, sza::util::SpawnableTask< GpibUsbControllerMsg >, and sza::util::SpawnableTask< FastPdbClientMsg >.

Definition at line 406 of file GenericTask.h.

template<class Msg >
void sza::util::GenericTask< Msg >::processTaskMsg ( bool *  stop)
protectedvirtual

Process a message received on our message queue.

Method to process a message received on the Task message * queue.

Exceptions
Exception

Definition at line 378 of file GenericTask.h.

template<class Msg >
void sza::util::GenericTask< Msg >::raise ( std::string  name,
int  sigNo 
)
protected

Raise a signal to a named thread.

Definition at line 677 of file GenericTask.h.

template<class Msg >
void sza::util::GenericTask< Msg >::respondToHeartBeat ( )
protectedvirtual

Respond to a heartbeat message.

Each thread should respond to a heartbeat request by re-setting its running state to true.

Exceptions
Exception

Definition at line 413 of file GenericTask.h.

template<class Msg >
void sza::util::GenericTask< Msg >::restart ( void  )
protectedvirtual

Restart this thread.

Restart method stub.

Definition at line 329 of file GenericTask.h.

template<class Msg >
void sza::util::GenericTask< Msg >::sendHeartBeatMsg ( )

Method to send a heartbeat message to this task via its message queue.

Send a heartbeat request to this task.

Definition at line 455 of file GenericTask.h.

template<class Msg >
void sza::util::GenericTask< Msg >::sendRestartMsg ( )

Method to send a stop message to this task via its message queue.

Send a restart request to this thread.

Definition at line 423 of file GenericTask.h.

template<class Msg >
void sza::util::GenericTask< Msg >::sendStopMsg ( )

Method to send a stop message to this task via its message queue.

Send a shutdown request to this thread.

Definition at line 439 of file GenericTask.h.

template<class Msg>
void sza::util::GenericTask< Msg >::sendTaskMsg ( Msg *  msg)
protected

Send a message to this task via its message queue.

A task-independent method for sending a message to a task via its message queue.

Parameters
msgPointer to the message to be sent to this task.

Definition at line 472 of file GenericTask.h.

template<class Msg >
void sza::util::GenericTask< Msg >::serviceMsgQ ( void  )
protectedvirtual

This routine will simply block, servicing messages on the message queue.

Main Task event loop: when this is called, the task blocks forever in select(), or until a stop message is received.

This is declared virtual so that inheritors can overload with their own methods.

Exceptions
Exceptionyes
Exception(also via msgq_.rfds())

Reimplemented in sza::util::SignalTask.

Definition at line 348 of file GenericTask.h.

template<class Msg >
void sza::util::GenericTask< Msg >::shutdownConnection ( int  fd)
protected

Shutdown a connection.

This method calls shutdown() and close() on the file descriptor, and clears it from the set of desfcriptors to be watched by this task.

Definition at line 744 of file GenericTask.h.

template<class Msg >
void sza::util::GenericTask< Msg >::startThread ( void *  arg,
unsigned  order 
)
protected

Start the next thread with the specified order.

Method to start the next thread with a given start priority.

Definition at line 505 of file GenericTask.h.

template<class Msg >
void sza::util::GenericTask< Msg >::startThreads ( void *  arg)
protected

A method to start all threads.

Method to start the next thread with a given start priority.

This calls the run() method of all Threads managed by this task, which calls pthread_create() for each thread.

Parameters
argThe argument to be passed to the thread startup function specified in the Thread constructor.

Definition at line 491 of file GenericTask.h.

template<class Msg >
bool sza::util::GenericTask< Msg >::threadsAreRunning ( )
protected

A method to test if the threads managed by this task are running.

Definition at line 693 of file GenericTask.h.

template<class Msg >
bool sza::util::GenericTask< Msg >::threadsNeedCancelling ( )
protected

Return true if there are still uncancelled threads.

Return true if there are still running threads.

Definition at line 539 of file GenericTask.h.

template<class Msg >
bool sza::util::GenericTask< Msg >::threadsNeedStarting ( )
protected

Return true if there are still unstarted threads.

Definition at line 527 of file GenericTask.h.

Member Data Documentation

template<class Msg>
sza::util::FdSet sza::util::GenericTask< Msg >::fdSet_
protected

A set of file descriptors associated with this task.

Definition at line 192 of file GenericTask.h.

template<class Msg>
PipeQ<Msg> sza::util::GenericTask< Msg >::msgq_
protected

A message queue, implemented as a pipe, by which we can communicate with this task.

Definition at line 187 of file GenericTask.h.

template<class Msg>
Thread* sza::util::GenericTask< Msg >::thread_
protected

If this GenericTask object was instantiated by another thread, keep a pointer to it here.

If non-NULL, this will be used to broadcast to other threads that this task is shutting down (see ~GenericTask(), below).

Definition at line 104 of file GenericTask.h.

template<class Msg>
std::vector<Thread*> sza::util::GenericTask< Msg >::threads_
protected

A vector of Thread objects managed by this task.

Definition at line 109 of file GenericTask.h.


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