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

Revision 736, 12.8 kB (checked in by ppalmers, 15 years ago)

fix some stuff that was not merged correctly

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 &= ser.write( basePath + "m_verbose", m_verbose );
173     result &= serializePlugVector( basePath + "m_plugs", ser, m_plugs );
174
175     return result;
176 }
177
178 FunctionBlock*
179 FunctionBlock::deserialize( Glib::ustring basePath,
180                             Util::IODeserialize& deser,
181                             AVC::Unit& unit,
182                             AVC::Subunit& subunit )
183 {
184     bool result;
185     function_block_type_t type;
186     function_block_type_t subtype;
187     FunctionBlock* pFB = 0;
188
189     result  = deser.read( basePath + "m_type", type );
190     result &= deser.read( basePath + "m_subtype", subtype );
191     if ( !result ) {
192         return 0;
193     }
194
195     switch ( type ) {
196     case ExtendedSubunitInfoCmd::eFBT_AudioSubunitSelector:
197         pFB = new FunctionBlockSelector;
198         break;
199     case ExtendedSubunitInfoCmd::eFBT_AudioSubunitFeature:
200         pFB = new FunctionBlockFeature;
201         break;
202     case ExtendedSubunitInfoCmd::eFBT_AudioSubunitProcessing:
203         if ( subtype == ExtendedSubunitInfoCmd::ePT_EnhancedMixer ) {
204             pFB = new FunctionBlockEnhancedMixer;
205         } else {
206             pFB = new FunctionBlockProcessing;
207         }
208         break;
209     case ExtendedSubunitInfoCmd::eFBT_AudioSubunitCodec:
210         pFB = new FunctionBlockCodec;
211         break;
212     default:
213         pFB = 0;
214     }
215
216     if ( !pFB ) {
217         return 0;
218     }
219
220     pFB->m_subunit = &subunit;
221     pFB->m_type = type;
222     pFB->m_subtype = subtype;
223
224     result &= deser.read( basePath + "m_id", pFB->m_id );
225     result &= deser.read( basePath + "m_purpose", pFB->m_purpose );
226     result &= deser.read( basePath + "m_nrOfInputPlugs", pFB->m_nrOfInputPlugs );
227     result &= deser.read( basePath + "m_nrOfOutputPlugs", pFB->m_nrOfOutputPlugs );
228     result &= deser.read( basePath + "m_verbose", pFB->m_verbose );
229     result &= deserializePlugVector( basePath + "m_plugs", deser,
230                                      unit.getPlugManager(), pFB->m_plugs );
231
232     return 0;
233 }
234
235 ///////////////////////
236
237 FunctionBlockSelector::FunctionBlockSelector(
238     AVC::Subunit& subunit,
239     function_block_id_t id,
240     ESpecialPurpose purpose,
241     no_of_input_plugs_t nrOfInputPlugs,
242     no_of_output_plugs_t nrOfOutputPlugs,
243     int verbose )
244     : FunctionBlock( subunit,
245                      eFBT_AudioSubunitSelector,
246                      0,
247                      id,
248                      purpose,
249                      nrOfInputPlugs,
250                      nrOfOutputPlugs,
251                      verbose )
252 {
253 }
254
255 FunctionBlockSelector::FunctionBlockSelector(
256     const FunctionBlockSelector& rhs )
257     : FunctionBlock( rhs )
258 {
259 }
260
261 FunctionBlockSelector::FunctionBlockSelector()
262     : FunctionBlock()
263 {
264 }
265
266 FunctionBlockSelector::~FunctionBlockSelector()
267 {
268 }
269
270 const char*
271 FunctionBlockSelector::getName()
272 {
273     return "Selector";
274 }
275
276 bool
277 FunctionBlockSelector::serializeChild( Glib::ustring basePath,
278                                               Util::IOSerialize& ser ) const
279 {
280     return true;
281 }
282
283 bool
284 FunctionBlockSelector::deserializeChild( Glib::ustring basePath,
285                                                 Util::IODeserialize& deser,
286                                                 AvDevice& unit )
287 {
288     return true;
289 }
290
291 ///////////////////////
292
293 FunctionBlockFeature::FunctionBlockFeature(
294     AVC::Subunit& subunit,
295     function_block_id_t id,
296     ESpecialPurpose purpose,
297     no_of_input_plugs_t nrOfInputPlugs,
298     no_of_output_plugs_t nrOfOutputPlugs,
299     int verbose )
300     : FunctionBlock( subunit,
301                      eFBT_AudioSubunitFeature,
302                      0,
303                      id,
304                      purpose,
305                      nrOfInputPlugs,
306                      nrOfOutputPlugs,
307                      verbose )
308 {
309 }
310
311 FunctionBlockFeature::FunctionBlockFeature(
312     const FunctionBlockFeature& rhs )
313     : FunctionBlock( rhs )
314 {
315 }
316
317 FunctionBlockFeature::FunctionBlockFeature()
318     : FunctionBlock()
319 {
320 }
321
322 FunctionBlockFeature::~FunctionBlockFeature()
323 {
324 }
325
326 const char*
327 FunctionBlockFeature::getName()
328 {
329     return "Feature";
330 }
331
332 bool
333 FunctionBlockFeature::serializeChild( Glib::ustring basePath,
334                                              Util::IOSerialize& ser ) const
335 {
336     return true;
337 }
338
339 bool
340 FunctionBlockFeature::deserializeChild( Glib::ustring basePath,
341                                                Util::IODeserialize& deser,
342                                                AvDevice& unit )
343 {
344     return true;
345 }
346
347 ///////////////////////
348
349 FunctionBlockEnhancedMixer::FunctionBlockEnhancedMixer(
350     AVC::Subunit& subunit,
351     function_block_id_t id,
352     ESpecialPurpose purpose,
353     no_of_input_plugs_t nrOfInputPlugs,
354     no_of_output_plugs_t nrOfOutputPlugs,
355     int verbose )
356     : FunctionBlock( subunit,
357                      eFBT_AudioSubunitProcessing,
358                      ExtendedSubunitInfoCmd::ePT_EnhancedMixer,
359                      id,
360                      purpose,
361                      nrOfInputPlugs,
362                      nrOfOutputPlugs,
363                      verbose )
364 {
365 }
366
367 FunctionBlockEnhancedMixer::FunctionBlockEnhancedMixer(
368     const FunctionBlockEnhancedMixer& rhs )
369     : FunctionBlock( rhs )
370 {
371 }
372
373 FunctionBlockEnhancedMixer::FunctionBlockEnhancedMixer()
374     : FunctionBlock()
375 {
376 }
377
378 FunctionBlockEnhancedMixer::~FunctionBlockEnhancedMixer()
379 {
380 }
381
382 const char*
383 FunctionBlockEnhancedMixer::getName()
384 {
385     return "EnhancedMixer";
386 }
387
388 bool
389 FunctionBlockEnhancedMixer::serializeChild( Glib::ustring basePath,
390                                                    Util::IOSerialize& ser ) const
391 {
392     return true;
393 }
394
395 bool
396 FunctionBlockEnhancedMixer::deserializeChild( Glib::ustring basePath,
397                                                      Util::IODeserialize& deser,
398                                                      AvDevice& unit )
399 {
400     return true;
401 }
402
403 ///////////////////////
404
405 FunctionBlockProcessing::FunctionBlockProcessing(
406     AVC::Subunit& subunit,
407     function_block_id_t id,
408     ESpecialPurpose purpose,
409     no_of_input_plugs_t nrOfInputPlugs,
410     no_of_output_plugs_t nrOfOutputPlugs,
411     int verbose )
412     : FunctionBlock( subunit,
413                      eFBT_AudioSubunitProcessing,
414                      0,
415                      id,
416                      purpose,
417                      nrOfInputPlugs,
418                      nrOfOutputPlugs,
419                      verbose )
420 {
421 }
422
423 FunctionBlockProcessing::FunctionBlockProcessing(
424     const FunctionBlockProcessing& rhs )
425     : FunctionBlock( rhs )
426 {
427 }
428
429 FunctionBlockProcessing::FunctionBlockProcessing()
430     : FunctionBlock()
431 {
432 }
433
434 FunctionBlockProcessing::~FunctionBlockProcessing()
435 {
436 }
437
438 const char*
439 FunctionBlockProcessing::getName()
440 {
441     return "Dummy Processing";
442 }
443
444 bool
445 FunctionBlockProcessing::serializeChild( Glib::ustring basePath,
446                                                 Util::IOSerialize& ser ) const
447 {
448     return true;
449 }
450
451 bool
452 FunctionBlockProcessing::deserializeChild( Glib::ustring basePath,
453                                                   Util::IODeserialize& deser,
454                                                   AvDevice& unit )
455 {
456     return true;
457 }
458
459 ///////////////////////
460
461 FunctionBlockCodec::FunctionBlockCodec(
462     AVC::Subunit& subunit,
463     function_block_id_t id,
464     ESpecialPurpose purpose,
465     no_of_input_plugs_t nrOfInputPlugs,
466     no_of_output_plugs_t nrOfOutputPlugs,
467     int verbose )
468     : FunctionBlock( subunit,
469                      eFBT_AudioSubunitCodec,
470                      0,
471                      id,
472                      purpose,
473                      nrOfInputPlugs,
474                      nrOfOutputPlugs,
475                      verbose )
476 {
477 }
478
479 FunctionBlockCodec::FunctionBlockCodec( const FunctionBlockCodec& rhs )
480     : FunctionBlock( rhs )
481 {
482 }
483
484 FunctionBlockCodec::FunctionBlockCodec()
485     : FunctionBlock()
486 {
487 }
488
489 FunctionBlockCodec::~FunctionBlockCodec()
490 {
491 }
492
493 const char*
494 FunctionBlockCodec::getName()
495 {
496     return "Dummy Codec";
497 }
498
499 bool
500 FunctionBlockCodec::serializeChild( Glib::ustring basePath,
501                                            Util::IOSerialize& ser ) const
502 {
503     return true;
504 }
505
506 bool
507 FunctionBlockCodec::deserializeChild( Glib::ustring basePath,
508                                              Util::IODeserialize& deser,
509                                              AvDevice& unit )
510 {
511     return true;
512 }
513
514 }
Note: See TracBrowser for help on using the browser.