root/trunk/libffado/support/firmware/downloader.cpp

Revision 1009, 3.5 kB (checked in by ppalmers, 16 years ago)

fiddle around with the argument parsing to ease the reuse by other firmware loaders

Line 
1 /*
2  * Copyright (C) 2005-2008 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  * This program 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) version 3 of the License.
13  *
14  * This program is distributed in the hope that it will be useful,
15  * but WITHOUT ANY WARRANTY; without even the implied warranty of
16  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
17  * GNU General Public License for more details.
18  *
19  * You should have received a copy of the GNU General Public License
20  * along with this program.  If not, see <http://www.gnu.org/licenses/>.
21  *
22  */
23
24 #include "downloader.h"
25
26 #include "libieee1394/configrom.h"
27 #include "libieee1394/ieee1394service.h"
28
29 #include "debugmodule/debugmodule.h"
30
31 #include <iostream>
32
33 #include <stdlib.h>
34
35 using namespace std;
36
37 DECLARE_GLOBAL_DEBUG_MODULE;
38
39 static char args_doc[] = "OPERATION [ARGUMENTS]";
40 static struct argp _argp = { options, parse_opt, args_doc, doc };
41 struct argp* argp = &_argp;
42 static struct arguments _args = { {0}, };
43 struct arguments* args = &_args;
44
45 error_t
46 parse_opt( int key, char* arg, struct argp_state* state )
47 {
48     // Get the input argument from `argp_parse', which we
49     // know is a pointer to our arguments structure.
50     struct arguments* arguments = ( struct arguments* ) state->input;
51    
52     char* tail;
53     switch (key) {
54     case 'v':
55         if (arg) {
56             arguments->verbose = strtol( arg, &tail, 0 );
57             if ( errno ) {
58                 debugError( "Could not parse 'verbose' argument\n" );
59                 return ARGP_ERR_UNKNOWN;
60             }
61         }
62         break;
63     case 'p':
64         errno = 0;
65         arguments->port = strtol(arg, &tail, 0);
66         if (errno) {
67             debugError("argument parsing failed: %s\n",
68                        strerror(errno));
69             return errno;
70         }
71         break;
72     case 'g':
73         errno = 0;
74         arguments->guid = strtoll(arg, &tail, 0);
75         if (errno) {
76             debugError("argument parsing failed: %s\n",
77                        strerror(errno));
78             return errno;
79         }
80         break;
81     case 'f':
82         arguments->force = 1;
83         break;
84     case 'b':
85         arguments->no_bootloader_restart = 1;
86         break;
87     case ARGP_KEY_ARG:
88         if (state->arg_num >= MAX_NB_ARGS) {
89             // Too many arguments.
90             argp_usage (state);
91         }
92        
93         arguments->args[state->arg_num] = arg;
94         arguments->nargs = state->arg_num;
95         break;
96     case ARGP_KEY_END:
97         arguments->nargs = state->arg_num;
98         break;
99     default:
100         return ARGP_ERR_UNKNOWN;
101     }
102     return 0;
103 }
104
105 void
106 printDeviceList()
107 {
108     Ieee1394Service service;
109     // switch off all messages since they mess up the list
110     service.setVerboseLevel(0);
111     if ( !service.initialize( args->port ) ) {
112         cerr << "Could not initialize IEEE 1394 service" << endl;
113         exit(-1);
114     }
115
116     cout << "Node id        GUID                  Vendor - Model" << endl;
117     for (int i = 0; i < service.getNodeCount(); i++) {
118         ConfigRom crom(service, i);
119         if (!crom.initialize())
120             break;
121
122         cout << i << "             "
123              << " 0x" <<  crom.getGuidString()
124              << "    '" << crom.getVendorName()
125              << "' - '" << crom.getModelName() << "'" << endl;
126     }
127 }
Note: See TracBrowser for help on using the browser.