#include <mcs.hh>
An event occur in two cases:
An Event object contains several informations about the event itself:
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:
An example follows:
#define MY_MESSAGE MCS_LAST_MESSAGE_CODE + 1 #define MY_ERROR MCS_LAST_ERROR_CODE + 1 ..... void initialize_messages(char* vmsg[MCS_VMSG_SIZE]) { 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 855 of file mcs.hh.
Public Member Functions | |
int | code () |
Returns the event code. | |
string | codemsg () |
Return the code and the message, formatted as MCS_PRE CODE MESSAGE. | |
Event (string atFile, unsigned int atLine, RetValue type, int code, int i1, int i2) | |
Constructor with two integers. | |
Event (string atFile, unsigned int atLine, RetValue type, int code, int i1, string s1="") | |
Constructor with an integer and a string. | |
Event (string atFile, unsigned int atLine, RetValue type, int code, string s1, int i1) | |
Constructor with a string and an integer. | |
Event (string atFile, unsigned int atLine, RetValue type, int code, string s1="", string s2="", string s3="") | |
Constructor with three optional strings. | |
string | file () |
Source file name where the event occurred. | |
unsigned int | line () |
Source line number where the event occurred. | |
string | msg () |
Returns the message. | |
Event & | subcode (int subcode) |
Set a subcode and return a reference to the object itself. | |
int | subcode () |
Return event subcode. | |
RetValue | type () |
Return the event type. | |
string | where () |
Returns the place where the error occurred formatted as FILE:LINE (CODE). | |
~Event () | |
Destructor. | |
Static Public Member Functions | |
static string | static_vmsg (unsigned int i) |
Return the msg in the i-th position of the vmsg array. | |
Static Public Attributes | |
static void(* | custom_init_vmsg )(const char *vmsg[1000]) = NULL |
Pointer to a callback function to initialize custom messages in the vmsg static array. | |
Private Member Functions | |
void | init (string atFile, unsigned int atLine, RetValue type, int code) |
Static Private Member Functions | |
static void | init_vmsg () |
Initialize the vmsg array. | |
Private Attributes | |
char | buf [1024] |
Temporary buffer. | |
string | latFile |
Source file. | |
int | latLine |
Line number. | |
int | lcode |
Event code;. | |
string | lmsg |
Message. | |
int | lsubcode |
Event subcode, usually an external library message code;. | |
RetValue | ltype |
Event type. | |
Static Private Attributes | |
static bool | flInitialized = false |
Flag to tell if the init() method has been already called. | |
static const char * | vmsg [1000] |
Static array of descriptive messages. | |
Friends | |
class | UserThread |
mcs::Event::Event | ( | string | atFile, | |
unsigned int | atLine, | |||
RetValue | type, | |||
int | code, | |||
string | s1 = "" , |
|||
string | s2 = "" , |
|||
string | s3 = "" | |||
) |
Constructor with three optional strings.
This constructor set the subcode to zero.
mcs::Event::Event | ( | string | atFile, | |
unsigned int | atLine, | |||
RetValue | type, | |||
int | code, | |||
string | s1, | |||
int | i1 | |||
) |
Constructor with a string and an integer.
This constructor set the subcode equal to the second parameter.
mcs::Event::Event | ( | string | atFile, | |
unsigned int | atLine, | |||
RetValue | type, | |||
int | code, | |||
int | i1, | |||
string | s1 = "" | |||
) |
Constructor with an integer and a string.
This constructor set the subcode to zero.
mcs::Event::Event | ( | string | atFile, | |
unsigned int | atLine, | |||
RetValue | type, | |||
int | code, | |||
int | i1, | |||
int | i2 | |||
) |
Constructor with two integers.
This constructor set the subcode equal to the second parameter.
string mcs::Event::codemsg | ( | ) |
string mcs::Event::file | ( | ) |
void mcs::Event::init_vmsg | ( | ) | [static, private] |
unsigned int mcs::Event::line | ( | ) |
string mcs::Event::static_vmsg | ( | unsigned int | i | ) | [static] |
Event & mcs::Event::subcode | ( | int | subcode | ) |
Set a subcode and return a reference to the object itself.
In the Event class constructor there's no way to distinguish a parameter from the variable list from an optional subcode, so we couldn't insert the "subcode" parameter in the constructor. But this way throwing an exception with a subcode require the following code:
This method solve the problem returning a reference to the object itself:
throw MCS_ERROR(MSG_***, a, b, c).subcode(sub);
string mcs::Event::where | ( | ) |
char mcs::Event::buf[1024] [private] |
void(* mcs::Event::custom_init_vmsg)(const char *vmsg[1000]) = NULL [static] |
bool mcs::Event::flInitialized = false [static, private] |
string mcs::Event::latFile [private] |
int mcs::Event::latLine [private] |
int mcs::Event::lcode [private] |
string mcs::Event::lmsg [private] |
int mcs::Event::lsubcode [private] |
RetValue mcs::Event::ltype [private] |
const char * mcs::Event::vmsg [static, private] |
![]() |
MCS (My Customizable Server) ver. 0.3.3-alpha3
|