/home/tetron/hack/vos/libs/vos/vos/messageblock.hh
Go to the documentation of this file.00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024 #ifndef _MESSAGEBLOCK_HH_
00025 #define _MESSAGEBLOCK_HH_
00026
00027 #include <iostream>
00028 #include <deque>
00029
00030 #include <boost/thread/recursive_mutex.hpp>
00031
00032 #include <vos/vos/vosdefs.hh>
00033 #include <vos/vutil/refcount.hh>
00034
00035 #define MSGENC_BINARY_SINGLE 1
00036 #define MSGENC_BINARY_BLOCK 2
00037 #define MSGENC_XML '<'
00038
00039 namespace VOS
00040 {
00041 class MessageBlock;
00042 class Message;
00043
00044
00045
00046
00047
00048
00049 struct parse_state_t
00050 {
00051 MessageBlock* m;
00052 unsigned int chars_read;
00053 unsigned int expected_length;
00054 uint32_t nonce;
00055 bool done;
00056 void* extra;
00057 int read_quoted;
00058 std::istream* input;
00059 };
00060
00061 class MBParser
00062 {
00063 public:
00064 virtual ~MBParser() { }
00065 virtual int parseUpdate(const std::string& s, uint32_t& nonce) = 0;
00066 virtual size_t getBufferSize() = 0;
00067 virtual size_t getExpectedSize() = 0;
00068 };
00069
00070 class BinaryParser : public MBParser
00071 {
00072 private:
00073 std::string parse_buffer;
00074 uint32_t msgsize;
00075 uint8_t encoding;
00076 MessageBlock* msgblock;
00077 void readMsgBlock(const uint8_t* s, size_t input_length);
00078 unsigned int readSingleMsg(const uint8_t* s, size_t input_length);
00079
00080 public:
00081 BinaryParser(MessageBlock* mb);
00082 virtual ~BinaryParser() { }
00083
00084 virtual int parseUpdate(const std::string& s, uint32_t& nonce);
00085 virtual size_t getBufferSize();
00086 virtual size_t getExpectedSize();
00087 };
00088
00089 class XmlParser : public MBParser
00090 {
00091 private:
00092 std::string parse_buffer;
00093 uint32_t msgsize;
00094 MessageBlock* msgblock;
00095 std::string parseWord(size_t& pos);
00096 std::string parseStringAttr(size_t& pos);
00097 uint32_t parseNumberAttr(size_t& pos);
00098 void readMsgBlock(size_t& pos);
00099 void readSingleMsg(size_t& pos, uint32_t& nonce, bool withLength);
00100
00101 public:
00102 XmlParser(MessageBlock* mb);
00103 virtual ~XmlParser() { }
00104
00105 virtual int parseUpdate(const std::string& s, uint32_t& nonce);
00106 virtual size_t getBufferSize();
00107 virtual size_t getExpectedSize();
00108 };
00109
00110
00111
00112
00113
00114
00115
00116
00117
00118
00119
00120
00121 class VOS_API MessageBlock : public VUtil::RefCounted
00122 {
00123 private:
00124 boost::recursive_mutex messageblock_mutex;
00125
00126 MBParser* parser;
00127 std::deque<Message*> messages;
00128 std::string* formattedString;
00129 std::string name;
00130
00131 public:
00132 MessageBlock();
00133 ~MessageBlock();
00134
00135
00136
00137
00138
00139 void setName(const std::string& s);
00140
00141
00142
00143 std::string getName();
00144
00145
00146
00147
00148
00149
00150 void insertMessage(int n, Message* m);
00151
00152
00153
00154
00155 inline void appendMessage(Message* m) { insertMessage(-1, m); };
00156
00157
00158
00159
00160 void removeMessage(int n);
00161
00162
00163
00164
00165
00166
00167
00168 VUtil::vRef<Message> getMessage(int n);
00169
00170
00171 VUtil::vRef<Message> lastMessage();
00172
00173
00174 int numMessages();
00175
00176
00177
00178
00179 std::string getFormattedString();
00180
00181
00182
00183
00184 std::string getBinaryEncoding();
00185
00186
00187
00188
00189
00190
00191
00192 int parseUpdate(const std::string& s, uint32_t& nonce);
00193
00194
00195
00196
00197 unsigned int getReceivedBytes();
00198
00199
00200
00201
00202 unsigned int getExpectedBytes();
00203 };
00204
00205 }
00206
00207 #endif