Version: 8.3.0
ComposedNode.hxx
Go to the documentation of this file.
1 // Copyright (C) 2006-2016 CEA/DEN, EDF R&D
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 #ifndef __COMPOSEDNODE_HXX__
21 #define __COMPOSEDNODE_HXX__
22 
23 #include "YACSlibEngineExport.hxx"
24 #include "Node.hxx"
25 #include "Scheduler.hxx"
26 
27 #include <set>
28 #include <string>
29 #include <vector>
30 
31 namespace YACS
32 {
33  namespace ENGINE
34  {
35  class Bloc;
36  class Loop;
37  class InPort;
38  class OutPort;
39  class LinkInfo;
40  class ElementaryNode;
41 
43  {
44  friend class Bloc;
45  friend class Loop;
46  friend class OutPort;
47  friend class ElementaryNode;
48  protected:
49  static const char SEP_CHAR_BTW_LEVEL[];
50  protected:
51  ComposedNode(const std::string& name);
52  ComposedNode(const ComposedNode& other, ComposedNode *father);
53  void performDuplicationOfPlacement(const Node& other);
54  void performShallowDuplicationOfPlacement(const Node& other);
55  public:
56  virtual ~ComposedNode();
57  bool isFinished();
58  void init(bool start=true);
59  virtual void shutdown(int level);
60  virtual void resetState(int level);
61  std::string getName() const;
62  std::string getTaskName(Task *task) const;
63  DeploymentTree getDeploymentTree() const;
64  DeploymentTree checkDeploymentTree(bool deep) const throw(Exception);
65  std::vector<Task *> getNextTasks(bool& isMore);
66  virtual bool isPlacementPredictableB4Run() const = 0;
67  void notifyFrom(const Task *sender, YACS::Event event, const Executor *execInst);
68  bool edAddLink(OutPort *start, InPort *end) throw(Exception);
69  virtual bool edAddDFLink(OutPort *start, InPort *end) throw(Exception);
70  //Node* DISOWNnode is a SWIG notation to indicate that the ownership of the node is transfered to C++
71  virtual bool edAddChild(Node *DISOWNnode) throw(Exception);
72  virtual void edRemoveChild(Node *node) throw(Exception);
73  bool edAddLink(OutGate *start, InGate *end) throw(Exception);
74  bool edAddCFLink(Node *nodeS, Node *nodeE) throw(Exception);
75  void edRemoveCFLink(Node *nodeS, Node *nodeE) throw(Exception);
76  void edRemoveLink(OutPort *start, InPort *end) throw(Exception);
77  void edRemoveLink(OutGate *start, InGate *end) throw(Exception);
78  virtual bool isRepeatedUnpredictablySeveralTimes() const { return false; }
79  virtual std::list<Node *> edGetDirectDescendants() const = 0;
80  virtual void removeRecursivelyRedundantCL();
81  std::list<ElementaryNode *> getRecursiveConstituents() const;
82  std::list<Node *> getAllRecursiveNodes();
83  virtual std::list<Node *> getAllRecursiveConstituents(); // first implementation
84  std::list<ProgressWeight> getProgressWeight() const;
85  std::string getInPortName(const InPort *) const throw (Exception);
86  std::string getOutPortName(const OutPort *) const throw (Exception);
87  //
88  int getNumberOfInputPorts() const;
89  int getNumberOfOutputPorts() const;
90  std::list<InputPort *> getSetOfInputPort() const;
91  std::list<OutputPort *> getSetOfOutputPort() const;
92  std::list<InputPort *> getLocalInputPorts() const;
93  std::list<OutputPort *> getLocalOutputPorts() const;
94  std::set<OutPort *> getAllOutPortsLeavingCurrentScope() const;
95  std::set<InPort *> getAllInPortsComingFromOutsideOfCurrentScope() const;
96  std::list<InputDataStreamPort *> getSetOfInputDataStreamPort() const;
97  std::list<OutputDataStreamPort *> getSetOfOutputDataStreamPort() const;
98  OutPort *getOutPort(const std::string& name) const throw(Exception);
99  InputPort *getInputPort(const std::string& name) const throw(Exception);
100  OutputPort *getOutputPort(const std::string& name) const throw(Exception);
101  InputDataStreamPort *getInputDataStreamPort(const std::string& name) const throw(Exception);
102  OutputDataStreamPort *getOutputDataStreamPort(const std::string& name) const throw(Exception);
103  std::vector< std::pair<OutPort *, InPort *> > getSetOfInternalLinks() const;
104  virtual std::vector< std::pair<OutPort *, InPort *> > getSetOfLinksLeavingCurrentScope() const;
105  void checkConsistency(LinkInfo& info) const throw(Exception);
106  virtual std::vector< std::pair<InPort *, OutPort *> > getSetOfLinksComingInCurrentScope() const;
107  virtual std::string typeName() {return "YACS__ENGINE__ComposedNode";}
108  virtual void edUpdateState();
109  virtual void checkBasicConsistency() const throw(Exception);
110  virtual std::string getErrorReport();
111  //
112  ComposedNode *getRootNode() const throw(Exception);
113  bool isNodeAlreadyAggregated(const Node *node) const;
114  virtual bool isNameAlreadyUsed(const std::string& name) const;
115  Node *isInMyDescendance(Node *nodeToTest) const;
116  std::string getChildName(const Node* node) const throw(Exception);
117  virtual std::string getMyQualifiedName(const Node *directSon) const;
118  Node *getChildByName(const std::string& name) const throw(Exception);
119  static ComposedNode *getLowestCommonAncestor(Node *node1, Node *node2) throw(Exception);
120  static std::string getLowestCommonAncestorStr(const std::string& node1, const std::string& node2);
121  void loaded();
122  void connected();
123  void accept(Visitor *visitor);
124  virtual void cleanNodes();
125  virtual std::string getProgress() const { return "0"; }
126  protected:
127  struct SortHierarc
128  {
129  bool operator()(ComposedNode *n1, ComposedNode *n2) const
130  {
131  return *n1<*n2;
132  }
133  };
134  protected:
135  void edDisconnectAllLinksWithMe();
136  static bool splitNamesBySep(const std::string& globalName, const char separator[],
137  std::string& firstPart, std::string& lastPart, bool priority) throw(Exception);
138  virtual Node *getChildByShortName(const std::string& name) const throw(Exception) = 0;
139  YACS::Event updateStateFrom(Node *node, YACS::Event event, const Executor *execInst);//update the state of this. Precondition : node->_father == this
140  virtual YACS::Event updateStateOnStartEventFrom(Node *node);//transition 3 doc P.R
141  virtual YACS::Event updateStateOnFinishedEventFrom(Node *node) = 0;//transition 9 doc P.R.
142  virtual YACS::Event updateStateOnFailedEventFrom(Node *node, const Executor *execInst);//transition 9 doc P.R.
143  virtual void checkLinkPossibility(OutPort *start, const std::list<ComposedNode *>& pointsOfViewStart,
144  InPort *end, const std::list<ComposedNode *>& pointsOfViewEnd) throw(Exception);
145  virtual void buildDelegateOf(InPort * & port, OutPort *initialStart, const std::list<ComposedNode *>& pointsOfView);
146  virtual void buildDelegateOf(std::pair<OutPort *, OutPort *>& port, InPort *finalTarget, const std::list<ComposedNode *>& pointsOfView);
147  virtual void getDelegateOf(InPort * & port, OutPort *initialStart, const std::list<ComposedNode *>& pointsOfView) throw(Exception);
148  virtual void getDelegateOf(std::pair<OutPort *, OutPort *>& port, InPort *finalTarget, const std::list<ComposedNode *>& pointsOfView) throw(Exception);
149  virtual void releaseDelegateOf(InPort * & port, OutPort *initialStart, const std::list<ComposedNode *>& pointsOfView) throw(Exception);
150  virtual void releaseDelegateOf(OutPort *portDwn, OutPort *portUp, InPort *finalTarget, const std::list<ComposedNode *>& pointsOfView) throw(Exception);
151  virtual void checkNoCyclePassingThrough(Node *node) throw(Exception) = 0;
152  void checkInMyDescendance(Node *nodeToTest) const throw(Exception);
153  template <class PORT>
154  std::string getPortName(const PORT * port) const throw (Exception);
155  //For CF Computations
156  void checkNoCrossHierachyWith(Node *node) const throw (Exception);
157  virtual void performCFComputations(LinkInfo& info) const;
158  virtual void destructCFComputations(LinkInfo& info) const;
159  Node *getLowestNodeDealingAll(const std::list<OutPort *>& ports) const;
160  void checkLinksCoherenceRegardingControl(const std::vector<OutPort *>& starts,
161  InputPort *end, LinkInfo& info) const throw(Exception);
162  virtual void checkControlDependancy(OutPort *start, InPort *end, bool cross,
163  std::map < ComposedNode *, std::list < OutPort * >, SortHierarc >& fw,
164  std::vector<OutPort *>& fwCross,
165  std::map< ComposedNode *, std::list < OutPort *>, SortHierarc >& bw,
166  LinkInfo& info) const = 0;
167  void solveObviousOrDelegateCFLinks(const std::list<OutPort *>& starts, InputPort *end, unsigned char& alreadyFed, bool direction, LinkInfo& info) const;
168  virtual void checkCFLinks(const std::list<OutPort *>& starts, InputPort *end, unsigned char& alreadyFed, bool direction, LinkInfo& info) const;
169  protected:
170  //For internal calculations.
171  static const unsigned char FED_ST = 2;
172  static const unsigned char FREE_ST = 0;
173  static const unsigned char FED_DS_ST = 1;
174  };
175 
176  template <class PORT>
177  std::string ComposedNode::getPortName(const PORT * port) const throw (Exception)
178  {
179  Node *node = port->getNode();
180  std::string portName = port->getName();
181  checkInMyDescendance(node);
182  Node *father = node;
183  while (father != this)
184  {
185  portName = father->getQualifiedName() + Node::SEP_CHAR_IN_PORT + portName;
186  father = father->_father;
187  }
188  return portName;
189  }
190  }
191 }
192 
193 #endif