00001
00002
00003
00004
00005
00006
00007 #ifndef __UNICONFROOT_H
00008 #define __UNICONFROOT_H
00009
00010 #include "uniconf.h"
00011 #include "uniconftree.h"
00012 #include "unimountgen.h"
00013
00014
00015
00016
00017
00018 class UniWatchInfo
00019 {
00020 public:
00021 void *cookie;
00022 bool recurse;
00023 UniConfCallback cb;
00024
00025 UniWatchInfo(void *_cookie, bool _recurse, UniConfCallback _cb)
00026 : cookie(_cookie), recurse(_recurse), cb(_cb) { }
00027
00028
00029 bool recursive()
00030 { return recurse; }
00031
00032
00033 void notify(const UniConf &cfg, const UniConfKey &key)
00034 { cb(cfg, key); }
00035
00036
00037 bool operator== (const UniWatchInfo &other) const
00038 { return other.cookie == cookie; }
00039 };
00040 DeclareWvList(UniWatchInfo);
00041
00042
00043
00044
00045
00046
00047 class UniWatchInfoTree : public UniConfTree<UniWatchInfoTree>
00048 {
00049 public:
00050 UniWatchInfoList watches;
00051
00052 UniWatchInfoTree(UniWatchInfoTree *parent,
00053 const UniConfKey &key = UniConfKey::EMPTY)
00054 : UniConfTree<UniWatchInfoTree>(parent, key) { }
00055
00056
00057 bool isessential()
00058 { return haschildren() || ! watches.isempty(); }
00059 };
00060
00061
00062
00063
00064
00065
00066
00067
00068
00069
00070
00071
00072
00073 class UniConfRoot : public UniConf
00074 {
00075 friend class UniConf;
00076 friend class UniConf::Iter;
00077
00078 UniWatchInfoTree watchroot;
00079
00080
00081 UniConfRoot(const UniConfRoot &other);
00082
00083 public:
00084
00085 UniConfRoot() : UniConf(this), watchroot(NULL)
00086 {
00087 mounts.setcallback(UniConfGenCallback(this,
00088 &UniConfRoot::gen_callback), NULL);
00089 }
00090
00091
00092 ~UniConfRoot()
00093 { mounts.setcallback(UniConfGenCallback(), NULL); }
00094
00095
00096
00097
00098
00099
00100 UniConfRoot(WvStringParm moniker, bool refresh = true)
00101 : UniConf(this), watchroot(NULL)
00102 {
00103 mounts.mount("/", moniker, refresh);
00104 mounts.setcallback(UniConfGenCallback(this,
00105 &UniConfRoot::gen_callback), NULL);
00106 }
00107
00108
00109
00110
00111
00112
00113 UniConfRoot(UniConfGen *gen, bool refresh = true)
00114 : UniConf(this), watchroot(NULL)
00115 {
00116 mounts.mountgen("/", gen, refresh);
00117 mounts.setcallback(UniConfGenCallback(this,
00118 &UniConfRoot::gen_callback), NULL);
00119 }
00120
00121
00122
00123
00124
00125 void add_callback(void *cookie, const UniConfKey &key,
00126 const UniConfCallback &callback, bool recurse = true);
00127
00128
00129
00130
00131 void del_callback(void *cookie, const UniConfKey &key,
00132 bool recurse = true);
00133
00134
00135
00136
00137
00138 void add_setbool(const UniConfKey &key, bool *flag, bool recurse = true);
00139
00140
00141
00142
00143 void del_setbool(const UniConfKey &key, bool *flag, bool recurse = true);
00144
00145 private:
00146
00147
00148
00149
00150
00151
00152 void check(UniWatchInfoTree *node, const UniConfKey &key, int segleft);
00153
00154
00155
00156
00157
00158
00159 void deletioncheck(UniWatchInfoTree *node, const UniConfKey &key);
00160
00161
00162 void prune(UniWatchInfoTree *node);
00163
00164
00165 void gen_callback(const UniConfKey &key, WvStringParm value, void *userdata);
00166
00167 protected:
00168 UniMountGen mounts;
00169
00170 public:
00171
00172 static void setbool_callback(bool *flag, const UniConf &,
00173 const UniConfKey &)
00174 { *flag = true; }
00175
00176 };
00177
00178 #endif //__UNICONFROOT_H