Version: 9.15.0
ServiceNode.cxx
Go to the documentation of this file.
1 // Copyright (C) 2006-2025 CEA, EDF
2 //
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.
7 //
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.
12 //
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
16 //
17 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
18 //
19 
20 #include "ServiceNode.hxx"
21 #include "Visitor.hxx"
22 #include "ComponentInstance.hxx"
23 #include "ComposedNode.hxx"
24 #include "Runtime.hxx"
25 #include <iostream>
26 #include <cassert>
27 
28 //#define _DEVDEBUG_
29 #include "YacsTrace.hxx"
30 
31 using namespace YACS::ENGINE;
32 
42 const char ServiceNode::KIND[]="";
43 
45 
50 std::string ServiceNode::getKind() const
51 {
52  return KIND;
53 }
54 
55 ServiceNode::ServiceNode(const std::string& name):ElementaryNode(name),_component(0)
56 {
57 }
58 
60  :ElementaryNode(other,father),_method(other._method),_component(0)
61 {
62 }
63 
65 {
66  const ServiceNode &otherC=*(dynamic_cast<const ServiceNode *>(&other));
67  //if other has no component don't clone: this will not have one
68  if(otherC._component)
69  _component=otherC._component->clone();
70 }
71 
73 {
74  const ServiceNode &otherC=*(dynamic_cast<const ServiceNode *>(&other));
75  //if other has no component don't clone: this will not have one
76  if(otherC._component)
77  {
78  _component=otherC._component;
80  }
81 }
82 
84 {
85  if(_component)
87 }
88 
91 {
92  if(_component)
93  {
94  if(!_component->isLoaded(this))
95  {
96  try
97  {
98  _component->load(this);
99  }
100  catch(Exception& e)
101  {
102  _errorDetails=e.what();
103  throw e;
104  }
105  }
106  }
107  else
108  {
109  std::string what("ServiceNode::load : a load operation requested on ServiceNode called \"");
110  what+=_name; what+="\" with no component specified.";
111  _errorDetails=what;
112  throw Exception(what);
113  }
114 }
115 
117 {
118  visitor->visitServiceNode(this);
119 }
120 
123 {
124  return _component;
125 }
126 
128 {
129  return _component;
130 }
131 
134 {
135  if(_component)return _component->getContainer();
136  return 0;
137 }
138 
141 {
142  return true;
143 }
144 
147 {
148  DEBTRACE("ServiceNode::setComponent " << compo);
149  if(compo)
150  {
151  DEBTRACE(compo->getInstanceName());
152  if(compo->getKindForNode() != this->getKind())
153  {
154  //Not allowed
155  std::string what("ServiceNode::setComponent : component instance kind not allowed ");
156  throw Exception(what);
157  }
158  }
159 
160  ComponentInstance* oldcompo=_component;
161  std::string oldref=_ref;
162 
163  _component=compo;
164  _ref=compo->getCompoName();
166  if(_component)
167  {
168  if(_father)
169  try
170  {
172  }
173  catch(Exception& e)
174  {
175  // Impossible to associate compo to this node. Keep the old component instance and throws exception
176  _component=oldcompo;
177  _ref=oldref;
178  throw e;
179  }
180  _component->incrRef();
181  }
182 
183  if(oldcompo)
184  oldcompo->decrRef();
185 }
186 
188 
193 void ServiceNode::setRef(const std::string& ref)
194 {
195  _ref = ref;
196  if(_component)
197  {
198  //The node is already associated with a component instance
199  _component->decrRef();
200  //Don't forget to unassociate
201  }
204 }
205 
206 std::string ServiceNode::getRef()
207 {
208  return _ref;
209 }
#define YASSERT(val)
YASSERT macro is always defined, used like assert, but throw a YACS::Exception instead of abort.
Definition: YacsTrace.hxx:59
#define DEBTRACE(msg)
Definition: YacsTrace.hxx:31
Base class for all component instances.
virtual ComponentInstance * clone() const =0
virtual std::string getKindForNode() const
virtual bool isLoaded(Task *askingNode) const =0
Indicate if the component instance is loaded (true) or not.
const std::string & getCompoName() const
const std::string & getInstanceName() const
virtual void load(Task *askingNode)=0
Load the component instance.
Base class for all composed nodes.
DeploymentTree checkDeploymentTree(bool deep) const
Perform check of deployment consistency of the current graph.
Base class for all calculation nodes.
Base class for all nodes.
Definition: Node.hxx:70
std::string _name
Definition: Node.hxx:89
virtual ComposedNode * getRootNode() const
Definition: Node.cxx:431
ComposedNode * _father
Definition: Node.hxx:90
std::string _errorDetails
Definition: Node.hxx:93
virtual ComponentInstance * createComponentInstance(const std::string &name, const std::string &kind="")
Definition: Runtime.cxx:215
Class for calculation node associated with a component service.
Definition: ServiceNode.hxx:35
virtual std::string getKind() const
Return the service node kind.
Definition: ServiceNode.cxx:50
virtual void setRef(const std::string &ref)
Associate a new component instance to this service node.
ServiceNode(const std::string &name)
Definition: ServiceNode.cxx:55
virtual Container * getContainer()
Return the associated container.
void performDuplicationOfPlacement(const Node &other)
performs a duplication of placement using clone method of containers and components....
Definition: ServiceNode.cxx:64
virtual void load()
Load the component associated to the node.
Definition: ServiceNode.cxx:90
ComponentInstance * _component
Definition: ServiceNode.hxx:60
virtual void setComponent(ComponentInstance *compo)
Associate an existing component instance to this service node AND check the consistency regarding the...
virtual std::string getRef()
virtual ComponentInstance * getComponent()
Return the associated component instance.
virtual void accept(Visitor *visitor)
void performShallowDuplicationOfPlacement(const Node &other)
performs a also duplication of placement but here containers and components are not copied at all wha...
Definition: ServiceNode.cxx:72
virtual bool isDeployable() const
By definition of ServiceNode class.
static const char KIND[]
Definition: ServiceNode.hxx:58
virtual void visitServiceNode(ServiceNode *node)=0
const char * what(void) const noexcept
Definition: Exception.cxx:50
YACSLIBENGINE_EXPORT Runtime * getRuntime()
Definition: Runtime.cxx:61
def ref(target, callback=None)
Definition: CONNECTOR.py:120