WvStreams
include/uniclientconn.h
1/* -*- Mode: C++ -*-
2 * Worldvisions Tunnel Vision Software:
3 * Copyright (C) 1997-2002 Net Integration Technologies, Inc.
4 *
5 * Manages a connection between the UniConf client and daemon.
6 */
7#ifndef __UNICONFCONN_H
8#define __UNICONFCONN_H
9
10#include "uniconfkey.h"
11#include "uniconfgen.h"
12#include "wvstreamclone.h"
13#include "wvistreamlist.h"
14#include "wvbuf.h"
15#include "wvlog.h"
16
17#define UNICONF_PROTOCOL_VERSION UniClientConn::NUM_COMMANDS
18#define DEFAULT_UNICONF_DAEMON_TCP_PORT 4111
19#define DEFAULT_UNICONF_DAEMON_SSL_PORT 4112
20
27class UniClientConn : public WvStreamClone
28{
29 WvDynBuf msgbuf;
30
31protected:
32 WvLog log;
33 bool closed;
34 int version;
35
36public:
39 /* This table is _very_ important!!!
40 *
41 * With UniConf, we promise to never remove or modify the behaviour of
42 * any of the commands listed here. If you want to modify anything,
43 * you'd better just add a new command instead. We keep track of the
44 * version of the UniConf protocol by the number of commands supported
45 * by the server.
46 *
47 * @see UniClientConn::cmdinfos
48 */
50 {
51 NONE = -2,
52 INVALID = -1,
54 // requests
55 REQ_NOOP,
56 REQ_GET,
57 REQ_SET,
58 REQ_SETV,
64 REQ_QUIT,
65 REQ_HELP,
67 // command completion replies
68 REPLY_OK,
73 // partial replies
75 PART_TEXT,
77 // events
80 };
81 static const int NUM_COMMANDS = EVENT_NOTICE + 1;
82 struct CommandInfo
83 {
84 const char *name;
85 const char *description;
86 };
87 static const CommandInfo cmdinfos[NUM_COMMANDS];
88
90 UniClientConn(IWvStream *_s, WvStringParm dst = WvString::null);
91 virtual ~UniClientConn();
92
93 virtual void close();
94
102 Command readcmd(WvString &command);
103
109
115 void writecmd(Command command, WvStringParm payload = WvString::null);
116
121 void writeok(WvStringParm payload = "");
122
127 void writefail(WvStringParm payload = "");
128
134 void writevalue(const UniConfKey &key, WvStringParm value);
135
141 void writeonevalue(const UniConfKey &key, WvStringParm value);
142
148
149private:
151 WvString readmsg();
152
154 void writemsg(WvStringParm message);
155};
156
157#endif // __UNICONFCONN_H
Represents a connection to a UniConf daemon via any WvStream.
void writeonevalue(const UniConfKey &key, WvStringParm value)
Writes a PART_VALUE message.
Command readcmd()
Reads a command from the connection.
void writetext(WvStringParm text)
Writes a PART_TEXT message.
virtual void close()
Close this stream.
void writecmd(Command command, WvStringParm payload=WvString::null)
Writes a command to the connection.
Command readcmd()
Reads a command from the connection.
UniClientConn(IWvStream *_s, WvStringParm dst=WvString::null)
Create a wrapper around the supplied WvStream.
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.
Represents a UniConf key which is a path in a hierarchy structured much like the traditional Unix fil...
A raw memory read-only buffer backed by a constant WvString.
A WvFastString acts exactly like a WvString, but can take (const char *) strings without needing to a...
A WvLog stream accepts log messages from applications and forwards them to all registered WvLogRcv's.
WvStreamClone simply forwards all requests to the "cloned" stream.
WvString is an implementation of a simple and efficient printable-string class.