mcs::Event Class Reference

#include <mcs.hh>

List of all members.


Detailed Description

Hold informations about an event.

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.
Eventsubcode (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

Constructor & Destructor Documentation

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.

Parameters:
atFile Source file at which the event occurred;
atLine Source file line at which the event occurred;
type Event type;
code Event code;
s1 Optional first string to write in the message;
s2 Optional second string to write in the message;
s3 Optional third string to write in the message;

Definition at line 53 of file Event.cc.

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.

See also:
Event(string, unsigned int, RetValue, int, string, string, string).

Definition at line 61 of file Event.cc.

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.

See also:
Event(string, unsigned int, RetValue, int, string, string, string).

Definition at line 70 of file Event.cc.

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.

See also:
Event(string, unsigned int, RetValue, int, string, string, string).

Definition at line 78 of file Event.cc.

mcs::Event::~Event (  ) 

Destructor.

Definition at line 89 of file Event.cc.


Member Function Documentation

int mcs::Event::code (  ) 

Returns the event code.

Definition at line 92 of file Event.cc.

string mcs::Event::codemsg (  ) 

Return the code and the message, formatted as MCS_PRE CODE MESSAGE.

Definition at line 136 of file Event.cc.

string mcs::Event::file (  ) 

Source file name where the event occurred.

Definition at line 124 of file Event.cc.

void mcs::Event::init_vmsg (  )  [static, private]

Initialize the vmsg array.

Definition at line 23 of file mcsmsg.cc.

unsigned int mcs::Event::line (  ) 

Source line number where the event occurred.

Definition at line 130 of file Event.cc.

string mcs::Event::msg (  ) 

Returns the message.

Definition at line 104 of file Event.cc.

string mcs::Event::static_vmsg ( unsigned int  i  )  [static]

Return the msg in the i-th position of the vmsg array.

Definition at line 156 of file Event.cc.

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:

    Event e(__FILE__, __LINE__, ERROR, MSG_***, a, b, c,);
    e.subcode(sub);
    throw e;

This method solve the problem returning a reference to the object itself:

    throw MCS_ERROR(MSG_***, a, b, c).subcode(sub);

Definition at line 150 of file Event.cc.

int mcs::Event::subcode (  ) 

Return event subcode.

Definition at line 145 of file Event.cc.

RetValue mcs::Event::type (  ) 

Return the event type.

Definition at line 99 of file Event.cc.

string mcs::Event::where (  ) 

Returns the place where the error occurred formatted as FILE:LINE (CODE).

Definition at line 110 of file Event.cc.


Member Data Documentation

char mcs::Event::buf[1024] [private]

Temporary buffer.

Definition at line 865 of file mcs.hh.

void(* mcs::Event::custom_init_vmsg)(const char *vmsg[1000]) = NULL [static]

Pointer to a callback function to initialize custom messages in the vmsg static array.

Definition at line 170 of file Event.cc.

bool mcs::Event::flInitialized = false [static, private]

Flag to tell if the init() method has been already called.

Definition at line 888 of file mcs.hh.

string mcs::Event::latFile [private]

Source file.

Definition at line 859 of file mcs.hh.

int mcs::Event::latLine [private]

Line number.

Definition at line 862 of file mcs.hh.

int mcs::Event::lcode [private]

Event code;.

Definition at line 871 of file mcs.hh.

string mcs::Event::lmsg [private]

Message.

Definition at line 868 of file mcs.hh.

int mcs::Event::lsubcode [private]

Event subcode, usually an external library message code;.

Definition at line 874 of file mcs.hh.

RetValue mcs::Event::ltype [private]

Event type.

Definition at line 877 of file mcs.hh.

const char * mcs::Event::vmsg [static, private]

Static array of descriptive messages.

Definition at line 882 of file mcs.hh.


The documentation for this class was generated from the following files:
mcslogo

MCS (My Customizable Server) ver. 0.3.3-alpha3
Documentation generated on Thu Mar 22 13:22:23 UTC 2012