1 // Copyright (C) 2007-2016 CEA/DEN, EDF R&D, OPEN CASCADE
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.
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.
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
17 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
19 // Author: Guillaume Boulant (EDF/R&D)
21 #include "SALOME_KernelServices.hxx"
26 * This function returns a static reference to the orb. The orb can
27 * be used for example to initialize CORBA variables or to serialize
28 * and unserialize the CORBA objet to/from an IOR string.
30 CORBA::ORB_ptr getORB() {
31 static CORBA::ORB_ptr orb;
32 if(CORBA::is_nil(orb)){
34 orb = CORBA::ORB_init(argc,0);
40 * This function returns a static reference to the SALOME naming service.
42 SALOME_NamingService * getNamingService() {
43 static SALOME_NamingService * namingService;
44 if ( namingService == NULL ) {
45 namingService = new SALOME_NamingService(getORB());
51 * This function returns a static reference to the SALOME life cycle CORBA.
53 SALOME_LifeCycleCORBA * getLifeCycleCORBA() {
54 static SALOME_LifeCycleCORBA * lifeCycleCORBA;
55 if ( lifeCycleCORBA == NULL ) {
56 SALOME_NamingService *aNamingService = getNamingService();
57 lifeCycleCORBA = new SALOME_LifeCycleCORBA(aNamingService);
59 return lifeCycleCORBA;
64 * This returns a static reference to the SALOME study. The
65 * study can be used to get informations about it.
67 SALOMEDS::Study_ptr getStudy() {
68 static SALOMEDS::Study_ptr aStudy;
69 if(CORBA::is_nil(aStudy)){
70 SALOME_NamingService *aNamingService = getNamingService();
71 CORBA::Object_ptr anObject = aNamingService->Resolve("/Study");
72 aStudy = SALOMEDS::Study::_narrow(anObject);
78 * This returns a static reference to the SALOME session. The
79 * SALOME session can be used to retrieve some objects of the
80 * current session, as the SALOME study.
82 SALOME::Session_ptr getSalomeSession() {
83 static SALOME::Session_ptr salomeSession;
84 if(CORBA::is_nil(salomeSession)){
85 SALOME_NamingService *aNamingService = getNamingService();
86 CORBA::Object_ptr obj = aNamingService->Resolve("/Kernel/Session");
87 salomeSession = SALOME::Session::_narrow(obj);
93 * This returns a static reference to the SALOME launcher. The
94 * SALOME launcher can be used to schedule jobs, local or remote,
95 * using a batch system or not (see SALOME documentation).
97 Engines::SalomeLauncher_ptr getSalomeLauncher() {
98 //LOG("KERNEL_services::getSalomeLauncher()");
99 static Engines::SalomeLauncher_ptr salomeLauncher;
100 if(CORBA::is_nil(salomeLauncher)){
101 //LOG("KERNEL_services::getSalomeLauncher(): creating the static instance");
102 SALOME_NamingService *aNamingService = getNamingService();
103 CORBA::Object_ptr obj = aNamingService->Resolve("/SalomeLauncher");
104 salomeLauncher = Engines::SalomeLauncher::_narrow(obj);
106 return salomeLauncher;
109 Engines::ResourcesManager_ptr getResourcesManager() {
110 static Engines::ResourcesManager_ptr resourcesManager;
111 if(CORBA::is_nil(resourcesManager)){
112 SALOME_NamingService *aNamingService = getNamingService();
113 CORBA::Object_ptr obj = aNamingService->Resolve("/ResourcesManager");
114 resourcesManager = Engines::ResourcesManager::_narrow(obj);
116 return resourcesManager;
120 * This function retrieve the CORBA object reference from the study
121 * object wrapping it.
123 CORBA::Object_ptr SObjectToObject(SALOMEDS::SObject_ptr theSObject) {
125 SALOMEDS::GenericAttribute_var anAttr;
126 CORBA::Object_var anObject;
127 if(CORBA::is_nil(theSObject))
130 if(theSObject->FindAttribute(anAttr, "AttributeIOR")){
131 SALOMEDS::AttributeIOR_var anIOR = SALOMEDS::AttributeIOR::_narrow(anAttr);
132 CORBA::String_var aValue = anIOR->Value();
133 CORBA::ORB_ptr anORB = getORB();
134 if(strcmp(aValue,"") != 0)
135 anObject = anORB->string_to_object(aValue);
138 INFOS("SObjectToObject - Unknown exception was occured!!!");
140 return anObject._retn();
144 * This function provides a CORBA pointer to a servant from its IOR
145 * given as a string of characters.
147 CORBA::Object_ptr IORToObject(char * IOR) {
148 return getORB()->string_to_object(IOR);
152 // __GBO__ See the file ./src/SMESHGUI/SMESHGUI_Utils.h of SMESH_SRC
153 // for other helper functions
156 SALOME::SALOME_Exception createSalomeException(const char * text) {
157 SALOME::ExceptionStruct es;
158 es.type = SALOME::INTERNAL_ERROR;
159 es.text = CORBA::string_dup(text);
160 return SALOME::SALOME_Exception(es);