tools: add playbook driver switch
[barry/progweb.git] / tools / bplaybook.cc
blobfdcb93c1637e8c2d86f762166f282451881eb7ab
1 ///
2 /// \file bplaybook.cc
3 /// bplaybook command line tool
4 ///
6 /*
7 Copyright (C) 2011, Nicolas VIVIEN
8 Copyright (C) 2005-2011, Net Direct Inc. (http://www.netdirect.ca/)
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) any later version.
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.
19 See the GNU General Public License in the COPYING file at the
20 root directory of this project for more details.
24 #include <barry/barry.h>
25 #include <iostream>
26 #include <string>
27 #include <stdlib.h>
28 #include "i18n.h"
30 #include "barrygetopt.h"
32 using namespace std;
33 using namespace Barry;
36 void Usage()
38 int logical, major, minor;
39 const char *Version = Barry::Version(logical, major, minor);
41 cerr
42 << "bplaybook - Command line USB Blackberry PlayBook\n"
43 << " Copyright 2011, Nicolas VIVIEN.\n"
44 << " Using: " << Version << "\n"
45 << "\n"
46 << " -h This help\n"
47 << " -v Dump protocol data during operation\n"
48 << "\n"
49 << endl;
53 int main(int argc, char *argv[], char *envp[])
55 INIT_I18N(PACKAGE);
57 try {
58 bool data_dump = false;
59 vector<string> params;
60 string iconvCharset;
62 // process command line options
63 for(;;) {
64 int cmd = getopt(argc, argv, "hv");
65 if( cmd == -1 )
66 break;
68 switch( cmd )
70 case 'v': // data dump on
71 data_dump = true;
72 break;
74 case 'h': // help
75 default:
76 Usage();
77 return 0;
81 argc -= optind;
82 argv += optind;
84 if( argc != 0 ) {
85 cerr << "unknown arguments" << endl;
86 Usage();
87 return 1;
90 // Initialize the barry library. Must be called before
91 // anything else.
92 Barry::Init(data_dump);
94 // Probe the USB bus for Blackberry devices and display.
95 // If user has specified a PIN, search for it in the
96 // available device list here as well
97 Barry::ProbePlayBook probe;
99 catch( Usb::Error &ue) {
100 std::cout << endl; // flush any normal output first
101 std::cerr << "Usb::Error caught: " << ue.what() << endl;
102 return 1;
104 catch( Barry::Error &se ) {
105 std::cout << endl;
106 std::cerr << "Barry::Error caught: " << se.what() << endl;
107 return 1;
109 catch( std::exception &e ) {
110 std::cout << endl;
111 std::cerr << "std::exception caught: " << e.what() << endl;
112 return 1;
115 return 0;