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 |
#warning do we need this? |
---|
39 |
#include "bebob/bebob_avplug.h" |
---|
40 |
|
---|
41 |
namespace AVC { |
---|
42 |
|
---|
43 |
IMPL_DEBUG_MODULE( Subunit, Subunit, DEBUG_LEVEL_VERBOSE ); |
---|
44 |
|
---|
45 |
//////////////////////////////////////////// |
---|
46 |
|
---|
47 |
Subunit::Subunit( Unit& unit, |
---|
48 |
ESubunitType type, |
---|
49 |
subunit_t id ) |
---|
50 |
: m_unit( &unit ) |
---|
51 |
, m_sbType( type ) |
---|
52 |
, m_sbId( id ) |
---|
53 |
{ |
---|
54 |
|
---|
55 |
} |
---|
56 |
|
---|
57 |
Subunit::Subunit() |
---|
58 |
{ |
---|
59 |
} |
---|
60 |
|
---|
61 |
Subunit::~Subunit() |
---|
62 |
{ |
---|
63 |
for ( PlugVector::iterator it = m_plugs.begin(); |
---|
64 |
it != m_plugs.end(); |
---|
65 |
++it ) |
---|
66 |
{ |
---|
67 |
delete *it; |
---|
68 |
} |
---|
69 |
} |
---|
70 |
|
---|
71 |
bool |
---|
72 |
Subunit::discover() |
---|
73 |
{ |
---|
74 |
// There is nothing we can discover for a generic subunit |
---|
75 |
// Maybe its plugs, but there are multiple ways of doing that. |
---|
76 |
return true; |
---|
77 |
} |
---|
78 |
|
---|
79 |
bool |
---|
80 |
Subunit::addPlug( Plug& plug ) |
---|
81 |
{ |
---|
82 |
m_plugs.push_back( &plug ); |
---|
83 |
return true; |
---|
84 |
} |
---|
85 |
|
---|
86 |
|
---|
87 |
Plug* |
---|
88 |
Subunit::getPlug(Plug::EPlugDirection direction, plug_id_t plugId) |
---|
89 |
{ |
---|
90 |
for ( PlugVector::iterator it = m_plugs.begin(); |
---|
91 |
it != m_plugs.end(); |
---|
92 |
++it ) |
---|
93 |
{ |
---|
94 |
Plug* plug = *it; |
---|
95 |
if ( ( plug->getPlugId() == plugId ) |
---|
96 |
&& ( plug->getDirection() == direction ) ) |
---|
97 |
{ |
---|
98 |
return plug; |
---|
99 |
} |
---|
100 |
} |
---|
101 |
return 0; |
---|
102 |
} |
---|
103 |
|
---|
104 |
bool |
---|
105 |
Subunit::serialize( Glib::ustring basePath, |
---|
106 |
Util::IOSerialize& ser ) const |
---|
107 |
{ |
---|
108 |
bool result; |
---|
109 |
|
---|
110 |
result = ser.write( basePath + "m_sbType", m_sbType ); |
---|
111 |
result &= ser.write( basePath + "m_sbId", m_sbId ); |
---|
112 |
result &= ser.write( basePath + "m_verboseLevel", getDebugLevel() ); |
---|
113 |
result &= serializeChild( basePath, ser ); |
---|
114 |
|
---|
115 |
return result; |
---|
116 |
} |
---|
117 |
|
---|
118 |
Subunit* |
---|
119 |
Subunit::deserialize( Glib::ustring basePath, |
---|
120 |
Util::IODeserialize& deser, |
---|
121 |
Unit& unit ) |
---|
122 |
{ |
---|
123 |
bool result; |
---|
124 |
ESubunitType sbType; |
---|
125 |
result = deser.read( basePath + "m_sbType", sbType ); |
---|
126 |
|
---|
127 |
Subunit* pSubunit = 0; |
---|
128 |
switch( sbType ) { |
---|
129 |
case eST_Audio: |
---|
130 |
pSubunit = new SubunitAudio; |
---|
131 |
break; |
---|
132 |
case eST_Music: |
---|
133 |
pSubunit = new SubunitMusic; |
---|
134 |
break; |
---|
135 |
default: |
---|
136 |
pSubunit = 0; |
---|
137 |
} |
---|
138 |
|
---|
139 |
if ( !pSubunit ) { |
---|
140 |
return 0; |
---|
141 |
} |
---|
142 |
|
---|
143 |
pSubunit->m_unit = &unit; |
---|
144 |
pSubunit->m_sbType = sbType; |
---|
145 |
result &= deser.read( basePath + "m_sbId", pSubunit->m_sbId ); |
---|
146 |
int verboseLevel; |
---|
147 |
result &= deser.read( basePath + "m_verboseLevel", verboseLevel ); |
---|
148 |
setDebugLevel(verboseLevel); |
---|
149 |
result &= pSubunit->deserializeChild( basePath, deser, unit ); |
---|
150 |
|
---|
151 |
if ( !result ) { |
---|
152 |
delete pSubunit; |
---|
153 |
return 0; |
---|
154 |
} |
---|
155 |
|
---|
156 |
return pSubunit; |
---|
157 |
} |
---|
158 |
|
---|
159 |
} |
---|