-//=============================================================================
-//! Unload component libraries from the container
-/*!
-* CORBA method: Discharges unused libraries from the container.
-*/
-//=============================================================================
-
-void Engines_Container_i::finalize_removal()
-{
- MESSAGE("finalize unload : dlclose");
- _numInstanceMutex.lock(); // lock to be alone
- // (see decInstanceCnt, load_component_Library)
- map<string, void *>::iterator ith;
- for (ith = _toRemove_map.begin(); ith != _toRemove_map.end(); ith++)
- {
- void *handle = (*ith).second;
- string impl_name= (*ith).first;
- if (handle)
- {
- SCRUTE(handle);
- SCRUTE(impl_name);
- // dlclose(handle); // SALOME unstable after ...
- // _library_map.erase(impl_name);
- }
- }
- _toRemove_map.clear();
- _numInstanceMutex.unlock();
-}
-
-//=============================================================================
-//! Kill the container
-/*!
-* CORBA method: Kill the container process with exit(0).
-* To remove : never returns !
-*/
-//=============================================================================
-
-bool Engines_Container_i::Kill_impl()
-{
- MESSAGE("Engines_Container_i::Kill() pid "<< getpid() << " containerName "
- << _containerName.c_str() << " machineName "
- << Kernel_Utils::GetHostname().c_str());
- INFOS("===============================================================");
- INFOS("= REMOVE calls to Kill_impl in C++ container =");
- INFOS("===============================================================");
- //exit( 0 ) ;
- ASSERT(0);
- return false;
-}
-
-//=============================================================================
-//! Get or create a file reference object associated to a local file (to transfer it)
-/*!
-* CORBA method: get or create a fileRef object associated to a local file
-* (a file on the computer on which runs the container server), which stores
-* a list of (machine, localFileName) corresponding to copies already done.
-*
-* \param origFileName absolute path for a local file to copy on other
-* computers
-* \return a fileRef object associated to the file.
-*/
-//=============================================================================
-
-Engines::fileRef_ptr
-Engines_Container_i::createFileRef(const char* origFileName)
-{
- string origName(origFileName);
- Engines::fileRef_var theFileRef = Engines::fileRef::_nil();
-
- if (origName[0] != '/')
- {
- INFOS("path of file to copy must be an absolute path begining with '/'");
- return Engines::fileRef::_nil();
- }
-
- if (CORBA::is_nil(_fileRef_map[origName]))
- {
- CORBA::Object_var obj=_poa->id_to_reference(*_id);
- Engines::Container_var pCont = Engines::Container::_narrow(obj);
- fileRef_i* aFileRef = new fileRef_i(pCont, origFileName);
- theFileRef = Engines::fileRef::_narrow(aFileRef->_this());
- _numInstanceMutex.lock() ; // lock to be alone (stl container write)
- _fileRef_map[origName] = theFileRef;
- _numInstanceMutex.unlock() ;
- }
-
- theFileRef = Engines::fileRef::_duplicate(_fileRef_map[origName]);
- ASSERT(! CORBA::is_nil(theFileRef));
- return theFileRef._retn();
-}
-
-//=============================================================================
-//! Get a fileTransfer reference
-/*!
-* CORBA method:
-* \return a reference to the fileTransfer object
-*/
-//=============================================================================
-
-Engines::fileTransfer_ptr
-Engines_Container_i::getFileTransfer()
-{
- Engines::fileTransfer_var aFileTransfer
- = Engines::fileTransfer::_duplicate(_fileTransfer);
- return aFileTransfer._retn();
-}
-
-
-//! Create a Salome file
-Engines::Salome_file_ptr
-Engines_Container_i::createSalome_file(const char* origFileName)
-{
- string origName(origFileName);
- if (CORBA::is_nil(_Salome_file_map[origName]))
- {
- Salome_file_i* aSalome_file = new Salome_file_i();
- aSalome_file->setContainer(Engines::Container::_duplicate(this->_this()));
- try
- {
- aSalome_file->setLocalFile(origFileName);
- aSalome_file->recvFiles();
- }
- catch (const SALOME::SALOME_Exception& e)
- {
- return Engines::Salome_file::_nil();
- }
-
- Engines::Salome_file_var theSalome_file = Engines::Salome_file::_nil();
- theSalome_file = Engines::Salome_file::_narrow(aSalome_file->_this());
- _numInstanceMutex.lock() ; // lock to be alone (stl container write)
- _Salome_file_map[origName] = theSalome_file;
- _numInstanceMutex.unlock() ;
- }
-
- Engines::Salome_file_ptr theSalome_file =
- Engines::Salome_file::_duplicate(_Salome_file_map[origName]);
- ASSERT(!CORBA::is_nil(theSalome_file));
- return theSalome_file;
-}
-//=============================================================================
-//! Finds an already existing component instance or create a new instance
-/*!
-* C++ method: Finds an already existing servant instance of a component, or
-* create an instance.
-* ---- USE ONLY FOR MULTISTUDY INSTANCES ! --------
-* \param genericRegisterName Name of the component instance to register
-* in Registry & Name Service,
-* (without _inst_n suffix, like "COMPONENT")
-* \param componentLibraryName like "libCOMPONENTEngine.so"
-* \return a loaded component
-*
-* example with names:
-* - aGenRegisterName = COMPONENT (= first argument)
-* - impl_name = libCOMPONENTEngine.so (= second argument)
-* - _containerName = /Containers/cli76ce/FactoryServer
-* - factoryName = COMPONENTEngine_factory
-* - component_registerBase = /Containers/cli76ce/FactoryServer/COMPONENT
-* - instanceName = COMPONENT_inst_1
-* - component_registerName = /Containers/cli76ce/FactoryServer/COMPONENT_inst_1
-*/
-//=============================================================================
-
-Engines::Component_ptr
-Engines_Container_i::find_or_create_instance(std::string genericRegisterName,
- std::string componentLibraryName)
-{
- string aGenRegisterName = genericRegisterName;
- string impl_name = componentLibraryName;
- if (_library_map.count(impl_name) == 0)
- {
- INFOS("shared library " << impl_name <<" must be loaded before creating instance");
- return Engines::Component::_nil() ;
- }
- else
- {
- // --- find a registered instance in naming service, or create
-
- void* handle = _library_map[impl_name];
- string component_registerBase =
- _containerName + "/" + aGenRegisterName;
- Engines::Component_var iobject = Engines::Component::_nil() ;
- try
- {
- CORBA::Object_var obj =
- _NS->ResolveFirst( component_registerBase.c_str());
- if ( CORBA::is_nil( obj ) )
- {
- iobject = createInstance(genericRegisterName,
- handle,
- 0); // force multiStudy instance here !
- }
- else
- {
- iobject = Engines::Component::_narrow( obj ) ;
- Engines_Component_i *servant =
- dynamic_cast<Engines_Component_i*>
- (_poa->reference_to_servant(iobject));
- ASSERT(servant)
- int studyId = servant->getStudyId();
- ASSERT (studyId >= 0);
- if (studyId == 0) // multiStudy instance, OK
- {
- // No ReBind !
- MESSAGE(component_registerBase.c_str()<<" already bound");
- }
- else // monoStudy instance: NOK
- {
- iobject = Engines::Component::_nil();
- INFOS("load_impl & find_component_instance methods "
- << "NOT SUITABLE for mono study components");
- }
- }
- }
- catch (...)