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 #include <stdint.h>
35 
36 namespace fawkes {
37 
38 class Mutex;
39 class InterruptibleBarrier;
40 class FawkesNetworkClient;
41 class MemoryConfiguration;
42 
44 {
45  public:
46  CannotEnableMirroringException(const char *msg);
47 };
48 
50 {
51  public:
52  NetworkConfiguration(FawkesNetworkClient *c, unsigned int mirror_timeout_sec = 15);
53  virtual ~NetworkConfiguration();
54 
55  virtual void copy(Configuration *copyconf);
56 
57  virtual void add_change_handler(ConfigurationChangeHandler *h);
58  virtual void rem_change_handler(ConfigurationChangeHandler *h);
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) throw();
116  virtual void inbound_received(FawkesNetworkMessage *msg,
117  unsigned int id) throw();
118  virtual void connection_died(unsigned int id) throw();
119  virtual void connection_established(unsigned int id) throw();
120 
121  virtual void set_mirror_mode(bool mirror);
122 
124  {
125  friend class NetworkConfiguration;
126  protected:
130  public:
131  virtual ~NetConfValueIterator();
132  virtual bool next();
133  virtual bool valid() const;
134 
135  virtual const char * path() const;
136  virtual const char * type() const;
137 
138  virtual bool is_float() const;
139  virtual bool is_uint() const;
140  virtual bool is_int() const;
141  virtual bool is_bool() const;
142  virtual bool is_string() const;
143  virtual bool is_list() const;
144  virtual size_t get_list_size() const;
145 
146  virtual bool is_default() const;
147 
148  virtual float get_float() const;
149  virtual unsigned int get_uint() const;
150  virtual int get_int() const;
151  virtual bool get_bool() const;
152  virtual std::string get_string() const;
153  virtual std::vector<float> get_floats() const;
154  virtual std::vector<unsigned int> get_uints() const;
155  virtual std::vector<int> get_ints() const;
156  virtual std::vector<bool> get_bools() const;
157  virtual std::vector<std::string> get_strings() const;
158  virtual std::string get_as_string() const;
159 
160  virtual std::string get_comment() const;
161 
162  private:
165  bool iterated_once;
166  char *_path;
167  };
168 
169  ValueIterator * iterator();
170  ValueIterator * iterator_default();
171  ValueIterator * iterator_hostspecific();
172  ValueIterator * search(const char *path);
173 
174  void lock();
175  bool try_lock();
176  void unlock();
177 
178  virtual void try_dump();
179 
180  private:
181  void send_get(const char *path, unsigned int msgid, unsigned int expected_reply);
182 
183  void set_value_internal(unsigned int msg_type, const char *path, uint16_t num_values,
184  size_t data_size, void *data);
185 
186  void erase_internal(const char *path, bool is_default);
187 
188 
191  Mutex *mutex;
192  bool __mirror_init_waiting;
193  InterruptibleBarrier *__mirror_init_barrier;
194 
195  bool __mirror_mode;
196  bool __mirror_mode_before_connection_dead;
197  unsigned int __mirror_timeout_sec;
198  MemoryConfiguration *mirror_config;
199 
200  bool __connected;
201 };
202 
203 } // end namespace fawkes
204 
205 #endif
Message handler for FawkesNetworkClient.
Simple Fawkes network client.
Definition: client.h:52
This class tries to translate the found plan to interpreteable data for the rest of the program...
Fawkes library namespace.
Interface for configuration change handling.
Representation of a message that is sent over the network.
Definition: message.h:75
A barrier is a synchronization tool which blocks until a given number of threads have reached the bar...
Base class for exceptions in Fawkes.
Definition: exception.h:36
Thrown if enabling mirror mode failed.
Definition: netconf.h:43
In-memory configuration store.
Definition: memory.h:38
Iterator interface to iterate over config values.
Definition: config.h:72
Network configuration value iterator.
Definition: netconf.h:123
Mutex mutual exclusion lock.
Definition: mutex.h:32
Interface for configuration handling.
Definition: config.h:67
CannotEnableMirroringException(const char *msg)
Constructor.
Definition: netconf.cpp:53
Remote configuration via Fawkes net.
Definition: netconf.h:49