7 #include "uniconfdaemonconn.h" 8 #include "uniconfdaemon.h" 15 UniConfDaemonConn::UniConfDaemonConn(
WvStream *_s,
const UniConf &_root)
26 UniConfDaemonConn::~UniConfDaemonConn()
40 void UniConfDaemonConn::addcallback()
42 root.add_callback(
this, wv::bind(&UniConfDaemonConn::deltacallback,
this,
47 void UniConfDaemonConn::delcallback()
49 root.del_callback(
this,
true);
71 do_invalid(command_string);
80 do_malformed(command);
87 do_malformed(command);
94 do_malformed(command);
101 do_malformed(command);
103 do_subtree(arg1, arg2.
num() == 1);
108 do_malformed(command);
110 do_haschildren(arg1);
130 do_invalid(command_string);
139 writefail(
WvString(
"unknown command: %s", c));
145 writefail(
WvString(
"malformed request: %s",
146 UniClientConn::cmdinfos[c].name));
150 void UniConfDaemonConn::do_noop()
158 writefail(
"unexpected reply");
162 void UniConfDaemonConn::do_get(
const UniConfKey &key)
169 writeonevalue(key, value);
175 root[key].setme(value);
179 void UniConfDaemonConn::do_remove(
const UniConfKey &_key)
181 int notifications_sent = 0;
182 bool single_key =
true;
186 for (
int n = strkey.len()-1; n > 0; n--)
188 if (strkey.
edit()[n] ==
'/')
189 strkey.
edit()[n] =
' ';
204 for (it.rewind(); it.next(); )
207 WvString sect_name = getdirname(it->fullkey());
208 root[it->fullkey()].remove();
210 if (sect_name ==
".")
211 sect_name = WvString::null;
213 if (!root[sect_name].haschildren())
214 root[sect_name].remove();
217 if (++notifications_sent > CONTINUE_SELECT_AT)
219 notifications_sent = 0;
232 void UniConfDaemonConn::do_subtree(
const UniConfKey &key,
bool recursive)
234 static int niceness = 0;
242 for (it.rewind(); it.next(); )
244 writevalue(it->fullkey(cfg), it._value());
250 if (++niceness > CONTINUE_SELECT_AT)
260 for (it.rewind(); it.next(); )
262 writevalue(it->fullkey(cfg), it._value());
277 void UniConfDaemonConn::do_haschildren(
const UniConfKey &key)
279 bool haschild = root[key].haschildren();
280 writecmd(REPLY_CHILD,
285 void UniConfDaemonConn::do_commit()
292 void UniConfDaemonConn::do_refresh()
301 void UniConfDaemonConn::do_quit()
308 void UniConfDaemonConn::do_help()
310 for (
int i = 0; i < UniClientConn::NUM_COMMANDS; ++i)
311 writetext(UniClientConn::cmdinfos[i].description);
A WvFastString acts exactly like a WvString, but can take (const char *) strings without needing to a...
Represents a UniConf key which is a path in a hierarchy structured much like the traditional Unix fil...
This iterator performs depth-first traversal of a subtree.
Functions to handle "tcl-style" strings and lists.
Represents a connection to a UniConf daemon via any WvStream.
This iterator walks through all immediate children of a UniConf node.
bool continue_select(time_t msec_timeout)
return to the caller from execute(), but don't really return exactly; this uses WvCont::yield() to re...
int num() const
Return a stdc++ string with the contents of this string.
bool isnull() const
returns true if this string is null
bool uses_continue_select
If this is set, enables the use of continue_select().
void append(const UniConfKey &other)
Appends a path to this path.
virtual void close()
Close this stream.
virtual void execute()
The callback() function calls execute(), and then calls the user- specified callback if one is define...
virtual void close()
Close the stream if it is open; isok() becomes false from now on.
bool exists() const
Without fetching its value, returns true if this key exists.
Unified support for streams, that is, sequences of bytes that may or may not be ready for read/write ...
UniConfKey fullkey() const
Returns the full path of this node, starting at the root.
char * edit()
make the string editable, and return a non-const (char*)
virtual bool isok() const
return true if the stream is actually usable right now
virtual void execute()
The callback() function calls execute(), and then calls the user- specified callback if one is define...
WvString spacecat(WvStringParm a, WvStringParm b, char sep=' ', bool onesep=false)
return the string formed by concatenating string 'a' and string 'b' with the 'sep' character between ...
UniConf instances function as handles to subtrees of a UniConf tree and expose a high-level interface...
WvString wvtcl_escape(WvStringParm s, const WvStringMask &nasties=WVTCL_NASTY_SPACES)
tcl-escape a string.
void terminate_continue_select()
you MUST run this from your destructor if you use continue_select(), or very weird things will happen...
Various little string functions.
char * trim_string(char *string)
Trims whitespace from the beginning and end of the character string, including carriage return / line...
WvString is an implementation of a simple and efficient printable-string class.
virtual void close()
Close this stream.