root/branches/echoaudio/src/libavc/general/avc_subunit.cpp

Revision 509, 3.8 kB (checked in by ppalmers, 14 years ago)

- Moved all generic stuff but the functionblocks over to libavc
- compiles and works

Line 
1 /*
2  * Copyright (C)      2007 by Pieter Palmers
3  * Copyright (C) 2005-2007 by Daniel Wagner
4  *
5  * This file is part of FFADO
6  * FFADO = Free Firewire (pro-)audio drivers for linux
7  *
8  * FFADO is based upon FreeBoB
9  *
10  * This library is free software; you can redistribute it and/or
11  * modify it under the terms of the GNU Lesser General Public
12  * License version 2.1, as published by the Free Software Foundation;
13  *
14  * This library 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 GNU
17  * Lesser General Public License for more details.
18  *
19  * You should have received a copy of the GNU Lesser General Public
20  * License along with this library; if not, write to the Free Software
21  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
22  * MA 02110-1301 USA
23  */
24
25
26 #include "avc_subunit.h"
27 #include "../general/avc_unit.h"
28 #include "../general/avc_plug.h"
29
30 #include "libieee1394/configrom.h"
31
32 #include "../general/avc_plug_info.h"
33 #include "../streamformat/avc_extended_stream_format.h"
34 #include "../util/avc_serialize.h"
35
36 #include <sstream>
37
38 namespace AVC {
39
40 IMPL_DEBUG_MODULE( Subunit, Subunit, DEBUG_LEVEL_VERBOSE );
41
42 ////////////////////////////////////////////
43
44 Subunit::Subunit( Unit& unit,
45                   ESubunitType type,
46                   subunit_t id )
47     : m_unit( &unit )
48     , m_sbType( type )
49     , m_sbId( id )
50 {
51
52 }
53
54 Subunit::Subunit()
55 {
56 }
57
58 Subunit::~Subunit()
59 {
60     for ( PlugVector::iterator it = m_plugs.begin();
61           it != m_plugs.end();
62           ++it )
63     {
64         delete *it;
65     }
66 }
67
68 bool
69 Subunit::discover()
70 {
71     // There is nothing we can discover for a generic subunit
72     // Maybe the plugs, but there are multiple ways of doing that.
73     // subclasses should implement this
74     return true;
75 }
76
77 bool
78 Subunit::addPlug( Plug& plug )
79 {
80     m_plugs.push_back( &plug );
81     return true;
82 }
83
84
85 Plug*
86 Subunit::getPlug(Plug::EPlugDirection direction, plug_id_t plugId)
87 {
88     for ( PlugVector::iterator it = m_plugs.begin();
89           it != m_plugs.end();
90           ++it )
91     {
92         Plug* plug = *it;
93         if ( ( plug->getPlugId() == plugId )
94             && ( plug->getDirection() == direction ) )
95         {
96             return plug;
97         }
98     }
99     return 0;
100 }
101
102 bool
103 Subunit::serialize( Glib::ustring basePath,
104                                    Util::IOSerialize& ser ) const
105 {
106     bool result;
107
108     result  = ser.write( basePath + "m_sbType", m_sbType );
109     result &= ser.write( basePath + "m_sbId", m_sbId );
110     result &= ser.write( basePath + "m_verboseLevel", getDebugLevel() );
111     result &= serializeChild( basePath, ser );
112
113     return result;
114 }
115
116 Subunit*
117 Subunit::deserialize( Glib::ustring basePath,
118                       Util::IODeserialize& deser,
119                       Unit& unit )
120 {
121     bool result;
122     ESubunitType sbType;
123     result  = deser.read( basePath + "m_sbType", sbType );
124
125     Subunit* pSubunit = 0;
126    
127     #warning FIXME: The derived class should be creating these
128     // FIXME: The derived class should be creating these, such that discover() can become pure virtual
129     switch( sbType ) {
130     case eST_Audio:
131         pSubunit = new SubunitAudio;
132         break;
133     case eST_Music:
134         pSubunit = new SubunitMusic;
135         break;
136     default:
137         pSubunit = 0;
138     }
139
140     if ( !pSubunit ) {
141         return 0;
142     }
143
144     pSubunit->m_unit = &unit;
145     pSubunit->m_sbType = sbType;
146     result &= deser.read( basePath + "m_sbId", pSubunit->m_sbId );
147     int verboseLevel;
148     result &= deser.read( basePath + "m_verboseLevel", verboseLevel );
149     setDebugLevel(verboseLevel);
150     result &= pSubunit->deserializeChild( basePath, deser, unit );
151
152     if ( !result ) {
153         delete pSubunit;
154         return 0;
155     }
156
157     return pSubunit;
158 }
159
160 }
Note: See TracBrowser for help on using the browser.