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()
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);
137 void UniConfDaemonConn::do_invalid(WvStringParm c)
146 UniClientConn::cmdinfos[c].name));
150 void UniConfDaemonConn::do_noop()
156 void UniConfDaemonConn::do_reply(WvStringParm reply)
162 void UniConfDaemonConn::do_get(
const UniConfKey &key)
173 void UniConfDaemonConn::do_set(
const UniConfKey &key, WvStringParm 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())
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(); )
250 if (++niceness > CONTINUE_SELECT_AT)
260 for (it.rewind(); it.next(); )
277 void UniConfDaemonConn::do_haschildren(
const UniConfKey &key)
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);
char * edit()
make the string editable, and return a non-const (char*)
bool refresh() const
Refreshes information about this key recursively.
void commit() const
Commits information about this key recursively.
void writeok(WvStringParm payload="")
Writes a REPLY_OK message.
void del_callback(void *cookie, bool recurse=true) const
Cancels notification requested using add_callback().
WvString readarg()
Reads the next argument from the command payload.
virtual void execute()
The callback() function calls execute(), and then calls the user- specified callback if one is define...
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...
void remove() const
Removes this key and all of its children from the registry.
UniConf instances function as handles to subtrees of a UniConf tree and expose a high-level interface...
void writetext(WvStringParm text)
Writes a PART_TEXT message.
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 ...
Represents a connection to a UniConf daemon via any WvStream.
bool uses_continue_select
If this is set, enables the use of continue_select().
WvString is an implementation of a simple and efficient printable-string class.
bool isnull() const
returns true if this string is null
WvString wvtcl_escape(WvStringParm s, const WvStringMask &nasties=WVTCL_NASTY_SPACES)
tcl-escape a string.
Represents a UniConf key which is a path in a hierarchy structured much like the traditional Unix fil...
void terminate_continue_select()
you MUST run this from your destructor if you use continue_select(), or very weird things will happen...
virtual void close()
Close this stream.
void setme(WvStringParm value) const
Stores a string value for this key into the registry.
Unified support for streams, that is, sequences of bytes that may or may not be ready for read/write ...
void writefail(WvStringParm payload="")
Writes a REPLY_FAIL message.
virtual bool isok() const
return true if the stream is actually usable right now
void writecmd(Command command, WvStringParm payload=WvString::null)
Writes a command to the connection.
virtual void execute()
The callback() function calls execute(), and then calls the user- specified callback if one is define...
Command readcmd()
Reads a command from the connection.
void writeonevalue(const UniConfKey &key, WvStringParm value)
Writes a PART_VALUE message.
UniConfKey fullkey() const
Returns the full path of this node, starting at the root.
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...
bool haschildren() const
Returns true if this key has children.
virtual void close()
Close this stream.
This iterator walks through all immediate children of a UniConf node.
int num() const
Return a stdc++ string with the contents of this string.
This iterator performs depth-first traversal of a subtree.
void writevalue(const UniConfKey &key, WvStringParm value)
Writes a PART_VALUE message.