Salome HOME
Initial version
[modules/gui.git] / doc / salome / KernelResources / kernel_resources.lyx
1 #LyX 1.1 created this file. For more info see http://www.lyx.org/
2 \lyxformat 218
3 \textclass linuxdoc
4 \language english
5 \inputencoding default
6 \fontscheme default
7 \graphics default
8 \paperfontsize 10
9 \spacing single 
10 \papersize Default
11 \paperpackage a4
12 \use_geometry 0
13 \use_amsmath 0
14 \paperorientation portrait
15 \secnumdepth 3
16 \tocdepth 3
17 \paragraph_separation indent
18 \defskip medskip
19 \quotes_language english
20 \quotes_times 2
21 \papercolumns 1
22 \papersides 1
23 \paperpagestyle default
24
25 \layout Title
26 \added_space_top vfill \added_space_bottom vfill 
27 SALOME Kernel resources for developer
28 \layout Author
29
30 Antoine Yessayan, Paul Rascle 
31 \layout Date
32
33 Version 0.1 January 16, 2002
34 \layout Abstract
35
36 ABSTRACT 
37 \layout Abstract
38
39 This document describes the development environment for C++ and Python.
40  Makefiles generation and usage are introduced in another document: 
41 \begin_inset Quotes eld
42 \end_inset 
43
44 using the SALOME configuration and building system environment
45 \begin_inset Quotes erd
46 \end_inset 
47
48 .
49  Development environment is intended here as: trace and debug macros usage;
50  SALOME exceptions usage, in C++ and Python; user CORBA exceptions usage,
51  in C++ and Python, with and without Graphical User Interface; some general
52  purpose services such as singleton, used for CORBA connection and disconnection.
53 \layout Standard
54
55
56 \begin_inset LatexCommand \tableofcontents{}
57
58 \end_inset 
59
60
61 \layout Section
62
63 Trace and debug Utilities
64 \layout Standard
65
66 During the development process, an execution log is useful to identify problems.
67  This log contains messages, variables values, source files names and line
68  numbers.
69  It is recommended to verify assertions on variables values and if necessary,
70  to stop the execution at debug time, in order to validate all parts of
71  code.
72 \layout Subsection
73
74 Two modes: debug and release
75 \layout Standard
76
77 The goal of debug mode is to check as many features as possible during the
78  early stages of the development process.
79  The purpose of the utilities provided in SALOME is to help the developer
80  to add detailed traces and check variables values, without writing a lot
81  of code.
82 \layout Standard
83
84 When the code is assumed to be valid, the release mode optimizes execution,
85  in terms of speed, memory, and display only user level messages.
86 \layout Standard
87
88 But, some informations must always be displayed in both modes: especially
89  messages concerning environment or internal errors, with version identification.
90  When an end user is confronted to such a message, he may refer to a configurati
91 on documentation or send the message to the people in charge of SALOME installat
92 ion, or to the development team, following the kind of error.
93 \layout Subsection
94
95 C++ Macros for trace and debug
96 \layout Standard
97
98 SALOME provides C++ macros for trace and debug.
99  These macros are in 
100 \family typewriter 
101 SALOME/src/utils/utilities.h
102 \family default 
103  and this file must be included in C++ source.
104  Some macros are activated only in debug mode, others are always activated.
105  To activate the debug mode, 
106 \family typewriter 
107 _DEBUG_
108 \family default 
109  must be defined, which is the case when SALOME Makefiles are generated
110  from configure, without options.
111  When 
112 \family typewriter 
113 _DEBUG_
114 \family default 
115  is undefined (release mode), the debug mode macros are defined empty (they
116  do nothing).
117  So, when switching from debug to release, it is possible (and recommended)
118  to let the macro calls unchanged in the source.
119 \layout Standard
120
121 All the macros writing on the standard output start by flushing the standard
122  error.
123  At the end of the display those macros flush the standard output.
124 \layout Standard
125
126 Two informations are systematically added in front of the information displayed:
127 \layout Itemize
128
129 the name of the source file in which the macros is set;
130 \layout Itemize
131
132 the line number of the source file at which the macro is set.
133 \layout Subsubsection
134
135 Macros defined in debug and release modes
136 \layout Paragraph
137
138 INFOS_COMPILATION
139 \layout Standard
140
141 The C++ macro 
142 \family typewriter 
143 INFOS_COMPILATION
144 \family default 
145  writes on the standard output informations about the compiling process:
146  
147 \layout Itemize
148
149 the name of the compiler : 
150 \family typewriter 
151 g++, KCC, CC, pgCC
152 \family default 
153 ;
154 \layout Itemize
155
156 the date and the time of the compiling processing process.
157 \layout Standard
158
159 This macro 
160 \family typewriter 
161 INFOS_COMPILATION
162 \family default 
163  does not have any argument.
164  Moreover, it is defined in both compiling mode : 
165 \family typewriter 
166 _DEBUG_
167 \family default 
168  and 
169 \family typewriter 
170 _RELEASE_
171 \family default 
172 .
173 \layout Standard
174
175 Example :
176 \layout Verbatim
177
178 #include "utilities.h"
179 \layout Verbatim
180
181 int main(int argc , char **argv) 
182 \layout Verbatim
183
184
185 \layout Verbatim
186
187   INFOS_COMPILATION;
188 \layout Verbatim
189
190   ...
191 \layout Verbatim
192
193 }
194 \layout Paragraph
195
196 INFOS(str)
197 \layout Standard
198
199 In both compiling mode 
200 \family typewriter 
201 _DEBUG_
202 \family default 
203  and 
204 \family typewriter 
205 _RELEASE_
206 \family default 
207 , The C++ macro 
208 \family typewriter 
209 INFOS
210 \family default 
211  writes on the standard output the string which has been passed in argument
212  by the user.
213 \layout Standard
214
215 Example : 
216 \layout Verbatim
217
218 #include "utilities.h"
219 \layout Verbatim
220
221 int main(int argc , char **argv)
222 \layout Verbatim
223
224
225 \layout Verbatim
226
227   ...
228  
229 \layout Verbatim
230
231   INFOS("NORMAL END OF THE PROCESS"); 
232 \layout Verbatim
233
234   return 0; 
235 \layout Verbatim
236
237 }
238 \layout Standard
239
240 displays :
241 \layout Verbatim
242
243 main.cxx [5] : NORMAL END OF THE PROCESS
244 \layout Subsubsection
245
246 Macros defined only in debug mode
247 \layout Paragraph
248
249 MESSAGE(str)
250 \layout Standard
251
252 In 
253 \family typewriter 
254 _DEBUG_
255 \family default 
256  compiling mode only, the C++ macro 
257 \family typewriter 
258 MESSAGE
259 \family default 
260  writes on the standard output the string which has been passed in argument
261  by the user.
262  In 
263 \family typewriter 
264 _RELEASE_
265 \family default 
266  compiling mode, this macro is blank.
267 \layout Standard
268
269 Example : 
270 \layout Verbatim
271
272 #include "utilities.h" 
273 \layout Verbatim
274
275 #include <string> 
276 \layout Verbatim
277
278 using namespace std; 
279 \layout Verbatim
280
281 int main(int argc , char **argv) 
282 \layout Verbatim
283
284
285 \layout Verbatim
286
287   ...
288  
289 \layout Verbatim
290
291   const char *str = "Salome";
292 \layout Verbatim
293
294   MESSAGE(str);
295 \layout Verbatim
296
297   ...
298  const string st; 
299 \layout Verbatim
300
301   st = "Aster"; 
302 \layout Verbatim
303
304   MESSAGE(c_str(st+" and CASTEM")); 
305 \layout Verbatim
306
307   return 0;
308 \layout Verbatim
309
310 }
311 \layout Standard
312
313 displays :
314 \layout Verbatim
315
316 - Trace main.cxx [8] : Salome
317 \layout Verbatim
318
319 - Trace main.cxx [12] : Aster and CASTEM
320 \layout Paragraph
321
322 BEGIN_OF(func_name)
323 \layout Standard
324
325 In 
326 \family typewriter 
327 _DEBUG_
328 \family default 
329  compiling mode, The C++ macro 
330 \family typewriter 
331 BEGIN_OF
332 \family default 
333  appends the string 
334 \family typewriter 
335 "Begin of "
336 \family default 
337  to the one passed in argument by the user and displays the result on the
338  standard output.
339  In 
340 \family typewriter 
341 _RELEASE_
342 \family default 
343  compiling mode, this macro is blank.
344 \layout Standard
345
346 Example : 
347 \layout Verbatim
348
349 #include "utilities.h" 
350 \layout Verbatim
351
352 int main(int argc , char **argv) 
353 \layout Verbatim
354
355
356 \layout Verbatim
357
358   BEGIN_OF(argv[0]);
359 \layout Verbatim
360
361   return 0;
362 \layout Verbatim
363
364 }
365 \layout Standard
366
367 displays : 
368 \layout Verbatim
369
370 - Trace main.cxx [3] : Begin of a.out
371 \layout Paragraph
372
373 END_OF(func_name)
374 \layout Standard
375
376 In 
377 \family typewriter 
378 _DEBUG_
379 \family default 
380  compiling mode, The C++ macro 
381 \family typewriter 
382 END_OF
383 \family default 
384  appends the string 
385 \family typewriter 
386 "Normal end of "
387 \family default 
388  to the one passed in argument by the user and displays the result on the
389  standard output.
390  In 
391 \family typewriter 
392 _RELEASE_
393 \family default 
394  compiling mode, this macro is blank.
395 \layout Standard
396
397 Example : 
398 \layout Verbatim
399
400 #include "utilities.h" 
401 \layout Verbatim
402
403 int main(int argc , char **argv) 
404 \layout Verbatim
405
406
407 \layout Verbatim
408
409   END_OF(argv[0]);
410 \layout Verbatim
411
412   return 0; 
413 \layout Verbatim
414
415 }
416 \layout Standard
417
418 displays : 
419 \layout Verbatim
420
421 - Trace main.cxx [4] : Normal end of a.out
422 \layout Paragraph
423
424 SCRUTE(var)
425 \layout Standard
426
427 In 
428 \family typewriter 
429 _DEBUG_
430 \family default 
431  compiling mode, The C++ macro 
432 \family typewriter 
433 SCRUTE
434 \family default 
435  displays its argument which is an application variable followed by the
436  value of the variable.
437  In 
438 \family typewriter 
439 _RELEASE_
440 \family default 
441  compiling mode, this macro is blank.
442 \layout Standard
443
444 Example : 
445 \layout Verbatim
446
447 #include "utilities.h"
448 \layout Verbatim
449
450 int main(int argc , char **argv) 
451 \layout Verbatim
452
453
454 \layout Verbatim
455
456   const int i=999;
457 \layout Verbatim
458
459   if( i > 0 ) SCRUTE(i) ; i=i+1;
460 \layout Verbatim
461
462   return 0;
463 \layout Verbatim
464
465 }
466 \layout Standard
467
468 displays :
469 \layout Verbatim
470
471 - Trace main.cxx [5] : i=999
472 \layout Paragraph
473
474 ASSERT(condition)
475 \layout Standard
476
477 In 
478 \family typewriter 
479 _DEBUG_
480 \family default 
481  compiling mode only, The C++ macro 
482 \family typewriter 
483 ASSERT
484 \family default 
485  checks the expression passed in argument to be not NULL.
486  If it is NULL the process is stopped and the condition is written on the
487  standard output.
488  In 
489 \family typewriter 
490 _RELEASE_
491 \family default 
492  compiling mode, this macro is blank.
493  N.B.
494  : if 
495 \family typewriter 
496 ASSERT
497 \family default 
498  is already defined, this macro is ignored.
499 \layout Standard
500
501 Example :
502 \layout Verbatim
503
504 #include "utilities.h" 
505 \layout Verbatim
506
507 ...
508  
509 \layout Verbatim
510
511 const char *ptrS = fonc();
512 \layout Verbatim
513
514 ASSERT(ptrS!=NULL); 
515 \layout Verbatim
516
517 cout << strlen(ptrS); 
518 \layout Verbatim
519
520 float table[10];
521 \layout Verbatim
522
523 int k;
524 \layout Verbatim
525
526 ...
527  
528 \layout Verbatim
529
530 ASSERT(k<10);
531 \layout Verbatim
532
533 cout << table[k];
534 \layout Section
535
536 Exceptions
537 \layout Subsection
538
539 C++ exceptions: class SALOME_Exception
540 \layout Subsubsection
541
542 definition
543 \layout Standard
544
545 The class 
546 \family typewriter 
547 SALOME_Exception
548 \family default 
549  provides a generic method to send a message, with optional source file
550  name and line number.
551  This class is intended to serve as a base class for all kinds of exceptions
552  SALOME code.
553  All the exceptions derived from 
554 \family typewriter 
555 SALOME_Exception
556 \family default 
557  could be handled in a single catch, in which the message associated to
558  the exception is displayed, or sent to a log file.
559 \layout Standard
560
561 The class 
562 \family typewriter 
563 SALOME_Exception
564 \family default 
565  inherits its behavior from the STL class exception.
566 \layout Subsubsection
567
568 usage
569 \layout Standard
570
571 The header 
572 \family typewriter 
573 SALOME/src/utils/utils_SALOME_Exception.hxx
574 \family default 
575  must be included in the C++ source, when raised or trapped:
576 \layout Standard
577
578
579 \family typewriter 
580 #include 
581 \family default 
582 "
583 \family typewriter 
584 utils_SALOME_Exception.hxx
585 \family default 
586 "
587 \layout Standard
588
589 The 
590 \family typewriter 
591 SALOME_Exception
592 \family default 
593  constructor is:
594 \layout Verbatim
595
596 SALOME_Exception( const char *text,
597 \layout Verbatim
598
599                   const char *fileName=0, 
600 \layout Verbatim
601
602                   const unsigned int lineNumber=0 );
603 \layout Standard
604
605 The exception is raised like this:
606 \layout Verbatim
607
608 throw SALOME_Exception("my pertinent message");
609 \layout Standard
610
611 or like this:
612 \layout Verbatim
613
614 throw SALOME_Exception(LOCALIZED("my pertinent message"));
615 \layout Standard
616
617 where LOCALIZED is a macro provided with 
618 \family typewriter 
619 utils_SALOME_Exception.hxx
620 \family default 
621  which gives file name and line number.
622 \layout Standard
623
624 The exception is handled like this:
625 \layout Verbatim
626
627 try
628 \layout Verbatim
629
630   {
631 \layout Verbatim
632
633     ...
634 \layout Verbatim
635
636   }
637 \layout Verbatim
638
639 catch (const SALOME_Exception &ex)
640 \layout Verbatim
641
642   {
643 \layout Verbatim
644
645     cerr << ex.what() <<endl;
646 \layout Verbatim
647
648   }
649 \layout Standard
650
651 The 
652 \family typewriter 
653 what()
654 \family default 
655  method overrides the one defined in the STL exception class.
656 \layout Subsection
657
658 CORBA exceptions
659 \layout Subsubsection
660
661 definition
662 \layout Standard
663
664 The idl 
665 \family typewriter 
666 SALOME_Exception
667 \family default 
668  provides a generic CORBA exception for SALOME, with an attribute that gives
669  an exception type,a message, plus optional source file name and line number.
670  
671 \layout Standard
672
673 This idl is intended to serve for all user CORBA exceptions raised in SALOME
674  code, as IDL specification does not support exception inheritance.
675  So, all the user CORBA exceptions from SALOME could be handled in a single
676  catch.
677 \layout Standard
678
679 The exception types defined in idl are:
680 \layout Description
681
682 COMM CORBA communication problem,
683 \layout Description
684
685 BAD_PARAM Bad User parameters,
686 \layout Description
687
688 INTERNAL_ERROR application level problem (often irrecoverable).
689 \layout Standard
690
691 CORBA system and user exceptions already defined in the packages used within
692  SALOME, such as OmniORB exceptions, must be handled separately.
693 \layout Subsubsection
694
695 usage
696 \layout Paragraph
697
698 CORBA servant, C++
699 \layout Standard
700
701 The CORBA Server header for 
702 \family typewriter 
703 SALOME_Exception
704 \family default 
705  and a macro to throw the exception are provided with the header 
706 \family typewriter 
707 SALOME/src/Utils/Utils_CorbaException.hxx
708 \family default 
709 :
710 \layout Verbatim
711
712 #include "Utils_CorbaException.hxx"
713 \layout Standard
714
715 The exception is raised with a macro which appends file name and line number.
716 \layout Verbatim
717
718 if (myStudyName.size() == 0)
719 \layout Verbatim
720
721    THROW_SALOME_CORBA_EXCEPTION("No Study Name given", 
722 \backslash 
723
724 \layout Verbatim
725
726                                 SALOME::BAD_PARAM);
727 \layout Paragraph
728
729 CORBA Client, GUI Qt C++
730 \layout Standard
731
732 The CORBA Client header for 
733 \family typewriter 
734 SALOME_Exception
735 \family default 
736  and a Qt function header that displays a message box are provided in 
737 \family typewriter 
738 SALOME/src/SALOMEGUI/SALOMEGUI_QtCatchCorbaException.hxx
739 \family default 
740 :
741 \layout Verbatim
742
743 #include "SALOMEGUI_QtCatchCorbaException.hxx"
744 \layout Standard
745
746 A typical exchange with a CORBA Servant will be:
747 \layout Verbatim
748
749 try
750 \layout Verbatim
751
752   {
753 \layout Verbatim
754
755     ...
756  // one ore more CORBA calls
757 \layout Verbatim
758
759   }
760 \layout Verbatim
761
762 catch (const SALOME::SALOME_Exception & S_ex)
763 \layout Verbatim
764
765   {
766 \layout Verbatim
767
768     QtCatchCorbaException(S_ex);
769 \layout Verbatim
770
771   }
772 \layout Verbatim
773
774 \layout Paragraph
775
776 CORBA Client, C++, without GUI
777 \layout Standard
778
779 Nothing specific has been provided to the developer yet.
780  See the idl or the Qt function 
781 \family typewriter 
782 SALOMEGUI_QtCatchCorbaException.hxx
783 \family default 
784  to see how to get the information given by the exception object.
785 \layout Section
786
787 Miscellaneous tools
788 \layout Subsection
789
790 Singleton
791 \layout Subsubsection
792
793 Definition
794 \layout Standard
795
796 A singleton is an application data which is created and deleted only once
797  at the end of the application process.
798  The C++ compiler allows the user to create a static singleton data before
799  the first executable statement.
800  They are deleted after the last statement execution.
801 \layout Standard
802
803 The 
804 \family typewriter 
805 SINGLETON_
806 \family default 
807  template class deals with dynamic singleton.
808  It is useful for functor objects.
809  For example, an object that connects the application to a system at creation
810  and disconnects the application at deletion.
811 \layout Subsubsection
812
813 Usage
814 \layout Standard
815
816 To create a single instance a POINT object :
817 \layout Verbatim
818
819 # include "Utils_SINGLETON.hxx"
820 \layout Verbatim
821
822 ...
823  
824 \layout Verbatim
825
826 POINT *ptrPoint=SINGLETON_<POINT>::Instance() ; 
827 \layout Verbatim
828
829 assert(ptrPoint!=NULL) ;
830 \layout Standard
831
832 No need to delete ptrPoint.
833  Deletion is achieved automatically at exit.
834  If the user tries to create more than one singleton by using the class
835  method 
836 \family typewriter 
837 SINGLETON_<TYPE>::Instance()
838 \family default 
839 , the pointer is returned with the same value even if this is done in different
840  functions (threads ?).
841 \layout Verbatim
842
843 POINT *p1=SINGLETON_<POINT>::Instance() ;
844 \layout Verbatim
845
846 ...
847  
848 \layout Verbatim
849
850 POINT *p2=SINGLETON_<POINT>::Instance() ; 
851 \layout Verbatim
852
853 assert(p1==p2)
854 \layout Subsubsection
855
856 Design description
857 \layout Standard
858
859 Here are the principles features of the singleton design :
860 \layout Itemize
861
862 the user creates an object of class 
863 \family typewriter 
864 TYPE
865 \family default 
866  by using the class method 
867 \family typewriter 
868 SINGLETON_<TYPE>::Instance()
869 \family default 
870  which returns a pointer to the single object ;
871 \layout Itemize
872
873 to create an object, 
874 \family typewriter 
875 SINGLETON_<TYPE>::Instance()
876 \family default 
877  uses the default constructor of class 
878 \family typewriter 
879 TYPE
880 \family default 
881  ;
882 \layout Itemize
883
884 at the same time, this class method creates a destructor object which is
885  added to the generic list of destructor objects to be executed at the end
886  of the application (
887 \family typewriter 
888 atexit
889 \family default 
890 ) ;
891 \layout Itemize
892
893 at the end of the application process all the deletions are performed by
894  the 
895 \family typewriter 
896 Nettoyage()
897 \family default 
898  C\SpecialChar ~
899 function which executes the destruction objects end then deletes the destructi
900 ons objects themselves ;
901 \layout Itemize
902
903 the 
904 \family typewriter 
905 Nettoyage()
906 \family default 
907  C \SpecialChar ~
908 function using atexit() C \SpecialChar ~
909 function is embedded in a static single object
910  
911 \family typewriter 
912 ATEXIT_()
913 \family default 
914 .
915 \the_end