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