From 73f9c9d3203b1f6347e516f64e1c5531ffe26e52 Mon Sep 17 00:00:00 2001 From: Anthony Geay Date: Tue, 5 Aug 2014 14:34:46 +0200 Subject: [PATCH] Addition of a new type of SalomeComponent to take advantage of HPContainer. --- src/engine/ComponentInstance.cxx | 5 + src/engine/ComponentInstance.hxx | 1 + src/engine/Container.cxx | 9 + src/engine/Container.hxx | 3 +- src/engine/HomogeneousPoolContainer.cxx | 21 +++ src/engine/HomogeneousPoolContainer.hxx | 4 + src/engine/ServiceNode.cxx | 2 +- src/engine/Test/ComponentInstanceTest.cxx | 10 + src/engine/Test/ComponentInstanceTest.hxx | 2 + src/runtime/CMakeLists.txt | 4 +- src/runtime/CORBAComponent.cxx | 5 + src/runtime/CORBAComponent.hxx | 1 + src/runtime/CppComponent.cxx | 7 +- src/runtime/CppComponent.hxx | 1 + src/runtime/RuntimeSALOME.cxx | 3 + src/runtime/SalomeComponent.cxx | 22 +-- src/runtime/SalomeComponent.hxx | 1 + src/runtime/SalomeContainerTools.cxx | 105 ++++++----- src/runtime/SalomeContainerTools.hxx | 1 + src/runtime/SalomeHPComponent.cxx | 213 ++++++++++++++++++++++ src/runtime/SalomeHPComponent.hxx | 56 ++++++ src/runtime/SalomeHPContainer.cxx | 4 +- src/runtime/SalomeHPContainer.hxx | 1 + src/runtime/SalomeHPContainerTools.cxx | 20 +- src/runtime/SalomeHPContainerTools.hxx | 2 +- 25 files changed, 419 insertions(+), 84 deletions(-) create mode 100644 src/runtime/SalomeHPComponent.cxx create mode 100644 src/runtime/SalomeHPComponent.hxx diff --git a/src/engine/ComponentInstance.cxx b/src/engine/ComponentInstance.cxx index c8f845724..4e5a7957e 100644 --- a/src/engine/ComponentInstance.cxx +++ b/src/engine/ComponentInstance.cxx @@ -128,6 +128,11 @@ string ComponentInstance::getKind() const return KIND; } +std::string ComponentInstance::getKindForNode() const +{ + return KIND; +} + void ComponentInstance::shutdown(int level) { } diff --git a/src/engine/ComponentInstance.hxx b/src/engine/ComponentInstance.hxx index 8f593af62..839e4d516 100644 --- a/src/engine/ComponentInstance.hxx +++ b/src/engine/ComponentInstance.hxx @@ -63,6 +63,7 @@ namespace YACS virtual ServiceNode* createNode(const std::string& name)=0; virtual ComponentInstance *clone() const = 0; virtual std::string getKind() const; + virtual std::string getKindForNode() const; static const char KIND[]; virtual void shutdown(int level); protected: diff --git a/src/engine/Container.cxx b/src/engine/Container.cxx index b77a26210..2bd052dd5 100644 --- a/src/engine/Container.cxx +++ b/src/engine/Container.cxx @@ -23,6 +23,8 @@ //#define _DEVDEBUG_ #include "YacsTrace.hxx" +#include + using namespace std; using namespace YACS::ENGINE; @@ -34,6 +36,13 @@ Container::~Container() { } +std::string Container::getDiscreminantStrOfThis() const +{ + const void *ptr(this); + std::ostringstream oss; oss << ptr; + return oss.str(); +} + /*! * By calling this method the current container 'this' is not destined to be deeply copied on clone call. */ diff --git a/src/engine/Container.hxx b/src/engine/Container.hxx index 6c8b8ed17..979485aeb 100644 --- a/src/engine/Container.hxx +++ b/src/engine/Container.hxx @@ -47,6 +47,7 @@ namespace YACS #endif public: //Execution only methods + virtual std::string getDiscreminantStrOfThis() const; virtual bool isAlreadyStarted(const Task *askingNode) const = 0; virtual void start(const Task *askingNode) throw(Exception) = 0; virtual std::string getPlacementId(const Task *askingNode) const = 0; @@ -54,7 +55,7 @@ namespace YACS //Edition only methods virtual void attachOnCloning() const; virtual void dettachOnCloning() const; - bool isAttachedOnCloning() const; + virtual bool isAttachedOnCloning() const; virtual void lock() = 0; virtual void unLock() = 0; //! \b WARNING ! clone behaviour \b MUST be in coherence with what is returned by isAttachedOnCloning() method diff --git a/src/engine/HomogeneousPoolContainer.cxx b/src/engine/HomogeneousPoolContainer.cxx index 814a2f358..39c3a45c7 100644 --- a/src/engine/HomogeneousPoolContainer.cxx +++ b/src/engine/HomogeneousPoolContainer.cxx @@ -18,11 +18,32 @@ // #include "HomogeneousPoolContainer.hxx" +#include "Exception.hxx" using namespace YACS::ENGINE; +void HomogeneousPoolContainer::attachOnCloning() const +{ + _isAttachedOnCloning=true; +} + +void HomogeneousPoolContainer::dettachOnCloning() const +{ + _isAttachedOnCloning=true; + throw Exception("An HomogeneousPoolContainer cannot be detached on cloning !"); +} + +/*! + * By definition an HomogeneousPoolContainer instance is attached on cloning. + */ +bool HomogeneousPoolContainer::isAttachedOnCloning() const +{ + return true; +} + HomogeneousPoolContainer::HomogeneousPoolContainer() { + _isAttachedOnCloning=true; } HomogeneousPoolContainer::~HomogeneousPoolContainer() diff --git a/src/engine/HomogeneousPoolContainer.hxx b/src/engine/HomogeneousPoolContainer.hxx index 6ef5ce897..c78693008 100644 --- a/src/engine/HomogeneousPoolContainer.hxx +++ b/src/engine/HomogeneousPoolContainer.hxx @@ -37,6 +37,10 @@ namespace YACS class YACSLIBENGINE_EXPORT HomogeneousPoolContainer : public Container { public: + void attachOnCloning() const; + void dettachOnCloning() const; + bool isAttachedOnCloning() const; + // virtual void setSizeOfPool(int sz) = 0; virtual std::size_t getNumberOfFreePlace() const = 0; virtual void allocateFor(const std::vector& nodes) = 0; diff --git a/src/engine/ServiceNode.cxx b/src/engine/ServiceNode.cxx index 89e23e872..6d4b167cd 100644 --- a/src/engine/ServiceNode.cxx +++ b/src/engine/ServiceNode.cxx @@ -138,7 +138,7 @@ void ServiceNode::setComponent(ComponentInstance* compo) throw(YACS::Exception) if(compo) { DEBTRACE(compo->getInstanceName()); - if(compo->getKind() != this->getKind()) + if(compo->getKindForNode() != this->getKind()) { //Not allowed std::string what("ServiceNode::setComponent : component instance kind not allowed "); diff --git a/src/engine/Test/ComponentInstanceTest.cxx b/src/engine/Test/ComponentInstanceTest.cxx index c18e738e3..6d1330d5e 100644 --- a/src/engine/Test/ComponentInstanceTest.cxx +++ b/src/engine/Test/ComponentInstanceTest.cxx @@ -51,6 +51,11 @@ std::string ComponentInstanceTest1::getKind() const return ToyNode1S::KIND; } +std::string ComponentInstanceTest1::getKindForNode() const +{ + return ToyNode1S::KIND; +} + ServiceNode* ComponentInstanceTest1::createNode(const std::string& name) { ToyNode1S* node=new ToyNode1S(name); @@ -97,6 +102,11 @@ std::string ComponentInstanceTest2::getKind() const return ToyNode2S::KIND; } +std::string ComponentInstanceTest2::getKindForNode() const +{ + return ToyNode2S::KIND; +} + ServiceNode* ComponentInstanceTest2::createNode(const std::string& name) { ToyNode2S* node=new ToyNode2S(name); diff --git a/src/engine/Test/ComponentInstanceTest.hxx b/src/engine/Test/ComponentInstanceTest.hxx index 71fef605b..043226356 100644 --- a/src/engine/Test/ComponentInstanceTest.hxx +++ b/src/engine/Test/ComponentInstanceTest.hxx @@ -35,6 +35,7 @@ namespace YACS void unload(Task *askingNode); bool isLoaded(Task *askingNode) const; std::string getKind() const; + std::string getKindForNode() const; ServiceNode* createNode(const std::string& name); ComponentInstance *clone() const; protected: @@ -50,6 +51,7 @@ namespace YACS void unload(Task *askingNode); bool isLoaded(Task *askingNode) const; std::string getKind() const; + std::string getKindForNode() const; ServiceNode* createNode(const std::string& name); ComponentInstance *clone() const; protected: diff --git a/src/runtime/CMakeLists.txt b/src/runtime/CMakeLists.txt index 42f0956f7..42ae3fbd8 100644 --- a/src/runtime/CMakeLists.txt +++ b/src/runtime/CMakeLists.txt @@ -116,6 +116,7 @@ SET(YACSRuntimeSALOME_HEADERS PythonXMLConv.hxx RuntimeSALOME.hxx SalomeComponent.hxx + SalomeHPComponent.hxx SalomeContainer.hxx SalomeContainerTools.hxx SalomeContainerHelper.hxx @@ -183,7 +184,8 @@ SET(YACSRuntimeSALOME_SOURCES SalomeProc.cxx CalStreamPort.cxx CORBAComponent.cxx - SalomeComponent.cxx + SalomeComponent.cxx + SalomeHPComponent.cxx CppComponent.cxx CppContainer.cxx CppCORBAConv.cxx diff --git a/src/runtime/CORBAComponent.cxx b/src/runtime/CORBAComponent.cxx index 09132ebe9..bdfe047de 100644 --- a/src/runtime/CORBAComponent.cxx +++ b/src/runtime/CORBAComponent.cxx @@ -68,6 +68,11 @@ std::string CORBAComponent::getKind() const return KIND; } +std::string CORBAComponent::getKindForNode() const +{ + return KIND; +} + //! Unload the component void CORBAComponent::unload(Task *askingNode) { diff --git a/src/runtime/CORBAComponent.hxx b/src/runtime/CORBAComponent.hxx index c6b4222ba..e536a723b 100644 --- a/src/runtime/CORBAComponent.hxx +++ b/src/runtime/CORBAComponent.hxx @@ -49,6 +49,7 @@ namespace YACS public: static const char KIND[]; virtual std::string getKind() const; + virtual std::string getKindForNode() const; protected: CORBA::Object_var _objComponent; }; diff --git a/src/runtime/CppComponent.cxx b/src/runtime/CppComponent.cxx index fb3b1b8c8..bb769a3ba 100644 --- a/src/runtime/CppComponent.cxx +++ b/src/runtime/CppComponent.cxx @@ -74,7 +74,12 @@ static std::ostream & operator<<(std::ostream & f, const Any & A) std::string CppComponent::getKind() const { - return CppComponent::KIND; + return CppComponent::KIND; +} + +std::string CppComponent::getKindForNode() const +{ + return CppComponent::KIND; } //! CppComponent constructor diff --git a/src/runtime/CppComponent.hxx b/src/runtime/CppComponent.hxx index 50d32d5c5..e5e7ebc05 100644 --- a/src/runtime/CppComponent.hxx +++ b/src/runtime/CppComponent.hxx @@ -56,6 +56,7 @@ namespace YACS static const char KIND[]; virtual std::string getKind() const; + virtual std::string getKindForNode() const; virtual void load(Task *askingNode); virtual void unload(Task *askingNode); virtual bool isLoaded(Task *askingNode) const; diff --git a/src/runtime/RuntimeSALOME.cxx b/src/runtime/RuntimeSALOME.cxx index 7134266dc..f3f43e2cb 100644 --- a/src/runtime/RuntimeSALOME.cxx +++ b/src/runtime/RuntimeSALOME.cxx @@ -50,6 +50,7 @@ //Components #include "CORBAComponent.hxx" #include "SalomeComponent.hxx" +#include "SalomeHPComponent.hxx" #include "SalomePythonComponent.hxx" #include "CppComponent.hxx" @@ -588,6 +589,8 @@ ComponentInstance* RuntimeSALOME::createComponentInstance(const std::string& nam return new SalomePythonComponent(name); else if (kind == CppComponent::KIND) return new CppComponent(name); + else if (kind == SalomeHPComponent::KIND) + return new SalomeHPComponent(name); std::string msg="Component Instance kind ("+kind+") unknown"; throw Exception(msg); } diff --git a/src/runtime/SalomeComponent.cxx b/src/runtime/SalomeComponent.cxx index ea1fbf053..0e9007837 100644 --- a/src/runtime/SalomeComponent.cxx +++ b/src/runtime/SalomeComponent.cxx @@ -62,6 +62,11 @@ std::string SalomeComponent::getKind() const return KIND; } +std::string SalomeComponent::getKindForNode() const +{ + return KIND; +} + //! Unload the component void SalomeComponent::unload(Task *askingNode) { @@ -90,20 +95,7 @@ void SalomeComponent::load(Task *askingNode) _objComponent=salomeContainer->loadComponent(askingNode); return ; } - SalomeHPContainer *salomeContainer2(dynamic_cast(_container)); - if(salomeContainer2) - { - SalomeContainerHelper *lmt(0); - { - YACS::BASES::AutoLocker altck(salomeContainer2); - lmt=salomeContainer2->getHelperOfTask(askingNode); - } - SalomeContainer tmpCont(*salomeContainer2,salomeContainer2->getContainerInfo(),lmt, - salomeContainer2->getComponentNames(),salomeContainer2->getShutdownLev()); - _objComponent=tmpCont.loadComponent(askingNode); - return ; - } - throw Exception("Unrecognized type of Container ! Only Salome and HPSalome container are supported by the Salome components !"); + throw Exception("Unrecognized type of Container ! Only Salome are supported by the Salome components !"); } //throw Exception("SalomeComponent::load : no container specified !!! To be implemented in executor to allocate default a Container in case of presenceOfDefaultContainer."); //This component has no specified container : use default container policy @@ -155,6 +147,8 @@ std::string SalomeComponent::getFileRepr() const bool SalomeComponent::setContainer(Container *cont) { + if(!dynamic_cast(cont)) + throw Exception("SalomeComponent::setContainer : a Salome component must be attached to a Salome container !"); if(ComponentInstance::setContainer(cont)) { if(_container) diff --git a/src/runtime/SalomeComponent.hxx b/src/runtime/SalomeComponent.hxx index 267cd07be..e2ae3d9bb 100644 --- a/src/runtime/SalomeComponent.hxx +++ b/src/runtime/SalomeComponent.hxx @@ -50,6 +50,7 @@ namespace YACS public: static const char KIND[]; virtual std::string getKind() const; + virtual std::string getKindForNode() const; protected: CORBA::Object_var _objComponent; }; diff --git a/src/runtime/SalomeContainerTools.cxx b/src/runtime/SalomeContainerTools.cxx index 2dec1aa0e..5c20ba5f0 100644 --- a/src/runtime/SalomeContainerTools.cxx +++ b/src/runtime/SalomeContainerTools.cxx @@ -23,6 +23,7 @@ #include "SALOME_ResourcesManager.hxx" #include "SALOME_ContainerManager.hxx" #include "Container.hxx" +#include "AutoLocker.hxx" #include "YacsTrace.hxx" #include "Proc.hxx" @@ -246,7 +247,7 @@ std::string SalomeContainerTools::getNotNullContainerName(const Container *contP stream << "_"; stream << contPtr->getName(); stream << "_"; - stream << (const void *)contPtr; + stream << contPtr->getDiscreminantStrOfThis(); return stream.str(); } } @@ -419,66 +420,65 @@ void SalomeContainerTools::Start(const std::vector& compoNames, Sal CORBA::Object_ptr SalomeContainerTools::LoadComponent(SalomeContainerHelper *launchModeType, Container *cont, Task *askingNode) { DEBTRACE("SalomeContainer::loadComponent "); - cont->lock();//To be sure const ComponentInstance *inst(askingNode?askingNode->getComponent():0); - if(!cont->isAlreadyStarted(askingNode)) - { - try - { - cont->start(askingNode); - } - catch(Exception& e) - { - cont->unLock(); - throw e; - } - } - cont->unLock(); - cont->lock();//To be sure + { + YACS::BASES::AutoLocker alck(cont);//To be sure + if(!cont->isAlreadyStarted(askingNode)) + cont->start(askingNode); + } + if(!inst) + throw Exception("SalomeContainerTools::LoadComponent : no instance of component in the task requesting for a load of its component !"); CORBA::Object_ptr objComponent=CORBA::Object::_nil(); - std::string compoName(inst->getCompoName()); - const char* componentName=compoName.c_str(); - Engines::Container_var container(launchModeType->getContainer(askingNode)); - - char* reason; + { + YACS::BASES::AutoLocker alck(cont);//To be sure + std::string compoName(inst->getCompoName()); + Engines::Container_var container(launchModeType->getContainer(askingNode)); + + char *reason; + bool isLoadable(container->load_component_Library(compoName.c_str(), reason)); + if(isLoadable) + objComponent=CreateComponentInstance(cont,container,inst); + } + return objComponent; +} - bool isLoadable = container->load_component_Library(componentName, reason); - if (isLoadable) +CORBA::Object_ptr SalomeContainerTools::CreateComponentInstance(Container *cont, Engines::Container_ptr contPtr, const ComponentInstance *inst) +{ + if(!inst) + throw Exception("SalomeContainerTools::CreateComponentInstance : no instance of component in the task requesting for a load of its component !"); + char *reason(0); + std::string compoName(inst->getCompoName()); + CORBA::Object_ptr objComponent=CORBA::Object::_nil(); + int studyid(1); + Proc* p(cont->getProc()); + if(p) { - CORBA::string_free(reason); - int studyid=1; - Proc* p(cont->getProc()); - if(p) - { - std::string value(p->getProperty("DefaultStudyID")); - if(!value.empty()) - studyid= atoi(value.c_str()); - } - // prepare component instance properties - Engines::FieldsDict_var env = new Engines::FieldsDict; - std::map properties = inst->getProperties(); - if(p) - { - std::map procMap=p->getProperties(); - properties.insert(procMap.begin(),procMap.end()); - } - - std::map::const_iterator itm; - env->length(properties.size()); - int item=0; - for(itm = properties.begin(); itm != properties.end(); ++itm, item++) - { - DEBTRACE("envname="<first<<" envvalue="<< itm->second); - env[item].key= CORBA::string_dup(itm->first.c_str()); - env[item].value <<= itm->second.c_str(); - } + std::string value(p->getProperty("DefaultStudyID")); + if(!value.empty()) + studyid= atoi(value.c_str()); + } + // prepare component instance properties + Engines::FieldsDict_var env(new Engines::FieldsDict); + std::map properties(inst->getProperties()); + if(p) + { + std::map procMap=p->getProperties(); + properties.insert(procMap.begin(),procMap.end()); + } - objComponent=container->create_component_instance_env(componentName, studyid, env, reason); + std::map::const_iterator itm; + env->length(properties.size()); + int item=0; + for(itm = properties.begin(); itm != properties.end(); ++itm, item++) + { + DEBTRACE("envname="<first<<" envvalue="<< itm->second); + env[item].key= CORBA::string_dup(itm->first.c_str()); + env[item].value <<= itm->second.c_str(); } + objComponent=contPtr->create_component_instance_env(compoName.c_str(), studyid, env, reason); if(CORBA::is_nil(objComponent)) { - cont->unLock(); std::string text="Error while trying to create a new component: component '"+ compoName; text=text+"' is not installed or it's a wrong name"; text += '\n'; @@ -486,7 +486,6 @@ CORBA::Object_ptr SalomeContainerTools::LoadComponent(SalomeContainerHelper *lau CORBA::string_free(reason); throw Exception(text); } - cont->unLock(); return objComponent; } diff --git a/src/runtime/SalomeContainerTools.hxx b/src/runtime/SalomeContainerTools.hxx index 4d5d2b88d..00b24ed85 100644 --- a/src/runtime/SalomeContainerTools.hxx +++ b/src/runtime/SalomeContainerTools.hxx @@ -59,6 +59,7 @@ namespace YACS public: static void Start(const std::vector& compoNames, SalomeContainerHelper *schelp, SalomeContainerTools& sct, int& shutdownLevel, const Container *cont, const Task *askingNode); static CORBA::Object_ptr LoadComponent(SalomeContainerHelper *launchModeType, Container *cont, Task *askingNode); + static CORBA::Object_ptr CreateComponentInstance(Container *cont, Engines::Container_ptr contPtr, const ComponentInstance *inst); static std::string GetPlacementId(const SalomeContainerHelper *launchModeType, const Container *cont, const Task *askingNode); static std::string GetFullPlacementId(const SalomeContainerHelper *launchModeType, const Container *cont, const Task *askingNode); protected: diff --git a/src/runtime/SalomeHPComponent.cxx b/src/runtime/SalomeHPComponent.cxx new file mode 100644 index 000000000..1976a88da --- /dev/null +++ b/src/runtime/SalomeHPComponent.cxx @@ -0,0 +1,213 @@ +// Copyright (C) 2006-2014 CEA/DEN, EDF R&D +// +// This library is free software; you can redistribute it and/or +// modify it under the terms of the GNU Lesser General Public +// License as published by the Free Software Foundation; either +// version 2.1 of the License, or (at your option) any later version. +// +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +// Lesser General Public License for more details. +// +// You should have received a copy of the GNU Lesser General Public +// License along with this library; if not, write to the Free Software +// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA +// +// See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com +// + +#include "SalomeHPComponent.hxx" +#include "RuntimeSALOME.hxx" +#include "SalomeContainer.hxx" +#include "SalomeHPContainer.hxx" +#include "SalomeComponent.hxx" // for KIND +#include "CORBANode.hxx" +#include "AutoLocker.hxx" + +#ifdef SALOME_KERNEL +#include "SALOME_NamingService.hxx" +#include "SALOME_LifeCycleCORBA.hxx" +#endif + +#include +#include +#include + +//#define _DEVDEBUG_ +#include "YacsTrace.hxx" + + +namespace YACS +{ + namespace ENGINE + { + class SalomeContainerTmpForHP : public SalomeContainer + { + public: + SalomeContainerTmpForHP(const Container& other, const SalomeContainerTools& sct, SalomeContainerHelper *lmt, + const std::vector& componentNames, int shutdownLev, + const SalomeHPContainer *zeOriginCont, std::size_t pos):SalomeContainer(other,sct,lmt,componentNames,shutdownLev),_zeOriginCont(zeOriginCont),_pos(pos) { } + std::string getDiscreminantStrOfThis() const { std::ostringstream oss; oss << _zeOriginCont << "_" << _pos; return oss.str(); } + CORBA::Object_ptr loadComponent(Task *inst); + private: + const SalomeHPContainer *_zeOriginCont; + std::size_t _pos; + }; + } +} + +using namespace YACS::ENGINE; +using namespace std; + +const char SalomeHPComponent::KIND[]="HPSalome"; + +CORBA::Object_ptr SalomeContainerTmpForHP::loadComponent(Task *askingNode) +{ + const ComponentInstance *inst(askingNode?askingNode->getComponent():0); + if(!inst) + throw Exception("SalomeContainerTmpForHP::loadComponent : asking to load a component on the given task whereas this task has no component !"); + std::string compoName(inst->getCompoName()); + { + YACS::BASES::AutoLocker alck(this);//To be sure + if(!this->isAlreadyStarted(askingNode)) + this->start(askingNode); + } + CORBA::Object_ptr objComponent=CORBA::Object::_nil(); + { + YACS::BASES::AutoLocker alck(this);//To be sure + std::string compoName(inst->getCompoName()); + Engines::Container_var container(_launchModeType->getContainer(askingNode)); + objComponent=container->find_component_instance(compoName.c_str(),0); + if(CORBA::is_nil(objComponent)) + { + char *reason; + bool isLoadable(container->load_component_Library(compoName.c_str(), reason)); + if(isLoadable) + objComponent=SalomeContainerTools::CreateComponentInstance(this,container,inst); + } + } + return objComponent; +} + +SalomeHPComponent::SalomeHPComponent(const std::string& name): ComponentInstance(name) +{ + _objComponent=CORBA::Object::_nil(); +} + +SalomeHPComponent::SalomeHPComponent(const SalomeHPComponent& other):ComponentInstance(other) +{ + _objComponent=CORBA::Object::_nil(); +} + +SalomeHPComponent::~SalomeHPComponent() +{ +} + +std::string SalomeHPComponent::getKind() const +{ + return KIND; +} + +std::string SalomeHPComponent::getKindForNode() const +{ + return SalomeComponent::KIND; +} + +//! Unload the component +void SalomeHPComponent::unload(Task *askingNode) +{ + //Not implemented + std::cerr << "SalomeHPComponent::unload : not implemented " << std::endl; +} + +//! Is the component instance already loaded ? +bool SalomeHPComponent::isLoaded(Task *askingNode) const +{ + return false; +} + +//#ifdef SALOME_KERNEL +//! Load the component +void SalomeHPComponent::load(Task *askingNode) +{ + if(_container) + { + SalomeHPContainer *salomeContainer(dynamic_cast(_container)); + if(salomeContainer) + { + SalomeContainerHelper *lmt(0); + std::size_t posIn(0); + { + YACS::BASES::AutoLocker altck(salomeContainer); + lmt=salomeContainer->getHelperOfTask(askingNode); + posIn=salomeContainer->locateTask(askingNode); + } + SalomeContainerTmpForHP tmpCont(*salomeContainer,salomeContainer->getContainerInfo(),lmt, + salomeContainer->getComponentNames(),salomeContainer->getShutdownLev(),salomeContainer,posIn); + _objComponent=tmpCont.loadComponent(askingNode); + return ; + } + throw Exception("Unrecognized type of Container ! Only Salome and HPSalome container are supported by the Salome components !"); + } + else + throw Exception("No container on HP component ! Impossible to load !"); +} +/*#else +void SalomeComponent::load(Task *askingNode) +{ + throw Exception("YACS has been built without SALOME support"); +} +#endif*/ + +//! Create a ServiceNode with this component instance and no input or output port +/*! + * \param name : node name + * \return a new SalomeNode node + */ +ServiceNode* SalomeHPComponent::createNode(const std::string& name) +{ + SalomeNode* node(new SalomeNode(name)); + node->setComponent(this); + return node; +} + +//! Clone the component instance +ComponentInstance* SalomeHPComponent::clone() const +{ + if(_isAttachedOnCloning) + { + incrRef(); + return (ComponentInstance*) (this); + } + else + return new SalomeHPComponent(*this); +} + +std::string SalomeHPComponent::getFileRepr() const +{ + ostringstream stream; + stream << "" << getCompoName() << ""; + return stream.str(); +} + +bool SalomeHPComponent::setContainer(Container *cont) +{ + if(!dynamic_cast(cont)) + throw Exception("SalomeHPComponent::setContainer : a Salome HP component must be attached to a Salome HP container !"); + if(ComponentInstance::setContainer(cont)) + { + if(_container) + _container->addComponentName(_compoName); + return true; + } + else + return false; +} + +void SalomeHPComponent::shutdown(int level) +{ + DEBTRACE("SalomeHPComponent::shutdown " << level); + if(_container) + _container->shutdown(level); +} diff --git a/src/runtime/SalomeHPComponent.hxx b/src/runtime/SalomeHPComponent.hxx new file mode 100644 index 000000000..3ca7a1c29 --- /dev/null +++ b/src/runtime/SalomeHPComponent.hxx @@ -0,0 +1,56 @@ +// Copyright (C) 2006-2014 CEA/DEN, EDF R&D +// +// This library is free software; you can redistribute it and/or +// modify it under the terms of the GNU Lesser General Public +// License as published by the Free Software Foundation; either +// version 2.1 of the License, or (at your option) any later version. +// +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +// Lesser General Public License for more details. +// +// You should have received a copy of the GNU Lesser General Public +// License along with this library; if not, write to the Free Software +// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA +// +// See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com +// + +#ifndef _SALOMEHPCOMPONENT_HXX_ +#define _SALOMEHPCOMPONENT_HXX_ + +#include "YACSRuntimeSALOMEExport.hxx" +#include "ComponentInstance.hxx" +#include + +namespace YACS +{ + namespace ENGINE + { + class YACSRUNTIMESALOME_EXPORT SalomeHPComponent : public ComponentInstance + { + public: + SalomeHPComponent(const std::string& name); + SalomeHPComponent(const SalomeHPComponent& other); + virtual ~SalomeHPComponent(); + virtual void load(Task *askingNode); + virtual void unload(Task *askingNode); + virtual bool isLoaded(Task *askingNode) const; + virtual bool setContainer(Container *cont); + virtual ServiceNode* createNode(const std::string& name); + virtual ComponentInstance* clone() const; + virtual std::string getFileRepr() const; + virtual CORBA::Object_ptr getCompoPtr(){return CORBA::Object::_duplicate(_objComponent);} + virtual void shutdown(int level); + public: + static const char KIND[]; + virtual std::string getKind() const; + virtual std::string getKindForNode() const; + protected: + CORBA::Object_var _objComponent; + }; + } +} + +#endif diff --git a/src/runtime/SalomeHPContainer.cxx b/src/runtime/SalomeHPContainer.cxx index 79a482ade..82c3d5dcc 100644 --- a/src/runtime/SalomeHPContainer.cxx +++ b/src/runtime/SalomeHPContainer.cxx @@ -18,7 +18,7 @@ // #include "SalomeHPContainer.hxx" -#include "SalomeComponent.hxx" +#include "SalomeHPComponent.hxx" #include @@ -150,6 +150,6 @@ std::map SalomeHPContainer::getResourceProperties(const void SalomeHPContainer::checkCapabilityToDealWith(const ComponentInstance *inst) const throw(YACS::Exception) { - if(inst->getKind()!=SalomeComponent::KIND) + if(inst->getKind()!=SalomeHPComponent::KIND) throw Exception("SalomeHPContainer::checkCapabilityToDealWith : SalomeContainer is not able to deal with this type of ComponentInstance."); } diff --git a/src/runtime/SalomeHPContainer.hxx b/src/runtime/SalomeHPContainer.hxx index e3e536e26..0e0ab738c 100644 --- a/src/runtime/SalomeHPContainer.hxx +++ b/src/runtime/SalomeHPContainer.hxx @@ -71,6 +71,7 @@ namespace YACS void checkCapabilityToDealWith(const ComponentInstance *inst) const throw(YACS::Exception); // #ifndef SWIG + std::size_t locateTask(const Task *askingNode) const { return _launchModeType.locateTask(askingNode); } const SalomeContainerTools &getContainerInfo() const { return _sct; } std::vector getComponentNames() const { return _componentNames; } int getShutdownLev() const { return _shutdownLevel; } diff --git a/src/runtime/SalomeHPContainerTools.cxx b/src/runtime/SalomeHPContainerTools.cxx index 92d83d59a..57a7afdec 100644 --- a/src/runtime/SalomeHPContainerTools.cxx +++ b/src/runtime/SalomeHPContainerTools.cxx @@ -69,16 +69,6 @@ void SalomeHPContainerVectOfHelper::release(const Task *node) _currentlyWorking.erase(it); } -const SalomeContainerMonoHelper *SalomeHPContainerVectOfHelper::getHelperOfTask(const Task *node) const -{ - return _launchModeType[locateTask(node)]; -} - -SalomeContainerMonoHelper *SalomeHPContainerVectOfHelper::getHelperOfTask(const Task *node) -{ - return _launchModeType[locateTask(node)]; -} - std::size_t SalomeHPContainerVectOfHelper::locateTask(const Task *node) const { std::map< const Task *,std::size_t >::const_iterator it(_currentlyWorking.find(node)); @@ -89,6 +79,16 @@ std::size_t SalomeHPContainerVectOfHelper::locateTask(const Task *node) const return ret; } +const SalomeContainerMonoHelper *SalomeHPContainerVectOfHelper::getHelperOfTask(const Task *node) const +{ + return _launchModeType[locateTask(node)]; +} + +SalomeContainerMonoHelper *SalomeHPContainerVectOfHelper::getHelperOfTask(const Task *node) +{ + return _launchModeType[locateTask(node)]; +} + void SalomeHPContainerVectOfHelper::checkNoCurrentWork() const { for(std::map::const_iterator it=_currentlyWorking.begin();it!=_currentlyWorking.end();it++) diff --git a/src/runtime/SalomeHPContainerTools.hxx b/src/runtime/SalomeHPContainerTools.hxx index d3beec092..c02b4267f 100644 --- a/src/runtime/SalomeHPContainerTools.hxx +++ b/src/runtime/SalomeHPContainerTools.hxx @@ -43,12 +43,12 @@ namespace YACS std::size_t getNumberOfFreePlace() const; void allocateFor(const std::vector& nodes); void release(const Task *node); + std::size_t locateTask(const Task *node) const; const SalomeContainerMonoHelper *at(std::size_t pos) const { checkPosInVec(pos); return _launchModeType[pos]; } SalomeContainerMonoHelper *at(std::size_t pos) { checkPosInVec(pos); return _launchModeType[pos]; } const SalomeContainerMonoHelper *getHelperOfTask(const Task *node) const; SalomeContainerMonoHelper *getHelperOfTask(const Task *node); private: - std::size_t locateTask(const Task *node) const; void checkNoCurrentWork() const; void checkPosInVec(std::size_t pos) const; private: -- 2.39.2