Main Page | Modules | Namespace List | Class Hierarchy | Alphabetical List | Class List | File List | Namespace Members | Class Members | File Members | Related Pages

MNMsg.h

Go to the documentation of this file.
00001 /* Copyright (C) 2000 KOM/Darmstadt University of Technology 00002 * 00003 * You are allowed to use all other parts of the code under the following terms: 00004 * 00005 * For non-commercial use, code may be used in unmodified form provided 00006 * that this copyright notice and this permission notice appear in 00007 * supporting documentation. 00008 * 00009 * This software is provided "as is" and without any express or implied 00010 * warranties, including, without limitation, the implied warranty of 00011 * fitness for a particular purpose. 00012 * 00013 * The code may be subjected to the GNU General Public License, Version 2, 00014 * and re-distributed under the terms of this license. 00015 * As a special exception, permission is granted to link this code 00016 * with the Qt library and distribute executables, as long as you 00017 * follow the requirements of the GNU GPL in regard to all of the 00018 * software in the executable aside from Qt. 00019 * 00020 * Commercial use other than under the terms of the GNU General Public 00021 * License is allowed only after express negotiation of conditions 00022 * with the authors. 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 ( ); // calls errNo(errno) 00070 static const char* errNo ( int r ); // return strings for many errno values 00071 static const char* herrNo ( int r ); // return strings for many herrno values 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 /* MN_OSS_MSG_H */ 00128

Generated on Sun Mar 6 13:35:49 2005 for Komssys by doxygen 1.3.8