3 /// Example code using the Barry library to dump all
4 /// device databases to stdout, using all known parsers,
5 /// and hex dumps for the rest.
9 Copyright (C) 2011, Net Direct Inc. (http://www.netdirect.ca/)
11 This program is free software; you can redistribute it and/or modify
12 it under the terms of the GNU General Public License as published by
13 the Free Software Foundation; either version 2 of the License, or
14 (at your option) any later version.
16 This program is distributed in the hope that it will be useful,
17 but WITHOUT ANY WARRANTY; without even the implied warranty of
18 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
20 See the GNU General Public License in the COPYING file at the
21 root directory of this project for more details.
24 #include <barry/barry.h>
29 using namespace Barry
;
31 template <class RecordT
>
35 void operator() (const RecordT
&rec
)
37 cout
<< RecordT::GetDBName() << ": "
38 << hex
<< rec
.GetUniqueId() << endl
;
42 class UnknownParser
: public Parser
45 void ParseRecord(const DBData
&data
, const IConverter
*ic
)
47 cout
<< "Unknown record of "
48 << dec
<< data
.GetData().GetSize()
55 int main(int argc
, char *argv
[])
61 int i
= probe
.FindActive();
63 cout
<< "No device available" << endl
;
68 Controller
con(probe
.Get(i
));
69 Mode::Desktop
desktop(con
);
70 desktop
.Open(); // specify password here if needed
72 // create builder object to extract records from the
73 // device, and add all database names to the builder
74 DeviceBuilder
builder(desktop
);
75 const DatabaseDatabase
&dbdb
= desktop
.GetDBDB();
76 DatabaseDatabase::DatabaseArrayType::const_iterator
77 b
= dbdb
.Databases
.begin(), e
= dbdb
.Databases
.end();
78 for( ; b
!= e
; ++b
) {
79 builder
.Add( b
->Name
);
82 // create the parser, and use stdout dump objects for output
83 AllRecordParser
parser(cout
,
84 new HexDumpParser(cout
),
85 new AllRecordDumpStore(cout
));
87 // create the pipe to connect builder to parser and
90 pipe
.PumpFile(parser
);
92 cout
<< "\n\n\nStarting again....................." << endl
;
94 // run it again, but this time with custom set of
95 // record parsers and default parser
97 MultiRecordParser
mrp( new UnknownParser
);
99 // add a few known record types... first, the manual way
100 mrp
.Add( Contact::GetDBName(),
101 new RecordParser
<Contact
, Store
<Contact
> >(
102 new Store
<Contact
>));
103 // and with the template member (does the same thing)
104 mrp
.Add
<Calendar
>( new Store
<Calendar
> );
105 mrp
.Add
<Sms
>( new Store
<Sms
> );
106 mrp
.Add
<Timezone
>( new Store
<Timezone
> );
111 // and one more time, with a tee
112 cout
<< "\n\n\nStarting again with a tee............" << endl
;
122 catch( exception
&e
) {
123 cerr
<< e
.what() << endl
;