00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025 #ifndef PRETTYDEBUG_HH
00026 #define PRETTYDEBUG_HH
00027
00028 #ifdef NO_PRETTYDEBUG
00029 #define NDEBUG
00030 #endif
00031
00032 #include "DebugOStream.hh"
00033 #include <string>
00034 #include "RTI.hh"
00035
00036 #define pdSEmptyMessage "Pretty Debug Server empty Message."
00037
00038
00039 typedef unsigned TDebugLevel;
00040
00041
00042
00043 #define pdMaxMessageSize 255 // greater then pdTooLongInitMessage length!
00044
00049 enum pdDebugLevel {pdUnused,
00050 pdAnswer,
00051 pdCom,
00052 pdDebug,
00053 pdError,
00054 pdGendoc,
00055 pdInit,
00056 pdMessage,
00057 pdProtocol,
00058 pdRegister,
00059 pdRequest,
00060 pdTerm,
00061 pdWarning,
00062 pdExcept,
00063 pdTrace,
00064 pdLast};
00066
00067
00068
00069
00070
00071 #define pdDebugKeysString ":ACDEGIMPRSTWXZ\0"
00072
00073
00074 class CERTI_EXPORT PrettyDebug {
00075
00076 public :
00077 static void setFederateName( const std::string &inName )
00078 { federateName_ = inName ; }
00079 static void setFederateName( const char *inName )
00080 { federateName_ = inName ; }
00081 protected :
00082 static std::string federateName_ ;
00083 private:
00084 char* LEnvVar;
00085 char* LMessage;
00087 char* HeaderMessage;
00089 static DebugOStream defaultOutputStream;
00090 static DebugOStream* nullOutputStreamPtr;
00091 static DebugOStream& nullOutputStream;
00092
00093 #ifdef _WIN32 //Mutex : Print Control
00094 static HANDLE g_hMutex;
00095 #endif
00096
00099 DebugOStream* Level_Map [pdLast + 1];
00100
00101 void Print(DebugOStream& theOutputStream,
00102 const char* theHeaderMessage,
00103 const char * Message);
00104
00105
00106
00107 void ParseEnvString(const char * Name);
00108
00109 public:
00110 PrettyDebug(const char * Name, const char * Header);
00111 ~PrettyDebug();
00112
00113
00114 bool Mode(pdDebugLevel Level);
00115
00116 void enableDebugLevel(pdDebugLevel Level,
00117 DebugOStream& theOutputStream = PrettyDebug::defaultOutputStream);
00118 void disableDebugLevel(pdDebugLevel Level);
00119
00120 DebugOStream& operator[](pdDebugLevel Level)
00121 {
00122 DebugOStream* theReturnedOutputStreamPtr = (Level_Map[Level]);
00123 if (theReturnedOutputStreamPtr == PrettyDebug::nullOutputStreamPtr) {
00124 return(PrettyDebug::nullOutputStream);
00125 }
00126 Print( *theReturnedOutputStreamPtr, HeaderMessage, "" );
00127 return(*theReturnedOutputStreamPtr);
00128 }
00129
00130 #ifdef NDEBUG
00131 inline void Out(pdDebugLevel Level, const char *Format, ...) {};
00132 #else
00133 void Out(pdDebugLevel Level, const char *Format, ...);
00134 void Mes(pdDebugLevel Level, const char type, const short testMess, const char *context);
00135
00136 #endif
00137
00138 };
00139
00140
00141
00142 typedef PrettyDebug pdCDebug ;
00143
00144 #endif // PRETTYDEBUG_HH
00145
00146