root/branches/echoaudio/src/libavc/descriptors/avc_descriptor_cmd.cpp

Revision 503, 5.8 kB (checked in by ppalmers, 17 years ago)

- put all libavc stuff into it's own name namespace (AVC)

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 #include "avc_descriptor_cmd.h"
26 #include "avc_descriptor.h"
27 #include "../util/avc_serialize.h"
28 #include "libieee1394/ieee1394service.h"
29
30 #include <netinet/in.h>
31 #include <iostream>
32
33 using namespace std;
34
35 namespace AVC {
36
37 OpenDescriptorCmd::OpenDescriptorCmd(Ieee1394Service& ieee1394service)
38     : AVCCommand( ieee1394service, AVC1394_CMD_OPEN_DESCRIPTOR )
39     , m_specifier( NULL )
40     , m_mode( eClose )
41     , m_status ( 0xFF )
42     , m_reserved ( 0x00 )
43     , m_locked_node_id ( 0xFFFF )
44 {
45 }
46
47 OpenDescriptorCmd::~OpenDescriptorCmd()
48 {
49 }
50
51 bool
52 OpenDescriptorCmd::clear()
53 {
54     m_status = 0xFF;
55     m_reserved =  0x00;
56     m_locked_node_id = 0xFFFF;
57     return true;
58 }
59
60 bool
61 OpenDescriptorCmd::serialize( IOSSerialize& se )
62 {
63     AVCCommand::serialize( se );
64    
65     if(m_specifier==NULL) {
66         debugError("m_specifier==NULL");
67         return false;
68     }
69    
70     m_specifier->serialize( se );
71    
72     switch (getCommandType()) {
73     case eCT_Status:
74         se.write( (byte_t)m_status, "OpenDescriptorCmd status" );
75         se.write( (byte_t)m_reserved, "OpenDescriptorCmd reserved" );
76         se.write( (uint16_t)m_locked_node_id, "OpenDescriptorCmd node_id" );
77         break;
78     case eCT_Control:
79         se.write( (byte_t)m_mode, "OpenDescriptorCmd subfunction" );
80         se.write( (byte_t)m_reserved, "OpenDescriptorCmd reserved" );
81         break;
82     default:
83         debugError("Unsupported type for this command: %02X\n", getCommandType());
84         return false;
85     }
86     return true;
87 }
88
89 bool
90 OpenDescriptorCmd::deserialize( IISDeserialize& de )
91 {
92     AVCCommand::deserialize( de );
93    
94     if(m_specifier==NULL) {
95         debugError("m_specifier==NULL");
96         return false;
97     }
98    
99     m_specifier->deserialize( de );
100    
101     switch ( getCommandType() ) {
102     case eCT_Status:
103         de.read( &m_status );
104         de.read( &m_reserved );
105         de.read( &m_locked_node_id );
106
107         break;
108     case eCT_Control:
109         de.read( &m_status );
110         de.read( &m_reserved );
111         switch (m_status) {
112             case (byte_t)eClose: m_mode=eClose; break;
113             case (byte_t)eRead: m_mode=eRead; break;
114             case (byte_t)eWrite: m_mode=eWrite; break;
115             default:
116             debugError("Unknown response subfunction 0x%02X\n", m_status);
117         }
118        
119         break;
120     default:
121         debugError("Can't handle command type %s\n", getCommandType());
122         return false;
123     }
124
125
126     return true;
127 }
128
129 //
130
131 ReadDescriptorCmd::ReadDescriptorCmd(Ieee1394Service& ieee1394service)
132     : AVCCommand( ieee1394service, AVC1394_CMD_READ_DESCRIPTOR )
133     , m_status ( 0xFF )
134     , m_reserved ( 0xFF )
135     , m_data_length ( 0 )
136     , m_address ( 0 )
137     , m_data ( NULL )
138     , m_specifier( NULL )
139 {
140 }
141
142 ReadDescriptorCmd::~ReadDescriptorCmd()
143 {
144
145 }
146
147 bool
148 ReadDescriptorCmd::clear()
149 {
150     m_status = 0xFF;
151     m_reserved =  0x00;
152     m_data_length = 0x0000;
153     m_address = 0x0000;
154     return true;
155 }
156
157 bool
158 ReadDescriptorCmd::serialize( IOSSerialize& se )
159 {
160     AVCCommand::serialize( se );
161    
162     if(m_specifier==NULL) {
163         debugError("m_specifier==NULL");
164         return false;
165     }
166    
167     m_specifier->serialize( se );
168    
169     switch (getCommandType()) {
170     case eCT_Control:
171         se.write( (byte_t)m_status, "ReadDescriptorCmd read_result_status" );
172         se.write( (byte_t)m_reserved, "ReadDescriptorCmd reserved" );
173         se.write( (uint16_t)m_data_length, "ReadDescriptorCmd data_length" );
174         se.write( (uint16_t)m_address, "ReadDescriptorCmd address" );
175
176         break;
177     default:
178         debugError("Unsupported type for this command: %02X\n", getCommandType());
179         return false;
180     }
181     return true;   
182     return true;
183 }
184
185 bool
186 ReadDescriptorCmd::deserialize( IISDeserialize& de )
187 {
188     AVCCommand::deserialize( de );
189    
190     if(m_specifier==NULL) {
191         debugError("m_specifier==NULL");
192         return false;
193     }
194    
195     m_specifier->deserialize( de );
196    
197     switch (getCommandType()) {
198     case eCT_Control:
199         de.read( (byte_t *)&m_status );
200         de.read( (byte_t *)&m_reserved );
201         de.read( (uint16_t *)&m_data_length );
202         de.read( (uint16_t *)&m_address );
203        
204         if (getResponse()==eR_Accepted) {
205             if (m_data_length>0) {
206                 if (!de.read( (char **)&m_data, m_data_length )) {
207                     m_data=NULL;
208                     debugError("Could not read payload data");
209                     return false;
210                 }
211                
212             } else {
213                 debugWarning("Read descriptor command accepted but no payload data returned.\n");
214                 m_data=NULL;
215             }
216         }
217         break;
218     default:
219         debugError("Unsupported type for this command: %02X\n", getCommandType());
220         return false;
221     }
222
223     return true;
224 }
225
226 enum ReadDescriptorCmd::EReadStatus
227 ReadDescriptorCmd::getStatus()
228 {
229     switch(m_status) {
230         case 0x10: return eComplete;
231         case 0x11: return eMoreToRead;
232         case 0x12: return eTooLarge;
233         default: return eInvalid;
234     }
235 }
236
237 }
Note: See TracBrowser for help on using the browser.