+ return iobject._retn();
+ }
+}
+
+//=============================================================================
+//! Create a new component instance
+/*!
+* C++ method: create a servant instance of a component.
+* \param genericRegisterName Name of the component instance to register
+* in Registry & Name Service,
+* (without _inst_n suffix, like "COMPONENT")
+* \param handle loaded library handle
+* \param studyId 0 for multiStudy instance,
+* study Id (>0) otherwise
+* \return a loaded component
+*
+* example with names:
+* - aGenRegisterName = COMPONENT (= first 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::createInstance(std::string genericRegisterName,
+ void *handle,
+ int studyId)
+{
+ // --- find the factory
+
+ string aGenRegisterName = genericRegisterName;
+ string factory_name = aGenRegisterName + string("Engine_factory");
+ SCRUTE(factory_name) ;
+
+ typedef PortableServer::ObjectId * (*FACTORY_FUNCTION)
+ (CORBA::ORB_ptr,
+ PortableServer::POA_ptr,
+ PortableServer::ObjectId *,
+ const char *,
+ const char *) ;
+
+#ifndef WIN32
+ FACTORY_FUNCTION Component_factory = (FACTORY_FUNCTION)dlsym( handle, factory_name.c_str() );
+#else
+ FACTORY_FUNCTION Component_factory = (FACTORY_FUNCTION)GetProcAddress( (HINSTANCE)handle, factory_name.c_str() );
+#endif
+
+ if ( !Component_factory )
+ {
+ INFOS( "Can't resolve symbol: " + factory_name );
+#ifndef WIN32
+ SCRUTE( dlerror() );
+#endif
+ return Engines::Component::_nil() ;
+ }
+
+ // --- create instance
+
+ Engines::Component_var iobject = Engines::Component::_nil() ;
+
+ try
+ {
+ _numInstanceMutex.lock() ; // lock on the instance number
+ _numInstance++ ;
+ int numInstance = _numInstance ;
+ _numInstanceMutex.unlock() ;
+
+ char aNumI[12];
+ sprintf( aNumI , "%d" , numInstance ) ;
+ string instanceName = aGenRegisterName + "_inst_" + aNumI ;
+ string component_registerName =
+ _containerName + "/" + instanceName;
+
+ // --- Instanciate required CORBA object
+
+ PortableServer::ObjectId *id ; //not owner, do not delete (nore use var)
+ id = (Component_factory) ( _orb, _poa, _id, instanceName.c_str(),
+ aGenRegisterName.c_str() ) ;
+ if (id == NULL)
+ return iobject._retn();
+
+ // --- get reference & servant from id
+
+ CORBA::Object_var obj = _poa->id_to_reference(*id);
+ iobject = Engines::Component::_narrow( obj ) ;
+
+ Engines_Component_i *servant =
+ dynamic_cast<Engines_Component_i*>(_poa->reference_to_servant(iobject));
+ ASSERT(servant);
+ //SCRUTE(servant->_refcount_value());
+ _numInstanceMutex.lock() ; // lock to be alone (stl container write)
+ _listInstances_map[instanceName] = iobject;
+ _cntInstances_map[aGenRegisterName] += 1;
+ _numInstanceMutex.unlock() ;
+ SCRUTE(aGenRegisterName);
+ SCRUTE(_cntInstances_map[aGenRegisterName]);
+ servant->setStudyId(studyId);
+ servant->_remove_ref(); // do not need servant any more (remove ref from reference_to_servant)
+ //SCRUTE(servant->_refcount_value());
+
+ // --- register the engine under the name
+ // containerName(.dir)/instanceName(.object)
+
+ _NS->Register( iobject , component_registerName.c_str() ) ;
+ MESSAGE( component_registerName.c_str() << " bound" ) ;
+ }
+ catch (...)
+ {
+ INFOS( "Container_i::createInstance exception catched" ) ;
+ }
+ return iobject._retn();
+}
+
+//=============================================================================
+//! Decrement component instance reference count
+/*!
+*
+*/
+//=============================================================================
+
+void Engines_Container_i::decInstanceCnt(std::string genericRegisterName)
+{
+ if(_cntInstances_map.count(genericRegisterName)==0)
+ return;
+ 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)
+ {
+ 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();
+}
+
+//=============================================================================
+//! Indicate if container is a python one
+/*!
+* Retrieves only with container naming convention if it is a python container
+*/
+//=============================================================================
+
+bool Engines_Container_i::isPythonContainer(const char* ContainerName)
+{
+ bool ret=false;
+ int len=strlen(ContainerName);
+ if(len>=2)
+ if(strcmp(ContainerName+len-2,"Py")==0)
+ ret=true;
+ return ret;