From 68606b75de229da5c4f0cadd2605e4e51ccd325b Mon Sep 17 00:00:00 2001 From: prascle Date: Fri, 27 May 2005 10:37:59 +0000 Subject: [PATCH] PR: documentation, find method, load method... --- src/LifeCycleCORBA/SALOME_LifeCycleCORBA.cxx | 120 ++++++++++++------- src/LifeCycleCORBA/SALOME_LifeCycleCORBA.hxx | 26 ++-- 2 files changed, 93 insertions(+), 53 deletions(-) diff --git a/src/LifeCycleCORBA/SALOME_LifeCycleCORBA.cxx b/src/LifeCycleCORBA/SALOME_LifeCycleCORBA.cxx index 1af1f64e6..d6c18ede9 100644 --- a/src/LifeCycleCORBA/SALOME_LifeCycleCORBA.cxx +++ b/src/LifeCycleCORBA/SALOME_LifeCycleCORBA.cxx @@ -99,7 +99,7 @@ SALOME_LifeCycleCORBA::FindContainer(const char *containerName) { // Compatibility ... string theComputer ; string theContainer ; - cont = ContainerName( containerName , &theComputer , &theContainer ) ; + cont = _ContainerName( containerName , &theComputer , &theContainer ) ; } else { @@ -142,7 +142,13 @@ SALOME_LifeCycleCORBA::FindComponent(const Engines::MachineParameters& params, int studyId, const char *instanceName) { - ASSERT(0); + if (! isKnownComponentClass(componentName)) + return Engines::Component::_nil(); + Engines::MachineList_var listOfMachine = + _ContManager->GetFittingResources(params,componentName); + Engines::Component_var compo = + _FindComponent(params.container_name,componentName,listOfMachine); + return compo._retn(); } //============================================================================= @@ -160,7 +166,23 @@ SALOME_LifeCycleCORBA::LoadComponent(const Engines::MachineParameters& params, const char *componentName, int studyId) { - ASSERT(0); + if (! isKnownComponentClass(componentName)) + return Engines::Component::_nil(); + + Engines::MachineList_var listOfMachine = + _ContManager->GetFittingResources(params,componentName); + + Engines::Container_var cont = + _ContManager->FindOrStartContainer(params.container_name, + listOfMachine); + if (CORBA::is_nil(cont)) return Engines::Component::_nil(); + + bool isLoadable = cont->load_component_Library(componentName); + if (!isLoadable) return Engines::Component::_nil(); + + Engines::Component_var myInstance = + cont->create_component_instance(componentName, 0); + return myInstance._retn(); } //============================================================================= @@ -185,12 +207,12 @@ FindOrLoad_Component(const Engines::MachineParameters& params, Engines::MachineList_var listOfMachine = _ContManager->GetFittingResources(params,componentName); - Engines::Component_ptr ret= - FindComponent(params.container_name,componentName,listOfMachine); - if(CORBA::is_nil(ret)) - return LoadComponent(params.container_name,componentName,listOfMachine); + Engines::Component_var compo= + _FindComponent(params.container_name,componentName,listOfMachine); + if(CORBA::is_nil(compo)) + return _LoadComponent(params.container_name,componentName,listOfMachine); else - return ret; + return compo._retn(); } //============================================================================= @@ -222,10 +244,10 @@ SALOME_LifeCycleCORBA::FindOrLoad_Component(const char *containerName, stContainer[rg]='\0'; if(strcmp(stContainer,"localhost")==0) { - Engines::Component_ptr ret=FindOrLoad_Component(stContainer+rg+1, - componentName); + Engines::Component_var compo = FindOrLoad_Component(stContainer+rg+1, + componentName); free(stContainer); - return ret; + return compo._retn(); } else ASSERT(0); // no return in that case... } @@ -236,13 +258,13 @@ SALOME_LifeCycleCORBA::FindOrLoad_Component(const char *containerName, Engines::MachineList_var listOfMachine=new Engines::MachineList; listOfMachine->length(1); listOfMachine[0]=CORBA::string_dup(GetHostname().c_str()); - Engines::Component_ptr ret = FindComponent(containerName, - componentName, - listOfMachine.in()); - if(CORBA::is_nil(ret)) - return LoadComponent(containerName,componentName,listOfMachine); + Engines::Component_var compo = _FindComponent(containerName, + componentName, + listOfMachine.in()); + if(CORBA::is_nil(compo)) + return _LoadComponent(containerName,componentName,listOfMachine); else - return ret; + return compo._retn(); } else { @@ -295,16 +317,25 @@ bool SALOME_LifeCycleCORBA::isKnownComponentClass(const char *componentName) //============================================================================= /*! Protected - - * + * Find and aready existing and registered component instance. + * \param containerName the name of container, or empty string + * (now, default Container Name used = FactoryServer) + * \param componentName the name of component class + * \param listOfMachines list of machine address + * \return a CORBA reference of the component instance, or _nil if not found + * - if containerName given, creates a sublist of the machine list, where + * machine/ContainerName/ComponentName exists. then chooses the best machine. + * - if no containerName given, choose first the best machine, then tries + * machine/ContainerName/ComponentName, where ContainerName = FactoryServer */ //============================================================================= Engines::Component_ptr -SALOME_LifeCycleCORBA::FindComponent(const char *containerName, - const char *componentName, - const Engines::MachineList& listOfMachines) +SALOME_LifeCycleCORBA::_FindComponent(const char *containerName, + const char *componentName, + const Engines::MachineList& listOfMachines) { - if (! isKnownComponentClass(componentName)) return Engines::Component::_nil(); + if (!isKnownComponentClass(componentName)) return Engines::Component::_nil(); if(containerName[0]!='\0') { Engines::MachineList_var machinesOK=new Engines::MachineList; @@ -358,39 +389,48 @@ SALOME_LifeCycleCORBA::FindComponent(const char *containerName, //============================================================================= /*! Protected - - * + * Load a component instance. + * \param containerName the name of container (no default name) + * \param componentName the name of component class + * \param listOfMachines list of machine address + * \return a CORBA reference of the component instance, or _nil if problem + * - uses the first container (of given name) found in the machines list. + * - if no container found, tries to launch one one the best machine of the + * list. + * Then, find or loads a component instance on the choosen container. */ //============================================================================= Engines::Component_ptr -SALOME_LifeCycleCORBA::LoadComponent(const char *containerName, - const char *componentName, - const Engines::MachineList& listOfMachines) +SALOME_LifeCycleCORBA::_LoadComponent(const char *containerName, + const char *componentName, + const Engines::MachineList& listOfMachines) { - Engines::Container_var cont=_ContManager->FindOrStartContainer(containerName, - listOfMachines); - //string implementation=Engines_Component_i::GetDynLibraryName(componentName); - //return cont->load_impl(componentName, implementation.c_str()); - return cont->load_impl(componentName,""); + Engines::Container_var cont = + _ContManager->FindOrStartContainer(containerName, + listOfMachines); + if (!CORBA::is_nil(cont)) return cont->load_impl(componentName,""); + else return Engines::Component::_nil(); } //============================================================================= /*! Protected - - * + * Alternate Container Launcher, without container manager... */ //============================================================================= Engines::Container_ptr -SALOME_LifeCycleCORBA::FindOrStartContainer(const string aComputerContainer , - const string theComputer , - const string theContainer ) +SALOME_LifeCycleCORBA::_FindOrStartContainer(const string aComputerContainer , + const string theComputer , + const string theContainer ) { SCRUTE( aComputerContainer ) ; SCRUTE( theComputer ) ; SCRUTE( theContainer ) ; - Engines::Container_var aContainer = FindContainer(aComputerContainer.c_str()); + Engines::Container_var aContainer = + FindContainer(aComputerContainer.c_str()); if ( !CORBA::is_nil( aContainer ) ) { @@ -454,9 +494,9 @@ SALOME_LifeCycleCORBA::FindOrStartContainer(const string aComputerContainer , */ //============================================================================= -string SALOME_LifeCycleCORBA::ContainerName(const char *aComputerContainer , - string * theComputer , - string * theContainer ) +string SALOME_LifeCycleCORBA::_ContainerName(const char *aComputerContainer , + string * theComputer , + string * theContainer ) { char * ContainerName = new char [ strlen( aComputerContainer ) + 1 ] ; strcpy( ContainerName , aComputerContainer ) ; @@ -498,7 +538,7 @@ string SALOME_LifeCycleCORBA::ContainerName(const char *aComputerContainer , */ //============================================================================= -string SALOME_LifeCycleCORBA::ComputerPath(const char * theComputer ) +string SALOME_LifeCycleCORBA::_ComputerPath(const char * theComputer ) { CORBA::String_var path; CORBA::Object_var obj = _NS->Resolve("/Kernel/ModulCatalog"); diff --git a/src/LifeCycleCORBA/SALOME_LifeCycleCORBA.hxx b/src/LifeCycleCORBA/SALOME_LifeCycleCORBA.hxx index fc4e9d479..d86a7a471 100644 --- a/src/LifeCycleCORBA/SALOME_LifeCycleCORBA.hxx +++ b/src/LifeCycleCORBA/SALOME_LifeCycleCORBA.hxx @@ -78,29 +78,29 @@ protected: * This method uses Naming Service to find the component. */ Engines::Component_ptr - FindComponent(const char *containerName, - const char *componentName, - const Engines::MachineList& listOfMachines); + _FindComponent(const char *containerName, + const char *componentName, + const Engines::MachineList& listOfMachines); Engines::Component_ptr - LoadComponent(const char *containerName, - const char *componentName, - const Engines::MachineList& listOfMachines); + _LoadComponent(const char *containerName, + const char *componentName, + const Engines::MachineList& listOfMachines); SALOME_NamingService *_NS; Engines::ContainerManager_var _ContManager; //private: - std::string ContainerName( const char * aComputerContainer , - std::string * theComputer , - std::string * theContainer ) ; - std::string ComputerPath( const char * theComputer ) ; + std::string _ContainerName( const char * aComputerContainer , + std::string * theComputer , + std::string * theContainer ) ; + std::string _ComputerPath( const char * theComputer ) ; Engines::Container_ptr - FindOrStartContainer(const std::string aComputerContainer , - const std::string theComputer , - const std::string theContainer ) ; + _FindOrStartContainer(const std::string aComputerContainer , + const std::string theComputer , + const std::string theContainer ) ; } ; #endif -- 2.39.2