1 // Copyright (C) 2006-2024 CEA, EDF
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 "VisitorSalomeSaveState.hxx"
21 #include "TypeConversions.hxx"
22 #include "ForEachLoop.hxx"
24 #include "Executor.hxx"
25 #include "AutoLocker.hxx"
27 #include "YacsTrace.hxx"
29 using namespace YACS::ENGINE;
31 VisitorSalomeSaveState::VisitorSalomeSaveState(ComposedNode *root)
32 :VisitorSaveState(root)
36 VisitorSalomeSaveState::~VisitorSalomeSaveState()
40 void VisitorSalomeSaveState::visitForEachLoop(ForEachLoop *node)
42 node->ComposedNode::accept(this);
43 if (!_out) throw Exception("No file open for dump state");
44 std::string name = _root->getName();
45 if (static_cast<ComposedNode*>(node) != _root) name = _root->getChildName(node);
46 DEBTRACE("VisitorSaveState::visitForEachLoop ------ " << name);
47 _out << " <node type='forEachLoop'>" << std::endl;
48 _out << " <name>" << name << "</name>" << std::endl;
49 _out << " <state>" << _nodeStateName[node->getState()] << "</state>" << std::endl;
50 // VisitorSaveState::visitForEachLoop(node);
51 std::list<InputPort *> setOfInputPort = node->getLocalInputPorts();
52 std::list<InputPort *>::iterator iter;
53 for(iter = setOfInputPort.begin(); iter != setOfInputPort.end(); iter++)
55 _out << " <inputPort>" << std::endl;
56 _out << " <name>" << (*iter)->getName() << "</name>" << std::endl;
60 _out << (*iter)->dump();
62 catch (YACS::Exception &e)
64 DEBTRACE("caught YACS:Exception: " << e.what());
65 _out << "<value><error><![CDATA[" << e.what() << "]]></error></value>" << std::endl;
67 _out << " </inputPort>" << std::endl;
70 StatesForNode state = node->getState();
71 if(YACS::LOADED == state ||
72 YACS::ACTIVATED == state ||
73 YACS::SUSPENDED == state ||
74 YACS::EXECFAILED == state ||
75 YACS::PAUSE == state ||
76 YACS::TORECONNECT == state ||
77 YACS::INTERNALERR == state ||
78 YACS::FAILED == state ||
81 ForEachLoopPassedData* processedData = node->getProcessedData();
84 const std::vector<unsigned int>& processedIndexes = processedData->getIds();
85 std::vector<SequenceAny *>::const_iterator it_outputs;
86 std::vector<std::string>::const_iterator it_names;
88 for(it_outputs = processedData->getOutputs().begin(), it_names = processedData->getOutputNames().begin();
89 it_names != processedData->getOutputNames().end();
90 it_outputs++, it_names++)
92 _out << " <loopOutputPort>" << std::endl;
93 _out << " <name>" << (*it_names) << "</name>" << std::endl;
94 for(unsigned int i = 0; i < (*it_outputs)->size(); i++)
96 AnyPtr value = (*(*it_outputs))[i];
97 _out << " <sample><index>" << processedIndexes[i]<< "</index>";
99 _out << convertNeutralXml(value->getType(), value);
101 _out << "<value>None</value>";
102 _out << " </sample>" << std::endl;
104 _out << " </loopOutputPort>" << std::endl;
107 delete processedData;
108 processedData = NULL;
111 _out << " </node>" << std::endl;
114 void YACS::ENGINE::schemaSaveState(Proc* proc,
116 const std::string& xmlSchemaFile)
118 YACS::BASES::AutoLocker<YACS::BASES::Mutex> alck(&(exec->getTheMutexForSchedulerUpdate()));
119 schemaSaveStateUnsafe(proc,xmlSchemaFile);
122 void YACS::ENGINE::schemaSaveStateUnsafe(Proc* proc, const std::string& xmlSchemaFile)
124 VisitorSalomeSaveState vss(proc);
125 vss.openFileDump(xmlSchemaFile);