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 #include "ElementaryNode.hxx"
23 #include "ForEachLoop.hxx"
24 #include "OptimizerLoop.hxx"
26 #include "ForLoop.hxx"
27 #include "WhileLoop.hxx"
29 #include "InputPort.hxx"
30 #include "InlineNode.hxx"
31 #include "ServiceNode.hxx"
32 #include "ServerNode.hxx"
33 #include "ServiceInlineNode.hxx"
34 #include "DataNode.hxx"
36 #include "VisitorSaveState.hxx"
41 using namespace YACS::ENGINE;
45 #include "YacsTrace.hxx"
47 VisitorSaveState::VisitorSaveState(ComposedNode *root): Visitor(root)
49 _nodeStateName[YACS::READY] ="READY";
50 _nodeStateName[YACS::TOLOAD] ="TOLOAD";
51 _nodeStateName[YACS::LOADED] ="LOADED";
52 _nodeStateName[YACS::TOACTIVATE] ="TOACTIVATE";
53 _nodeStateName[YACS::ACTIVATED] ="ACTIVATED";
54 _nodeStateName[YACS::DESACTIVATED] ="DESACTIVATED";
55 _nodeStateName[YACS::DONE] ="DONE";
56 _nodeStateName[YACS::SUSPENDED] ="SUSPENDED";
57 _nodeStateName[YACS::LOADFAILED] ="LOADFAILED";
58 _nodeStateName[YACS::EXECFAILED] ="EXECFAILED";
59 _nodeStateName[YACS::PAUSE] ="PAUSE";
60 _nodeStateName[YACS::INTERNALERR] ="INTERNALERR";
61 _nodeStateName[YACS::DISABLED] ="DISABLED";
62 _nodeStateName[YACS::FAILED] ="FAILED";
63 _nodeStateName[YACS::ERROR] ="ERROR";
66 VisitorSaveState::~VisitorSaveState()
70 _out << "</graphState>" << endl;
75 void VisitorSaveState::openFileDump(const std::string& xmlDump) throw(YACS::Exception)
77 _out.open(xmlDump.c_str(), ios::out);
80 string what = "Impossible to open file for writing: " + xmlDump;
81 throw Exception(what);
83 _out << "<?xml version='1.0'?>" << endl;
84 _out << "<graphState>" << endl;
87 void VisitorSaveState::closeFileDump()
89 if (!_out) throw Exception("No file open for dump state");
90 _out << "</graphState>" << endl;
94 void VisitorSaveState::visitElementaryNode(ElementaryNode *node)
96 if (!_out) throw Exception("No file open for dump state");
97 string name = _root->getChildName(node);
98 DEBTRACE("VisitorSaveState::visitElementaryNode --- " << name);
99 _out << " <node type='elementaryNode'>" << endl;
100 _out << " <name>" << name << "</name>" << endl;
101 int nodeState = node->getState();
102 _out << " <state>" << _nodeStateName[nodeState] << "</state>" << endl;
104 list<InputPort *> setOfInputPort = node->getSetOfInputPort();
105 list<InputPort *>::iterator iter;
106 for(iter = setOfInputPort.begin(); iter != setOfInputPort.end(); iter++)
108 _out << " <inputPort>" << endl;
109 _out << " <name>" << (*iter)->getName() << "</name>" << endl;
113 _out << (*iter)->dump();
115 catch (YACS::Exception &e)
117 DEBTRACE("caught YACS:Exception: " << e.what());
118 _out << "<value><error><![CDATA[" << e.what() << "]]></error></value>" << endl;
120 _out << " </inputPort>" << endl;
123 list<OutputPort *> setOfOutputPort = node->getSetOfOutputPort();
124 list<OutputPort *>::iterator oiter;
125 for(oiter = setOfOutputPort.begin(); oiter != setOfOutputPort.end(); oiter++)
127 _out << " <outputPort>" << endl;
128 _out << " <name>" << (*oiter)->getName() << "</name>" << endl;
132 _out << (*oiter)->dump();
134 catch (YACS::Exception &e)
136 DEBTRACE("caught YACS:Exception: " << e.what());
137 _out << "<value><error><![CDATA[" << e.what() << "]]></error></value>" << endl;
139 _out << " </outputPort>" << endl;
142 _out << " </node>" << endl;
145 void VisitorSaveState::visitBloc(Bloc *node)
147 node->ComposedNode::accept(this);
148 if (!_out) throw Exception("No file open for dump state");
149 string name = _root->getName();
150 if (static_cast<ComposedNode*>(node) != _root) name = _root->getChildName(node);
151 DEBTRACE("VisitorSaveState::visitBloc ------------- " << name);
152 _out << " <node type='bloc'>" << endl;
153 _out << " <name>" << name << "</name>" << endl;
154 _out << " <state>" << _nodeStateName[node->getState()] << "</state>" << endl;
156 _out << " </node>" << endl;
159 void VisitorSaveState::visitProc(Proc *node)
161 node->ComposedNode::accept(this);
162 if (!_out) throw Exception("No file open for dump state");
163 string name = _root->getName();
164 if (static_cast<ComposedNode*>(node) != _root) name = _root->getChildName(node);
165 DEBTRACE("VisitorSaveState::visitProc ------------- " << name);
166 _out << " <node type='proc'>" << endl;
167 _out << " <name>" << name << "</name>" << endl;
168 _out << " <state>" << _nodeStateName[node->getState()] << "</state>" << endl;
170 _out << " </node>" << endl;
173 void VisitorSaveState::visitForEachLoop(ForEachLoop *node)
175 node->ComposedNode::accept(this);
176 if (!_out) throw Exception("No file open for dump state");
177 string name = _root->getName();
178 if (static_cast<ComposedNode*>(node) != _root) name = _root->getChildName(node);
179 DEBTRACE("VisitorSaveState::visitForEachLoop ------ " << name);
180 _out << " <node type='forEachLoop'>" << endl;
181 _out << " <name>" << name << "</name>" << endl;
182 _out << " <state>" << _nodeStateName[node->getState()] << "</state>" << endl;
184 _out << " </node>" << endl;
187 void VisitorSaveState::visitOptimizerLoop(OptimizerLoop *node)
189 node->ComposedNode::accept(this);
190 if (!_out) throw Exception("No file open for dump state");
191 string name = _root->getName();
192 if (static_cast<ComposedNode*>(node) != _root) name = _root->getChildName(node);
193 DEBTRACE("VisitorSaveState::visitOptimizerLoop ------ " << name);
194 _out << " <node type='optimizerLoop'>" << endl;
195 _out << " <name>" << name << "</name>" << endl;
196 _out << " <state>" << _nodeStateName[node->getState()] << "</state>" << endl;
198 _out << " </node>" << endl;
201 void VisitorSaveState::visitDynParaLoop(DynParaLoop *node)
203 node->ComposedNode::accept(this);
206 void VisitorSaveState::visitLoop(Loop *node)
208 node->ComposedNode::accept(this);
209 if (!_out) throw Exception("No file open for dump state");
210 string name = _root->getName();
211 if (static_cast<ComposedNode*>(node) != _root) name = _root->getChildName(node);
212 DEBTRACE("VisitorSaveState::visitLoop ------------- " << name);
213 _out << " <node type ='loop'>" << endl;
214 _out << " <name>" << name << "</name>" << endl;
215 _out << " <state>" << _nodeStateName[node->getState()] << "</state>" << endl;
216 _out << " <nbdone>" << node->getNbOfTurns() << "</nbdone>" << endl;
218 _out << " </node>" << endl;
221 void VisitorSaveState::visitForLoop(ForLoop *node)
223 node->ComposedNode::accept(this);
224 if (!_out) throw Exception("No file open for dump state");
225 string name = _root->getName();
226 if (static_cast<ComposedNode*>(node) != _root) name = _root->getChildName(node);
227 DEBTRACE("VisitorSaveState::visitForLoop ---------- " << name);
228 _out << " <node type='forLoop'>" << endl;
229 _out << " <name>" << name << "</name>" << endl;
230 _out << " <state>" << _nodeStateName[node->getState()] << "</state>" << endl;
231 _out << " <nbdone>" << node->getNbOfTurns() << "</nbdone>" << endl;
232 InputPort * ip = node->edGetNbOfTimesInputPort();
234 throw Exception("NbOfTimesInputPort in forLoop empty, case not handled yet...");
235 Any *val = static_cast<Any*>(ip->get());
236 int nsteps = val->getIntValue();
237 _out << " <nsteps>" << nsteps << "</nsteps>" << endl;
239 _out << " </node>" << endl;
242 void VisitorSaveState::visitWhileLoop(WhileLoop *node)
244 node->ComposedNode::accept(this);
245 if (!_out) throw Exception("No file open for dump state");
246 string name = _root->getName();
247 if (static_cast<ComposedNode*>(node) != _root) name = _root->getChildName(node);
248 DEBTRACE("VisitorSaveState::visitWhileLoop -------- " << name);
249 _out << " <node type='whileLoop'>" << endl;
250 _out << " <name>" << name << "</name>" << endl;
251 _out << " <state>" << _nodeStateName[node->getState()] << "</state>" << endl;
252 _out << " <nbdone>" << node->getNbOfTurns() << "</nbdone>" << endl;
253 InputPort * ip = node->edGetConditionPort();
255 throw Exception("condition in WhileLoop empty, case not handled yet...");
256 if ( ConditionInputPort* cip = dynamic_cast<ConditionInputPort*>(ip) )
258 bool condition = cip->getValue();
259 _out << " <condition>" << condition << "</condition>" << endl;
262 _out << " </node>" << endl;
265 void VisitorSaveState::visitSwitch(Switch *node)
267 node->ComposedNode::accept(this);
268 if (!_out) throw Exception("No file open for dump state");
269 string name = _root->getName();
270 if (static_cast<ComposedNode*>(node) != _root) name = _root->getChildName(node);
271 DEBTRACE("VisitorSaveState::visitSwitch ----------- " << name);
272 _out << " <node type='switch'>" << endl;
273 _out << " <name>" << name << "</name>" << endl;
274 _out << " <state>" << _nodeStateName[node->getState()] << "</state>" << endl;
275 InputPort * ip = node->edGetConditionPort();
277 throw Exception("condition in switch empty, case not handled yet...");
278 Any *val = static_cast<Any*>(ip->get());
279 int condition = val->getIntValue();
280 _out << " <condition>" << condition << "</condition>" << endl;
282 _out << " </node>" << endl;
285 void VisitorSaveState::visitInlineNode(InlineNode *node)
287 visitElementaryNode(node);
290 void VisitorSaveState::visitInlineFuncNode(InlineFuncNode *node)
292 visitElementaryNode(node);
295 void VisitorSaveState::visitServiceNode(ServiceNode *node)
297 visitElementaryNode(node);
300 void VisitorSaveState::visitServerNode(ServerNode *node)
302 visitElementaryNode(node);
305 void VisitorSaveState::visitServiceInlineNode(ServiceInlineNode *node)
307 visitElementaryNode(node);
310 void VisitorSaveState::visitPresetNode(DataNode *node)
312 visitElementaryNode(node);
315 void VisitorSaveState::visitOutNode(DataNode *node)
317 visitElementaryNode(node);
320 void VisitorSaveState::visitStudyInNode(DataNode *node)
322 visitElementaryNode(node);
325 void VisitorSaveState::visitStudyOutNode(DataNode *node)
327 visitElementaryNode(node);