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"
24 #include "Utils_SALOME_Exception.hxx"
29 std::map<std::string,CORBA::Object_var> _compo_map;
31 std::unique_ptr<SALOME_NamingService_Abstract> _naming_service;
35 void assignNamingServiceSL()
37 if ( !_naming_service.get() )
39 _naming_service.reset( new SALOME_Fake_NamingService );
43 THROW_SALOME_EXCEPTION("assignNamingServiceSL : NS SALOME Wrapper is already set !");
48 * This function returns a static reference to the SALOME naming service.
50 SALOME_NamingService_Abstract *getNamingService()
52 if ( !_naming_service.get() )
54 _naming_service.reset( new SALOME_NamingService(getORB()) );
56 return _naming_service.get();
60 * This function returns a static reference to the SALOME life cycle CORBA.
62 SALOME_LifeCycleCORBA * getLifeCycleCORBA() {
63 static SALOME_LifeCycleCORBA * lifeCycleCORBA;
64 if ( lifeCycleCORBA == NULL ) {
65 SALOME_NamingService_Abstract *aNamingService = getNamingService();
66 lifeCycleCORBA = new SALOME_LifeCycleCORBA(aNamingService);
68 return lifeCycleCORBA;
73 * This returns a static reference to the SALOME study. The
74 * study can be used to get informations about it.
75 * \sa getStudyServantSA
77 SALOMEDS::Study_ptr getStudyServant() {
78 static SALOMEDS::Study_ptr aStudy;
79 if(CORBA::is_nil(aStudy)){
80 SALOME_NamingService_Abstract *aNamingService = getNamingService();
81 CORBA::Object_ptr anObject = aNamingService->Resolve("/Study");
82 aStudy = SALOMEDS::Study::_narrow(anObject);
84 return SALOMEDS::Study::_duplicate(aStudy); // we duplicate it here to allow using it with the var client instances.
88 * This returns a static reference to the SALOME session. The
89 * SALOME session can be used to retrieve some objects of the
90 * current session, as the SALOME study.
92 SALOME::Session_ptr getSalomeSession() {
93 static SALOME::Session_ptr salomeSession;
94 if(CORBA::is_nil(salomeSession)){
95 SALOME_NamingService_Abstract *aNamingService = getNamingService();
96 CORBA::Object_ptr obj = aNamingService->Resolve("/Kernel/Session");
97 salomeSession = SALOME::Session::_narrow(obj);
103 * This returns a static reference to the SALOME launcher. The
104 * SALOME launcher can be used to schedule jobs, local or remote,
105 * using a batch system or not (see SALOME documentation).
107 Engines::SalomeLauncher_ptr getSalomeLauncher() {
108 //LOG("KERNEL_services::getSalomeLauncher()");
109 static Engines::SalomeLauncher_ptr salomeLauncher;
110 if(CORBA::is_nil(salomeLauncher)){
111 //LOG("KERNEL_services::getSalomeLauncher(): creating the static instance");
112 SALOME_NamingService_Abstract *aNamingService = getNamingService();
113 CORBA::Object_ptr obj = aNamingService->Resolve("/SalomeLauncher");
114 salomeLauncher = Engines::SalomeLauncher::_narrow(obj);
116 return salomeLauncher;
119 Engines::ResourcesManager_ptr getResourcesManager() {
120 static Engines::ResourcesManager_ptr resourcesManager;
121 if(CORBA::is_nil(resourcesManager)){
122 SALOME_NamingService_Abstract *aNamingService = getNamingService();
123 CORBA::Object_ptr obj = aNamingService->Resolve("/ResourcesManager");
124 resourcesManager = Engines::ResourcesManager::_narrow(obj);
126 return resourcesManager;
130 * This function retrieve the CORBA object reference from the study
131 * object wrapping it.
133 CORBA::Object_ptr SObjectToObject(SALOMEDS::SObject_ptr theSObject) {
135 SALOMEDS::GenericAttribute_var anAttr;
136 CORBA::Object_var anObject;
137 if(CORBA::is_nil(theSObject))
140 if(theSObject->FindAttribute(anAttr, "AttributeIOR")){
141 SALOMEDS::AttributeIOR_var anIOR = SALOMEDS::AttributeIOR::_narrow(anAttr);
142 CORBA::String_var aValue = anIOR->Value();
143 CORBA::ORB_ptr anORB = getORB();
144 if(strcmp(aValue,"") != 0)
145 anObject = anORB->string_to_object(aValue);
148 INFOS("SObjectToObject - Unknown exception has occurred!!!");
150 return anObject._retn();
154 * This function provides a CORBA pointer to a servant from its IOR
155 * given as a string of characters.
157 CORBA::Object_ptr IORToObject(char * IOR) {
158 return getORB()->string_to_object(IOR);
162 // __GBO__ See the file ./src/SMESHGUI/SMESHGUI_Utils.h of SMESH_SRC
163 // for other helper functions
166 SALOME::SALOME_Exception createSalomeException(const char * text) {
167 SALOME::ExceptionStruct es;
168 es.type = SALOME::INTERNAL_ERROR;
169 es.text = CORBA::string_dup(text);
170 return SALOME::SALOME_Exception(es);
173 void RegisterCompo(const std::string& compoName, CORBA::Object_var compoPtr)
175 _compo_map[compoName] = compoPtr;
178 CORBA::Object_var RetrieveCompo(const std::string& compoName)
180 CORBA::Object_var ret;
181 auto it = _compo_map.find(compoName);
182 if( it != _compo_map.end() )
188 //SALOME::SALOME_Exception ex(createSalomeException("RetrieveCompo : not implemented yet !"));
190 throw SALOME_Exception("RetrieveCompo : not implemented yet !");
191 //GetLCC()->FindOrLoad_Component( "FactoryServer", compoName );