1 // Copyright (C) 2005 OPEN CASCADE, CEA/DEN, EDF R&D, PRINCIPIA 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
20 #include <YACSGui_Executor.h>
21 #include <YACSGui_XMLDriver.h>
22 #include <YACSGui_Observer.h>
23 #include <YACSGui_Module.h>
24 #include <SUIT_MessageBox.h>
25 #include <SalomeApp_Application.h>
26 #include <Executor.hxx>
27 #include "utilities.h"
33 using namespace YACS::ENGINE;
40 YACSGui_Executor::YACSGui_Executor(YACSGui_Module* guiMod, Proc* theProc) :
46 _engineRef = YACSGui_ORB::YACSGui_Gen::_nil();
47 _procRef = YACSGui_ORB::ProcExec::_nil();
48 _observerRef = YACSGui_ORB::Observer::_nil();
52 _execMode = YACS::CONTINUE;
58 YACSGui_Executor::~YACSGui_Executor()
62 //! local run in a QThread
63 /*! local run in a QThread Reimplemented from QThread class.
65 void YACSGui_Executor::run()
69 int debug = 0; // for debug only
70 _localEngine->RunW(_proc, debug);
75 /*! local run or remote (in a SALOME Container)
77 void YACSGui_Executor::runDataflow(const bool isRemoteRun)
79 MESSAGE("YACSGui_Executor::runDataflow");
80 _isRemoteRun = isRemoteRun;
81 if (!isRemoteRun) // --- wanted local run
84 _localEngine = new Executor();
86 if (! checkEndOfDataFlow()) return;
88 _localEngine->setExecMode(YACS::CONTINUE); // --- control only on remote run
91 else // --- wanted run in a SALOME Container
93 if (CORBA::is_nil(_engineRef))
94 _engineRef = YACSGui_Module::InitYACSGuiGen(_guiMod->getApp());
97 if (! checkEndOfDataFlow()) return;
99 //Export the proc into temporary XML file
100 QString aFileName = Qtx::tmpDir() + QDir::QDir::separator() + "tmp_" + _proc->getName();
102 if (CORBA::is_nil(_procRef))
104 MESSAGE("init _procRef");
105 VisitorSaveSchema aWriter( _proc );
106 aWriter.openFileSchema( aFileName );
107 aWriter.visitProc( _proc );
108 aWriter.closeFileSchema();
109 _procRef = _engineRef->LoadProc(aFileName.latin1());
110 registerStatusObservers();
111 MESSAGE("_procRef _init");
113 _procRef->setExecMode(getCurrentExecMode());
119 //! test if a dataflow is running
121 * return true if no running dataflow (TODO: check save state ? delete procexec servant ?)
123 bool YACSGui_Executor::checkEndOfDataFlow(bool display)
127 if(running()) // --- local run not finished
130 SUIT_MessageBox::error1(_guiMod->getApp()->desktop(),
132 tr("Local Execution Already running..."),
136 if (CORBA::is_nil(_procRef))
139 SUIT_MessageBox::error1(_guiMod->getApp()->desktop(),
141 tr("Runtime error: connection lost on a running scheme"),
146 if (_procRef->isNotFinished())
149 SUIT_MessageBox::error1(_guiMod->getApp()->desktop(),
151 tr("Remote Execution Already running..."),
158 // --- TODO: delete procExec on server ...
167 void YACSGui_Executor::killDataflow()
169 MESSAGE("YACSGui_Executor::killDataflow");
170 //terminate(); // not safe!
171 if (running()) // --- local run
173 _localEngine->stopExecution();
175 else if (_isRunning) // --- remote run
177 _procRef->stopExecution();
182 //! Suspend/Resume dataflow.
185 void YACSGui_Executor::suspendResumeDataflow()
187 MESSAGE("YACSGui_Executor::suspendResumeDataflow");
188 if (running()) // --- local run
192 _localEngine->setExecMode(_execMode);
193 _localEngine->resumeCurrentBreakPoint();
196 _localEngine->setExecMode(YACS::STEPBYSTEP);
198 else if (_isRunning) // --- remote run
202 _procRef->setExecMode(getCurrentExecMode());
203 _procRef->resumeCurrentBreakPoint();
206 _procRef->setExecMode(YACSGui_ORB::STEPBYSTEP);
208 _isSuspended = !_isSuspended;
211 void YACSGui_Executor::suspendDataflow()
213 MESSAGE("YACSGui_Executor::suspendDataflow");
214 if (running()) // --- local run
216 _localEngine->setExecMode(YACS::STEPBYSTEP);
218 else if (_isRunning) // --- remote run
220 _procRef->setExecMode(YACSGui_ORB::STEPBYSTEP);
224 void YACSGui_Executor::resumeDataflow()
226 MESSAGE("YACSGui_Executor::ResumeDataflow");
227 if (running()) // --- local run
229 _localEngine->setExecMode(_execMode);
230 _localEngine->resumeCurrentBreakPoint();
232 else if (_isRunning) // --- remote run
234 _procRef->setExecMode(getCurrentExecMode());
235 _procRef->resumeCurrentBreakPoint();
239 void YACSGui_Executor::stopDataflow()
241 MESSAGE("YACSGui_Executor::stopDataflow");
242 if (running()) // --- local run
244 _localEngine->stopExecution();
246 else if (_isRunning) // --- remote run
248 _procRef->stopExecution();
253 void YACSGui_Executor::setStepByStepMode()
255 MESSAGE("YACSGui_Executor::setStepByStepMode");
256 _execMode = YACS::STEPBYSTEP;
257 if (running()) // --- local run
259 _localEngine->setExecMode(YACS::STEPBYSTEP);
261 else if (_isRunning) // --- remote run
263 _procRef->setExecMode(YACSGui_ORB::STEPBYSTEP);
267 void YACSGui_Executor::setContinueMode()
269 MESSAGE("YACSGui_Executor::setContinueMode");
270 _execMode = YACS::CONTINUE;
271 if (running()) // --- local run
273 _localEngine->setExecMode(YACS::CONTINUE);
275 else if (_isRunning) // --- remote run
277 _procRef->setExecMode(YACSGui_ORB::CONTINUE);
281 void YACSGui_Executor::setBreakpointMode()
283 MESSAGE("YACSGui_Executor::setBreakpointMode");
284 _execMode = YACS::STOPBEFORENODES;
285 if (running()) // --- local run
287 _localEngine->setExecMode(YACS::STOPBEFORENODES);
289 else if (_isRunning) // --- remote run
291 _procRef->setExecMode(YACSGui_ORB::STOPBEFORENODES);
295 void YACSGui_Executor::setStopOnError(bool aMode)
297 MESSAGE("YACSGui_Executor::setStopOnError");
298 if (running()) // --- local run
300 _localEngine->setStopOnError(aMode, "/tmp/dumpStateOnError.xml");
302 else if (_isRunning) // --- remote run
304 _procRef->setStopOnError(aMode, "/tmp/dumpStateOnError.xml");
308 void YACSGui_Executor::setNextStepList(std::list<std::string> nextStepList)
310 MESSAGE("YACSGui_Executor::setNextStepList");
311 if (running()) // --- local run
313 _localEngine->setStepsToExecute(nextStepList);
315 else if (_isRunning) // --- remote run
317 YACSGui_ORB::stringArray listOfNextStep;
318 listOfNextStep.length(nextStepList.size());
320 for (list<string>::iterator it = nextStepList.begin(); it != nextStepList.end(); ++it)
321 listOfNextStep[i++] = (*it).c_str();
322 _procRef->setStepsToExecute(listOfNextStep);
326 void YACSGui_Executor::setBreakpointList(std::list<std::string> breakpointList)
328 MESSAGE("YACSGui_Executor::setBreakpointList");
329 _breakpointList.clear();
330 _breakpointList = breakpointList;
334 //! list must be sent, even empty (only way to remove all breakpoints)
335 void YACSGui_Executor::_setBPList()
337 if (running()) // --- local run
339 _localEngine->setListOfBreakPoints(_breakpointList);
341 else if (_isRunning) // --- remote run
343 YACSGui_ORB::stringArray listOfBreakPoints;
344 listOfBreakPoints.length(_breakpointList.size());
346 for (list<string>::iterator it = _breakpointList.begin(); it != _breakpointList.end(); ++it)
347 listOfBreakPoints[i++] = (*it).c_str();
348 _procRef->setListOfBreakPoints(listOfBreakPoints);
352 void YACSGui_Executor::registerStatusObservers()
354 MESSAGE("YACSGui_Executor::registerStatusObservers");
355 if (CORBA::is_nil(_procRef))
357 SUIT_MessageBox::error1(_guiMod->getApp()->desktop(),
359 tr("Runtime error (yacsgui): Lost connection on YACS executor"),
363 if (CORBA::is_nil(_observerRef))
365 _serv = new Observer_i(_proc, _guiMod, this);
366 _observerRef = _serv->_this();
367 _serv->SetImpl(_graph->getStatusObserver());
370 _serv->SetRemoteProc(_procRef);
371 _serv->setConversion();
373 std::set<Node*> aNodeSet = _proc->getAllRecursiveConstituents();
374 for ( std::set<Node*>::iterator it = aNodeSet.begin(); it != aNodeSet.end(); it++ )
376 _procRef->addObserver(_observerRef, _serv->getEngineId((*it)->getNumId()) , "status");
378 _procRef->addObserver(_observerRef, _serv->getEngineId(_proc->getNumId()) , "executor");
381 YACSGui_ORB::executionMode YACSGui_Executor::getCurrentExecMode()
385 case YACS::CONTINUE: return YACSGui_ORB::CONTINUE;
386 case YACS::STEPBYSTEP: return YACSGui_ORB::STEPBYSTEP;
387 case YACS::STOPBEFORENODES: return YACSGui_ORB::STOPBEFORENODES;
388 default: return YACSGui_ORB::CONTINUE;