1 // Copyright (C) 2006-2008 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.
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
19 #ifndef __SWITCH_HXX__
20 #define __SWITCH_HXX__
22 #include "StaticDefinedComposedNode.hxx"
23 #include "ElementaryNode.hxx"
24 #include "AnyInputPort.hxx"
25 #include "OutPort.hxx"
35 class CollectorSwOutPort : public OutPort
39 int edGetNumberOfOutLinks() const;
40 std::set<InPort *> edSetInPort() const;
41 bool isAlreadyLinkedWith(InPort *with) const;
42 std::string getNameOfTypeOfCurrentInstance() const;
43 void edRemoveAllLinksLinkedWithMe() throw(Exception);
44 TypeOfChannel getTypeOfChannel() const;
45 void getAllRepresented(std::set<OutPort *>& represented) const;
46 bool addInPort(InPort *inPort) throw(Exception);
47 int removeInPort(InPort *inPort, bool forward) throw(Exception);
49 void getHumanReprOfIncompleteCases(std::ostream& stream) const;
50 private://Specific part
51 bool removePotentialProducerForMaster();
52 void checkConsistency(LinkInfo& info) const;
53 CollectorSwOutPort(Switch *master, InPort *port);
54 CollectorSwOutPort(const CollectorSwOutPort& other, Switch *master);
55 void addPotentialProducerForMaster(OutPort *port);
56 bool checkManagementOfPort(OutPort *port) throw(Exception);
59 std::string _className;
60 OutPort *_currentProducer;
61 std::map<int, OutPort *> _potentialProducers;
64 class FakeNodeForSwitch : public ElementaryNode
72 FakeNodeForSwitch(Switch *sw, bool normalFinish, bool internalError=false);
73 FakeNodeForSwitch(const FakeNodeForSwitch& other);
74 Node *simpleClone(ComposedNode *father, bool editionOnly) const;
75 void exForwardFailed();
76 void exForwardFinished();
82 class Switch : public StaticDefinedComposedNode
84 friend class FakeNodeForSwitch;
85 friend class CollectorSwOutPort;
87 static const char DEFAULT_NODE_NAME[];
88 static const char SELECTOR_INPUTPORT_NAME[];
89 static const int ID_FOR_DEFAULT_NODE;
91 AnyInputPort _condition;
92 std::map< int , Node * > _mapOfNode;//Nodes ownered
93 FakeNodeForSwitch *_undispatchableNotificationNode;
94 std::map<InPort *, CollectorSwOutPort * > _outPortsCollector;
95 mutable std::vector<CollectorSwOutPort *> _alreadyExistingCollectors;
97 Switch(const Switch& other, ComposedNode *father, bool editionOnly);
98 Switch(const std::string& name);
100 void exUpdateState();
101 void init(bool start=true);
102 //Node* DISOWNnode is a SWIG notation to indicate that the ownership of the node is transfered to C++
103 Node *edSetDefaultNode(Node *DISOWNnode);
104 Node *edReleaseDefaultNode() throw(Exception);
105 Node *edReleaseCase(int caseId) throw(Exception);
106 Node *edGetNode(int caseId);
107 Node *edSetNode(int caseId, Node *DISOWNnode) throw(Exception);
108 virtual bool edAddChild(Node *DISOWNnode) throw(Exception);
109 void getReadyTasks(std::vector<Task *>& tasks);
110 void selectRunnableTasks(std::vector<Task *>& tasks);
111 std::list<Node *> edGetDirectDescendants() const;
112 InputPort *edGetConditionPort() { return &_condition; }
113 void writeDot(std::ostream &os) const;
114 int getNumberOfInputPorts() const;
115 void edRemoveChild(Node *node) throw(Exception);
116 std::list<InputPort *> getSetOfInputPort() const;
117 std::list<InputPort *> getLocalInputPorts() const;
118 YACS::StatesForNode getEffectiveState() const;
119 YACS::StatesForNode getEffectiveState(const Node* node) const;
120 OutPort *getOutPort(const std::string& name) const throw(Exception);
121 InputPort* getInputPort(const std::string& name) const throw(Exception);
122 Node *getChildByShortName(const std::string& name) const throw(Exception);
123 std::string getMyQualifiedName(const Node *directSon) const;
124 std::string getCaseId(const Node *node) const throw(Exception);
125 virtual void accept(Visitor *visitor);
126 int getRankOfNode(Node *node) const;
127 virtual std::string typeName() {return "YACS__ENGINE__Switch";}
129 YACS::Event updateStateOnFinishedEventFrom(Node *node);
130 Node *simpleClone(ComposedNode *father, bool editionOnly=true) const;
131 std::set<InPort *> getAllInPortsComingFromOutsideOfCurrentScope() const;
132 void checkLinkPossibility(OutPort *start, const std::list<ComposedNode *>& pointsOfViewStart,
133 InPort *end, const std::list<ComposedNode *>& pointsOfViewEnd) throw(Exception);
134 void buildDelegateOf(std::pair<OutPort *, OutPort *>& port, InPort *finalTarget, const std::list<ComposedNode *>& pointsOfView);
135 void getDelegateOf(std::pair<OutPort *, OutPort *>& port, InPort *finalTarget, const std::list<ComposedNode *>& pointsOfView) throw(Exception);
136 void releaseDelegateOf(OutPort *portDwn, OutPort *portUp, InPort *finalTarget, const std::list<ComposedNode *>& pointsOfView) throw(Exception);
137 void checkCFLinks(const std::list<OutPort *>& starts, InputPort *end, unsigned char& alreadyFed, bool direction, LinkInfo& info) const;
138 void checkControlDependancy(OutPort *start, InPort *end, bool cross,
139 std::map < ComposedNode *, std::list < OutPort * > >& fw,
140 std::vector<OutPort *>& fwCross,
141 std::map< ComposedNode *, std::list < OutPort *> >& bw,
142 LinkInfo& info) const;
143 void checkNoCyclePassingThrough(Node *node) throw(Exception);
145 int getNbOfCases() const;
146 static std::string getRepresentationOfCase(int i);