Fawkes API  Fawkes Development Version
 All Classes Namespaces Functions Variables Typedefs Enumerations Enumerator Friends Groups Pages
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