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