Fawkes API Fawkes Development Version
|
00001 00002 /*************************************************************************** 00003 * config.h - Fawkes configuration interface 00004 * 00005 * Created: Mon Dec 04 17:38:32 2006 00006 * Copyright 2006 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_CONFIG_H_ 00025 #define __CONFIG_CONFIG_H_ 00026 00027 #include <core/exception.h> 00028 #include <config/change_handler.h> 00029 #include <utils/misc/string_compare.h> 00030 #include <string> 00031 #include <list> 00032 #include <map> 00033 00034 namespace fawkes { 00035 00036 class ConfigurationException : public Exception 00037 { 00038 public: 00039 ConfigurationException(const char *msg); 00040 ConfigurationException(const char *prefix, const char *msg); 00041 }; 00042 00043 class ConfigEntryNotFoundException : public Exception 00044 { 00045 public: 00046 ConfigEntryNotFoundException(const char *path); 00047 }; 00048 00049 class ConfigTypeMismatchException : public Exception 00050 { 00051 public: 00052 ConfigTypeMismatchException(const char *path, 00053 const char *actual, const char *requested); 00054 }; 00055 00056 class CouldNotOpenConfigException : public Exception 00057 { 00058 public: 00059 CouldNotOpenConfigException(const char *format, ...); 00060 }; 00061 00062 class Configuration 00063 { 00064 public: 00065 virtual ~Configuration() {} 00066 00067 class ValueIterator 00068 { 00069 public: 00070 virtual ~ValueIterator() {} 00071 virtual bool next() = 0; 00072 virtual bool valid() = 0; 00073 00074 virtual const char * path() = 0; 00075 virtual const char * type() = 0; 00076 00077 virtual bool is_float() = 0; 00078 virtual bool is_uint() = 0; 00079 virtual bool is_int() = 0; 00080 virtual bool is_bool() = 0; 00081 virtual bool is_string() = 0; 00082 00083 virtual float get_float() = 0; 00084 virtual unsigned int get_uint() = 0; 00085 virtual int get_int() = 0; 00086 virtual bool get_bool() = 0; 00087 virtual std::string get_string() = 0; 00088 00089 virtual std::string get_comment() = 0; 00090 00091 virtual bool is_default() = 0; 00092 }; 00093 00094 virtual void copy(Configuration *copyconf) = 0; 00095 00096 virtual void add_change_handler(ConfigurationChangeHandler *h); 00097 virtual void rem_change_handler(ConfigurationChangeHandler *h); 00098 00099 virtual void load(const char *name, const char *defaults_name, 00100 const char *tag = NULL) = 0; 00101 00102 virtual void tag(const char *tag) = 0; 00103 virtual std::list<std::string> tags() = 0; 00104 00105 virtual bool exists(const char *path) = 0; 00106 virtual bool is_float(const char *path) = 0; 00107 virtual bool is_uint(const char *path) = 0; 00108 virtual bool is_int(const char *path) = 0; 00109 virtual bool is_bool(const char *path) = 0; 00110 virtual bool is_string(const char *path) = 0; 00111 00112 virtual bool is_default(const char *path) = 0; 00113 00114 virtual float get_float(const char *path) = 0; 00115 virtual unsigned int get_uint(const char *path) = 0; 00116 virtual int get_int(const char *path) = 0; 00117 virtual bool get_bool(const char *path) = 0; 00118 virtual std::string get_string(const char *path) = 0; 00119 virtual ValueIterator * get_value(const char *path) = 0; 00120 virtual std::string get_type(const char *path) = 0; 00121 virtual std::string get_comment(const char *path) = 0; 00122 virtual std::string get_default_comment(const char *path) = 0; 00123 00124 virtual void set_float(const char *path, float f) = 0; 00125 virtual void set_uint(const char *path, unsigned int uint) = 0; 00126 virtual void set_int(const char *path, int i) = 0; 00127 virtual void set_bool(const char *path, bool b) = 0; 00128 virtual void set_string(const char *path, std::string &s) = 0; 00129 virtual void set_string(const char *path, const char *s) = 0; 00130 virtual void set_comment(const char *path, 00131 const char *comment) = 0; 00132 virtual void set_comment(const char *path, 00133 std::string &comment) = 0; 00134 00135 virtual void erase(const char *path) = 0; 00136 00137 virtual void set_default_float(const char *path, float f) = 0; 00138 virtual void set_default_uint(const char *path, 00139 unsigned int uint) = 0; 00140 virtual void set_default_int(const char *path, int i) = 0; 00141 virtual void set_default_bool(const char *path, bool b) = 0; 00142 virtual void set_default_string(const char *path, 00143 std::string &s) = 0; 00144 virtual void set_default_string(const char *path, 00145 const char *s) = 0; 00146 00147 virtual void set_default_comment(const char *path, 00148 const char *comment) = 0; 00149 virtual void set_default_comment(const char *path, 00150 std::string &comment) = 0; 00151 00152 virtual void erase_default(const char *path) = 0; 00153 00154 virtual ValueIterator * iterator() = 0; 00155 virtual ValueIterator * iterator_default() = 0; 00156 virtual ValueIterator * iterator_hostspecific() = 0; 00157 00158 virtual ValueIterator * search(const char *path) = 0; 00159 00160 virtual void lock() = 0; 00161 virtual bool try_lock() = 0; 00162 virtual void unlock() = 0; 00163 00164 protected: 00165 /** List that contains pointers to ConfigurationChangeHandler */ 00166 typedef std::list<ConfigurationChangeHandler *> ChangeHandlerList; 00167 00168 /** Multimap string to config change handlers. */ 00169 typedef std::multimap<const char *, ConfigurationChangeHandler *, StringLess > 00170 ChangeHandlerMultimap; 00171 00172 /** Config change handler multimap range. */ 00173 typedef std::pair<ChangeHandlerMultimap::iterator, 00174 ChangeHandlerMultimap::iterator> 00175 ChangeHandlerMultimapRange; 00176 00177 /** Registered change handlers. */ 00178 ChangeHandlerMultimap _change_handlers; 00179 /** Change handler range. */ 00180 ChangeHandlerMultimapRange _ch_range; 00181 00182 /** Find handlers for given path. 00183 * @param path path to get handlers for 00184 * @return list with config change handlers. 00185 */ 00186 ChangeHandlerList * find_handlers(const char *path); 00187 00188 }; 00189 00190 } // end namespace fawkes 00191 00192 #endif