root/trunk/libffado/tests/test-extplugcmd.cpp

Revision 445, 6.4 kB (checked in by pieterpalmers, 16 years ago)

* name change from FreeBoB to FFADO
* replaced tabs by 4 spaces
* got rid of end-of-line spaces
* made all license and copyrights conform

library becomes LGPL, apps become GPL
explicitly state LGPL v2.1 and GPL v2 (don't like v3 draft)

copyrights are 2005-2007 Daniel & Pieter
except for the MotU stuff (C) Jonathan, Pieter

  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
Line 
1 /*
2  * Copyright (C) 2005-2007 by Daniel Wagner
3  *
4  * This file is part of FFADO
5  * FFADO = Free Firewire (pro-)audio drivers for linux
6  *
7  * FFADO is based upon FreeBoB
8  *
9  * FFADO is free software; you can redistribute it and/or modify
10  * it under the terms of the GNU General Public License as published by
11  * the Free Software Foundation; either version 2 of the License, or
12  * (at your option) any later version.
13  * FFADO is distributed in the hope that it will be useful,
14  * but WITHOUT ANY WARRANTY; without even the implied warranty of
15  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
16  * GNU General Public License for more details.
17  *
18  * You should have received a copy of the GNU General Public License
19  * along with FFADO; if not, write to the Free Software
20  * Foundation, Inc., 59 Temple Place, Suite 330, Boston,
21  * MA 02111-1307 USA.
22  *
23  */
24
25 #include "libavc/avc_extended_plug_info.h"
26 #include "libavc/avc_plug_info.h"
27 #include "libavc/avc_serialize.h"
28
29 #include "libieee1394/configrom.h"
30 #include "libieee1394/ieee1394service.h"
31
32 #include <argp.h>
33
34 using namespace std;
35
36 ////////////////////////////////////////////////
37 // arg parsing
38 ////////////////////////////////////////////////
39 const char *argp_program_version = "test-extplugcmd 0.2";
40 const char *argp_program_bug_address = "<ffado-devel@lists.sf.net>";
41 static char doc[] = "test-extplugcmd -- tests some extended plug info commands on a BeBoB device";
42 static char args_doc[] = "NODE_ID";
43 static struct argp_option options[] = {
44     {"verbose",   'v', 0,           0,  "Produce verbose output" },
45     {"port",      'p', "PORT",      0,  "Set port" },
46    { 0 }
47 };
48
49 struct arguments
50 {
51     arguments()
52         : verbose( false )
53         , test( false )
54         , port( 0 )
55         {
56             args[0] = 0;
57         }
58
59     char* args[1];
60     bool  verbose;
61     bool  test;
62     int   port;
63 } arguments;
64
65 // Parse a single option.
66 static error_t
67 parse_opt( int key, char* arg, struct argp_state* state )
68 {
69     // Get the input argument from `argp_parse', which we
70     // know is a pointer to our arguments structure.
71     struct arguments* arguments = ( struct arguments* ) state->input;
72
73     char* tail;
74     switch (key) {
75     case 'v':
76         arguments->verbose = true;
77         break;
78     case 't':
79         arguments->test = true;
80         break;
81     case 'p':
82         errno = 0;
83         arguments->port = strtol(arg, &tail, 0);
84         if (errno) {
85             perror("argument parsing failed:");
86             return errno;
87         }
88         break;
89     case ARGP_KEY_ARG:
90         if (state->arg_num >= 1) {
91             // Too many arguments.
92             argp_usage (state);
93         }
94         arguments->args[state->arg_num] = arg;
95         break;
96     case ARGP_KEY_END:
97         if (state->arg_num < 1) {
98             // Not enough arguments.
99             argp_usage (state);
100         }
101         break;
102     default:
103         return ARGP_ERR_UNKNOWN;
104     }
105     return 0;
106 }
107
108 static struct argp argp = { options, parse_opt, args_doc, doc };
109
110 ////////////////////////////////////////
111 // Application
112 ////////////////////////////////////////
113
114 bool
115 doPlugType( Ieee1394Service& ieee1394service, int node_id )
116 {
117     ExtendedPlugInfoCmd extPlugInfoCmd( ieee1394service );
118     UnitPlugAddress unitPlugAddress( UnitPlugAddress::ePT_PCR, 0 );
119     extPlugInfoCmd.setPlugAddress( PlugAddress( PlugAddress::ePD_Input,
120                                                 PlugAddress::ePAM_Unit,
121                                                 unitPlugAddress ) );
122     extPlugInfoCmd.setNodeId( node_id );
123     extPlugInfoCmd.setCommandType( AVCCommand::eCT_Status );
124     extPlugInfoCmd.setVerbose( arguments.verbose );
125     ExtendedPlugInfoInfoType extendedPlugInfoInfoType( ExtendedPlugInfoInfoType::eIT_PlugType );
126     extendedPlugInfoInfoType.initialize();
127     extPlugInfoCmd.setInfoType( extendedPlugInfoInfoType );
128
129     if ( extPlugInfoCmd.fire() ) {
130         CoutSerializer se;
131         extPlugInfoCmd.serialize( se );
132     }
133
134     ExtendedPlugInfoInfoType* infoType = extPlugInfoCmd.getInfoType();
135     if ( infoType
136          && infoType->m_plugType )
137     {
138             plug_type_t plugType = infoType->m_plugType->m_plugType;
139
140             printf( "iso input plug %d is of type %d (%s)\n",
141                     0,
142                     plugType,
143                     extendedPlugInfoPlugTypeToString( plugType ) );
144     } else {
145         fprintf( stderr, "Not plug name specific data found\n" );
146         return false;
147     }
148
149     return true;
150 }
151
152
153 bool
154 doPlugName( Ieee1394Service& ieee1394service, int node_id )
155 {
156     ExtendedPlugInfoCmd extPlugInfoCmd( ieee1394service );
157     UnitPlugAddress unitPlugAddress( UnitPlugAddress::ePT_PCR, 0 );
158     extPlugInfoCmd.setPlugAddress( PlugAddress( PlugAddress::ePD_Input,
159                                                 PlugAddress::ePAM_Unit,
160                                                 unitPlugAddress ) );
161     extPlugInfoCmd.setNodeId( node_id );
162     extPlugInfoCmd.setCommandType( AVCCommand::eCT_Status );
163     extPlugInfoCmd.setVerbose( arguments.verbose );
164     ExtendedPlugInfoInfoType extendedPlugInfoInfoType( ExtendedPlugInfoInfoType::eIT_PlugName );
165     extendedPlugInfoInfoType.initialize();
166     extPlugInfoCmd.setInfoType( extendedPlugInfoInfoType );
167
168     if ( extPlugInfoCmd.fire() ) {
169         CoutSerializer se;
170         extPlugInfoCmd.serialize( se );
171     }
172
173     ExtendedPlugInfoInfoType* infoType = extPlugInfoCmd.getInfoType();
174     if ( infoType
175          && infoType->m_plugName )
176     {
177         printf( "iso input plug %d has name '%s'\n",
178                 0,
179                infoType->m_plugName->m_name.c_str() );
180     } else {
181         fprintf( stderr, "Not plug name specific data found\n" );
182         return false;
183     }
184
185     return true;
186 }
187
188 bool
189 doApp(Ieee1394Service& ieee1394service, int node_id )
190 {
191     bool success;
192
193     success = doPlugType( ieee1394service, node_id );
194     success &= doPlugName( ieee1394service, node_id );
195
196     return success;
197 }
198
199 ///////////////////////////
200 // main
201 //////////////////////////
202 int
203 main(int argc, char **argv)
204 {
205     // arg parsing
206     argp_parse (&argp, argc, argv, 0, 0, &arguments);
207
208     errno = 0;
209     char* tail;
210     int node_id = strtol(arguments.args[0], &tail, 0);
211     if (errno) {
212     perror("argument parsing failed:");
213     return -1;
214     }
215     Ieee1394Service ieee1394service;
216     if ( !ieee1394service.initialize( arguments.port ) ) {
217         fprintf( stderr, "could not set port on ieee1394service\n" );
218         return -1;
219     }
220
221     doApp( ieee1394service, node_id );
222
223     return 0;
224 }
Note: See TracBrowser for help on using the browser.