1 /**************************************************************************/
2 /*                                                                        */
3 /* Copyright (c) 2001, 2011 NoMachine (http://www.nomachine.com)          */
4 /* Copyright (c) 2008-2014 Oleksandr Shneyder <o.shneyder@phoca-gmbh.de>  */
5 /* Copyright (c) 2014-2016 Ulrich Sibiller <uli42@gmx.de>                 */
6 /* Copyright (c) 2014-2016 Mihai Moldovan <ionic@ionic.de>                */
7 /* Copyright (c) 2011-2016 Mike Gabriel <mike.gabriel@das-netzwerkteam.de>*/
8 /* Copyright (c) 2015-2016 Qindel Group (http://www.qindel.com)           */
9 /*                                                                        */
10 /* NXCOMP, NX protocol compression and NX extensions to this software     */
11 /* are copyright of the aforementioned persons and companies.             */
12 /*                                                                        */
13 /* Redistribution and use of the present software is allowed according    */
14 /* to terms specified in the file LICENSE.nxcomp which comes in the       */
15 /* source distribution.                                                   */
16 /*                                                                        */
17 /* All rights reserved.                                                   */
18 /*                                                                        */
19 /* NOTE: This software has received contributions from various other      */
20 /* contributors, only the core maintainers and supporters are listed as   */
21 /* copyright holders. Please contact us, if you feel you should be listed */
22 /* as copyright holder, as well.                                          */
23 /*                                                                        */
24 /**************************************************************************/
25 
26 #ifndef ClearArea_H
27 #define ClearArea_H
28 
29 #include "Message.h"
30 
31 //
32 // Set the verbosity level.
33 //
34 
35 #define PANIC
36 #define WARNING
37 #undef  TEST
38 #undef  DEBUG
39 #undef  DUMP
40 
41 //
42 // Set default values.
43 //
44 
45 #define CLEARAREA_ENABLE_CACHE               1
46 #define CLEARAREA_ENABLE_DATA                0
47 #define CLEARAREA_ENABLE_SPLIT               0
48 #define CLEARAREA_ENABLE_COMPRESS            0
49 
50 #define CLEARAREA_DATA_LIMIT                 0
51 #define CLEARAREA_DATA_OFFSET                16
52 
53 #define CLEARAREA_CACHE_SLOTS                3000
54 #define CLEARAREA_CACHE_THRESHOLD            5
55 #define CLEARAREA_CACHE_LOWER_THRESHOLD      1
56 
57 //
58 // The message class.
59 //
60 
61 class ClearAreaMessage : public Message
62 {
63   friend class ClearAreaStore;
64 
65   public:
66 
ClearAreaMessage()67   ClearAreaMessage()
68   {
69   }
70 
~ClearAreaMessage()71   ~ClearAreaMessage()
72   {
73   }
74 
75   //
76   // Put here the fields which constitute
77   // the 'identity' part of the message.
78   //
79 
80   private:
81 
82   unsigned char  exposures;
83   unsigned int   window;
84   unsigned short x;
85   unsigned short y;
86   unsigned short width;
87   unsigned short height;
88 };
89 
90 class ClearAreaStore : public MessageStore
91 {
92   //
93   // Constructors and destructors.
94   //
95 
96   public:
97 
ClearAreaStore()98   ClearAreaStore() : MessageStore()
99   {
100     enableCache    = CLEARAREA_ENABLE_CACHE;
101     enableData     = CLEARAREA_ENABLE_DATA;
102     enableSplit    = CLEARAREA_ENABLE_SPLIT;
103     enableCompress = CLEARAREA_ENABLE_COMPRESS;
104 
105     dataLimit  = CLEARAREA_DATA_LIMIT;
106     dataOffset = CLEARAREA_DATA_OFFSET;
107 
108     cacheSlots          = CLEARAREA_CACHE_SLOTS;
109     cacheThreshold      = CLEARAREA_CACHE_THRESHOLD;
110     cacheLowerThreshold = CLEARAREA_CACHE_LOWER_THRESHOLD;
111 
112     messages_ -> resize(cacheSlots);
113 
114     for (T_messages::iterator i = messages_ -> begin();
115              i < messages_ -> end(); i++)
116     {
117       *i = NULL;
118     }
119 
120     temporary_ = NULL;
121   }
122 
~ClearAreaStore()123   virtual ~ClearAreaStore()
124   {
125     for (T_messages::iterator i = messages_ -> begin();
126              i < messages_ -> end(); i++)
127     {
128       destroy(*i);
129     }
130 
131     destroy(temporary_);
132   }
133 
name()134   virtual const char *name() const
135   {
136     return "ClearArea";
137   }
138 
opcode()139   virtual unsigned char opcode() const
140   {
141     return X_ClearArea;
142   }
143 
storage()144   virtual unsigned int storage() const
145   {
146     return sizeof(ClearAreaMessage);
147   }
148 
149   //
150   // Message handling methods.
151   //
152 
153   public:
154 
create()155   virtual Message *create() const
156   {
157     return new ClearAreaMessage();
158   }
159 
create(const Message & message)160   virtual Message *create(const Message &message) const
161   {
162     return new ClearAreaMessage((const ClearAreaMessage &) message);
163   }
164 
destroy(Message * message)165   virtual void destroy(Message *message) const
166   {
167     delete (ClearAreaMessage *) message;
168   }
169 
170   virtual int parseIdentity(Message *message, const unsigned char *buffer,
171                                 unsigned int size, int bigEndian) const;
172 
173   virtual int unparseIdentity(const Message *message, unsigned char *buffer,
174                                   unsigned int size, int bigEndian) const;
175 
176   virtual void identityChecksum(const Message *message, const unsigned char *buffer,
177                                     unsigned int size, int bigEndian) const;
178 
179   virtual void dumpIdentity(const Message *message) const;
180 };
181 
182 #endif /* ClearArea_H */
183