37 using namespace YACS::ENGINE;
39 const char DynParaLoop::NAME_OF_SPLITTED_SEQ_OUT[] =
"evalSamples";
40 const char DynParaLoop::OLD_NAME_OF_SPLITTED_SEQ_OUT[] =
"SmplPrt";
42 const char DynParaLoop::NAME_OF_NUMBER_OF_BRANCHES[]=
"nbBranches";
44 DynParaLoop::DynParaLoop(
const std::string& name,
TypeCode *typeOfDataSplitted)
45 :
ComposedNode(name),_node(0),_initNode(0),_finalizeNode(0),_nbOfEltConsumed(0),
46 _nbOfBranches(NAME_OF_NUMBER_OF_BRANCHES,this,
Runtime::_tc_int),
47 _splittedPort(NAME_OF_SPLITTED_SEQ_OUT,this,typeOfDataSplitted),_initializingCounter(0),_unfinishedCounter(0),_failedCounter(0)
59 :
ComposedNode(other,father), _nbOfBranches(other._nbOfBranches,this),
60 _splittedPort(other._splittedPort,this), _node(0), _initNode(0), _finalizeNode(0),
61 _nbOfEltConsumed(0),_initializingCounter(0),_unfinishedCounter(0),_failedCounter(0)
70 set<InPort *> endsOfLinksToReproduce=startOfLinksToReproduce.
edSetInPort();
71 for(set<InPort *>::iterator iter=endsOfLinksToReproduce.begin();iter!=endsOfLinksToReproduce.end();iter++)
83 if (node == NULL || nodeToReplace == node)
86 throw Exception(
string(
"Can't set node: node ") + node->
getName() +
" is not orphan.");
89 " has the same name than exec node already in " +
_name +
".");
92 " has the same name than init node already in " +
_name +
".");
95 " has the same name than finalize node already in " +
_name +
".");
111 string what(
"DynParaLoop::init : no node specified for ForEachLoop with name "); what +=
_name;
144 return edAddLink(start,end);
201 if (name == NAME_OF_SPLITTED_SEQ_OUT || name == OLD_NAME_OF_SPLITTED_SEQ_OUT)
202 return (
OutPort *)&_splittedPort;
209 if (name == NAME_OF_SPLITTED_SEQ_OUT || name == OLD_NAME_OF_SPLITTED_SEQ_OUT)
253 if(node==_finalizeNode)
260 return edSetNode(DISOWNnode);
267 ret.push_back(
_node);
284 if(name==NAME_OF_NUMBER_OF_BRANCHES)
299 throw Exception(
"ForEachLoop::getNumberOfBranches : No branches created dynamically ! - ForEachLoop needs to run or to be runned to call getNumberOfBranches");
306 if (_node && name == _node->getName())
308 if (_initNode && name == _initNode->getName())
310 if (_finalizeNode && name == _finalizeNode->getName())
311 return _finalizeNode;
312 std::string what(
"node "); what+= name ; what+=
" is not a child of DynParaLoop node "; what += getName();
318 if(
id>=getNumberOfBranchesCreatedDyn())
319 throw Exception(
"ForEachLoop::getChildByNameExec : invalid id - too large compared with dynamically created branches.");
320 if (_node && name == _node->getName())
321 return _execNodes[
id];
322 if (_initNode && name == _initNode->getName())
323 return _execInitNodes[
id];
324 if (_finalizeNode && name == _finalizeNode->getName())
325 return _execFinalizeNodes[
id];
326 std::string what(
"node "); what+= name ; what+=
" is not a child of DynParaLoop node "; what += getName();
332 vector<Node *>::iterator iter;
354 for(list<InPort *>::iterator iter2=temp.begin();iter2!=temp.end();iter2++)
356 if ((*iter2)->edSetOutPort().size() == 1 && *(*iter2)->edSetOutPort().begin() == NULL)
358 portsToSetVals.insert(*iter2);
364 for(list<InputPort *>::iterator iter = localPorts.begin() ; iter != localPorts.end() ; iter++)
365 portsToSetVals.erase(*iter);
366 for(set< InPort * >::iterator iter=portsToSetVals.begin();iter!=portsToSetVals.end();iter++)
369 void *val=curPortCasted->
get();
373 portToSet->
put((
const void *)val);
382 bool isDispatched =
false;
384 for(set<InPort *>::iterator iter=inPrtLkdWthSplttdPrt.begin();iter!=inPrtLkdWthSplttdPrt.end();iter++)
389 if(portOnGivenBranch)
395 traducer->
put((
const void *)val);
397 if(traducer!=portOnGivenBranch)
411 vector<Node *>::iterator iter;
447 throw Exception(
"DynParaLoop::buildDelegateOf : A link with datastream end inside DynParaLoop is not possible");
452 std::string linkName(
"(");
453 linkName += port.first->getName()+
" to "+finalTarget->
getName()+
")";
456 throw Exception(std::string(
"Illegal link within a parallel loop: \
457 a link starting from the init node can't leave the scope of the loop.")
462 throw Exception(std::string(
"Illegal link within a parallel loop: \
463 an output port of the finalize node can't be linked.")
467 throw Exception(std::string(
"Illegal link within a parallel loop: \
468 the 'evalSamples' port must be linked within the scope of the loop.")
474 const char what[]=
"DynParaLoop::checkCFLinks : internal error.";
485 else if(alreadyFed==
FED_ST)
503 std::vector<OutPort *>& fwCross,
514 Node * startNode = isInMyDescendance(start->getNode());
515 Node * endNode = isInMyDescendance(end->getNode());
516 std::string linkName(
"(");
517 linkName += start->getName()+
" to "+end->getName()+
")";
519 if(start == &_splittedPort && endNode != _node)
520 throw Exception(std::string(
"Illegal link within a parallel loop: \
521 the 'evalSamples' port can only be connected to the working node of the loop.")
524 if(_finalizeNode && _finalizeNode == startNode)
525 throw Exception(std::string(
"Illegal link within a parallel loop: \
526 the finalize node can't be the origin of a link.")
529 if(_initNode && _node == startNode && _initNode == endNode)
530 throw Exception(std::string(
"Illegal link within a parallel loop: \
531 can't make a link from the working node to the init node.")
534 if(_finalizeNode && _node == startNode && _finalizeNode == endNode)
535 throw Exception(std::string(
"Illegal link within a parallel loop: \
536 can't make a link from the working node to the finalize node.")
549 string portName, nodeName;
556 return _execNodes[branchNb]->getInputPort(portName);
569 DEBTRACE(
"DynParaLoop::checkBasicConsistency");
572 throw Exception(
"For a dynamic loop, internal node is mandatory");
583 std::string report=
"<error node= " +
getName();
584 switch(effectiveState)
587 report=report+
" state= INVALID";
590 report=report+
" state= ERROR";
593 report=report+
" state= FAILED";
598 report=report +
">\n" ;
606 for(list<Node *>::iterator iter=constituents.begin(); iter!=constituents.end(); iter++)
608 std::string rep=(*iter)->getErrorReport();
611 report=report+rep+
"\n";
620 std::string rep=(*iter)->getErrorReport();
623 report=report+rep+
"\n";
628 std::string rep=(*iter)->getErrorReport();
631 report=report+rep+
"\n";
636 std::string rep=(*iter)->getErrorReport();
639 report=report+rep+
"\n";
644 report=report+
"</error>";
651 Node * origNode = NULL;
679 if (compNode && compNodeExe)
682 list<Node *>::iterator iter=aChldn.begin();
683 for(;iter!=aChldn.end();iter++)
686 node->
setState((*iter)->getState());
701 DEBTRACE(
"DynParaLoop::updateStateOnFailedEventFrom " << node->
getName());
731 DEBTRACE(
"Begin cloneAndPlaceNodesCoherently")
732 vector<Node *> clones;
734 vector<list<ElementaryNode *> > origElemNodeList;
735 for (
int i=0 ;
i<origNodes.size() ;
i++)
738 if (origNodes[
i] == NULL)
740 DEBTRACE(
"Cloning node " <<
i <<
", NULL" )
741 clones.push_back(NULL);
742 origElemNodeList.push_back(list<ElementaryNode *>());
747 clones.push_back(origNodes[
i]->
simpleClone(
this,
false));
748 list<ElementaryNode *> tasks = origNodes[
i]->getRecursiveConstituents();
749 origElemNodeList.push_back(tasks);
750 for (list< ElementaryNode *>::iterator iter=tasks.begin() ; iter!=tasks.end() ; iter++)
751 treeToDup.
appendTask(*iter, (*iter)->getDynClonerIfExists(
this));
760 std::vector< std::pair<OutPort *, InPort *> >::const_iterator it;
761 for(it=outLinks.begin(); it!=outLinks.end(); it++)
763 OutPort *startPort = it->first;
764 InPort *endPort = it->second;
766 if(destNode ==
_node)
779 for(vector<Container *>::iterator iterCt=conts.begin();iterCt!=conts.end();iterCt++)
781 DEBTRACE(
"Container " << ((*iterCt)?(*iterCt)->getName():
"NULL"))
785 contCloned=(*iterCt)->
clone();
788 for(vector<ComponentInstance *>::iterator iterCp=comps.begin();iterCp!=comps.end();iterCp++)
790 DEBTRACE(
"Component " << (*iterCp)->getCompoName())
793 DEBTRACE(
"Assign container " << (*iterCp)->getCompoName())
795 for(vector<Task *>::iterator iterT=tasks.begin();iterT!=tasks.end();iterT++)
800 for (i=0 ; i<origNodes.size() ; i++)
801 if (origNodes[i] != NULL)
803 DEBTRACE(
"Looking in original node " << i)
804 list<ElementaryNode *>::iterator res=find(origElemNodeList[i].begin(),
805 origElemNodeList[i].end(),
807 if (res != origElemNodeList[i].end()) {
814 DEBTRACE(
"Found task in node " << i)
816 if (origNodes[i] == origElemNode)
820 string childName = ((
ComposedNode *)origNodes[i])->getChildName(origElemNode);
823 DEBTRACE(
"Assign component: " << (*iterCp)->getCompoName() <<
"," << nodeC->
getName())
831 for(vector<Task *>::iterator iterT=tasks.begin();iterT!=tasks.end();iterT++)
836 for (i=0 ; i<origNodes.size() ; i++)
837 if (origNodes[i] != NULL)
839 DEBTRACE(
"Looking in original node " << i)
840 list<ElementaryNode *>::iterator res=find(origElemNodeList[i].begin(),
841 origElemNodeList[i].end(),
843 if (res != origElemNodeList[i].end())
850 DEBTRACE(
"Found task in node " << i)
852 if (origNodes[i] == origElemNode)
858 string childName = ((
ComposedNode *)origNodes[i])->getChildName(origElemNode);
870 DEBTRACE(
"End cloneAndPlaceNodesCoherently")
904 std::vector<Node *>::iterator iter;
906 (*iter)->shutdown(level);
908 (*iter)->shutdown(level);
910 (*iter)->shutdown(level);