RSC  0.16.0
rsc::misc Namespace Reference

Namespaces

 detail
 

Classes

class  IllegalStateException
 Exception indicating a call on a method where the underlying object is in an illegal state for this call. More...
 
class  NullDeleter
 A deleter object that can be used with boost::shared_ptr that doesn't release any memory. More...
 
class  ParentSharedPtrDeleter
 A deleter for boost::shared_ptr which enables to use a pointer in a shared_ptr, which is not a shared_ptr itself and owned by another object. More...
 
class  UnsupportedOperationException
 An exception which indicates that a certain operation is not supported by the target. More...
 
class  UUID
 Encapsulates the generation and handling of UUIDs. More...
 

Typedefs

typedef boost::shared_ptr< UUIDUUIDPtr
 

Enumerations

enum  Signal { NO_SIGNAL = 0, INTERRUPT_REQUESTED = 0x01, TERMINATE_REQUESTED = 0x02, QUIT_REQUESTED = 0x04 }
 Signals waitForSignal can wait for. More...
 

Functions

boost::uint64_t currentTimeMillis ()
 Returns the current system time as milliseconds. More...
 
boost::uint64_t currentTimeMicros ()
 Returns the current system time as microseconds. More...
 
char randAlnumChar ()
 Generates a random alpha-numeric character. More...
 
std::string randAlnumStr (const std::string::size_type &length)
 Generates a random alpha-numeric string with fixed length. More...
 
void handler (int signal)
 
void throwRuntimeError (int errorNumber, const std::string &description)
 
void initSignalWaiter (int signals=INTERRUPT_REQUESTED|TERMINATE_REQUESTED)
 Prepare waiting for signals. More...
 
Signal mappedSignal ()
 
Signal waitForSignal ()
 Block until one of the signals specified in initSignalWaiter arrives, then return the signal. More...
 
Signal lastArrivedSignal ()
 Returns the last signal that has arrived at this process or Signal::NO_SIGNAL in case no signal arrived so far. More...
 
int suggestedExitCode (Signal signal)
 Return suggested exit code for exiting the program after receiving signal signal. More...
 
ostream & operator<< (ostream &stream, const UUID &id)
 

Variables

int requestedSignals = 0
 
static std::string semaphore_name
 
sem_t * semaphore
 
volatile sig_atomic_t receivedSignal = 0
 

Typedef Documentation

typedef boost::shared_ptr<UUID> rsc::misc::UUIDPtr

Definition at line 124 of file UUID.h.

Enumeration Type Documentation

Signals waitForSignal can wait for.

The numeric values are chosen in a way that allows combining values via logical "or".

Author
jmoringe
Enumerator
NO_SIGNAL 

Artificial enum entry to indicate that no signal is meant at all.

INTERRUPT_REQUESTED 

Interrupting the program has be requested.

On POSIX platforms, this corresponds to SIGINT.

TERMINATE_REQUESTED 

Terminating the program has be requested.

On POSIX platforms, this corresponds to SIGTERM.

QUIT_REQUESTED 

Quitting the program has be requested.

On POSIX platforms, this corresponds to SIGQUIT.

Definition at line 44 of file SignalWaiter.h.

Function Documentation

RSC_EXPORT boost::uint64_t rsc::misc::currentTimeMicros ( )

Returns the current system time as microseconds.

Returns
current system time in microseconds

Definition at line 82 of file langutils.cpp.

Referenced by rsc::threading::PeriodicTask::continueExec(), and initSignalWaiter().

Here is the caller graph for this function:

RSC_EXPORT boost::uint64_t rsc::misc::currentTimeMillis ( )

Returns the current system time as milliseconds.

Returns
current system time in milliseconds

Definition at line 64 of file langutils.cpp.

Referenced by rsc::logging::ConsoleLogger::printHeader().

Here is the caller graph for this function:

void rsc::misc::handler ( int  signal)

Definition at line 48 of file MacSignalWaiter.cpp.

Referenced by initSignalWaiter().

Here is the caller graph for this function:

void rsc::misc::initSignalWaiter ( int  signals = INTERRUPT_REQUESTED | TERMINATE_REQUESTED)

Prepare waiting for signals.

