00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021 #ifndef _GLASS_PACKET_HH_
00022 #define _GLASS_PACKET_HH_
00023
00024 #include <ostream>
00025 #include <set>
00026 #include <vector>
00027 #include "types.h"
00028 #include "chain.h"
00029
00030 namespace libglass {
00031
00032 const PluginId rootBaseId = PluginId("RootBase");
00033
00034 class Packet {
00035 private:
00036 nodeId from;
00037 chain data;
00038 PluginId pid;
00039 bool reliable;
00041 std::set<nodeId> targetIds;
00042 std::set<nodeFD> targetFDs;
00044 protected:
00045 friend class Glass;
00046 friend class Protocol;
00047
00048 public:
00052 Packet();
00053
00057 virtual ~Packet();
00058
00064 void setData(unsigned char *data, unsigned int length);
00065
00071 void setData(const char *data, unsigned int length);
00072
00077 void setData(chain &s);
00078
00085 void appendData(unsigned char *data, unsigned int length);
00086
00093 void appendData(const char *data, unsigned int length);
00094
00099 void appendData(string &s);
00100
00105 void appendData(chain &s);
00106
00112 unsigned int getDataLength(void) const;
00113
00114 #ifdef DEPRECATED
00115
00123 unsigned char *getData(void) const;
00124 #endif
00125
00131 void getData(chain &s);
00132
00138 void setPluginId(PluginId id);
00139
00145 PluginId getPluginId(void) const;
00146
00152 void setTargetNodes(nodeId id);
00153
00159 void setTargetNodes(std::set<nodeId> &id_set);
00160
00166 void setTargetNodes(std::vector<nodeId> &id_set);
00167
00173 void addTargetNodes(nodeId id);
00174
00180 void addTargetNodes(std::set<nodeId> &id_set);
00181
00187 std::set<nodeId> &getTargetNodes(void);
00188
00193 void clearTargetNodes(void);
00194
00200 void setSenderNode(nodeId id);
00201
00211 bool isReliable(void) const;
00212
00221 void setReliable(bool reliable);
00222
00228 nodeId getSenderNode(void) const;
00229
00233 void setTargetFDs(nodeFD fd);
00234
00238 void setTargetFDs(std::set<nodeFD> &fds);
00239
00240 std::set<nodeFD> &getTargetFDs(void);
00241
00253 virtual chain encode(unsigned int *len = NULL);
00254
00275 bool decode(chain &s);
00276
00282 bool decode(unsigned char *buffer, unsigned int length);
00283
00291 bool decode(unsigned char *header, unsigned int headerlen,
00292 unsigned char *databuf, unsigned int datalen);
00293
00297 virtual std::ostream& print(std::ostream &o);
00298
00299 friend std::ostream& operator<<(std::ostream &o, Packet &p);
00300 };
00301
00302 extern std::ostream& operator<<(std::ostream &o, Packet &p);
00303
00304 }
00305
00306 #endif