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

Revision 1234, 3.8 kB (checked in by holin, 13 years ago)

fix gcc 4.3 compile errors and some warnings (largely from Adrian Knoth)

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