My Project
 All Classes Files Functions Variables Enumerations Enumerator Friends Macros Pages
gcp::util::GenericTask< Msg > Class Template Reference

#include <GenericTask.h>

Inheritance diagram for gcp::util::GenericTask< Msg >:
gcp::util::GenericMasterTask< Msg > gcp::util::SpawnableTask< Msg >

Public Member Functions

void sendRestartMsg ()
 
void sendStopMsg ()
 
void sendHeartBeatMsg ()
 
virtual void fwdTaskMsg (Msg *msg)
 

Protected Member Functions

 GenericTask ()
 
 GenericTask (Thread *thread)
 
virtual ~GenericTask ()
 
void sendTaskMsg (Msg *msg)
 
void startThreads (void *arg)
 
void startThread (void *arg, unsigned order)
 
unsigned getMinStartOrder ()
 
bool threadsNeedStarting ()
 
void cancelThreads ()
 
void cancelThread (unsigned order)
 
unsigned getMinCancelOrder ()
 
bool threadsNeedCancelling ()
 
void pingThreads (void *arg)
 
void raise (std::string name, int sigNo)
 
ThreadgetThread (std::string name)
 
bool threadsAreRunning ()
 
void shutdownConnection (int fd)
 
virtual void serviceMsgQ (void)
 
virtual void restart (void)
 
virtual void run (void)
 
virtual void processTaskMsg (bool *stop)
 
virtual void processMsg (Msg *msg)
 
virtual void respondToHeartBeat ()
 
virtual void installTimer (Msg *msg)
 
virtual void installSignal (Msg *msg)
 
virtual void enableTimer (Msg *msg)
 
virtual void addHandler (Msg *msg)
 
void stepCommands ()
 

Protected Attributes

Threadthread_
 
std::vector< Thread * > threads_
 
PipeQ< Msg > msgq_
 
gcp::util::FdSet fdSet_
 
std::vector< Command * > commands_
 
struct timeval * timeOut_
 
TimeVal commandTimeOut_
 

Detailed Description

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

All tasks will have the following functionality:

Constructor & Destructor Documentation

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

Protected constructor ensures that the base class cannot be instantiated.

Constructor

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

Constructor which initializes thread_, below.

Constructor

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

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

Destructor

Member Function Documentation

template<class Msg>
void gcp::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.

Reimplemented in gcp::util::GenericMasterTask< Msg >, gcp::util::GenericMasterTask< MasterMsg >, and gcp::util::GenericMasterTask< AntennaMasterMsg >.

template<class Msg >
void gcp::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.

template<class Msg >
void gcp::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.

template<class Msg>
void gcp::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.

Reimplemented in gcp::util::GenericMasterTask< Msg >, gcp::util::GenericMasterTask< MasterMsg >, and gcp::util::GenericMasterTask< AntennaMasterMsg >.

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

Forward a message to this 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.

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

template<class Msg >
unsigned gcp::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.

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

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

template<class Msg >
Thread * gcp::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

template<class Msg>
void gcp::util::GenericTask< Msg >::installSignal ( Msg *  msg)
protectedvirtual
template<class Msg>
void gcp::util::GenericTask< Msg >::installTimer ( Msg *  msg)
protectedvirtual
template<class Msg >
void gcp::util::GenericTask< Msg >::pingThreads ( void *  arg)
protected

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

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

Method to ping all threads managed by this task.

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

Process a message received on our message queue

Exceptions
ExceptionMethod to process a message received on the Task message * queue

Reimplemented in gcp::util::GenericMasterTask< Msg >, gcp::util::GenericMasterTask< MasterMsg >, and gcp::util::GenericMasterTask< AntennaMasterMsg >.

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

Raise a signal to a named thread.

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

Respond to a heartbeat message.

Exceptions
ExceptionEach thread should respond to a heartbeat request by re-setting its running state to true
template<class Msg >
void gcp::util::GenericTask< Msg >::restart ( void  )
protectedvirtual

Restart this thread.

Restart method stub

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

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

Send a heartbeat request to this task.

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

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

Send a restart request to this thread

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

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

Send a shutdown request to this thread

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

Send a message to this task via its message queue.

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

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

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

This routine will simply block, servicing messages on the message queue. This is declared virtual so that inheritors can overload with their own methods.

Exceptions
ExceptionMain Task event loop: when this is called, the task blocks forever in select(), or until a stop message is received. yes
Exception(also via msgq_.rfds())

Reimplemented in gcp::util::GpibUsbController, gcp::receiver::ReceiverConfigConsumer, gcp::util::SignalTask, and gcp::receiver::DioConsumer.

template<class Msg >
void gcp::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.

Shutdown a connection.

template<class Msg >
void gcp::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

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

A method to start all threads. 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.

Method to start the next thread with a given start priority

template<class Msg >
void gcp::util::GenericTask< Msg >::stepCommands ( )
protected

....................................................................... Step through any commands we are running

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

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

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

Return true if there are still uncancelled threads

Return true if there are still running threads

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

Return true if there are still unstarted threads

Member Data Documentation

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

A set of file descriptors associated with this task.

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

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

template<class Msg>
Thread* gcp::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).

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

A vector of Thread objects managed by this task.


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