My Project
 All Classes Files Functions Variables Enumerations Enumerator Friends Macros Pages
gcp::util::SignalTask Class Reference

#include <SignalTask.h>

Inheritance diagram for gcp::util::SignalTask:
gcp::util::GenericTask< gcp::util::SignalTaskMsg >

Classes

class  SignalHandler
 
class  TimerInfo
 

Public Member Functions

 SignalTask (bool spawnThread=false)
 
virtual ~SignalTask ()
 
void sendInstallTimerMsg (std::string name, int sigNo, unsigned long initSec, unsigned long initNsec, unsigned long intervalSec, unsigned long intervaNsec, SIGNALTASK_HANDLER_FN(*handler))
 
void sendAddHandlerMsg (std::string name, SIGNALTASK_HANDLER_FN(*handler), bool add)
 
void sendInstallSignalMsg (int sigNo, SIGNALTASK_HANDLER_FN(*handler), void *arg=NULL)
 
void sendAddHandlerMsg (int sigNo, SIGNALTASK_HANDLER_FN(*handler), bool add)
 
void sendEnableTimerMsg (std::string name, bool enable)
 
void stopTimers ()
 
int getIoSig ()
 
virtual void run ()
 
void serviceMsgQ ()
 
- Public Member Functions inherited from gcp::util::GenericTask< gcp::util::SignalTaskMsg >
void sendRestartMsg ()
 
void sendStopMsg ()
 
void sendHeartBeatMsg ()
 

Protected Attributes

sigset_t handledSignals_
 
- Protected Attributes inherited from gcp::util::GenericTask< gcp::util::SignalTaskMsg >
Threadthread_
 
std::vector< Thread * > threads_
 
PipeQ< gcp::util::SignalTaskMsgmsgq_
 
gcp::util::FdSet fdSet_
 
std::vector< Command * > commands_
 
struct timeval * timeOut_
 
TimeVal commandTimeOut_
 

Additional Inherited Members

- Protected Member Functions inherited from gcp::util::GenericTask< gcp::util::SignalTaskMsg >
 GenericTask ()
 
 GenericTask (Thread *thread)
 
virtual ~GenericTask ()
 
void sendTaskMsg (gcp::util::SignalTaskMsg *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 restart (void)
 
virtual void processMsg (gcp::util::SignalTaskMsg *msg)
 
virtual void respondToHeartBeat ()
 
virtual void addHandler (gcp::util::SignalTaskMsg *msg)
 
void stepCommands ()
 

Detailed Description

A generic base-class task for handling timers & signals.

Context:

Under pthreads, there is no guarantee which thread a signal will be delivered to, so traditional use of signal handlers in multiple threads is unsafe.

The safe way of handling signals under pthreads is to block signals in all threads but one, which is dedicated to servicing all signals.

The default run() method of this class handles signals in normal code, by blocking in a loop on sigwait() until any catchable signal has arrived. On receipt of a signal, if a handler has been installed for that signal using either installTimer() or installSignal() methods below, that handler is called. Note that all signals are blocked between calls to sigwait(), so that we are guaranteed not to be interrupted by another signal while servicing one that has just arrived.

Each pass of the loop atomically unblocks a set of signals specified by a sigset_t* argument passed to sigwait(). This set is modified by calls to installTimer() and installSignal(), below.

SignalTask installs

Constructor & Destructor Documentation

SignalTask::SignalTask ( bool  spawnThread = false)

Constructor for SignalTask. The thread id is set in this constructor to the id returned by pthread_self(). Calling our internal send*Msg() methods will therefore cause an I/O signal to be raised to the thread which instantiated this object, causing the message queue to be checked.

....................................................................... Constructor.

SignalTask::~SignalTask ( )
virtual

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

....................................................................... Destructor: Delete any timers managed by this task.

Member Function Documentation

int SignalTask::getIoSig ( )

Query what signal this object uses for I/O events.

....................................................................... Return which signal this object uses for I/O events.

void SignalTask::run ( void  )
virtual

Run, handling signals.

....................................................................... A run method for this task.

Reimplemented from gcp::util::GenericTask< gcp::util::SignalTaskMsg >.

void gcp::util::SignalTask::sendAddHandlerMsg ( std::string  name,
SIGNALTASK_HANDLER_FN *  handler,
bool  add 
)

Send a message to attach a handler to an existing timer.

void SignalTask::sendAddHandlerMsg ( int  sigNo,
SIGNALTASK_HANDLER_FN *  handler,
bool  add 
)

Send a message to attach a handler to a signal.

....................................................................... Send a message to add a handler to the set attached to this timer.

void SignalTask::sendEnableTimerMsg ( std::string  name,
bool  enable 
)

Send a message to enable/disable a timer.

....................................................................... Respond to a message to enable/disable a timer.

void SignalTask::sendInstallSignalMsg ( int  sigNo,
SIGNALTASK_HANDLER_FN *  handler,
void *  arg = NULL 
)

Send a message to install a signal.

....................................................................... Send a message to install a signal.

void SignalTask::sendInstallTimerMsg ( std::string  name,
int  sigNo,
unsigned long  initSec,
unsigned long  initNsec,
unsigned long  intervalSec,
unsigned long  intervaNsec,
SIGNALTASK_HANDLER_FN *  handler 
)

Send a message to install a timer.

....................................................................... Send a message to install a timer.

void SignalTask::serviceMsgQ ( void  )
virtual

Service our message queue.

....................................................................... Check our message queue for pending messages.

Reimplemented from gcp::util::GenericTask< gcp::util::SignalTaskMsg >.

void SignalTask::stopTimers ( )

Stop all timers.

....................................................................... Stop all timers

Member Data Documentation

sigset_t gcp::util::SignalTask::handledSignals_
protected

The set of signals handled by this task. We make this protected so that inheritors of this class can redefine run(), which may require access to handledSignals_.


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