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

uniconfdaemonconn.cc

Go to the documentation of this file.
00001 /* 00002 * Worldvisions Weaver Software: 00003 * Copyright (C) 1997-2002 Net Integration Technologies, Inc. 00004 * 00005 * Manages a UniConf daemon session. 00006 */ 00007 #include "uniconfdaemonconn.h" 00008 #include "uniconfdaemon.h" 00009 #include "wvtclstring.h" 00010 00011 00012 /***** UniConfDaemonConn *****/ 00013 00014 UniConfDaemonConn::UniConfDaemonConn(WvStream *_s, const UniConf &_root) : 00015 UniClientConn(_s), root(_root) 00016 { 00017 addcallback(); 00018 writecmd(EVENT_HELLO, wvtcl_escape("UniConf Server ready.")); 00019 } 00020 00021 00022 void UniConfDaemonConn::close() 00023 { 00024 delcallback(); 00025 UniClientConn::close(); 00026 } 00027 00028 00029 void UniConfDaemonConn::addcallback() 00030 { 00031 root.add_callback(this, UniConfCallback(this, 00032 &UniConfDaemonConn::deltacallback), true); 00033 } 00034 00035 00036 void UniConfDaemonConn::delcallback() 00037 { 00038 root.del_callback(this, true); 00039 } 00040 00041 00042 void UniConfDaemonConn::execute() 00043 { 00044 UniClientConn::execute(); 00045 00046 for (;;) 00047 { 00048 UniClientConn::Command command = readcmd(); 00049 if (command == UniClientConn::NONE) 00050 break; 00051 00052 // parse and execute command 00053 WvString arg1(readarg()); 00054 WvString arg2(readarg()); 00055 switch (command) 00056 { 00057 case UniClientConn::NONE: 00058 break; 00059 00060 case UniClientConn::INVALID: 00061 do_malformed(); 00062 break; 00063 00064 case UniClientConn::REQ_NOOP: 00065 do_noop(); 00066 break; 00067 00068 case UniClientConn::REQ_GET: 00069 if (arg1.isnull()) 00070 do_malformed(); 00071 else 00072 do_get(arg1); 00073 break; 00074 00075 case UniClientConn::REQ_SET: 00076 if (arg1.isnull() || arg2.isnull()) 00077 do_malformed(); 00078 else 00079 do_set(arg1, arg2); 00080 break; 00081 00082 case UniClientConn::REQ_REMOVE: 00083 if (arg1.isnull()) 00084 do_malformed(); 00085 else 00086 do_remove(arg1); 00087 break; 00088 00089 case UniClientConn::REQ_SUBTREE: 00090 if (arg1.isnull()) 00091 do_malformed(); 00092 else 00093 do_subtree(arg1); 00094 break; 00095 00096 case UniClientConn::REQ_HASCHILDREN: 00097 if (arg1.isnull()) 00098 do_malformed(); 00099 else 00100 do_haschildren(arg1); 00101 break; 00102 00103 case UniClientConn::REQ_QUIT: 00104 do_quit(); 00105 break; 00106 00107 case UniClientConn::REQ_HELP: 00108 do_help(); 00109 break; 00110 00111 default: 00112 do_malformed(); 00113 break; 00114 } 00115 } 00116 } 00117 00118 00119 void UniConfDaemonConn::do_malformed() 00120 { 00121 writefail("malformed request"); 00122 } 00123 00124 00125 void UniConfDaemonConn::do_noop() 00126 { 00127 writeok(); 00128 } 00129 00130 00131 void UniConfDaemonConn::do_reply(WvStringParm reply) 00132 { 00133 writefail("unexpected reply"); 00134 } 00135 00136 00137 void UniConfDaemonConn::do_get(const UniConfKey &key) 00138 { 00139 WvString value(root[key].get()); 00140 if (value.isnull()) 00141 writefail(); 00142 else 00143 writeonevalue(key, value); 00144 } 00145 00146 00147 void UniConfDaemonConn::do_set(const UniConfKey &key, WvStringParm value) 00148 { 00149 root[key].set(value); 00150 } 00151 00152 00153 void UniConfDaemonConn::do_remove(const UniConfKey &key) 00154 { 00155 root[key].remove(); 00156 } 00157 00158 00159 void UniConfDaemonConn::do_subtree(const UniConfKey &key) 00160 { 00161 UniConf cfg(root[key]); 00162 if (cfg.exists()) 00163 { 00164 UniConf::Iter it(cfg); 00165 for (it.rewind(); it.next(); ) 00166 writevalue(it->fullkey(), it->get()); 00167 writeok(); 00168 } 00169 else 00170 writefail(); 00171 } 00172 00173 00174 void UniConfDaemonConn::do_haschildren(const UniConfKey &key) 00175 { 00176 bool haschild = root[key].haschildren(); 00177 WvString msg("%s %s", wvtcl_escape(key), haschild ? "TRUE" : "FALSE"); 00178 writecmd(REPLY_CHILD, msg); 00179 } 00180 00181 00182 void UniConfDaemonConn::do_quit() 00183 { 00184 writeok(); 00185 close(); 00186 } 00187 00188 00189 void UniConfDaemonConn::do_help() 00190 { 00191 for (int i = 0; i < UniClientConn::NUM_COMMANDS; ++i) 00192 writetext(UniClientConn::cmdinfos[i].description); 00193 writeok(); 00194 } 00195 00196 00197 void UniConfDaemonConn::deltacallback(const UniConf &cfg, const UniConfKey &key) 00198 { 00199 WvString value(cfg[key].get()); 00200 WvString msg; 00201 00202 UniConfKey fullkey(cfg.fullkey()); 00203 fullkey.append(key); 00204 00205 if (value.isnull()) 00206 msg = WvString("%s", wvtcl_escape(fullkey)); 00207 else 00208 msg = WvString("%s %s", wvtcl_escape(fullkey), 00209 wvtcl_escape(cfg[key].get())); 00210 00211 writecmd(UniClientConn::EVENT_NOTICE, msg); 00212 }

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