root/trunk/libffado/src/libavc/ccm/avc_signal_source.cpp

Revision 618, 6.9 kB (checked in by ppalmers, 13 years ago)

move serialization routines to libutil such that they can be used for non-AVC stuff too (fireworks EFC)

  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
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 "avc_signal_source.h"
25 #include "libutil/cmd_serialize.h"
26 #include "libieee1394/ieee1394service.h"
27
28 #include <netinet/in.h>
29 #include <iostream>
30
31 using namespace std;
32
33 #define AVC1394_CMD_SIGNAL_SOURCE 0x1A
34
35 namespace AVC {
36
37
38 SignalUnitAddress::SignalUnitAddress()
39     : m_plugId( ePI_Invalid )
40 {
41 }
42
43 bool
44 SignalUnitAddress::serialize( Util::IOSSerialize& se )
45 {
46     byte_t reserved = 0xff;
47     se.write( reserved, "SignalUnitAddress" );
48     se.write( m_plugId, "SignalUnitAddress plugId" );
49     return true;
50 }
51
52 bool
53 SignalUnitAddress::deserialize( Util::IISDeserialize& de )
54 {
55     byte_t operand;
56     de.read( &operand );
57     de.read( &m_plugId );
58     return true;
59 }
60
61 SignalUnitAddress*
62 SignalUnitAddress::clone() const
63 {
64     return new SignalUnitAddress( *this );
65 }
66
67 ////////////////////////////////////////
68
69 SignalSubunitAddress::SignalSubunitAddress()
70     : m_subunitType( AVC1394_SUBUNIT_RESERVED )
71     , m_subunitId( AVC1394_SUBUNIT_ID_RESERVED )
72     , m_plugId( ePI_Invalid )
73 {
74 }
75
76 bool
77 SignalSubunitAddress::serialize( Util::IOSSerialize& se )
78 {
79     byte_t operand = ( m_subunitType << 3 ) | ( m_subunitId & 0x7 );
80     se.write( operand,  "SignalSubunitAddress subunitType & subunitId" );
81     se.write( m_plugId, "SignalSubunitAddress plugId" );
82     return true;
83 }
84
85 bool
86 SignalSubunitAddress::deserialize( Util::IISDeserialize& de )
87 {
88     byte_t operand;
89     de.read( &operand );
90     m_subunitType = operand >> 3;
91     m_subunitId = operand & 0x7;
92     de.read( &m_plugId );
93     return true;
94 }
95
96 SignalSubunitAddress*
97 SignalSubunitAddress::clone() const
98 {
99     return new SignalSubunitAddress( *this );
100 }
101
102 ////////////////////////////////////////
103
104
105 SignalSourceCmd::SignalSourceCmd( Ieee1394Service& ieee1394service )
106     : AVCCommand( ieee1394service, AVC1394_CMD_SIGNAL_SOURCE )
107     , m_resultStatus( 0xff )
108     , m_outputStatus( 0xff )
109     , m_conv( 0xff )
110     , m_signalStatus( 0xff )
111     , m_signalSource( 0 )
112     , m_signalDestination( 0 )
113 {
114 }
115
116 SignalSourceCmd::~SignalSourceCmd()
117 {
118     delete m_signalSource;
119     m_signalSource = 0;
120     delete m_signalDestination;
121     m_signalDestination = 0;
122 }
123
124 bool
125 SignalSourceCmd::serialize( Util::IOSSerialize& se )
126 {
127     AVCCommand::serialize( se );
128
129     byte_t operand;
130     switch ( getCommandType() ) {
131     case eCT_Status:
132         operand = ( m_outputStatus << 5 )
133                   | ( ( m_conv & 0x1 ) << 4 )
134                   | ( m_signalStatus & 0xf );
135         se.write( operand, "SignalSourceCmd outputStatus & conv & signalStatus" );
136         break;
137     case eCT_Control:
138     case eCT_SpecificInquiry:
139         operand = m_resultStatus & 0xf;
140         se.write( operand, "SignalSourceCmd resultStatus" );
141         break;
142     default:
143         cerr << "Can't handle command type " << getCommandType() << endl;
144         return false;
145     }
146
147     switch( getSubunitType() ) {
148     case eST_Unit:
149     case eST_Audio:
150     case eST_Music:
151         {
152             if ( m_signalSource ) {
153                 m_signalSource->serialize( se );
154             } else {
155                 byte_t reserved = 0xff;
156                 se.write( reserved, "SignalSourceCmd" );
157                 se.write( reserved, "SignalSourceCmd" );
158             }
159
160             if ( m_signalDestination ) {
161                 m_signalDestination->serialize( se );
162             } else {
163                 byte_t reserved = 0xff;
164                 se.write( reserved, "SignalSourceCmd" );
165                 se.write( reserved, "SignalSourceCmd" );
166             }
167         }
168         break;
169     default:
170         cerr << "Can't handle subunit type " << getSubunitType() << endl;
171         return false;
172     }
173
174     return true;
175 }
176
177 bool
178 SignalSourceCmd::deserialize( Util::IISDeserialize& de )
179 {
180     delete m_signalSource;
181     m_signalSource = 0;
182     delete m_signalDestination;
183     m_signalDestination = 0;
184
185     AVCCommand::deserialize( de );
186
187     byte_t operand;
188     switch ( getCommandType() ) {
189     case eCT_Status:
190         de.read( &operand );
191         m_outputStatus = operand >> 5;
192         m_conv = ( operand & 0x10 ) >> 4;
193         m_signalStatus = operand & 0xf;
194         break;
195     case eCT_Control:
196     case eCT_SpecificInquiry:
197         de.read( &operand );
198         m_resultStatus = operand & 0xf;
199         break;
200     default:
201         cerr << "Can't handle command type " << getCommandType() << endl;
202         return false;
203     }
204
205     switch( getSubunitType() ) {
206     case eST_Unit:
207     case eST_Audio:
208     case eST_Music:
209         {
210             byte_t operand;
211             de.peek( &operand );
212             if ( operand == 0xff ) {
213                 m_signalSource = new SignalUnitAddress;
214             } else {
215                 m_signalSource = new SignalSubunitAddress;
216             }
217
218             m_signalSource->deserialize( de );
219
220             de.peek( &operand );
221             if ( operand == 0xff ) {
222                 m_signalDestination = new SignalUnitAddress;
223             } else {
224                 m_signalDestination = new SignalSubunitAddress;
225             }
226             m_signalDestination->deserialize( de );
227         }
228         break;
229     default:
230         cerr << "Can't handle subunit type " << getSubunitType() << endl;
231         return false;
232     }
233
234     return true;
235 }
236
237 bool
238 SignalSourceCmd::setSignalSource( SignalUnitAddress& signalAddress )
239 {
240     if ( m_signalSource ) {
241         delete m_signalSource;
242     }
243     m_signalSource = signalAddress.clone();
244     return true;
245 }
246
247 bool
248 SignalSourceCmd::setSignalSource( SignalSubunitAddress& signalAddress )
249 {
250     if ( m_signalSource ) {
251         delete m_signalSource;
252     }
253     m_signalSource = signalAddress.clone();
254     return true;
255 }
256
257 bool
258 SignalSourceCmd::setSignalDestination( SignalUnitAddress& signalAddress )
259 {
260     if ( m_signalDestination ) {
261         delete m_signalDestination;
262     }
263     m_signalDestination = signalAddress.clone();
264     return true;
265 }
266
267 bool
268 SignalSourceCmd::setSignalDestination( SignalSubunitAddress& signalAddress )
269 {
270     if ( m_signalDestination ) {
271         delete m_signalDestination;
272     }
273     m_signalDestination = signalAddress.clone();
274     return true;
275 }
276
277 SignalAddress*
278 SignalSourceCmd::getSignalSource()
279 {
280     return m_signalSource;
281 }
282
283 SignalAddress*
284 SignalSourceCmd::getSignalDestination()
285 {
286     return m_signalDestination;
287 }
288
289 }
Note: See TracBrowser for help on using the browser.