1 // Copyright (C) 2006-2014 CEA/DEN, EDF R&D
3 // This library is free software; you can redistribute it and/or
4 // modify it under the terms of the GNU Lesser General Public
5 // License as published by the Free Software Foundation; either
6 // version 2.1 of the License, or (at your option) any later version.
8 // This library is distributed in the hope that it will be useful,
9 // but WITHOUT ANY WARRANTY; without even the implied warranty of
10 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
11 // Lesser General Public License for more details.
13 // You should have received a copy of the GNU Lesser General Public
14 // License along with this library; if not, write to the Free Software
15 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
17 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
20 #include "ServiceNode.hxx"
21 #include "Visitor.hxx"
22 #include "ComponentInstance.hxx"
23 #include "ComposedNode.hxx"
24 #include "Runtime.hxx"
29 #include "YacsTrace.hxx"
31 using namespace YACS::ENGINE;
33 /*! \class YACS::ENGINE::ServiceNode
34 * \brief Class for calculation node associated with a component service
42 const char ServiceNode::KIND[]="";
44 //! Return the service node kind
46 * A runtime can provide several implementations of a service node.
47 * Each implementation has a different kind. A ComponentInstance can be
48 * associated to a ServiceNode with the same kind.
50 std::string ServiceNode::getKind() const
55 ServiceNode::ServiceNode(const std::string& name):ElementaryNode(name),_component(0)
59 ServiceNode::ServiceNode(const ServiceNode& other, ComposedNode *father)
60 :ElementaryNode(other,father),_method(other._method),_component(0)
64 void ServiceNode::performDuplicationOfPlacement(const Node& other)
66 const ServiceNode &otherC=*(dynamic_cast<const ServiceNode *>(&other));
67 //if other has no component don't clone: this will not have one
69 _component=otherC._component->clone();
72 void ServiceNode::performShallowDuplicationOfPlacement(const Node& other)
74 const ServiceNode &otherC=*(dynamic_cast<const ServiceNode *>(&other));
75 //if other has no component don't clone: this will not have one
78 _component=otherC._component;
79 _component->incrRef();
83 ServiceNode::~ServiceNode()
86 _component->decrRef();
89 //! Load the component associated to the node
90 void ServiceNode::load()
94 if(!_component->isLoaded(this))
98 _component->load(this);
102 _errorDetails=e.what();
109 std::string what("ServiceNode::load : a load operation requested on ServiceNode called \"");
110 what+=_name; what+="\" with no component specified.";
112 throw Exception(what);
116 void ServiceNode::accept(Visitor *visitor)
118 visitor->visitServiceNode(this);
121 //! Return the associated component instance
122 ComponentInstance *ServiceNode::getComponent()
127 const ComponentInstance *ServiceNode::getComponent() const
132 //! Return the associated container
133 Container *ServiceNode::getContainer()
135 if(_component)return _component->getContainer();
139 //! By definition of ServiceNode class.
140 bool ServiceNode::isDeployable() const
145 //! Associate an existing component instance to this service node \b AND check the consistency regarding the deployment from root node point of view.
146 void ServiceNode::setComponent(ComponentInstance* compo) throw(YACS::Exception)
148 DEBTRACE("ServiceNode::setComponent " << compo);
151 DEBTRACE(compo->getInstanceName());
152 if(compo->getKindForNode() != this->getKind())
155 std::string what("ServiceNode::setComponent : component instance kind not allowed ");
156 throw Exception(what);
160 ComponentInstance* oldcompo=_component;
161 std::string oldref=_ref;
164 _ref=compo->getCompoName();
165 DEBTRACE(_component->getInstanceName());
171 getRootNode()->checkDeploymentTree(false);
175 // Impossible to associate compo to this node. Keep the old component instance and throws exception
180 _component->incrRef();
187 //! Associate a new component instance to this service node
189 * A new component instance with type name ref is created (from runtime
190 * factory createComponentInstance) and associated to the node.
193 void ServiceNode::setRef(const std::string& ref)
198 //The node is already associated with a component instance
199 _component->decrRef();
200 //Don't forget to unassociate
202 _component= getRuntime()->createComponentInstance(ref,getKind());
206 std::string ServiceNode::getRef()