Fawkes API
Fawkes Development Version
|
00001 00002 /*************************************************************************** 00003 * netconf.h - Fawkes remote configuration access via Fawkes net 00004 * 00005 * Created: Sun Jan 07 15:01:50 2007 00006 * Copyright 2006-2009 Tim Niemueller [www.niemueller.de] 00007 * 00008 ****************************************************************************/ 00009 00010 /* This program is free software; you can redistribute it and/or modify 00011 * it under the terms of the GNU General Public License as published by 00012 * the Free Software Foundation; either version 2 of the License, or 00013 * (at your option) any later version. A runtime exception applies to 00014 * this software (see LICENSE.GPL_WRE file mentioned below for details). 00015 * 00016 * This program is distributed in the hope that it will be useful, 00017 * but WITHOUT ANY WARRANTY; without even the implied warranty of 00018 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 00019 * GNU Library General Public License for more details. 00020 * 00021 * Read the full text in the LICENSE.GPL_WRE file in the doc directory. 00022 */ 00023 00024 #ifndef __CONFIG_NETCONF_H_ 00025 #define __CONFIG_NETCONF_H_ 00026 00027 #include <config/config.h> 00028 #include <netcomm/fawkes/client_handler.h> 00029 #include <core/exception.h> 00030 00031 #include <map> 00032 #include <list> 00033 #include <string> 00034 00035 namespace fawkes { 00036 00037 class Mutex; 00038 class InterruptibleBarrier; 00039 class FawkesNetworkClient; 00040 class SQLiteConfiguration; 00041 00042 class CannotEnableMirroringException : public Exception 00043 { 00044 public: 00045 CannotEnableMirroringException(const char *msg); 00046 }; 00047 00048 class NetworkConfiguration : public Configuration, public FawkesNetworkClientHandler 00049 { 00050 public: 00051 NetworkConfiguration(FawkesNetworkClient *c, unsigned int mirror_timeout_sec = 15); 00052 virtual ~NetworkConfiguration(); 00053 00054 virtual void copy(Configuration *copyconf); 00055 00056 virtual void add_change_handler(ConfigurationChangeHandler *h); 00057 virtual void rem_change_handler(ConfigurationChangeHandler *h); 00058 00059 virtual void load(const char *filename, const char *defaults_filename, 00060 const char *tag = NULL); 00061 00062 virtual void tag(const char *tag); 00063 virtual std::list<std::string> tags(); 00064 00065 virtual bool exists(const char *path); 00066 virtual bool is_float(const char *path); 00067 virtual bool is_uint(const char *path); 00068 virtual bool is_int(const char *path); 00069 virtual bool is_bool(const char *path); 00070 virtual bool is_string(const char *path); 00071 00072 virtual bool is_default(const char *path); 00073 00074 virtual float get_float(const char *path); 00075 virtual unsigned int get_uint(const char *path); 00076 virtual int get_int(const char *path); 00077 virtual bool get_bool(const char *path); 00078 virtual std::string get_string(const char *path); 00079 virtual ValueIterator * get_value(const char *path); 00080 virtual std::string get_comment(const char *path); 00081 virtual std::string get_default_comment(const char *path); 00082 virtual std::string get_type(const char *path); 00083 00084 virtual void set_float(const char *path, float f); 00085 virtual void set_uint(const char *path, unsigned int uint); 00086 virtual void set_int(const char *path, int i); 00087 virtual void set_bool(const char *path, bool b); 00088 virtual void set_string(const char *path, std::string &s); 00089 virtual void set_string(const char *path, const char *s); 00090 virtual void set_comment(const char *path, std::string &comment); 00091 virtual void set_comment(const char *path, const char *comment); 00092 00093 virtual void erase(const char *path); 00094 00095 virtual void set_default_float(const char *path, float f); 00096 virtual void set_default_uint(const char *path, unsigned int uint); 00097 virtual void set_default_int(const char *path, int i); 00098 virtual void set_default_bool(const char *path, bool b); 00099 virtual void set_default_string(const char *path, std::string &s); 00100 virtual void set_default_string(const char *path, const char *s); 00101 virtual void set_default_comment(const char *path, std::string &comment); 00102 virtual void set_default_comment(const char *path, const char *comment); 00103 00104 virtual void erase_default(const char *path); 00105 00106 virtual void deregistered(unsigned int id) throw(); 00107 virtual void inbound_received(FawkesNetworkMessage *msg, 00108 unsigned int id) throw(); 00109 virtual void connection_died(unsigned int id) throw(); 00110 virtual void connection_established(unsigned int id) throw(); 00111 00112 virtual void set_mirror_mode(bool mirror); 00113 00114 class NetConfValueIterator : public Configuration::ValueIterator 00115 { 00116 friend class NetworkConfiguration; 00117 protected: 00118 NetConfValueIterator(Configuration::ValueIterator *i); 00119 NetConfValueIterator(FawkesNetworkMessage *m); 00120 NetConfValueIterator(); 00121 public: 00122 virtual ~NetConfValueIterator(); 00123 virtual bool next(); 00124 virtual bool valid() const; 00125 00126 virtual const char * path() const; 00127 virtual const char * type() const; 00128 00129 virtual bool is_float() const; 00130 virtual bool is_uint() const; 00131 virtual bool is_int() const; 00132 virtual bool is_bool() const; 00133 virtual bool is_string() const; 00134 00135 virtual bool is_default() const; 00136 00137 virtual float get_float() const; 00138 virtual unsigned int get_uint() const; 00139 virtual int get_int() const; 00140 virtual bool get_bool() const; 00141 virtual std::string get_string() const; 00142 virtual std::string get_as_string() const; 00143 00144 virtual std::string get_comment() const; 00145 00146 private: 00147 Configuration::ValueIterator *i; 00148 FawkesNetworkMessage *msg; 00149 bool iterated_once; 00150 char *_path; 00151 }; 00152 00153 ValueIterator * iterator(); 00154 ValueIterator * iterator_default(); 00155 ValueIterator * iterator_hostspecific(); 00156 ValueIterator * search(const char *path); 00157 00158 void lock(); 00159 bool try_lock(); 00160 void unlock(); 00161 00162 private: 00163 void send_get(const char *path, unsigned int msgid); 00164 00165 void set_float_internal(unsigned int msg_type, const char *path, float f); 00166 void set_uint_internal(unsigned int msg_type, const char *path, 00167 unsigned int uint); 00168 void set_int_internal(unsigned int msg_type, const char *path, int i); 00169 void set_bool_internal(unsigned int msg_type, const char *path, bool b); 00170 void set_string_internal(unsigned int msg_type, const char *path, 00171 const char *s); 00172 void set_comment_internal(unsigned int msg_type, const char *path, 00173 const char *s); 00174 00175 void erase_internal(const char *path, bool is_default); 00176 00177 00178 FawkesNetworkClient *c; 00179 FawkesNetworkMessage *msg; 00180 Mutex *mutex; 00181 InterruptibleBarrier *__mirror_init_barrier; 00182 00183 bool __mirror_mode; 00184 bool __mirror_mode_before_connection_dead; 00185 unsigned int __mirror_timeout_sec; 00186 SQLiteConfiguration *mirror_config; 00187 00188 bool __connected; 00189 }; 00190 00191 } // end namespace fawkes 00192 00193 #endif