Version: 9.15.0
VisitorSalomeSaveState.cxx
Go to the documentation of this file.
1 // Copyright (C) 2006-2025 CEA, EDF
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 
21 #include "TypeConversions.hxx"
22 #include "ForEachLoop.hxx"
23 #include "Proc.hxx"
24 #include "Executor.hxx"
25 #include "AutoLocker.hxx"
26 
27 #include "YacsTrace.hxx"
28 
29 using namespace YACS::ENGINE;
30 
32 :VisitorSaveState(root)
33 {
34 }
35 
37 {
38 }
39 
41 {
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++)
54  {
55  _out << " <inputPort>" << std::endl;
56  _out << " <name>" << (*iter)->getName() << "</name>" << std::endl;
57  try
58  {
59  _out << " ";
60  _out << (*iter)->dump();
61  }
62  catch (YACS::Exception &e)
63  {
64  DEBTRACE("caught YACS:Exception: " << e.what());
65  _out << "<value><error><![CDATA[" << e.what() << "]]></error></value>" << std::endl;
66  }
67  _out << " </inputPort>" << std::endl;
68  }
69 
70  StatesForNode state = node->getState();
71  if(YACS::LOADED == state ||
75  YACS::PAUSE == state ||
78  YACS::FAILED == state ||
79  YACS::ERROR == state)
80  {
81  ForEachLoopPassedData* processedData = node->getProcessedData();
82  if(processedData)
83  {
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;
87 
88  for(it_outputs = processedData->getOutputs().begin(), it_names = processedData->getOutputNames().begin();
89  it_names != processedData->getOutputNames().end();
90  it_outputs++, it_names++)
91  {
92  _out << " <loopOutputPort>" << std::endl;
93  _out << " <name>" << (*it_names) << "</name>" << std::endl;
94  for(unsigned int i = 0; i < (*it_outputs)->size(); i++)
95  {
96  AnyPtr value = (*(*it_outputs))[i];
97  _out << " <sample><index>" << processedIndexes[i]<< "</index>";
98  if(value)
99  _out << convertNeutralXml(value->getType(), value);
100  else
101  _out << "<value>None</value>";
102  _out << " </sample>" << std::endl;
103  }
104  _out << " </loopOutputPort>" << std::endl;
105  }
106 
107  delete processedData;
108  processedData = NULL;
109  }
110  }
111  _out << " </node>" << std::endl;
112 }
113 
115  Executor* exec,
116  const std::string& xmlSchemaFile)
117 {
119  schemaSaveStateUnsafe(proc,xmlSchemaFile);
120 }
121 
122 void YACS::ENGINE::schemaSaveStateUnsafe(Proc* proc, const std::string& xmlSchemaFile)
123 {
124  VisitorSalomeSaveState vss(proc);
125  vss.openFileDump(xmlSchemaFile);
126  proc->accept(&vss);
127  vss.closeFileDump();
128 }
#define DEBTRACE(msg)
Definition: YacsTrace.hxx:31
: Allow to manage memory of instances of T. The only constraint on T is to have method incrRef and De...
Definition: SharedPtr.hxx:30
Base class for all composed nodes.
std::string getChildName(const Node *node) const
std::string getName() const
Threaded Executor.
Definition: Executor.hxx:63
YACS::BASES::Mutex & getTheMutexForSchedulerUpdate()
Definition: Executor.hxx:133
std::list< InputPort * > getLocalInputPorts() const
redefined on derived class of ComposedNode. by default a ComposedNode has no port by itself
ForEachLoopPassedData * getProcessedData() const
const std::vector< unsigned int > & getIds() const
const std::vector< std::string > & getOutputNames() const
const std::vector< SequenceAny * > & getOutputs() const
Loop node for parametric calculation.
virtual YACS::StatesForNode getState() const
Definition: Node.hxx:118
Base class for all schema objects.
Definition: Proc.hxx:44
virtual void accept(Visitor *visitor)
Definition: Proc.cxx:199
virtual void visitForEachLoop(ForEachLoop *node)
std::map< int, std::string > _nodeStateName
void openFileDump(const std::string &xmlDump)
ComposedNode * _root
Definition: Visitor.hxx:85
const char * what(void) const noexcept
Definition: Exception.cxx:50
YACSRUNTIMESALOME_EXPORT void schemaSaveState(Proc *proc, Executor *exec, const std::string &xmlSchemaFile)
YACSRUNTIMESALOME_EXPORT void schemaSaveStateUnsafe(Proc *proc, const std::string &xmlSchemaFile)
std::string convertNeutralXml(const TypeCode *t, YACS::ENGINE::Any *data)
StatesForNode
Definition: define.hxx:34
@ FAILED
Definition: define.hxx:51
@ EXECFAILED
Definition: define.hxx:46
@ LOADED
Definition: define.hxx:39
@ ACTIVATED
Definition: define.hxx:41
@ INTERNALERR
Definition: define.hxx:49
@ SUSPENDED
Definition: define.hxx:44
@ PAUSE
Definition: define.hxx:47
@ TORECONNECT
Definition: define.hxx:48
@ ERROR
Definition: define.hxx:52