PushFlowControl.cxx

Go to the documentation of this file.
00001 /*
00002  * Copyright (c) 2001-2004 MUSIC TECHNOLOGY GROUP (MTG)
00003  *                         UNIVERSITAT POMPEU FABRA
00004  *
00005  *
00006  * This program is free software; you can redistribute it and/or modify
00007  * it under the terms of the GNU General Public License as published by
00008  * the Free Software Foundation; either version 2 of the License, or
00009  * (at your option) any later version.
00010  *
00011  * This program is distributed in the hope that it will be useful,
00012  * but WITHOUT ANY WARRANTY; without even the implied warranty of
00013  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00014  * GNU General Public License for more details.
00015  *
00016  * You should have received a copy of the GNU General Public License
00017  * along with this program; if not, write to the Free Software
00018  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
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) // if it's a generator
00041                 mGenerators.push_back( &added );
00042 }
00043 
00044 void PushFlowControl::ProcessingRemovedFromNetwork( Processing & removed )
00045 {
00046         NetworkTopologyChanged();
00047 
00048         if (removed.GetNInPorts() == 0) // if it's a generator
00049                 mGenerators.remove( &removed );
00050 }
00051 
00052 void PushFlowControl::Do()
00053 {
00054         std::list< Processing* > toDo(mGenerators);
00055 
00056         while (!toDo.empty())
00057         {
00058                 // pop the next processing
00059                 Processing * next = *(toDo.begin()); // the first
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                         //std::cerr << "Can't consume "<<next->GetClassName() << std::endl;
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                         //ignore orphan inports
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 } // namespace CLAM
00100 
00101 
Generated by  doxygen 1.6.3