Salome HOME
updated copyright message
[modules/kernel.git] / src / KernelHelpers / SALOME_KernelServices.hxx
1 // Copyright (C) 2007-2023  CEA, EDF, 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, or (at your option) any later version.
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
20 // Author: Guillaume Boulant (EDF/R&D) 
21 #ifndef __SALOME_KERNEL_SERVICES_HXX__
22 #define __SALOME_KERNEL_SERVICES_HXX__
23 #pragma once
24
25 #include "KernelHelpers.hxx"
26
27 #include "SALOMEconfig.h"
28 #include CORBA_SERVER_HEADER(SALOMEDS)
29 #include CORBA_SERVER_HEADER(SALOMEDS_Attributes)
30 #include CORBA_SERVER_HEADER(SALOME_Launcher)
31 #include CORBA_CLIENT_HEADER(SALOME_Session)
32 #include CORBA_SERVER_HEADER(SALOME_Exception)
33
34 #include "SALOME_NamingService.hxx"
35 #include "SALOME_LifeCycleCORBA.hxx"
36
37 #include "SALOME_KernelORB.hxx"
38
39 namespace KERNEL {
40
41   // ---------------------------------------------
42   // SALOME KERNEL main services
43   KERNELHELPERS_EXPORT SALOME_NamingService_Abstract *getNamingService();
44   KERNELHELPERS_EXPORT void assignNamingServiceSL();
45   KERNELHELPERS_EXPORT SALOME_LifeCycleCORBA *       getLifeCycleCORBA();
46   KERNELHELPERS_EXPORT SALOME::Session_ptr           getSalomeSession();
47   KERNELHELPERS_EXPORT SALOMEDS::Study_ptr           getStudyServant();
48   KERNELHELPERS_EXPORT Engines::SalomeLauncher_ptr   getSalomeLauncher();
49   KERNELHELPERS_EXPORT Engines::ResourcesManager_ptr getResourcesManager();
50
51   // ---------------------------------------------
52   // SALOME KERNEL services to deal with a SALOME study, SObject and
53   // SComponent.
54   //
55   KERNELHELPERS_EXPORT CORBA::Object_ptr   IORToObject(char * IOR);
56   KERNELHELPERS_EXPORT CORBA::Object_ptr   SObjectToObject(SALOMEDS::SObject_ptr);
57   
58
59   KERNELHELPERS_EXPORT void RegisterCompo(const std::string& compoName, CORBA::Object_var compoPtr);
60   KERNELHELPERS_EXPORT CORBA::Object_var RetrieveCompo(const std::string& compoName);
61   /*!
62    * This template function provides you with the servant (CORBA
63    * object narrowed to its interface) corresponding to the specified
64    * CORBA object (naked CORBA pointer).
65    */
66   template<class TInterface> typename TInterface::_var_type
67   ObjectToInterface(CORBA::Object_ptr object) {
68     if(!CORBA::is_nil(object))
69       return TInterface::_narrow(object);
70     return TInterface::_nil();
71   }
72
73   template<class TInterface> typename TInterface::_var_type
74   SObjectToInterface(SALOMEDS::SObject_ptr sobject) {
75     CORBA::Object_ptr object = SObjectToObject(sobject);
76     return ObjectToInterface<TInterface>(object);
77   }
78
79   // _MEM_: note that template functions have to be declared AND
80   // implemented in the header because they are not compiled in this
81   // library but in every client library that includes this header
82   // file. The effective compilation depends on the particular class
83   // used for TInterface.
84
85   // ---------------------------------------------
86   // To create a standard SALOME exception embedding a simple text
87   KERNELHELPERS_EXPORT SALOME::SALOME_Exception createSalomeException(const char * text);
88 }
89
90
91 //
92 // =============================================================
93 // SALOME Logger macros
94 // =============================================================
95 //
96 // We can use the macros defined by SALOMELocalTrace/utilities.h
97 #include "utilities.h"
98 #define SALOMELOG(msg) {MESS_BEGIN("[XSALOME]") << msg << MESS_END}
99 #ifdef LOG
100 #undef LOG
101 #endif
102 #define LOG SALOMELOG
103
104 #include "Utils_CorbaException.hxx"
105 // Tip: CORBA exceptions can be used with LOG (or more generally in streams)
106 // Ex: LOG("An exception occurs: "<<e) will log the data of the exception e
107 #endif //__SALOME_KERNEL_SERVICES_HXX__