PushFlowControl.cxx
Go to the documentation of this file.00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023 #include "PushFlowControl.hxx"
00024 #include "Processing.hxx"
00025 #include "OutPort.hxx"
00026 #include "InPort.hxx"
00027 #include "Network.hxx"
00028
00029 namespace CLAM
00030 {
00031
00032 PushFlowControl::PushFlowControl()
00033 {
00034 }
00035
00036 void PushFlowControl::ProcessingAddedToNetwork( Processing & added )
00037 {
00038 NetworkTopologyChanged();
00039
00040 if (added.GetNInPorts() == 0)
00041 mGenerators.push_back( &added );
00042 }
00043
00044 void PushFlowControl::ProcessingRemovedFromNetwork( Processing & removed )
00045 {
00046 NetworkTopologyChanged();
00047
00048 if (removed.GetNInPorts() == 0)
00049 mGenerators.remove( &removed );
00050 }
00051
00052 void PushFlowControl::Do()
00053 {
00054 std::list< Processing* > toDo(mGenerators);
00055
00056 while (!toDo.empty())
00057 {
00058
00059 Processing * next = *(toDo.begin());
00060 toDo.pop_front();
00061
00062 if(next->CanConsumeAndProduce())
00063 {
00064 next->Do();
00065 std::cerr << "Consume "<<next->GetClassName() << std::endl;
00066 }
00067 else
00068 {
00069
00070 }
00071 AddNewPossibleProcessingsToDo(next, toDo);
00072 }
00073 }
00074
00075 void PushFlowControl::AddNewPossibleProcessingsToDo(
00076 Processing * producer,
00077 std::list<Processing*> & toDo )
00078 {
00079 unsigned nOutPorts = producer->GetNOutPorts();
00080 for (unsigned i=0; i<nOutPorts; i++)
00081 {
00082 Network::InPortsList consumers =
00083 mNetwork->GetInPortsConnectedTo( producer->GetOutPort(i) );
00084
00085 Network::InPortsList::iterator itInPort;
00086 for (itInPort=consumers.begin(); itInPort!=consumers.end(); itInPort++)
00087 {
00088 InPortBase & inPort = **itInPort;
00089
00090 if (!inPort.HasProcessing()) continue;
00091
00092 Processing * proc = inPort.GetProcessing();
00093 if (proc->CanConsumeAndProduce())
00094 toDo.push_back( proc );
00095 }
00096 }
00097 }
00098
00099 }
00100
00101