root/trunk/libffado/src/bebob/bebob_functionblock.cpp

Revision 740, 12.7 kB (checked in by ppalmers, 13 years ago)

fix propagation of debug/verbose level

Line 
1 /*
2  * Copyright (C) 2005-2007 by Daniel Wagner
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 library is free software; you can redistribute it and/or
10  * modify it under the terms of the GNU Lesser General Public
11  * License version 2.1, as published by the Free Software Foundation;
12  *
13  * This library is distributed in the hope that it will be useful,
14  * but WITHOUT ANY WARRANTY; without even the implied warranty of
15  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
16  * Lesser General Public License for more details.
17  *
18  * You should have received a copy of the GNU Lesser General Public
19  * License along with this library; if not, write to the Free Software
20  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
21  * MA 02110-1301 USA
22  */
23
24 #include "bebob/bebob_functionblock.h"
25 #include "bebob/bebob_avdevice_subunit.h"
26 #include "bebob/bebob_avdevice.h"
27 #include "libieee1394/configrom.h"
28
29 using namespace AVC;
30
31 namespace BeBoB {
32
33 IMPL_DEBUG_MODULE( FunctionBlock, FunctionBlock, DEBUG_LEVEL_NORMAL );
34
35 FunctionBlock::FunctionBlock(
36     AVC::Subunit& subunit,
37     function_block_type_t type,
38     function_block_type_t subtype,
39     function_block_id_t id,
40     ESpecialPurpose purpose,
41     no_of_input_plugs_t nrOfInputPlugs,
42     no_of_output_plugs_t nrOfOutputPlugs,
43     int verbose )
44     : m_subunit( &subunit )
45     , m_type( type )
46     , m_subtype( subtype )
47     , m_id( id )
48     , m_purpose( purpose )
49     , m_nrOfInputPlugs( nrOfInputPlugs )
50     , m_nrOfOutputPlugs( nrOfOutputPlugs )
51     , m_verbose( verbose )
52 {
53     setDebugLevel( verbose );
54 }
55
56 FunctionBlock::FunctionBlock( const FunctionBlock& rhs )
57     : m_subunit( rhs.m_subunit )
58     , m_type( rhs.m_type )
59     , m_subtype( rhs.m_subtype )
60     , m_id( rhs.m_id )
61     , m_purpose( rhs.m_purpose )
62     , m_nrOfInputPlugs( rhs.m_nrOfInputPlugs )
63     , m_nrOfOutputPlugs( rhs.m_nrOfOutputPlugs )
64     , m_verbose( rhs.m_verbose )
65 {
66 }
67
68 FunctionBlock::FunctionBlock()
69 {
70 }
71
72 FunctionBlock::~FunctionBlock()
73 {
74     for ( PlugVector::iterator it = m_plugs.begin();
75           it != m_plugs.end();
76           ++it )
77     {
78         delete *it;
79     }
80
81 }
82
83 bool
84 FunctionBlock::discover()
85 {
86     debugOutput( DEBUG_LEVEL_NORMAL,
87                  "discover function block %s (nr of input plugs = %d, "
88                  "nr of output plugs = %d)\n",
89                  getName(),
90                  m_nrOfInputPlugs,
91                  m_nrOfOutputPlugs );
92
93     if ( !discoverPlugs( AVC::Plug::eAPD_Input, m_nrOfInputPlugs ) ) {
94         debugError( "Could not discover input plug for '%s'\n",
95                     getName() );
96         return false;
97     }
98
99     if ( !discoverPlugs( AVC::Plug::eAPD_Output, m_nrOfOutputPlugs ) ) {
100         debugError( "Could not discover output plugs for '%s'\n",
101                     getName() );
102         return false;
103     }
104
105     return true;
106 }
107
108 bool
109 FunctionBlock::discoverPlugs( AVC::Plug::EPlugDirection plugDirection,
110                                      plug_id_t plugMaxId )
111 {
112     for ( int plugId = 0; plugId < plugMaxId; ++plugId ) {
113         AVC::Plug* plug = new BeBoB::Plug(
114             &m_subunit->getUnit(),
115             m_subunit,
116             m_type,
117             m_id,
118             AVC::Plug::eAPA_FunctionBlockPlug,
119             plugDirection,
120             plugId);
121
122         if ( !plug || !plug->discover() ) {
123             debugError( "plug discovering failed for plug %d\n",
124                         plugId );
125             delete plug;
126             return false;
127         }
128
129         debugOutput( DEBUG_LEVEL_NORMAL, "plug '%s' found\n",
130                      plug->getName() );
131         m_plugs.push_back( plug );
132     }
133
134     return true;
135 }
136
137 bool
138 FunctionBlock::discoverConnections()
139 {
140     debugOutput( DEBUG_LEVEL_VERBOSE,
141                  "discover connections function block %s\n",
142                  getName() );
143
144     for ( PlugVector::iterator it = m_plugs.begin();
145           it != m_plugs.end();
146           ++it )
147     {
148         BeBoB::Plug* plug = dynamic_cast<BeBoB::Plug*>(*it);
149         if(!plug) {
150             debugError("BUG: not a bebob plug\n");
151             return false;
152         }
153         if ( !plug->discoverConnections() ) {
154             debugError( "Could not discover plug connections\n" );
155             return false;
156         }
157     }
158     return true;
159 }
160
161 bool
162 FunctionBlock::serialize( Glib::ustring basePath, Util::IOSerialize& ser ) const
163 {
164     bool result;
165
166     result  = ser.write( basePath + "m_type", m_type );
167     result &= ser.write( basePath + "m_subtype", m_subtype );
168     result &= ser.write( basePath + "m_id", m_id );
169     result &= ser.write( basePath + "m_purpose", m_purpose );
170     result &= ser.write( basePath + "m_nrOfInputPlugs", m_nrOfInputPlugs );
171     result &= ser.write( basePath + "m_nrOfOutputPlugs", m_nrOfOutputPlugs );
172     result &= serializePlugVector( basePath + "m_plugs", ser, m_plugs );
173
174     return result;
175 }
176
177 FunctionBlock*
178 FunctionBlock::deserialize( Glib::ustring basePath,
179                             Util::IODeserialize& deser,
180                             AVC::Unit& unit,
181                             AVC::Subunit& subunit )
182 {
183     bool result;
184     function_block_type_t type;
185     function_block_type_t subtype;
186     FunctionBlock* pFB = 0;
187
188     result  = deser.read( basePath + "m_type", type );
189     result &= deser.read( basePath + "m_subtype", subtype );
190     if ( !result ) {
191         return 0;
192     }
193
194     switch ( type ) {
195     case ExtendedSubunitInfoCmd::eFBT_AudioSubunitSelector:
196         pFB = new FunctionBlockSelector;
197         break;
198     case ExtendedSubunitInfoCmd::eFBT_AudioSubunitFeature:
199         pFB = new FunctionBlockFeature;
200         break;
201     case ExtendedSubunitInfoCmd::eFBT_AudioSubunitProcessing:
202         if ( subtype == ExtendedSubunitInfoCmd::ePT_EnhancedMixer ) {
203             pFB = new FunctionBlockEnhancedMixer;
204         } else {
205             pFB = new FunctionBlockProcessing;
206         }
207         break;
208     case ExtendedSubunitInfoCmd::eFBT_AudioSubunitCodec:
209         pFB = new FunctionBlockCodec;
210         break;
211     default:
212         pFB = 0;
213     }
214
215     if ( !pFB ) {
216         return 0;
217     }
218
219     pFB->m_subunit = &subunit;
220     pFB->m_type = type;
221     pFB->m_subtype = subtype;
222
223     result &= deser.read( basePath + "m_id", pFB->m_id );
224     result &= deser.read( basePath + "m_purpose", pFB->m_purpose );
225     result &= deser.read( basePath + "m_nrOfInputPlugs", pFB->m_nrOfInputPlugs );
226     result &= deser.read( basePath + "m_nrOfOutputPlugs", pFB->m_nrOfOutputPlugs );
227     result &= deserializePlugVector( basePath + "m_plugs", deser,
228                                      unit.getPlugManager(), pFB->m_plugs );
229
230     return 0;
231 }
232
233 ///////////////////////
234
235 FunctionBlockSelector::FunctionBlockSelector(
236     AVC::Subunit& subunit,
237     function_block_id_t id,
238     ESpecialPurpose purpose,
239     no_of_input_plugs_t nrOfInputPlugs,
240     no_of_output_plugs_t nrOfOutputPlugs,
241     int verbose )
242     : FunctionBlock( subunit,
243                      eFBT_AudioSubunitSelector,
244                      0,
245                      id,
246                      purpose,
247                      nrOfInputPlugs,
248                      nrOfOutputPlugs,
249                      verbose )
250 {
251 }
252
253 FunctionBlockSelector::FunctionBlockSelector(
254     const FunctionBlockSelector& rhs )
255     : FunctionBlock( rhs )
256 {
257 }
258
259 FunctionBlockSelector::FunctionBlockSelector()
260     : FunctionBlock()
261 {
262 }
263
264 FunctionBlockSelector::~FunctionBlockSelector()
265 {
266 }
267
268 const char*
269 FunctionBlockSelector::getName()
270 {
271     return "Selector";
272 }
273
274 bool
275 FunctionBlockSelector::serializeChild( Glib::ustring basePath,
276                                               Util::IOSerialize& ser ) const
277 {
278     return true;
279 }
280
281 bool
282 FunctionBlockSelector::deserializeChild( Glib::ustring basePath,
283                                                 Util::IODeserialize& deser,
284                                                 AvDevice& unit )
285 {
286     return true;
287 }
288
289 ///////////////////////
290
291 FunctionBlockFeature::FunctionBlockFeature(
292     AVC::Subunit& subunit,
293     function_block_id_t id,
294     ESpecialPurpose purpose,
295     no_of_input_plugs_t nrOfInputPlugs,
296     no_of_output_plugs_t nrOfOutputPlugs,
297     int verbose )
298     : FunctionBlock( subunit,
299                      eFBT_AudioSubunitFeature,
300                      0,
301                      id,
302                      purpose,
303                      nrOfInputPlugs,
304                      nrOfOutputPlugs,
305                      verbose )
306 {
307 }
308
309 FunctionBlockFeature::FunctionBlockFeature(
310     const FunctionBlockFeature& rhs )
311     : FunctionBlock( rhs )
312 {
313 }
314
315 FunctionBlockFeature::FunctionBlockFeature()
316     : FunctionBlock()
317 {
318 }
319
320 FunctionBlockFeature::~FunctionBlockFeature()
321 {
322 }
323
324 const char*
325 FunctionBlockFeature::getName()
326 {
327     return "Feature";
328 }
329
330 bool
331 FunctionBlockFeature::serializeChild( Glib::ustring basePath,
332                                              Util::IOSerialize& ser ) const
333 {
334     return true;
335 }
336
337 bool
338 FunctionBlockFeature::deserializeChild( Glib::ustring basePath,
339                                                Util::IODeserialize& deser,
340                                                AvDevice& unit )
341 {
342     return true;
343 }
344
345 ///////////////////////
346
347 FunctionBlockEnhancedMixer::FunctionBlockEnhancedMixer(
348     AVC::Subunit& subunit,
349     function_block_id_t id,
350     ESpecialPurpose purpose,
351     no_of_input_plugs_t nrOfInputPlugs,
352     no_of_output_plugs_t nrOfOutputPlugs,
353     int verbose )
354     : FunctionBlock( subunit,
355                      eFBT_AudioSubunitProcessing,
356                      ExtendedSubunitInfoCmd::ePT_EnhancedMixer,
357                      id,
358                      purpose,
359                      nrOfInputPlugs,
360                      nrOfOutputPlugs,
361                      verbose )
362 {
363 }
364
365 FunctionBlockEnhancedMixer::FunctionBlockEnhancedMixer(
366     const FunctionBlockEnhancedMixer& rhs )
367     : FunctionBlock( rhs )
368 {
369 }
370
371 FunctionBlockEnhancedMixer::FunctionBlockEnhancedMixer()
372     : FunctionBlock()
373 {
374 }
375
376 FunctionBlockEnhancedMixer::~FunctionBlockEnhancedMixer()
377 {
378 }
379
380 const char*
381 FunctionBlockEnhancedMixer::getName()
382 {
383     return "EnhancedMixer";
384 }
385
386 bool
387 FunctionBlockEnhancedMixer::serializeChild( Glib::ustring basePath,
388                                                    Util::IOSerialize& ser ) const
389 {
390     return true;
391 }
392
393 bool
394 FunctionBlockEnhancedMixer::deserializeChild( Glib::ustring basePath,
395                                                      Util::IODeserialize& deser,
396                                                      AvDevice& unit )
397 {
398     return true;
399 }
400
401 ///////////////////////
402
403 FunctionBlockProcessing::FunctionBlockProcessing(
404     AVC::Subunit& subunit,
405     function_block_id_t id,
406     ESpecialPurpose purpose,
407     no_of_input_plugs_t nrOfInputPlugs,
408     no_of_output_plugs_t nrOfOutputPlugs,
409     int verbose )
410     : FunctionBlock( subunit,
411                      eFBT_AudioSubunitProcessing,
412                      0,
413                      id,
414                      purpose,
415                      nrOfInputPlugs,
416                      nrOfOutputPlugs,
417                      verbose )
418 {
419 }
420
421 FunctionBlockProcessing::FunctionBlockProcessing(
422     const FunctionBlockProcessing& rhs )
423     : FunctionBlock( rhs )
424 {
425 }
426
427 FunctionBlockProcessing::FunctionBlockProcessing()
428     : FunctionBlock()
429 {
430 }
431
432 FunctionBlockProcessing::~FunctionBlockProcessing()
433 {
434 }
435
436 const char*
437 FunctionBlockProcessing::getName()
438 {
439     return "Dummy Processing";
440 }
441
442 bool
443 FunctionBlockProcessing::serializeChild( Glib::ustring basePath,
444                                                 Util::IOSerialize& ser ) const
445 {
446     return true;
447 }
448
449 bool
450 FunctionBlockProcessing::deserializeChild( Glib::ustring basePath,
451                                                   Util::IODeserialize& deser,
452                                                   AvDevice& unit )
453 {
454     return true;
455 }
456
457 ///////////////////////
458
459 FunctionBlockCodec::FunctionBlockCodec(
460     AVC::Subunit& subunit,
461     function_block_id_t id,
462     ESpecialPurpose purpose,
463     no_of_input_plugs_t nrOfInputPlugs,
464     no_of_output_plugs_t nrOfOutputPlugs,
465     int verbose )
466     : FunctionBlock( subunit,
467                      eFBT_AudioSubunitCodec,
468                      0,
469                      id,
470                      purpose,
471                      nrOfInputPlugs,
472                      nrOfOutputPlugs,
473                      verbose )
474 {
475 }
476
477 FunctionBlockCodec::FunctionBlockCodec( const FunctionBlockCodec& rhs )
478     : FunctionBlock( rhs )
479 {
480 }
481
482 FunctionBlockCodec::FunctionBlockCodec()
483     : FunctionBlock()
484 {
485 }
486
487 FunctionBlockCodec::~FunctionBlockCodec()
488 {
489 }
490
491 const char*
492 FunctionBlockCodec::getName()
493 {
494     return "Dummy Codec";
495 }
496
497 bool
498 FunctionBlockCodec::serializeChild( Glib::ustring basePath,
499                                            Util::IOSerialize& ser ) const
500 {
501     return true;
502 }
503
504 bool
505 FunctionBlockCodec::deserializeChild( Glib::ustring basePath,
506                                              Util::IODeserialize& deser,
507                                              AvDevice& unit )
508 {
509     return true;
510 }
511
512 }
Note: See TracBrowser for help on using the browser.