21 #include "SALOME_LifeCycleCORBA.hxx"
23 #include "SALOME_Launcher.hxx"
37 #include "KernelBasis.hxx"
48 DEBTRACE(
"GuiExecutor::GuiExecutor");
51 _context = QtGuiContext::getQtCurrent();
53 _engineRef = YACS_ORB::YACS_Gen::_nil();
54 _procRef = YACS_ORB::ProcExec::_nil();
55 _observerRef = YACS_ORB::Observer::_nil();
62 _isStopOnError =
false;
66 _breakpointList.clear();
69 KERNEL::getLauncherSA();
74 GuiExecutor::~GuiExecutor()
76 DEBTRACE(
"GuiExecutor::~GuiExecutor");
79 void GuiExecutor::closeContext()
81 DEBTRACE(
"GuiExecutor::closeContext");
85 void GuiExecutor::startResumeDataflow(
bool initialize)
87 DEBTRACE(
"GuiExecutor::runDataflow " << initialize);
93 if (CORBA::is_nil(_engineRef))
101 SALOME_LifeCycleCORBA lcc(&namingService);
102 ostringstream containerName;
103 containerName <<
"localhost/YACSContainer";
104 Engines::EngineComponent_var
comp = lcc.FindOrLoad_Component(containerName.str().c_str(),
"YACS" );
105 _engineRef =YACS_ORB::YACS_Gen::_narrow(
comp);
106 YASSERT(!CORBA::is_nil(_engineRef));
110 checkEndOfDataflow();
116 _procRef->setExecMode(getCurrentExecMode());
117 _procRef->resumeCurrentBreakPoint();
118 _isSuspended =
false;
125 if (CORBA::is_nil(_procRef))
128 _procRef = _engineRef->LoadProc(_context->getFileName().toUtf8());
129 registerStatusObservers();
133 YASSERT(!CORBA::is_nil(_procRef));
138 _procRef->setExecMode(getCurrentExecMode());
141 if (_loadStateFile.empty())
151 _procRef->RunFromState(_loadStateFile.c_str());
155 DEBTRACE(
"Runtime error: execution from the loaded state failed")
161 bool GuiExecutor::checkEndOfDataflow(
bool display)
163 DEBTRACE(
"GuiExecutor::checkEndOfDataFlow");
166 if (CORBA::is_nil(_procRef))
168 DEBTRACE(
"Runtime error: connection lost on a running scheme");
172 if (_procRef->isNotFinished())
174 DEBTRACE(
"Remote Execution Already running...");
186 void GuiExecutor::killDataflow()
188 DEBTRACE(
"GuiExecutor::killDataflow");
190 _procRef->stopExecution();
193 void GuiExecutor::suspendDataflow()
195 DEBTRACE(
"GuiExecutor::suspendDataflow");
200 void GuiExecutor::resumeDataflow()
202 DEBTRACE(
"GuiExecutor::resumeDataflow");
205 _procRef->setExecMode(getCurrentExecMode());
206 _procRef->resumeCurrentBreakPoint();
210 void GuiExecutor::stopDataflow()
212 DEBTRACE(
"GuiExecutor::stopDataflow");
214 _procRef->stopExecution();
217 void GuiExecutor::resetDataflow()
219 DEBTRACE(
"GuiExecutor::resetDataflow");
221 checkEndOfDataflow();
223 _procRef->stopExecution();
224 checkEndOfDataflow();
231 _procRef->RestartFromState(
"");
236 void GuiExecutor::setStepByStepMode()
238 DEBTRACE(
"GuiExecutor::setStepByStepMode");
244 void GuiExecutor::setContinueMode()
246 DEBTRACE(
"GuiExecutor::setContinueMode");
252 void GuiExecutor::setBreakpointMode()
254 DEBTRACE(
"GuiExecutor::setBreakpointMode");
260 void GuiExecutor::setStopOnError(
bool aMode)
262 DEBTRACE(
"GuiExecutor::setStopOnError " << aMode);
266 _procRef->setStopOnError(aMode, (getenv(
"TEMP") +
string(
"\\dumpStateOnError_") + getenv(
"USER") +
string(
".xml")).c_str());
268 _procRef->setStopOnError(aMode, (
string(
"/tmp/dumpStateOnError_") + getenv(
"USER") +
string(
".xml")).c_str());
270 _isStopOnError =
true;
274 void GuiExecutor::unsetStopOnError()
276 DEBTRACE(
"GuiExecutor::unsetStopOnError");
279 _procRef->unsetStopOnError();
280 _isStopOnError =
false;
285 void GuiExecutor::saveState(
const std::string& xmlFile)
287 DEBTRACE(
"GuiExecutor::saveState " << xmlFile);
291 !(CORBA::is_nil(_procRef)) && StartFinish ) {
292 if ( !_procRef->saveState(xmlFile.c_str()) ) {
293 string what =
"Impossible to open file for writing: " + xmlFile;
299 void GuiExecutor::setLoadStateFile(std::string xmlFile)
301 DEBTRACE(
"GuiExecutor::setLoadStateFile " << xmlFile);
302 _loadStateFile = xmlFile;
308 DEBTRACE(
"GuiExecutor::getCurrentExecMode");
318 int GuiExecutor::getExecutorState()
320 DEBTRACE(
"GuiExecutor::getExecutorState");
321 if (_isRunning || !CORBA::is_nil(_procRef))
322 return _procRef->getExecutorState();
323 else if (CORBA::is_nil(_procRef))
330 void GuiExecutor::setBreakpointList(std::list<std::string> breakpointList)
332 DEBTRACE(
"GuiExecutor::setBreakpointList");
338 _breakpointList.clear();
339 _breakpointList = breakpointList;
343 _context->getGMain()->_breakpointsModeAct->setChecked(
true);
348 void GuiExecutor::addBreakpoint(std::string breakpoint)
350 DEBTRACE(
"addBreakpoint " << breakpoint);
356 _breakpointList.push_back(breakpoint);
360 _context->getGMain()->_breakpointsModeAct->setChecked(
true);
365 void GuiExecutor::removeBreakpoint(std::string breakpoint)
367 DEBTRACE(
"removeBreakpoint " << breakpoint);
368 _breakpointList.remove(breakpoint);
372 void GuiExecutor::setNextStepList(std::list<std::string> nextStepList)
374 DEBTRACE(
"GuiExecutor::setNextStepList");
378 listOfNextStep.length(nextStepList.size());
380 for (list<string>::iterator it = nextStepList.begin(); it != nextStepList.end(); ++it)
381 listOfNextStep[
i++] = (*it).c_str();
382 _procRef->setStepsToExecute(listOfNextStep);
386 void GuiExecutor::registerStatusObservers()
388 DEBTRACE(
"GuiExecutor::registerStatusObservers");
389 if (CORBA::is_nil(_procRef))
391 DEBTRACE(
"Runtime error (yacsgui): Lost connection on YACS executor");
394 if (CORBA::is_nil(_observerRef))
397 _serv->SetImpl(
this);
398 _observerRef = _serv->_this();
401 _serv->SetRemoteProc(_procRef);
402 _serv->setConversion();
404 std::list<Node*> aNodeSet =
_proc->getAllRecursiveConstituents();
405 for ( std::list<Node*>::iterator it = aNodeSet.begin(); it != aNodeSet.end(); it++ )
407 _procRef->addObserver(_observerRef, _serv->getEngineId((*it)->getNumId()) ,
"status");
408 _procRef->addObserver(_observerRef, _serv->getEngineId((*it)->getNumId()) ,
"progress");
410 _procRef->addObserver(_observerRef, _serv->getEngineId(
_proc->getNumId()) ,
"executor");
415 void GuiExecutor::setEngineRef(YACS_ORB::YACS_Gen_ptr
ref)
417 DEBTRACE(
"GuiExecutor::setEngineRef");
423 DEBTRACE(
"GuiExecutor::getErrorDetails");
426 int engineId=_serv->getEngineId(node->
getNumId());
427 return _procRef->getErrorDetails(engineId);
434 DEBTRACE(
"GuiExecutor::getErrorReport");
437 int engineId=_serv->getEngineId(node->
getNumId());
438 return _procRef->getErrorReport(engineId);
443 std::string GuiExecutor::getContainerLog()
445 DEBTRACE(
"GuiExecutor::getContainerLog");
447 if (!CORBA::is_nil(_engineRef))
449 Engines::Container_var cont= _engineRef->GetContainerRef();
450 CORBA::String_var logname = cont->logfilename();
453 std::string::size_type pos = msg.find(
":");
454 msg=msg.substr(pos+1);
461 DEBTRACE(
"GuiExecutor::getContainerLog(YACS::ENGINE::Node* node)");
465 int engineId=_serv->getEngineId(node->
getNumId());
466 CORBA::String_var logname = _procRef->getContainerLog(engineId);
468 std::string::size_type pos = msg.find(
":");
469 msg=msg.substr(pos+1);
474 void GuiExecutor::shutdownProc()
476 DEBTRACE(
"GuiExecutor::shutdownProc " << _shutdownLevel <<
"," << _isRunning);
477 checkEndOfDataflow();
479 _procRef->shutdownProc(_shutdownLevel);
484 DEBTRACE(
"GuiExecutor::setInPortValue");
489 std::string nodeName;
495 std::string msg = _procRef->setInPortValue(nodeName.c_str(), port->
getName().c_str(), value.c_str());
502 if (!yev)
return false;
505 DEBTRACE(
"<" << numid <<
"," << event <<
">");
511 if (event ==
"executor")
513 int execState = _procRef->getExecutorState();
514 list<string> nextSteps;
517 YACS_ORB::stringArray_var nstp = _procRef->getTasksToLoad();
518 for (CORBA::ULong
i=0;
i<nstp->length();
i++)
519 nextSteps.push_back(nstp[
i].in());
528 if (! _serv->_engineToGuiMap.count(numid))
530 int state = _procRef->getNodeState(numid);
531 int iGui = _serv->_engineToGuiMap[numid];
532 YASSERT(_context->_mapOfExecSubjectNode.count(iGui));
533 SubjectNode *snode = _context->_mapOfExecSubjectNode[iGui];
536 if (event ==
"progress") {
537 std::string progress = _procRef->getNodeProgress(numid);
544 list<InputPort*>::iterator iti = inports.begin();
545 for ( ; iti != inports.end(); ++iti)
547 string val = _procRef->getInPortValue(numid, (*iti)->getName().c_str());
548 DEBTRACE(
"node " << snode->
getName() <<
" inport " << (*iti)->getName()
549 <<
" value " << val);
550 YASSERT(_context->_mapOfSubjectDataPort.count(*iti));
556 list<OutputPort*>::iterator ito = outports.begin();
557 for ( ; ito != outports.end(); ++ito)
559 string val = _procRef->getOutPortValue(numid, (*ito)->getName().c_str());
560 DEBTRACE(
"node " << snode->
getName() <<
" outport " << (*ito)->getName()
561 <<
" value " << val);
562 YASSERT(_context->_mapOfSubjectDataPort.count(*ito));
574 void GuiExecutor::setBPList()
580 listOfBreakPoints.length(_breakpointList.size());
582 for (list<string>::iterator it = _breakpointList.begin(); it != _breakpointList.end(); ++it)
583 listOfBreakPoints[
i++] = (*it).c_str();
584 _procRef->setListOfBreakPoints(listOfBreakPoints);
594 std::list<Node*> aNodeSet =
_proc->getAllRecursiveConstituents();
595 for ( std::list<Node*>::iterator it = aNodeSet.begin(); it != aNodeSet.end(); it++ ){
597 numid = (*it)->getNumId();
600 SubjectNode *snode = _context->_mapOfExecSubjectNode[numid];
604 list<InputPort*>::iterator iti = inports.begin();
605 for ( ; iti != inports.end(); ++iti)
607 string val =
_proc->getInPortValue(numid, (*iti)->getName().c_str());
608 YASSERT(_context->_mapOfSubjectDataPort.count(*iti));
614 list<OutputPort*>::iterator ito = outports.begin();
615 for ( ; ito != outports.end(); ++ito)
617 string val =
_proc->getOutPortValue(numid, (*ito)->getName().c_str());
618 YASSERT(_context->_mapOfSubjectDataPort.count(*ito));
625 state =
_proc->getRootNode()->getEffectiveState();
629 if(jobState!=
"RUNNING")
void display(CORBA::Any *data)
#define YASSERT(val)
YASSERT macro is always defined, used like assert, but throw a YACS::Exception instead of abort.
Base class for all composed nodes.
std::string getChildName(const Node *node) const
std::string getName() const
Base class for all nodes.
virtual ComposedNode * getRootNode() const
virtual std::list< InputPort * > getLocalInputPorts() const =0
virtual std::list< OutputPort * > getLocalOutputPorts() const =0
const std::string & getName() const
int getNumId()
return node instance identifiant, unique for each node instance
Base class for all schema objects.
CORBA::ORB_ptr getOrb() const
void setExecValue(std::string value)
virtual std::string getName()
virtual void update(GuiEvent event, int type, Subject *son)
virtual YACS::ENGINE::Node * getNode()
virtual void update(GuiEvent event, int type, Subject *son)
virtual void setProgress(std::string newProgress)
std::pair< int, std::string > getYACSEvent() const
YACSRUNTIMESALOME_EXPORT RuntimeSALOME * getSALOMERuntime()
sequence< string > stringArray
def ref(target, callback=None)