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(); 00125 00126 virtual const char * path(); 00127 virtual const char * type(); 00128 00129 virtual bool is_float(); 00130 virtual bool is_uint(); 00131 virtual bool is_int(); 00132 virtual bool is_bool(); 00133 virtual bool is_string(); 00134 00135 virtual bool is_default(); 00136 00137 virtual float get_float(); 00138 virtual unsigned int get_uint(); 00139 virtual int get_int(); 00140 virtual bool get_bool(); 00141 virtual std::string get_string(); 00142 00143 virtual std::string get_comment(); 00144 00145 private: 00146 Configuration::ValueIterator *i; 00147 FawkesNetworkMessage *msg; 00148 bool iterated_once; 00149 char *_path; 00150 }; 00151 00152 ValueIterator * iterator(); 00153 ValueIterator * iterator_default(); 00154 ValueIterator * iterator_hostspecific(); 00155 ValueIterator * search(const char *path); 00156 00157 void lock(); 00158 bool try_lock(); 00159 void unlock(); 00160 00161 private: 00162 void send_get(const char *path, unsigned int msgid); 00163 00164 void set_float_internal(unsigned int msg_type, const char *path, float f); 00165 void set_uint_internal(unsigned int msg_type, const char *path, 00166 unsigned int uint); 00167 void set_int_internal(unsigned int msg_type, const char *path, int i); 00168 void set_bool_internal(unsigned int msg_type, const char *path, bool b); 00169 void set_string_internal(unsigned int msg_type, const char *path, 00170 const char *s); 00171 void set_comment_internal(unsigned int msg_type, const char *path, 00172 const char *s); 00173 00174 void erase_internal(const char *path, bool is_default); 00175 00176 00177 FawkesNetworkClient *c; 00178 FawkesNetworkMessage *msg; 00179 Mutex *mutex; 00180 InterruptibleBarrier *__mirror_init_barrier; 00181 00182 bool __mirror_mode; 00183 bool __mirror_mode_before_connection_dead; 00184 unsigned int __mirror_timeout_sec; 00185 SQLiteConfiguration *mirror_config; 00186 00187 bool __connected; 00188 }; 00189 00190 } // end namespace fawkes 00191 00192 #endif