MNMsg.h
Go to the documentation of this file.00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
#ifndef MN_OSS_MSG_H
00025
#define MN_OSS_MSG_H
00026
00027
#include <config.h>
00028
00029
#include <stdio.h>
00030
#include <errno.h>
00031
00032
#include "mnstream.h"
00033
00034
using std::string;
00035
00036
#define EDLLLOAD 101
00037
#define EDLLUNLOAD 102
00038
#define EDEVFAIL 103
00039
00040
#define MN_LV_INFO 0x00000001
00041
#define MN_LV_WARN 0x00000010
00042
#define MN_LV_ERROR 0x00000100
00043
00044
class MNMutex;
00045
00046 class MNMessage
00047 {
00048
static bool _first_time;
00049
static MNMutex* _coutMutex;
00050
static MNMutex* _cerrMutex;
00051
00052
static void init ( );
00053
00054
static void prt(
const char* txt,
const char* file,
int line,
ostrstream& x );
00055
00056
public:
00057
MNMessage ( );
00058
~MNMessage ( );
00059
00060
static ostream&
out ( );
00061
static ostream&
in ( );
00062
static void info (
const char* file,
int line,
ostrstream& x );
00063
static void err (
const char* file,
int line,
ostrstream& x );
00064
static void warn (
const char* file,
int line,
ostrstream& x );
00065
static void fatal (
const char* file,
int line,
ostrstream& x );
00066
00067
static void std_err (
const char* file,
int line,
int errnum,
ostrstream& x );
00068
00069
static const char*
errNo ( );
00070
static const char*
errNo (
int r );
00071
static const char*
herrNo (
int r );
00072
00073
static bool atLevel(
long module,
int level );
00074
00075
static long level_from_config(
const char* modulename );
00076 };
00077
00078
#define MN_UNCONDITIONAL_MSG(a,what) \
00079
do { \
00080
ostrstream mn_msg_x; \
00081
mn_msg_x << a << ends; \
00082
MNMessage::what (__FILE__,__LINE__, mn_msg_x); \
00083
UNFREEZE(mn_msg_x) \
00084
} while(0)
00085
00086
#define MN_CONDITIONAL_MSG(a,printit,what) \
00087
do { \
00088
if ( printit ) { \
00089
ostrstream mn_msg_x; \
00090
mn_msg_x << a << ends; \
00091
MNMessage::what (__FILE__,__LINE__, mn_msg_x); \
00092
UNFREEZE(mn_msg_x) \
00093
} \
00094
} while(0)
00095
00096
#ifndef NDEBUG
00097
#define MN_INFO(msg) MN_CONDITIONAL_MSG( \
00098
msg, \
00099
mnmsg_fit(MN_LV_INFO), \
00100
info)
00101
#else
00102
#define MN_INFO(msg)
00103
#endif
00104
00105
#define MN_WARN(msg) MN_CONDITIONAL_MSG( \
00106
msg, \
00107
mnmsg_fit(MN_LV_WARN), \
00108
warn)
00109
#define MN_ERROR(msg) MN_CONDITIONAL_MSG( \
00110
msg, \
00111
mnmsg_fit(MN_LV_ERROR), \
00112
err)
00113
#define MN_FATAL(msg) MN_UNCONDITIONAL_MSG(msg,fatal)
00114
00115
#define MNMSG_USE(name) \
00116
static bool mnmsg_first_fit = true; \
00117
static long mnmsg_module_level = 0; \
00118
\
00119
static inline bool mnmsg_fit( int level ) { \
00120
if ( ::mnmsg_first_fit ) { \
00121
::mnmsg_first_fit = false; \
00122
::mnmsg_module_level = MNMessage::level_from_config(name); \
00123
} \
00124
return ( ::mnmsg_module_level & level ); \
00125
}
00126
00127
#endif
00128
Generated on Sun Mar 6 13:35:49 2005 for Komssys by
1.3.8