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 <netcomm/fawkes/client_handler.h>
29 #include <core/exception.h>
30 
31 #include <map>
32 #include <list>
33 #include <string>
34 
35 namespace fawkes {
36 
37 class Mutex;
38 class InterruptibleBarrier;
39 class FawkesNetworkClient;
40 class SQLiteConfiguration;
41 
43 {
44  public:
45  CannotEnableMirroringException(const char *msg);
46 };
47 
49 {
50  public:
51  NetworkConfiguration(FawkesNetworkClient *c, unsigned int mirror_timeout_sec = 15);
52  virtual ~NetworkConfiguration();
53 
54  virtual void copy(Configuration *copyconf);
55 
58 
59  virtual void load(const char *filename, const char *defaults_filename,
60  const char *tag = NULL);
61 
62  virtual void tag(const char *tag);
63  virtual std::list<std::string> tags();
64 
65  virtual bool exists(const char *path);
66  virtual bool is_float(const char *path);
67  virtual bool is_uint(const char *path);
68  virtual bool is_int(const char *path);
69  virtual bool is_bool(const char *path);
70  virtual bool is_string(const char *path);
71 
72  virtual bool is_default(const char *path);
73 
74  virtual float get_float(const char *path);
75  virtual unsigned int get_uint(const char *path);
76  virtual int get_int(const char *path);
77  virtual bool get_bool(const char *path);
78  virtual std::string get_string(const char *path);
79  virtual ValueIterator * get_value(const char *path);
80  virtual std::string get_comment(const char *path);
81  virtual std::string get_default_comment(const char *path);
82  virtual std::string get_type(const char *path);
83 
84  virtual void set_float(const char *path, float f);
85  virtual void set_uint(const char *path, unsigned int uint);
86  virtual void set_int(const char *path, int i);
87  virtual void set_bool(const char *path, bool b);
88  virtual void set_string(const char *path, std::string &s);
89  virtual void set_string(const char *path, const char *s);
90  virtual void set_comment(const char *path, std::string &comment);
91  virtual void set_comment(const char *path, const char *comment);
92 
93  virtual void erase(const char *path);
94 
95  virtual void set_default_float(const char *path, float f);
96  virtual void set_default_uint(const char *path, unsigned int uint);
97  virtual void set_default_int(const char *path, int i);
98  virtual void set_default_bool(const char *path, bool b);
99  virtual void set_default_string(const char *path, std::string &s);
100  virtual void set_default_string(const char *path, const char *s);
101  virtual void set_default_comment(const char *path, std::string &comment);
102  virtual void set_default_comment(const char *path, const char *comment);
103 
104  virtual void erase_default(const char *path);
105 
106  virtual void deregistered(unsigned int id) throw();
107  virtual void inbound_received(FawkesNetworkMessage *msg,
108  unsigned int id) throw();
109  virtual void connection_died(unsigned int id) throw();
110  virtual void connection_established(unsigned int id) throw();
111 
112  virtual void set_mirror_mode(bool mirror);
113 
115  {
116  friend class NetworkConfiguration;
117  protected:
121  public:
122  virtual ~NetConfValueIterator();
123  virtual bool next();
124  virtual bool valid() const;
125 
126  virtual const char * path() const;
127  virtual const char * type() const;
128 
129  virtual bool is_float() const;
130  virtual bool is_uint() const;
131  virtual bool is_int() const;
132  virtual bool is_bool() const;
133  virtual bool is_string() const;
134 
135  virtual bool is_default() const;
136 
137  virtual float get_float() const;
138  virtual unsigned int get_uint() const;
139  virtual int get_int() const;
140  virtual bool get_bool() const;
141  virtual std::string get_string() const;
142  virtual std::string get_as_string() const;
143 
144  virtual std::string get_comment() const;
145 
146  private:
149  bool iterated_once;
150  char *_path;
151  };
152 
156  ValueIterator * search(const char *path);
157 
158  void lock();
159  bool try_lock();
160  void unlock();
161 
162  private:
163  void send_get(const char *path, unsigned int msgid);
164 
165  void set_float_internal(unsigned int msg_type, const char *path, float f);
166  void set_uint_internal(unsigned int msg_type, const char *path,
167  unsigned int uint);
168  void set_int_internal(unsigned int msg_type, const char *path, int i);
169  void set_bool_internal(unsigned int msg_type, const char *path, bool b);
170  void set_string_internal(unsigned int msg_type, const char *path,
171  const char *s);
172  void set_comment_internal(unsigned int msg_type, const char *path,
173  const char *s);
174 
175  void erase_internal(const char *path, bool is_default);
176 
177 
180  Mutex *mutex;
181  InterruptibleBarrier *__mirror_init_barrier;
182 
183  bool __mirror_mode;
184  bool __mirror_mode_before_connection_dead;
185  unsigned int __mirror_timeout_sec;
186  SQLiteConfiguration *mirror_config;
187 
188  bool __connected;
189 };
190 
191 } // end namespace fawkes
192 
193 #endif
virtual std::string get_comment() const
Get comment of value.
Definition: netconf.cpp:1762
virtual void connection_died(unsigned int id)
Client connection died.
Definition: netconf.cpp:1228
Message handler for FawkesNetworkClient.
NetworkConfiguration(FawkesNetworkClient *c, unsigned int mirror_timeout_sec=15)
Constructor.
Definition: netconf.cpp:78
virtual void add_change_handler(ConfigurationChangeHandler *h)
Add a configuration change handler.
Definition: netconf.cpp:1246
virtual bool exists(const char *path)
Check if a given value exists.
Definition: netconf.cpp:177
virtual bool is_default() const
Check if current value was read from the default config.
Definition: netconf.cpp:1589
virtual std::list< std::string > tags()
List of tags.
Definition: netconf.cpp:167
virtual bool is_default(const char *path)
Check if a value was read from the default config.
Definition: netconf.cpp:187
virtual bool is_string(const char *path)
Check if a value is of type string.
Definition: netconf.cpp:247
Simple Fawkes network client.
Definition: client.h:51
virtual ~NetworkConfiguration()
Destructor.
Definition: netconf.cpp:99
virtual void set_float(const char *path, float f)
Set new value in configuration of type float.
Definition: netconf.cpp:710
virtual void tag(const char *tag)
Tag this configuration version.
Definition: netconf.cpp:158
virtual ValueIterator * get_value(const char *path)
Get value from configuration.
Definition: netconf.cpp:633
virtual bool is_uint(const char *path)
Check if a value is of type unsigned int.
Definition: netconf.cpp:226
Configuration storage using SQLite.
Definition: sqlite.h:39
virtual void inbound_received(FawkesNetworkMessage *msg, unsigned int id)
Called for incoming messages.
Definition: netconf.cpp:1021
virtual bool next()
Check if there is another element and advance to this if possible.
Definition: netconf.cpp:1458
virtual bool is_int() const
Check if current value is a int.
Definition: netconf.cpp:1547
Fawkes library namespace.
virtual void set_default_bool(const char *path, bool b)
Set new default value in configuration of type bool.
Definition: netconf.cpp:842
virtual std::string get_as_string() const
Get value as string.
Definition: netconf.cpp:1730
virtual void load(const char *filename, const char *defaults_filename, const char *tag=NULL)
Load configuration.
Definition: netconf.cpp:119
Interface for configuration change handling.
void lock()
Lock the config.
Definition: netconf.cpp:1323
Representation of a message that is sent over the network.
Definition: message.h:75
ValueIterator * iterator()
Iterator for all values.
Definition: netconf.cpp:1344
void unlock()
Unlock the config.
Definition: netconf.cpp:1337
virtual float get_float(const char *path)
Get value from configuration which is of type float.
Definition: netconf.cpp:282
virtual std::string get_string(const char *path)
Get value from configuration which is of type string.
Definition: netconf.cpp:482
virtual bool get_bool() const
Get bool value.
Definition: netconf.cpp:1691
virtual bool is_float(const char *path)
Check if a value is of type float.
Definition: netconf.cpp:219
virtual int get_int(const char *path)
Get value from configuration which is of type int.
Definition: netconf.cpp:382
virtual std::string get_type(const char *path)
Get type of field.
Definition: netconf.cpp:201
virtual bool is_bool() const
Check if current value is a bool.
Definition: netconf.cpp:1561
A barrier is a synchronization tool which blocks until a given number of threads have reached the bar...
virtual bool valid() const
Check if the current element is valid.
Definition: netconf.cpp:1474
virtual bool get_bool(const char *path)
Get value from configuration which is of type bool.
Definition: netconf.cpp:432
virtual void rem_change_handler(ConfigurationChangeHandler *h)
Remove a configuration change handler.
Definition: netconf.cpp:1257
ValueIterator * iterator_default()
Iterator for all default values.
Definition: netconf.cpp:1355
virtual bool is_int(const char *path)
Check if a value is of type int.
Definition: netconf.cpp:233
virtual int get_int() const
Get int value.
Definition: netconf.cpp:1672
virtual std::string get_comment(const char *path)
Get comment of value at given path.
Definition: netconf.cpp:532
virtual void set_default_uint(const char *path, unsigned int uint)
Set new default value in configuration of type unsigned int.
Definition: netconf.cpp:760
virtual void set_comment(const char *path, std::string &comment)
Set new comment for existing value.
Definition: netconf.cpp:955
Base class for exceptions in Fawkes.
Definition: exception.h:36
virtual unsigned int get_uint() const
Get unsigned int value.
Definition: netconf.cpp:1653
virtual void erase(const char *path)
Erase the given value from the configuration.
Definition: netconf.cpp:997
ValueIterator * iterator_hostspecific()
Iterator for all host-specific values.
Definition: netconf.cpp:1366
virtual void set_default_float(const char *path, float f)
Set new default value in configuration of type float.
Definition: netconf.cpp:717
virtual bool is_float() const
Check if current value is a float.
Definition: netconf.cpp:1519
virtual void set_mirror_mode(bool mirror)
Enable or disable mirror mode.
Definition: netconf.cpp:1270
virtual void set_bool(const char *path, bool b)
Set new value in configuration of type bool.
Definition: netconf.cpp:835
virtual void copy(Configuration *copyconf)
Copy all values from the given configuration.
Definition: netconf.cpp:134
virtual unsigned int get_uint(const char *path)
Get value from configuration which is of type unsigned int.
Definition: netconf.cpp:332
virtual void connection_established(unsigned int id)
Client has established a connection.
Definition: netconf.cpp:1238
Thrown if enabling mirror mode failed.
Definition: netconf.h:42
virtual void set_default_int(const char *path, int i)
Set new default value in configuration of type int.
Definition: netconf.cpp:799
virtual std::string get_default_comment(const char *path)
Get comment of value at given path.
Definition: netconf.cpp:582
Iterator interface to iterate over config values.
Definition: config.h:68
Network configuration value iterator.
Definition: netconf.h:114
virtual std::string get_string() const
Get string value.
Definition: netconf.cpp:1710
virtual void set_int(const char *path, int i)
Set new value in configuration of type int.
Definition: netconf.cpp:792
virtual float get_float() const
Get float value.
Definition: netconf.cpp:1634
virtual const char * path() const
Path of value.
Definition: netconf.cpp:1481
bool try_lock()
Try to lock the config.
Definition: netconf.cpp:1330
virtual bool is_uint() const
Check if current value is a unsigned int.
Definition: netconf.cpp:1533
virtual bool is_bool(const char *path)
Check if a value is of type bool.
Definition: netconf.cpp:240
virtual const char * type() const
Type of value.
Definition: netconf.cpp:1496
Mutex mutual exclusion lock.
Definition: mutex.h:32
virtual void set_default_comment(const char *path, std::string &comment)
Set new default comment for existing default configuration value.
Definition: netconf.cpp:962
virtual void deregistered(unsigned int id)
We are no longer registered in Fawkes network client.
Definition: netconf.cpp:1015
Interface for configuration handling.
Definition: config.h:63
virtual bool is_string() const
Check if current value is a string.
Definition: netconf.cpp:1575
virtual void set_default_string(const char *path, std::string &s)
Set new default value in configuration of type string.
Definition: netconf.cpp:901
ValueIterator * search(const char *path)
Iterator with search results.
Definition: netconf.cpp:1377
virtual void set_uint(const char *path, unsigned int uint)
Set new value in configuration of type unsigned int.
Definition: netconf.cpp:753
CannotEnableMirroringException(const char *msg)
Constructor.
Definition: netconf.cpp:53
Remote configuration via Fawkes net.
Definition: netconf.h:48
virtual void set_string(const char *path, std::string &s)
Set new value in configuration of type string.
Definition: netconf.cpp:894
virtual void erase_default(const char *path)
Erase the given default value from the configuration.
Definition: netconf.cpp:1004