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