7#include "uniconfdaemonconn.h"
8#include "uniconfdaemon.h"
9#include "wvtclstring.h"
10#include "wvstrutils.h"
18 uses_continue_select =
true;
26UniConfDaemonConn::~UniConfDaemonConn()
40void UniConfDaemonConn::addcallback()
42 root.
add_callback(
this, wv::bind(&UniConfDaemonConn::deltacallback,
this,
47void 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);
137void UniConfDaemonConn::do_invalid(WvStringParm c)
145 writefail(WvString(
"malformed request: %s",
146 UniClientConn::cmdinfos[c].name));
150void UniConfDaemonConn::do_noop()
156void UniConfDaemonConn::do_reply(WvStringParm reply)
162void UniConfDaemonConn::do_get(
const UniConfKey &key)
164 WvString value(root[key].getme());
173void UniConfDaemonConn::do_set(
const UniConfKey &key, WvStringParm value)
175 root[key].setme(value);
179void UniConfDaemonConn::do_remove(
const UniConfKey &_key)
181 int notifications_sent = 0;
182 bool single_key =
true;
185 WvString strkey = _key;
186 for (
int n = strkey.len()-1; n > 0; n--)
188 if (strkey.
edit()[n] ==
'/')
189 strkey.
edit()[n] =
' ';
196 UniConfKey key = strkey;
199 UniConf cfg(root[key]);
203 UniConf::RecursiveIter it(cfg);
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;
232void UniConfDaemonConn::do_subtree(
const UniConfKey &key,
bool recursive)
234 static int niceness = 0;
236 UniConf cfg(root[key]);
241 UniConf::RecursiveIter it(cfg);
242 for (it.rewind(); it.next(); )
250 if (++niceness > CONTINUE_SELECT_AT)
259 UniConf::Iter it(cfg);
260 for (it.rewind(); it.next(); )
277void UniConfDaemonConn::do_haschildren(
const UniConfKey &key)
279 bool haschild = root[key].haschildren();
285void UniConfDaemonConn::do_commit()
292void UniConfDaemonConn::do_refresh()
301void UniConfDaemonConn::do_quit()
308void UniConfDaemonConn::do_help()
310 for (
int i = 0; i < UniClientConn::NUM_COMMANDS; ++i)
311 writetext(UniClientConn::cmdinfos[i].description);
321 WvString value(cfg[key].getme());
324 UniConfKey fullkey(cfg.
fullkey(cfg));
Represents a connection to a UniConf daemon via any WvStream.
void writeonevalue(const UniConfKey &key, WvStringParm value)
Writes a PART_VALUE message.
virtual void close()
Close this stream.
Command readcmd()
Reads a command from the connection.
void writetext(WvStringParm text)
Writes a PART_TEXT message.
void writecmd(Command command, WvStringParm payload=WvString::null)
Writes a command to the connection.
void writefail(WvStringParm payload="")
Writes a REPLY_FAIL message.
WvString readarg()
Reads the next argument from the command payload.
void writeok(WvStringParm payload="")
Writes a REPLY_OK message.
void writevalue(const UniConfKey &key, WvStringParm value)
Writes a PART_VALUE message.
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...
Represents a UniConf key which is a path in a hierarchy structured much like the traditional Unix fil...
UniConf instances function as handles to subtrees of a UniConf tree and expose a high-level interface...
void add_callback(void *cookie, const UniConfCallback &callback, bool recurse=true) const
Requests notification when any of the keys covered by the recursive depth specification change by inv...
UniConfKey fullkey() const
Returns the full path of this node, starting at the root.
int num() const
Return a stdc++ string with the contents of this string.
bool isnull() const
returns true if this string is null
virtual bool isok() const
return true if the stream is actually usable right now
Unified support for streams, that is, sequences of bytes that may or may not be ready for read/write ...
virtual void execute()
The callback() function calls execute(), and then calls the user- specified callback if one is define...
void terminate_continue_select()
you MUST run this from your destructor if you use continue_select(), or very weird things will happen...
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...
WvString is an implementation of a simple and efficient printable-string class.
char * edit()
make the string editable, and return a non-const (char*)
char * trim_string(char *string)
Trims whitespace from the beginning and end of the character string, including carriage return / line...
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 ...
WvString wvtcl_escape(WvStringParm s, const WvStringMask &nasties=WVTCL_NASTY_SPACES)
tcl-escape a string.