root/branches/streaming-rework/tests/test-extplugcmd.cpp

Revision 413, 6.3 kB (checked in by pieterpalmers, 16 years ago)

- moved all generic IEEE1394 classes into libieee1394

src/libieee1394/ieee1394service.h
src/libieee1394/csr1212.h
src/libieee1394/configrom.cpp
src/libieee1394/configrom.h
src/libieee1394/ieee1394service.cpp
src/libieee1394/csr1212.c

  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
Line 
1 /* test-extplugcmd.cpp
2  * Copyright (C) 2005,06 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 "libfreebobavc/avc_extended_plug_info.h"
22 #include "libfreebobavc/avc_plug_info.h"
23 #include "libfreebobavc/avc_serialize.h"
24
25 #include "libieee1394/configrom.h"
26 #include "libieee1394/ieee1394service.h"
27
28 #include <argp.h>
29
30 using namespace std;
31
32 ////////////////////////////////////////////////
33 // arg parsing
34 ////////////////////////////////////////////////
35 const char *argp_program_version = "test-extplugcmd 0.2";
36 const char *argp_program_bug_address = "<freebob-devel@lists.sf.net>";
37 static char doc[] = "test-extplugcmd -- tests some extended plug info commands on a BeBoB device";
38 static char args_doc[] = "NODE_ID";
39 static struct argp_option options[] = {
40     {"verbose",   'v', 0,           0,  "Produce verbose output" },
41     {"port",      'p', "PORT",      0,  "Set port" },
42    { 0 }
43 };
44
45 struct arguments
46 {
47     arguments()
48         : verbose( false )
49         , test( false )
50         , port( 0 )
51         {
52             args[0] = 0;
53         }
54
55     char* args[1];
56     bool  verbose;
57     bool  test;
58     int   port;
59 } arguments;
60
61 // Parse a single option.
62 static error_t
63 parse_opt( int key, char* arg, struct argp_state* state )
64 {
65     // Get the input argument from `argp_parse', which we
66     // know is a pointer to our arguments structure.
67     struct arguments* arguments = ( struct arguments* ) state->input;
68
69     char* tail;
70     switch (key) {
71     case 'v':
72         arguments->verbose = true;
73         break;
74     case 't':
75         arguments->test = true;
76         break;
77     case 'p':
78         errno = 0;
79         arguments->port = strtol(arg, &tail, 0);
80         if (errno) {
81             perror("argument parsing failed:");
82             return errno;
83         }
84         break;
85     case ARGP_KEY_ARG:
86         if (state->arg_num >= 1) {
87             // Too many arguments.
88             argp_usage (state);
89         }
90         arguments->args[state->arg_num] = arg;
91         break;
92     case ARGP_KEY_END:
93         if (state->arg_num < 1) {
94             // Not enough arguments.
95             argp_usage (state);
96         }
97         break;
98     default:
99         return ARGP_ERR_UNKNOWN;
100     }
101     return 0;
102 }
103
104 static struct argp argp = { options, parse_opt, args_doc, doc };
105
106 ////////////////////////////////////////
107 // Application
108 ////////////////////////////////////////
109
110 bool
111 doPlugType( Ieee1394Service& ieee1394service, int node_id )
112 {
113     ExtendedPlugInfoCmd extPlugInfoCmd( ieee1394service );
114     UnitPlugAddress unitPlugAddress( UnitPlugAddress::ePT_PCR, 0 );
115     extPlugInfoCmd.setPlugAddress( PlugAddress( PlugAddress::ePD_Input,
116                                                 PlugAddress::ePAM_Unit,
117                                                 unitPlugAddress ) );
118     extPlugInfoCmd.setNodeId( node_id );
119     extPlugInfoCmd.setCommandType( AVCCommand::eCT_Status );
120     extPlugInfoCmd.setVerbose( arguments.verbose );
121     ExtendedPlugInfoInfoType extendedPlugInfoInfoType( ExtendedPlugInfoInfoType::eIT_PlugType );
122     extendedPlugInfoInfoType.initialize();
123     extPlugInfoCmd.setInfoType( extendedPlugInfoInfoType );
124
125     if ( extPlugInfoCmd.fire() ) {
126         CoutSerializer se;
127         extPlugInfoCmd.serialize( se );
128     }
129
130     ExtendedPlugInfoInfoType* infoType = extPlugInfoCmd.getInfoType();
131     if ( infoType
132          && infoType->m_plugType )
133     {
134             plug_type_t plugType = infoType->m_plugType->m_plugType;
135
136             printf( "iso input plug %d is of type %d (%s)\n",
137                     0,
138                     plugType,
139                     extendedPlugInfoPlugTypeToString( plugType ) );
140     } else {
141         fprintf( stderr, "Not plug name specific data found\n" );
142         return false;
143     }
144
145     return true;
146 }
147
148
149 bool
150 doPlugName( Ieee1394Service& ieee1394service, int node_id )
151 {
152     ExtendedPlugInfoCmd extPlugInfoCmd( ieee1394service );
153     UnitPlugAddress unitPlugAddress( UnitPlugAddress::ePT_PCR, 0 );
154     extPlugInfoCmd.setPlugAddress( PlugAddress( PlugAddress::ePD_Input,
155                                                 PlugAddress::ePAM_Unit,
156                                                 unitPlugAddress ) );
157     extPlugInfoCmd.setNodeId( node_id );
158     extPlugInfoCmd.setCommandType( AVCCommand::eCT_Status );
159     extPlugInfoCmd.setVerbose( arguments.verbose );
160     ExtendedPlugInfoInfoType extendedPlugInfoInfoType( ExtendedPlugInfoInfoType::eIT_PlugName );
161     extendedPlugInfoInfoType.initialize();
162     extPlugInfoCmd.setInfoType( extendedPlugInfoInfoType );
163
164     if ( extPlugInfoCmd.fire() ) {
165         CoutSerializer se;
166         extPlugInfoCmd.serialize( se );
167     }
168
169     ExtendedPlugInfoInfoType* infoType = extPlugInfoCmd.getInfoType();
170     if ( infoType
171          && infoType->m_plugName )
172     {
173         printf( "iso input plug %d has name '%s'\n",
174                 0,
175                infoType->m_plugName->m_name.c_str() );
176     } else {
177         fprintf( stderr, "Not plug name specific data found\n" );
178         return false;
179     }
180
181     return true;
182 }
183
184 bool
185 doApp(Ieee1394Service& ieee1394service, int node_id )
186 {
187     bool success;
188
189     success = doPlugType( ieee1394service, node_id );
190     success &= doPlugName( ieee1394service, node_id );
191
192     return success;
193 }
194
195 ///////////////////////////
196 // main
197 //////////////////////////
198 int
199 main(int argc, char **argv)
200 {
201     // arg parsing
202     argp_parse (&argp, argc, argv, 0, 0, &arguments);
203
204     errno = 0;
205     char* tail;
206     int node_id = strtol(arguments.args[0], &tail, 0);
207     if (errno) {
208         perror("argument parsing failed:");
209         return -1;
210     }
211     Ieee1394Service ieee1394service;
212     if ( !ieee1394service.initialize( arguments.port ) ) {
213         fprintf( stderr, "could not set port on ieee1394service\n" );
214         return -1;
215     }
216
217     doApp( ieee1394service, node_id );
218
219     return 0;
220 }
Note: See TracBrowser for help on using the browser.