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 #include <iostream> //for debug only
36 #include "YacsTrace.hxx"
38 using namespace YACS::ENGINE;
45 YACSGui_Executor::YACSGui_Executor(YACSGui_Module* guiMod, Proc* theProc) :
51 _engineRef = YACS_ORB::YACS_Gen::_nil();
52 _procRef = YACS_ORB::ProcExec::_nil();
53 _observerRef = YACS_ORB::Observer::_nil();
57 _isStopOnError = false;
58 _execMode = YACS::CONTINUE;
65 YACSGui_Executor::~YACSGui_Executor()
69 //! local run in a QThread
70 /*! local run in a QThread Reimplemented from QThread class.
72 void YACSGui_Executor::run()
76 int debug = 0; // for debug only
77 _localEngine->RunW(_proc, debug);
82 /*! local run or remote (in a SALOME Container)
84 void YACSGui_Executor::runDataflow(const bool isRemoteRun)
86 DEBTRACE("YACSGui_Executor::runDataflow");
87 _isRemoteRun = isRemoteRun;
88 if (!isRemoteRun) // --- wanted local run
91 _localEngine = new Executor();
93 if (! checkEndOfDataFlow()) return;
95 _localEngine->setExecMode(YACS::CONTINUE); // --- control only on remote run
98 else // --- wanted run in a SALOME Container
100 if (CORBA::is_nil(_engineRef))
102 DEBTRACE(">> Create YACS ORB engine!");
103 _engineRef = YACSGui_Module::InitYACSGuiGen(_guiMod->getApp());
107 if (! checkEndOfDataFlow()) return;
109 //Export the proc into temporary XML file
110 QString aFileName = Qtx::tmpDir() + QDir::QDir::separator() + "tmp_" + _proc->getName();
112 if (CORBA::is_nil(_procRef))
114 DEBTRACE("init _procRef");
115 VisitorSaveSalomeSchema aWriter( _proc );
116 aWriter.openFileSchema( aFileName );
117 aWriter.visitProc( _proc );
118 aWriter.closeFileSchema();
119 _procRef = _engineRef->LoadProc(aFileName.latin1());
120 registerStatusObservers();
121 DEBTRACE("_procRef _init");
123 _procRef->setExecMode(getCurrentExecMode());
125 if ( _loadStateFile.empty() )
128 cout<<">> this = "<<this<<endl<<endl;
133 DEBTRACE(">> Run from STATE!");
135 _procRef->RunFromState(_loadStateFile.c_str());
138 SUIT_MessageBox::error1(_guiMod->getApp()->desktop(),
140 tr("Runtime error: execution from the loaded state failed"),
144 cout<<">> this = "<<this<<endl<<endl;
149 //! test if a dataflow is running
151 * return true if no running dataflow (TODO: check save state ? delete procexec servant ?)
153 bool YACSGui_Executor::checkEndOfDataFlow(bool display)
157 if(running()) // --- local run not finished
160 SUIT_MessageBox::error1(_guiMod->getApp()->desktop(),
162 tr("Local Execution Already running..."),
166 if (CORBA::is_nil(_procRef))
169 SUIT_MessageBox::error1(_guiMod->getApp()->desktop(),
171 tr("Runtime error: connection lost on a running scheme"),
176 if (_procRef->isNotFinished())
179 SUIT_MessageBox::error1(_guiMod->getApp()->desktop(),
181 tr("Remote Execution Already running..."),
188 // --- TODO: delete procExec on server ...
197 void YACSGui_Executor::killDataflow()
199 DEBTRACE("YACSGui_Executor::killDataflow");
200 //terminate(); // not safe!
201 if (running()) // --- local run
203 _localEngine->stopExecution();
205 else if (_isRunning) // --- remote run
207 _procRef->stopExecution();
212 //! Suspend/Resume dataflow.
215 void YACSGui_Executor::suspendResumeDataflow()
217 DEBTRACE("YACSGui_Executor::suspendResumeDataflow");
218 if (running()) // --- local run
222 _localEngine->setExecMode(_execMode);
223 _localEngine->resumeCurrentBreakPoint();
226 _localEngine->setExecMode(YACS::STEPBYSTEP);
228 else if (_isRunning) // --- remote run
232 _procRef->setExecMode(getCurrentExecMode());
233 _procRef->resumeCurrentBreakPoint();
236 _procRef->setExecMode(YACS_ORB::STEPBYSTEP);
238 _isSuspended = !_isSuspended;
241 void YACSGui_Executor::suspendDataflow()
243 DEBTRACE("YACSGui_Executor::suspendDataflow");
244 if (running()) // --- local run
246 _localEngine->setExecMode(YACS::STEPBYSTEP);
248 else if (_isRunning) // --- remote run
250 _procRef->setExecMode(YACS_ORB::STEPBYSTEP);
254 void YACSGui_Executor::resumeDataflow()
256 DEBTRACE("YACSGui_Executor::ResumeDataflow");
257 if (running()) // --- local run
259 _localEngine->setExecMode(_execMode);
260 _localEngine->resumeCurrentBreakPoint();
262 else if (_isRunning) // --- remote run
264 _procRef->setExecMode(getCurrentExecMode());
265 _procRef->resumeCurrentBreakPoint();
272 void YACSGui_Executor::stopDataflow()
274 DEBTRACE("YACSGui_Executor::stopDataflow");
275 if (running()) // --- local run
277 _localEngine->stopExecution();
279 else if (_isRunning) // --- remote run
281 _procRef->stopExecution();
286 void YACSGui_Executor::setStepByStepMode()
288 DEBTRACE("YACSGui_Executor::setStepByStepMode");
289 _execMode = YACS::STEPBYSTEP;
290 if (running()) // --- local run
291 _localEngine->setExecMode(YACS::STEPBYSTEP);
292 else if (_isRunning) // --- remote run
293 _procRef->setExecMode(YACS_ORB::STEPBYSTEP);
296 void YACSGui_Executor::setContinueMode()
298 DEBTRACE("YACSGui_Executor::setContinueMode");
299 _execMode = YACS::CONTINUE;
300 if (running()) // --- local run
302 _localEngine->setExecMode(YACS::CONTINUE);
304 else if (_isRunning) // --- remote run
306 _procRef->setExecMode(YACS_ORB::CONTINUE);
310 void YACSGui_Executor::setBreakpointMode()
312 DEBTRACE("YACSGui_Executor::setBreakpointMode");
313 _execMode = YACS::STOPBEFORENODES;
314 if (running()) // --- local run
316 _localEngine->setExecMode(YACS::STOPBEFORENODES);
318 else if (_isRunning) // --- remote run
320 _procRef->setExecMode(YACS_ORB::STOPBEFORENODES);
324 void YACSGui_Executor::setStopOnError(bool aMode)
326 DEBTRACE("YACSGui_Executor::setStopOnError");
327 if (running()) // --- local run
329 _localEngine->setStopOnError(aMode, "/tmp/dumpStateOnError.xml");
330 _isStopOnError = true;
332 else if (_isRunning) // --- remote run
334 _procRef->setStopOnError(aMode, "/tmp/dumpStateOnError.xml");
335 _isStopOnError = true;
339 void YACSGui_Executor::unsetStopOnError()
341 DEBTRACE("YACSGui_Executor::unsetStopOnError");
342 if (running()) // --- local run
344 _localEngine->unsetStopOnError();
345 _isStopOnError = false;
347 else if (_isRunning) // --- remote run
349 _procRef->unsetStopOnError();
350 _isStopOnError = false;
354 void YACSGui_Executor::saveState(const std::string& xmlFile)
356 DEBTRACE("YACSGui_Executor::saveState");
357 bool StartFinish = (getExecutorState() == YACS::NOTYETINITIALIZED || getExecutorState() == YACS::FINISHED );
361 _localEngine && (CORBA::is_nil(_procRef)) && StartFinish ) // --- local run
362 _localEngine->saveState(xmlFile);
365 !_localEngine && !(CORBA::is_nil(_procRef)) && StartFinish ) // --- remote run
366 _procRef->saveState(xmlFile.c_str());
369 void YACSGui_Executor::setLoadStateFile(std::string xmlFile)
371 _loadStateFile = xmlFile;
374 void YACSGui_Executor::setNextStepList(std::list<std::string> nextStepList)
376 DEBTRACE("YACSGui_Executor::setNextStepList");
377 if (running()) // --- local run
379 _localEngine->setStepsToExecute(nextStepList);
381 else if (_isRunning) // --- remote run
383 YACS_ORB::stringArray listOfNextStep;
384 listOfNextStep.length(nextStepList.size());
386 for (list<string>::iterator it = nextStepList.begin(); it != nextStepList.end(); ++it)
387 listOfNextStep[i++] = (*it).c_str();
388 _procRef->setStepsToExecute(listOfNextStep);
392 void YACSGui_Executor::setBreakpointList(std::list<std::string> breakpointList)
394 DEBTRACE("YACSGui_Executor::setBreakpointList");
395 _breakpointList.clear();
396 _breakpointList = breakpointList;
400 //! list must be sent, even empty (only way to remove all breakpoints)
401 void YACSGui_Executor::_setBPList()
403 if (running()) // --- local run
405 _localEngine->setListOfBreakPoints(_breakpointList);
407 else if (_isRunning) // --- remote run
409 YACS_ORB::stringArray listOfBreakPoints;
410 listOfBreakPoints.length(_breakpointList.size());
412 for (list<string>::iterator it = _breakpointList.begin(); it != _breakpointList.end(); ++it)
413 listOfBreakPoints[i++] = (*it).c_str();
414 _procRef->setListOfBreakPoints(listOfBreakPoints);
418 void YACSGui_Executor::registerStatusObservers()
420 DEBTRACE("YACSGui_Executor::registerStatusObservers");
421 if (CORBA::is_nil(_procRef))
423 SUIT_MessageBox::error1(_guiMod->getApp()->desktop(),
425 tr("Runtime error (yacsgui): Lost connection on YACS executor"),
429 if (CORBA::is_nil(_observerRef))
431 _serv = new Observer_i(_proc, _guiMod, this);
432 _observerRef = _serv->_this();
433 _serv->SetImpl(_graph->getStatusObserver());
436 _serv->SetRemoteProc(_procRef);
437 _serv->setConversion();
439 std::list<Node*> aNodeSet = _proc->getAllRecursiveConstituents();
440 for ( std::list<Node*>::iterator it = aNodeSet.begin(); it != aNodeSet.end(); it++ )
442 _procRef->addObserver(_observerRef, _serv->getEngineId((*it)->getNumId()) , "status");
444 _procRef->addObserver(_observerRef, _serv->getEngineId(_proc->getNumId()) , "executor");
447 YACS_ORB::executionMode YACSGui_Executor::getCurrentExecMode()
451 case YACS::CONTINUE: return YACS_ORB::CONTINUE;
452 case YACS::STEPBYSTEP: return YACS_ORB::STEPBYSTEP;
453 case YACS::STOPBEFORENODES: return YACS_ORB::STOPBEFORENODES;
454 default: return YACS_ORB::CONTINUE;
458 int YACSGui_Executor::getExecutorState()
462 _localEngine && (CORBA::is_nil(_procRef)) ) // --- local run
463 return _localEngine->getExecutorState();
466 !_localEngine && !(CORBA::is_nil(_procRef)) ) // --- remote run
467 return _procRef->getExecutorState();
468 else if ( !_localEngine && (CORBA::is_nil(_procRef)) )
469 return YACS::NOTYETINITIALIZED;
470 else if ( _localEngine && !(CORBA::is_nil(_procRef)) )
471 return YACS::FINISHED;
474 void YACSGui_Executor::setEngineRef(YACS_ORB::YACS_Gen_ptr theRef)
479 std::string YACSGui_Executor::getErrorDetails(YACS::ENGINE::Node* node)
483 //get the node engine id
484 int engineId=_serv->getEngineId(node->getNumId());
485 return _procRef->getErrorDetails(engineId);
490 std::string YACSGui_Executor::getErrorReport(YACS::ENGINE::Node* node)
494 //get the node engine id
495 int engineId=_serv->getEngineId(node->getNumId());
496 return _procRef->getErrorReport(engineId);
501 std::string YACSGui_Executor::getContainerLog()
503 DEBTRACE("YACSGui_Executor::getContainerLog");
505 if (!CORBA::is_nil(_engineRef))
507 Engines::Container_var cont= _engineRef->GetContainerRef();
508 CORBA::String_var logname = cont->logfilename();
511 std::string::size_type pos = msg.find(":");
512 msg=msg.substr(pos+1);
517 std::string YACSGui_Executor::getContainerLog(YACS::ENGINE::Node* node)
522 //get the node engine id
523 int engineId=_serv->getEngineId(node->getNumId());
524 CORBA::String_var logname = _procRef->getContainerLog(engineId);
526 std::string::size_type pos = msg.find(":");
527 msg=msg.substr(pos+1);