root/trunk/libfreebob/src/libfreebobavc/avc_signal_source.cpp

Revision 375, 6.8 kB (checked in by wagi, 17 years ago)

AVCCommand: All AVC commants take a reference instead a pointer to 1394 service
BeBoB::AvDevice?: PreSonus? FIREBOX id added

De/Serialize all AvPlugs? through AvPlugManager?
AvPlugManager? can't be a member because of serialization

  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
Line 
1 /* avc_signal_source.cpp
2  * Copyright (C) 2005 by Daniel Wagner
3  *
4  * This file is part of FreeBoB.
5  *
6  * FreeBoB is free software; you can redistribute it and/or modify
7  * it under the terms of the GNU General Public License as published by
8  * the Free Software Foundation; either version 2 of the License, or
9  * (at your option) any later version.
10  * FreeBoB is distributed in the hope that it will be useful,
11  * but WITHOUT ANY WARRANTY; without even the implied warranty of
12  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
13  * GNU General Public License for more details.
14  *
15  * You should have received a copy of the GNU General Public License
16  * along with FreeBoB; if not, write to the Free Software
17  * Foundation, Inc., 59 Temple Place, Suite 330, Boston,
18  * MA 02111-1307 USA.
19  */
20
21 #include "avc_signal_source.h"
22 #include "avc_serialize.h"
23 #include "ieee1394service.h"
24
25 #include <netinet/in.h>
26 #include <iostream>
27
28 using namespace std;
29
30 #define AVC1394_CMD_SIGNAL_SOURCE 0x1A
31
32 SignalUnitAddress::SignalUnitAddress()
33     : m_plugId( ePI_Invalid )
34 {
35 }
36
37 bool
38 SignalUnitAddress::serialize( IOSSerialize& se )
39 {
40     byte_t reserved = 0xff;
41     se.write( reserved, "SignalUnitAddress" );
42     se.write( m_plugId, "SignalUnitAddress plugId" );
43     return true;
44 }
45
46 bool
47 SignalUnitAddress::deserialize( IISDeserialize& de )
48 {
49     byte_t operand;
50     de.read( &operand );
51     de.read( &m_plugId );
52     return true;
53 }
54
55 SignalUnitAddress*
56 SignalUnitAddress::clone() const
57 {
58     return new SignalUnitAddress( *this );
59 }
60
61 ////////////////////////////////////////
62
63 SignalSubunitAddress::SignalSubunitAddress()
64     : m_subunitType( AVC1394_SUBUNIT_RESERVED )
65     , m_subunitId( AVC1394_SUBUNIT_ID_RESERVED )
66     , m_plugId( ePI_Invalid )
67 {
68 }
69
70 bool
71 SignalSubunitAddress::serialize( IOSSerialize& se )
72 {
73     byte_t operand = ( m_subunitType << 3 ) | ( m_subunitId & 0x7 );
74     se.write( operand,  "SignalSubunitAddress subunitType & subunitId" );
75     se.write( m_plugId, "SignalSubunitAddress plugId" );
76     return true;
77 }
78
79 bool
80 SignalSubunitAddress::deserialize( IISDeserialize& de )
81 {
82     byte_t operand;
83     de.read( &operand );
84     m_subunitType = operand >> 3;
85     m_subunitId = operand & 0x7;
86     de.read( &m_plugId );
87     return true;
88 }
89
90 SignalSubunitAddress*
91 SignalSubunitAddress::clone() const
92 {
93     return new SignalSubunitAddress( *this );
94 }
95
96 ////////////////////////////////////////
97
98
99 SignalSourceCmd::SignalSourceCmd( Ieee1394Service& ieee1394service )
100     : AVCCommand( ieee1394service, AVC1394_CMD_SIGNAL_SOURCE )
101     , m_resultStatus( 0xff )
102     , m_outputStatus( 0xff )
103     , m_conv( 0xff )
104     , m_signalStatus( 0xff )
105     , m_signalSource( 0 )
106     , m_signalDestination( 0 )
107 {
108 }
109
110 SignalSourceCmd::~SignalSourceCmd()
111 {
112     delete m_signalSource;
113     m_signalSource = 0;
114     delete m_signalDestination;
115     m_signalDestination = 0;
116 }
117
118 bool
119 SignalSourceCmd::serialize( IOSSerialize& se )
120 {
121     AVCCommand::serialize( se );
122
123     byte_t operand;
124     switch ( getCommandType() ) {
125     case eCT_Status:
126         operand = ( m_outputStatus << 5 )
127                   | ( ( m_conv & 0x1 ) << 4 )
128                   | ( m_signalStatus & 0xf );
129         se.write( operand, "SignalSourceCmd outputStatus & conv & signalStatus" );
130         break;
131     case eCT_Control:
132     case eCT_SpecificInquiry:
133         operand = m_resultStatus & 0xf;
134         se.write( operand, "SignalSourceCmd resultStatus" );
135         break;
136     default:
137         cerr << "Can't handle command type " << getCommandType() << endl;
138         return false;
139     }
140
141     switch( getSubunitType() ) {
142     case eST_Unit:
143     case eST_Audio:
144     case eST_Music:
145         {
146             if ( m_signalSource ) {
147                 m_signalSource->serialize( se );
148             } else {
149                 byte_t reserved = 0xff;
150                 se.write( reserved, "SignalSourceCmd" );
151                 se.write( reserved, "SignalSourceCmd" );
152             }
153
154             if ( m_signalDestination ) {
155                 m_signalDestination->serialize( se );
156             } else {
157                 byte_t reserved = 0xff;
158                 se.write( reserved, "SignalSourceCmd" );
159                 se.write( reserved, "SignalSourceCmd" );
160             }
161         }
162         break;
163     default:
164         cerr << "Can't handle subunit type " << getSubunitType() << endl;
165         return false;
166     }
167
168     return true;
169 }
170
171 bool
172 SignalSourceCmd::deserialize( IISDeserialize& de )
173 {
174     delete m_signalSource;
175     m_signalSource = 0;
176     delete m_signalDestination;
177     m_signalDestination = 0;
178
179     AVCCommand::deserialize( de );
180
181     byte_t operand;
182     switch ( getCommandType() ) {
183     case eCT_Status:
184         de.read( &operand );
185         m_outputStatus = operand >> 5;
186         m_conv = ( operand & 0x10 ) >> 4;
187         m_signalStatus = operand & 0xf;
188         break;
189     case eCT_Control:
190     case eCT_SpecificInquiry:
191         de.read( &operand );
192         m_resultStatus = operand & 0xf;
193         break;
194     default:
195         cerr << "Can't handle command type " << getCommandType() << endl;
196         return false;
197     }
198
199     switch( getSubunitType() ) {
200     case eST_Unit:
201     case eST_Audio:
202     case eST_Music:
203         {
204             byte_t operand;
205             de.peek( &operand );
206             if ( operand == 0xff ) {
207                 m_signalSource = new SignalUnitAddress;
208             } else {
209                 m_signalSource = new SignalSubunitAddress;
210             }
211
212             m_signalSource->deserialize( de );
213
214             de.peek( &operand );
215             if ( operand == 0xff ) {
216                 m_signalDestination = new SignalUnitAddress;
217             } else {
218                 m_signalDestination = new SignalSubunitAddress;
219             }
220             m_signalDestination->deserialize( de );
221         }
222         break;
223     default:
224         cerr << "Can't handle subunit type " << getSubunitType() << endl;
225         return false;
226     }
227
228     return true;
229 }
230
231 bool
232 SignalSourceCmd::setSignalSource( SignalUnitAddress& signalAddress )
233 {
234     if ( m_signalSource ) {
235         delete m_signalSource;
236     }
237     m_signalSource = signalAddress.clone();
238     return true;
239 }
240
241 bool
242 SignalSourceCmd::setSignalSource( SignalSubunitAddress& signalAddress )
243 {
244     if ( m_signalSource ) {
245         delete m_signalSource;
246     }
247     m_signalSource = signalAddress.clone();
248     return true;
249 }
250
251 bool
252 SignalSourceCmd::setSignalDestination( SignalUnitAddress& signalAddress )
253 {
254     if ( m_signalDestination ) {
255         delete m_signalDestination;
256     }
257     m_signalDestination = signalAddress.clone();
258     return true;
259 }
260
261 bool
262 SignalSourceCmd::setSignalDestination( SignalSubunitAddress& signalAddress )
263 {
264     if ( m_signalDestination ) {
265         delete m_signalDestination;
266     }
267     m_signalDestination = signalAddress.clone();
268     return true;
269 }
270
271 SignalAddress*
272 SignalSourceCmd::getSignalSource()
273 {
274     return m_signalSource;
275 }
276
277 SignalAddress*
278 SignalSourceCmd::getSignalDestination()
279 {
280     return m_signalDestination;
281 }
Note: See TracBrowser for help on using the browser.