|
int | code () |
| Returns the event code. More...
|
|
string | codemsg () |
| Return the code and the message, formatted as MCS_PRE CODE MESSAGE. More...
|
|
| Event (string atFile, unsigned int atLine, RetValue type, int code, string s1="", string s2="", string s3="") |
| Constructor with three optional strings. More...
|
|
| Event (string atFile, unsigned int atLine, RetValue type, int code, string s1, int i1) |
| Constructor with a string and an integer. More...
|
|
| Event (string atFile, unsigned int atLine, RetValue type, int code, int i1, string s1="") |
| Constructor with an integer and a string. More...
|
|
| Event (string atFile, unsigned int atLine, RetValue type, int code, int i1, int i2) |
| Constructor with two integers. More...
|
|
string | file () |
| Source file name where the event occurred. More...
|
|
unsigned int | line () |
| Source line number where the event occurred. More...
|
|
string | msg () |
| Returns the message. More...
|
|
int | subcode () |
| Return event subcode. More...
|
|
Event & | subcode (int subcode) |
| Set a subcode and return a reference to the object itself. More...
|
|
RetValue | type () |
| Return the event type. More...
|
|
string | where () |
| Returns the place where the error occurred formatted as FILE:LINE (CODE). More...
|
|
| ~Event () |
| Destructor. More...
|
|
Hold informations about an event.
An event occur in two cases:
- when we want to log informations about something happened, for example a new user connected, a request made by users, etc...;
- an error occur and an exception must be thrown.
An Event object contains several informations about the event itself:
- the source file and line at which the event occurred;
- an event code, that is a numeric code which identify the event;
- an event subcode, which is usually the return value of an external library function;
- an event type, which says if the event is just a message or an error (see the RetValue enumeration);
- a descriptive message.
To create an Event object you should provide all these informations (source file name, source file line, event type and event code) using one of the constructors. You cannot specify the descriptive message directly in the constructor, instead there must be an entry in the Event.vmsg static array, whose index is given by the event code, which contain the message and eventually some "printf" format specifier to add information to the message. These extra information can be passed in the constructors, this is the reason why all constructors have the same first four parameters while the other changes, so that the Event class can be easily used in all situations.
The Event.vmsg array is static, and contains all MCS predefined messages. It must be initialized calling the init() method (actually called by the constructor). The event codes for the MCS messages are defined as symbols with the "MSG_" prefix.
To use this class with new user-defined messages you should follow this rule:
- define new numeric symbols for any of your messages, starting from (MCS_LAST_MESSAGE_CODE + 1) for messages, from (MCS_LAST_ERROR_CODE + 1) for errors;
- after you istantiated the MCS server, set the correct values in the Event.vmsg array so that it points to your message descriptions;
An example follows:
#define MY_MESSAGE MCS_LAST_MESSAGE_CODE + 1
#define MY_ERROR MCS_LAST_ERROR_CODE + 1
.....
vmsg[MY_MESSAGE] =
"My message: %s";
vmsg[MY_ERROR ] =
"My error message: %s";
}
.....
mcs::Event::custom_init_vmsg = &initialize_messages;
Note that for any event there must be a numeric code identifier and a message in the corresponding position in the Event.vmsg array.
The Event class has all private fields, so once you created the object you can't modify its content.
Note that in the constructors parameter list there are always the arguments (atFile, atLine, type), in this order. You can avoid specifying any of these values using one of the MCS_OK, MCS_WARN, MCS_ERROR, MCS_FATAL or MCS_ macros.
Definition at line 814 of file mcs.hh.