From ab310dc68c4114bae2a1744fbd424029b2aa68fe Mon Sep 17 00:00:00 2001 From: Anthony Geay Date: Fri, 1 Aug 2014 15:55:16 +0200 Subject: [PATCH] Ready to update Executor to take into account of the new type of containers. --- src/engine/ComponentInstance.hxx | 9 +- src/engine/Container.cxx | 3 - src/engine/Container.hxx | 11 ++- src/engine/ElementaryNode.cxx | 5 + src/engine/ElementaryNode.hxx | 1 + src/engine/Executor.cxx | 6 +- src/engine/InlineNode.cxx | 13 ++- src/engine/InlineNode.hxx | 7 +- src/engine/PropertyInterface.hxx | 2 +- src/engine/ServiceNode.cxx | 5 + src/engine/ServiceNode.hxx | 1 + src/engine/Task.hxx | 1 + src/engine/Test/ComponentInstanceTest.cxx | 12 +-- src/engine/Test/ComponentInstanceTest.hxx | 12 +-- src/engine/Test/ContainerTest.cxx | 8 +- src/engine/Test/ContainerTest.hxx | 18 ++-- src/engine_swig/pilot.i | 2 + src/runtime/CMakeLists.txt | 2 + src/runtime/CORBAComponent.cxx | 6 +- src/runtime/CORBAComponent.hxx | 6 +- src/runtime/CppComponent.cxx | 72 +++++++------- src/runtime/CppComponent.hxx | 6 +- src/runtime/CppContainer.cxx | 115 +++++++++++----------- src/runtime/CppContainer.hxx | 9 +- src/runtime/DistributedPythonNode.cxx | 2 +- src/runtime/PythonNode.cxx | 16 +-- src/runtime/RuntimeSALOME.cxx | 3 + src/runtime/SalomeComponent.cxx | 8 +- src/runtime/SalomeComponent.hxx | 8 +- src/runtime/SalomeContainer.cxx | 26 ++--- src/runtime/SalomeContainer.hxx | 12 +-- src/runtime/SalomeContainerHelper.cxx | 16 +-- src/runtime/SalomeContainerHelper.hxx | 19 ++-- src/runtime/SalomeContainerTools.cxx | 26 ++--- src/runtime/SalomeContainerTools.hxx | 9 +- src/runtime/SalomeHPContainer.cxx | 113 ++++++++++++++++++++- src/runtime/SalomeHPContainer.hxx | 34 ++++++- src/runtime/SalomeHPContainerTools.cxx | 101 +++++++++++++++++++ src/runtime/SalomeHPContainerTools.hxx | 60 +++++++++++ src/runtime/SalomePythonComponent.cxx | 14 +-- src/runtime/SalomePythonComponent.hxx | 8 +- src/runtime/SalomePythonNode.cxx | 2 +- src/runtime_swig/SALOMERuntime.i | 2 + 43 files changed, 574 insertions(+), 237 deletions(-) create mode 100644 src/runtime/SalomeHPContainerTools.cxx create mode 100644 src/runtime/SalomeHPContainerTools.hxx diff --git a/src/engine/ComponentInstance.hxx b/src/engine/ComponentInstance.hxx index d3caef620..f76ff3019 100644 --- a/src/engine/ComponentInstance.hxx +++ b/src/engine/ComponentInstance.hxx @@ -31,8 +31,9 @@ namespace YACS { namespace ENGINE { - class Container; + class Task; class ServiceNode; + class Container; class YACSLIBENGINE_EXPORT ComponentInstance : public PropertyInterface, public RefCounter { @@ -50,11 +51,11 @@ namespace YACS virtual void setContainer(Container *cont); Container *getContainer() const { return _container; } //! Load the component instance - virtual void load(ServiceNode *askingNode) = 0; + virtual void load(Task *askingNode) = 0; //! Unload the component instance - virtual void unload(ServiceNode *askingNode) = 0; + virtual void unload(Task *askingNode) = 0; //! Indicate if the component instance is loaded (true) or not - virtual bool isLoaded(ServiceNode *askingNode) = 0; + virtual bool isLoaded(Task *askingNode) const = 0; virtual void attachOnCloning() const; virtual void dettachOnCloning() const; bool isAttachedOnCloning() const; diff --git a/src/engine/Container.cxx b/src/engine/Container.cxx index 133c5784a..b77a26210 100644 --- a/src/engine/Container.cxx +++ b/src/engine/Container.cxx @@ -70,6 +70,3 @@ void Container::setProperties(const std::map& propertie setProperty((*it).first,(*it).second); } -void Container::shutdown(int level) -{ -} diff --git a/src/engine/Container.hxx b/src/engine/Container.hxx index 00675f643..1a7c2aed2 100644 --- a/src/engine/Container.hxx +++ b/src/engine/Container.hxx @@ -33,6 +33,7 @@ namespace YACS { class ComponentInstance; class Proc; + class Task; /*! * This is an abstract class, that represents an abstract process in which ComponentInstances can be launched and run. * An instance of this will be mapped to one and only one physical container (except in the foreach context) @@ -46,10 +47,10 @@ namespace YACS #endif public: //Execution only methods - virtual bool isAlreadyStarted(const ComponentInstance *inst) const = 0; - virtual void start(const ComponentInstance *inst) throw(Exception) = 0; - virtual std::string getPlacementId(const ComponentInstance *inst) const = 0; - virtual std::string getFullPlacementId(const ComponentInstance *inst) const = 0; + 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; + virtual std::string getFullPlacementId(const Task *askingNode) const = 0; //Edition only methods virtual void attachOnCloning() const; virtual void dettachOnCloning() const; @@ -72,7 +73,7 @@ namespace YACS void setName(std::string name) { _name = name; }; void setProc(Proc* proc) { _proc = proc; }; Proc* getProc() { return _proc; }; - virtual void shutdown(int level); + virtual void shutdown(int level) = 0; protected: std::string _name; mutable bool _isAttachedOnCloning; diff --git a/src/engine/ElementaryNode.cxx b/src/engine/ElementaryNode.cxx index 145d5e56f..933768992 100644 --- a/src/engine/ElementaryNode.cxx +++ b/src/engine/ElementaryNode.cxx @@ -111,6 +111,11 @@ ComponentInstance *ElementaryNode::getComponent() return 0; } +const ComponentInstance *ElementaryNode::getComponent() const +{ + return 0; +} + Container *ElementaryNode::getContainer() { return 0; diff --git a/src/engine/ElementaryNode.hxx b/src/engine/ElementaryNode.hxx index 8cfb57759..62d8e185d 100644 --- a/src/engine/ElementaryNode.hxx +++ b/src/engine/ElementaryNode.hxx @@ -62,6 +62,7 @@ namespace YACS void init(bool start=true); bool isDeployable() const; ComponentInstance *getComponent(); + const ComponentInstance *getComponent() const; Container *getContainer(); YACS::StatesForNode getState() const; void getReadyTasks(std::vector& tasks); diff --git a/src/engine/Executor.cxx b/src/engine/Executor.cxx index 1f958a0ef..46dc33c52 100644 --- a/src/engine/Executor.cxx +++ b/src/engine/Executor.cxx @@ -25,6 +25,7 @@ #include "ComponentInstance.hxx" #include "VisitorSaveState.hxx" +#include "ServiceNode.hxx" #include "ComposedNode.hxx" #include @@ -1235,8 +1236,9 @@ void Executor::traceExec(Task *task, const std::string& message) { containerName = cont->getName(); ComponentInstance *compo = task->getComponent(); - //if (compo) - placement = cont->getFullPlacementId(compo); + ServiceNode *taskCast(dynamic_cast(task)); + if(taskCast) + placement = cont->getFullPlacementId(taskCast); } #ifdef WIN32 DWORD now = timeGetTime(); diff --git a/src/engine/InlineNode.cxx b/src/engine/InlineNode.cxx index 57194ae52..b2f4b757a 100644 --- a/src/engine/InlineNode.cxx +++ b/src/engine/InlineNode.cxx @@ -29,7 +29,11 @@ using namespace YACS::ENGINE; using namespace std; -InlineNode::~InlineNode() { } +InlineNode::~InlineNode() +{ + if(_container) + _container->decrRef(); +} void InlineNode::accept(Visitor *visitor) { @@ -48,9 +52,7 @@ void InlineNode::setScript(const std::string& script) InlineFuncNode::~InlineFuncNode() -{ - if(_container) - _container->decrRef(); +{ } void InlineFuncNode::accept(Visitor *visitor) @@ -58,6 +60,9 @@ void InlineFuncNode::accept(Visitor *visitor) visitor->visitInlineFuncNode(this); } +/*! + * \param fname: name of the function contained in the script to execute + */ void InlineFuncNode::setFname(const std::string& fname) { _fname=fname; diff --git a/src/engine/InlineNode.hxx b/src/engine/InlineNode.hxx index f6f15c02f..402eafe0e 100644 --- a/src/engine/InlineNode.hxx +++ b/src/engine/InlineNode.hxx @@ -91,15 +91,12 @@ namespace YACS :InlineNode(other,father),_fname(other._fname) { } InlineFuncNode(const std::string& name):InlineNode(name) { } public: -//! Set the function name to use in node execution -/*! - * \param fname: name of the function contained in the script to execute - */ + //! Set the function name to use in node execution virtual void setFname(const std::string& fname); virtual std::string getFname() { return _fname; } void accept(Visitor *visitor); virtual ~InlineFuncNode(); - virtual std::string typeName() {return "YACS__ENGINE__InlineFuncNode";} + virtual std::string typeName() { return "YACS__ENGINE__InlineFuncNode"; } virtual void checkBasicConsistency() const throw(Exception); protected: std::string _fname; diff --git a/src/engine/PropertyInterface.hxx b/src/engine/PropertyInterface.hxx index 7c53eccf0..1d8e735b0 100644 --- a/src/engine/PropertyInterface.hxx +++ b/src/engine/PropertyInterface.hxx @@ -36,7 +36,7 @@ namespace YACS virtual void setProperty(const std::string& name,const std::string& value); virtual std::string getProperty(const std::string& name); - std::map getProperties() { return _propertyMap; }; + std::map getProperties() const { return _propertyMap; }; virtual void setProperties(std::map properties); protected: std::map _propertyMap; diff --git a/src/engine/ServiceNode.cxx b/src/engine/ServiceNode.cxx index 8f9f312f3..89e23e872 100644 --- a/src/engine/ServiceNode.cxx +++ b/src/engine/ServiceNode.cxx @@ -113,6 +113,11 @@ ComponentInstance *ServiceNode::getComponent() return _component; } +const ComponentInstance *ServiceNode::getComponent() const +{ + return _component; +} + //! Return the associated container Container *ServiceNode::getContainer() { diff --git a/src/engine/ServiceNode.hxx b/src/engine/ServiceNode.hxx index a079a9288..99bf25ee3 100644 --- a/src/engine/ServiceNode.hxx +++ b/src/engine/ServiceNode.hxx @@ -42,6 +42,7 @@ namespace YACS virtual bool isDeployable() const; virtual void setComponent(ComponentInstance* compo) throw(Exception); virtual ComponentInstance *getComponent(); + virtual const ComponentInstance *getComponent() const; virtual Container *getContainer(); virtual void setRef(const std::string& ref); virtual std::string getRef(); diff --git a/src/engine/Task.hxx b/src/engine/Task.hxx index 4f9d0ba54..65f56b8ee 100644 --- a/src/engine/Task.hxx +++ b/src/engine/Task.hxx @@ -46,6 +46,7 @@ namespace YACS virtual void getCoupledTasks(std::set& coupledSet) = 0; virtual bool isDeployable() const = 0; virtual ComponentInstance *getComponent() = 0; + virtual const ComponentInstance *getComponent() const = 0; virtual Container *getContainer() = 0; virtual YACS::StatesForNode getState() const = 0; virtual void finished() = 0; diff --git a/src/engine/Test/ComponentInstanceTest.cxx b/src/engine/Test/ComponentInstanceTest.cxx index 6cc6b79f5..c18e738e3 100644 --- a/src/engine/Test/ComponentInstanceTest.cxx +++ b/src/engine/Test/ComponentInstanceTest.cxx @@ -31,17 +31,17 @@ ComponentInstanceTest1::ComponentInstanceTest1(const std::string& name):Componen { } -void ComponentInstanceTest1::load(ServiceNode *askingNode) +void ComponentInstanceTest1::load(Task *askingNode) { _loaded=true; } -void ComponentInstanceTest1::unload(ServiceNode *askingNode) +void ComponentInstanceTest1::unload(Task *askingNode) { _loaded=false; } -bool ComponentInstanceTest1::isLoaded(ServiceNode *askingNode) +bool ComponentInstanceTest1::isLoaded(Task *askingNode) const { return _loaded; } @@ -77,17 +77,17 @@ ComponentInstanceTest2::ComponentInstanceTest2(const std::string& name):Componen { } -void ComponentInstanceTest2::load(ServiceNode *askingNode) +void ComponentInstanceTest2::load(Task *askingNode) { _loaded=true; } -void ComponentInstanceTest2::unload(ServiceNode *askingNode) +void ComponentInstanceTest2::unload(Task *askingNode) { _loaded=false; } -bool ComponentInstanceTest2::isLoaded(ServiceNode *askingNode) +bool ComponentInstanceTest2::isLoaded(Task *askingNode) const { return _loaded; } diff --git a/src/engine/Test/ComponentInstanceTest.hxx b/src/engine/Test/ComponentInstanceTest.hxx index 503867f2d..71fef605b 100644 --- a/src/engine/Test/ComponentInstanceTest.hxx +++ b/src/engine/Test/ComponentInstanceTest.hxx @@ -31,9 +31,9 @@ namespace YACS public: ComponentInstanceTest1(const ComponentInstanceTest1& other); ComponentInstanceTest1(const std::string& name); - void load(ServiceNode *askingNode); - void unload(ServiceNode *askingNode); - bool isLoaded(ServiceNode *askingNode); + void load(Task *askingNode); + void unload(Task *askingNode); + bool isLoaded(Task *askingNode) const; std::string getKind() const; ServiceNode* createNode(const std::string& name); ComponentInstance *clone() const; @@ -46,9 +46,9 @@ namespace YACS public: ComponentInstanceTest2(const ComponentInstanceTest2& other); ComponentInstanceTest2(const std::string& name); - void load(ServiceNode *askingNode); - void unload(ServiceNode *askingNode); - bool isLoaded(ServiceNode *askingNode); + void load(Task *askingNode); + void unload(Task *askingNode); + bool isLoaded(Task *askingNode) const; std::string getKind() const; ServiceNode* createNode(const std::string& name); ComponentInstance *clone() const; diff --git a/src/engine/Test/ContainerTest.cxx b/src/engine/Test/ContainerTest.cxx index fbad9fa71..f1450843e 100644 --- a/src/engine/Test/ContainerTest.cxx +++ b/src/engine/Test/ContainerTest.cxx @@ -44,12 +44,12 @@ std::string ContainerTest::getPlacementInfo() const return stream.str(); } -bool ContainerTest::isAlreadyStarted(const ComponentInstance *inst) const +bool ContainerTest::isAlreadyStarted(const Task *askingNode) const { return _alreadyStarted; } -void ContainerTest::start(const ComponentInstance *inst) throw(YACS::Exception) +void ContainerTest::start(const Task *askingNode) throw(YACS::Exception) { if(_alreadyStarted) throw Exception("ContainerTest already started !!!!"); @@ -87,12 +87,12 @@ ContainerTest2::ContainerTest2():_alreadyStarted(false),_myCounter(_counter++) { } -bool ContainerTest2::isAlreadyStarted(const ComponentInstance *inst) const +bool ContainerTest2::isAlreadyStarted(const Task *askingNode) const { return _alreadyStarted; } -void ContainerTest2::start(const ComponentInstance *inst) throw(YACS::Exception) +void ContainerTest2::start(const Task *askingNode) throw(YACS::Exception) { if(_alreadyStarted) throw Exception("ContainerTest already started !!!!"); diff --git a/src/engine/Test/ContainerTest.hxx b/src/engine/Test/ContainerTest.hxx index d77edcce2..bfd49a872 100644 --- a/src/engine/Test/ContainerTest.hxx +++ b/src/engine/Test/ContainerTest.hxx @@ -32,21 +32,22 @@ namespace YACS ContainerTest(); std::string getPlacementInfo() const; // implementation of compulsary methods - bool isAlreadyStarted(const ComponentInstance *inst) const; - void start(const ComponentInstance *inst) throw(Exception); + bool isAlreadyStarted(const Task *askingNode) const; + void start(const Task *askingNode) throw(Exception); Container *clone() const; Container *cloneAlways() const; // void lock() { } void unLock() { } void clearProperties() { } + void shutdown(int level) { } void setProperty(const std::string& name,const std::string& value) { } std::string getProperty(const std::string& name) const { } std::map getResourceProperties(const std::string& name) const { return std::map(); } std::map getProperties() const { return std::map(); } // - std::string getPlacementId(const ComponentInstance *inst) const { return ""; } - std::string getFullPlacementId(const ComponentInstance *inst) const { return ""; } + std::string getPlacementId(const Task *askingNode) const { return ""; } + std::string getFullPlacementId(const Task *askingNode) const { return ""; } static void initAllContainers(); protected: void checkCapabilityToDealWith(const ComponentInstance *inst) const throw(Exception); @@ -62,21 +63,22 @@ namespace YACS public: ContainerTest2(); // implementation of compulsary methods - bool isAlreadyStarted(const ComponentInstance *inst) const; - void start(const ComponentInstance *inst) throw(Exception); + bool isAlreadyStarted(const Task *askingNode) const; + void start(const Task *askingNode) throw(Exception); Container *clone() const; Container *cloneAlways() const; // void lock() { } void unLock() { } void clearProperties() { } + void shutdown(int level) { } void setProperty(const std::string& name,const std::string& value) { } std::string getProperty(const std::string& name) const { } std::map getResourceProperties(const std::string& name) const { return std::map(); } std::map getProperties() const { return std::map(); } // - std::string getPlacementId(const ComponentInstance *inst) const { return ""; } - std::string getFullPlacementId(const ComponentInstance *inst) const { return ""; } + std::string getPlacementId(const Task *askingNode) const { return ""; } + std::string getFullPlacementId(const Task *askingNode) const { return ""; } static void initAllContainers(); protected: void checkCapabilityToDealWith(const ComponentInstance *inst) const throw(Exception); diff --git a/src/engine_swig/pilot.i b/src/engine_swig/pilot.i index f2ffcb3f0..01bc22dc1 100644 --- a/src/engine_swig/pilot.i +++ b/src/engine_swig/pilot.i @@ -53,6 +53,7 @@ #include "ExecutorSwig.hxx" #include "Dispatcher.hxx" #include "Container.hxx" +#include "HomogeneousPoolContainer.hxx" #include "Logger.hxx" #include "DeploymentTree.hxx" #include "ComponentInstance.hxx" @@ -247,6 +248,7 @@ EXCEPTION(YACS::ENGINE::ExecutorSwig::waitPause) %include %include +%include %include %extend YACS::ENGINE::InputPort { diff --git a/src/runtime/CMakeLists.txt b/src/runtime/CMakeLists.txt index bb8e6299b..42f0956f7 100644 --- a/src/runtime/CMakeLists.txt +++ b/src/runtime/CMakeLists.txt @@ -120,6 +120,7 @@ SET(YACSRuntimeSALOME_HEADERS SalomeContainerTools.hxx SalomeContainerHelper.hxx SalomeHPContainer.hxx + SalomeHPContainerTools.hxx SALOMEDispatcher.hxx SalomeProc.hxx SalomePythonComponent.hxx @@ -172,6 +173,7 @@ SET(YACSRuntimeSALOME_SOURCES SalomeContainer.cxx SalomeContainerTools.cxx SalomeHPContainer.cxx + SalomeHPContainerTools.cxx SalomeContainerHelper.cxx PythonPorts.cxx XMLNode.cxx diff --git a/src/runtime/CORBAComponent.cxx b/src/runtime/CORBAComponent.cxx index 538eebe14..09132ebe9 100644 --- a/src/runtime/CORBAComponent.cxx +++ b/src/runtime/CORBAComponent.cxx @@ -69,7 +69,7 @@ std::string CORBAComponent::getKind() const } //! Unload the component -void CORBAComponent::unload(ServiceNode *askingNode) +void CORBAComponent::unload(Task *askingNode) { //Not implemented std::cerr << "CORBAComponent::unload : not implemented " << std::endl; @@ -84,7 +84,7 @@ CORBA::Object_ptr CORBAComponent::getCompoPtr() } //! Is the component instance already loaded ? -bool CORBAComponent::isLoaded(ServiceNode *askingNode) +bool CORBAComponent::isLoaded(Task *askingNode) const { if(CORBA::is_nil(_objComponent)) return false; @@ -93,7 +93,7 @@ bool CORBAComponent::isLoaded(ServiceNode *askingNode) } //! Load the component -void CORBAComponent::load(ServiceNode *askingNode) +void CORBAComponent::load(Task *askingNode) { DEBTRACE( "CORBAComponent::load" ); CORBA::ORB_ptr orb; diff --git a/src/runtime/CORBAComponent.hxx b/src/runtime/CORBAComponent.hxx index 1b93f69d2..c6b4222ba 100644 --- a/src/runtime/CORBAComponent.hxx +++ b/src/runtime/CORBAComponent.hxx @@ -39,9 +39,9 @@ namespace YACS CORBAComponent(const std::string& name); CORBAComponent(const CORBAComponent& other); virtual ~CORBAComponent(); - virtual void load(ServiceNode *askingNode); - virtual void unload(ServiceNode *askingNode); - virtual bool isLoaded(ServiceNode *askingNode); + virtual void load(Task *askingNode); + virtual void unload(Task *askingNode); + virtual bool isLoaded(Task *askingNode) const; virtual ServiceNode* createNode(const std::string& name); virtual ComponentInstance* clone() const; virtual std::string getFileRepr() const; diff --git a/src/runtime/CppComponent.cxx b/src/runtime/CppComponent.cxx index fb877df38..fb3b1b8c8 100644 --- a/src/runtime/CppComponent.cxx +++ b/src/runtime/CppComponent.cxx @@ -78,34 +78,33 @@ std::string CppComponent::getKind() const } //! CppComponent constructor -CppComponent::CppComponent(const std::string &name) : ComponentInstance(name) +CppComponent::CppComponent(const std::string &name) : ComponentInstance(name), __obj(0), __run(0),__terminate(0) { _container = getRuntime()->createContainer(CppNode::KIND); - if (!_container->isAlreadyStarted(this)) - _container->start(this); - + /* This part of code has been commented because the load part is supposed to do that ! + if (!_container->isAlreadyStarted(0)) + _container->start(0); CppContainer * _containerC = dynamic_cast (_container); - _containerC->createInternalInstance(name, __obj, __run, __terminate); + _containerC->createInternalInstance(name, __obj, __run, __terminate);*/ } //! CppComponent copy constructor -CppComponent::CppComponent(const CppComponent& other) : ComponentInstance(other._compoName), __run(other.__run), - __terminate(other.__terminate), __obj(0) +CppComponent::CppComponent(const CppComponent& other) : ComponentInstance(other._compoName), __obj(0), __run(0),__terminate(0) { _container = getRuntime()->createContainer(CppNode::KIND); - if (!_container->isAlreadyStarted(this)) - _container->start(this); - + /* This part of code has been commented because the load part is supposed to do that ! + if (!_container->isAlreadyStarted(0)) + _container->start(0); CppContainer * _containerC = dynamic_cast (_container); - _containerC->createInternalInstance(_compoName, __obj, __run, __terminate); + _containerC->createInternalInstance(_compoName, __obj, __run, __terminate);*/ } CppComponent::~CppComponent() { - DEBTRACE("CppComponent::~CppComponent()"); - if (__terminate) __terminate(&__obj); - if (_container) - ((CppContainer *) _container)->unregisterComponentInstance(this); + DEBTRACE("CppComponent::~CppComponent()"); + if (__terminate) __terminate(&__obj); + if (_container) + ((CppContainer *) _container)->unregisterComponentInstance(this); } void CppComponent::run (const char * service, int nbIn, int nbOut, @@ -146,48 +145,50 @@ void CppComponent::run (const char * service, int nbIn, int nbOut, } //! Unload the component -void CppComponent::unload(ServiceNode *askingNode) +void CppComponent::unload(Task *askingNode) { //Not implemented DEBTRACE("CppComponent::unload : not implemented "); } //! Is the component instance already loaded ? -bool CppComponent::isLoaded(ServiceNode *askingNode) +bool CppComponent::isLoaded(Task *askingNode) const { return NULL != __obj; } -void CppComponent::load(ServiceNode *askingNode) +void CppComponent::load(Task *askingNode) { - if (!_container) { - _container = getRuntime()->createContainer(CppNode::KIND); - } - - if(_container) { - - CppContainer * containerC= dynamic_cast< CppContainer *> (_container); - + if (!_container) + { + _container = getRuntime()->createContainer(CppNode::KIND); + } + + if(_container) + { + CppContainer *containerC(dynamic_cast< CppContainer *> (_container)); + if(!containerC) + throw Exception("The type of container should be CPP for component CPP !"); containerC->lock();//To be sure - if(!_container->isAlreadyStarted(this)) + if(!_container->isAlreadyStarted(askingNode)) { try - { - _container->start(this); - } + { + _container->start(askingNode); + } catch(Exception& e) - { + { containerC->unLock(); throw e; - } + } } containerC->unLock(); containerC->lock();//To be sure - - bool isLoadable = containerC->loadComponentLibrary(_compoName); + + bool isLoadable(containerC->loadComponentLibrary(_compoName)); if (isLoadable) containerC->createInternalInstance(_compoName, __obj, __run, __terminate); - + if(NULL == __obj) { containerC->unLock(); @@ -196,7 +197,6 @@ void CppComponent::load(ServiceNode *askingNode) containerC->unLock(); return; } - } ServiceNode* CppComponent::createNode(const std::string& name) diff --git a/src/runtime/CppComponent.hxx b/src/runtime/CppComponent.hxx index b02a8e468..50d32d5c5 100644 --- a/src/runtime/CppComponent.hxx +++ b/src/runtime/CppComponent.hxx @@ -56,9 +56,9 @@ namespace YACS static const char KIND[]; virtual std::string getKind() const; - virtual void load(ServiceNode *askingNode); - virtual void unload(ServiceNode *askingNode); - virtual bool isLoaded(ServiceNode *askingNode); + virtual void load(Task *askingNode); + virtual void unload(Task *askingNode); + virtual bool isLoaded(Task *askingNode) const; virtual ServiceNode* createNode(const std::string& name); virtual YACS::ENGINE::ComponentInstance* clone() const; diff --git a/src/runtime/CppContainer.cxx b/src/runtime/CppContainer.cxx index 1711814b0..54bcc1d51 100644 --- a/src/runtime/CppContainer.cxx +++ b/src/runtime/CppContainer.cxx @@ -73,16 +73,21 @@ void CppContainer::unLock() _mutex.unlock(); } -bool CppContainer::isAlreadyStarted(const ComponentInstance *inst) const +bool CppContainer::isAlreadyStarted(const Task *askingNode) const { return NULL != _trueCont; } -void CppContainer::start(const ComponentInstance *inst) throw (YACS::Exception) +void CppContainer::start(const Task *askingNode) throw (YACS::Exception) { _trueCont = LocalContainer::get(); } +void CppContainer::shutdown(int level) +{ + +} + Container *CppContainer::clone() const { if(_isAttachedOnCloning) @@ -100,60 +105,58 @@ Container *CppContainer::cloneAlways() const } bool CppContainer::loadComponentLibrary(const std::string & componentName) throw (YACS::Exception) -{ - if (_trueCont) { - LocalLibrary L = _trueCont->loadComponentLibrary(componentName); - return L.good(); + if (_trueCont) + { + LocalLibrary L = _trueCont->loadComponentLibrary(componentName); + return L.good(); } - else + else { - std::string mesg = "CppContainer not started"; - throw YACS::Exception(mesg); + std::string mesg = "CppContainer not started"; + throw YACS::Exception(mesg); + } + return false; } - return false; -} CppComponent * CppContainer::createComponentInstance(const std::string & componentName, int /* studyID */) { - DEBTRACE("CppContainer::createComponentInstance"); - if (_trueCont) - return _trueCont->createComponentInstance(componentName.c_str()); - else + DEBTRACE("CppContainer::createComponentInstance"); + if (_trueCont) + return _trueCont->createComponentInstance(componentName.c_str()); + else { - std::string mesg = "CppContainer not started"; - throw YACS::Exception(mesg); + std::string mesg = "CppContainer not started"; + throw YACS::Exception(mesg); } } void CppContainer::createInternalInstance(const std::string & name, void *&obj, RunFunction &r, TerminateFunction &t) { - DEBTRACE("CppContainer::createInternalInstance"); - if (_trueCont) - _trueCont->createInternalInstance(name.c_str(), obj, r, t); - else - { - std::string mesg = "CppContainer not started"; - throw YACS::Exception(mesg); - } + DEBTRACE("CppContainer::createInternalInstance"); + if (_trueCont) + _trueCont->createInternalInstance(name.c_str(), obj, r, t); + else + { + std::string mesg = "CppContainer not started"; + throw YACS::Exception(mesg); + } } -void CppContainer::unregisterComponentInstance(CppComponent * C) +void CppContainer::unregisterComponentInstance(CppComponent *compo) { - if (_trueCont) - { - _trueCont->unregisterComponentInstance(C); - } + if (_trueCont) + _trueCont->unregisterComponentInstance(compo); } -std::string CppContainer::getPlacementId(const ComponentInstance *inst) const +std::string CppContainer::getPlacementId(const Task *askingNode) const { return "/"; } -std::string CppContainer::getFullPlacementId(const ComponentInstance *inst) const +std::string CppContainer::getFullPlacementId(const Task *askingNode) const { return "/"; } @@ -189,31 +192,31 @@ LocalContainer * LocalContainer::get() void LocalContainer::destroy() { - if (NULL == _singleton) - return; - - // destroy all component instances - _instance_mapMutex.lock(); // lock - std::multimap::iterator iI, iJ; - for (iI=_instance_map.begin(); iI != _instance_map.end(); iI = iJ) + if (NULL == _singleton) + return; + + // destroy all component instances + _instance_mapMutex.lock(); // lock + std::multimap::iterator iI, iJ; + for (iI=_instance_map.begin(); iI != _instance_map.end(); iI = iJ) { iJ = iI++; iI->second->setContainer(NULL); delete iI->second; } - _instance_map.clear(); - _instance_mapMutex.unlock(); // unlock - - // unload all dynamic libraries - _library_mapMutex.lock(); - std::map::iterator iL; - for (iL=_library_map.begin(); iL != _library_map.end(); iL++) - dlclose(iL->second.handle); - _library_map.clear(); - _library_mapMutex.unlock(); - - delete _singleton; - _singleton = NULL; + _instance_map.clear(); + _instance_mapMutex.unlock(); // unlock + + // unload all dynamic libraries + _library_mapMutex.lock(); + std::map::iterator iL; + for (iL=_library_map.begin(); iL != _library_map.end(); iL++) + dlclose(iL->second.handle); + _library_map.clear(); + _library_mapMutex.unlock(); + + delete _singleton; + _singleton = NULL; } @@ -270,14 +273,14 @@ void LocalContainer::createInternalInstance(const char *name, void *&obj, void LocalContainer::unregisterComponentInstance(CppComponent * C) { - _instance_mapMutex.lock(); // lock to be alone - _instance_map.erase(C->getCompoName()); - _instance_mapMutex.unlock(); // unlock + _instance_mapMutex.lock(); // lock to be alone + _instance_map.erase(C->getCompoName()); + _instance_mapMutex.unlock(); // unlock } inline void toupper (std::string & s) { - transform (s.begin (), s.end (), s.begin (), (int(*)(int)) toupper); + transform (s.begin (), s.end (), s.begin (), (int(*)(int)) toupper); } LocalLibrary LocalContainer::loadComponentLibrary(const std::string & aCompName, const char * prefix, bool forcedLoad) diff --git a/src/runtime/CppContainer.hxx b/src/runtime/CppContainer.hxx index 012e8d17a..03ee0eb8e 100644 --- a/src/runtime/CppContainer.hxx +++ b/src/runtime/CppContainer.hxx @@ -107,10 +107,11 @@ namespace YACS public: CppContainer(); virtual ~CppContainer(); - bool isAlreadyStarted(const ComponentInstance *inst) const; - void start(const ComponentInstance *inst) throw (YACS::Exception); - std::string getPlacementId(const ComponentInstance *inst) const; - std::string getFullPlacementId(const ComponentInstance *inst) const; + bool isAlreadyStarted(const Task *askingNode) const; + void start(const Task *askingNode) throw (YACS::Exception); + void shutdown(int level); + std::string getPlacementId(const Task *askingNode) const; + std::string getFullPlacementId(const Task *askingNode) const; YACS::ENGINE::Container *clone() const; Container *cloneAlways() const; void lock(); diff --git a/src/runtime/DistributedPythonNode.cxx b/src/runtime/DistributedPythonNode.cxx index 7150a6bd9..cb65eb186 100644 --- a/src/runtime/DistributedPythonNode.cxx +++ b/src/runtime/DistributedPythonNode.cxx @@ -117,7 +117,7 @@ void DistributedPythonNode::execute() { YACSTRACE(1,"+++++++++++++++++ DistributedPythonNode::execute: " << getName() << " " << getFname() << " +++++++++++++++++" ); { - Engines::Container_var objContainer=((SalomeContainer*)_container)->getContainerPtr(0); + Engines::Container_var objContainer=((SalomeContainer*)_container)->getContainerPtr(this); Engines::PyNode_var pn=objContainer->createPyNode(getName().c_str(),getScript().c_str()); ////// int pos=0; diff --git a/src/runtime/PythonNode.cxx b/src/runtime/PythonNode.cxx index bfd3b3a68..bd33fbd14 100644 --- a/src/runtime/PythonNode.cxx +++ b/src/runtime/PythonNode.cxx @@ -132,11 +132,11 @@ void PythonNode::loadRemote() DEBTRACE( "---------------PyNode::loadRemote function---------------" ); if(_container) { - if(!_container->isAlreadyStarted(0)) + if(!_container->isAlreadyStarted(this)) { try { - _container->start(0); + _container->start(this); } catch(Exception& e) { @@ -153,7 +153,7 @@ void PythonNode::loadRemote() throw Exception(what); } - Engines::Container_var objContainer=((SalomeContainer*)_container)->getContainerPtr(0); + Engines::Container_var objContainer=((SalomeContainer*)_container)->getContainerPtr(this); try { @@ -494,7 +494,7 @@ std::string PythonNode::getContainerLog() std::string msg; try { - Engines::Container_var objContainer=((SalomeContainer*)_container)->getContainerPtr(0); + Engines::Container_var objContainer=((SalomeContainer*)_container)->getContainerPtr(this); CORBA::String_var logname = objContainer->logfilename(); DEBTRACE(logname); msg=logname; @@ -637,11 +637,11 @@ void PyFuncNode::loadRemote() DEBTRACE( "---------------PyfuncNode::loadRemote function---------------" ); if(_container) { - if(!_container->isAlreadyStarted(0)) + if(!_container->isAlreadyStarted(this)) { try { - _container->start(0); + _container->start(this); } catch(Exception& e) { @@ -658,7 +658,7 @@ void PyFuncNode::loadRemote() throw Exception(what); } - Engines::Container_var objContainer=((SalomeContainer*)_container)->getContainerPtr(0); + Engines::Container_var objContainer=((SalomeContainer*)_container)->getContainerPtr(this); try { _pynode = objContainer->createPyNode(getName().c_str(),getScript().c_str()); @@ -1089,7 +1089,7 @@ std::string PyFuncNode::getContainerLog() std::string msg; try { - Engines::Container_var objContainer=((SalomeContainer*)_container)->getContainerPtr(0); + Engines::Container_var objContainer=((SalomeContainer*)_container)->getContainerPtr(this); CORBA::String_var logname = objContainer->logfilename(); DEBTRACE(logname); msg=logname; diff --git a/src/runtime/RuntimeSALOME.cxx b/src/runtime/RuntimeSALOME.cxx index da74e14ca..7134266dc 100644 --- a/src/runtime/RuntimeSALOME.cxx +++ b/src/runtime/RuntimeSALOME.cxx @@ -55,6 +55,7 @@ #include "SalomeContainer.hxx" #include "CppContainer.hxx" +#include "SalomeHPContainer.hxx" //Nodes #include "PythonNode.hxx" @@ -595,6 +596,8 @@ Container *RuntimeSALOME::createContainer(const std::string& kind) { if(kind == "" || kind == SalomeComponent::KIND) return new SalomeContainer; + if(kind==SalomeHPContainer::KIND) + return new SalomeHPContainer; else if (kind == CppComponent::KIND) return new CppContainer; std::string msg="Container kind ("+kind+") unknown"; diff --git a/src/runtime/SalomeComponent.cxx b/src/runtime/SalomeComponent.cxx index 37add9536..2a53981c5 100644 --- a/src/runtime/SalomeComponent.cxx +++ b/src/runtime/SalomeComponent.cxx @@ -61,14 +61,14 @@ std::string SalomeComponent::getKind() const } //! Unload the component -void SalomeComponent::unload(ServiceNode *askingNode) +void SalomeComponent::unload(Task *askingNode) { //Not implemented std::cerr << "SalomeComponent::unload : not implemented " << std::endl; } //! Is the component instance already loaded ? -bool SalomeComponent::isLoaded(ServiceNode *askingNode) +bool SalomeComponent::isLoaded(Task *askingNode) const { if(CORBA::is_nil(_objComponent)) return false; @@ -78,7 +78,7 @@ bool SalomeComponent::isLoaded(ServiceNode *askingNode) #ifdef SALOME_KERNEL //! Load the component -void SalomeComponent::load(ServiceNode *askingNode) +void SalomeComponent::load(Task *askingNode) { if(_container) { @@ -96,7 +96,7 @@ void SalomeComponent::load(ServiceNode *askingNode) _objComponent=LCC.LoadComponent(params,_compoName.c_str()); } #else -void SalomeComponent::load(ServiceNode *askingNode) +void SalomeComponent::load(Task *askingNode) { throw Exception("YACS has been built without SALOME support"); } diff --git a/src/runtime/SalomeComponent.hxx b/src/runtime/SalomeComponent.hxx index f28da0974..743b5afcb 100644 --- a/src/runtime/SalomeComponent.hxx +++ b/src/runtime/SalomeComponent.hxx @@ -28,8 +28,6 @@ namespace YACS { namespace ENGINE { - class ServiceNode; - /*! \brief Class for Salome component instance * * @@ -40,9 +38,9 @@ namespace YACS SalomeComponent(const std::string& name); SalomeComponent(const SalomeComponent& other); virtual ~SalomeComponent(); - virtual void load(ServiceNode *askingNode); - virtual void unload(ServiceNode *askingNode); - virtual bool isLoaded(ServiceNode *askingNode); + virtual void load(Task *askingNode); + virtual void unload(Task *askingNode); + virtual bool isLoaded(Task *askingNode) const; virtual void setContainer(Container *cont); virtual ServiceNode* createNode(const std::string& name); virtual ComponentInstance* clone() const; diff --git a/src/runtime/SalomeContainer.cxx b/src/runtime/SalomeContainer.cxx index 4dd6f719e..38ec23235 100644 --- a/src/runtime/SalomeContainer.cxx +++ b/src/runtime/SalomeContainer.cxx @@ -57,7 +57,7 @@ SalomeContainer::SalomeContainer():_launchModeType(new SalomeContainerMonoHelper } SalomeContainer::SalomeContainer(const SalomeContainer& other) -: Container(other), +: Container(other),_componentNames(other._componentNames), _launchModeType(other._launchModeType->deepCpyOnlyStaticInfo()), _shutdownLevel(other._shutdownLevel), _sct(other._sct) @@ -146,9 +146,9 @@ void SalomeContainer::addToResourceList(const std::string& name) /*! * \param inst the component instance to load */ -CORBA::Object_ptr SalomeContainer::loadComponent(ServiceNode *inst) +CORBA::Object_ptr SalomeContainer::loadComponent(Task *askingNode) { - return SalomeContainerTools::LoadComponent(_launchModeType,this,inst->getComponent()); + return SalomeContainerTools::LoadComponent(_launchModeType,this,askingNode); } //! Get the container placement id for a component instance @@ -156,9 +156,9 @@ CORBA::Object_ptr SalomeContainer::loadComponent(ServiceNode *inst) * \param inst the component instance * \return the placement id */ -std::string SalomeContainer::getPlacementId(const ComponentInstance *inst) const +std::string SalomeContainer::getPlacementId(const Task *askingNode) const { - return SalomeContainerTools::GetPlacementId(_launchModeType,this,inst); + return SalomeContainerTools::GetPlacementId(_launchModeType,this,askingNode); } //! Get the container full path for a component instance @@ -166,9 +166,9 @@ std::string SalomeContainer::getPlacementId(const ComponentInstance *inst) const * \param inst the component instance * \return the full placement id */ -std::string SalomeContainer::getFullPlacementId(const ComponentInstance *inst) const +std::string SalomeContainer::getFullPlacementId(const Task *askingNode) const { - return SalomeContainerTools::GetFullPlacementId(_launchModeType,this,inst); + return SalomeContainerTools::GetFullPlacementId(_launchModeType,this,askingNode); } //! Check if the component instance container is already started @@ -176,23 +176,23 @@ std::string SalomeContainer::getFullPlacementId(const ComponentInstance *inst) c * \param inst the component instance * \return true, if the container is already started, else false */ -bool SalomeContainer::isAlreadyStarted(const ComponentInstance *inst) const +bool SalomeContainer::isAlreadyStarted(const Task *askingNode) const { - return _launchModeType->isAlreadyStarted(inst); + return _launchModeType->isAlreadyStarted(askingNode); } -Engines::Container_ptr SalomeContainer::getContainerPtr(const ComponentInstance *inst) const +Engines::Container_ptr SalomeContainer::getContainerPtr(const Task *askingNode) const { - return Engines::Container::_duplicate(_launchModeType->getContainer(inst)); + return Engines::Container::_duplicate(_launchModeType->getContainer(askingNode)); } //! Start a salome container (true salome container not yacs one) with given ContainerParameters (_params) /*! * \param inst the component instance */ -void SalomeContainer::start(const ComponentInstance *inst) throw(YACS::Exception) +void SalomeContainer::start(const Task *askingNode) throw(YACS::Exception) { - SalomeContainerTools::Start(_componentNames,_launchModeType,_sct,_shutdownLevel,this,inst); + SalomeContainerTools::Start(_componentNames,_launchModeType,_sct,_shutdownLevel,this,askingNode); } void SalomeContainer::shutdown(int level) diff --git a/src/runtime/SalomeContainer.hxx b/src/runtime/SalomeContainer.hxx index 1c87e1156..5553e946e 100644 --- a/src/runtime/SalomeContainer.hxx +++ b/src/runtime/SalomeContainer.hxx @@ -45,20 +45,20 @@ namespace YACS void lock(); //! For thread safety for concurrent load operation on same Container. void unLock(); - bool isAlreadyStarted(const ComponentInstance *inst) const; - Engines::Container_ptr getContainerPtr(const ComponentInstance *inst) const; - void start(const ComponentInstance *inst) throw (Exception); + bool isAlreadyStarted(const Task *askingNode) const; + Engines::Container_ptr getContainerPtr(const Task *askingNode) const; + void start(const Task *askingNode) throw (Exception); Container *clone() const; Container *cloneAlways() const; - std::string getPlacementId(const ComponentInstance *inst) const; - std::string getFullPlacementId(const ComponentInstance *inst) const; + std::string getPlacementId(const Task *askingNode) const; + std::string getFullPlacementId(const Task *askingNode) const; void checkCapabilityToDealWith(const ComponentInstance *inst) const throw (Exception); void setProperty(const std::string& name, const std::string& value); std::string getProperty(const std::string& name) const; void clearProperties(); void addComponentName(const std::string& name); void addToResourceList(const std::string& name); - virtual CORBA::Object_ptr loadComponent(ServiceNode *inst); + virtual CORBA::Object_ptr loadComponent(Task *inst); void shutdown(int level); // Helper methods std::map getResourceProperties(const std::string& name) const; diff --git a/src/runtime/SalomeContainerHelper.cxx b/src/runtime/SalomeContainerHelper.cxx index 3afa30894..9a9056863 100644 --- a/src/runtime/SalomeContainerHelper.cxx +++ b/src/runtime/SalomeContainerHelper.cxx @@ -19,6 +19,7 @@ #include "SalomeContainerHelper.hxx" +#include "ServiceNode.hxx" #include "YacsTrace.hxx" #include @@ -54,12 +55,12 @@ SalomeContainerMonoHelper *SalomeContainerMonoHelper::deepCpyOnlyStaticInfo() co return new SalomeContainerMonoHelper; } -Engines::Container_var SalomeContainerMonoHelper::getContainer(const ComponentInstance *inst) const +Engines::Container_var SalomeContainerMonoHelper::getContainer(const Task *askingNode) const { return _trueCont; } -bool SalomeContainerMonoHelper::isAlreadyStarted(const ComponentInstance *inst) const +bool SalomeContainerMonoHelper::isAlreadyStarted(const Task *askingNode) const { if(CORBA::is_nil(_trueCont)) return false; @@ -67,7 +68,7 @@ bool SalomeContainerMonoHelper::isAlreadyStarted(const ComponentInstance *inst) return true; } -void SalomeContainerMonoHelper::setContainer(const ComponentInstance *inst, Engines::Container_var cont) +void SalomeContainerMonoHelper::setContainer(const Task *askingNode, Engines::Container_var cont) { _trueCont=cont; #ifdef REFCNT @@ -106,8 +107,9 @@ SalomeContainerMultiHelper *SalomeContainerMultiHelper::deepCpyOnlyStaticInfo() return new SalomeContainerMultiHelper; } -Engines::Container_var SalomeContainerMultiHelper::getContainer(const ComponentInstance *inst) const +Engines::Container_var SalomeContainerMultiHelper::getContainer(const Task *askingNode) const { + const ComponentInstance *inst(askingNode?askingNode->getComponent():0); std::map::const_iterator it(_trueContainers.find(inst)); if(it!=_trueContainers.end()) return (*it).second; @@ -115,16 +117,18 @@ Engines::Container_var SalomeContainerMultiHelper::getContainer(const ComponentI return Engines::Container::_nil(); } -bool SalomeContainerMultiHelper::isAlreadyStarted(const ComponentInstance *inst) const +bool SalomeContainerMultiHelper::isAlreadyStarted(const Task *askingNode) const { + const ComponentInstance *inst(askingNode?askingNode->getComponent():0); if(_trueContainers.count(inst)==0) return false; else return true; } -void SalomeContainerMultiHelper::setContainer(const ComponentInstance *inst, Engines::Container_var cont) +void SalomeContainerMultiHelper::setContainer(const Task *askingNode, Engines::Container_var cont) { + const ComponentInstance *inst(askingNode?askingNode->getComponent():0); _trueContainers[inst]=cont; #ifdef REFCNT std::map::const_iterator it; diff --git a/src/runtime/SalomeContainerHelper.hxx b/src/runtime/SalomeContainerHelper.hxx index 1ae0601ee..aa301a90b 100644 --- a/src/runtime/SalomeContainerHelper.hxx +++ b/src/runtime/SalomeContainerHelper.hxx @@ -32,6 +32,7 @@ namespace YACS { namespace ENGINE { + class Task; class ComponentInstance; class SalomeContainerHelper @@ -39,9 +40,9 @@ namespace YACS public: virtual std::string getType() const = 0; virtual SalomeContainerHelper *deepCpyOnlyStaticInfo() const = 0; - virtual Engines::Container_var getContainer(const ComponentInstance *inst) const = 0; - virtual bool isAlreadyStarted(const ComponentInstance *inst) const = 0; - virtual void setContainer(const ComponentInstance *inst, Engines::Container_var cont) = 0; + virtual Engines::Container_var getContainer(const Task *askingNode) const = 0; + virtual bool isAlreadyStarted(const Task *askingNode) const = 0; + virtual void setContainer(const Task *askingNode, Engines::Container_var cont) = 0; virtual void shutdown() = 0; virtual ~SalomeContainerHelper(); }; @@ -52,9 +53,9 @@ namespace YACS SalomeContainerMonoHelper(); std::string getType() const; SalomeContainerMonoHelper *deepCpyOnlyStaticInfo() const; - Engines::Container_var getContainer(const ComponentInstance *inst) const; - bool isAlreadyStarted(const ComponentInstance *inst) const; - void setContainer(const ComponentInstance *inst, Engines::Container_var cont); + Engines::Container_var getContainer(const Task *askingNode) const; + bool isAlreadyStarted(const Task *askingNode) const; + void setContainer(const Task *askingNode, Engines::Container_var cont); void shutdown(); ~SalomeContainerMonoHelper(); public: @@ -69,9 +70,9 @@ namespace YACS public: std::string getType() const; SalomeContainerMultiHelper *deepCpyOnlyStaticInfo() const; - Engines::Container_var getContainer(const ComponentInstance *inst) const; - bool isAlreadyStarted(const ComponentInstance *inst) const; - void setContainer(const ComponentInstance *inst, Engines::Container_var cont); + Engines::Container_var getContainer(const Task *askingNode) const; + bool isAlreadyStarted(const Task *askingNode) const; + void setContainer(const Task *askingNode, Engines::Container_var cont); void shutdown(); ~SalomeContainerMultiHelper(); public: diff --git a/src/runtime/SalomeContainerTools.cxx b/src/runtime/SalomeContainerTools.cxx index fd3336efd..1976a9679 100644 --- a/src/runtime/SalomeContainerTools.cxx +++ b/src/runtime/SalomeContainerTools.cxx @@ -26,6 +26,7 @@ #include "YacsTrace.hxx" #include "Proc.hxx" +#include "ServiceNode.hxx" #include "ComponentInstance.hxx" #include "SalomeContainerHelper.hxx" #include "RuntimeSALOME.hxx" @@ -299,7 +300,7 @@ std::map SalomeContainerTools::getResourceProperties(co * \param [in] compoNames * \param [in,out] shutdownLevel */ -void SalomeContainerTools::Start(const std::vector& compoNames, SalomeContainerHelper *schelp, SalomeContainerTools& sct, int& shutdownLevel, const Container *cont, const ComponentInstance *inst) +void SalomeContainerTools::Start(const std::vector& compoNames, SalomeContainerHelper *schelp, SalomeContainerTools& sct, int& shutdownLevel, const Container *cont, const Task *askingNode) { CORBA::ORB_ptr orb(getSALOMERuntime()->getOrb()); SALOME_NamingService ns; @@ -399,21 +400,22 @@ void SalomeContainerTools::Start(const std::vector& compoNames, Sal if(CORBA::is_nil(trueCont)) throw Exception("SalomeContainer::start : Unable to launch container in Salome. Check your CatalogResources.xml file"); - schelp->setContainer(inst,trueCont); + schelp->setContainer(askingNode,trueCont); CORBA::String_var containerName(trueCont->name()),hostName(trueCont->getHostName()); std::cerr << "SalomeContainer launched : " << containerName << " " << hostName << " " << trueCont->getPID() << std::endl; } -CORBA::Object_ptr SalomeContainerTools::LoadComponent(SalomeContainerHelper *launchModeType, Container *cont, ComponentInstance *inst) +CORBA::Object_ptr SalomeContainerTools::LoadComponent(SalomeContainerHelper *launchModeType, Container *cont, Task *askingNode) { DEBTRACE("SalomeContainer::loadComponent "); cont->lock();//To be sure - if(!cont->isAlreadyStarted(inst)) + const ComponentInstance *inst(askingNode?askingNode->getComponent():0); + if(!cont->isAlreadyStarted(askingNode)) { try { - cont->start(inst); + cont->start(askingNode); } catch(Exception& e) { @@ -426,7 +428,7 @@ CORBA::Object_ptr SalomeContainerTools::LoadComponent(SalomeContainerHelper *lau CORBA::Object_ptr objComponent=CORBA::Object::_nil(); std::string compoName(inst->getCompoName()); const char* componentName=compoName.c_str(); - Engines::Container_var container(launchModeType->getContainer(inst)); + Engines::Container_var container(launchModeType->getContainer(askingNode)); char* reason; @@ -478,11 +480,11 @@ CORBA::Object_ptr SalomeContainerTools::LoadComponent(SalomeContainerHelper *lau return objComponent; } -std::string SalomeContainerTools::GetPlacementId(SalomeContainerHelper *launchModeType, const Container *cont, const ComponentInstance *inst) +std::string SalomeContainerTools::GetPlacementId(const SalomeContainerHelper *launchModeType, const Container *cont, const Task *askingNode) { - if(cont->isAlreadyStarted(inst)) + if(cont->isAlreadyStarted(askingNode)) { - Engines::Container_var container(launchModeType->getContainer(inst)); + Engines::Container_var container(launchModeType->getContainer(askingNode)); const char *what="/"; CORBA::String_var corbaStr(container->name()); std::string ret(corbaStr); @@ -498,11 +500,11 @@ std::string SalomeContainerTools::GetPlacementId(SalomeContainerHelper *launchMo return "Not placed yet !!!"; } -std::string SalomeContainerTools::GetFullPlacementId(SalomeContainerHelper *launchModeType, const Container *cont, const ComponentInstance *inst) +std::string SalomeContainerTools::GetFullPlacementId(const SalomeContainerHelper *launchModeType, const Container *cont, const Task *askingNode) { - if(cont->isAlreadyStarted(inst)) + if(cont->isAlreadyStarted(askingNode)) { - Engines::Container_var container(launchModeType->getContainer(inst)); + Engines::Container_var container(launchModeType->getContainer(askingNode)); try { CORBA::String_var corbaStr(container->name()); diff --git a/src/runtime/SalomeContainerTools.hxx b/src/runtime/SalomeContainerTools.hxx index 1ef95fb61..deb6cdb5b 100644 --- a/src/runtime/SalomeContainerTools.hxx +++ b/src/runtime/SalomeContainerTools.hxx @@ -32,6 +32,7 @@ namespace YACS { namespace ENGINE { + class Task; class Container; class ComponentInstance; class SalomeContainerHelper; @@ -55,10 +56,10 @@ namespace YACS std::string getHostName() const; Engines::ContainerParameters getParameters() const { return _params; } public: - static void Start(const std::vector& compoNames, SalomeContainerHelper *schelp, SalomeContainerTools& sct, int& shutdownLevel, const Container *cont, const ComponentInstance *inst); - static CORBA::Object_ptr LoadComponent(SalomeContainerHelper *launchModeType, Container *cont, ComponentInstance *inst); - static std::string GetPlacementId(SalomeContainerHelper *launchModeType, const Container *cont, const ComponentInstance *inst); - static std::string GetFullPlacementId(SalomeContainerHelper *launchModeType, const Container *cont, const ComponentInstance *inst); + 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 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: std::map _propertyMap; Engines::ContainerParameters _params; diff --git a/src/runtime/SalomeHPContainer.cxx b/src/runtime/SalomeHPContainer.cxx index aee80db77..91c9f9d60 100644 --- a/src/runtime/SalomeHPContainer.cxx +++ b/src/runtime/SalomeHPContainer.cxx @@ -18,14 +18,19 @@ // #include "SalomeHPContainer.hxx" +#include "SalomeComponent.hxx" + +#include using namespace YACS::ENGINE; +const char SalomeHPContainer::KIND[]="HPSalome"; + SalomeHPContainer::SalomeHPContainer():_shutdownLevel(999) { } -SalomeHPContainer::SalomeHPContainer(const SalomeHPContainer& other):_shutdownLevel(999) +SalomeHPContainer::SalomeHPContainer(const SalomeHPContainer& other):_componentNames(other._componentNames),_shutdownLevel(999),_sct(other._sct) { } @@ -34,6 +39,112 @@ void SalomeHPContainer::setSizeOfPool(int sz) _launchModeType.resize(sz); } +std::size_t SalomeHPContainer::getNumberOfFreePlace() const +{ + return _launchModeType.getNumberOfFreePlace(); +} + +void SalomeHPContainer::allocateFor(const std::vector& nodes) +{ + _launchModeType.allocateFor(nodes); +} + +void SalomeHPContainer::release(Task *node) +{ + _launchModeType.release(node); +} + SalomeHPContainer::~SalomeHPContainer() { } + +void SalomeHPContainer::lock() +{ + _mutex.lock(); +} + +void SalomeHPContainer::unLock() +{ + _mutex.unlock(); +} + +bool SalomeHPContainer::isAlreadyStarted(const Task *askingNode) const +{ + const SalomeContainerMonoHelper& helper(_launchModeType.getHelperOfTask(askingNode)); + return helper.isAlreadyStarted(askingNode); +} + +void SalomeHPContainer::start(const Task *askingNode) throw(Exception) +{ + SalomeContainerMonoHelper& helper(_launchModeType.getHelperOfTask(askingNode)); + SalomeContainerTools::Start(_componentNames,&helper,_sct,_shutdownLevel,this,askingNode); +} + +void SalomeHPContainer::shutdown(int level) +{ + if(level < _shutdownLevel) + return; + _shutdownLevel=999; + for(std::size_t i=0;_launchModeType.size();i++) + { + SalomeContainerMonoHelper& helper(_launchModeType.at(i)); + helper.shutdown(); + } +} + +std::string SalomeHPContainer::getPlacementId(const Task *askingNode) const +{ + const SalomeContainerMonoHelper& helper(_launchModeType.getHelperOfTask(askingNode)); + return SalomeContainerTools::GetPlacementId(&helper,this,askingNode); +} + +std::string SalomeHPContainer::getFullPlacementId(const Task *askingNode) const +{ + const SalomeContainerMonoHelper& helper(_launchModeType.getHelperOfTask(askingNode)); + return SalomeContainerTools::GetFullPlacementId(&helper,this,askingNode); +} + +/*! + * It is not a bug here ! clone for homogeneous container is not supposed to be copied ! + */ +Container *SalomeHPContainer::clone() const +{ + incrRef(); + return const_cast(this); +} + +Container *SalomeHPContainer::cloneAlways() const +{ + return new SalomeHPContainer(*this); +} + +void SalomeHPContainer::setProperty(const std::string& name,const std::string& value) +{ + _sct.setProperty(name,value); +} + +std::string SalomeHPContainer::getProperty(const std::string& name) const +{ + return _sct.getProperty(name); +} + +void SalomeHPContainer::clearProperties() +{ + _sct.clearProperties(); +} + +std::map SalomeHPContainer::getProperties() const +{ + return _sct.getProperties(); +} + +std::map SalomeHPContainer::getResourceProperties(const std::string& name) const +{ + return _sct.getResourceProperties(name); +} + +void SalomeHPContainer::checkCapabilityToDealWith(const ComponentInstance *inst) const throw(YACS::Exception) +{ + if(inst->getKind()!=SalomeComponent::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 53033cd26..28e8f563c 100644 --- a/src/runtime/SalomeHPContainer.hxx +++ b/src/runtime/SalomeHPContainer.hxx @@ -24,9 +24,11 @@ #include "HomogeneousPoolContainer.hxx" #include "SalomeContainerHelper.hxx" #include "SalomeContainerTools.hxx" +#include "SalomeHPContainerTools.hxx" #include "Mutex.hxx" #include #include +#include #include #include CORBA_CLIENT_HEADER(SALOME_Component) #include CORBA_CLIENT_HEADER(SALOME_ContainerManager) @@ -35,6 +37,7 @@ namespace YACS { namespace ENGINE { + class Task; class SalomeComponent; class YACSRUNTIMESALOME_EXPORT SalomeHPContainer : public HomogeneousPoolContainer @@ -42,17 +45,42 @@ namespace YACS public: SalomeHPContainer(); SalomeHPContainer(const SalomeHPContainer& other); + //HP specific part void setSizeOfPool(int sz); + std::size_t getNumberOfFreePlace() const; + void allocateFor(const std::vector& nodes); + void release(Task *node); + //! For thread safety for concurrent load operation on same Container. + void lock(); + //! For thread safety for concurrent load operation on same Container. + void unLock(); + // + bool isAlreadyStarted(const Task *askingNode) const; + void start(const Task *askingNode) throw(Exception); + void shutdown(int level); + std::string getPlacementId(const Task *askingNode) const; + std::string getFullPlacementId(const Task *askingNode) const; + Container *clone() const; + Container *cloneAlways() const; + void setProperty(const std::string& name,const std::string& value); + std::string getProperty(const std::string& name) const; + void clearProperties(); + std::map getProperties() const; + std::map getResourceProperties(const std::string& name) const; + void checkCapabilityToDealWith(const ComponentInstance *inst) const throw(YACS::Exception); + public: + static const char KIND[]; protected: #ifndef SWIG ~SalomeHPContainer(); #endif protected: - YACS::BASES::Mutex _mutex; - std::vector _componentNames; - std::vector _launchModeType; int _shutdownLevel; SalomeContainerTools _sct; + YACS::BASES::Mutex _mutex; + std::vector _componentNames; + // + SalomeHPContainerVectOfHelper _launchModeType; }; } } diff --git a/src/runtime/SalomeHPContainerTools.cxx b/src/runtime/SalomeHPContainerTools.cxx new file mode 100644 index 000000000..59e45fd56 --- /dev/null +++ b/src/runtime/SalomeHPContainerTools.cxx @@ -0,0 +1,101 @@ +// 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 "SalomeHPContainerTools.hxx" +#include "Exception.hxx" + +#include + +using namespace YACS::ENGINE; + +void SalomeHPContainerVectOfHelper::resize(std::size_t sz) +{ + checkNoCurrentWork(); + _whichOccupied.resize(sz); std::fill(_whichOccupied.begin(),_whichOccupied.end(),false); + _launchModeType.clear(); _launchModeType.resize(sz); + _currentlyWorking.clear(); +} + +std::size_t SalomeHPContainerVectOfHelper::getNumberOfFreePlace() const +{ + return std::count(_whichOccupied.begin(),_whichOccupied.end(),false); +} + +void SalomeHPContainerVectOfHelper::allocateFor(const std::vector& nodes) +{ + for(std::vector::const_iterator it=nodes.begin();it!=nodes.end();it++) + { + if(!(*it)) + continue; + if(_currentlyWorking.find(*it)!=_currentlyWorking.end()) + throw Exception("Searching to allocate for a ServiceNode instance already declared as allocated !"); + std::vector::iterator it2(std::find(_whichOccupied.begin(),_whichOccupied.end(),false)); + if(it2==_whichOccupied.end()) + throw Exception("All ressources are already occupied ! You are expected to wait for released resources !"); + std::size_t pos(std::distance(_whichOccupied.begin(),it2)); + _currentlyWorking[*it]=pos; _whichOccupied[pos]=true; + } +} + +void SalomeHPContainerVectOfHelper::release(const Task *node) +{ + if(!node) + return ; + std::map< const Task *,std::size_t >::iterator it(_currentlyWorking.find(node)); + if(it==_currentlyWorking.end()) + throw Exception("Request to release a resource not declared as working !"); + _whichOccupied[(*it).second]=false; + _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)); + if(it==_currentlyWorking.end()) + throw Exception("current Node to be located is not marked as launched !"); + std::size_t ret((*it).second); + checkPosInVec(ret); + return ret; +} + +void SalomeHPContainerVectOfHelper::checkNoCurrentWork() const +{ + for(std::map::const_iterator it=_currentlyWorking.begin();it!=_currentlyWorking.end();it++) + if((*it).first) + throw Exception("Something wrong a node is still declared to be using the ressource !"); + for(std::vector::const_iterator it=_launchModeType.begin();it!=_launchModeType.end();it++) + if((*it).isAlreadyStarted(0)) + throw Exception("Some of the containers have be started ! Please shutdown them before !"); +} + +void SalomeHPContainerVectOfHelper::checkPosInVec(std::size_t pos) const +{ + if(pos<0 || pos>=_launchModeType.size()) + throw Exception("The task has been found, but its id is not in the correct range ! resize of of container size during run ?"); +} diff --git a/src/runtime/SalomeHPContainerTools.hxx b/src/runtime/SalomeHPContainerTools.hxx new file mode 100644 index 000000000..c052cbe5a --- /dev/null +++ b/src/runtime/SalomeHPContainerTools.hxx @@ -0,0 +1,60 @@ +// 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 __SALOMEHPCONTAINERTOOLS_HXX__ +#define __SALOMEHPCONTAINERTOOLS_HXX__ + +#include "YACSRuntimeSALOMEExport.hxx" +#include "SalomeContainerHelper.hxx" + +#include +#include + +namespace YACS +{ + namespace ENGINE + { + class Task; + class SalomeComponent; + + class SalomeHPContainerVectOfHelper + { + public: + std::size_t size() const { return _launchModeType.size(); } + void resize(std::size_t sz); + std::size_t getNumberOfFreePlace() const; + void allocateFor(const std::vector& nodes); + void release(const Task *node); + 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: + std::vector _whichOccupied; + std::vector _launchModeType; + std::map _currentlyWorking; + }; + } +} + +#endif diff --git a/src/runtime/SalomePythonComponent.cxx b/src/runtime/SalomePythonComponent.cxx index fc6912fde..4ece84852 100644 --- a/src/runtime/SalomePythonComponent.cxx +++ b/src/runtime/SalomePythonComponent.cxx @@ -44,11 +44,11 @@ SalomePythonComponent::~SalomePythonComponent() { } -void SalomePythonComponent::load(ServiceNode *askingNode) +void SalomePythonComponent::load(Task *askingNode) { if(_container) { - _container->start(this); + _container->start(askingNode); return; } //This component has no specified container : use default container policy @@ -56,16 +56,16 @@ void SalomePythonComponent::load(ServiceNode *askingNode) //throw Exception("SalomePythonComponent::load : no container specified !!! To be implemented in executor to allocate default a Container in case of presenceOfDefaultContainer."); } -void SalomePythonComponent::unload(ServiceNode *askingNode) +void SalomePythonComponent::unload(Task *askingNode) { } -bool SalomePythonComponent::isLoaded(ServiceNode *askingNode) +bool SalomePythonComponent::isLoaded(Task *askingNode) const { if(!_container) return false; else - return _container->isAlreadyStarted(this); + return _container->isAlreadyStarted(askingNode); } std::string SalomePythonComponent::getKind() const @@ -99,10 +99,10 @@ std::string SalomePythonComponent::getFileRepr() const return stream.str(); } -std::string SalomePythonComponent::getStringValueToExportInInterp() const +std::string SalomePythonComponent::getStringValueToExportInInterp(const Task *askingNode) const { if(!_container) return "localhost/FactoryServer"; else - return _container->getPlacementId(this); + return _container->getPlacementId(askingNode); } diff --git a/src/runtime/SalomePythonComponent.hxx b/src/runtime/SalomePythonComponent.hxx index d7701c383..58bf7287a 100644 --- a/src/runtime/SalomePythonComponent.hxx +++ b/src/runtime/SalomePythonComponent.hxx @@ -33,15 +33,15 @@ namespace YACS SalomePythonComponent(const SalomePythonComponent& other); std::string getPlacementId() const; virtual ~SalomePythonComponent(); - virtual void load(ServiceNode *askingNode); - virtual void unload(ServiceNode *askingNode); - virtual bool isLoaded(ServiceNode *askingNode); + virtual void load(Task *askingNode); + virtual void unload(Task *askingNode); + virtual bool isLoaded(Task *askingNode) const; virtual std::string getKind() const; virtual ComponentInstance* clone() const; virtual std::string getFileRepr() const; virtual ServiceNode *createNode(const std::string &name); //! The specific method that justified SalomePythonComponent class. - std::string getStringValueToExportInInterp() const; + std::string getStringValueToExportInInterp(const Task *askingNode) const; public: unsigned _cntForRepr; static unsigned _cntForReprS; diff --git a/src/runtime/SalomePythonNode.cxx b/src/runtime/SalomePythonNode.cxx index 4f3b55d10..773efe7ad 100644 --- a/src/runtime/SalomePythonNode.cxx +++ b/src/runtime/SalomePythonNode.cxx @@ -71,7 +71,7 @@ void SalomePythonNode::load() ServiceInlineNode::load(); cerr << "---------------SalomePythonNode::load function---------------" << endl; list::iterator iter; - string value2Export=((SalomePythonComponent*)_component)->getStringValueToExportInInterp(); + string value2Export=((SalomePythonComponent*)_component)->getStringValueToExportInInterp(this); PyObject* ob=PyString_FromString(value2Export.c_str()); PyDict_SetItemString(_context,PLACEMENT_VAR_NAME_IN_INTERP,ob); for(iter = _setOfOutputPort.begin(); iter != _setOfOutputPort.end(); iter++) diff --git a/src/runtime_swig/SALOMERuntime.i b/src/runtime_swig/SALOMERuntime.i index b7eb87f44..b06663b19 100644 --- a/src/runtime_swig/SALOMERuntime.i +++ b/src/runtime_swig/SALOMERuntime.i @@ -44,6 +44,7 @@ %{ #include "SalomeContainer.hxx" +#include "SalomeHPContainer.hxx" #include "RuntimeSALOME.hxx" #include "SALOMEDispatcher.hxx" #include "SalomeProc.hxx" @@ -117,6 +118,7 @@ %include %include "SalomeContainer.hxx" +%include "SalomeHPContainer.hxx" %include "RuntimeSALOME.hxx" %include "SALOMEDispatcher.hxx" %include "SalomeProc.hxx" -- 2.30.2