1 // Copyright (C) 2007-2021 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
20 // Author: Guillaume Boulant (EDF/R&D)
22 #include "SALOME_KernelServices.hxx"
23 #include "SALOME_Fake_NamingService.hxx"
28 std::map<std::string,CORBA::Object_var> _compo_map;
30 std::unique_ptr<SALOME_NamingService_Abstract> _naming_service;
34 void assignNamingServiceSL()
36 if ( !_naming_service.get() )
38 _naming_service.reset( new SALOME_Fake_NamingService );
42 THROW_SALOME_EXCEPTION("assignNamingServiceSL : NS SALOME Wrapper is already set !");
47 * This function returns a static reference to the SALOME naming service.
49 SALOME_NamingService_Abstract *getNamingService()
51 if ( !_naming_service.get() )
53 _naming_service.reset( new SALOME_NamingService(getORB()) );
55 return _naming_service.get();
59 * This function returns a static reference to the SALOME life cycle CORBA.
61 SALOME_LifeCycleCORBA * getLifeCycleCORBA() {
62 static SALOME_LifeCycleCORBA * lifeCycleCORBA;
63 if ( lifeCycleCORBA == NULL ) {
64 SALOME_NamingService_Abstract *aNamingService = getNamingService();
65 lifeCycleCORBA = new SALOME_LifeCycleCORBA(aNamingService);
67 return lifeCycleCORBA;
72 * This returns a static reference to the SALOME study. The
73 * study can be used to get informations about it.
74 * \sa getStudyServantSA
76 SALOMEDS::Study_ptr getStudyServant() {
77 static SALOMEDS::Study_ptr aStudy;
78 if(CORBA::is_nil(aStudy)){
79 SALOME_NamingService_Abstract *aNamingService = getNamingService();
80 CORBA::Object_ptr anObject = aNamingService->Resolve("/Study");
81 aStudy = SALOMEDS::Study::_narrow(anObject);
83 return SALOMEDS::Study::_duplicate(aStudy); // we duplicate it here to allow using it with the var client instances.
87 * This returns a static reference to the SALOME session. The
88 * SALOME session can be used to retrieve some objects of the
89 * current session, as the SALOME study.
91 SALOME::Session_ptr getSalomeSession() {
92 static SALOME::Session_ptr salomeSession;
93 if(CORBA::is_nil(salomeSession)){
94 SALOME_NamingService_Abstract *aNamingService = getNamingService();
95 CORBA::Object_ptr obj = aNamingService->Resolve("/Kernel/Session");
96 salomeSession = SALOME::Session::_narrow(obj);
102 * This returns a static reference to the SALOME launcher. The
103 * SALOME launcher can be used to schedule jobs, local or remote,
104 * using a batch system or not (see SALOME documentation).
106 Engines::SalomeLauncher_ptr getSalomeLauncher() {
107 //LOG("KERNEL_services::getSalomeLauncher()");
108 static Engines::SalomeLauncher_ptr salomeLauncher;
109 if(CORBA::is_nil(salomeLauncher)){
110 //LOG("KERNEL_services::getSalomeLauncher(): creating the static instance");
111 SALOME_NamingService_Abstract *aNamingService = getNamingService();
112 CORBA::Object_ptr obj = aNamingService->Resolve("/SalomeLauncher");
113 salomeLauncher = Engines::SalomeLauncher::_narrow(obj);
115 return salomeLauncher;
118 Engines::ResourcesManager_ptr getResourcesManager() {
119 static Engines::ResourcesManager_ptr resourcesManager;
120 if(CORBA::is_nil(resourcesManager)){
121 SALOME_NamingService_Abstract *aNamingService = getNamingService();
122 CORBA::Object_ptr obj = aNamingService->Resolve("/ResourcesManager");
123 resourcesManager = Engines::ResourcesManager::_narrow(obj);
125 return resourcesManager;
129 * This function retrieve the CORBA object reference from the study
130 * object wrapping it.
132 CORBA::Object_ptr SObjectToObject(SALOMEDS::SObject_ptr theSObject) {
134 SALOMEDS::GenericAttribute_var anAttr;
135 CORBA::Object_var anObject;
136 if(CORBA::is_nil(theSObject))
139 if(theSObject->FindAttribute(anAttr, "AttributeIOR")){
140 SALOMEDS::AttributeIOR_var anIOR = SALOMEDS::AttributeIOR::_narrow(anAttr);
141 CORBA::String_var aValue = anIOR->Value();
142 CORBA::ORB_ptr anORB = getORB();
143 if(strcmp(aValue,"") != 0)
144 anObject = anORB->string_to_object(aValue);
147 INFOS("SObjectToObject - Unknown exception has occurred!!!");
149 return anObject._retn();
153 * This function provides a CORBA pointer to a servant from its IOR
154 * given as a string of characters.
156 CORBA::Object_ptr IORToObject(char * IOR) {
157 return getORB()->string_to_object(IOR);
161 // __GBO__ See the file ./src/SMESHGUI/SMESHGUI_Utils.h of SMESH_SRC
162 // for other helper functions
165 SALOME::SALOME_Exception createSalomeException(const char * text) {
166 SALOME::ExceptionStruct es;
167 es.type = SALOME::INTERNAL_ERROR;
168 es.text = CORBA::string_dup(text);
169 return SALOME::SALOME_Exception(es);
172 void RegisterCompo(const std::string& compoName, CORBA::Object_var compoPtr)
174 _compo_map[compoName] = compoPtr;
177 CORBA::Object_var RetrieveCompo(const std::string& compoName)
179 auto it = _compo_map.find(compoName);
180 if( it != _compo_map.end() )
186 SALOME::SALOME_Exception ex(createSalomeException("RetrieveCompo : not implemented yet !"));
188 //GetLCC()->FindOrLoad_Component( "FactoryServer", compoName );