BOSS 7.0.9
BESIII Offline Software System
|
Factory for Stream objects and repository of default streams. More...
#include <StreamFactory.h>
Public Types | |
typedef Stream *(* | create_stream_callback) (const std::string &, const std::string &) |
typedef std::map< std::string, create_stream_callback > | stream_factory_collection |
Public Member Functions | |
~StreamFactory () | |
Stream * | create_stream (const std::string &key) const |
create a stream from a key | |
Stream * | get_stream (severity_t s) |
get stream for severity_t | |
void | set (severity_t severity, Stream *s) |
Sets the stream for a given severity_t. | |
void | set (severity_t severity, const char *key) |
Setup a stream for a given severity_t based on a key. | |
Stream * | fatal () |
Fatal stream. | |
Stream * | error () |
Error stream. | |
Stream * | warning () |
Warning stream. | |
Stream * | debug (severity_t s) |
Debug stream for level. | |
bool | register_factory (const std::string &name, create_stream_callback callback) |
register a factory method | |
void | write_to (std::ostream &stream) const |
write content of factory to stream | |
Static Public Member Functions | |
static StreamFactory * | instance () |
return the singleton | |
static void | print_registered () |
static void | fatal (Issue *i) |
sends an issue to the fatal stream | |
static void | error (Issue *i) |
sends an issue to the error stream | |
static void | warning (Issue *i) |
sends an issue to the warning stream | |
static void | warning (const Context &c, const std::string &message) |
sends a warning message | |
static void | debug (Issue *i, severity_t) |
sends an Issue to the debug stream | |
static void | debug (const Context &c, const std::string &message, severity_t s) |
sends a debug message | |
static void | dispatch (Issue *i, bool throw_error=false) |
Sends an issue to the appropriate stream according to its severity_t. | |
static void | dispatch (Issue &i, bool throw_error=false) |
static void | set_stream (severity_t, const std::string &key) |
Protected Member Functions | |
StreamFactory () | |
StreamFactory (const StreamFactory &other) | |
Stream * | create_stream (severity_t s) |
create a stream for severity_t | |
Static Protected Member Functions | |
static const char * | key_for_severity (severity_t s) |
finds key for severity_t | |
static Stream * | get_default_stream (severity_t s) |
builds default stream for severity_t | |
Protected Attributes | |
Stream * | m_streams [severity_max] |
array of pointers to streams per severity_t | |
stream_factory_collection | m_factories |
collection of factories to build streams | |
Static Protected Attributes | |
static StreamFactory * | s_instance = 0 |
singleton instance | |
static const char * | DEFAULT_STREAMS [] |
keys for default streams | |
Factory for Stream objects and repository of default streams.
The StreamFactory
class is responsible for creating and handling all the ers stream used by the system. It implements the singleton pattern and the factory pattern. There should normally only be one instance of this class per process at any time, each instance handles a table of the different stream attached to each severity. When issues occurs, they can be dispatched using this instance. In general, the following method should be used to dispatch issues
dispatch
if the severity_t of the issue is set correctly. fatal
, error
, warning
, debug
for setting the severity_t and dispatch. The default stream are set up in the following way:
file
protocol, or a keyword that identifies a different type of protocol followed by a colon. file:/tmp/out.xml
represents a stream that writes issues into file /tmp/out.xml
in the XML format. cerr:tab
represents a stream that writes in tabulated format on the standard output. DEFAULT_STREAMS
. The content is a key with the format described above.y set
, either by specifying the stream directly, or by providing a key. Different packages offer different stream implementations. To use a specific stream type, the relevant library needs to be linked in. If the key for a type of stream that is not available is used, the system will revert to the default stream.
Supported Keys - ERS package
The ERS package supports by default the following keys:
null:
issues are discarded default:
issues are displayed on standard error stream fifo:
writes into a FIFO stream, to be actually used the issues need to be read by another entity filter:
filter stream, the Issues are filtered and if the filter accept them, passed on to another stream (specified by another key in the stream description). Supported Keys - System package:
The System package supports the following keys:
Supported Keys - ers-ipc package:
The ersipc package supports the following keys:
In order to add new stream implementations, one needs to register a factory function of type create_stream_callback
. This method takes two parameters, a protocol parameter, and an uri parameter, that basically contains everything except the protocol part of the key. If the implementation can offer a stream that corresponds to the key it should return a heap allocated stream, if not it should return a null pointer. This method should be registered using the register_factory
method on the default instance.
Macros
This file also defines a set of macros that send messages to the relevant streams in the factory. Those macros are intendred for logging out debug messages. They can compiled out by the way of the DEBUG_LEVEL
macro. This macro should be defined with an integer level. A debugging macro is disabled if its number is higher than the value of DEBUG_LEVEL
. For instance if DEBUG_LEVEL=2 then ERS_DEBUG_3 is compiled out. ERS_DEBUG_0 is never compiled out. If no debug level is specified, level 3 (maximum) is assumed. If the macro ERS_FAST_DEBUG is defined then ERS_DEBUG_0 macro directly maps to a fprintf statement on stderr.
Definition at line 119 of file StreamFactory.h.
typedef Stream *(* ers::StreamFactory::create_stream_callback) (const std::string &, const std::string &) |
Definition at line 122 of file StreamFactory.h.
typedef std::map<std::string, create_stream_callback> ers::StreamFactory::stream_factory_collection |
Definition at line 123 of file StreamFactory.h.
|
protected |
Constructor - should never be called by user code, use the instance()
method instead
Definition at line 43 of file StreamFactory.cxx.
|
protected |
Copy constructor - disabled, use the instance()
method instead
ers::NotImplemented | in all cases |
Definition at line 55 of file StreamFactory.cxx.
ers::StreamFactory::~StreamFactory | ( | ) |
Destructor - basic cleanup
Definition at line 64 of file StreamFactory.cxx.
ers::Stream * ers::StreamFactory::create_stream | ( | const std::string & | key | ) | const |
create a stream from a key
Builds a stream from a textual key The key should have the format protocol:path.extension
In certain cases, the path will be empty. For instance to write in XML format to the error stream, the key is: cerr:
.xml
key | the textual key |
Definition at line 143 of file StreamFactory.cxx.
|
protected |
create a stream for severity_t
Builds a stream for a given severity. The actual key for the severity_t is found using key_for_severity
, then the appropriate stream is constructred using create_stream
s | the severity_t of the requested stream |
Definition at line 176 of file StreamFactory.cxx.
Referenced by ers::FilterStream::factory().
|
static |
sends a debug message
Sends a message to the debug stream
c | the Context of the message |
message | the text of the message |
s | the severity_t of the associated stream. Accepted values:
|
Definition at line 231 of file StreamFactory.cxx.
|
static |
sends an Issue to the debug stream
Sends an issue to the debug stream
issue_ptr | the Issue to send |
s | the severity_t of the associated stream. Accepted values:
|
Definition at line 218 of file StreamFactory.cxx.
ers::Stream * ers::StreamFactory::debug | ( | severity_t | s | ) |
Debug stream for level.
Finds the debug stream
s | the severity_t of the associated stream. Accepted values:
|
Definition at line 347 of file StreamFactory.cxx.
Definition at line 264 of file StreamFactory.cxx.
Sends an issue to the appropriate stream according to its severity_t.
Dispatches an issue to the appropriate stream. The stream is decided based upon the severity_t specified in the Issue. If throw_error
is true errors and fatal errors are not sent to a stream, but thrown in the context of the caller.
issue_ptr | the Issue to dispatch |
throw_error | should errors and fatals are thrown |
Definition at line 254 of file StreamFactory.cxx.
Referenced by main().
ers::Stream * ers::StreamFactory::error | ( | ) |
|
static |
sends an issue to the error stream
Sends an Issue to the error stream
issue_ptr |
Definition at line 196 of file StreamFactory.cxx.
ers::Stream * ers::StreamFactory::fatal | ( | ) |
|
static |
sends an issue to the fatal stream
Sends an Issue to the fatal error stream
issue_ptr |
Definition at line 186 of file StreamFactory.cxx.
|
staticprotected |
builds default stream for severity_t
Finds the default stream for a given severity. The stream is searched in the default instance
s | the severity_t |
Definition at line 104 of file StreamFactory.cxx.
ers::Stream * ers::StreamFactory::get_stream | ( | severity_t | s | ) |
get stream for severity_t
Gets stream for severity_t
s | the severity_t of the requested stream |
Definition at line 283 of file StreamFactory.cxx.
|
static |
return the singleton
This method returns the singleton instance. It should be used for every operation on the factory.
Definition at line 80 of file StreamFactory.cxx.
Referenced by ers::FilterStream::factory().
|
staticprotected |
finds key for severity_t
Searches for the textual key for a given severity. This key is first searched in the environnement variables, if this fails, the default values are loaded. The environnement variable should have the same name than the severity with the prefix ERS_ in front. The whole name should be in uppercases. For instance for severity_t warning, the environnement variable should be ERS_WARNING
.
s | the severity_t |
Definition at line 119 of file StreamFactory.cxx.
|
static |
Dumps all registered types of streams
Definition at line 89 of file StreamFactory.cxx.
bool ers::StreamFactory::register_factory | ( | const std::string & | name, |
create_stream_callback | callback | ||
) |
register a factory method
Registers a factory function with the stream factory. The callback is function that takes two parameters
file
The function should return a heap allocated stream, or null if it does not understand the protocol.
name | name of the stream type (human display only). |
callback | the callback function |
true
if the registration was sucessfull Definition at line 367 of file StreamFactory.cxx.
void ers::StreamFactory::set | ( | severity_t | severity, |
const char * | key | ||
) |
Setup a stream for a given severity_t based on a key.
Builds a stream using a string key and sets it up for a given severity
severity_t | severity_t of the stream Accepted values:
|
key | the key used to build the new stream |
Definition at line 316 of file StreamFactory.cxx.
void ers::StreamFactory::set | ( | severity_t | severity, |
Stream * | s | ||
) |
Sets the stream for a given severity_t.
Sets the stream for a given severity_t
severity_t | severity_t of the stream Accepted values:
|
s | the new stream |
Definition at line 299 of file StreamFactory.cxx.
|
static |
Definition at line 269 of file StreamFactory.cxx.
Referenced by main(), and massive_test().
ers::Stream * ers::StreamFactory::warning | ( | ) |
Warning stream.
Definition at line 338 of file StreamFactory.cxx.
Referenced by main().
|
static |
sends a warning message
Sends a message to the warning stream
c | the context of the message |
message | the message to send |
Definition at line 241 of file StreamFactory.cxx.
|
static |
sends an issue to the warning stream
Sends an Issue to the warning stream
issue_ptr | the issue to send |
Definition at line 206 of file StreamFactory.cxx.
void ers::StreamFactory::write_to | ( | std::ostream & | stream | ) | const |
write content of factory to stream
Writes a description of the factory to a stream. This method gives a list of all registered stream types.
stream | the stream to write into |
Definition at line 378 of file StreamFactory.cxx.
|
staticprotected |
keys for default streams
This variable contains the default keys for building the default streams. The default is to use the default stream, in verbose mode for errors and fatals.
Definition at line 126 of file StreamFactory.h.
|
protected |
collection of factories to build streams
Definition at line 134 of file StreamFactory.h.
|
protected |
array of pointers to streams per severity_t
Definition at line 133 of file StreamFactory.h.
Referenced by StreamFactory().
|
staticprotected |
singleton instance
Pointer to the singleton instance
Definition at line 125 of file StreamFactory.h.