-// Copyright (C) 2007-2016 CEA/DEN, EDF R&D, OPEN CASCADE
+// Copyright (C) 2007-2021 CEA/DEN, EDF R&D, OPEN CASCADE
//
// Copyright (C) 2003-2007 OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN,
// CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS
#include "SALOME_FileTransfer_i.hxx"
#include "Salome_file_i.hxx"
#include "SALOME_NamingService.hxx"
+#include "SALOME_Fake_NamingService.hxx"
+#include "SALOME_Embedded_NamingService_Client.hxx"
#include "Basics_Utils.hxx"
#ifdef _XOPEN_SOURCE
//=============================================================================
Engines_Container_i::Engines_Container_i () :
-_numInstance(0),_id(0),_NS(0)
+ _NS(0),_id(0),_numInstance(0)
{
}
PortableServer::POA_ptr poa,
char *containerName ,
int argc , char* argv[],
- bool activAndRegist,
+ SALOME_NamingService_Container_Abstract *ns,
bool isServantAloneInProcess
) :
- _numInstance(0),_isServantAloneInProcess(isServantAloneInProcess),_id(0),_NS(0)
+ _NS(nullptr),_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();
+ // key point : if ns is nullptr : this servant is alone in its process
+ // if ns is not null : this servant embedded into single process.
+ _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
- = Engines::Container::_narrow(obj);
+ Engines::Container_var pCont = Engines::Container::_narrow(obj);
_remove_ref();
- _containerName = _NS->BuildContainerNameForNS(containerName,
- hostname.c_str());
+ _containerName = SALOME_NamingService_Abstract::BuildContainerNameForNS(containerName, hostname.c_str());
SCRUTE(_containerName);
_NS->Register(pCont, _containerName.c_str());
- MESSAGE("Engines_Container_i::Engines_Container_i : Container name "
- << _containerName);
+ MESSAGE("Engines_Container_i::Engines_Container_i : Container name " << _containerName);
// Python:
// import SALOME_Container
delete _id;
if(_NS)
delete _NS;
- for(std::map<std::string,Engines::PyNode_var>::iterator it=_dftPyNode.begin();it!=_dftPyNode.end();it++)
- {
- Engines::PyNode_var tmpVar((*it).second);
- if(!CORBA::is_nil(tmpVar))
- tmpVar->UnRegister();
- }
- for(std::map<std::string,Engines::PyScriptNode_var>::iterator it=_dftPyScriptNode.begin();it!=_dftPyScriptNode.end();it++)
- {
- Engines::PyScriptNode_var tmpVar((*it).second);
- if(!CORBA::is_nil(tmpVar))
- tmpVar->UnRegister();
- }
+ cleanAllPyScripts();
}
//=============================================================================
{
itm->second->destroy();
}
- catch(const CORBA::Exception& e)
+ catch(const CORBA::Exception&)
{
// ignore this entry and continue
}
}
_listInstances_map.clear();
- _NS->Destroy_FullDirectory(_containerName.c_str());
- _NS->Destroy_Name(_containerName.c_str());
+ // NS unregistering may throw in SSL mode if master process hosting SALOME_Embedded_NamingService servant has vanished
+ // In this case it's skip it and still continue.
+ try
+ {
+ _NS->Destroy_FullDirectory(_containerName.c_str());
+ _NS->Destroy_Name(_containerName.c_str());
+ }
+ catch(...)
+ {
+ }
+ //
if(_isServantAloneInProcess)
{
MESSAGE("Effective Shutdown of container Begins...");
}
#else
HINSTANCE handle;
- handle = LoadLibrary( impl_name.c_str() );
+#ifdef UNICODE
+ std::wstring libToLoad = Kernel_Utils::utf8_decode_s( impl_name );
+#else
+ std::string libToLoad = impl_name;
+#endif
+ handle = LoadLibrary(libToLoad.c_str() );
if ( !handle )
{
reason="ImplementationNotFound";
Engines::EngineComponent_ptr
Engines_Container_i::load_impl( const char* genericRegisterName,
- const char* componentName )
+ const char* /*componentName*/ )
{
char* reason;
std::string impl_name = std::string(LIB) + genericRegisterName + ENGINESO;
return iobject._retn();
}
+Engines::EmbeddedNamingService_ptr Engines_Container_i::get_embedded_NS_if_ssl()
+{
+ SALOME_Embedded_NamingService_Client *nsc(dynamic_cast<SALOME_Embedded_NamingService_Client *>(this->_NS));
+ if(nsc)
+ {
+ Engines::EmbeddedNamingService_var obj = nsc->GetObject();
+ return Engines::EmbeddedNamingService::_duplicate(obj);
+ }
+ else
+ {
+ return Engines::EmbeddedNamingService::_nil();
+ }
+}
+
//=============================================================================
//! Finds an already existing component instance or create a new instance
/*!
bool Engines_Container_i::isPythonContainer(const char* ContainerName)
{
bool ret=false;
- int len=strlen(ContainerName);
+ size_t len=strlen(ContainerName);
if(len>=2)
if(strcmp(ContainerName+len-2,"Py")==0)
ret=true;
void CallCancelThread() ;
#ifndef WIN32
-void SigIntHandler(int what ,
+void SigIntHandler(int /*what*/ ,
siginfo_t * siginfo ,
- void * toto )
+ void * /*toto*/ )
{
//PAL9042 JR : during the execution of a Signal Handler (and of methods called through Signal Handlers)
// use of streams (and so on) should never be used because :
aSalome_file->setLocalFile(origFileName);
aSalome_file->recvFiles();
}
- catch (const SALOME::SALOME_Exception& e)
+ catch (const SALOME::SALOME_Exception& /*e*/) //!< TODO: unused variable
{
return Engines::Salome_file::_nil();
}
oldNode->UnRegister();
(*it).second=node;
}
- if(!CORBA::is_nil(node))
- node->Register();
return node._retn();
}
else
}
}
+void Engines_Container_i::removePyScriptNode(const char *nodeName)
+{
+ std::map<std::string,Engines::PyScriptNode_var>::iterator it(_dftPyScriptNode.find(nodeName));
+ if(it==_dftPyScriptNode.end())
+ {
+ std::ostringstream oss; oss << "Engines_Container_i::removePyScriptNode : node \"" << nodeName << "\" is not map !";
+ SALOME::ExceptionStruct es;
+ es.type = SALOME::INTERNAL_ERROR;
+ es.text = oss.str().c_str();
+ throw SALOME::SALOME_Exception(es);
+ }
+ (*it).second->UnRegister();
+ _dftPyScriptNode.erase(it);
+}
+
+void Engines_Container_i::cleanAllPyScripts()
+{
+ for(std::map<std::string,Engines::PyNode_var>::iterator it=_dftPyNode.begin();it!=_dftPyNode.end();it++)
+ {
+ Engines::PyNode_var tmpVar((*it).second);
+ if(!CORBA::is_nil(tmpVar))
+ tmpVar->UnRegister();
+ }
+ _dftPyNode.clear();
+ for(std::map<std::string,Engines::PyScriptNode_var>::iterator it=_dftPyScriptNode.begin();it!=_dftPyScriptNode.end();it++)
+ {
+ Engines::PyScriptNode_var tmpVar((*it).second);
+ if(!CORBA::is_nil(tmpVar))
+ tmpVar->UnRegister();
+ }
+ _dftPyScriptNode.clear();
+}
+
//=============================================================================
/*! \brief Retrieves the last created PyScriptNode instance with createPyScriptNode.
*
{
std::list<std::string>::const_iterator it;
for ( it = _tmp_files.begin(); it != _tmp_files.end(); ++it ) {
-#ifdef WIN32
- std::string command = "del /F /P";
+#if defined(WIN32) && defined(UNICODE)
+ std::wstring aFile = Kernel_Utils::utf8_decode_s(*it);
+ std::wstring command = (GetFileAttributes(aFile.c_str()) == FILE_ATTRIBUTE_DIRECTORY) ? L"rd /Q \"" : L"del /F /Q \"";
+ command += aFile;
+ command += L"\" 2>NUL";
+ _wsystem(command.c_str());
+#else
+#if defined(WIN32)
+ std::string aFile = *it;
+ std::string command = (GetFileAttributes(aFile.c_str()) == FILE_ATTRIBUTE_DIRECTORY) ? "rd /Q \"" : "del /F /Q \"";
+ command += aFile;
+ command += "\" 2>NUL";
#else
- std::string command = "rm -rf ";
+ std::string command = "rm -rf ";
+ command += *it;
+#endif
+ system(command.c_str());
#endif
- command += *it;
- system( command.c_str() );
}
_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;
}
-*/