00001
00002
00003
00004
00005
00006
00007 #ifndef __UNICONFCONN_H
00008 #define __UNICONFCONN_H
00009
00010 #include "uniconfkey.h"
00011 #include "uniconfgen.h"
00012 #include "wvstreamclone.h"
00013 #include "wvistreamlist.h"
00014 #include "wvbuf.h"
00015 #include "wvlog.h"
00016
00017 #define UNICONF_PROTOCOL_VERSION UniClientConn::NUM_COMMANDS
00018 #define DEFAULT_UNICONF_DAEMON_TCP_PORT 4111
00019 #define DEFAULT_UNICONF_DAEMON_SSL_PORT 4112
00020
00027 class UniClientConn : public WvStreamClone
00028 {
00029 WvDynBuf msgbuf;
00030
00031 protected:
00032 WvLog log;
00033 bool closed;
00034 int version;
00035
00036 public:
00037 WvConstStringBuffer payloadbuf;
00039
00040
00041
00042
00043
00044
00045
00046
00047
00048
00049 enum Command
00050 {
00051 NONE = -2,
00052 INVALID = -1,
00054
00055 REQ_NOOP,
00056 REQ_GET,
00057 REQ_SET,
00058 REQ_SETV,
00059 REQ_REMOVE,
00060 REQ_SUBTREE,
00061 REQ_HASCHILDREN,
00062 REQ_COMMIT,
00063 REQ_REFRESH,
00064 REQ_QUIT,
00065 REQ_HELP,
00067
00068 REPLY_OK,
00069 REPLY_FAIL,
00070 REPLY_CHILD,
00071 REPLY_ONEVAL,
00073
00074 PART_VALUE,
00075 PART_TEXT,
00077
00078 EVENT_HELLO,
00079 EVENT_NOTICE,
00080 };
00081 static const int NUM_COMMANDS = EVENT_NOTICE + 1;
00082 struct CommandInfo
00083 {
00084 const char *name;
00085 const char *description;
00086 };
00087 static const CommandInfo cmdinfos[NUM_COMMANDS];
00088
00090 UniClientConn(IWvStream *_s, WvStringParm dst = WvString::null);
00091 virtual ~UniClientConn();
00092
00093 virtual void close();
00094
00101 Command readcmd();
00102 Command readcmd(WvString &command);
00103
00108 WvString readarg();
00109
00115 void writecmd(Command command, WvStringParm payload = WvString::null);
00116
00121 void writeok(WvStringParm payload = "");
00122
00127 void writefail(WvStringParm payload = "");
00128
00134 void writevalue(const UniConfKey &key, WvStringParm value);
00135
00141 void writeonevalue(const UniConfKey &key, WvStringParm value);
00142
00147 void writetext(WvStringParm text);
00148
00149 private:
00151 WvString readmsg();
00152
00154 void writemsg(WvStringParm message);
00155 };
00156
00157 #endif // __UNICONFCONN_H