lib: simplified parser and builder API, using the new DBData class
[barry.git] / tools / bidentify.cc
blobdc6c25b1eb7890fd576f90c1a769adfec955da36
1 ///
2 /// \file bidentify.cc
3 /// Tool for probing identifying Blackberry devices
4 ///
6 /*
7 Copyright (C) 2005-2010, Net Direct Inc. (http://www.netdirect.ca/)
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) any later version.
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.
18 See the GNU General Public License in the COPYING file at the
19 root directory of this project for more details.
22 #include <barry/barry.h>
23 #include <iostream>
24 #include <iomanip>
25 #include <getopt.h>
26 #include "i18n.h"
28 using namespace std;
29 using namespace Barry;
31 void Usage()
33 int major, minor;
34 const char *Version = Barry::Version(major, minor);
36 cerr
37 << "bidentify - USB Blackberry Identifier Tool\n"
38 << " Copyright 2005-2010, Net Direct Inc. (http://www.netdirect.ca/)\n"
39 << " Using: " << Version << "\n"
40 << "\n"
41 << " -B bus Specify which USB bus to search on\n"
42 << " -N dev Specify which system device, using system specific string\n"
43 << "\n"
44 << " -h This help\n"
45 << " -v Dump protocol data during operation\n"
46 << endl;
49 int main(int argc, char *argv[])
51 INIT_I18N(PACKAGE);
53 cout.sync_with_stdio(true); // leave this on, since libusb uses
54 // stdio for debug messages
56 try {
58 bool data_dump = false;
59 string busname;
60 string devname;
62 // process command line options
63 for(;;) {
64 int cmd = getopt(argc, argv, "B:hN:v");
65 if( cmd == -1 )
66 break;
68 switch( cmd )
70 case 'B': // busname
71 busname = optarg;
72 break;
74 case 'N': // Devname
75 devname = optarg;
76 break;
78 case 'v': // data dump on
79 data_dump = true;
80 break;
82 case 'h': // help
83 default:
84 Usage();
85 return 0;
89 Barry::Init(data_dump);
90 Barry::Probe probe(busname.c_str(), devname.c_str());
92 // show any errors during probe first
93 if( probe.GetFailCount() ) {
94 cerr << "Blackberry device errors with errors during probe:" << endl;
95 for( int i = 0; i < probe.GetFailCount(); i++ ) {
96 cerr << probe.GetFailMsg(i) << endl;
100 // show all successfully found devices
101 for( int i = 0; i < probe.GetCount(); i++ ) {
102 const ProbeResult &pr = probe.Get(i);
103 cout << pr.m_pin.str() << ", "
104 << pr.m_description << endl;
107 return probe.GetFailCount();
110 catch( std::exception &e ) {
111 cerr << "exception caught: " << e.what() << endl;
112 return 1;