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
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
00047
00048
00049
00050
00051
00052
00053
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
00112
00113
00114
00115 extern char * ColCOWSExceptionKindName[];
00116
00117
00118 enum ColCOWSExceptionKind { cstGenericalException,
00119 cstCorbaException,
00120 cstNotReadyException,
00121 cstBadAssertException
00122 };
00123
00124
00125
00126
00127
00128
00129
00130
00131
00132
00133
00134
00135
00136
00137
00138 class ColCOWSException {
00139 friend std::ostream& operator <<(std::ostream& stream, const ColCOWSException& e);
00140
00141 public:
00142
00143
00144 ColCOWSException(ColCOWSExceptionKind kind, const char* info, const char* file, long int line) :
00145 _kind(kind), _info(info), _file(file), _line(line) { }
00146
00147
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
00152 virtual ~ColCOWSException(){}
00153
00154
00155 ColCOWSException( CorbaException & e );
00156
00157
00158 void forwardCorbaException();
00159
00160 private:
00161
00162
00163 ColCOWSExceptionKind _kind;
00164
00165
00166 std::string _info;
00167
00168
00169 std::string _file;
00170
00171
00172 long int _line;
00173
00174 };
00175
00176
00177
00178
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__