31 using namespace YACS::ENGINE;
47 ret.insert(_consumer);
55 return s.find(_consumer)!=s.end();
65 map<int, OutPort *>::iterator pt;
67 for(pt=_potentialProducers.begin();pt!=_potentialProducers.end();pt++)
68 ((*pt).second)->removeInPort(_consumer,
true);
73 return (*(_potentialProducers.begin())).second->getTypeOfChannel();
78 map<int, OutPort *>::const_iterator pt;
79 for(pt=_potentialProducers.begin();pt!=_potentialProducers.end();pt++)
80 ((*pt).second)->getAllRepresented(represented);
87 bool ret=_currentProducer->addInPort(inPort);
92 for(map<int, OutPort *>::iterator iter=_potentialProducers.begin();iter!=_potentialProducers.end();iter++)
93 (*iter).second->addInPort(inPort);
100 return _currentProducer->removeInPort(inPort,forward);
103 throw Exception(
"CollectorSwOutputPort::edRemoveInputPort : internal error on link removal.");
112 DataPort(
"",master,port->edGetType()),
114 _consumer(port),_currentProducer(0)
120 DataPort(
"",master,other.edGetType()),
122 _consumer(0),_currentProducer(0)
147 string what(
"CollectorSwOutPort::addPotentialProducerForMaster : In switch node "); what+=
_node->
getName();
149 what+=
" already got out for case of label ";
160 map<int, OutPort *>::iterator result;
169 ostringstream stream; stream <<
"CollectorSwOutPort::removePotentialProducerForMaster : link from the branch whith id ";
170 stream << i <<
" not defined";
175 ostringstream stream; stream <<
"CollectorSwOutPort::removePotentialProducerForMaster : link from the branch whith id ";
176 stream << i <<
" defined but the output specified is not compatible";
185 for(map<int, OutPort *>::iterator iter=_potentialProducers.begin();iter!=_potentialProducers.end();iter++)
186 if((*iter).second==port)
188 _currentProducer=port;
189 return _potentialProducers.size()==1;
191 throw Exception(
"CollectorSwOutPort::checkManagementOfPort : unexported port");
202 (*iter).second->checkConsistency(info);
211 set<int> lackingCases;
212 for(map< int ,Node * >::const_iterator iter=((
Switch *)
_node)->_mapOfNode.begin();iter!=((
Switch *)
_node)->_mapOfNode.end();iter++)
215 lackingCases.insert((*iter).first);
217 ostringstream streamForExc;
219 <<
" the cases of switch node named " <<
_node->
getName()
220 <<
" do not define links for following cases ids :";
221 for(set<int>::iterator iter=lackingCases.begin();iter!=lackingCases.end();iter++)
228 _normalFinish(normalFinish),
229 _internalError(internalError)
236 _normalFinish(false),
282 _undispatchableNotificationNode(0)
284 for(map<int,Node *>::const_iterator iter=other.
_mapOfNode.begin();iter!=other.
_mapOfNode.end();iter++)
285 _mapOfNode[(*iter).first]=(*iter).second->clone(
this,editionOnly);
303 delete (*iter).second;
305 delete (*iter2).second;
312 return new Switch(*
this,father,editionOnly);
338 ((*iter).second)->exUpdateState();
341 ((*iter).second)->exUpdateState();
355 ostringstream stream;
356 stream <<
"Switch::init : initialization failed due to unitialized branch of id " << (*iter).first;
359 ((*iter).second)->
init(start);
374 ((*iter).second)->getReadyTasks(tasks);
379 (*iter).second->getReadyTasks(tasks);
384 throw Exception(
"Switch::getReadyTasks : internal error");
394 ret.push_back((*iter).second);
407 ret=std::max(ret,((*it).second)->getMaxLevelOfParallelism());
413 map< int , Node * >::iterator iter=_mapOfNode.begin();
414 for(;iter!=_mapOfNode.end();iter++)
415 if(node==(*iter).second)
417 edReleaseCase((*iter).first);
420 ostringstream what; what <<
"Switch::edRemoveChild : node with name " << node->getName() <<
" is not a direct child of Switch node " << _name;
440 for(map<InPort *, CollectorSwOutPort * >::const_iterator iter=_outPortsCollector.begin();iter!=_outPortsCollector.end();iter++)
441 if(name==(*iter).second->getName())
442 return (*iter).second;
443 for(vector<CollectorSwOutPort *>::const_iterator iter2=_alreadyExistingCollectors.begin();iter2!=_alreadyExistingCollectors.end();iter2++)
444 if(name==(*iter2)->getName())
451 if(name==SELECTOR_INPUTPORT_NAME)
458 if(name==DEFAULT_NODE_NAME)
460 map< int , Node * >::const_iterator iter=_mapOfNode.find(ID_FOR_DEFAULT_NODE);
461 if(iter!=_mapOfNode.end())
462 return (
Node *)((*iter).second);
465 string what(
"Switch::getChildByShortName : no default node defined for switch of name "); what+=getName();
469 for(map< int , Node * >::const_iterator iter=_mapOfNode.begin();iter!=_mapOfNode.end();iter++)
471 if(name==((*iter).second)->getQualifiedName())
472 return (*iter).second;
474 string what(
"node "); what+= name ; what+=
" is not a child of node switch "; what += getName();
490 map< int , Node * >::iterator iter=_mapOfNode.find(caseId);
491 if(iter==_mapOfNode.end())
493 string what(
"Switch::edReleaseCase : the case # "); what+=getRepresentationOfCase(caseId); what+=
" is not set yet.";
500 _mapOfNode.erase(iter);
523 throw Exception(
"Switch::edSetNode : null node cannot be set as a case in switch node");
525 throw Exception(
"Switch::edSetNode : node already held by another father");
526 checkNoCrossHierachyWith(node);
528 map< int , Node * >::iterator iter=_mapOfNode.find(caseId);
529 if(iter==_mapOfNode.end())
531 _mapOfNode[caseId]=node;
537 if(node!=(*iter).second)
555 std::map< int , Node * >::iterator iter=
_mapOfNode.find(oldCase);
559 throw Exception(
"Switch::edChangeCase : case does not exist");
565 throw Exception(
"Switch::edChangeCase : new case exists");
576 map<int, Node*>::const_iterator it =
_mapOfNode.begin();
578 if ((*it).first > aCase)
590 list<ProgressWeight>
ret;
594 for(list<Node *>::const_iterator iter=setOfNode.begin();iter!=setOfNode.end();iter++)
597 ret=(*iter)->getProgressWeight();
602 for(list<Node *>::const_iterator iter=setOfNode.begin();iter!=setOfNode.end();iter++)
604 list<ProgressWeight> myCurrentSet=(*iter)->getProgressWeight();
605 ret.insert(ret.end(),myCurrentSet.begin(),myCurrentSet.end());
613 int aCase = getMaxCase() + 1;
615 bool ret = edSetNode(aCase, node);
630 for(set<OutPort *>::iterator iter3=temp2.begin();iter3!=temp2.end();iter3++)
641 map<InPort *, CollectorSwOutPort * >::const_iterator iter=
_outPortsCollector.find(end);
644 set<OutPort *> represented;
645 (*iter).second->getAllRepresented(represented);
646 list<OutPort *> others;
647 for(list<OutPort *>::const_iterator iter2=starts.begin();iter2!=starts.end();iter2++)
648 if(represented.find(*iter2)==represented.end())
649 others.push_back(*iter2);
660 std::map <
ComposedNode *, std::list < OutPort * > >& fw,
661 std::vector<OutPort *>& fwCross,
665 throw Exception(
"Switch::checkControlDependancy : a link was dectected between 2 cases of a switch. Impossible !");
670 throw Exception(
"Switch::checkNoCyclePassingThrough : uncorrect control flow link relative to switch");
676 throw Exception(
"Switch::checkLinkPossibility : A link between 2 different cases of a same Switch requested -> Impossible");
681 map<InPort *, CollectorSwOutPort * >::iterator result=
_outPortsCollector.find(finalTarget);
684 newCollector=(*result).second;
688 newCollector->
edSetType((port.first)->edGetType());
692 port.second=newCollector;
693 port.first=newCollector;
696 void Switch::getDelegateOf(std::pair<OutPort *, OutPort *>& port,
InPort *finalTarget,
const std::list<ComposedNode *>& pointsOfView)
throw(
YACS::Exception)
698 map<InPort *, CollectorSwOutPort * >::iterator iter=_outPortsCollector.find(finalTarget);
699 if(iter==_outPortsCollector.end())
701 string what(
"Switch::getDelegateOf : not exported OuputPort with name "); what+=(port.first)->getName(); what+=
" for target inport of name ";
702 what+=finalTarget->getName();
705 ((*iter).second)->checkManagementOfPort(port.first);
706 port.second=(*iter).second;
707 port.first=(*iter).second;
713 portDwn->getAllRepresented(repr);
720 _outPortsCollector.erase(finalTarget);
725 int Switch::getNbOfCases()
const
727 return _mapOfNode.size();
730 int Switch::getRankOfNode(
Node *node)
const
732 Node *directSon=isInMyDescendance(node);
733 for(map< int , Node * >::const_iterator iter=_mapOfNode.begin();iter!=_mapOfNode.end();iter++)
734 if((*iter).second==directSon)
735 return (*iter).first;
736 throw Exception(
"Switch::getRankOfNode : node not in switch");
739 string Switch::getRepresentationOfCase(
int i)
741 if(i!=ID_FOR_DEFAULT_NODE)
743 ostringstream stream;
748 return DEFAULT_NODE_NAME;
770 return Node::getEffectiveState();
773 void Switch::writeDot(std::ostream &os)
const
775 os <<
" subgraph cluster_" << getId() <<
" {\n" ;
776 for(map<int,Node*>::const_iterator iter=_mapOfNode.begin();iter!=_mapOfNode.end();iter++)
778 Node*
n=(*iter).second;
780 os << getId() <<
" -> " << n->
getId() <<
";\n";
783 os << getId() <<
"[fillcolor=\"" ;
785 os << getColorState(state);
786 os <<
"\" label=\"" <<
"Switch:" ;
787 os << getQualifiedName() <<
"\"];\n";
790 std::string Switch::getMyQualifiedName(
const Node *directSon)
const
792 string id=getCaseId(directSon);
800 map<int, Node*>::const_iterator iter;
801 for (iter = _mapOfNode.begin(); iter != _mapOfNode.end(); iter++)
802 if (iter->second == node)
805 if (iter->first == Switch::ID_FOR_DEFAULT_NODE)
806 a << DEFAULT_NODE_NAME << sep;
807 else if (iter->first <0)
808 a <<
"m" << -iter->first << sep;
809 else a <<
"p" << iter->first << sep;
812 string what(
"node "); what+= node->getName() ; what+=
" is not a child of node "; what += getName();