The actual waiting is performed by waitForSignal.

This function be called at any time before waitForSignal, for example calling it at the very beginning of the program is fine. If such a program receives a signal early (i.e. before the waitForSignal call), the program will continue execution until waitForSignal is called and immediately continue there, for example by shutting down.

Parameters
signalsThe non-empty set of signals to wait for. Should be constructed by applying bitwise-or to elements of the Signal enumeration.
Exceptions
std::runtime_errorIf initialization fails, for example due to unavailable resources.
std::program_errorIf signals is 0, corresponding to the empty set of signals.
Author
jmoringe

Definition at line 63 of file MacSignalWaiter.cpp.

References currentTimeMicros(), handler(), INTERRUPT_REQUESTED, QUIT_REQUESTED, randAlnumStr(), TERMINATE_REQUESTED, and throwRuntimeError().

Here is the call graph for this function:

Signal rsc::misc::lastArrivedSignal ( )

Returns the last signal that has arrived at this process or Signal::NO_SIGNAL in case no signal arrived so far.

Returns
a signal to handle or Signal::NO_SIGNAL
Exceptions
std::logic_errorIf initSignalWaiter has not been called.
Author
jmoringe

Definition at line 159 of file MacSignalWaiter.cpp.

References mappedSignal().

Here is the call graph for this function:

Signal rsc::misc::mappedSignal ( )

Definition at line 109 of file MacSignalWaiter.cpp.

References INTERRUPT_REQUESTED, NO_SIGNAL, QUIT_REQUESTED, and TERMINATE_REQUESTED.

Referenced by lastArrivedSignal(), and waitForSignal().

Here is the caller graph for this function:

RSC_EXPORT std::ostream & rsc::misc::operator<< ( ostream &  stream,
const UUID id 
)

Definition at line 98 of file UUID.cpp.

RSC_EXPORT char rsc::misc::randAlnumChar ( )

Generates a random alpha-numeric character.

Returns
alpha-numeric character

Definition at line 100 of file langutils.cpp.

Referenced by randAlnumStr().

Here is the caller graph for this function:

RSC_EXPORT std::string rsc::misc::randAlnumStr ( const std::string::size_type &  length)

Generates a random alpha-numeric string with fixed length.

Parameters
lengthdesired length of the string
Returns
random string of specified length

Definition at line 108 of file langutils.cpp.

References randAlnumChar().

Referenced by initSignalWaiter().

Here is the call graph for this function:

Here is the caller graph for this function:

int rsc::misc::suggestedExitCode ( Signal  signal)

Return suggested exit code for exiting the program after receiving signal signal.

Parameters
signalThe received signal as a member of the Signal enumeration. Signal::NO_SIGNAL is not allowed.
Returns
The suggested exit code.
Author
jmoringe

Definition at line 168 of file MacSignalWaiter.cpp.

References INTERRUPT_REQUESTED, NO_SIGNAL, QUIT_REQUESTED, and TERMINATE_REQUESTED.

void rsc::misc::throwRuntimeError ( int  errorNumber,
const std::string &  description 
)

Definition at line 56 of file MacSignalWaiter.cpp.

Referenced by initSignalWaiter(), and waitForSignal().

Here is the caller graph for this function:

Signal rsc::misc::waitForSignal ( )

Block until one of the signals specified in initSignalWaiter arrives, then return the signal.

Returns
The received signal as a member of the Signal enumeration. Will not include Signal::NO_SIGNAL
Exceptions
std::logic_errorIf initSignalWaiter has not been called.
std::runtime_errorIf waiting for signals fails.
Author
jmoringe

Definition at line 128 of file MacSignalWaiter.cpp.

References mappedSignal(), and throwRuntimeError().

Here is the call graph for this function:

Variable Documentation

volatile sig_atomic_t rsc::misc::receivedSignal = 0

Definition at line 46 of file MacSignalWaiter.cpp.

int rsc::misc::requestedSignals = 0

Definition at line 43 of file MacSignalWaiter.cpp.

sem_t rsc::misc::semaphore

Definition at line 45 of file MacSignalWaiter.cpp.

std::string rsc::misc::semaphore_name
static

Definition at line 44 of file MacSignalWaiter.cpp.