Fawkes API Fawkes Development Version
netconf.h
1
2/***************************************************************************
3 * netconf.h - Fawkes remote configuration access via Fawkes net
4 *
5 * Created: Sun Jan 07 15:01:50 2007
6 * Copyright 2006-2009 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#ifndef _CONFIG_NETCONF_H_
25#define _CONFIG_NETCONF_H_
26
27#include <config/config.h>
28#include <core/exception.h>
29#include <netcomm/fawkes/client_handler.h>
30
31#include <list>
32#include <map>
33#include <stdint.h>
34#include <string>
35
36namespace fawkes {
37
38class Mutex;
39class InterruptibleBarrier;
40class FawkesNetworkClient;
41class MemoryConfiguration;
42
44{
45public:
46 CannotEnableMirroringException(const char *msg);
47};
48
50{
51public:
52 NetworkConfiguration(FawkesNetworkClient *c, unsigned int mirror_timeout_sec = 15);
53 virtual ~NetworkConfiguration();
54
55 virtual void copy(Configuration *copyconf);
56
59
60 virtual void load(const char *file_path);
61
62 virtual bool exists(const char *path);
63 virtual bool is_float(const char *path);
64 virtual bool is_uint(const char *path);
65 virtual bool is_int(const char *path);
66 virtual bool is_bool(const char *path);
67 virtual bool is_string(const char *path);
68 virtual bool is_list(const char *path);
69
70 virtual bool is_default(const char *path);
71
72 virtual float get_float(const char *path);
73 virtual unsigned int get_uint(const char *path);
74 virtual int get_int(const char *path);
75 virtual bool get_bool(const char *path);
76 virtual std::string get_string(const char *path);
77 virtual std::vector<float> get_floats(const char *path);
78 virtual std::vector<unsigned int> get_uints(const char *path);
79 virtual std::vector<int> get_ints(const char *path);
80 virtual std::vector<bool> get_bools(const char *path);
81 virtual std::vector<std::string> get_strings(const char *path);
82 virtual ValueIterator * get_value(const char *path);
83 virtual std::string get_comment(const char *path);
84 virtual std::string get_default_comment(const char *path);
85 virtual std::string get_type(const char *path);
86
87 virtual void set_float(const char *path, float f);
88 virtual void set_uint(const char *path, unsigned int uint);
89 virtual void set_int(const char *path, int i);
90 virtual void set_bool(const char *path, bool b);
91 virtual void set_string(const char *path, std::string &s);
92 virtual void set_string(const char *path, const char *s);
93 virtual void set_floats(const char *path, std::vector<float> &f);
94 virtual void set_uints(const char *path, std::vector<unsigned int> &uint);
95 virtual void set_ints(const char *path, std::vector<int> &i);
96 virtual void set_bools(const char *path, std::vector<bool> &b);
97 virtual void set_strings(const char *path, std::vector<std::string> &s);
98 virtual void set_strings(const char *path, std::vector<const char *> &s);
99 virtual void set_comment(const char *path, std::string &comment);
100 virtual void set_comment(const char *path, const char *comment);
101
102 virtual void erase(const char *path);
103
104 virtual void set_default_float(const char *path, float f);
105 virtual void set_default_uint(const char *path, unsigned int uint);
106 virtual void set_default_int(const char *path, int i);
107 virtual void set_default_bool(const char *path, bool b);
108 virtual void set_default_string(const char *path, std::string &s);
109 virtual void set_default_string(const char *path, const char *s);
110 virtual void set_default_comment(const char *path, std::string &comment);
111 virtual void set_default_comment(const char *path, const char *comment);
112
113 virtual void erase_default(const char *path);
114
115 virtual void deregistered(unsigned int id) noexcept;
116 virtual void inbound_received(FawkesNetworkMessage *msg, unsigned int id) noexcept;
117 virtual void connection_died(unsigned int id) noexcept;
118 virtual void connection_established(unsigned int id) noexcept;
119
120 virtual void set_mirror_mode(bool mirror);
121
123 {
125
126 protected:
130
131 public:
132 virtual ~NetConfValueIterator();
133 virtual bool next();
134 virtual bool valid() const;
135
136 virtual const char *path() const;
137 virtual const char *type() const;
138
139 virtual bool is_float() const;
140 virtual bool is_uint() const;
141 virtual bool is_int() const;
142 virtual bool is_bool() const;
143 virtual bool is_string() const;
144 virtual bool is_list() const;
145 virtual size_t get_list_size() const;
146
147 virtual bool is_default() const;
148
149 virtual float get_float() const;
150 virtual unsigned int get_uint() const;
151 virtual int get_int() const;
152 virtual bool get_bool() const;
153 virtual std::string get_string() const;
154 virtual std::vector<float> get_floats() const;
155 virtual std::vector<unsigned int> get_uints() const;
156 virtual std::vector<int> get_ints() const;
157 virtual std::vector<bool> get_bools() const;
158 virtual std::vector<std::string> get_strings() const;
159 virtual std::string get_as_string() const;
160
161 virtual std::string get_comment() const;
162
163 private:
166 bool iterated_once;
167 char * _path;
168 };
169
173 ValueIterator *search(const char *path);
174
175 void lock();
176 bool try_lock();
177 void unlock();
178
179 virtual void try_dump();
180
181private:
182 void send_get(const char *path, unsigned int msgid, unsigned int expected_reply);
183
184 void set_value_internal(unsigned int msg_type,
185 const char * path,
186 uint16_t num_values,
187 size_t data_size,
188 void * data);
189
190 void erase_internal(const char *path, bool is_default);
191
194 Mutex * mutex;
195 bool mirror_init_waiting_;
196 InterruptibleBarrier *mirror_init_barrier_;
197
198 bool mirror_mode_;
199 bool mirror_mode_before_connection_dead_;
200 unsigned int mirror_timeout_sec_;
201 MemoryConfiguration *mirror_config;
202
203 bool connected_;
204};
205
206} // end namespace fawkes
207
208#endif
Thrown if enabling mirror mode failed.
Definition: netconf.h:44
CannotEnableMirroringException(const char *msg)
Constructor.
Definition: netconf.cpp:51
Interface for configuration change handling.
Iterator interface to iterate over config values.
Definition: config.h:75
Interface for configuration handling.
Definition: config.h:68
Base class for exceptions in Fawkes.
Definition: exception.h:36
Message handler for FawkesNetworkClient.
Simple Fawkes network client.
Definition: client.h:52
Representation of a message that is sent over the network.
Definition: message.h:77
A barrier is a synchronization tool which blocks until a given number of threads have reached the bar...
In-memory configuration store.
Definition: memory.h:39
Mutex mutual exclusion lock.
Definition: mutex.h:33
Network configuration value iterator.
Definition: netconf.h:123
virtual bool is_bool() const
Check if current value is a bool.
Definition: netconf.cpp:1555
virtual std::vector< float > get_floats() const
Get list of values from configuration which is of type float.
Definition: netconf.cpp:1748
virtual std::string get_as_string() const
Get value as string.
Definition: netconf.cpp:1901
virtual size_t get_list_size() const
Get number of elements in list value.
Definition: netconf.cpp:1595
virtual std::vector< unsigned int > get_uints() const
Get list of values from configuration which is of type unsigned int.
Definition: netconf.cpp:1778
virtual bool is_string() const
Check if current value is a string.
Definition: netconf.cpp:1568
virtual std::vector< bool > get_bools() const
Get list of values from configuration which is of type bool.
Definition: netconf.cpp:1838
virtual bool is_int() const
Check if current value is a int.
Definition: netconf.cpp:1542
virtual bool valid() const
Check if the current element is valid.
Definition: netconf.cpp:1475
virtual bool get_bool() const
Get bool value.
Definition: netconf.cpp:1699
virtual std::string get_string() const
Get string value.
Definition: netconf.cpp:1720
virtual float get_float() const
Get float value.
Definition: netconf.cpp:1636
virtual bool is_list() const
Check if a value is a list.
Definition: netconf.cpp:1581
virtual std::vector< std::string > get_strings() const
Get list of values from configuration which is of type string.
Definition: netconf.cpp:1868
virtual bool is_float() const
Check if current value is a float.
Definition: netconf.cpp:1516
virtual const char * type() const
Type of value.
Definition: netconf.cpp:1495
virtual std::string get_comment() const
Get comment of value.
Definition: netconf.cpp:1927
virtual bool is_uint() const
Check if current value is a unsigned int.
Definition: netconf.cpp:1529
virtual bool next()
Check if there is another element and advance to this if possible.
Definition: netconf.cpp:1460
virtual const char * path() const
Path of value.
Definition: netconf.cpp:1481
virtual unsigned int get_uint() const
Get unsigned int value.
Definition: netconf.cpp:1657
virtual std::vector< int > get_ints() const
Get list of values from configuration which is of type int.
Definition: netconf.cpp:1808
virtual int get_int() const
Get int value.
Definition: netconf.cpp:1678
virtual bool is_default() const
Check if current value was read from the default config.
Definition: netconf.cpp:1609
Remote configuration via Fawkes net.
Definition: netconf.h:50
virtual bool is_float(const char *path)
Check if a value is of type float.
Definition: netconf.cpp:182
virtual void add_change_handler(ConfigurationChangeHandler *h)
Add a configuration change handler.
Definition: netconf.cpp:1247
ValueIterator * iterator_default()
Iterator for all default values.
Definition: netconf.cpp:1357
virtual void erase_default(const char *path)
Erase the given default value from the configuration.
Definition: netconf.cpp:911
bool try_lock()
Try to lock the config.
Definition: netconf.cpp:1323
virtual std::vector< unsigned int > get_uints(const char *path)
Get list of values from configuration which is of type unsigned int.
Definition: netconf.cpp:525
virtual std::string get_comment(const char *path)
Get comment of value at given path.
Definition: netconf.cpp:549
virtual std::string get_string(const char *path)
Get value from configuration which is of type string.
Definition: netconf.cpp:463
NetworkConfiguration(FawkesNetworkClient *c, unsigned int mirror_timeout_sec=15)
Constructor.
Definition: netconf.cpp:75
virtual int get_int(const char *path)
Get value from configuration which is of type int.
Definition: netconf.cpp:355
virtual void set_default_int(const char *path, int i)
Set new default value in configuration of type int.
Definition: netconf.cpp:761
virtual std::string get_default_comment(const char *path)
Get comment of value at given path.
Definition: netconf.cpp:598
virtual std::string get_type(const char *path)
Get type of field.
Definition: netconf.cpp:165
virtual bool exists(const char *path)
Check if a given value exists.
Definition: netconf.cpp:143
ValueIterator * iterator()
Iterator for all values.
Definition: netconf.cpp:1340
void lock()
Lock the config.
Definition: netconf.cpp:1317
virtual void erase(const char *path)
Erase the given value from the configuration.
Definition: netconf.cpp:905
void unlock()
Unlock the config.
Definition: netconf.cpp:1329
virtual void set_int(const char *path, int i)
Set new value in configuration of type int.
Definition: netconf.cpp:755
virtual void connection_established(unsigned int id) noexcept
Client has established a connection.
Definition: netconf.cpp:1240
virtual void load(const char *file_path)
Load configuration.
Definition: netconf.cpp:108
virtual bool is_list(const char *path)
Check if a value is a list.
Definition: netconf.cpp:212
ValueIterator * iterator_hostspecific()
Iterator for all host-specific values.
Definition: netconf.cpp:1374
ValueIterator * search(const char *path)
Iterator with search results.
Definition: netconf.cpp:1384
virtual unsigned int get_uint(const char *path)
Get value from configuration which is of type unsigned int.
Definition: netconf.cpp:301
virtual void set_bool(const char *path, bool b)
Set new value in configuration of type bool.
Definition: netconf.cpp:767
virtual void set_default_float(const char *path, float f)
Set new default value in configuration of type float.
Definition: netconf.cpp:737
virtual bool is_uint(const char *path)
Check if a value is of type unsigned int.
Definition: netconf.cpp:188
virtual void set_mirror_mode(bool mirror)
Enable or disable mirror mode.
Definition: netconf.cpp:1269
virtual void inbound_received(FawkesNetworkMessage *msg, unsigned int id) noexcept
Called for incoming messages.
Definition: netconf.cpp:926
virtual void set_default_string(const char *path, std::string &s)
Set new default value in configuration of type string.
Definition: netconf.cpp:816
virtual void set_default_bool(const char *path, bool b)
Set new default value in configuration of type bool.
Definition: netconf.cpp:774
virtual void set_default_uint(const char *path, unsigned int uint)
Set new default value in configuration of type unsigned int.
Definition: netconf.cpp:749
virtual void deregistered(unsigned int id) noexcept
We are no longer registered in Fawkes network client.
Definition: netconf.cpp:921
virtual bool is_bool(const char *path)
Check if a value is of type bool.
Definition: netconf.cpp:200
virtual std::vector< bool > get_bools(const char *path)
Get list of values from configuration which is of type bool.
Definition: netconf.cpp:537
virtual void set_float(const char *path, float f)
Set new value in configuration of type float.
Definition: netconf.cpp:731
virtual std::vector< std::string > get_strings(const char *path)
Get list of values from configuration which is of type string.
Definition: netconf.cpp:543
virtual void set_strings(const char *path, std::vector< std::string > &s)
Set new value in configuration of type string.
Definition: netconf.cpp:846
virtual ~NetworkConfiguration()
Destructor.
Definition: netconf.cpp:96
virtual std::vector< int > get_ints(const char *path)
Get list of values from configuration which is of type int.
Definition: netconf.cpp:531
virtual bool is_string(const char *path)
Check if a value is of type string.
Definition: netconf.cpp:206
virtual void set_comment(const char *path, std::string &comment)
Set new comment for existing value.
Definition: netconf.cpp:868
virtual bool is_default(const char *path)
Check if a value was read from the default config.
Definition: netconf.cpp:152
virtual void set_bools(const char *path, std::vector< bool > &b)
Set new value in configuration of type bool.
Definition: netconf.cpp:840
virtual void set_uints(const char *path, std::vector< unsigned int > &uint)
Set new value in configuration of type unsigned int.
Definition: netconf.cpp:828
virtual void rem_change_handler(ConfigurationChangeHandler *h)
Remove a configuration change handler.
Definition: netconf.cpp:1257
virtual void set_ints(const char *path, std::vector< int > &i)
Set new value in configuration of type int.
Definition: netconf.cpp:834
virtual void set_default_comment(const char *path, std::string &comment)
Set new default comment for existing default configuration value.
Definition: netconf.cpp:873
virtual void try_dump()
Try to dump configuration.
Definition: netconf.cpp:1335
virtual bool get_bool(const char *path)
Get value from configuration which is of type bool.
Definition: netconf.cpp:409
virtual bool is_int(const char *path)
Check if a value is of type int.
Definition: netconf.cpp:194
virtual void set_uint(const char *path, unsigned int uint)
Set new value in configuration of type unsigned int.
Definition: netconf.cpp:743
virtual float get_float(const char *path)
Get value from configuration which is of type float.
Definition: netconf.cpp:247
virtual void connection_died(unsigned int id) noexcept
Client connection died.
Definition: netconf.cpp:1231
virtual void copy(Configuration *copyconf)
Copy all values from the given configuration.
Definition: netconf.cpp:120
virtual ValueIterator * get_value(const char *path)
Get value from configuration.
Definition: netconf.cpp:648
virtual std::vector< float > get_floats(const char *path)
Get list of values from configuration which is of type float.
Definition: netconf.cpp:519
virtual void set_string(const char *path, std::string &s)
Set new value in configuration of type string.
Definition: netconf.cpp:810
virtual void set_floats(const char *path, std::vector< float > &f)
Set new value in configuration of type float.
Definition: netconf.cpp:822
Fawkes library namespace.