21 #include "SALOME_LifeCycleCORBA.hxx"
22 #include "SALOME_NamingService.hxx"
41 using namespace YACS::HMI;
42 using namespace YACS::ENGINE;
46 DEBTRACE(
"GuiExecutor::GuiExecutor");
49 _context = QtGuiContext::getQtCurrent();
51 _engineRef = YACS_ORB::YACS_Gen::_nil();
52 _procRef = YACS_ORB::ProcExec::_nil();
53 _observerRef = YACS_ORB::Observer::_nil();
60 _isStopOnError =
false;
64 _breakpointList.clear();
68 GuiExecutor::~GuiExecutor()
70 DEBTRACE(
"GuiExecutor::~GuiExecutor");
73 void GuiExecutor::closeContext()
75 DEBTRACE(
"GuiExecutor::closeContext");
79 void GuiExecutor::startResumeDataflow(
bool initialize)
81 DEBTRACE(
"GuiExecutor::runDataflow " << initialize);
87 if (CORBA::is_nil(_engineRef))
92 SALOME_NamingService namingService(orb);
93 SALOME_LifeCycleCORBA lcc(&namingService);
94 ostringstream containerName;
95 containerName <<
"localhost/YACSContainer" << QtGuiContext::getQtCurrent()->getStudyId();
96 Engines::EngineComponent_var
comp = lcc.FindOrLoad_Component(containerName.str().c_str(),
"YACS" );
97 _engineRef =YACS_ORB::YACS_Gen::_narrow(comp);
98 YASSERT(!CORBA::is_nil(_engineRef));
101 checkEndOfDataflow();
107 _procRef->setExecMode(getCurrentExecMode());
108 _procRef->resumeCurrentBreakPoint();
109 _isSuspended =
false;
116 if (CORBA::is_nil(_procRef))
119 _procRef = _engineRef->LoadProc(_context->getFileName().toUtf8());
120 registerStatusObservers();
124 YASSERT(!CORBA::is_nil(_procRef));
129 _procRef->setExecMode(getCurrentExecMode());
132 if (_loadStateFile.empty())
142 _procRef->RunFromState(_loadStateFile.c_str());
146 DEBTRACE(
"Runtime error: execution from the loaded state failed")
152 bool GuiExecutor::checkEndOfDataflow(
bool display)
154 DEBTRACE(
"GuiExecutor::checkEndOfDataFlow");
157 if (CORBA::is_nil(_procRef))
159 DEBTRACE(
"Runtime error: connection lost on a running scheme");
163 if (_procRef->isNotFinished())
165 DEBTRACE(
"Remote Execution Already running...");
177 void GuiExecutor::killDataflow()
179 DEBTRACE(
"GuiExecutor::killDataflow");
181 _procRef->stopExecution();
184 void GuiExecutor::suspendDataflow()
186 DEBTRACE(
"GuiExecutor::suspendDataflow");
191 void GuiExecutor::resumeDataflow()
193 DEBTRACE(
"GuiExecutor::resumeDataflow");
196 _procRef->setExecMode(getCurrentExecMode());
197 _procRef->resumeCurrentBreakPoint();
201 void GuiExecutor::stopDataflow()
203 DEBTRACE(
"GuiExecutor::stopDataflow");
205 _procRef->stopExecution();
208 void GuiExecutor::resetDataflow()
210 DEBTRACE(
"GuiExecutor::resetDataflow");
212 checkEndOfDataflow();
214 _procRef->stopExecution();
215 checkEndOfDataflow();
222 _procRef->RestartFromState(
"");
227 void GuiExecutor::setStepByStepMode()
229 DEBTRACE(
"GuiExecutor::setStepByStepMode");
235 void GuiExecutor::setContinueMode()
237 DEBTRACE(
"GuiExecutor::setContinueMode");
243 void GuiExecutor::setBreakpointMode()
245 DEBTRACE(
"GuiExecutor::setBreakpointMode");
251 void GuiExecutor::setStopOnError(
bool aMode)
253 DEBTRACE(
"GuiExecutor::setStopOnError " << aMode);
257 _procRef->setStopOnError(aMode, (getenv(
"TEMP") +
string(
"\\dumpStateOnError_") + getenv(
"USER") +
string(
".xml")).c_str());
259 _procRef->setStopOnError(aMode, (
string(
"/tmp/dumpStateOnError_") + getenv(
"USER") +
string(
".xml")).c_str());
261 _isStopOnError =
true;
265 void GuiExecutor::unsetStopOnError()
267 DEBTRACE(
"GuiExecutor::unsetStopOnError");
270 _procRef->unsetStopOnError();
271 _isStopOnError =
false;
276 void GuiExecutor::saveState(
const std::string& xmlFile)
278 DEBTRACE(
"GuiExecutor::saveState " << xmlFile);
282 !(CORBA::is_nil(_procRef)) && StartFinish ) {
283 if ( !_procRef->saveState(xmlFile.c_str()) ) {
284 string what =
"Impossible to open file for writing: " + xmlFile;
290 void GuiExecutor::setLoadStateFile(std::string xmlFile)
292 DEBTRACE(
"GuiExecutor::setLoadStateFile " << xmlFile);
293 _loadStateFile = xmlFile;
299 DEBTRACE(
"GuiExecutor::getCurrentExecMode");
309 int GuiExecutor::getExecutorState()
311 DEBTRACE(
"GuiExecutor::getExecutorState");
312 if (_isRunning || !CORBA::is_nil(_procRef))
313 return _procRef->getExecutorState();
314 else if (CORBA::is_nil(_procRef))
321 void GuiExecutor::setBreakpointList(std::list<std::string> breakpointList)
323 DEBTRACE(
"GuiExecutor::setBreakpointList");
329 _breakpointList.clear();
330 _breakpointList = breakpointList;
334 _context->getGMain()->_breakpointsModeAct->setChecked(
true);
339 void GuiExecutor::addBreakpoint(std::string breakpoint)
341 DEBTRACE(
"addBreakpoint " << breakpoint);
347 _breakpointList.push_back(breakpoint);
351 _context->getGMain()->_breakpointsModeAct->setChecked(
true);
356 void GuiExecutor::removeBreakpoint(std::string breakpoint)
358 DEBTRACE(
"removeBreakpoint " << breakpoint);
359 _breakpointList.remove(breakpoint);
363 void GuiExecutor::setNextStepList(std::list<std::string> nextStepList)
365 DEBTRACE(
"GuiExecutor::setNextStepList");
369 listOfNextStep.length(nextStepList.size());
371 for (list<string>::iterator it = nextStepList.begin(); it != nextStepList.end(); ++it)
372 listOfNextStep[i++] = (*it).c_str();
373 _procRef->setStepsToExecute(listOfNextStep);
377 void GuiExecutor::registerStatusObservers()
379 DEBTRACE(
"GuiExecutor::registerStatusObservers");
380 if (CORBA::is_nil(_procRef))
382 DEBTRACE(
"Runtime error (yacsgui): Lost connection on YACS executor");
385 if (CORBA::is_nil(_observerRef))
388 _serv->SetImpl(
this);
389 _observerRef = _serv->_this();
392 _serv->SetRemoteProc(_procRef);
393 _serv->setConversion();
395 std::list<Node*> aNodeSet = _proc->getAllRecursiveConstituents();
396 for ( std::list<Node*>::iterator it = aNodeSet.begin(); it != aNodeSet.end(); it++ )
398 _procRef->addObserver(_observerRef, _serv->getEngineId((*it)->getNumId()) ,
"status");
399 _procRef->addObserver(_observerRef, _serv->getEngineId((*it)->getNumId()) ,
"progress");
401 _procRef->addObserver(_observerRef, _serv->getEngineId(_proc->getNumId()) ,
"executor");
406 void GuiExecutor::setEngineRef(YACS_ORB::YACS_Gen_ptr
ref)
408 DEBTRACE(
"GuiExecutor::setEngineRef");
414 DEBTRACE(
"GuiExecutor::getErrorDetails");
417 int engineId=_serv->getEngineId(node->
getNumId());
418 return _procRef->getErrorDetails(engineId);
425 DEBTRACE(
"GuiExecutor::getErrorReport");
428 int engineId=_serv->getEngineId(node->
getNumId());
429 return _procRef->getErrorReport(engineId);
434 std::string GuiExecutor::getContainerLog()
436 DEBTRACE(
"GuiExecutor::getContainerLog");
438 if (!CORBA::is_nil(_engineRef))
440 Engines::Container_var cont= _engineRef->GetContainerRef();
441 CORBA::String_var logname = cont->logfilename();
444 std::string::size_type pos = msg.find(
":");
445 msg=msg.substr(pos+1);
452 DEBTRACE(
"GuiExecutor::getContainerLog(YACS::ENGINE::Node* node)");
456 int engineId=_serv->getEngineId(node->
getNumId());
457 CORBA::String_var logname = _procRef->getContainerLog(engineId);
459 std::string::size_type pos = msg.find(
":");
460 msg=msg.substr(pos+1);
465 void GuiExecutor::shutdownProc()
467 DEBTRACE(
"GuiExecutor::shutdownProc " << _shutdownLevel <<
"," << _isRunning);
468 checkEndOfDataflow();
470 _procRef->shutdownProc(_shutdownLevel);
475 DEBTRACE(
"GuiExecutor::setInPortValue");
480 std::string nodeName;
486 std::string msg = _procRef->setInPortValue(nodeName.c_str(), port->
getName().c_str(), value.c_str());
493 if (!yev)
return false;
496 DEBTRACE(
"<" << numid <<
"," << event <<
">");
502 if (event ==
"executor")
504 int execState = _procRef->getExecutorState();
505 list<string> nextSteps;
508 YACS_ORB::stringArray_var nstp = _procRef->getTasksToLoad();
509 for (CORBA::ULong
i=0;
i<nstp->length();
i++)
510 nextSteps.push_back(nstp[
i].in());
519 if (! _serv->_engineToGuiMap.count(numid))
521 int state = _procRef->getNodeState(numid);
522 int iGui = _serv->_engineToGuiMap[numid];
523 YASSERT(_context->_mapOfExecSubjectNode.count(iGui));
524 SubjectNode *snode = _context->_mapOfExecSubjectNode[iGui];
527 if (event ==
"progress") {
528 std::string progress = _procRef->getNodeProgress(numid);
529 snode->setProgress( progress );
535 list<InputPort*>::iterator iti = inports.begin();
536 for ( ; iti != inports.end(); ++iti)
538 string val = _procRef->getInPortValue(numid, (*iti)->getName().c_str());
539 DEBTRACE(
"node " << snode->getName() <<
" inport " << (*iti)->getName()
540 <<
" value " << val);
541 YASSERT(_context->_mapOfSubjectDataPort.count(*iti));
547 list<OutputPort*>::iterator ito = outports.begin();
548 for ( ; ito != outports.end(); ++ito)
550 string val = _procRef->getOutPortValue(numid, (*ito)->getName().c_str());
551 DEBTRACE(
"node " << snode->getName() <<
" outport " << (*ito)->getName()
552 <<
" value " << val);
553 YASSERT(_context->_mapOfSubjectDataPort.count(*ito));
565 void GuiExecutor::setBPList()
571 listOfBreakPoints.length(_breakpointList.size());
573 for (list<string>::iterator it = _breakpointList.begin(); it != _breakpointList.end(); ++it)
574 listOfBreakPoints[i++] = (*it).c_str();
575 _procRef->setListOfBreakPoints(listOfBreakPoints);
585 std::list<Node*> aNodeSet = _proc->getAllRecursiveConstituents();
586 for ( std::list<Node*>::iterator it = aNodeSet.begin(); it != aNodeSet.end(); it++ ){
588 numid = (*it)->getNumId();
590 state = _proc->getNodeState(numid);
591 SubjectNode *snode = _context->_mapOfExecSubjectNode[numid];
595 list<InputPort*>::iterator iti = inports.begin();
596 for ( ; iti != inports.end(); ++iti)
598 string val = _proc->getInPortValue(numid, (*iti)->getName().c_str());
599 YASSERT(_context->_mapOfSubjectDataPort.count(*iti));
605 list<OutputPort*>::iterator ito = outports.begin();
606 for ( ; ito != outports.end(); ++ito)
608 string val = _proc->getOutPortValue(numid, (*ito)->getName().c_str());
609 YASSERT(_context->_mapOfSubjectDataPort.count(*ito));
616 state = _proc->getRootNode()->getEffectiveState();
620 if(jobState!=
"RUNNING")