CLAM-Development  1.4.0
PushFlowControl.cxx
Go to the documentation of this file.
1 /*
2  * Copyright (c) 2001-2004 MUSIC TECHNOLOGY GROUP (MTG)
3  * UNIVERSITAT POMPEU FABRA
4  *
5  *
6  * This program is free software; you can redistribute it and/or modify
7  * it under the terms of the GNU General Public License as published by
8  * the Free Software Foundation; either version 2 of the License, or
9  * (at your option) any later version.
10  *
11  * This program is distributed in the hope that it will be useful,
12  * but WITHOUT ANY WARRANTY; without even the implied warranty of
13  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14  * GNU General Public License for more details.
15  *
16  * You should have received a copy of the GNU General Public License
17  * along with this program; if not, write to the Free Software
18  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
19  *
20  */
21 
22 
23 #include "PushFlowControl.hxx"
24 #include "Processing.hxx"
25 #include "OutPort.hxx"
26 #include "InPort.hxx"
27 #include "Network.hxx"
28 
29 namespace CLAM
30 {
31 
33 {
34 }
35 
37 {
39 
40  if (added.GetNInPorts() == 0) // if it's a generator
41  mGenerators.push_back( &added );
42 }
43 
45 {
47 
48  if (removed.GetNInPorts() == 0) // if it's a generator
49  mGenerators.remove( &removed );
50 }
51 
53 {
54  std::list< Processing* > toDo(mGenerators);
55 
56  while (!toDo.empty())
57  {
58  // pop the next processing
59  Processing * next = *(toDo.begin()); // the first
60  toDo.pop_front();
61 
62  if(next->CanConsumeAndProduce())
63  {
64  next->Do();
65  std::cerr << "Consume "<<next->GetClassName() << std::endl;
66  }
67  else
68  {
69  //std::cerr << "Can't consume "<<next->GetClassName() << std::endl;
70  }
71  AddNewPossibleProcessingsToDo(next, toDo);
72  }
73 }
74 
75 void PushFlowControl::AddNewPossibleProcessingsToDo(
76  Processing * producer,
77  std::list<Processing*> & toDo )
78 {
79  unsigned nOutPorts = producer->GetNOutPorts();
80  for (unsigned i=0; i<nOutPorts; i++)
81  {
82  Network::InPortsList consumers =
83  mNetwork->GetInPortsConnectedTo( producer->GetOutPort(i) );
84 
85  Network::InPortsList::iterator itInPort;
86  for (itInPort=consumers.begin(); itInPort!=consumers.end(); itInPort++)
87  {
88  InPortBase & inPort = **itInPort;
89  //ignore orphan inports
90  if (!inPort.HasProcessing()) continue;
91 
92  Processing * proc = inPort.GetProcessing();
93  if (proc->CanConsumeAndProduce())
94  toDo.push_back( proc );
95  }
96  }
97 }
98 
99 } // namespace CLAM
100 
101