libserial  0.6.0rc3
Classes | Public Member Functions | Static Public Member Functions | Private Member Functions | List of all members
PosixSignalDispatcher Class Reference

#include <PosixSignalDispatcher.h>

Classes

class  CannotAttachHandler
 Exception thrown when AttachHandler() fails due to a runtime error. More...
 
class  CannotDetachHandler
 Exception thrown when DetachHandler() fails due to a runtime error. More...
 

Public Member Functions

void AttachHandler (const int posixSignalNumber, PosixSignalHandler &signalHandler) throw ( CannotAttachHandler )
 Attach a signal handler to the signal dispatcher. More...
 
void DetachHandler (const int posixSignalNumber, const PosixSignalHandler &signalHandler) throw ( CannotDetachHandler, std::logic_error )
 Detach the specified signal handler from the signal dispatcher. More...
 

Static Public Member Functions

static PosixSignalDispatcherInstance ()
 This is a singleton class and there is only one instance of this class per process. More...
 

Private Member Functions

 PosixSignalDispatcher ()
 This is a singleton class and the only instances of this class can only be accessed using the Instance() method. More...
 
 ~PosixSignalDispatcher ()
 This class cannot be subclassed. More...
 
 PosixSignalDispatcher (const PosixSignalDispatcher &otherInstance)
 Copying of an instance of this class is not allowed. More...
 
const PosixSignalDispatcheroperator= (const PosixSignalDispatcher &otherInstance)
 Copying of an instance of this class is not allowed. More...
 

Detailed Description

Note
The signal dispatcher will not interfere with any signals for which there are no signal handlers attached. Similarly, if a signal handler function is already attached to a signal that the dispatcher is asked to administer, that signal handler will be called after all the attached PosixSignalHandlers.
Todo:
Make this a singleton class.

Definition at line 33 of file PosixSignalDispatcher.h.

Constructor & Destructor Documentation

PosixSignalDispatcher::PosixSignalDispatcher ( )
private

This is a singleton class and the only instances of this class can only be accessed using the Instance() method.

This is enforced by making the default constructor a private member disalloweing construction of new instances of this class

PosixSignalDispatcher::~PosixSignalDispatcher ( )
private

This class cannot be subclassed.

We enforce this by making the destructor a private member.

PosixSignalDispatcher::PosixSignalDispatcher ( const PosixSignalDispatcher otherInstance)
private

Copying of an instance of this class is not allowed.

We enforce this by making the copy constructor and the assignment operator private members.

Member Function Documentation

void PosixSignalDispatcher::AttachHandler ( const int  posixSignalNumber,
PosixSignalHandler signalHandler 
)
throw (CannotAttachHandler
)

Attach a signal handler to the signal dispatcher.

The signal handler's HandlePosixSignal() method will be called every time the specified signal is received. The signal handler should not be destroyed while it attached to the signal dispatcher. Otherwise, weird things are bound to happen (i.e. "undefined behavior" shall ensue). Make sure you call DetachHandler() from the destructor of the signal handler.

If a PosixSignalHandler is attached to the same signal number multiple times, it will be called multiple times. Furthermore, it should also be detached as many times as it was attached before it is destroyed. Otherwise, undefined behavior may result.

Parameters
posixSignalNumberThe signal number that will result in call to the HandlePosixSignal() method of the signal handler.
signalHandlerThe signal handler to be invoked on receiving a posixSignalNumber signal.
void PosixSignalDispatcher::DetachHandler ( const int  posixSignalNumber,
const PosixSignalHandler signalHandler 
)
throw ( CannotDetachHandler,
std::logic_error
)

Detach the specified signal handler from the signal dispatcher.

The signal handler will stop being called on receiving the corresponding POSIX signal. If the signal handler is not attached to the signal dispatcher when this method is called then this method has no effect.

Parameters
posixSignalNumberThe signal number corresponding to the signal handler.
signalHandlerThe signal handler to be detached.
static PosixSignalDispatcher& PosixSignalDispatcher::Instance ( )
static

This is a singleton class and there is only one instance of this class per process.

This instance can be obtained using the GetInstance() method.

const PosixSignalDispatcher& PosixSignalDispatcher::operator= ( const PosixSignalDispatcher otherInstance)
private

Copying of an instance of this class is not allowed.

We enforce this by making the copy constructor and the assignment operator private members.


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