Main Page | Modules | Namespace List | Class Hierarchy | Alphabetical List | Compound List | File List | Namespace Members | Compound Members | File Members | Related Pages | Examples

vos/corelibs/vos/messageblock.hh

Go to the documentation of this file.
00001 /*
00002     This file is part of the Virtual Object System of
00003     the Interreality project (http://interreality.org).
00004 
00005     Copyright (C) 2001-2003 Peter Amstutz
00006 
00007     This library is free software; you can redistribute it and/or
00008     modify it under the terms of the GNU Lesser General Public
00009     License as published by the Free Software Foundation; either
00010     version 2 of the License, or (at your option) any later version.
00011 
00012     This library is distributed in the hope that it will be useful,
00013     but WITHOUT ANY WARRANTY; without even the implied warranty of
00014     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00015     Lesser General Public License for more details.
00016 
00017     You should have received a copy of the GNU Lesser General Public
00018     License along with this library; if not, write to the Free Software
00019     Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307  USA
00020 
00021     Peter Amstutz <tetron@interreality.org>
00022 */
00023 
00024 #ifndef _MESSAGEBLOCK_HH_
00025 #define _MESSAGEBLOCK_HH_
00026 
00027 #include <vos/corelibs/vos/vosdefs.hh>
00028 #include <vos/corelibs/vos/refcount.hh>
00029 
00030 #include <iostream>
00031 #include <deque>
00032 
00033 
00034 namespace VOS
00035 {
00036     class MessageBlock;
00037     class Message;
00038 
00039 /**
00040     Stores some state information needed between calls to the Message parser, when
00041     a message has only been partially parsed.
00042     @internal
00043  */
00044 struct parse_state_t
00045 {
00046     MessageBlock* m;
00047     unsigned int chars_read;
00048     unsigned int expected_length;
00049     bool done;
00050     void* extra;
00051     int read_quoted;
00052     std::istream* input;
00053 };
00054 
00055 /**  @class MessageBlock messageblock.hh vos/corelibs/vos/messageblock.hh
00056  *
00057  * A message block is a list of messages which have been bundled
00058      together into a single block.  It is used for various purposes.
00059      One useful feature of a message block is that it is processed all
00060      at once: the first message will not be delivered until the entire
00061      message block has been received, parsed and queued.  This is be
00062      useful for supporting transactions.
00063  */
00064 class VOS_API MessageBlock : public virtual RefCounted
00065 {
00066 private:
00067     deque<Message*> messages;
00068     int expected_length;
00069     string* formattedString;
00070     string parse_buffer;
00071     parse_state_t parsestate;
00072     string name;
00073 public:
00074     MessageBlock();
00075     ~MessageBlock();
00076 
00077     /** Set the message block macro name, which can then be refered
00078         back to later in a message using &lt;include&gt;.  If this is blank, the message
00079         block will not be used as a macro template.
00080         @param s the name
00081     */
00082     void setName(const string& s);
00083 
00084     /** Get the macro name.
00085         @return the macro name
00086     */
00087     string getName();
00088 
00089     /** Add a message to the message block.
00090         @param n The position to insert into.  May be negative, in which case the position
00091         will be counted from the end.  To append to the end, use -1.
00092         @param m the message to insert
00093     */
00094     void insertMessage(int n, Message* m);
00095 
00096     /** Remove a message from the message block.
00097         @param n The position to remove.
00098     */
00099     void removeMessage(int n);
00100 
00101     /** Retrieve a message from this messageblock.
00102         @param n The desired position.  May be negative, in which case
00103         the position will be counted from the end.  The very
00104         last element can be accessed using -1.
00105         @return The message at the desired position, or 0 if the index is invalid.
00106         NOTE YOU MUST CALL release() WHEN DONE OR USE vRef.
00107     */
00108     Message* getMessage(int n);
00109 
00110     /** Convenience function returns the last message in this messageblock.
00111         @return The last message 0 if the message block is empty.
00112         NOTE YOU MUST CALL release() WHEN DONE OR USE vRef.
00113     */
00114     Message* lastMessage();
00115 
00116     /** Get the number of messages in the messageblock.
00117         @return the number of messages in the messageblock.
00118     */
00119     int numMessages();
00120 
00121     /** Get the XML-like textual representation of this messageblock,
00122         suitable for sending over the network.
00123      */
00124     const string& getString();
00125 
00126     /** Internal parsing function.  Update the current partial parse of this messageblock with new data.
00127         @param s the new data
00128         @return The number of bytes from the beginning of 's' which
00129         were read in.  However, 0 is special: rather than
00130         meaning that nothing was read in, this indicates that the
00131         ENTIRE string was read in, but more data is still expected.
00132     */
00133     int parseUpdate(const string& s);
00134 };
00135 
00136 /** Bison driver for XML parser. 
00137  * @internal
00138  */ 
00139 int msgparse(void* lexer);
00140 
00141 /** Bison callback for XML parser. 
00142  * @internal
00143  */
00144 int msglex(char** lvalp, void* lexer);
00145 
00146 /** Bison callback for XML parser. 
00147  * @internal */
00148 void msgerror(char* blah);
00149 }
00150 
00151 #endif

Generated on Tue Aug 12 03:55:40 2003 for Interreality Project - VOS by doxygen 1.3.2