root/trunk/libffado/src/libstreaming/generic/PortManager.cpp

Revision 742, 5.7 kB (checked in by ppalmers, 13 years ago)

- Remove some obsolete support files and dirs

- Clean up the license statements in the source files. Everything is

GPL version 3 now.

- Add license and copyright notices to scons scripts

- Clean up some other text files

Line 
1 /*
2  * Copyright (C) 2005-2007 by Pieter Palmers
3  *
4  * This file is part of FFADO
5  * FFADO = Free Firewire (pro-)audio drivers for linux
6  *
7  * FFADO is based upon FreeBoB.
8  *
9  * This program is free software: you can redistribute it and/or modify
10  * it under the terms of the GNU General Public License as published by
11  * the Free Software Foundation, either version 3 of the License, or
12  * (at your option) any later version.
13  *
14  * This program is distributed in the hope that it will be useful,
15  * but WITHOUT ANY WARRANTY; without even the implied warranty of
16  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
17  * GNU General Public License for more details.
18  *
19  * You should have received a copy of the GNU General Public License
20  * along with this program.  If not, see <http://www.gnu.org/licenses/>.
21  *
22  */
23
24 #include "PortManager.h"
25 #include "Port.h"
26
27 #include <assert.h>
28
29 #include <iostream>
30 #include <sstream>
31
32
33 namespace Streaming {
34
35 IMPL_DEBUG_MODULE( PortManager, PortManager, DEBUG_LEVEL_NORMAL );
36
37 PortManager::PortManager() {
38
39 }
40
41 PortManager::~PortManager() {
42 //     deleteAllPorts();
43 }
44
45 // bool PortManager::setPortBuffersize(unsigned int newsize) {
46 //     debugOutput( DEBUG_LEVEL_VERBOSE, "setting port buffer size to %d\n",newsize);
47 //
48 //
49 //     for ( PortVectorIterator it = m_Ports.begin();
50 //       it != m_Ports.end();
51 //       ++it )
52 //     {
53 //         if(!(*it)->setBufferSize(newsize)) {
54 //             debugFatal("Could not set buffer size for port %s\n",(*it)->getName().c_str());
55 //             return false;
56 //         }
57 //     }
58 //
59 //     return true; //not found
60 //
61 // }
62
63 bool PortManager::makeNameUnique(Port *port)
64 {
65     bool done=false;
66     int idx=0;
67     std::string portname_orig=port->getName();
68    
69     while(!done && idx<10000) {
70         bool is_unique=true;
71        
72         for ( PortVectorIterator it = m_Ports.begin();
73         it != m_Ports.end();
74         ++it )
75         {
76             is_unique &= !((*it)->getName() == port->getName());
77         }
78        
79         if (is_unique) {
80             done=true;
81         } else {
82             std::ostringstream portname;
83             portname << portname_orig << idx++;
84            
85             port->setName(portname.str());
86         }
87     }
88    
89     if(idx<10000) return true;
90     else return false;
91 }
92
93 /**
94  *
95  * @param port
96  * @return
97  */
98 bool PortManager::addPort(Port *port)
99 {
100     assert(port);
101
102     debugOutput( DEBUG_LEVEL_VERBOSE, "Adding port %s, type: %d, dir: %d, dtype: %d\n",
103         port->getName().c_str(), port->getPortType(), port->getDirection(), port->getDataType());
104    
105     if (makeNameUnique(port)) {
106         m_Ports.push_back(port);
107         return true;
108     } else {
109         return false;
110     }
111 }
112
113 bool PortManager::deletePort(Port *port)
114 {
115     assert(port);
116     debugOutput( DEBUG_LEVEL_VERBOSE, "deleting port %s\n",port->getName().c_str());
117
118     for ( PortVectorIterator it = m_Ports.begin();
119       it != m_Ports.end();
120       ++it )
121     {
122         if(*it == port) {
123             m_Ports.erase(it);
124 //             delete *it;
125             return true;
126         }
127     }
128
129     debugOutput( DEBUG_LEVEL_VERBOSE, "port %s not found \n",port->getName().c_str());
130
131     return false; //not found
132
133 }
134
135 void PortManager::deleteAllPorts()
136 {
137     debugOutput( DEBUG_LEVEL_VERBOSE, "deleting all ports\n");
138
139     for ( PortVectorIterator it = m_Ports.begin();
140       it != m_Ports.end();
141       ++it )
142     {
143         m_Ports.erase(it);
144 //         delete *it;
145     }
146
147     return;
148
149 }
150
151 int PortManager::getPortCount(enum Port::E_PortType type) {
152     int count=0;
153
154     for ( PortVectorIterator it = m_Ports.begin();
155       it != m_Ports.end();
156       ++it )
157     {
158         if ( (*it)->getPortType() == type ) {
159             count++;
160         }
161     }
162     return count;
163 }
164
165 int PortManager::getPortCount() {
166     int count=0;
167
168     count+=m_Ports.size();
169
170     return count;
171 }
172
173 Port * PortManager::getPortAtIdx(unsigned int index) {
174
175     return m_Ports.at(index);
176
177 }
178
179 void PortManager::setVerboseLevel(int i) {
180
181     setDebugLevel(i);
182
183     for ( PortVectorIterator it = m_Ports.begin();
184       it != m_Ports.end();
185       ++it )
186     {
187         (*it)->setVerboseLevel(i);
188     }
189
190 }
191
192
193 bool PortManager::resetPorts() {
194     debugOutput( DEBUG_LEVEL_VERBOSE, "reset ports\n");
195
196     for ( PortVectorIterator it = m_Ports.begin();
197       it != m_Ports.end();
198       ++it )
199     {
200         if(!(*it)->reset()) {
201             debugFatal("Could not reset port %s",(*it)->getName().c_str());
202             return false;
203         }
204     }
205     return true;
206 }
207
208 bool PortManager::initPorts() {
209     debugOutput( DEBUG_LEVEL_VERBOSE, "init ports\n");
210
211     for ( PortVectorIterator it = m_Ports.begin();
212       it != m_Ports.end();
213       ++it )
214     {
215         if(!(*it)->init()) {
216             debugFatal("Could not init port %s",(*it)->getName().c_str());
217             return false;
218         }
219     }
220     return true;
221 }
222
223 bool PortManager::preparePorts() {
224     debugOutput( DEBUG_LEVEL_VERBOSE, "preparing ports\n");
225
226     // clear the cache lists
227     m_PeriodPorts.clear();
228     m_PacketPorts.clear();
229
230     for ( PortVectorIterator it = m_Ports.begin();
231       it != m_Ports.end();
232       ++it )
233     {
234         if(!(*it)->prepare()) {
235             debugFatal("Could not prepare port %s",(*it)->getName().c_str());
236             return false;
237         }
238
239         // now prepare the cache lists
240         switch((*it)->getSignalType()) {
241             case Port::E_PacketSignalled:
242                 m_PacketPorts.push_back(*it);
243                 break;
244             case Port::E_PeriodSignalled:
245                 m_PeriodPorts.push_back(*it);
246                 break;
247             default:
248                 debugWarning("%s has unsupported port type\n",
249                              (*it)->getName().c_str());
250             break;
251         }
252     }
253     return true;
254 }
255
256 }
Note: See TracBrowser for help on using the browser.