File: downloader.cpp

package info (click to toggle)
libffado 2.4.9-3
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 9,604 kB
  • sloc: cpp: 77,151; python: 8,997; ansic: 2,951; sh: 1,429; xml: 855; makefile: 29
file content (139 lines) | stat: -rw-r--r-- 3,932 bytes parent folder | download | duplicates (3)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
/*
 * Copyright (C) 2005-2008 by Daniel Wagner
 * Copyright (C) 2005-2008 by Pieter Palmers
 *
 * This file is part of FFADO
 * FFADO = Free FireWire (pro-)audio drivers for Linux
 *
 * FFADO is based upon FreeBoB
 *
 * This program is free software: you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation, either version 2 of the License, or
 * (at your option) version 3 of the License.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program.  If not, see <http://www.gnu.org/licenses/>.
 *
 */

#include "config.h"

#include "downloader.h"

#include "libieee1394/configrom.h"
#include "libieee1394/ieee1394service.h"

#include "debugmodule/debugmodule.h"

#include <iostream>
#include <cstdlib>
#include <cstring>

using namespace std;

DECLARE_GLOBAL_DEBUG_MODULE;

static char args_doc[] = "OPERATION [ARGUMENTS]";
static struct argp _argp = { options, parse_opt, args_doc, doc }; 
struct argp* argp = &_argp;
static struct arguments _args = { {0}, };
struct arguments* args = &_args;

error_t
parse_opt( int key, char* arg, struct argp_state* state )
{
    // Get the input argument from `argp_parse', which we
    // know is a pointer to our arguments structure.
    struct arguments* arguments = ( struct arguments* ) state->input;
    
    char* tail;
    switch (key) {
    case 'v':
        if (arg) {
            arguments->verbose = strtol( arg, &tail, 0 );
            if ( errno ) {
                debugError( "Could not parse 'verbose' argument\n" );
                return ARGP_ERR_UNKNOWN;
            }
        }
        break;
    case 'p':
        errno = 0;
        arguments->port = strtol(arg, &tail, 0);
        if (errno) {
            debugError("argument parsing failed: %s\n",
                       strerror(errno));
            return errno;
        }
        break;
    case 'g':
        errno = 0;
        arguments->guid = strtoll(arg, &tail, 0);
        if (errno) {
            debugError("argument parsing failed: %s\n",
                       strerror(errno));
            return errno;
        }
        break;
    case 'm':
        errno = 0;
        arguments->magic = strtoll(arg, &tail, 0);
        if (errno) {
            debugError("argument parsing failed: %s\n",
                       strerror(errno));
            return errno;
        }
        break;
    case 'f':
        arguments->force = 1;
        break;
    case 'b':
        arguments->no_bootloader_restart = 1;
        break;
    case ARGP_KEY_ARG:
        if (state->arg_num >= MAX_NB_ARGS) {
            // Too many arguments.
            argp_usage (state);
        }
        
        arguments->args[state->arg_num] = arg;
        arguments->nargs = state->arg_num;
        break;
    case ARGP_KEY_END:
        arguments->nargs = state->arg_num;
        break;
    default:
        return ARGP_ERR_UNKNOWN;
    }
    return 0;
}

void 
printDeviceList()
{
    Ieee1394Service service;
    // switch off all messages since they mess up the list
    service.setVerboseLevel(0);
    if ( !service.initialize( args->port ) ) {
        cerr << "Could not initialize IEEE 1394 service" << endl;
        exit(-1);
    }

    cout << "Node id        GUID                  Vendor - Model" << endl;
    for (int i = 0; i < service.getNodeCount(); i++) {
        ConfigRom crom(service, i);
        if (!crom.initialize())
            break;

        cout << i << "             "
             << " 0x" <<  crom.getGuidString()
             << "    '" << crom.getVendorName()
             << "' - '" << crom.getModelName() << "'" << endl;
    }
}