Salome HOME
Merging from BR_DEBUG_3_2_0b1
[modules/kernel.git] / src / SALOMELocalTrace / utilities.h
1 //  SALOME Utils : general SALOME's definitions and tools
2 //
3 //  Copyright (C) 2003  OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN,
4 //  CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS 
5 // 
6 //  This library is free software; you can redistribute it and/or 
7 //  modify it under the terms of the GNU Lesser General Public 
8 //  License as published by the Free Software Foundation; either 
9 //  version 2.1 of the License. 
10 // 
11 //  This library is distributed in the hope that it will be useful, 
12 //  but WITHOUT ANY WARRANTY; without even the implied warranty of 
13 //  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU 
14 //  Lesser General Public License for more details. 
15 // 
16 //  You should have received a copy of the GNU Lesser General Public 
17 //  License along with this library; if not, write to the Free Software 
18 //  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA 
19 // 
20 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
21 //
22 //
23 //
24 //  File   : utilities.h
25 //  Author : Antoine YESSAYAN, Paul RASCLE, EDF
26 //  Module : SALOME
27 //  $Header$
28
29 /* ---  Definition macros file to print informations if _DEBUG_ is defined --- */
30
31 #ifndef UTILITIES_H
32 #define UTILITIES_H
33
34 #include <iostream>
35 #include <sstream>
36 #include <cstdlib>
37
38
39 #include "LocalTraceBufferPool.hxx"
40
41 /*!
42  * For each message to put in the trace, a specific ostingstream object is
43  * created and destroyed automatically at the end of the message macro.
44  * The insert function of LocalTraceBufferPool class gets a buffer in a
45  * buffer pool (unique with the help of mutexes and semaphores) and copy the
46  * message in the buffer.
47  * This buffer is read later by a specific thread in charge of trace print.
48  * Order of trace entries is globally respected. Nevertheless, if there are
49  * several threads waiting for a free buffer to trace, the order of
50  * thread waken up is not garanteed (no fifo or priority rules in Linux Kernel)
51  */
52
53 #define MESS_INIT(deb) std::ostringstream os; os<<deb
54 #define MESS_BEGIN(deb) MESS_INIT(deb)<<__FILE__ <<" ["<<__LINE__<<"] : "
55 #define MESS_END std::endl; LocalTraceBufferPool::instance()->insert(NORMAL_MESS, os.str().c_str());
56 #define MESS_ABORT std::endl; LocalTraceBufferPool::instance()->insert(ABORT_MESS, os.str().c_str());
57
58 // --- Some macros are always defined (without _DEBUG_): for use with release version
59
60 #define INFOS(msg) {MESS_BEGIN("- Trace ") << msg << MESS_END}
61 #define PYSCRIPT(msg) {MESS_INIT("---PYSCRIPT--- ") << msg << MESS_END}
62 #define INTERRUPTION(msg) {MESS_BEGIN("- INTERRUPTION: ")<< msg << MESS_ABORT}
63 #ifdef WNT
64 #define IMMEDIATE_ABORT(code) {std::cout <<std::flush; \
65                                std::cerr << "- ABORT " << __FILE__ << " [" <<__LINE__<< "] : " << flush; \
66                                std::cerr << "ABORT return code= "<< code << std::endl; \
67                                /*std::*/exit(code);}
68 #else
69 #define IMMEDIATE_ABORT(code) {std::cout <<std::flush; \
70                                std::cerr << "- ABORT " << __FILE__ << " [" <<__LINE__<< "] : " << flush; \
71                                std::cerr << "ABORT return code= "<< code << std::endl; \
72                                std::exit(code);}
73 #endif
74
75 /* --- To print date and time of compilation of current source --- */
76
77 #if defined ( __GNUC__ )
78 #define COMPILER                "g++" 
79 #elif defined ( __sun )
80 #define COMPILER                "CC" 
81 #elif defined ( __KCC )
82 #define COMPILER                "KCC" 
83 #elif defined ( __PGI )
84 #define COMPILER                "pgCC" 
85 #elif defined ( __alpha )
86 #define COMPILER                "cxx" 
87 #else
88 #define COMPILER                "undefined" 
89 #endif
90
91 #ifdef INFOS_COMPILATION
92 #error INFOS_COMPILATION already defined
93 #endif
94
95 #define INFOS_COMPILATION { MESS_BEGIN("COMPILED with ") << COMPILER \
96                                        << ", " << __DATE__ \
97                                        << " at " << __TIME__ << MESS_END }
98 #ifdef _DEBUG_
99
100 // --- the following MACROS are useful at debug time
101
102 #define MESSAGE(msg) {MESS_BEGIN("- Trace ") << msg << MESS_END}
103 #define SCRUTE(var)  {MESS_BEGIN("- Trace ") << #var << "=" << var <<MESS_END}
104
105 #define REPERE ("------- ")
106 #define BEGIN_OF(msg) {MESS_BEGIN(REPERE) << "Begin of: "      << msg << MESS_END} 
107 #define END_OF(msg)   {MESS_BEGIN(REPERE) << "Normal end of: " << msg << MESS_END} 
108
109 #ifndef ASSERT
110 #define ASSERT(condition) \
111         if (!(condition)){INTERRUPTION("CONDITION "<<#condition<<" NOT VERIFIED")}
112 #endif /* ASSERT */
113
114
115 #else /* ifdef _DEBUG_*/
116
117 #define MESSAGE(msg) {}
118 #define SCRUTE(var) {}
119 #define REPERE
120 #define BEGIN_OF(msg) {}
121 #define END_OF(msg) {}
122
123 #ifndef ASSERT
124 #define ASSERT(condition) {}
125 #endif /* ASSERT */
126
127 #endif /* ifdef _DEBUG_*/
128
129 #endif /* ifndef UTILITIES_H */