root/trunk/libffado/src/libavc/descriptors/avc_descriptor_cmd.cpp

Revision 742, 6.3 kB (checked in by ppalmers, 13 years ago)

- Remove some obsolete support files and dirs

- Clean up the license statements in the source files. Everything is

GPL version 3 now.

- Add license and copyright notices to scons scripts

- Clean up some other text files

Line 
1 /*
2  * Copyright (C) 2005-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 program is free software: you can redistribute it and/or modify
11  * it under the terms of the GNU General Public License as published by
12  * the Free Software Foundation, either version 3 of the License, or
13  * (at your option) any later version.
14  *
15  * This program is distributed in the hope that it will be useful,
16  * but WITHOUT ANY WARRANTY; without even the implied warranty of
17  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
18  * GNU General Public License for more details.
19  *
20  * You should have received a copy of the GNU General Public License
21  * along with this program.  If not, see <http://www.gnu.org/licenses/>.
22  *
23  */
24
25 #include "avc_descriptor_cmd.h"
26 #include "avc_descriptor.h"
27 #include "libutil/cmd_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( Util::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( Util::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     delete[] m_data;
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     delete[] m_data;
155     m_data = NULL;
156     return true;
157 }
158
159 bool
160 ReadDescriptorCmd::serialize( Util::IOSSerialize& se )
161 {
162     AVCCommand::serialize( se );
163    
164     if(m_specifier==NULL) {
165         debugError("m_specifier==NULL");
166         return false;
167     }
168    
169     m_specifier->serialize( se );
170    
171     switch (getCommandType()) {
172     case eCT_Control:
173         se.write( (byte_t)m_status, "ReadDescriptorCmd read_result_status" );
174         se.write( (byte_t)m_reserved, "ReadDescriptorCmd reserved" );
175         se.write( (uint16_t)m_data_length, "ReadDescriptorCmd data_length" );
176         se.write( (uint16_t)m_address, "ReadDescriptorCmd address" );
177
178         break;
179     default:
180         debugError("Unsupported type for this command: %02X\n", getCommandType());
181         return false;
182     }
183     return true;
184 }
185
186 bool
187 ReadDescriptorCmd::deserialize( Util::IISDeserialize& de )
188 {
189     AVCCommand::deserialize( de );
190
191     if(m_specifier==NULL) {
192         debugError("m_specifier==NULL");
193         return false;
194     }
195
196     m_specifier->deserialize( de );
197
198     switch (getCommandType()) {
199     case eCT_Control:
200         de.read( (byte_t *)&m_status );
201         de.read( (byte_t *)&m_reserved );
202         de.read( (uint16_t *)&m_data_length );
203         de.read( (uint16_t *)&m_address );
204
205         if (getResponse()==eR_Accepted) {
206             if (m_data_length>0) {
207                 // the pointer returned by de.read is not valid outside this function
208                 // hence we copy the data to an internal buffer
209                 m_data = new byte_t[m_data_length];
210                 if(m_data == NULL) {
211                     debugError("Could not allocate memory for payload data");
212                     return false;
213                 }
214                 char * cmd_data = NULL;
215                 if (!de.read( (char **)&cmd_data, m_data_length )) {
216                     delete[] m_data;
217                     m_data = NULL;
218                     debugError("Could not read payload data");
219                     return false;
220                 }
221                 memcpy(m_data, cmd_data, m_data_length);
222
223             } else {
224                 debugWarning("Read descriptor command accepted but no payload data returned.\n");
225                 m_data=NULL;
226             }
227         }
228         break;
229     default:
230         debugError("Unsupported type for this command: %02X\n", getCommandType());
231         return false;
232     }
233
234     return true;
235 }
236
237 enum ReadDescriptorCmd::EReadStatus
238 ReadDescriptorCmd::getStatus()
239 {
240     switch(m_status) {
241         case 0x10: return eComplete;
242         case 0x11: return eMoreToRead;
243         case 0x12: return eTooLarge;
244         default: return eInvalid;
245     }
246 }
247
248 }
Note: See TracBrowser for help on using the browser.