-// Copyright (C) 2007-2016 CEA/DEN, EDF R&D, OPEN CASCADE
+// Copyright (C) 2007-2020 CEA/DEN, EDF R&D, OPEN CASCADE
//
// This library is free software; you can redistribute it and/or
// modify it under the terms of the GNU Lesser General Public
//
// See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
//
+
// Author: Guillaume Boulant (EDF/R&D)
#include "SALOME_KernelServices.hxx"
+#include "SALOME_Fake_NamingService.hxx"
+
+#include <map>
+#include <memory>
+
+std::map<std::string,CORBA::Object_var> _compo_map;
+
+std::unique_ptr<SALOME_NamingService_Abstract> _naming_service;
namespace KERNEL {
return orb;
}
+ void assignNamingServiceSL()
+ {
+ if ( !_naming_service.get() )
+ {
+ _naming_service.reset( new SALOME_Fake_NamingService );
+ }
+ else
+ {
+ THROW_SALOME_EXCEPTION("assignNamingServiceSL : NS SALOME Wrapper is already set !");
+ }
+ }
+
/**
* This function returns a static reference to the SALOME naming service.
*/
- SALOME_NamingService * getNamingService() {
- static SALOME_NamingService * namingService;
- if ( namingService == NULL ) {
- namingService = new SALOME_NamingService(getORB());
+ SALOME_NamingService_Abstract *getNamingService()
+ {
+ if ( !_naming_service.get() )
+ {
+ _naming_service.reset( new SALOME_NamingService(getORB()) );
}
- return namingService;
+ return _naming_service.get();
}
/**
SALOME_LifeCycleCORBA * getLifeCycleCORBA() {
static SALOME_LifeCycleCORBA * lifeCycleCORBA;
if ( lifeCycleCORBA == NULL ) {
- SALOME_NamingService *aNamingService = getNamingService();
+ SALOME_NamingService_Abstract *aNamingService = getNamingService();
lifeCycleCORBA = new SALOME_LifeCycleCORBA(aNamingService);
}
return lifeCycleCORBA;
/**
- * This returns a static reference to the SALOME study manager. The
- * study manager can be used to retrieve a study or to get
- * information about a study.
+ * This returns a static reference to the SALOME study. The
+ * study can be used to get informations about it.
+ * \sa getStudyServantSA
*/
- SALOMEDS::StudyManager_ptr getStudyManager() {
- static SALOMEDS::StudyManager_ptr aStudyManager;
- if(CORBA::is_nil(aStudyManager)){
- SALOME_NamingService *aNamingService = getNamingService();
- CORBA::Object_ptr anObject = aNamingService->Resolve("/myStudyManager");
- aStudyManager = SALOMEDS::StudyManager::_narrow(anObject);
+ SALOMEDS::Study_ptr getStudyServant() {
+ static SALOMEDS::Study_ptr aStudy;
+ if(CORBA::is_nil(aStudy)){
+ SALOME_NamingService_Abstract *aNamingService = getNamingService();
+ CORBA::Object_ptr anObject = aNamingService->Resolve("/Study");
+ aStudy = SALOMEDS::Study::_narrow(anObject);
}
- return aStudyManager;
+ return SALOMEDS::Study::_duplicate(aStudy); // we duplicate it here to allow using it with the var client instances.
}
/**
SALOME::Session_ptr getSalomeSession() {
static SALOME::Session_ptr salomeSession;
if(CORBA::is_nil(salomeSession)){
- SALOME_NamingService *aNamingService = getNamingService();
+ SALOME_NamingService_Abstract *aNamingService = getNamingService();
CORBA::Object_ptr obj = aNamingService->Resolve("/Kernel/Session");
salomeSession = SALOME::Session::_narrow(obj);
}
static Engines::SalomeLauncher_ptr salomeLauncher;
if(CORBA::is_nil(salomeLauncher)){
//LOG("KERNEL_services::getSalomeLauncher(): creating the static instance");
- SALOME_NamingService *aNamingService = getNamingService();
+ SALOME_NamingService_Abstract *aNamingService = getNamingService();
CORBA::Object_ptr obj = aNamingService->Resolve("/SalomeLauncher");
salomeLauncher = Engines::SalomeLauncher::_narrow(obj);
}
Engines::ResourcesManager_ptr getResourcesManager() {
static Engines::ResourcesManager_ptr resourcesManager;
if(CORBA::is_nil(resourcesManager)){
- SALOME_NamingService *aNamingService = getNamingService();
+ SALOME_NamingService_Abstract *aNamingService = getNamingService();
CORBA::Object_ptr obj = aNamingService->Resolve("/ResourcesManager");
resourcesManager = Engines::ResourcesManager::_narrow(obj);
}
return resourcesManager;
}
- /**
- * This returns the study with the specified id if it's defined in
- * the SALOME study manager. Returns null otherwise.
- * Please not that it is just a shortcut, and you may prefer use
- * directly the study manager:
- * KERNEL::getStudyManager()->GetStudyByID(aStudyId)
- */
- SALOMEDS::Study_ptr getStudyById(int aStudyId) {
- if ( aStudyId < 0 ) {
- INFOS("ERR: trying to get a study with ID<0");
- return SALOMEDS::Study::_nil();
- }
- return getStudyManager()->GetStudyByID(aStudyId);
- }
-
- int getStudyId(SALOMEDS::Study_ptr study) {
- if( CORBA::is_nil(study) ) return -1;
- return study->StudyId();
- }
-
-
/**
* This function retrieve the CORBA object reference from the study
* object wrapping it.
es.text = CORBA::string_dup(text);
return SALOME::SALOME_Exception(es);
}
-
+
+ void RegisterCompo(const std::string& compoName, CORBA::Object_var compoPtr)
+ {
+ _compo_map[compoName] = compoPtr;
+ }
+
+ CORBA::Object_var RetrieveCompo(const std::string& compoName)
+ {
+ auto it = _compo_map.find(compoName);
+ if( it != _compo_map.end() )
+ {
+ return (*it).second;
+ }
+ else
+ {
+ SALOME::SALOME_Exception ex(createSalomeException("RetrieveCompo : not implemented yet !"));
+ throw ex;
+ //GetLCC()->FindOrLoad_Component( "FactoryServer", compoName );
+ }
+ }
}