1 /**************************************************************************/ 2 /* */ 3 /* Copyright (c) 2001, 2010 NoMachine, http://www.nomachine.com/. */ 4 /* */ 5 /* NXCOMP, NX protocol compression and NX extensions to this software */ 6 /* are copyright of NoMachine. Redistribution and use of the present */ 7 /* software is allowed according to terms specified in the file LICENSE */ 8 /* which comes in the source distribution. */ 9 /* */ 10 /* Check http://www.nomachine.com/licensing.html for applicability. */ 11 /* */ 12 /* NX and NoMachine are trademarks of Medialogic S.p.A. */ 13 /* */ 14 /* All rights reserved. */ 15 /* */ 16 /**************************************************************************/ 17 18 #ifndef WriteBuffer_H 19 #define WriteBuffer_H 20 21 #include "Misc.h" 22 23 #define PANIC 24 #define WARNING 25 #undef TEST 26 #undef DEBUG 27 28 #define WRITE_BUFFER_DEFAULT_SIZE 16384 29 30 // 31 // Adjust for the biggest reply that we could receive. 32 // This is likely to be a reply to a X_ListFonts where 33 // user has a large amount of installed fonts. 34 // 35 36 #define WRITE_BUFFER_OVERFLOW_SIZE 4194304 37 38 class WriteBuffer 39 { 40 public: 41 42 WriteBuffer(); 43 44 ~WriteBuffer(); 45 46 void setSize(unsigned int initialSize, unsigned int thresholdSize, 47 unsigned int maximumSize); 48 49 unsigned char *addMessage(unsigned int numBytes); 50 51 unsigned char *removeMessage(unsigned int numBytes); 52 53 unsigned char *addScratchMessage(unsigned int numBytes); 54 55 // 56 // This form allows user to provide its own 57 // buffer as write buffer's scratch area. 58 // 59 60 unsigned char *addScratchMessage(unsigned char *newBuffer, unsigned int numBytes); 61 62 void removeScratchMessage(); 63 64 void partialReset(); 65 66 void fullReset(); 67 getData()68 unsigned char *getData() const 69 { 70 return buffer_; 71 } 72 getLength()73 unsigned int getLength() const 74 { 75 return length_; 76 } 77 getAvailable()78 unsigned int getAvailable() const 79 { 80 return (size_ - length_); 81 } 82 getScratchData()83 unsigned char *getScratchData() const 84 { 85 return scratchBuffer_; 86 } 87 getScratchLength()88 unsigned int getScratchLength() const 89 { 90 return scratchLength_; 91 } 92 getTotalLength()93 unsigned int getTotalLength() const 94 { 95 return (length_ + scratchLength_); 96 } 97 registerPointer(unsigned char ** pointer)98 void registerPointer(unsigned char **pointer) 99 { 100 index_ = pointer; 101 } 102 unregisterPointer()103 void unregisterPointer() 104 { 105 index_ = 0; 106 } 107 108 private: 109 110 unsigned int size_; 111 unsigned int length_; 112 113 unsigned char *buffer_; 114 unsigned char **index_; 115 116 unsigned int scratchLength_; 117 unsigned char *scratchBuffer_; 118 119 int scratchOwner_; 120 121 unsigned int initialSize_; 122 unsigned int thresholdSize_; 123 unsigned int maximumSize_; 124 }; 125 126 #endif /* WriteBuffer_H */ 127