]> SALOME platform Git repositories - modules/kernel.git/blob - src/KernelHelpers/SALOME_KernelServices.hxx
Salome HOME
Add missing linking flags
[modules/kernel.git] / src / KernelHelpers / SALOME_KernelServices.hxx
1 // Copyright (C) 2007-2011  CEA/DEN, EDF R&D, OPEN CASCADE
2 //
3 // This library is free software; you can redistribute it and/or
4 // modify it under the terms of the GNU Lesser General Public
5 // License as published by the Free Software Foundation; either
6 // version 2.1 of the License.
7 //
8 // This library is distributed in the hope that it will be useful,
9 // but WITHOUT ANY WARRANTY; without even the implied warranty of
10 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
11 // Lesser General Public License for more details.
12 //
13 // You should have received a copy of the GNU Lesser General Public
14 // License along with this library; if not, write to the Free Software
15 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA
16 //
17 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
18 //
19 // Author: Guillaume Boulant (EDF/R&D) 
20
21 #ifndef __KERNEL_SERVICES_H__
22 #define __KERNEL_SERVICES_H__
23
24 #include "SALOMEconfig.h"
25 #include CORBA_SERVER_HEADER(SALOMEDS)
26 #include CORBA_SERVER_HEADER(SALOMEDS_Attributes)
27 #include CORBA_SERVER_HEADER(SALOME_ContainerManager)
28 #include CORBA_CLIENT_HEADER(SALOME_Session)
29 #include CORBA_SERVER_HEADER(SALOME_Exception)
30
31 #include "SALOME_NamingService.hxx"
32 #include "SALOME_LifeCycleCORBA.hxx"
33
34 namespace KERNEL {
35
36   // ---------------------------------------------
37   // SALOME KERNEL main services
38   CORBA::ORB_ptr                getORB();
39   SALOME_NamingService *        getNamingService();
40   SALOME_LifeCycleCORBA *       getLifeCycleCORBA();
41   SALOME::Session_ptr           getSalomeSession();
42   SALOMEDS::StudyManager_ptr    getStudyManager();
43   Engines::SalomeLauncher_ptr   getSalomeLauncher();
44   Engines::ResourcesManager_ptr getResourcesManager();
45
46   // ---------------------------------------------
47   // SALOME KERNEL services to deal with a SALOME study, SObject and
48   // SComponent.
49   //
50   SALOMEDS::Study_ptr getStudyById(int aStudyId);
51   int                 getStudyId(SALOMEDS::Study_ptr study);
52   CORBA::Object_ptr   IORToObject(char * IOR);
53   CORBA::Object_ptr   SObjectToObject(SALOMEDS::SObject_ptr);
54   
55
56
57   /*!
58    * This template function provides you with the servant (CORBA
59    * object narrowed to its interface) corresponding to the specified
60    * CORBA object (naked CORBA pointer).
61    */
62   template<class TInterface> typename TInterface::_var_type
63   ObjectToInterface(CORBA::Object_ptr object) {
64     if(!CORBA::is_nil(object))
65       return TInterface::_narrow(object);
66     return TInterface::_nil();
67   }
68
69   template<class TInterface> typename TInterface::_var_type
70   SObjectToInterface(SALOMEDS::SObject_ptr sobject) {
71     CORBA::Object_ptr object = SObjectToObject(sobject);
72     return ObjectToInterface<TInterface>(object);
73   }
74
75   // _MEM_: note that template functions have to be declared AND
76   // implemented in the header because they are not compiled in this
77   // library but in every client library that includes this header
78   // file. The effective compilation depends on the particular class
79   // used for TInterface.
80
81   // ---------------------------------------------
82   // To create a standard SALOME exception embedding a simple text
83   SALOME::SALOME_Exception createSalomeException(const char * text);
84 }
85
86
87 //
88 // =============================================================
89 // SALOME Logger macros
90 // =============================================================
91 //
92 // We can use the macros defined by SALOMELocalTrace/utilities.h
93 #include "utilities.h"
94 #define SALOMELOG(msg) {MESS_BEGIN("[XSALOME]") << msg << MESS_END}
95 #define LOG SALOMELOG
96
97 // This can help to LOG (or use in stream) the CORBA exceptions
98 // Ex: LOG("An exception occurs: "<<e) will log the data of the exception e
99 #include <CORBA.h>
100 #include <ostream>
101 static std::ostream &
102 operator<<(std::ostream & os, const CORBA::Exception & e)
103 {
104   CORBA::Any tmp;
105   tmp <<=e ;
106   CORBA::TypeCode_var tc = tmp.type();
107   const char * p = tc->name ();
108   if (*p != '\0')
109     os << p;
110   else
111     os << tc->id();
112   return os;
113 }
114
115
116 #endif // KERNEL_SERVICES