+//! Decrement component instance reference count
+/*!
+*
+*/
+//=============================================================================
+void Engines_Container_i::decInstanceCnt(std::string genericRegisterName)
+{
+ if(_cntInstances_map.count(genericRegisterName)==0)
+ return;
+ std::string aGenRegisterName =genericRegisterName;
+ MESSAGE("Engines_Container_i::decInstanceCnt " << aGenRegisterName);
+ ASSERT(_cntInstances_map[aGenRegisterName] > 0);
+ _numInstanceMutex.lock(); // lock to be alone
+ // (see finalize_removal, load_component_Library)
+ _cntInstances_map[aGenRegisterName] -= 1;
+ SCRUTE(_cntInstances_map[aGenRegisterName]);
+ if (_cntInstances_map[aGenRegisterName] == 0)
+ {
+ std::string impl_name =
+ Engines_Component_i::GetDynLibraryName(aGenRegisterName.c_str());
+ SCRUTE(impl_name);
+ void* handle = _library_map[impl_name];
+ ASSERT(handle);
+ _toRemove_map[impl_name] = handle;
+ }
+ _numInstanceMutex.unlock();
+}
+
+//=============================================================================
+//! Find or create a new component instance
+/*!
+* CORBA method: find or create an instance of the component (servant),
+* load a new component class (dynamic library) if required,
+*
+* ---- FOR COMPATIBILITY WITH 2.2 ----
+*
+* ---- USE ONLY FOR MULTISTUDY INSTANCES ! --------
+*
+* The servant registers itself to naming service and Registry.
+* \param genericRegisterName Name of the component to register
+* in Registry & Name Service
+* \param componentName Name of the constructed library of the component
+* \return a loaded component
+*/
+//=============================================================================
+
+Engines::EngineComponent_ptr
+Engines_Container_i::load_impl( const char* genericRegisterName,
+ const char* componentName )
+{
+ char* reason;
+ std::string impl_name = std::string(LIB) + genericRegisterName + ENGINESO;
+ Engines::EngineComponent_var iobject = Engines::EngineComponent::_nil() ;
+ if (load_component_Library(genericRegisterName,reason))
+ iobject = find_or_create_instance(genericRegisterName, impl_name);
+ CORBA::string_free(reason);
+ return iobject._retn();
+}
+
+//=============================================================================
+//! 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::EngineComponent_ptr
+Engines_Container_i::find_or_create_instance(std::string genericRegisterName,
+ std::string componentLibraryName)
+{
+ std::string aGenRegisterName = genericRegisterName;
+ std::string impl_name = componentLibraryName;
+ if (_library_map.count(impl_name) == 0)
+ {
+ INFOS("shared library " << impl_name <<" must be loaded before creating instance");
+ return Engines::EngineComponent::_nil() ;
+ }
+ else
+ {
+ // --- find a registered instance in naming service, or create
+
+ void* handle = _library_map[impl_name];
+ std::string component_registerBase =
+ _containerName + "/" + aGenRegisterName;
+ Engines::EngineComponent_var iobject = Engines::EngineComponent::_nil() ;
+ std::string reason;
+ try
+ {
+ CORBA::Object_var obj =
+ _NS->ResolveFirst( component_registerBase.c_str());
+ if ( CORBA::is_nil( obj ) )
+ {
+ iobject = createInstance(genericRegisterName,
+ handle,
+ 0,
+ reason); // force multiStudy instance here !
+ }
+ else
+ {
+ iobject = Engines::EngineComponent::_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::EngineComponent::_nil();
+ INFOS("load_impl & find_component_instance methods "
+ << "NOT SUITABLE for mono study components");
+ }
+ }
+ }
+ catch (...)
+ {
+ INFOS( "Container_i::load_impl catched" ) ;
+ }
+ return iobject._retn();
+ }
+}
+
+//=============================================================================
+//! Indicate if container is a python one