3 \page kernel_resources SALOME Kernel resources for developer
5 <b>WORK in PROGRESS, INCOMPLETE DOCUMENT</b>
8 \section S1_kernel_res Abstract
10 This document describes the development environment for
11 C++ and Python. Makefiles generation and usage are
12 introduced in another document: "using the %SALOME
13 configuration and building system environment".
14 Development environment is intended here as: trace and
15 debug macros usage; %SALOME exceptions usage, in C++ and
16 Python; user CORBA exceptions usage, in C++ and Python,
17 with and without Graphical User Interface; some general
18 purpose services such as singleton, used for CORBA
19 connection and disconnection.
21 \section S2_kernel_res Trace and debug Utilities
23 During the development process, an execution log is
24 useful to identify problems. This log contains
25 messages, variables values, source files names and line
26 numbers. It is recommended to verify assertions on
27 variables values and if necessary, to stop the
28 execution at debug time, in order to validate all parts
33 <b>Two modes: debug and release</b>
35 The goal of debug mode is to check as many features as
36 possible during the early stages of the development
37 process. The purpose of the utilities provided in
38 %SALOME is to help the developer to add detailed traces
39 and check variables values, without writing a lot of code.
41 When the code is assumed to be valid, the release mode
42 optimizes execution, in terms of speed, memory, and
43 display only user level messages.
45 But, some informations must always be displayed in both
46 modes: especially messages concerning environment or
47 internal errors, with version identification. When an
48 end user is confronted to such a message, he may refer
49 to a configuration documentation or send the message to
50 the people in charge of %SALOME installation, or to the
51 development team, following the kind of error.
54 <b>C++ Macros for trace and debug</b>
56 %SALOME provides C++ macros for trace and debug. These
60 KERNEL_SRC/src/SALOMELocalTrace/utilities.h
63 This file must be included in C++ source. Some
64 macros are activated only in debug mode, others are
65 always activated. To activate the debug mode, ``_DEBUG_``
66 must be defined, which is the case when %SALOME
67 Makefiles are generated from configure, without
68 options. When ``_DEBUG_`` is undefined (release mode:
69 ``configure --disable-debug --enable-production``), the
70 debug mode macros are defined empty (they do nothing).
71 So, when switching from debug to release, it is
72 possible (and recommended) to let the macro calls
73 unchanged in the source.
75 All the macros generate trace messages, stored in a
76 circular buffer pool. %A separate %thread reads the
77 messages in the buffer pool, and, depending on options
78 given at %SALOME start, writes the messages on the
79 standard output, a file, or send them via CORBA, in
80 case of a multi machine configuration.
82 Three informations are systematically added in front of
83 the information displayed:
85 - the %thread number from which the message come from;
87 - the name of the source file in which the macros is set;
89 - the line number of the source file at which the macro
94 <b>Macros defined in debug and release modes</b>
96 <b>INFOS_COMPILATION</b>
98 The C++ macro INFOS_COMPILATION writes on the trace
99 buffer pool informations about the compiling process:
101 - the name of the compiler : g++, KCC, CC, pgCC;
103 - the date and the time of the compiling processing process.
105 This macro INFOS_COMPILATION does not have any
106 argument. Moreover, it is defined in both compiling
107 mode : _DEBUG_ and _RELEASE_.
112 #include "utilities.h"
113 int main(int argc , char **argv)
123 In both compiling mode _DEBUG_ and _RELEASE_, The C++
124 macro INFOS writes on the trace buffer pool %the string
125 which has been passed in argument by the user.
130 #include "utilities.h"
131 int main(int argc , char **argv)
134 INFOS("NORMAL END OF THE PROCESS");
142 main.cxx [5] : NORMAL END OF THE PROCESS
145 <b>INTERRUPTION(str)</b>
147 In both compiling mode _DEBUG_ and _RELEASE_, The C++
148 macro INTERRUPTION writes on the trace buffer pool the
149 %string, with a special ABORT type. When the %thread in
150 charge of collecting messages finds this message, it
151 terminates the application, after message treatment.
153 <b>IMMEDIATE_ABORT(str)</b>
155 In both compiling mode _DEBUG_ and _RELEASE_, The C++
156 macro IMMEDIATE_ABORT writes the message str immediately on
157 standard error and exits the application. Remaining
158 messages not treated by the message collector %thread
163 <b>Macros defined only in debug mode</b>
167 In _DEBUG_ compiling mode only, the C++ macro MESSAGE
168 writes on the trace buffer pool the %string which has
169 been passed in argument by the user. In _RELEASE_
170 compiling mode, this macro is blank.
175 #include "utilities.h"
180 int main(int argc , char **argv)
183 const char *str = "Salome";
187 MESSAGE(c_str(st+" and CASTEM"));
196 - Trace main.cxx [8] : Salome
197 - Trace main.cxx [12] : Aster and CASTEM
201 <b>BEGIN_OF(func_name)</b>
203 In _DEBUG_ compiling mode, The C++ macro BEGIN_OF
204 appends the %string "Begin of " to the one passed in
205 argument by the user and displays the result on the
206 trace buffer pool. In _RELEASE_ compiling mode, this
212 #include "utilities.h"
213 int main(int argc , char **argv)
223 - Trace main.cxx [3] : Begin of a.out
226 <b>END_OF(func_name)</b>
228 In _DEBUG_ compiling mode, The C++ macro END_OF appends
229 the %string "Normal end of " to the one passed in
230 argument by the user and displays the result on the
231 trace buffer pool. In _RELEASE_ compiling mode, this
237 #include "utilities.h"
238 int main(int argc , char **argv)
248 - Trace main.cxx [4] : Normal end of a.out
253 In _DEBUG_ compiling mode, The C++ macro SCRUTE
254 displays its argument which is an application variable
255 followed by the value of the variable. In _RELEASE_
256 compiling mode, this macro is blank.
261 #include "utilities.h"
262 int main(int argc , char **argv)
265 if( i > 0 ) SCRUTE(i) ; i=i+1;
273 - Trace main.cxx [5] : i=999
276 <b>ASSERT(condition)</b>
278 In _DEBUG_ compiling mode only, The C++ macro ASSERT
279 checks the expression passed in argument to be not
280 NULL. If it is NULL the condition is written with the
281 macro INTERRUPTION (see above). The process exits after
282 trace of this last message. In _RELEASE_ compiling
283 mode, this macro is blank. N.B. : if ASSERT is already
284 defined, this macro is ignored.
289 #include "utilities.h"
291 const char *ptrS = fonc();
293 cout << strlen(ptrS);
306 \section S3_kernel_res Exceptions
310 <b>C++ exceptions: class SALOME_Exception</b>
316 The class SALOME_Exception provides a generic method to
317 send a message, with optional source file name and line
318 number. This class is intended to serve as a base class
319 for all kinds of exceptions %SALOME code. All the
320 exceptions derived from SALOME_Exception could be
321 handled in a single catch, in which the message
322 associated to the exception is displayed, or sent to a
325 The class SALOME_Exception inherits its behavior from
326 the STL class exception.
331 The header %SALOME/src/utils/utils_SALOME_Exception.hxx
332 must be included in the C++ source, when raised or trapped:
335 #include "utils_SALOME_Exception.hxx"
338 The SALOME_Exception constructor is:
341 SALOME_Exception( const char *text,
342 const char *fileName=0,
343 const unsigned int lineNumber=0 );
346 The exception is raised like this:
349 throw SALOME_Exception("my pertinent message");
355 throw SALOME_Exception(LOCALIZED("my pertinent message"));
358 where LOCALIZED is a macro provided with
359 ``utils_SALOME_Exception.hxx`` which gives file name and
362 The exception is handled like this:
369 catch (const SALOME_Exception &ex)
371 cerr << ex.what() <<endl;
375 The what() method overrides the one defined in the STL
381 <b>CORBA exceptions</b>
387 The idl SALOME_Exception provides a generic CORBA
388 exception for %SALOME, with an attribute that gives an
389 exception type,a message, plus optional source file
390 name and line number.
392 This idl is intended to serve for all user CORBA
393 exceptions raised in %SALOME code, as IDL specification
394 does not support exception inheritance. So, all the
395 user CORBA exceptions from %SALOME could be handled in a
398 The exception types defined in idl are:
400 - COMM CORBA communication problem,
402 - BAD_PARAM Bad User parameters,
404 - INTERNAL_ERROR application level problem (often irrecoverable).
406 CORBA system and user exceptions already defined in the
407 packages used within %SALOME, such as OmniORB
408 exceptions, must be handled separately.
415 <b>CORBA servant, C++</b>
417 The CORBA Server header for SALOME_Exception and a
418 macro to throw the exception are provided with the
419 header ``KERNEL_SRC/src/Utils/Utils_CorbaException.hxx``:
422 #include "Utils_CorbaException.hxx"
425 The exception is raised with a macro which appends file
426 name and line number:
429 if (myStudyName.size() == 0)
430 THROW_SALOME_CORBA_EXCEPTION("No Study Name given",
436 <b>CORBA Client, GUI Qt C++</b>
438 <b>NO MORE AVAILABLE in %SALOME 3.x</b>
440 The CORBA Client header for SALOME_Exception and a Qt
441 function header that displays a message box are
444 ``KERNEL_SRC/src/SALOMEGUI/SALOMEGUI_QtCatchCorbaException.hxx``
447 #include "SALOMEGUI_QtCatchCorbaException.hxx"
450 %A typical exchange with a CORBA Servant will be:
455 ... // one ore more CORBA calls
458 catch (const SALOME::SALOME_Exception & S_ex)
460 QtCatchCorbaException(S_ex);
466 <b>CORBA Client, C++, without GUI</b>
468 Nothing specific has been provided to the developer
469 yet. See the idl or the Qt function
470 SALOMEGUI_QtCatchCorbaException.hxx to see how to get
471 the information given by the exception %object.
479 \section S4_kernel_res Miscellaneous tools
488 %A singleton is an application data which is created and
489 deleted only once at the end of the application
490 process. The C++ compiler allows the user to create a
491 static singleton data before the first executable
492 statement. They are deleted after the last statement execution.
494 The ``SINGLETON_`` template class deals with dynamic
495 singleton. It is useful for functor objects. For
496 example, an %object that connects the application to a
497 system at creation and disconnects the application at deletion.
503 To create a single instance of a POINT %object:
506 # include "Utils_SINGLETON.hxx"
508 POINT *ptrPoint=SINGLETON_<POINT>::Instance() ;
509 assert(ptrPoint!=NULL) ;
512 No need to delete ptrPoint. Deletion is achieved
513 automatically at exit. If the user tries to create more
514 than one singleton by using the class method
515 SINGLETON_<TYPE>::Instance(), the pointer is returned
516 with the same value even if this is done in different
517 functions (threads ?):
520 POINT *p1=SINGLETON_<POINT>::Instance() ;
522 POINT *p2=SINGLETON_<POINT>::Instance() ;
529 <b>Design description</b>
531 Here are the principles features of the singleton
534 - the user creates an %object of class TYPE by using the
535 class method ``SINGLETON_<TYPE>::Instance()`` which
536 returns a pointer to the single %object ;
538 - to create an %object, ``SINGLETON_<TYPE>::Instance()``
539 uses the default constructor of class TYPE ;
541 - at the same time, this class method creates a
542 destructor %object which is added to the generic list
543 of destructor objects to be executed at the end of
544 the application (atexit) ;
546 - at the end of the application process all the
547 deletions are performed by the ``Nettoyage()`` C function
548 which executes the destruction objects end then
549 deletes the destructions objects themselves ;
551 - the ``Nettoyage()`` C function using ``atexit()`` C function
552 is embedded in a static single %object ``ATEXIT_()``.