ML Reference
|
00001 // **InsertLicense** code 00002 //------------------------------------------------------------------------- 00004 00010 //------------------------------------------------------------------------- 00011 #ifndef __mlErrorOutput_H 00012 #define __mlErrorOutput_H 00013 00014 #ifndef __mlUtilsSystem_H 00015 #include "mlUtilsSystem.h" 00016 #endif 00017 #ifndef __mlUtilsAPI_H 00018 #include "mlUtilsAPI.h" 00019 #endif 00020 #ifndef __mlMutex_H 00021 #include "mlMutex.h" 00022 #endif 00023 00024 00025 00026 //----------------------------------------------------------------------------------- 00027 // Forward declarations. 00028 //----------------------------------------------------------------------------------- 00029 ML_UTILS_START_NAMESPACE 00030 00032 class ErrorOutput; 00033 00034 ML_UTILS_END_NAMESPACE 00035 00036 00037 ML_START_NAMESPACE 00040 class State; 00041 ML_END_NAMESPACE 00042 00043 00044 00045 //----------------------------------------------------------------------------------- 00046 // Stream output for std::ostream 00047 //----------------------------------------------------------------------------------- 00048 namespace std { 00049 00051 ML_UTILS_EXPORT ostream& operator<<(ostream& s, const ML_UTILS_NAMESPACE::ErrorOutput &errorOutput); 00052 } 00053 00054 00055 00056 00057 ML_UTILS_START_NAMESPACE 00058 00059 //--------------------------------------------------------------------------------------------- 00061 //--------------------------------------------------------------------------------------------- 00062 class ErrorOutputInfos; 00063 00064 //--------------------------------------------------------------------------------------------- 00066 //--------------------------------------------------------------------------------------------- 00067 class RuntimeType; 00068 00069 //--------------------------------------------------------------------------------------------- 00071 00094 //--------------------------------------------------------------------------------------------- 00095 class ML_UTILS_EXPORT ErrorOutput{ 00096 00097 public: 00098 00099 //--------------------------------------------------------------------------------------------- 00103 //--------------------------------------------------------------------------------------------- 00104 typedef void ErrorOutputCB(void *usrData, 00105 const char* errStr, 00106 const ErrorOutputInfos &infos); 00107 00108 //--------------------------------------------------------------------------------------------- 00122 //--------------------------------------------------------------------------------------------- 00123 typedef char *DumpCB(const void *dumpObj, const RuntimeType *dumpObjRT); 00124 00125 //--------------------------------------------------------------------------------------------- 00127 //--------------------------------------------------------------------------------------------- 00128 ErrorOutput(); 00129 00130 //--------------------------------------------------------------------------------------------- 00132 //--------------------------------------------------------------------------------------------- 00133 ~ErrorOutput(); 00134 00135 //----------------------------------------------------------------------------------- 00137 //----------------------------------------------------------------------------------- 00138 void reset(); 00139 00140 //--------------------------------------------------------------------------------------------- 00142 00143 //--------------------------------------------------------------------------------------------- 00149 void init(); 00150 00153 void destroy(); 00155 00156 00157 //--------------------------------------------------------------------------------------------- 00162 00163 //--------------------------------------------------------------------------------------------- 00164 00167 void setTerminationType(MLMessageType level, MLTerminator term); 00168 00170 MLTerminator getTerminationType(MLMessageType level) const; 00172 00173 //--------------------------------------------------------------------------------------------- 00175 00176 //--------------------------------------------------------------------------------------------- 00182 void setMessageFilter(MLuint32 messageType); 00183 00186 MLuint32 getMessageFilter(); 00188 00189 00190 //----------------------------------------------------------------------------------- 00192 00193 //----------------------------------------------------------------------------------- 00197 void setDumpCB(DumpCB *dumpCB); 00198 00200 DumpCB *getDumpCB() const; 00202 00203 00204 //--------------------------------------------------------------------------------------------- 00211 00212 //--------------------------------------------------------------------------------------------- 00214 void setFullDebuggingOn(bool on); 00215 00217 bool isFullDebuggingOn() const; 00219 00220 00221 //--------------------------------------------------------------------------------------------- 00223 00224 //--------------------------------------------------------------------------------------------- 00230 void addErrorOutputCB(void *userData, ErrorOutputCB *callback); 00231 00234 void removeErrorOutputCB(void *userData, ErrorOutputCB *callback); 00235 00239 bool hasErrorOutputCB(void *userData, ErrorOutputCB *callback) const; 00240 00244 void removeAllErrorOutputCBs(); 00245 00247 size_t getNumOutputCBs() const { return _errorOutputCBList.size(); } 00249 00250 00251 //--------------------------------------------------------------------------------------------- 00253 00254 //--------------------------------------------------------------------------------------------- 00256 void addDebugEnvName(const std::string &envName); 00257 00259 void removeDebugEnvName(const std::string &envName); 00260 00262 bool hasDebugEnvName(const std::string &envName) const; 00263 00265 const std::vector<std::string> &getDebugEnvNames() const; 00266 00269 void removeAllDebugEnvNames(); 00270 00272 size_t getNumDebugEnvNames() const; 00274 00275 //--------------------------------------------------------------------------------------------- 00277 00278 //--------------------------------------------------------------------------------------------- 00279 00281 void setOutputMessagesInVisualStudio(bool flag) { _outputMessagesInVisualStudio = flag; } 00282 00284 bool shouldOutputMessagesInVisualStudio() const { return _outputMessagesInVisualStudio; } 00285 00287 00288 00289 //--------------------------------------------------------------------------------------------- 00291 00292 //--------------------------------------------------------------------------------------------- 00294 bool areMessagesSentToCout() const { return _sendToCout; } 00295 00298 void sendMessagesToCout(bool on); 00299 00301 bool areMessagesSentToCerr() const { return _sendToCerr; } 00302 00305 void sendMessagesToCerr(bool on); 00307 00308 //--------------------------------------------------------------------------------------------- 00310 00311 //--------------------------------------------------------------------------------------------- 00313 MLuint32 getMaxNumTraceListDumps() const { return _maxNumTraceListDumps; } 00314 00316 void setMaxNumTraceListDumps(MLGlobalTraceBufferType num); 00317 00319 MLuint32 getMaxNumTraceStackDumps() const { return _maxNumTraceStackDumps; } 00320 00322 void setMaxNumTraceStackDumps(MLGlobalTraceBufferType num); 00323 00326 MLuint32 getTraceDumpMessageBits() const { return _traceDumpMessageBits; } 00327 00330 void setTraceDumpMessageBits(MLuint32 bitMask); 00332 00333 00334 // ------------------------------------------------------------------------------------------- 00339 00340 // ------------------------------------------------------------------------------------------- 00341 00365 // ErrorOutput::printAndNotify(ML_WARNING, // message type 00366 // "ML_", // Library prefix 00367 // "Function=", // function prefix 00368 // "MyFunction", // functionName 00369 // "MyFunction had an overflow", // reason 00370 // "I will do nothing to handle it", // handling 00371 // __FILE__, // file 00372 // __LINE__); // line 00373 // NULL, // no runtime object to be dumped 00374 // NULL, // no runtime type of any object 00375 // ML_CALCULATION_ERROR); // line 00379 void printAndNotify(MLMessageType messageType, 00380 const std::string &libraryPrefix, 00381 const std::string &fPrefix, 00382 const std::string &functionName, 00383 const std::string &reason, 00384 const std::string &handling = "", 00385 const std::string &file = "", 00386 int line = -1, 00387 const void *dumpObj = NULL, 00388 const RuntimeType *dumpObjRT= NULL, 00389 MLErrorCode errCode = ML_RESULT_OK) const; 00390 00394 void printAndNotify(MLMessageType messageType, 00395 const std::string &libraryPrefix, 00396 const std::string &fPrefix, 00397 const std::string &functionName, 00398 MLErrorCode reason, 00399 const std::string &handling = "", 00400 const std::string &file = "", 00401 int line = -1, 00402 const void *dumpObj = NULL, 00403 const RuntimeType *dumpObjRT= NULL 00404 ) const; 00405 00416 void handleDebugPrint(const std::string &envVar, 00417 const std::string &libraryPrefix, 00418 std::stringstream &reason, 00419 const char * file, 00420 int line) const; 00421 00433 void handleDebugPrint(const std::string &envVar, 00434 const std::string &libraryPrefix, 00435 const char * reason, 00436 const char * file, 00437 int line) const; 00438 00440 00441 00442 protected: 00443 00445 friend class ML_NAMESPACE::State; 00446 00448 ErrorOutput(const ErrorOutput &errorOutput); 00449 00451 ErrorOutput& operator=(const ErrorOutput &errorOutput); 00452 00453 private: 00454 00456 friend std::ostream& std::operator<<(std::ostream& s, const ErrorOutput &errorOutput); 00457 00459 void _init(); 00460 00462 void _printConsole(const std::string &errStr, const ErrorOutputInfos &infos) const; 00463 00467 std::string getTraceDump() const; 00468 00472 std::streambuf *_defaultCoutBuffer; 00473 00477 std::streambuf *_defaultCerrBuffer; 00478 00480 bool _sendToCout; 00481 00483 bool _sendToCerr; 00484 00485 //--------------------------------------------------------------------------------------------- 00487 00488 //--------------------------------------------------------------------------------------------- 00489 00491 bool _isFullDebuggingOn; 00492 00494 MLuint32 _messageTypeBits; 00495 00498 DumpCB *_dumpCB; 00499 00500 00502 MLTerminator _infoTerm; 00503 00505 MLTerminator _warnTerm; 00506 00508 MLTerminator _errorTerm; 00509 00512 MLTerminator _fatalTerm; 00513 00515 MLTerminator _debugTerm; 00516 00518 MLTerminator _coutTerm; 00519 00521 MLTerminator _cerrTerm; 00522 00524 MLTerminator _otherTerm; 00525 00528 MLGlobalTraceBufferType _maxNumTraceListDumps; 00529 00532 MLGlobalTraceBufferType _maxNumTraceStackDumps; 00533 00536 MLuint32 _traceDumpMessageBits; 00537 00539 std::vector<void*> _errorUserDataList; 00540 00542 std::vector<ErrorOutputCB*> _errorOutputCBList; 00543 00545 std::vector<std::string> _debugEnvStrings; 00546 00551 mutable RecursiveMutex _mutex; 00552 00554 bool _outputMessagesInVisualStudio; 00555 00557 }; 00558 00560 extern ML_UTILS_EXPORT ErrorOutput MLErrorOutput; 00561 00562 ML_UTILS_END_NAMESPACE 00563 00564 #endif // End of __mlErrorOutput_H 00565 00566