X-Git-Url: http://git.salome-platform.org/gitweb/?a=blobdiff_plain;f=src%2FContainer%2FContainer_i.cxx;h=315f7cee6c1e5f8ea7fa975b6c0d21c19892f304;hb=888f04cad3e3fa57bf92c96789959fc87bfdd555;hp=49f3f67e92dcfb3571136561e7664dcb1a6f3649;hpb=3f048e2513c4a1053a84a98ebd708921c831fa23;p=modules%2Fkernel.git diff --git a/src/Container/Container_i.cxx b/src/Container/Container_i.cxx index 49f3f67e9..315f7cee6 100644 --- a/src/Container/Container_i.cxx +++ b/src/Container/Container_i.cxx @@ -1,4 +1,4 @@ -// 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 @@ -54,6 +54,8 @@ int SIGUSR1 = 1000; #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 @@ -119,13 +121,13 @@ int findpathof(const std::string& path, std::string&, const std::string&); //============================================================================= Engines_Container_i::Engines_Container_i () : -_numInstance(0),_id(0),_NS(0) + _NS(0),_id(0),_numInstance(0) { } //============================================================================= /*! -* Construtor to use +* Constructor to use */ //============================================================================= @@ -133,14 +135,14 @@ Engines_Container_i::Engines_Container_i (CORBA::ORB_ptr orb, 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 ; @@ -177,22 +179,20 @@ Engines_Container_i::Engines_Container_i (CORBA::ORB_ptr orb, // 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 @@ -258,18 +258,7 @@ Engines_Container_i::~Engines_Container_i() delete _id; if(_NS) delete _NS; - for(std::map::iterator it=_dftPyNode.begin();it!=_dftPyNode.end();it++) - { - Engines::PyNode_var tmpVar((*it).second); - if(!CORBA::is_nil(tmpVar)) - tmpVar->UnRegister(); - } - for(std::map::iterator it=_dftPyScriptNode.begin();it!=_dftPyScriptNode.end();it++) - { - Engines::PyScriptNode_var tmpVar((*it).second); - if(!CORBA::is_nil(tmpVar)) - tmpVar->UnRegister(); - } + cleanAllPyScripts(); } //============================================================================= @@ -379,7 +368,7 @@ void Engines_Container_i::Shutdown() { itm->second->destroy(); } - catch(const CORBA::Exception& e) + catch(const CORBA::Exception&) { // ignore this entry and continue } @@ -390,8 +379,17 @@ void Engines_Container_i::Shutdown() } _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..."); @@ -406,7 +404,7 @@ void Engines_Container_i::Shutdown() * CORBA method * \param componentName component name * \param reason explains error when load fails -* \return true if dlopen successfull or already done, false otherwise +* \return true if dlopen successful or already done, false otherwise */ //============================================================================= bool @@ -494,7 +492,7 @@ Engines_Container_i::load_component_Library(const char* componentName, CORBA::St * C++ method: * \param componentName the name of the component (COMPONENT, for example) * \param reason explains error when load fails -* \return true if loading is successfull or already done, false otherwise +* \return true if loading is successful or already done, false otherwise */ //============================================================================= bool @@ -554,7 +552,12 @@ Engines_Container_i::load_component_CppImplementation(const char* componentName, } #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"; @@ -579,7 +582,7 @@ Engines_Container_i::load_component_CppImplementation(const char* componentName, * C++ method: * \param componentName name of the component * \param reason explains error when load fails -* \return true if loading is successfull or already done, false otherwise +* \return true if loading is successful or already done, false otherwise */ //============================================================================= bool @@ -634,7 +637,7 @@ Engines_Container_i::load_component_PythonImplementation(const char* componentNa * C++ method: * \param componentName name of the component * \param reason explains error when load fails -* \return true if loading is successfull or already done, false otherwise +* \return true if loading is successful or already done, false otherwise */ //============================================================================= bool @@ -1060,7 +1063,7 @@ Engines_Container_i::createInstance(std::string genericRegisterName, std::string component_registerName = _containerName + "/" + instanceName; - // --- Instanciate required CORBA object + // --- Instantiate required CORBA object PortableServer::ObjectId *id ; //not owner, do not delete (nore use var) id = (Component_factory) ( _orb, _poa, _id, instanceName.c_str(), @@ -1092,7 +1095,7 @@ Engines_Container_i::createInstance(std::string genericRegisterName, } catch (...) { - reason="Container_i::createInstance exception catched"; + reason="Container_i::createInstance exception caught"; INFOS(reason) ; } return iobject._retn(); @@ -1223,7 +1226,7 @@ void Engines_Container_i::decInstanceCnt(std::string genericRegisterName) 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; @@ -1234,6 +1237,20 @@ Engines_Container_i::load_impl( const char* genericRegisterName, return iobject._retn(); } +Engines::EmbeddedNamingService_ptr Engines_Container_i::get_embedded_NS_if_ssl() +{ + SALOME_Embedded_NamingService_Client *nsc(dynamic_cast(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 /*! @@ -1294,7 +1311,7 @@ Engines_Container_i::find_or_create_instance(std::string genericRegisterName, } catch (...) { - INFOS( "Container_i::load_impl catched" ) ; + INFOS( "Container_i::load_impl caught" ) ; } return iobject._retn(); } @@ -1309,7 +1326,7 @@ Engines_Container_i::find_or_create_instance(std::string genericRegisterName, 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; @@ -1392,9 +1409,9 @@ void SetCpuUsed() ; 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 : @@ -1497,7 +1514,7 @@ Engines_Container_i::createFileRef(const char* origFileName) if (origName[0] != '/') { - INFOS("path of file to copy must be an absolute path begining with '/'"); + INFOS("path of file to copy must be an absolute path beginning with '/'"); return Engines::fileRef::_nil(); } @@ -1548,7 +1565,7 @@ Engines_Container_i::createSalome_file(const char* origFileName) 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(); } @@ -1744,8 +1761,6 @@ Engines::PyScriptNode_ptr Engines_Container_i::createPyScriptNode(const char* no oldNode->UnRegister(); (*it).second=node; } - if(!CORBA::is_nil(node)) - node->Register(); return node._retn(); } else @@ -1757,6 +1772,39 @@ Engines::PyScriptNode_ptr Engines_Container_i::createPyScriptNode(const char* no } } +void Engines_Container_i::removePyScriptNode(const char *nodeName) +{ + std::map::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::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::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. * @@ -1853,53 +1901,57 @@ void Engines_Container_i::clearTemporaryFiles() { std::list::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; } -*/