# PrettyDebug.hh

Go to the documentation of this file.

    00001 // ----------------------------------------------------------------------------
    00002 // CERTI - HLA RunTime Infrastructure
    00003 // Copyright (C) 2002, 2003  ONERA
    00004 //
    00005 // This file is part of CERTI-libCERTI
    00006 //
    00007 // CERTI-libCERTI is free software ; you can redistribute it and/or
    00008 // modify it under the terms of the GNU Lesser General Public License
    00009 // as published by the Free Software Foundation ; either version 2 of
    00010 // the License, or (at your option) any later version.
    00011 //
    00012 // CERTI-libCERTI is distributed in the hope that it will be useful, but
    00013 // WITHOUT ANY WARRANTY ; without even the implied warranty of
    00014 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
    00015 // Lesser General Public License for more details.
    00016 //
    00017 // You should have received a copy of the GNU Lesser General Public
    00018 // License along with this program ; if not, write to the Free Software
    00019 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
    00020 // USA
    00021 //
    00022 // $Id: PrettyDebug.hh,v 4.5 2009/04/02 19:58:07 erk Exp $
    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 // Pretty Debug Basic types
    00039 typedef unsigned TDebugLevel;
    00040
    00041
    00042 // Pretty Debug Constants
    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 // The following keys are used in the environment variable to enable
    00067 // debug level.  For example, if ENVVAR=D:C, the pdDebug and the pdCom
    00068 // debug level are enabled, and all others are not enabled.
    00069
    00070 // KEEP THE SAME ORDER AS IN THE pdDebugLevel ENUM!
    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     // Parse the environment variable value to find debug keys and
    00106     // enable debug levels
    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) //Inline method
    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 // Alias
    00142 typedef PrettyDebug pdCDebug ;
    00143
    00144 #endif // PRETTYDEBUG_HH
    00145
    00146 // $Id: PrettyDebug.hh,v 4.5 2009/04/02 19:58:07 erk Exp $