Main Page | Namespace List | Class Hierarchy | Alphabetical List | Class List | File List | Namespace Members | Class Members | File Members | Related Pages

uniconfroot.h

Go to the documentation of this file.
00001 /* -*- Mode: C++ -*- 00002 * Worldvisions Weaver Software: 00003 * Copyright (C) 1997-2002 Net Integration Technologies, Inc. 00004 * 00005 * Defines the root management class for UniConf. 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 * @internal 00016 * Holds information about a single watch. 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 /** Returns watch recursion */ 00029 bool recursive() 00030 { return recurse; } 00031 00032 /** Notifies that a key has changed. */ 00033 void notify(const UniConf &cfg, const UniConfKey &key) 00034 { cb(cfg, key); } 00035 00036 /** Equality test. */ 00037 bool operator== (const UniWatchInfo &other) const 00038 { return other.cookie == cookie; } 00039 }; 00040 DeclareWvList(UniWatchInfo); 00041 00042 00043 /** 00044 * @internal 00045 * Data structure to track requested watches. 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 /** Returns true if the node should not be pruned. */ 00057 bool isessential() 00058 { return haschildren() || ! watches.isempty(); } 00059 }; 00060 00061 00062 /** 00063 * Represents the root of a hierarhical registry consisting of pairs 00064 * of UniConfKeys and associated string values. * 00065 * 00066 * Any number of data containers may be mounted into the tree at any 00067 * number of mount points to provide a backing store from which 00068 * registry keys and values are fetched and into which they are 00069 * stored. Multiple data containers may be mounted at the same 00070 * location using standard unix semantics. 00071 * 00072 */ 00073 class UniConfRoot : public UniConf 00074 { 00075 friend class UniConf; 00076 friend class UniConf::Iter; 00077 00078 UniWatchInfoTree watchroot; 00079 00080 /** undefined. */ 00081 UniConfRoot(const UniConfRoot &other); 00082 00083 public: 00084 /** Creates an empty UniConf tree with no mounted stores. */ 00085 UniConfRoot() : UniConf(this), watchroot(NULL) 00086 { 00087 mounts.setcallback(UniConfGenCallback(this, 00088 &UniConfRoot::gen_callback), NULL); 00089 } 00090 00091 /** Destroys the UniConf tree along with all uncommitted data. */ 00092 ~UniConfRoot() 00093 { mounts.setcallback(UniConfGenCallback(), NULL); } 00094 00095 /** 00096 * Creates a new UniConf tree and mounts the given moniker at the root. 00097 * Since most people only want to mount one generator, this should save 00098 * a line of code here and there. 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 * Creates a new UniConf tree and mounts the given generator at the root. 00110 * Since most people only want to mount one generator, this should save 00111 * a line of code here and there. 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 * Requests notification when any of the keys covered by the 00123 * recursive depth specification change by invoking a callback. 00124 */ 00125 void add_callback(void *cookie, const UniConfKey &key, 00126 const UniConfCallback &callback, bool recurse = true); 00127 00128 /** 00129 * Cancels notification requested using add_callback(). 00130 */ 00131 void del_callback(void *cookie, const UniConfKey &key, 00132 bool recurse = true); 00133 00134 /** 00135 * Requests notification when any of the keys covered by the 00136 * recursive depth specification change by setting a flag. 00137 */ 00138 void add_setbool(const UniConfKey &key, bool *flag, bool recurse = true); 00139 00140 /** 00141 * Cancels notification requested using add_setbool(). 00142 */ 00143 void del_setbool(const UniConfKey &key, bool *flag, bool recurse = true); 00144 00145 private: 00146 /** 00147 * Checks a branch of the watch tree for notification candidates. 00148 * node - the current node 00149 * key - the key that changed 00150 * segleft - the number of segments left in the key (possibly negative) 00151 */ 00152 void check(UniWatchInfoTree *node, const UniConfKey &key, int segleft); 00153 00154 /** 00155 * Recursively checks a branch of the watch tree for notification candidates. 00156 * node - the current node 00157 * key - the key that changed 00158 */ 00159 void deletioncheck(UniWatchInfoTree *node, const UniConfKey &key); 00160 00161 /** Prunes a branch of the watch tree. */ 00162 void prune(UniWatchInfoTree *node); 00163 00164 /** Callback from UniMountTreeGen */ 00165 void gen_callback(const UniConfKey &key, WvStringParm value, void *userdata); 00166 00167 protected: 00168 UniMountGen mounts; 00169 00170 public: 00171 /** Internal callback for setbool style notifications. */ 00172 static void setbool_callback(bool *flag, const UniConf &, 00173 const UniConfKey &) 00174 { *flag = true; } 00175 00176 }; 00177 00178 #endif //__UNICONFROOT_H

Generated on Tue Oct 5 01:09:19 2004 for WvStreams by doxygen 1.3.7