CARMA C++
|
All tasks will have the following functionality: More...
#include <carma/szautil/GenericTask.h>
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... | |
Thread * | getThread (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... | |
Thread * | thread_ |
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... | |
All tasks will have the following functionality:
Definition at line 32 of file GenericTask.h.
|
protected |
Protected constructor ensures that the base class cannot be instantiated.
Constructor.
Definition at line 276 of file GenericTask.h.
|
protected |
Constructor which initializes thread_, below.
Constructor.
Definition at line 290 of file GenericTask.h.
|
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.
|
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.
|
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.
|
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.
|
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.
|
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.
msg | Pointer to the message to be sent to this task. |
Definition at line 482 of file GenericTask.h.
|
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.
|
protected |
Method to return the minimum start order for threads which are not yet running.
Definition at line 551 of file GenericTask.h.
|
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.
|
protectedvirtual |
Respond to a message to install a signal.
Definition at line 724 of file GenericTask.h.
|
protectedvirtual |
Respond to a message to install a timer.
Definition at line 718 of file GenericTask.h.
|
protected |
A method to ping all pingable threads managed by this task.
Method to ping all threads managed by this task.
arg | The argument to be passed to the ping function specified in the Thread constructor. |
Definition at line 645 of file GenericTask.h.
|
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.
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.
|
protectedvirtual |
Process a message received on our message queue.
Method to process a message received on the Task message * queue.
Exception |
Definition at line 378 of file GenericTask.h.
|
protected |
Raise a signal to a named thread.
Definition at line 677 of file GenericTask.h.
|
protectedvirtual |
Respond to a heartbeat message.
Each thread should respond to a heartbeat request by re-setting its running state to true.
Exception |
Definition at line 413 of file GenericTask.h.
|
protectedvirtual |
|
protectedvirtual |
Force inheritors to define a run method.
Run method defaults to calling the serviceMsgQ() method below.
Reimplemented in sza::util::SignalTask, 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 336 of file GenericTask.h.
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.
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.
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.
|
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.
msg | Pointer to the message to be sent to this task. |
Definition at line 472 of file GenericTask.h.
|
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.
Exception | yes |
Exception | (also via msgq_.rfds()) |
Reimplemented in sza::util::SignalTask.
Definition at line 348 of file GenericTask.h.
|
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.
|
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.
|
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.
arg | The argument to be passed to the thread startup function specified in the Thread constructor. |
Definition at line 491 of file GenericTask.h.
|
protected |
A method to test if the threads managed by this task are running.
Definition at line 693 of file GenericTask.h.
|
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.
|
protected |
Return true if there are still unstarted threads.
Definition at line 527 of file GenericTask.h.
|
protected |
A set of file descriptors associated with this task.
Definition at line 192 of file GenericTask.h.
|
protected |
A message queue, implemented as a pipe, by which we can communicate with this task.
Definition at line 187 of file GenericTask.h.
|
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.
|
protected |
A vector of Thread objects managed by this task.
Definition at line 109 of file GenericTask.h.