#include "SALOME_FileTransfer_i.hxx"
#include "Salome_file_i.hxx"
#include "SALOME_NamingService.hxx"
+#include "SALOME_Fake_NamingService.hxx"
#include "Basics_Utils.hxx"
#ifdef _XOPEN_SOURCE
PortableServer::POA_ptr poa,
char *containerName ,
int argc , char* argv[],
- bool activAndRegist,
+ SALOME_NamingService_Abstract *ns,
bool isServantAloneInProcess
) :
_NS(0),_id(0),_numInstance(0),_isServantAloneInProcess(isServantAloneInProcess)
{
_pid = (long)getpid();
- if(activAndRegist)
+ if(ns)
ActSigIntHandler() ;
_argc = argc ;
// Pour les containers paralleles: il ne faut pas enregistrer et activer
// le container generique, mais le container specialise
- if(activAndRegist)
{
_id = _poa->activate_object(this);
- _NS = new SALOME_NamingService();
+ _NS = ns==nullptr ? new SALOME_NamingService : ns->clone();
_NS->init_orb( _orb ) ;
CORBA::Object_var obj=_poa->id_to_reference(*_id);
Engines::Container_var pCont
_tmp_files.clear();
}
-/*
-std::string Engines_Container_i::AnotherMethodeToReplace_PyString_AsString(PyObject * result)
+static Engines_Container_i *_container_singleton_ssl = nullptr;
+
+static Engines::Container_var _container_ref_singleton_ssl;
+
+Engines_Container_i *KERNEL::getContainerSA()
{
- std::string my_result = "";
- if (PyUnicode_Check(result)) {
- // Convert string to bytes.
- // strdup() bytes into my_result.
- PyObject * temp_bytes = PyUnicode_AsEncodedString(result, "ASCII", "strict"); // Owned reference
- if (temp_bytes != NULL) {
- my_result = PyBytes_AS_STRING(temp_bytes); // Borrowed pointer
- my_result = strdup(my_result);
- Py_DECREF(temp_bytes);
- } else {
- // TODO PY3: Handle encoding error.
- Py_DECREF(temp_bytes);
- }
+ if(!_container_singleton_ssl)
+ {
+ int argc(0);
+ CORBA::ORB_var orb = CORBA::ORB_init(argc,nullptr);
+ CORBA::Object_var obj = orb->resolve_initial_references("RootPOA");
+ PortableServer::POA_var poa = PortableServer::POA::_narrow(obj);
+ PortableServer::POAManager_var pman = poa->the_POAManager();
+ CORBA::PolicyList policies;
+ policies.length(0);
+ //
+ char *argv[4] = {"Container","FactoryServer","toto",nullptr};
+ SALOME_Fake_NamingService ns;
+ _container_singleton_ssl = new Engines_Container_i(orb,poa,"FactoryServer",2,argv,&ns,false);
+ PortableServer::ObjectId * cont_id = _container_singleton_ssl->getCORBAId();
+ //
+ CORBA::Object_var zeRef = poa->id_to_reference(*cont_id);
+ _container_ref_singleton_ssl = Engines::Container::_narrow(zeRef);
+ }
+ return _container_singleton_ssl;
+}
- } else if (PyBytes_Check(result)) {
- // strdup() bytes into my_result.
- my_result = PyBytes_AS_STRING(result); // Borrowed pointer
- my_result = strdup(my_result);
- } else {
- // Convert into your favorite string representation.
- // Convert string to bytes if it is not already.
- // strdup() bytes into my_result.
- // TODO PY3: Check if only bytes is ok.
- PyObject * temp_bytes = PyObject_Bytes(result); // Owned reference
- if (temp_bytes != NULL) {
- my_result = PyBytes_AS_STRING(temp_bytes); // Borrowed pointer
- my_result = strdup(my_result);
- Py_DECREF(temp_bytes);
- } else {
- // TODO PY3: Handle error.
- Py_DECREF(temp_bytes);
- }
- }
- return my_result;
+Engines::Container_var KERNEL::getContainerRefSA()
+{
+ getContainerSA();
+ return _container_ref_singleton_ssl;
}
-*/
threadPol->destroy();
PortableServer::ObjectId_var id = _poa->activate_object(this);
CORBA::Object_var obj = _poa->id_to_reference(id);
- Engines::ContainerManager_var refContMan =
- Engines::ContainerManager::_narrow(obj);
-
- _NS->Register(refContMan,_ContainerManagerNameInNS);
+ Engines::ContainerManager_var refContMan = Engines::ContainerManager::_narrow(obj);
+ if(_NS)
+ _NS->Register(refContMan,_ContainerManagerNameInNS);
_isAppliSalomeDefined = (GetenvThreadSafe("APPLI") != 0);
#ifdef HAVE_MPI2
{
MESSAGE("Shutdown");
ShutdownContainers();
- _NS->Destroy_Name(_ContainerManagerNameInNS);
+ if(_NS)
+ _NS->Destroy_Name(_ContainerManagerNameInNS);
PortableServer::ObjectId_var oid = _poa->servant_to_id(this);
_poa->deactivate_object(oid);
}
void SALOME_ContainerManager::ShutdownContainers()
{
MESSAGE("ShutdownContainers");
-
+ if(!_NS)
+ return ;
SALOME::Session_var session = SALOME::Session::_nil();
CORBA::Long pid = 0;
CORBA::Object_var objS = _NS->Resolve("/Kernel/Session");
#include <list>
#include <string>
-class SALOME_NamingService;
+class SALOME_NamingService_Abstract;
class CONTAINER_EXPORT Engines_Container_i:
public virtual POA_Engines::Container,
PortableServer::POA_ptr poa,
char * containerName ,
int argc, char* argv[],
- bool activAndRegist = true,
+ SALOME_NamingService_Abstract *ns = nullptr,
bool isServantAloneInProcess = true);
virtual ~Engines_Container_i();
void registerTemporaryFile( const std::string& fileName );
void unregisterTemporaryFile( const std::string& fileName );
void clearTemporaryFiles();
+ PortableServer::ObjectId *getCORBAId() const { return _id; }
protected:
bool _isSupervContainer;
- SALOME_NamingService *_NS ;
+ SALOME_NamingService_Abstract *_NS ;
std::string _library_path;
std::string _containerName;
std::string _logfilename;
bool _isServantAloneInProcess;
};
+/*!
+ * Methods to be used in SSL mode to skip NS.
+ */
+namespace KERNEL
+{
+ CONTAINER_EXPORT Engines_Container_i *getContainerSA();
+ CONTAINER_EXPORT Engines::Container_var getContainerRefSA();
+}
+
#endif
return oss_.str();
}
- // Surtout ne pas écrire le code suivant:
+ // Surtout ne pas �crire le code suivant:
// car oss_.str() renvoie une string temporaire
// operator const char*()
// {
}; /* end class OSS */
#endif
-
-// Cette fonction provient de Utils_SALOME_Exception
-// Solution pas très élégante mais contrainte par les manques de la classe SALOME_Exception
-const char *makeText( const char *text, const char *fileName, const unsigned int lineNumber);
-
struct DSC_Exception : public SALOME_Exception {
- // Attention, en cas de modification des paramètres par défaut
+ // Attention, en cas de modification des param�tres par d�faut
// il est necessaire de les repporter dans la macro DSC_EXCEPTION ci-dessous
// Le constructeur de la SALOME_Exception demande une chaine non vide
- // Du coup on est obliger de la désallouer avant d'y mettre la notre
+ // Du coup on est obliger de la d�sallouer avant d'y mettre la notre
// car le what n'est pas virtuel donc il faut que le contenu de SALOME_Exception::_text
// soit utilisable.
- // Ne pas mettre lineNumber=0 à cause du calcul log dans la SALOME_Exception si fileName est défini
+ // Ne pas mettre lineNumber=0 � cause du calcul log dans la SALOME_Exception si fileName est d�fini
DSC_Exception( const std::string & text,
const char *fileName="",
const unsigned int lineNumber=0,
const char *funcName="" ):
- SALOME_Exception(text.c_str()) ,
+ SALOME_Exception(text) ,
_dscText(text),
_filefuncName(setFileFuncName(fileName?fileName:"",funcName?funcName:"")),
_lineNumber(lineNumber),
_exceptionName("DSC_Exception")
{
- // Mise en cohérence avec l'exception SALOME (à revoir)
- delete [] ((char*)SALOME_Exception::_text);
if (! _filefuncName.empty() )
SALOME_Exception::_text = makeText(text.c_str(),_filefuncName.c_str(),lineNumber) ;
else
return _what.c_str() ;
}
- // L'opérateur = de SALOME_Exception n'est pas défini
- // problème potentiel concernant la recopie de son pointeur _text
+ // L'op�rateur = de SALOME_Exception n'est pas d�fini
+ // probl�me potentiel concernant la recopie de son pointeur _text
- // Le destructeur de la SALOME_Exception devrait être virtuel
+ // Le destructeur de la SALOME_Exception devrait �tre virtuel
// sinon pb avec nos attributs de type pointeur.
virtual ~DSC_Exception(void) noexcept {};
virtual ~Derived(void) noexcept;\
};\
-//Sert à eviter le problème d'identification RTTI des exceptions
-//Crée un unique typeInfo pour tous les bibliothèques composants SALOME
+//Sert � eviter le probl�me d'identification RTTI des exceptions
+//Cr�e un unique typeInfo pour tous les biblioth�ques composants SALOME
//dans un fichier cxx
#define DSC_EXCEPTION_CXX(NameSpace,Derived) NameSpace::Derived::~Derived(void) noexcept {}
LOG("TEST_Corba: orb ERROR");
return false;
}
- SALOME_NamingService * ns = KERNEL::getNamingService();
+ SALOME_NamingService_Abstract * ns = KERNEL::getNamingService();
if ( ns == NULL ) {
LOG("TEST_Corba: ns ERROR");
return false;
// 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;
SALOMEDS::Study_ptr getStudyServant() {
static SALOMEDS::Study_ptr aStudy;
if(CORBA::is_nil(aStudy)){
- SALOME_NamingService *aNamingService = getNamingService();
+ SALOME_NamingService_Abstract *aNamingService = getNamingService();
CORBA::Object_ptr anObject = aNamingService->Resolve("/Study");
aStudy = SALOMEDS::Study::_narrow(anObject);
}
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);
}
// ---------------------------------------------
// SALOME KERNEL main services
KERNELHELPERS_EXPORT CORBA::ORB_ptr getORB();
- KERNELHELPERS_EXPORT SALOME_NamingService * getNamingService();
+ KERNELHELPERS_EXPORT SALOME_NamingService_Abstract *getNamingService();
+ KERNELHELPERS_EXPORT void assignNamingServiceSL();
KERNELHELPERS_EXPORT SALOME_LifeCycleCORBA * getLifeCycleCORBA();
KERNELHELPERS_EXPORT SALOME::Session_ptr getSalomeSession();
KERNELHELPERS_EXPORT SALOMEDS::Study_ptr getStudyServant();
CPPUNIT_ASSERT(!CORBA::is_nil(orb));
- SALOME_NamingService * ns = KERNEL::getNamingService();
+ SALOME_NamingService_Abstract * ns = KERNEL::getNamingService();
CPPUNIT_ASSERT(ns!=NULL);
SALOME_LifeCycleCORBA * lcc = KERNEL::getLifeCycleCORBA();
* \param orb
*/
//=============================================================================
-SALOME_Launcher::SALOME_Launcher(CORBA::ORB_ptr orb, PortableServer::POA_var poa) : _l()
+SALOME_Launcher::SALOME_Launcher(CORBA::ORB_ptr orb, PortableServer::POA_var poa)
{
MESSAGE("SALOME_Launcher constructor");
_NS = new SALOME_NamingService(orb);
- _ResManager = new SALOME_ResourcesManager(orb,poa,_NS);
+ init(orb,poa);
+ MESSAGE("SALOME_Launcher constructor end");
+}
+
+SALOME_Launcher::SALOME_Launcher(CORBA::ORB_ptr orb, PortableServer::POA_var poa, SALOME_NamingService_Abstract *externalNS):_NS(externalNS)
+{
+ init(orb,poa);
+}
+
+void SALOME_Launcher::init(CORBA::ORB_ptr orb, PortableServer::POA_var poa)
+{
+ _ResManager = new SALOME_ResourcesManager(orb,poa,tradNS());
_l.SetResourcesManager(_ResManager->GetImpl());
- _ContManager = new SALOME_ContainerManager(orb,poa,_NS);
+ _ContManager = new SALOME_ContainerManager(orb,poa,tradNS());
_ResManager->_remove_ref();
_ContManager->_remove_ref();
PortableServer::ObjectId_var id = _poa->activate_object(this);
CORBA::Object_var obj = _poa->id_to_reference(id);
Engines::SalomeLauncher_var refContMan = Engines::SalomeLauncher::_narrow(obj);
-
_NS->Register(refContMan,_LauncherNameInNS);
- MESSAGE("SALOME_Launcher constructor end");
}
//=============================================================================
void SALOME_Launcher::Shutdown()
{
MESSAGE("Shutdown");
+ if(!_NS)
+ return;
_NS->Destroy_Name(_LauncherNameInNS);
_ContManager->Shutdown();
_ResManager->Shutdown();
result->launcher_args = CORBA::string_dup(job_parameters.launcher_args.c_str());
return result;
}
+
+static SALOME_Launcher *_launcher_singleton_ssl = nullptr;
+
+#include "SALOME_Fake_NamingService.hxx"
+
+SALOME_Launcher *KERNEL::getLauncherSA()
+{
+ if(!_launcher_singleton_ssl)
+ {
+ int argc(0);
+ CORBA::ORB_var orb = CORBA::ORB_init(argc,nullptr);
+ PortableServer::POA_var root_poa=PortableServer::POA::_the_root_poa();
+ SALOME_Fake_NamingService *ns=new SALOME_Fake_NamingService(orb);
+ _launcher_singleton_ssl = new SALOME_Launcher(orb,root_poa,ns);//3rd arg is important to skip NS !
+ }
+ return _launcher_singleton_ssl;
+}
#include "SALOME_Launcher_defs.hxx"
-#include <SALOMEconfig.h>
+#include "SALOME_NamingService.hxx"
+#include "SALOMEconfig.h"
#include CORBA_CLIENT_HEADER(SALOME_Launcher)
#include "Launcher.hxx"
#include <string>
#include <list>
-class SALOME_NamingService;
class SALOME_ContainerManager;
class SALOME_ResourcesManager;
public:
SALOME_Launcher(CORBA::ORB_ptr orb, PortableServer::POA_var poa);
+ SALOME_Launcher(CORBA::ORB_ptr orb, PortableServer::POA_var poa, SALOME_NamingService_Abstract *externalNS);
virtual ~SALOME_Launcher();
-
// Main methods
CORBA::Long createJob (const Engines::JobParameters & job_parameters);
void launchJob (CORBA::Long job_id);
static Engines::JobParameters_var
JobParameters_CPP2CORBA(const JobParameters_cpp& job_parameters);
+ SALOME_NamingService *tradNS() { return SALOME_NamingService::GetTraditionalNS(_NS); }
+
protected:
// Internal methods
virtual void notifyObservers(const std::string & event_name, const std::string & event_data);
-
+ void init(CORBA::ORB_ptr orb, PortableServer::POA_var poa);
protected:
CORBA::ORB_var _orb;
PortableServer::POA_var _poa;
SALOME_ContainerManager *_ContManager;
SALOME_ResourcesManager *_ResManager;
- SALOME_NamingService *_NS;
+ SALOME_NamingService_Abstract *_NS = nullptr;
std::list<Engines::SalomeLauncherObserver_var> _observers;
Launcher_cpp _l;
};
+/*!
+ * Methods to be used in SSL mode to skip NS.
+ */
+namespace KERNEL
+{
+ SALOMELAUNCHER_EXPORT SALOME_Launcher *getLauncherSA();
+}
+
#endif
*/
//=============================================================================
-SALOME_LifeCycleCORBA::SALOME_LifeCycleCORBA(SALOME_NamingService *ns)
+SALOME_LifeCycleCORBA::SALOME_LifeCycleCORBA(SALOME_NamingService_Abstract *ns)
{
// be sure to have an instance of traceCollector, when used via SWIG
// in a Python module
// not enough: set a current directory in naming service is not thread safe
// if naming service instance is shared among several threads...
// ==> always use absolute path and don't rely on current directory!
-
- CORBA::Object_var obj =
- _NS->Resolve(SALOME_ContainerManager::_ContainerManagerNameInNS);
- if (CORBA::is_nil(obj))
- throw SALOME_Exception("Error: Cannot resolve ContainerManager in Naming Service");
- _ContManager=Engines::ContainerManager::_narrow(obj);
-
- obj = _NS->Resolve(SALOME_ResourcesManager::_ResourcesManagerNameInNS);
- if (CORBA::is_nil(obj))
- throw SALOME_Exception("Error: Cannot resolve ResourceManager in Naming Service");
- _ResManager=Engines::ResourcesManager::_narrow(obj);
+ if( dynamic_cast<SALOME_NamingService *>(_NS) )
+ {
+ CORBA::Object_var obj =
+ _NS->Resolve(SALOME_ContainerManager::_ContainerManagerNameInNS);
+ if (CORBA::is_nil(obj))
+ throw SALOME_Exception("Error: Cannot resolve ContainerManager in Naming Service");
+ _ContManager=Engines::ContainerManager::_narrow(obj);
+
+ obj = _NS->Resolve(SALOME_ResourcesManager::_ResourcesManagerNameInNS);
+ if (CORBA::is_nil(obj))
+ throw SALOME_Exception("Error: Cannot resolve ResourceManager in Naming Service");
+ _ResManager=Engines::ResourcesManager::_narrow(obj);
+ }
}
//=============================================================================
*
* \return the naming service
*/
-SALOME_NamingService * SALOME_LifeCycleCORBA::namingService()
+SALOME_NamingService_Abstract * SALOME_LifeCycleCORBA::namingService()
{
return _NS;
}
*/
CORBA::ORB_ptr SALOME_LifeCycleCORBA::orb()
{
- return _NS->orb();
+ SALOME_NamingService *NSC = dynamic_cast<SALOME_NamingService *>(_NS);
+ if(!_NS)
+ THROW_SALOME_EXCEPTION("SALOME_LifeCycleCORBA::orb : not a CORBA SALOME_NamingService ");
+ return NSC->orb();
}
#endif
-class SALOME_NamingService;
+class SALOME_NamingService_Abstract;
class LIFECYCLECORBA_EXPORT IncompatibleComponent : public SALOME_Exception
{
class LIFECYCLECORBA_EXPORT SALOME_LifeCycleCORBA
{
public:
- SALOME_LifeCycleCORBA(SALOME_NamingService *ns = 0);
+ SALOME_LifeCycleCORBA(SALOME_NamingService_Abstract *ns = 0);
virtual ~SALOME_LifeCycleCORBA();
Engines::EngineComponent_ptr
Engines::ContainerManager_ptr getContainerManager();
Engines::ResourcesManager_ptr getResourcesManager();
- SALOME_NamingService * namingService();
+ SALOME_NamingService_Abstract * namingService();
CORBA::ORB_ptr orb();
void copyFile(const char* hostSrc, const char* fileSrc, const char* hostDest, const char* fileDest);
_LoadComponent(const Engines::ContainerParameters& params,
const char *componentName);
- SALOME_NamingService *_NS;
- SALOME_NamingService *_NSnew;
+ SALOME_NamingService_Abstract *_NS;
+ SALOME_NamingService_Abstract *_NSnew;
Engines::ContainerManager_var _ContManager;
Engines::ResourcesManager_var _ResManager;
SALOME_NamingService.cxx
ServiceUnreachable.cxx
NamingService_WaitForServerReadiness.cxx
+ SALOME_Fake_NamingService.cxx
+ SALOME_NamingService_Abstract.cxx
)
// $Header$
//
#include "NamingService_WaitForServerReadiness.hxx"
+#include "SALOME_NamingService.hxx"
+
#include "utilities.h"
#include <iostream>
#include <ctime>
exit(EXIT_FAILURE);
}
}
+
+/*!
+ * Fake NS : no need to wait ;)
+ */
+void NamingService_WaitForServerReadiness(SALOME_Fake_NamingService* NS, std::string serverName)
+{
+}
#ifndef _NAMINGSERVICE_WAITFORSERVERREADINESS_HXX_
#define _NAMINGSERVICE_WAITFORSERVERREADINESS_HXX_
-#include "SALOME_NamingService.hxx"
+#include "SALOME_NamingService_defs.hxx"
#include <string>
-void NAMINGSERVICE_EXPORT NamingService_WaitForServerReadiness(SALOME_NamingService* NS,
- std::string serverName);
+class SALOME_NamingService;
+
+void NAMINGSERVICE_EXPORT NamingService_WaitForServerReadiness(SALOME_NamingService* NS, std::string serverName);
+
+class SALOME_Fake_NamingService;
+
+void NAMINGSERVICE_EXPORT NamingService_WaitForServerReadiness(SALOME_Fake_NamingService* NS, std::string serverName);
#endif
--- /dev/null
+// Copyright (C) 2021 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
+// License as published by the Free Software Foundation; either
+// version 2.1 of the License, or (at your option) any later version.
+//
+// This library is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+// Lesser General Public License for more details.
+//
+// You should have received a copy of the GNU Lesser General Public
+// License along with this library; if not, write to the Free Software
+// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
+//
+// See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
+//
+
+#include "SALOME_Fake_NamingService.hxx"
+#include "Utils_SALOME_Exception.hxx"
+
+std::mutex SALOME_Fake_NamingService::_mutex;
+std::map<std::string,CORBA::Object_var> SALOME_Fake_NamingService::_map;
+
+SALOME_Fake_NamingService::SALOME_Fake_NamingService(CORBA::ORB_ptr orb)
+{
+}
+
+void SALOME_Fake_NamingService::init_orb(CORBA::ORB_ptr orb)
+{
+}
+
+void SALOME_Fake_NamingService::Register(CORBA::Object_ptr ObjRef, const char* Path)
+{
+ std::lock_guard<std::mutex> g(_mutex);
+ CORBA::Object_var ObjRefAuto = CORBA::Object::_duplicate(ObjRef);
+ _map[Path] = ObjRefAuto;
+}
+
+void SALOME_Fake_NamingService::Destroy_Name(const char* Path)
+{
+}
+
+void SALOME_Fake_NamingService::Destroy_Directory(const char* Path)
+{
+}
+
+void SALOME_Fake_NamingService::Destroy_FullDirectory(const char* Path)
+{
+}
+
+bool SALOME_Fake_NamingService::Change_Directory(const char* Path)
+{
+ return true;
+}
+
+std::vector<std::string> SALOME_Fake_NamingService::list_subdirs()
+{
+ return std::vector<std::string>();
+}
+
+std::vector<std::string> SALOME_Fake_NamingService::list_directory()
+{
+ return std::vector<std::string>();
+}
+
+CORBA::Object_ptr SALOME_Fake_NamingService::Resolve(const char* Path)
+{
+ std::string pathCpp(Path);
+ auto it = _map.find(pathCpp);
+ if( it != _map.end() )
+ return CORBA::Object::_duplicate((*it).second);
+ return CORBA::Object::_nil();
+}
+
+CORBA::Object_ptr SALOME_Fake_NamingService::ResolveFirst(const char* Path)
+{
+ return CORBA::Object::_nil();
+}
+
+SALOME_NamingService_Abstract *SALOME_Fake_NamingService::clone()
+{
+ return new SALOME_Fake_NamingService;
+}
+
+CORBA::Object_ptr SALOME_Fake_NamingService::ResolveComponent(const char* hostname, const char* containerName, const char* componentName, const int nbproc)
+{
+ THROW_SALOME_EXCEPTION("SALOME_Fake_NamingService::ResolveComponent : " << hostname << " " << containerName << " " << componentName << " " << nbproc);
+}
--- /dev/null
+// Copyright (C) 2021 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
+// License as published by the Free Software Foundation; either
+// version 2.1 of the License, or (at your option) any later version.
+//
+// This library is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+// Lesser General Public License for more details.
+//
+// You should have received a copy of the GNU Lesser General Public
+// License along with this library; if not, write to the Free Software
+// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
+//
+// See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
+//
+
+#pragma once
+
+#include "omniORB4/CORBA.h"
+
+#include "SALOME_NamingService_Abstract.hxx"
+
+#include <mutex>
+#include <string>
+#include <map>
+
+class NAMINGSERVICE_EXPORT SALOME_Fake_NamingService : public SALOME_NamingService_Abstract
+{
+public:
+ SALOME_Fake_NamingService(CORBA::ORB_ptr orb);
+ SALOME_Fake_NamingService() = default;
+ void init_orb(CORBA::ORB_ptr orb=0) override;
+ void Register(CORBA::Object_ptr ObjRef, const char* Path) override;
+ CORBA::Object_ptr Resolve(const char* Path) override;
+ CORBA::Object_ptr ResolveFirst(const char* Path) override;
+ void Destroy_Name(const char* Path) override;
+ void Destroy_Directory(const char* Path) override;
+ void Destroy_FullDirectory(const char* Path) override;
+ bool Change_Directory(const char* Path) override;
+ std::vector<std::string> list_subdirs() override;
+ std::vector<std::string> list_directory() override;
+ SALOME_NamingService_Abstract *clone() override;
+ CORBA::Object_ptr ResolveComponent(const char* hostname, const char* containerName, const char* componentName, const int nbproc=0) override;
+private:
+ static std::mutex _mutex;
+ static std::map<std::string,CORBA::Object_var> _map;
+};
_initialize_root_context();
}
+SALOME_NamingService_Abstract *SALOME_NamingService::clone()
+{
+ return new SALOME_NamingService(_orb);
+}
+
// ============================================================================
/*! \brief Standard destructor.
*
//MESSAGE("SALOME_NamingService destruction");
}
+SALOME_NamingService *SALOME_NamingService::GetTraditionalNS(SALOME_NamingService_Abstract *ns)
+{
+ SALOME_NamingService *nsc(dynamic_cast<SALOME_NamingService *>(ns));
+ return nsc;
+}
+
// ============================================================================
/*! \brief initializes ORB reference and naming service root context.
*
}
}
-// ============================================================================
-/*! \brief provide a default container name if empty.
- *
- * the given container name is returned unchanged, unless it is empty.
- * \param containerName
- * \return container name, where empty input is replaced by "FactoryServer",
- * without the path.
- * \sa BuildContainerNameForNS(const char *containerName, const char *hostname)
- */
-// ============================================================================
-
-std::string SALOME_NamingService::ContainerName(const char *containerName)
-{
- std::string ret,containerNameCpp(containerName);
-
- if (containerNameCpp.empty())
- ret = "FactoryServer";
- else
- ret = containerName;
-
- return ret;
-}
-
// ============================================================================
/*! \brief build a container name, given a ContainerParameters struct.
*
else
nbproc = params.nb_proc;
- std::string ret(ContainerName(params.container_name));
+ std::string ret(SALOME_NamingService_Abstract::ContainerName(params.container_name));
if ( nbproc >= 1 )
{
return ret;
}
-// ============================================================================
-/*! \brief build a string representing a container in Naming Service.
- *
- * Build a string representing the absolute pathname of a container in
- * SALOME_NamingService. This form gives a suffixed containerName in case of
- * multi processor machine.
- * \param containerName name of the container in which the component is
- instantiated.
- * \param hostname name of the host of the container, without domain names.
- * \return the path under the form /Containers/hostname/containerName
- * \sa ContainerName(const Engines::MachineParameters& params)
- */
-// ============================================================================
-
-std::string SALOME_NamingService::BuildContainerNameForNS(const char *containerName, const char *hostname)
-{
- std::string ret("/Containers/");
- ret += hostname;
- ret += "/";
- ret += ContainerName(containerName);
-
- return ret;
-}
-
// ============================================================================
/*! \brief build a string representing a container in Naming Service.
*
#include "Utils_Mutex.hxx"
#include "ServiceUnreachable.hxx"
-#include "SALOME_NamingService_defs.hxx"
+#include "SALOME_NamingService_Abstract.hxx"
#ifdef WIN32
//#pragma warning(disable:4290) // Warning Exception ...
#endif
-class NAMINGSERVICE_EXPORT SALOME_NamingService
+class NAMINGSERVICE_EXPORT SALOME_NamingService : public SALOME_NamingService_Abstract
{
public:
SALOME_NamingService();
SALOME_NamingService(CORBA::ORB_ptr orb);
virtual ~SALOME_NamingService();
+
+ static SALOME_NamingService *GetTraditionalNS(SALOME_NamingService_Abstract *ns);
- void init_orb(CORBA::ORB_ptr orb=0);
- void Register(CORBA::Object_ptr ObjRef, const char* Path) ;
- CORBA::Object_ptr Resolve(const char* Path) ;
+ void init_orb(CORBA::ORB_ptr orb=0) override;
+ void Register(CORBA::Object_ptr ObjRef, const char* Path) override;
+ CORBA::Object_ptr Resolve(const char* Path) override;
CORBA::Object_ptr ResolveFirst(const char* Path) ;
CORBA::Object_ptr ResolveComponent(const char* hostname,
const char* containerName,
const char* componentName,
- const int nbproc=0) ;
- std::string ContainerName(const char *ContainerName);
+ const int nbproc=0) override;
std::string ContainerName(const Engines::ContainerParameters& params);
- std::string BuildContainerNameForNS(const char *ContainerName, const char *hostname);
std::string BuildContainerNameForNS(const Engines::ContainerParameters& params, const char *hostname);
int Find(const char* name) ;
bool Create_Directory(const char* Path) ;
- bool Change_Directory(const char* Path) ;
+ bool Change_Directory(const char* Path) override;
char* Current_Directory() ;
void list() ;
- std::vector<std::string> list_directory() ;
- std::vector<std::string> list_subdirs() ;
+ std::vector<std::string> list_directory() override;
+ std::vector<std::string> list_subdirs() override;
std::vector<std::string> list_directory_recurs() ;
- void Destroy_Name(const char* Path) ;
- virtual void Destroy_Directory(const char* Path) ;
- virtual void Destroy_FullDirectory(const char* Path) ;
+ void Destroy_Name(const char* Path) override;
+ void Destroy_Directory(const char* Path) override;
+ void Destroy_FullDirectory(const char* Path) override;
char *getIORaddr();
CORBA::ORB_ptr orb();
+ SALOME_NamingService_Abstract *clone() override;
protected:
Utils_Mutex _myMutex;
--- /dev/null
+// Copyright (C) 2021 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
+// License as published by the Free Software Foundation; either
+// version 2.1 of the License, or (at your option) any later version.
+//
+// This library is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+// Lesser General Public License for more details.
+//
+// You should have received a copy of the GNU Lesser General Public
+// License along with this library; if not, write to the Free Software
+// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
+//
+// See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
+//
+
+#include "SALOME_NamingService_Abstract.hxx"
+
+// ============================================================================
+/*! \brief provide a default container name if empty.
+ *
+ * the given container name is returned unchanged, unless it is empty.
+ * \param containerName
+ * \return container name, where empty input is replaced by "FactoryServer",
+ * without the path.
+ * \sa BuildContainerNameForNS(const char *containerName, const char *hostname)
+ */
+// ============================================================================
+
+std::string SALOME_NamingService_Abstract::ContainerName(const char *containerName)
+{
+ std::string ret,containerNameCpp(containerName);
+
+ if (containerNameCpp.empty())
+ ret = "FactoryServer";
+ else
+ ret = containerName;
+
+ return ret;
+}
+
+// ============================================================================
+/*! \brief build a string representing a container in Naming Service.
+ *
+ * Build a string representing the absolute pathname of a container in
+ * SALOME_NamingService. This form gives a suffixed containerName in case of
+ * multi processor machine.
+ * \param containerName name of the container in which the component is
+ instantiated.
+ * \param hostname name of the host of the container, without domain names.
+ * \return the path under the form /Containers/hostname/containerName
+ * \sa ContainerName(const Engines::MachineParameters& params)
+ */
+// ============================================================================
+
+std::string SALOME_NamingService_Abstract::BuildContainerNameForNS(const char *containerName, const char *hostname)
+{
+ std::string ret("/Containers/");
+ ret += hostname;
+ ret += "/";
+ ret += ContainerName(containerName);
+
+ return ret;
+}
--- /dev/null
+// Copyright (C) 2021 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
+// License as published by the Free Software Foundation; either
+// version 2.1 of the License, or (at your option) any later version.
+//
+// This library is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+// Lesser General Public License for more details.
+//
+// You should have received a copy of the GNU Lesser General Public
+// License along with this library; if not, write to the Free Software
+// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
+//
+// See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
+//
+
+#pragma once
+
+#include "SALOME_NamingService_defs.hxx"
+
+#include "omniORB4/CORBA.h"
+
+#include <vector>
+#include <string>
+
+class NAMINGSERVICE_EXPORT SALOME_NamingService_Abstract
+{
+public:
+ virtual void init_orb(CORBA::ORB_ptr orb=0) = 0;
+ virtual void Register(CORBA::Object_ptr ObjRef, const char* Path) = 0;
+ virtual CORBA::Object_ptr Resolve(const char* Path) = 0;
+ virtual CORBA::Object_ptr ResolveFirst(const char* Path) = 0;
+ virtual void Destroy_Name(const char* Path) = 0;
+ virtual void Destroy_Directory(const char* Path) = 0;
+ virtual void Destroy_FullDirectory(const char* Path) = 0;
+ virtual bool Change_Directory(const char* Path) = 0;
+ virtual std::vector<std::string> list_subdirs() = 0;
+ virtual std::vector<std::string> list_directory() = 0;
+ virtual SALOME_NamingService_Abstract *clone() = 0;
+ virtual CORBA::Object_ptr ResolveComponent(const char* hostname, const char* containerName, const char* componentName, const int nbproc=0) = 0;
+ virtual ~SALOME_NamingService_Abstract() { }
+ static std::string ContainerName(const char *ContainerName);
+ static std::string BuildContainerNameForNS(const char *ContainerName, const char *hostname);
+};
NamingServiceTest::testContainerName()
{
std::string ref0 = "FactoryServer";
- std::string ret = _NS.ContainerName("");
+ std::string ret = SALOME_NamingService_Abstract::ContainerName("");
CPPUNIT_ASSERT(ret == ref0);
ref0 = "MyContainerName";
- ret = _NS.ContainerName(ref0.c_str());
+ ret = SALOME_NamingService_Abstract::ContainerName(ref0.c_str());
CPPUNIT_ASSERT(ret == ref0);
}
NamingServiceTest::testBuildContainerNameForNS()
{
std::string ref0 = "/Containers/theHostName/theContainerName";
- std::string ret = _NS.BuildContainerNameForNS("theContainerName","theHostName");
+ std::string ret = SALOME_NamingService_Abstract::BuildContainerNameForNS("theContainerName","theHostName");
CPPUNIT_ASSERT(ret == ref0);
ref0 = "/Containers/theHostName/FactoryServer";
- ret = _NS.BuildContainerNameForNS("","theHostName");
+ ret = SALOME_NamingService_Abstract::BuildContainerNameForNS("","theHostName");
CPPUNIT_ASSERT(ret == ref0);
}
PortableServer::ObjectId_var id = _poa->activate_object(this);
CORBA::Object_var obj = _poa->id_to_reference(id);
Engines::ResourcesManager_var refContMan = Engines::ResourcesManager::_narrow(obj);
- _NS->Register(refContMan,_ResourcesManagerNameInNS);
+ if(_NS)
+ _NS->Register(refContMan,_ResourcesManagerNameInNS);
MESSAGE("SALOME_ResourcesManager constructor end");
}
void SALOME_ResourcesManager::Shutdown()
{
MESSAGE("Shutdown");
+ if(!_NS)
+ return ;
_NS->Destroy_Name(_ResourcesManagerNameInNS);
PortableServer::ObjectId_var oid = _poa->servant_to_id(this);
_poa->deactivate_object(oid);
#include "SALOMEDSClient.hxx"
#include "SALOMEDSClient_IParameters.hxx"
#include "SALOMEDS_IParameters.hxx"
+#include "SALOME_Fake_NamingService.hxx"
#include "SALOMEDS_Defines.hxx"
return new SALOMEDS_StudyBuilder(theBuilder);
}
- SALOMEDS_EXPORT
- void CreateStudy(CORBA::ORB_ptr orb, PortableServer::POA_ptr root_poa)
+ void CreateStudyNSAbstract(CORBA::ORB_ptr orb, PortableServer::POA_ptr root_poa, SALOME_NamingService_Abstract& namingService)
{
- SALOME_NamingService namingService(orb);
CORBA::Object_var obj = namingService.Resolve( "/Study" );
SALOMEDS::Study_var aStudy = SALOMEDS::Study::_narrow( obj );
if( CORBA::is_nil(aStudy) ) {
threadPol->destroy();
SALOMEDS_Study_i::SetThePOA(poa);
- SALOMEDS_Study_i* aStudy_i = new SALOMEDS_Study_i(orb);
+ SALOMEDS_Study_i* aStudy_i = new SALOMEDS_Study_i(orb,&namingService);
// Activate the objects. This tells the POA that the objects are ready to accept requests.
PortableServer::ObjectId_var aStudy_iid = root_poa->activate_object(aStudy_i);
aStudy = aStudy_i->_this();
+ KERNEL::setStudyServantSA(aStudy,poa);
namingService.Register(aStudy, "/Study");
aStudy_i->GetImpl()->GetDocument()->SetModified(false);
aStudy_i->_remove_ref();
}
}
+ SALOMEDS_EXPORT
+ void CreateStudy(CORBA::ORB_ptr orb, PortableServer::POA_ptr root_poa)
+ {
+ SALOME_NamingService namingService(orb);
+ CreateStudyNSAbstract(orb,root_poa,namingService);
+ }
+
+ SALOMEDS_EXPORT
+ void CreateStudyWithoutNS(CORBA::ORB_ptr orb, PortableServer::POA_ptr root_poa)
+ {
+ SALOME_Fake_NamingService namingService(orb);
+ CreateStudyNSAbstract(orb,root_poa,namingService);
+ }
+
SALOMEDS_EXPORT
SALOMEDSClient_IParameters* GetIParameters(const _PTR(AttributeParameter)& ap)
{
// SALOMEDS_DriverFactory
//###############################################################################################################
-SALOMEDS_DriverFactory_i::SALOMEDS_DriverFactory_i(CORBA::ORB_ptr theORB, bool isNSAvail)
+SALOMEDS_DriverFactory_i::SALOMEDS_DriverFactory_i(CORBA::ORB_ptr theORB, bool isNSAvail):_orb( CORBA::ORB::_duplicate(theORB) )
{
- _orb = CORBA::ORB::_duplicate(theORB);
if(isNSAvail)
_name_service = new SALOME_NamingService(_orb);
}
+SALOMEDS_DriverFactory_i::SALOMEDS_DriverFactory_i(CORBA::ORB_ptr theORB, SALOME_NamingService_Abstract *ns):_orb( CORBA::ORB::_duplicate(theORB) )
+{
+ _name_service = ns->clone();
+}
SALOMEDS_DriverFactory_i::~SALOMEDS_DriverFactory_i()
{
{
protected:
CORBA::ORB_var _orb;
- SALOME_NamingService* _name_service = nullptr;
+ SALOME_NamingService_Abstract* _name_service = nullptr;
public:
SALOMEDS_DriverFactory_i(CORBA::ORB_ptr theORB, bool isNSAvail = true);
+
+ SALOMEDS_DriverFactory_i(CORBA::ORB_ptr theORB, SALOME_NamingService_Abstract *ns);
virtual ~SALOMEDS_DriverFactory_i();
static SALOMEDS_Driver_i* GetDriver(const SALOMEDSImpl_SObject& theObject, CORBA::ORB_ptr orb);
-static PortableServer::POA_ptr _poa;
+static PortableServer::POA_var _poa;
+static SALOMEDS::Study_var _study;
/**
* Return a unique study obj but servant is embeded here.
*/
SALOMEDS::Study_ptr KERNEL::getStudyServantSA()
{
- static SALOMEDS::Study_ptr aStudy;
- if(CORBA::is_nil(aStudy))
+
+ if(CORBA::is_nil(_study))
{
CORBA::ORB_ptr orb = KERNEL::getORB();
CORBA::Object_var obj = orb->resolve_initial_references("RootPOA");
PortableServer::POA_var poa = PortableServer::POA::_narrow(obj);
_poa = PortableServer::POA::_duplicate(poa);
SALOMEDS_Study_i *servant = new SALOMEDS_Study_i(orb,SALOME::Session::_nil());
- aStudy = servant->_this();
+ _study = servant->_this();
+ }
+ return SALOMEDS::Study::_duplicate(_study);
+}
+
+/**
+ * If a study is already built and activated elsewhere (for example in GUI context)
+ */
+void KERNEL::setStudyServantSA(SALOMEDS::Study_var study, PortableServer::POA_var poa)
+{
+ if( ! CORBA::is_nil(_study) )
+ {
+ PortableServer::ServantBase *serv = nullptr;
+ try
+ {
+ serv = _poa->reference_to_servant(_study);
+ }
+ catch(...) { }
+ if(serv)
+ serv->_remove_ref();
}
- return SALOMEDS::Study::_duplicate(aStudy);
+ _study = study; _poa = poa;
}
namespace SALOMEDS
void sendMessageToGUI(const char* msg )
{
- SALOME_NamingService *aNamingService = KERNEL::getNamingService();
+ SALOME_NamingService_Abstract *aNamingService = KERNEL::getNamingService();
CORBA::Object_var obj = aNamingService->Resolve("/Kernel/Session");
SALOME::Session_var aSession = SALOME::Session::_narrow(obj);
sendMessageToGUIGivenSession(aSession,msg);
} // namespace SALOMEDS
-SALOMEDS_Study_i::SALOMEDS_Study_i(CORBA::ORB_ptr orb)
+SALOMEDS_Study_i::SALOMEDS_Study_i(CORBA::ORB_ptr orb, SALOME_NamingService_Abstract *ns)
{
+ SALOME_NamingService_Abstract *aNamingService = ns==nullptr?KERNEL::getNamingService():ns;
_orb = CORBA::ORB::_duplicate(orb);
_impl = new SALOMEDSImpl_Study();
- _factory = new SALOMEDS_DriverFactory_i(_orb);
+ _factory = new SALOMEDS_DriverFactory_i(_orb,aNamingService);
_closed = true;
- SALOME_NamingService *aNamingService = KERNEL::getNamingService();
CORBA::Object_var obj = aNamingService->Resolve("/Kernel/Session");
SALOME::Session_var aSession = SALOME::Session::_narrow(obj);
Init(aSession);
void SALOMEDS_Study_i::Init()
{
- SALOME_NamingService *aNamingService = KERNEL::getNamingService();
+ SALOME_NamingService_Abstract *aNamingService = KERNEL::getNamingService();
CORBA::Object_var obj = aNamingService->Resolve("/Kernel/Session");
SALOME::Session_var aSession = SALOME::Session::_narrow(obj);
Init(aSession);
_impl->URL(Kernel_Utils::encode_s(wurl));
// update desktop title with new study name
- SALOME_NamingService *aNamingService = KERNEL::getNamingService();
+ SALOME_NamingService_Abstract *aNamingService = KERNEL::getNamingService();
CORBA::Object_var obj = aNamingService->Resolve("/Kernel/Session");
SALOME::Session_var aSession = SALOME::Session::_narrow(obj);
NameChanged(aSession);
#include "SALOMEDSImpl_Study.hxx"
#include "SALOMEDSImpl_AttributeIOR.hxx"
+class SALOME_NamingService_Abstract;
+
namespace KERNEL
{
Standard_EXPORT SALOMEDS::Study_ptr getStudyServantSA();
+ Standard_EXPORT void setStudyServantSA(SALOMEDS::Study_var study, PortableServer::POA_var poa);
}
class Standard_EXPORT SALOMEDS_Study_i: public POA_SALOMEDS::Study
public:
//! standard constructor
- SALOMEDS_Study_i(CORBA::ORB_ptr);
+ SALOMEDS_Study_i(CORBA::ORB_ptr, SALOME_NamingService_Abstract * = nullptr);
//! standard constructor
SALOMEDS_Study_i(CORBA::ORB_ptr, SALOME::Session_ptr session);
#endif
#endif
-#define SOBJECT_FACTORY "SObjectFactory"
-#define SCOMPONENT_FACTORY "SComponentFactory"
-#define STUDY_FACTORY "StudyFactory"
-#define STUDY_CREATE "CreateStudy"
-#define BUILDER_FACTORY "BuilderFactory"
-#define GET_PARAMETERS "GetIParameters"
-#define CONVERT_SOBJECT "ConvertSObject"
-#define CONVERT_BUILDER "ConvertBuilder"
+#define SOBJECT_FACTORY "SObjectFactory"
+#define SCOMPONENT_FACTORY "SComponentFactory"
+#define STUDY_FACTORY "StudyFactory"
+#define STUDY_CREATE "CreateStudy"
+#define STUDY_CREATE_WITHOUT_NS "CreateStudyWithoutNS"
+#define BUILDER_FACTORY "BuilderFactory"
+#define GET_PARAMETERS "GetIParameters"
+#define CONVERT_SOBJECT "ConvertSObject"
+#define CONVERT_BUILDER "ConvertBuilder"
typedef SALOMEDSClient_SObject* (*SOBJECT_FACTORY_FUNCTION) (SALOMEDS::SObject_ptr);
typedef SALOMEDSClient_SComponent* (*SCOMPONENT_FACTORY_FUNCTION) (SALOMEDS::SComponent_ptr);
if(aCreateFactory) aCreateFactory(orb, poa);
}
+void ClientFactory::createStudyWithoutNS(CORBA::ORB_ptr orb, PortableServer::POA_ptr poa)
+{
+#ifdef WIN32
+ if(!_libHandle) _libHandle = ::LoadLibrary(SALOMEDS_LIB_NAME);
+ if(!aCreateFactory) aCreateFactory = (STUDY_CREATE_FUNCTION)::GetProcAddress(_libHandle, STUDY_CREATE_WITHOUT_NS);
+#else
+ if(!_libHandle) _libHandle = dlopen(SALOMEDS_LIB_NAME, RTLD_LAZY | RTLD_GLOBAL);
+ if(!aCreateFactory) aCreateFactory = (STUDY_CREATE_FUNCTION) dlsym(_libHandle, STUDY_CREATE_WITHOUT_NS);
+#endif
+
+ if(aCreateFactory) aCreateFactory(orb, poa);
+}
+
_PTR(StudyBuilder) ClientFactory::StudyBuilder(SALOMEDS::StudyBuilder_ptr theStudyBuilder)
{
SALOMEDSClient_StudyBuilder* studyBuilder = NULL;
* Creates and returns a client Study wrapper
*/
static void createStudy(CORBA::ORB_ptr orb, PortableServer::POA_ptr poa);
+
+ /*!
+ * Creates and returns a client Study wrapper without external NS process
+ */
+ static void createStudyWithoutNS(CORBA::ORB_ptr orb, PortableServer::POA_ptr poa);
/*!
* Returns a client StudyBuilder wrapper that corresponds %theStudy
# include <iostream>
# include "utilities.h"
# include "Utils_Identity.hxx"
+# include <cstring>
extern "C"
{
-# include <string.h>
-
#ifndef WIN32 /* unix functionality */
# include <pwd.h>
#endif
// Module : SALOME
// $Header$
//
-#include <iostream>
#include "Utils_SALOME_Exception.hxx"
#include "utilities.h"
}
#endif
-
-const char* duplicate( const char *const str ) ;
-
-SALOME_Exception::SALOME_Exception( void ): exception() , _text(0)
+std::string makeText(const char *text, const char *fileName, const unsigned int lineNumber)
{
- MESSAGE( "You must use the standard builder: SALOME_Exception::SALOME_Exception( const char *text )" ) ;
- INTERRUPTION(1) ;
+ constexpr char prefix[] = "Salome Exception";
+ std::ostringstream oss;
+ if (fileName)
+ {
+ oss << prefix << " in " << fileName << "[" << lineNumber << "] : " << text;
+ }
+ else
+ {
+ oss << prefix << " : " << text;
+ }
+ return oss.str();
}
-
-
-const char *makeText( const char *text, const char *fileName, const unsigned int lineNumber )
+SALOME_Exception::SALOME_Exception(const char *text, const char *fileName, const unsigned int lineNumber) : _text(makeText(text, fileName, lineNumber))
{
- char *newText = 0 ;
-
- ASSERT(text) ;
- const size_t l1 = 1+strlen(text) ;
- ASSERT(l1>1) ;
-
- const char* prefix = "Salome Exception" ;
- const size_t l0 = 2+strlen(prefix) ;
-
- if ( fileName )
- {
- const size_t l2 = 4+strlen(fileName) ;
- ASSERT(l2>4) ;
-
- ASSERT(lineNumber>=1) ;
- const size_t l3 = 4+int(log10(float(lineNumber))) ;
-
- newText = new char [ 1+l0+l1+l2+l3 ] ;
- sprintf( newText , "%s in %s [%u] : %s" , prefix, fileName, lineNumber, text ) ;
- }
- else
- {
- newText = new char [ 1+l0+l1 ] ;
- sprintf( newText , "%s : %s" , prefix, text ) ;
- }
- ASSERT(newText) ;
- return newText ;
}
-
-SALOME_Exception::SALOME_Exception( const char *text, const char *fileName, const unsigned int lineNumber ) : exception(), _text( makeText( text , fileName , lineNumber ) )
-{
-}
-
-
SALOME_Exception::~SALOME_Exception() noexcept
{
- if ( _text )
- {
- delete [] ((char*)_text);
- char** pRef = (char**)&_text;
- *pRef = 0;
- }
- ASSERT(_text==NULL) ;
-}
-
-
-
-SALOME_Exception::SALOME_Exception( const SALOME_Exception &ex ): _text(duplicate(ex._text))
-{
- ;
}
-
-std::ostream & operator<<( std::ostream &os , const SALOME_Exception &ex )
+std::ostream &operator<<(std::ostream &os, const SALOME_Exception &ex)
{
- os << ex._text ;
- return os ;
+ os << ex._text;
+ return os;
}
-
-
-const char* SALOME_Exception::what( void ) const noexcept
+const char *SALOME_Exception::what(void) const noexcept
{
- return _text ;
+ return _text.c_str();
}
// Module : SALOME
// $Header$
//
-#if !defined( __Utils_SALOME_Exception_hxx__ )
-#define __Utils_SALOME_Exception_hxx__
+#pragma once
-//#include "SALOME_Utils.hxx"
-
-# include <exception>
-# include <iostream>
+#include <exception>
+#include <sstream>
+#include <string>
#ifdef LOCALIZED
#undef LOCALIZED
#endif
#if defined(_DEBUG_) || defined(_DEBUG)
-# define LOCALIZED(message) #message , __FILE__ , __LINE__
+#define LOCALIZED(message) #message, __FILE__, __LINE__
#else
-# define LOCALIZED(message) #message
+#define LOCALIZED(message) #message
#endif
//swig tool on Linux doesn't pass defines from header SALOME_Utils.hxx
//therefore (temporary solution) defines are placed below
#ifdef WIN32
-# if defined UTILS_EXPORTS || defined OpUtil_EXPORTS
-# define UTILS_EXPORT __declspec( dllexport )
-# else
-# define UTILS_EXPORT __declspec( dllimport )
-# undef LOCALIZED
-# define LOCALIZED(message) #message
-# endif
+#if defined UTILS_EXPORTS || defined OpUtil_EXPORTS
+#define UTILS_EXPORT __declspec(dllexport)
+#else
+#define UTILS_EXPORT __declspec(dllimport)
+#undef LOCALIZED
+#define LOCALIZED(message) #message
+#endif
#else
-# define UTILS_EXPORT
+#define UTILS_EXPORT
#endif
class SALOME_Exception;
-UTILS_EXPORT std::ostream& operator<<( std::ostream&, const SALOME_Exception& );
+UTILS_EXPORT std::ostream &operator<<(std::ostream &, const SALOME_Exception &);
-UTILS_EXPORT const char *makeText( const char *text, const char *fileName, const unsigned int lineNumber );
+UTILS_EXPORT std::string makeText(const char *text, const char *fileName, const unsigned int lineNumber);
class UTILS_EXPORT SALOME_Exception : public std::exception
{
+protected:
+ std::string _text;
+public:
+ SALOME_Exception() = delete;
+ SALOME_Exception(const std::string& text):_text(text) { }
+ SALOME_Exception(const char *text, const char *fileName = nullptr, const unsigned int lineNumber = 0);
+ virtual ~SALOME_Exception() noexcept;
+ UTILS_EXPORT friend std::ostream &operator<<(std::ostream &os, const SALOME_Exception &ex);
+ virtual const char *what(void) const noexcept;
+};
-private :
- SALOME_Exception( void );
-
-protected :
- const char* _text ; // non constant pointer but read only char variable
-
-public :
- SALOME_Exception( const char *text, const char *fileName=0, const unsigned int lineNumber=0 );
- SALOME_Exception( const SALOME_Exception &ex );
- virtual ~SALOME_Exception() noexcept;
- UTILS_EXPORT friend std::ostream & operator<<( std::ostream &os , const SALOME_Exception &ex );
- virtual const char *what( void ) const noexcept;
-} ;
-
-
-#endif /* #if !defined( __Utils_SALOME_Exception_hxx__ ) */
+#define THROW_SALOME_EXCEPTION(text) \
+{ \
+ std::ostringstream oss; oss << text; \
+ throw SALOME_Exception(oss.str()); \
+}