RSC  0.12.1
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
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...
 
template<class R >
class DEPRECATED_CLASS ("If possible, use rsc::patterns::Factory instead") Registry
 A templatized global registry. More...
 
 DEPRECATED_MSG (void addRegistree(R *r, const std::string &errorDescription=""),"If possible, use rsc::patterns::Factory instead")
 Registers a new registree in the Registry. More...
 
 DEPRECATED_MSG (boost::shared_ptr< R > getRegistree(const std::string &key),"If possible, use rsc::patterns::Factory instead")
 Returns the registree for the provided key. More...
 
 DEPRECATED_MSG (std::set< std::string > getKnownRegistryKeys(),"If possible, use rsc::patterns::Factory instead")
 Returns a set with all known registree keys. More...
 
 DEPRECATED_MSG (bool removeRegistree(const std::string &name),"If possible, use rsc::patterns::Factory instead")
 Removes a registree from this registry. More...
 
 DEPRECATED_MSG (boost::recursive_mutex *getMutex(),"If possible, use rsc::patterns::Factory instead")
 Returns a recursive mutex that can be used to make multiple operations on this class atomic. 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
 
boost::recursive_mutex mutex
 
std::map< std::string,
boost::shared_ptr< R > > 
registreesByName
 

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:

template<class R >
class rsc::misc::DEPRECATED_CLASS ( "If  possible,
use rsc::patterns::Factory instead"   
)

A templatized global registry.

To create a registree, that will be registered on application startup before main use the provided macros. This will work on every supported compiler.

This class is reentrant.

Author
jwienke
Template Parameters
Rtype to register called registree.
Deprecated:
If possible, use rsc::patterns::Factory instead.

Definition at line 62 of file Registry.h.

rsc::misc::DEPRECATED_MSG ( void   addRegistreeR *r, const std::string &errorDescription="",
"If  possible,
use rsc::patterns::Factory instead"   
)

Registers a new registree in the Registry.

This class takes over the ownership of the pointer and manages deleting the pointer when needed.

Parameters
rnew registree to register
errorDescriptionoptional string to add to the message of the exception which is raised when a registree with a same key already exists.
Exceptions
std::invalid_argumentif a registree with the same key is already registered. In this case r is not owned by this registry

Definition at line 80 of file Registry.h.

References mutex, and registreesByName.

rsc::misc::DEPRECATED_MSG ( boost::shared_ptr< R >   getRegistreeconst std::string &key,
"If  possible,
use rsc::patterns::Factory instead"   
)

Returns the registree for the provided key.

Parameters
keykey of the registree
Returns
registree
Exceptions
std::invalid_argumentif there is no registree with this name

Definition at line 102 of file Registry.h.

References mutex, and registreesByName.

rsc::misc::DEPRECATED_MSG ( std::set< std::string >   getKnownRegistryKeys(),
"If  possible,
use rsc::patterns::Factory instead"   
)

Returns a set with all known registree keys.

Returns
all known registree keys

Definition at line 123 of file Registry.h.

References mutex, and registreesByName.

rsc::misc::DEPRECATED_MSG ( bool   removeRegistreeconst std::string &name,
"If  possible,
use rsc::patterns::Factory instead"   
)

Removes a registree from this registry.

Use this with caution as many clients will assume that system configuration knowledge is static!

Parameters
namename of the registree to remove
Returns
true if a registree was removed, else false

Definition at line 145 of file Registry.h.

References mutex, and registreesByName.

rsc::misc::DEPRECATED_MSG ( boost::recursive_mutex *  getMutex(),
"If  possible,
use rsc::patterns::Factory instead"   
)

Returns a recursive mutex that can be used to make multiple operations on this class atomic.

Returns
mutex internally used by this class

Definition at line 157 of file Registry.h.

References mutex.

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

Definition at line 48 of file MacSignalWaiter.cpp.

References receivedSignal, and semaphore.

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(), requestedSignals, semaphore, semaphore_name, 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(), and requestedSignals.

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, receivedSignal, 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(), receivedSignal, requestedSignals, semaphore, semaphore_name, 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.

Referenced by handler(), mappedSignal(), and waitForSignal().

std::map<std::string, boost::shared_ptr<R> > rsc::misc::registreesByName

Definition at line 165 of file Registry.h.

Referenced by DEPRECATED_MSG().

int rsc::misc::requestedSignals = 0

Definition at line 43 of file MacSignalWaiter.cpp.

Referenced by initSignalWaiter(), lastArrivedSignal(), and waitForSignal().

sem_t rsc::misc::semaphore

Definition at line 45 of file MacSignalWaiter.cpp.

Referenced by handler(), initSignalWaiter(), and waitForSignal().

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

Definition at line 44 of file MacSignalWaiter.cpp.

Referenced by initSignalWaiter(), and waitForSignal().