HDK
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
UT_Packet.h
Go to the documentation of this file.
1 /*
2  * PROPRIETARY INFORMATION. This software is proprietary to
3  * Side Effects Software Inc., and is not to be reproduced,
4  * transmitted, or disclosed in any way without written permission.
5  *
6  * NAME: UT_Packet.h (Utility Libray, C++)
7  *
8  * COMMENTS:
9  * This class is used to save and load binary packets of
10  * byte streams. It is assumed that the stream is seekable.
11  *
12  */
13 
14 #ifndef __UT_Packet__
15 #define __UT_Packet__
16 
17 #include "UT_API.h"
18 #include "UT_NTStreamUtil.h"
19 #include "UT_OStream.h"
20 
21 // streampos is 64 bits on alpha, and 32 bits on the other machines,
22 // so let's use a 32 bit value
23 typedef int UT_StreamPos;
24 class UT_IStream;
25 class UT_PacketTaint;
26 class UT_OStringStream;
27 
28 UT_API short UTgetClassPacketID(const char *classname);
29 
31 {
32 public:
33  UT_Packet();
34  ~UT_Packet();
35 
36  int beginWrite(std::ostream &str, short class_id, short signature);
37  int beginWrite(UT_OStream &str, short class_id, short signature);
38  int endWrite();
39 
40  bool beginRead(UT_IStream &stream, short &class_id,
41  short &signature);
42  int cancelRead();
43  int endRead();
44 
45  // The following methods can be used if the stream is a pipe (or
46  // stdin/stdout).
47  std::ostream*beginPipeWrite(std::ostream &str, short class_id, short signature);
48  int endPipeWrite();
49 
50  UT_IStream *beginPipeRead(UT_IStream &stream, short &class_id, short &sig);
51  int endPipeRead();
52 
53  void setHeaderTaint(UT_PacketTaint *taint);
54 
55  // compressData will do zlib compression on the source data. The data
56  // should be "smallish" in that a buffer is allocated off the stack which
57  // is roughly 1.1 times the size passed in. There's an internal limit of
58  // 8Mb on data to be stored.
59  // A malloc'ed buffer is returned, and size is set to the compressed size
60  // The packet has a packet header which contains additional information
61  // used in decompression.
62  static char *compressPacket(const char *src, int &size);
63 
64  // decompressData will do zlib uncompression on the source data. The
65  // compressed data must have been created with UTcompressPacket.
66  // A malloc'ed buffer is returned, and size is set to the un-compressed size
67  static char *uncompressPacket(const char *src, int &size);
68 
69  // getHeaderSize() returns the number of bytes used for the packet header.
70  static unsigned int getHeaderSize();
71 
72 
73 private:
74  char myState;
75  UT_StreamPos myPacketSize;
76  UT_StreamPos myPacketStart;
77  UT_OStringStream *myOutBuffer;
78  UT_IStream *mySBuffer; // UT IStreams
79  UT_IStream *mySStreamPtr;
80  UT_OStream myOutStreamRef;
81  char *myData;
82  UT_PacketTaint *myHeaderTaint;
83 };
84 
85 // use this function to get the class packet-id for your class
86 // just include the line: SETUPCLASSPACKETID("LIB_CLASS") or
87 // whatever in your .C file and also add "LIB_CLASS" to the table
88 // at the top of UT_Packet.C
89 
90 #define SETUPCLASSPACKETID(classname) \
91 static int \
92 getClassPacketID() \
93 { \
94  static int classid = UTgetClassPacketID(classname); \
95  return classid; \
96 }
97 
98 #endif
GLuint GLuint stream
Definition: glcorearb.h:1831
An output stream object that owns its own string buffer storage.
#define UT_API
Definition: UT_API.h:13
int UT_StreamPos
Definition: UT_Packet.h:23
GLsizeiptr size
Definition: glcorearb.h:663
UT_API short UTgetClassPacketID(const char *classname)
GLenum src
Definition: glcorearb.h:1792