root/branches/stable_0_2_0/libfreebob/src/libfreebobavc/avc_plug_info.cpp

Revision 161, 6.9 kB (checked in by anonymous, 18 years ago)

This commit was manufactured by cvs2svn to create branch 'stable_0_2_0'.

  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
Line 
1 /* avc_plug_info.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_plug_info.h"
22 #include "serialize.h"
23 #include "ieee1394service.h"
24
25 #include <netinet/in.h>
26 #include <iostream>
27
28 using namespace std;
29
30 PlugInfoCmd::PlugInfoCmd( Ieee1394Service* ieee1394service,
31                           ESubFunction eSubFunction )
32     : AVCCommand( ieee1394service, AVC1394_CMD_PLUG_INFO )
33     , m_serialBusIsochronousInputPlugs( 0xff )
34     , m_serialBusIsochronousOutputPlugs( 0xff )
35     , m_externalInputPlugs( 0xff )
36     , m_externalOutputPlugs( 0xff )
37     , m_serialBusAsynchronousInputPlugs( 0xff )
38     , m_serialBusAsynchronousOuputPlugs( 0xff )
39     , m_destinationPlugs( 0xff )
40     , m_sourcePlugs( 0xff )
41     , m_subFunction( eSubFunction )
42 {
43 }
44
45 PlugInfoCmd::~PlugInfoCmd()
46 {
47 }
48
49 bool
50 PlugInfoCmd::serialize( IOSSerialize& se )
51 {
52     byte_t reserved = 0xff;
53
54     AVCCommand::serialize( se );
55     se.write( m_subFunction, "PlugInfoCmd subFunction" );
56     switch( getSubunitType() ) {
57     case eST_Unit:
58         switch( m_subFunction ) {
59         case eSF_SerialBusIsochronousAndExternalPlug:
60             se.write( m_serialBusIsochronousInputPlugs, "PlugInfoCmd serialBusIsochronousInputPlugs" );
61             se.write( m_serialBusIsochronousOutputPlugs, "PlugInfoCmd serialBusIsochronousOutputPlugs" );
62             se.write( m_externalInputPlugs, "PlugInfoCmd externalInputPlugs" );
63             se.write( m_externalOutputPlugs, "PlugInfoCmd externalOutputPlugs" );
64             break;
65         case eSF_SerialBusAsynchonousPlug:
66             se.write( m_serialBusAsynchronousInputPlugs, "PlugInfoCmd serialBusAsynchronousInputPlugs" );
67             se.write( m_serialBusAsynchronousOuputPlugs, "PlugInfoCmd serialBusAsynchronousOuputPlugs" );
68             se.write( reserved, "PlugInfoCmd" );
69             se.write( reserved, "PlugInfoCmd" );
70             break;
71         default:
72             cerr << "Could not serialize with subfucntion " << m_subFunction << endl;
73             return false;
74         }
75         break;
76     default:
77         se.write( m_destinationPlugs, "PlugInfoCmd destinationPlugs" );
78         se.write( m_sourcePlugs, "PlugInfoCmd sourcePlugs" );
79         se.write( reserved, "PlugInfoCmd" );
80         se.write( reserved, "PlugInfoCmd" );
81     }
82     return true;
83 }
84
85 bool
86 PlugInfoCmd::deserialize( IISDeserialize& de )
87 {
88     byte_t reserved;
89
90     AVCCommand::deserialize( de );
91     de.read( &m_subFunction );
92     switch ( getSubunitType() ) {
93     case eST_Unit:
94         switch ( m_subFunction ) {
95         case eSF_SerialBusIsochronousAndExternalPlug:
96             de.read( &m_serialBusIsochronousInputPlugs );
97             de.read( &m_serialBusIsochronousOutputPlugs );
98             de.read( &m_externalInputPlugs );
99             de.read( &m_externalOutputPlugs );
100             break;
101         case eSF_SerialBusAsynchonousPlug:
102             de.read( &m_serialBusAsynchronousInputPlugs );
103             de.read( &m_serialBusAsynchronousOuputPlugs );
104             de.read( &reserved );
105             de.read( &reserved );
106             break;
107         default:
108             cerr << "Could not deserialize with subfunction " << m_subFunction << endl;
109             return false;
110         }
111         break;
112     default:
113         de.read( &m_destinationPlugs );
114         de.read( &m_sourcePlugs );
115         de.read( &reserved );
116         de.read( &reserved );
117     }
118     return true;
119 }
120
121 bool
122 PlugInfoCmd::fire()
123 {
124     bool result = false;
125
126     #define STREAM_FORMAT_REQUEST_SIZE 20 // XXX random length
127     union UPacket {
128         quadlet_t     quadlet[STREAM_FORMAT_REQUEST_SIZE];
129         unsigned char byte[STREAM_FORMAT_REQUEST_SIZE*4];
130     };
131     typedef union UPacket packet_t;
132
133     packet_t  req;
134     packet_t* resp;
135
136     // initialize complete packet
137     memset( &req,  0xff,  sizeof( req ) );
138
139     BufferSerialize se( req.byte, sizeof( req ) );
140     if ( !serialize( se ) ) {
141         printf(  "PlugInfoCmd::fire: Could not serialize\n" );
142         return false;
143     }
144
145     // reorder the bytes to the correct layout
146     for (int i = 0; i < STREAM_FORMAT_REQUEST_SIZE; ++i) {
147         req.quadlet[i] = ntohl( req.quadlet[i] );
148     }
149
150     if ( isVerbose() ) {
151         // debug output
152         puts("request:");
153         for (int i = 0; i < STREAM_FORMAT_REQUEST_SIZE; ++i) {
154             printf("  %2d: 0x%08x\n", i, req.quadlet[i]);
155         }
156     }
157
158     resp = reinterpret_cast<packet_t*>(
159         m_1394Service->transactionBlock( m_nodeId,
160                                          req.quadlet,
161                                          STREAM_FORMAT_REQUEST_SIZE ) );
162     if ( resp ) {
163         if ( isVerbose() ) {
164             // debug output
165             puts("response:");
166             for ( int i = 0; i < STREAM_FORMAT_REQUEST_SIZE; ++i ) {
167                 printf( "  %2d: 0x%08x\n", i, resp->quadlet[i] );
168             }
169         }
170
171         // reorder the bytes to the correct layout
172         for ( int i = 0; i < STREAM_FORMAT_REQUEST_SIZE; ++i ) {
173             resp->quadlet[i] = htonl( resp->quadlet[i] );
174         }
175
176         if ( isVerbose() ) {
177             // a more detailed debug output
178             printf( "\n" );
179             printf( " idx type                       value\n" );
180             printf( "-------------------------------------\n" );
181             printf( "  %02d                     ctype: 0x%02x\n", 0, resp->byte[0] );
182             printf( "  %02d subunit_type + subunit_id: 0x%02x\n", 1, resp->byte[1] );
183             printf( "  %02d                    opcode: 0x%02x\n", 2, resp->byte[2] );
184
185             for ( int i = 3; i < STREAM_FORMAT_REQUEST_SIZE * 4; ++i ) {
186                 printf( "  %02d                operand %2d: 0x%02x\n", i, i-3, resp->byte[i] );
187             }
188         }
189
190         // parse output
191         parseResponse( resp->byte[0] );
192         switch ( getResponse() )
193         {
194             case eR_Implemented:
195             {
196                 BufferDeserialize de( resp->byte, sizeof( req ) );
197                 deserialize( de );
198                 result = true;
199             }
200             break;
201             default:
202                 printf( "unexpected response received (0x%x)\n", getResponse() );
203         }
204     } else {
205         printf( "no response\n" );
206     }
207
208     return result;
209 }
210
211 bool
212 PlugInfoCmd::setSubFunction( ESubFunction subFunction )
213 {
214     m_subFunction = subFunction;
215     return true;
216 }
Note: See TracBrowser for help on using the browser.