Fawkes API
Fawkes Development Version
Main Page
Related Pages
Modules
Namespaces
Classes
Files
File List
All
Classes
Namespaces
Functions
Variables
Typedefs
Enumerations
Enumerator
Friends
Groups
Pages
qa_config_change_handler.cpp
1
2
/***************************************************************************
3
* qa_config_change_handler.cpp - QA for configuration change handlers
4
*
5
* Created: Mon Nov 12 19:11:06 2007
6
* Copyright 2006-2007 Tim Niemueller [www.niemueller.de]
7
*
8
****************************************************************************/
9
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. A runtime exception applies to
14
* this software (see LICENSE.GPL_WRE file mentioned below for details).
15
*
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. See the
19
* GNU Library General Public License for more details.
20
*
21
* Read the full text in the LICENSE.GPL_WRE file in the doc directory.
22
*/
23
24
/// @cond QA
25
26
#include <config/sqlite.h>
27
28
#include <iostream>
29
#include <cstdio>
30
31
32
using namespace
std;
33
using namespace
fawkes;
34
35
class
QAConfigChangeHandler :
public
ConfigurationChangeHandler
36
{
37
public
:
38
QAConfigChangeHandler() :
ConfigurationChangeHandler
(
"/testing"
) {}
39
40
virtual
void
41
config_tag_changed(
const
char
*new_tag)
42
{
43
printf(
"CCH: New tag '%s'\n"
, new_tag);
44
}
45
46
virtual
void
47
config_value_changed(
const
Configuration::ValueIterator
*v)
48
{
49
if
(v->
is_string
()) {
50
printf(
"CCH: String '%s' changed to %s\n"
,
51
v->
path
(), v->
get_string
().c_str());
52
}
else
if
(v->
is_bool
()) {
53
printf(
"CCH: Bool '%s' changed to %i\n"
, v->
path
(), v->
get_bool
());
54
}
else
if
(v->
is_int
()) {
55
printf(
"CCH: Integer '%s' changed to %i\n"
, v->
path
(), v->
get_int
());
56
}
else
if
(v->
is_uint
()) {
57
printf(
"CCH: Unsigned Integer '%s' changed to %u\n"
,
58
v->
path
(), v->
get_uint
());
59
}
else
if
(v->
is_float
()) {
60
printf(
"CCH: Float '%s' changed to %f\n"
, v->
path
(), v->
get_float
());
61
}
62
}
63
64
virtual
void
65
config_comment_changed(
const
Configuration::ValueIterator
*v)
66
{
67
printf(
"CCH: Comment of '%s' changed to %s\n"
,
68
v->
path
(), v->
get_comment
().c_str());
69
}
70
71
72
virtual
void
73
config_value_erased(
const
char
*path)
74
{
75
printf(
"CCH: Value '%s' erased\n"
, path);
76
}
77
78
};
79
80
int
81
main(
int
argc,
char
**argv)
82
{
83
SQLiteConfiguration
*config =
new
SQLiteConfiguration
(CONFDIR);
84
85
QAConfigChangeHandler qach;
86
config->
add_change_handler
(&qach);
87
88
try
{
89
cout <<
"Loading configuration..."
<< flush;
90
config->
load
(
"qa.db"
,
"qa_defaults.db"
);
91
cout <<
"done"
<< endl;
92
}
catch
(
CouldNotOpenConfigException
&e) {
93
cout <<
"failed"
<< endl;
94
e.
print_trace
();
95
}
96
97
try
{
98
float
of = 5.234;
99
cout <<
"[FLOAT] set f="
<< of <<
"..."
<< endl;
100
config->
set_float
(
"/testing/float"
, of);
101
cout <<
"[FLOAT] get..."
<< endl;
102
float
f = config->
get_float
(
"/testing/float"
);
103
printf(
"done, f=%f\n"
, f);
104
}
catch
(
ConfigurationException
&e) {
105
cout <<
"failed"
<< endl;
106
e.
print_trace
();
107
}
108
109
try
{
110
unsigned
int
ou = 6;
111
cout <<
"[UINT] set u="
<< ou <<
"..."
<< endl;
112
config->
set_uint
(
"/testing/uint"
, ou);
113
cout <<
"[UINT] get..."
<< endl;
114
unsigned
int
u = config->
get_uint
(
"/testing/uint"
);
115
printf(
"done, u=%u\n"
, u);
116
}
catch
(
ConfigurationException
&e) {
117
cout <<
"failed"
<< endl;
118
e.
print_trace
();
119
}
120
121
try
{
122
int
oi = -7;
123
cout <<
"[INT] set i="
<< oi <<
"..."
<< endl;
124
config->
set_int
(
"/testing/int"
, oi);
125
cout <<
"[INT] get..."
<< endl;
126
int
i = config->
get_int
(
"/testing/int"
);
127
printf(
"done, i=%i\n"
, i);
128
}
catch
(
ConfigurationException
&e) {
129
cout <<
"failed"
<< endl;
130
e.
print_trace
();
131
}
132
133
try
{
134
bool
ob =
true
;
135
cout <<
"[BOOL] set b="
<< ob <<
"..."
<< endl;
136
config->
set_bool
(
"/testing/bool"
, ob);
137
cout <<
"[BOOL] get..."
<< endl;
138
bool
b = config->
get_bool
(
"/testing/bool"
);
139
printf(
"done, b=%s\n"
, (b ?
"true"
:
"false"
));
140
}
catch
(
ConfigurationException
&e) {
141
cout <<
"failed"
<< endl;
142
e.
print_trace
();
143
}
144
145
try
{
146
string
os =
"This ain't no paradoxon"
;
147
cout <<
"[STRING] set s='"
<< os <<
"'..."
<< endl;
148
config->
set_string
(
"/testing/string"
, os);
149
cout <<
"[STRING] get..."
<< endl;
150
string
s = config->
get_string
(
"/testing/string"
);
151
printf(
"done, s='%s'\n"
, s.c_str());
152
}
catch
(
ConfigurationException
&e) {
153
cout <<
"failed"
<< endl;
154
e.
print_trace
();
155
}
156
157
try
{
158
cout <<
"[EXIST] Checking if test string exists..."
<< endl;
159
if
( config->
exists
(
"/testing/string"
) ) {
160
cout <<
"success"
;
161
}
else
{
162
cout <<
"failed"
;
163
}
164
cout << endl;
165
}
catch
(
ConfigurationException
&e) {
166
cout <<
"failed"
<< endl;
167
e.
print_trace
();
168
}
169
170
try
{
171
string
os =
"This ain't no paradoxon"
;
172
cout <<
"[LONGSTRING] set s='"
<< os <<
"'..."
<< endl;
173
config->
set_string
(
"/testing/veryveryveryverylongstring"
, os);
174
cout <<
"[LONGSTRING] get..."
<< endl;
175
string
s = config->
get_string
(
"/testing/veryveryveryverylongstring"
);
176
printf(
"done, s='%s'\n"
, s.c_str());
177
}
catch
(
ConfigurationException
&e) {
178
cout <<
"failed"
<< endl;
179
e.
print_trace
();
180
}
181
182
cout <<
"[ERASE] erasing all values"
<< endl;
183
config->
erase
(
"/testing/float"
);
184
config->
erase
(
"/testing/uint"
);
185
config->
erase
(
"/testing/int"
);
186
config->
erase
(
"/testing/bool"
);
187
config->
erase
(
"/testing/string"
);
188
config->
erase
(
"/testing/veryveryveryverylongstring"
);
189
190
config->
rem_change_handler
(&qach);
191
192
delete
config;
193
194
return
0;
195
}
196
197
198
199
/// @endcond
src
libs
config
qa
qa_config_change_handler.cpp
Generated by
1.8.1.2