Revision 418, 1.2 kB
(checked in by pieterpalmers, 17 years ago)
|
added serialization support to the OptionContainer?
|
Line | |
---|
1 |
#include "devicemanager.h" |
---|
2 |
#include "libutil/serialize.h" |
---|
3 |
|
---|
4 |
#include <iostream> |
---|
5 |
|
---|
6 |
const char FileName[] = "serialize-test.xml"; |
---|
7 |
|
---|
8 |
static bool |
---|
9 |
serialize( const char* pFileName, int port ) |
---|
10 |
{ |
---|
11 |
DeviceManager devMgr; |
---|
12 |
if (!devMgr.initialize( port )) { |
---|
13 |
std::cerr << "could not init DeviceManager" << std::endl; |
---|
14 |
return false; |
---|
15 |
} |
---|
16 |
if (!devMgr.discover( 0 )) { |
---|
17 |
std::cerr << "could not discover devices" << std::endl; |
---|
18 |
return false; |
---|
19 |
} |
---|
20 |
return devMgr.saveCache( pFileName ); |
---|
21 |
} |
---|
22 |
|
---|
23 |
static bool |
---|
24 |
deserialize( const char* pFileName ) |
---|
25 |
{ |
---|
26 |
DeviceManager devMgr; |
---|
27 |
if (!devMgr.initialize( 0 )) { |
---|
28 |
std::cerr << "could not init DeviceManager" << std::endl; |
---|
29 |
return false; |
---|
30 |
} |
---|
31 |
return devMgr.loadCache( pFileName ); |
---|
32 |
} |
---|
33 |
|
---|
34 |
int |
---|
35 |
main( int argc, char** argv ) |
---|
36 |
{ |
---|
37 |
int port=0; |
---|
38 |
if (argc==2) { |
---|
39 |
port=atoi(argv[1]); |
---|
40 |
} |
---|
41 |
|
---|
42 |
if ( !serialize( FileName, port ) ) { |
---|
43 |
std::cerr << "serializing failed" << std::endl; |
---|
44 |
return -1; |
---|
45 |
} |
---|
46 |
if ( !deserialize( FileName ) ) { |
---|
47 |
std::cerr << "deserializing failed" << std::endl; |
---|
48 |
return -1; |
---|
49 |
} |
---|
50 |
|
---|
51 |
std::cout << "passed" << std::endl; |
---|
52 |
return 0; |
---|
53 |
} |
---|