Main Page | Namespace List | Class Hierarchy | Alphabetical List | Class List | Directories | File List | Namespace Members | Class Members | File Members | Related Pages

uniclientconn.h

Go to the documentation of this file.
00001 /* -*- Mode: C++ -*-
00002  * Worldvisions Tunnel Vision Software:
00003  *   Copyright (C) 1997-2002 Net Integration Technologies, Inc.
00004  *
00005  * Manages a connection between the UniConf client and daemon.
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 DEFAULT_UNICONF_DAEMON_TCP_PORT 4111
00018 #define DEFAULT_UNICONF_DAEMON_SSL_PORT 4112
00019 
00020 /**
00021  * Represents a connection to a UniConf daemon via any WvStream.
00022  * Makes several operations much simpler, such as TCL
00023  * encoding/decoding of lists, filling of the operation buffer and
00024  * comparison for UniConf operations.
00025  */
00026 class UniClientConn : public WvStreamClone
00027 {
00028     WvDynBuf msgbuf;
00029 
00030 protected:
00031     WvLog log;
00032     bool closed;
00033     
00034 public:
00035     WvConstStringBuffer payloadbuf; /*!< holds the previous command payload */
00036     enum Command
00037     {
00038         NONE = -2, /*!< used to signal no command received */
00039         INVALID = -1, /*!< used to signal invalid command */
00040         
00041         // requests
00042         REQ_NOOP, /*!< noop ==> OK */
00043         REQ_GET, /*!< get <key> ==> VAL ... OK / FAIL */
00044         REQ_SET, /*!< set <key> <value> ==> OK / FAIL */
00045         REQ_REMOVE, /*!< del <key> ==> OK / FAIL */
00046         REQ_SUBTREE, /*!< subt <key> ==> VAL ... OK / FAIL <*/
00047         REQ_HASCHILDREN, /*!< hchild <key> => HCHILD <key> TRUE / FALSE */
00048         REQ_QUIT, /*!< quit ==> OK */
00049         REQ_HELP, /*!< help ==> TEXT ... OK / FAIL */
00050 
00051         // command completion replies
00052         REPLY_OK, /*!< OK */
00053         REPLY_FAIL, /*!< FAIL */
00054         REPLY_CHILD, /*!< HCHILD <key> TRUE / FALSE */
00055         REPLY_ONEVAL, /*!< ONEVAL <key> <value> */
00056 
00057         // partial replies
00058         PART_VALUE, /*!< VAL <key> <value> */
00059         PART_TEXT, /*!< TEXT <text> */
00060 
00061         // events
00062         EVENT_HELLO, /*!< HELLO <message> */
00063         EVENT_NOTICE, /*!< NOTICE <key> <oldval> <newval> */
00064     };
00065     static const int NUM_COMMANDS = EVENT_NOTICE + 1;
00066     struct CommandInfo
00067     {
00068         const char *name;
00069         const char *description;
00070     };
00071     static const CommandInfo cmdinfos[NUM_COMMANDS];
00072 
00073     /** Create a wrapper around the supplied WvStream. */
00074     UniClientConn(IWvStream *_s, WvStringParm dst = WvString::null);
00075     virtual ~UniClientConn();
00076 
00077     virtual bool pre_select(SelectInfo &si);
00078     virtual bool isok() const;
00079     virtual void close();
00080 
00081     /**
00082      * Reads a command from the connection.
00083      * The payload is stored in UniClientConn::payloadbuf.
00084      * Returns: the command code, NONE, or INVALID
00085      */
00086     Command readcmd();
00087 
00088     /**
00089      * Reads the next argument from the command payload.
00090      * Returns: the argument or WvString::null
00091      */
00092     WvString readarg();
00093 
00094     /**
00095      * Writes a command to the connection.
00096      * "command" is the command
00097      * "payload" is the payload
00098      */
00099     void writecmd(Command command, WvStringParm payload = WvString::null);
00100 
00101     /**
00102      * Writes a REPLY_OK message.
00103      * "payload" is the payload, defaults to ""
00104      */
00105     void writeok(WvStringParm payload = "");
00106 
00107     /**
00108      * Writes a REPLY_FAIL message.
00109      * "payload" is the payload, defaults to ""
00110      */
00111     void writefail(WvStringParm payload = "");
00112 
00113     /**
00114      * Writes a PART_VALUE message.
00115      * "key" is the key
00116      * "value" is the value
00117      */
00118     void writevalue(const UniConfKey &key, WvStringParm value);
00119 
00120     /**
00121      * Writes a PART_VALUE message.
00122      * "key" is the key
00123      * "value" is the value
00124      */ 
00125     void writeonevalue(const UniConfKey &key, WvStringParm value);
00126 
00127     /**
00128      * Writes a PART_TEXT message.
00129      * "text" is the text
00130      */
00131     void writetext(WvStringParm text);
00132 
00133 private:
00134     /** Reads a message from the connection. */
00135     WvString readmsg();
00136 
00137     /** Writes a message to the connection. */
00138     void writemsg(WvStringParm message);
00139 };
00140 
00141 #endif // __UNICONFCONN_H

Generated on Wed Dec 15 15:08:10 2004 for WvStreams by  doxygen 1.3.9.1