+ }
+
+ std::string hostname = Kernel_Utils::GetHostname();
+
+ // 1) ConnectionManager
+ try
+ {
+ CORBA::Object_var objCnM=_NS->Resolve("/ConnectionManager");
+ Engines::ConnectionManager_var connMan=Engines::ConnectionManager::_narrow(objCnM);
+ if ( !CORBA::is_nil(connMan) && ( pid != connMan->getPID() ) )
+ connMan->ShutdownWithExit();
+ }
+ catch(const CORBA::Exception& e)
+ {
+ // ignore and continue
+ }
+
+ timespec ts_req;
+ ts_req.tv_nsec=100000000;
+ ts_req.tv_sec=0;
+
+//Wait some time so that ConnectionManager be completely shutdown
+#ifndef WIN32
+ nanosleep(&ts_req,0);
+#endif
+
+ // 2) SALOMEDS
+ try
+ {
+ CORBA::Object_var objSDS = _NS->Resolve("/myStudyManager");
+ SALOMEDS::StudyManager_var studyManager = SALOMEDS::StudyManager::_narrow(objSDS) ;
+ if ( !CORBA::is_nil(studyManager) && ( pid != studyManager->getPID() ) )
+ studyManager->Shutdown();
+ }
+ catch(const CORBA::Exception& e)
+ {
+ // ignore and continue
+ }
+
+//Wait some time so that study be completely shutdown
+#ifndef WIN32
+ nanosleep(&ts_req,0);
+#endif
+
+ // 3) ModuleCatalog
+ try
+ {
+ CORBA::Object_var objMC=_NS->Resolve("/Kernel/ModulCatalog");
+ SALOME_ModuleCatalog::ModuleCatalog_var catalog = SALOME_ModuleCatalog::ModuleCatalog::_narrow(objMC);
+ if ( !CORBA::is_nil(catalog) && ( pid != catalog->getPID() ) )
+ catalog->shutdown();
+ }
+ catch(const CORBA::Exception& e)
+ {
+ // ignore and continue
+ }
+
+//Wait some time so that ModulCatalog be completely shutdown
+#ifndef WIN32
+ nanosleep(&ts_req,0);
+#endif
+ // 4 ) Remote ScopeServer (the DataServer is hosted by SalomeLauncher shutdown right after)
+ try
+ {
+ CORBA::Object_var objDSM(_NS->Resolve(SALOMESDS::DataServerManager::NAME_IN_NS));
+ SALOME::DataServerManager_var dsm(SALOME::DataServerManager::_narrow(objDSM));
+ if ( !CORBA::is_nil(dsm) )
+ dsm->shutdownScopes();
+ }
+ catch(const CORBA::Exception& e)
+ {
+ // ignore and continue
+ }
+
+ // 5) SalomeLauncher
+ try
+ {
+ CORBA::Object_var objSL = _NS->Resolve("/SalomeLauncher");
+ Engines::SalomeLauncher_var launcher = Engines::SalomeLauncher::_narrow(objSL);
+ if (!CORBA::is_nil(launcher) && (pid != launcher->getPID()))
+ launcher->Shutdown();
+ }
+ catch(const CORBA::Exception& e)
+ {
+ // ignore and continue
+ }
+
+//Wait some time so that launcher be completely shutdown
+#ifndef WIN32
+ nanosleep(&ts_req,0);
+#endif
+
+ // 6) Registry
+ try
+ {
+ CORBA::Object_var objR = _NS->Resolve("/Registry");
+ Registry::Components_var registry = Registry::Components::_narrow(objR);
+ if ( !CORBA::is_nil(registry) && ( pid != registry->getPID() ) )
+ registry->Shutdown();
+ }
+ catch(const CORBA::Exception& e)
+ {
+ // ignore and continue
+ }
+
+ // 7) Logger
+ int argc = 0;
+ char *xargv = (char*)"";
+ char **argv = &xargv;
+ CORBA::ORB_var orb = CORBA::ORB_init(argc, argv);
+
+ CORBA::Object_var objLog = CORBA::Object::_nil();
+ CosNaming::NamingContext_var inc;
+ CORBA::Object_var theObj = CORBA::Object::_nil();
+ std::string stdname = "Logger";
+ CosNaming::Name name;
+ name.length(1);
+ name[0].id = CORBA::string_dup(stdname.c_str());
+ try
+ {
+ if(!CORBA::is_nil(orb))
+ theObj = orb->resolve_initial_references("NameService");
+ if (!CORBA::is_nil(theObj))
+ inc = CosNaming::NamingContext::_narrow(theObj);
+ }
+ catch(...)
+ {
+ }
+ if(!CORBA::is_nil(inc))
+ {
+ try
+ {
+ objLog = inc->resolve(name);
+ SALOME_Logger::Logger_var logger = SALOME_Logger::Logger::_narrow(objLog);
+ if ( !CORBA::is_nil(logger) )
+ logger->shutdown();
+ }
+ catch(...)
+ {
+ }
+ }
+}
+
+//=============================================================================
+/*! \brief shutdown omniNames
+ */
+//=============================================================================
+
+void SALOME_LifeCycleCORBA::killOmniNames()
+{
+ std::string portNumber (::getenv ("NSPORT") );
+ std::string python_exe;
+
+ python_exe = std::string("python");
+
+ if ( !portNumber.empty() )
+ {
+ std::string cmd;
+
+ cmd = std::string("from salome_utils import killOmniNames; ");
+ cmd += std::string("killOmniNames(") + portNumber + "); ";
+ cmd = python_exe + std::string(" -c \"") + cmd +"\"";
+ MESSAGE(cmd);
+ system( cmd.c_str() );
+
+ cmd = std::string("from killSalomeWithPort import cleanApplication; ");
+ cmd += std::string("cleanApplication(") + portNumber + "); ";
+ cmd = python_exe + std::string(" -c \"") + cmd +"\"";
+ MESSAGE(cmd);
+ system( cmd.c_str() );
+ }
+
+ // shutdown portmanager
+ if ( !portNumber.empty() )
+ {
+ std::string cmd;
+
+ cmd = std::string("from PortManager import releasePort; ");
+ cmd += std::string("releasePort(") + portNumber + "); ";
+ cmd = python_exe + std::string(" -c \"") + cmd +"\"";
+ MESSAGE(cmd);
+ system( cmd.c_str() );
+ }
+}
+
+//=============================================================================
+/*! \brief Find an already existing and registered component instance.
+ *
+ * - build a list of machines on which an instance of the component is running,
+ * - find the best machine among the list
+ *
+ * \param params machine parameters like type or name...
+ * \param componentName the name of component class
+ * \param studyId default = 0 : multistudy instance
+ * \param listOfMachines list of machine address
+ * \return a CORBA reference of the component instance, or _nil if not found
+ */
+//=============================================================================
+
+Engines::EngineComponent_ptr
+SALOME_LifeCycleCORBA::
+_FindComponent(const Engines::ContainerParameters& params,
+ const char *componentName,
+ int studyId,
+ const Engines::ResourceList& listOfResources)
+{
+ // --- build the list of machines on which the component is already running
+ const char *containerName = params.container_name;
+ int nbproc = NbProc(params);
+
+ Engines::ResourceList_var resourcesOK = new Engines::ResourceList;
+
+ unsigned int lghtOfresourcesOK = 0;
+ resourcesOK->length(listOfResources.length());
+
+ for(unsigned int i=0; i < listOfResources.length(); i++)
+ {
+ const char * currentResource = listOfResources[i];
+ Engines::ResourceDefinition_var resource_definition =
+ _ResManager->GetResourceDefinition(currentResource);
+ CORBA::Object_var obj = _NS->ResolveComponent(resource_definition->hostname.in(),
+ containerName,
+ componentName,
+ nbproc);
+ if (!CORBA::is_nil(obj))
+ resourcesOK[lghtOfresourcesOK++] = CORBA::string_dup(currentResource);
+ }
+
+ // --- find the best machine among the list
+ if(lghtOfresourcesOK != 0)
+ {
+ resourcesOK->length(lghtOfresourcesOK);
+ CORBA::String_var bestResource = _ResManager->FindFirst(resourcesOK);
+ Engines::ResourceDefinition_var resource_definition =
+ _ResManager->GetResourceDefinition(bestResource);
+ CORBA::Object_var obj = _NS->ResolveComponent(resource_definition->hostname.in(),
+ containerName,
+ componentName,
+ nbproc);
+ return Engines::EngineComponent::_narrow(obj);
+ }