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

ColCOWS_Debug.hh

00001 //===========================================================================//
00002 //    
00003 //    Description: Debug output Management
00004 //    Filename: colcows/ColCOWS_Debug.hh
00005 //    Authors: Michael Dussere and Aurélien Esnard
00006 //    
00007 //===========================================================================//
00008 //    
00009 //    Copyright (C) 2003 INRIA and CNRS
00010 //    
00011 //    This library is free software; you can redistribute it and/or
00012 //    modify it under the terms of the GNU Lesser General Public
00013 //    License as published by the Free Software Foundation; either
00014 //    version 2.1 of the License, or (at your option) any later version.
00015 //    
00016 //    This library is distributed in the hope that it will be useful,
00017 //    but WITHOUT ANY WARRANTY; without even the implied warranty of
00018 //    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00019 //    Lesser General Public License for more details.
00020 //    
00021 //    You should have received a copy of the GNU Lesser General Public
00022 //    License along with this library; if not, write to the Free Software
00023 //    Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
00024 //    
00025 //===========================================================================//
00026 
00027 
00028 #ifndef __COLCOWS_DEBUG_HH__
00029 #define __COLCOWS_DEBUG_HH__
00030 
00031 //---------------------------------------------------------------------------//
00032 #include "ColCOWS_Include.hh"
00033 //---------------------------------------------------------------------------//
00034 
00035 namespace ColCOWS {
00036   struct CorbaException;
00037 }
00038 
00039 __COLCOWS_BEGIN__
00040 
00041 extern bool _DebugInitialized;
00042 extern int  _DebugTraceLevel;
00043 
00044 
00045 //------------------------------------------------------------------------
00046 // Debug Mode
00047 // 
00048 // Le principe du level de debug est de renvoyer des sorties de manière 
00049 // conditionnée suivant le niveau choisi par l'utilisateur.
00050 //
00051 //------------------------------------------------------------------------
00052 
00053 //! debug level
00054 enum DebugLevel {   
00055   dbl0           = 0,
00056   dblForce       = 0,
00057   dblError       = 0,
00058   dbl1           = 1,
00059   dblException   = 1,
00060   dblCritical    = 1,
00061   dbl2           = 2,
00062   dblWarning     = 2,
00063   dblMajor       = 2,
00064   dbl3           = 3,
00065   dblCall        = 3,
00066   dblSecondary   = 3,
00067   dblHead        = 3,
00068   dblIn          = 3,
00069   dblOut         = 3,
00070   dbl4           = 4,
00071   dblAccessory   = 4,
00072   dblHeadDetail  = 4,
00073   dblTail        = 4,
00074   dblCallDone    = 4,
00075   dbl5           = 5,
00076   dblCallDetail  = 5,
00077   dbl6           = 6,
00078   dbl7           = 7,
00079   dbl8           = 8,
00080   dblTrace       = 8,
00081   dbl9           = 9,
00082   dblInternal    = 9,
00083   dbl10          = 10,
00084   dblTest        = 10
00085 };
00086 
00087 #define  COLCOWS_DEBUG_LEVEL_VARIABLE   "COLCOWS_DEBUG_LEVEL"
00088 #define  COLCOWS_DEBUG_LEVEL_DEFAULT    3
00089 
00090 #define COLCOWS_DEBUG_LOCATION "(" <<__FILE__ << ":" << __LINE__ << ") "
00091 #define COLCOWS_DEBUG_SPACE "\t\t"
00092 
00093 #ifdef COLCOWS_NO_DEBUG
00094 #define COLCOWS_DEBUG(l,x)   ( false )
00095 #define COLCOWS_IN_DEBUG()   ( false )
00096 #define COLCOWS_OUT_DEBUG()  ( false )
00097 #else
00098 #define COLCOWS_DEBUG(l,x)   ((_DebugTraceLevel >= l     ) && \
00099                           (std::cerr << x                  << COLCOWS_DEBUG_SPACE << COLCOWS_DEBUG_LOCATION << std::endl))
00100 #define COLCOWS_IN_DEBUG()   ((_DebugTraceLevel >= dblIn ) && \
00101                           (std::cerr << "==> " << __func__ << COLCOWS_DEBUG_SPACE << COLCOWS_DEBUG_LOCATION << std::endl))
00102 #define COLCOWS_OUT_DEBUG()  ((_DebugTraceLevel >= dblOut) && \
00103                           (std::cerr << "<== " << __func__ << COLCOWS_DEBUG_SPACE << COLCOWS_DEBUG_LOCATION << std::endl))
00104 #endif
00105 
00106 #define COLCOWS_TRACE_LOCATION ""
00107 #define COLCOWS_TRACE_SPACE ""
00108 #define COLCOWS_TRACE(x)   (std::cout << x << COLCOWS_TRACE_SPACE << COLCOWS_TRACE_LOCATION << std::endl)
00109 
00110 //------------------------------------------------------------------------
00111 // ColCOWS Exception 
00112 //------------------------------------------------------------------------
00113 
00114 //! names associated with ColCOWSExceptionKind
00115 extern char * ColCOWSExceptionKindName[];
00116 
00117 //! kind of exceptions thrown by EPSN
00118 enum ColCOWSExceptionKind { cstGenericalException, 
00119                             cstCorbaException,
00120                             cstNotReadyException,
00121                             cstBadAssertException
00122 };
00123 
00124 //    Generical,
00125 //    ActivationFailure,
00126 //    DeactivationFailure,
00127 //    ConnectiontionFailure,
00128 //    AlreadyActivated,
00129 //    NotActivated,
00130 //    ActivationTimeout,
00131 //    AlreadyConnected, 
00132 //    NotConnected,
00133 //    NotReady,
00134 //    BadAssert
00135 
00136 
00137 //! exceptions thrown by COLCOWS
00138 class ColCOWSException {
00139   friend std::ostream& operator <<(std::ostream& stream, const ColCOWSException& e);
00140 
00141 public:
00142 
00143   //! full constructor
00144   ColCOWSException(ColCOWSExceptionKind kind, const char* info, const char* file, long int line) :
00145     _kind(kind), _info(info), _file(file), _line(line) { }
00146 
00147   //! full constructor
00148   ColCOWSException(ColCOWSExceptionKind kind, const std::string & info, const std::string & file, long int line) :
00149     _kind(kind), _info(info), _file(file), _line(line) { }
00150 
00151   //! destructor
00152   virtual ~ColCOWSException(){}
00153 
00154   //! CorbaException converter constructor
00155   ColCOWSException( CorbaException & e );
00156 
00157   //! forward as CorbaException
00158   void forwardCorbaException();
00159 
00160 private:
00161 
00162   //! exception kind
00163   ColCOWSExceptionKind _kind;
00164 
00165   //! exception description and additionals
00166   std::string       _info;
00167 
00168   //! file it is thrown from
00169   std::string       _file;
00170 
00171   //! ligne it is thrown from
00172   long int          _line;
00173 
00174 };
00175 
00176 
00177 //------------------------------------------------------------------------
00178 // Error & Assert
00179 //------------------------------------------------------------------------
00180 
00181 #define THROW_CORBA_EXCEPTION( kind, info) do {                                                                           \
00182                                                 COLCOWS_DEBUG(dblError, "Throw Corba exception : " << info );             \
00183                                                 std::stringstream s_info;                                                 \
00184                                                 s_info << info ;                                                          \
00185                                                 CorbaException ex( (int)kind, s_info.str().c_str(), __FILE__, __LINE__ ); \
00186                                                 throw ex;                                                                 \
00187                                               } while(0)
00188 
00189 #define COLCOWS_ERROR(info) do {                                                                                       \
00190                               COLCOWS_DEBUG(dblError, info );                                                          \
00191                               std::stringstream s_info;                                                                \
00192                               s_info << info ;                                                                         \
00193                               ColCOWSException ex(cstGenericalException, s_info.str(), __FILE__, __LINE__ );           \
00194                               throw ex;                                                                                \
00195                             } while(0)
00196 
00197 
00198 #define COLCOWS_ASSERT(test, info) do {                                                                                \
00199                                      if (!(test)) {                                                                    \
00200                                         COLCOWS_DEBUG(dblError, info );                                                \
00201                                         std::stringstream s_info;                                                      \
00202                                         s_info << info ;                                                               \
00203                                         ColCOWSException ex(cstBadAssertException, s_info.str(), __FILE__, __LINE__ ); \
00204                                         throw ex;}                                                                     \
00205                                    } while(0)
00206 
00207 
00208 #define __BEGIN_REDIRECT_ALL_EXCEPTIONS_TO_COLCOWS__  try {
00209 
00210 #define __END_REDIRECT_ALL_EXCEPTIONS_TO_COLCOWS__        }                                                                       \
00211                                                     catch(ColCOWS::ColCOWSException & ex) {                                       \
00212                                                       COLCOWS_DEBUG(dblError,"ColCOWSException forwarded as CorbaException");     \
00213                                                       throw;                                                                      \
00214                                                     }                                                                             \
00215                                                     catch(ColCOWS::CorbaException & corba_ex) {                                   \
00216                                                       COLCOWS_DEBUG(dblError,"CorbaException forwarded");                         \
00217                                                       ColCOWSException ex(corba_ex);                                              \
00218                                                       throw ex;                                                                   \
00219                                                     }                                                                             \
00220                                                     catch(...) {                                                                  \
00221                                                       COLCOWS_DEBUG(dblError,"Unknown exception forwarded as CorbaException");    \
00222                                                       CorbaException corba_ex( (int)cstGenericalException,                        \
00223                                                                                "Unknown exception forwarded as CorbaException",   \
00224                                                                                __FILE__, __LINE__ );                              \
00225                                                       throw corba_ex;                                                             \
00226                                                     }
00227 
00228 
00229 #define __BEGIN_REDIRECT_ALL_EXCEPTIONS_TO_CORBA__  try {
00230 
00231 #define __END_REDIRECT_ALL_EXCEPTIONS_TO_CORBA__        }                                                                         \
00232                                                     catch(ColCOWS::ColCOWSException & ex) {                                       \
00233                                                       COLCOWS_DEBUG(dblError,"ColCOWSException forwarded as CorbaException");     \
00234                                                       ex.forwardCorbaException();                                                \
00235                                                     }                                                                             \
00236                                                     catch(ColCOWS::CorbaException & corba_ex) {                                   \
00237                                                       COLCOWS_DEBUG(dblError,"CorbaException forwarded");                         \
00238                                                       throw;                                                                      \
00239                                                     }                                                                             \
00240                                                     catch(...) {                                                                  \
00241                                                       COLCOWS_DEBUG(dblError,"Unknown exception forwarded as CorbaException");    \
00242                                                       CorbaException corba_ex( (int)cstGenericalException,                        \
00243                                                                                "Unknown exception forwarded as CorbaException",   \
00244                                                                                __FILE__, __LINE__ );                              \
00245                                                       throw corba_ex;                                                             \
00246                                                     }
00247 
00248 
00249 #define __BEGIN_REDIRECT_CORBA_EXCEPTIONS_TO_COLCOWS__  try {
00250 
00251 #define __END_REDIRECT_CORBA_EXCEPTIONS_TO_COLCOWS__         }                                                                      \
00252                                                         catch(ColCOWS::CorbaException & corba_ex) {                                 \
00253                                                           COLCOWS_DEBUG(dblError,"CorbaException forwarded as ColCOWSException");   \
00254                                                           ColCOWSException ex(corba_ex);                                            \
00255                                                           throw ex;                                                                 \
00256                                                         }
00257 
00258 
00259 //------------------------------------------------------------------------
00260 
00261 bool InitDebug();
00262 
00263 //------------------------------------------------------------------------
00264 
00265 __COLCOWS_END__
00266 
00267 #endif // __COLCOWS_DEBUG_HH__

Generated on Tue Jun 21 12:55:56 2005 for ColCOWS by  doxygen 1.4.1