Salome HOME
aae2d97a31495bad3f9594f586d04ae517f4b740
[modules/yacs.git] / src / engine / InGate.cxx
1 // Copyright (C) 2006-2014  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 #include "InGate.hxx"
21 #include "Node.hxx"
22
23 //#define _DEVDEBUG_
24 #include "YacsTrace.hxx"
25
26 using namespace YACS::ENGINE;
27 using namespace std;
28
29 const char InGate::NAME[]="InGate";
30
31 InGate::InGate(Node *node):Port(node)
32 {
33 }
34
35 InGate::~InGate()
36 {
37 }
38
39 string InGate::getNameOfTypeOfCurrentInstance() const
40 {
41   return NAME;
42 }
43
44 void InGate::edDisconnectAllLinksToMe()
45 {
46   for(map<OutGate *, bool >::iterator iter=_backLinks.begin();iter!=_backLinks.end();iter++)
47     ((*iter).first)->edRemoveInGate(this,false);
48   _backLinks.clear();
49 }
50
51 //! Notify this port that an upstream node connected by a control flow link is finished
52 /*!
53  *  Calls the node's gate method : Node::exUpdateState
54  *
55  *  Called by OutGate::exNotifyDone
56  */
57 void InGate::exNotifyFromPrecursor(OutGate *from)
58 {
59   DEBTRACE("InGate::exNotifyFromPrecursor");
60   map< OutGate *, bool >::iterator iter=_backLinks.find(from);
61   (*iter).second=true;
62   if(exIsReady())
63     _node->exUpdateState();
64 }
65
66 //! Notify this port that an upstream node connected by a control flow link has failed
67 /*!
68  *
69  */
70 void InGate::exNotifyFailed()
71 {
72   if(_node) _node->exFailedState();
73 }
74
75 //! Notify this port that an upstream node connected by a control flow link has been disabled
76 /*!
77  *
78  */
79 void InGate::exNotifyDisabled()
80 {
81   if(_node)
82     _node->exDisabledState();
83 }
84
85 void InGate::edAppendPrecursor(OutGate *from)
86 {
87   _backLinks[from]=false;
88 }
89
90 void InGate::edRemovePrecursor(OutGate *from)
91 {
92   _backLinks.erase(from);
93 }
94
95 int InGate::getNumberOfBackLinks() const
96 {
97   return _backLinks.size();
98 }
99
100 void InGate::exReset()
101 {
102   for(map<OutGate *, bool >::iterator iter=_backLinks.begin();iter!=_backLinks.end();iter++)
103     (*iter).second=false;
104 }
105
106 bool InGate::exIsReady() const
107 {
108   bool isReady=true;
109   for(map<OutGate *, bool >::const_iterator iter=_backLinks.begin();iter!=_backLinks.end() && isReady;iter++)
110     isReady=(*iter).second;
111   return isReady;
112 }
113
114 std::list<OutGate *> InGate::getBackLinks()
115 {
116   list<OutGate *> listo;
117   for(map<OutGate *, bool >::iterator iter=_backLinks.begin();iter!=_backLinks.end();iter++)
118     listo.push_back(iter->first);
119   return listo;  
120 }
121
122 void InGate::setPrecursorDone(OutGate *from)
123 {
124   map< OutGate *, bool >::iterator iter=_backLinks.find(from);
125   (*iter).second=true;  
126 }