gem5  v19.0.0.0
All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Modules Pages
vncserver.hh
Go to the documentation of this file.
1 /*
2  * Copyright (c) 2010, 2015 ARM Limited
3  * All rights reserved
4  *
5  * The license below extends only to copyright in the software and shall
6  * not be construed as granting a license to any other intellectual
7  * property including but not limited to intellectual property relating
8  * to a hardware implementation of the functionality of the software
9  * licensed hereunder. You may use the software subject to the license
10  * terms below provided that you ensure that this notice is replicated
11  * unmodified and in its entirety in all distributions of the software,
12  * modified or unmodified, in source code or in binary form.
13  *
14  * Redistribution and use in source and binary forms, with or without
15  * modification, are permitted provided that the following conditions are
16  * met: redistributions of source code must retain the above copyright
17  * notice, this list of conditions and the following disclaimer;
18  * redistributions in binary form must reproduce the above copyright
19  * notice, this list of conditions and the following disclaimer in the
20  * documentation and/or other materials provided with the distribution;
21  * neither the name of the copyright holders nor the names of its
22  * contributors may be used to endorse or promote products derived from
23  * this software without specific prior written permission.
24  *
25  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
26  * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
27  * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
28  * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
29  * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
30  * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
31  * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
32  * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
33  * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
34  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
35  * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
36  *
37  * Authors: Ali Saidi
38  * William Wang
39  */
40 
45 #ifndef __BASE_VNC_VNC_SERVER_HH__
46 #define __BASE_VNC_VNC_SERVER_HH__
47 
48 #include <iostream>
49 
50 #include "base/vnc/vncinput.hh"
51 #include "base/circlebuf.hh"
52 #include "base/pollevent.hh"
53 #include "base/socket.hh"
54 #include "params/VncServer.hh"
55 #include "sim/sim_object.hh"
56 
61 class VncServer : public VncInput
62 {
63  public:
64 
70  const static uint32_t AuthInvalid = 0;
71  const static uint32_t AuthNone = 1;
72 
74  const static uint32_t VncOK = 0;
75 
82  };
83 
90  };
91 
93  enum MouseEvents {
97  };
98 
99  const char* vncVersion() const
100  {
101  return "RFB 003.008\n";
102  }
103 
110  };
111 
112  struct ServerInitMsg {
113  uint16_t fbWidth;
114  uint16_t fbHeight;
116  uint32_t namelen;
117  char name[2]; // just to put M5 in here
118  } M5_ATTR_PACKED;
119 
121  uint8_t type;
122  uint8_t padding;
123  uint16_t num_rects;
124  } M5_ATTR_PACKED;
125 
127  uint16_t x;
128  uint16_t y;
129  uint16_t width;
130  uint16_t height;
131  int32_t encoding;
132  } M5_ATTR_PACKED;
133 
134  struct ServerCutText {
135  uint8_t type;
136  uint8_t padding[3];
137  uint32_t length;
138  } M5_ATTR_PACKED;
139 
142  protected:
144  class ListenEvent: public PollEvent
145  {
146  protected:
148 
149  public:
150  ListenEvent(VncServer *vs, int fd, int e);
151  void process(int revent);
152  };
153 
154  friend class ListenEvent;
156 
158  class DataEvent: public PollEvent
159  {
160  protected:
162 
163  public:
164  DataEvent(VncServer *vs, int fd, int e);
165  void process(int revent);
166  };
167 
168  friend class DataEvent;
170 
171  int number;
172  int dataFd; // data stream file describer
173 
175 
176  void listen(int port);
177  void accept();
178  void data();
179  void detach();
180 
181  public:
182  typedef VncServerParams Params;
183  VncServer(const Params *p);
184  ~VncServer();
185 
186  // RFB
187  protected:
188 
191 
195 
198 
201 
204 
205  protected:
213  void sendError(const char* error_msg);
214 
220  bool read(uint8_t *buf, size_t len);
221 
230  bool read1(uint8_t *buf, size_t len);
231 
232 
237  template <typename T> bool read(T* val);
238 
239 
245  bool write(const uint8_t *buf, size_t len);
246 
251  template <typename T> bool write(T* val);
252 
256  bool write(const char* str);
257 
261  void checkProtocolVersion();
262 
265  void checkSecurity();
266 
268  void sendServerInit();
269 
273  void sendError(std::string error_msg);
274 
278  void sendFrameBufferUpdate();
279 
281  void setPixelFormat();
282 
284  void setEncodings();
285 
287  void requestFbUpdate();
288 
290  void recvKeyboardInput();
291 
293  void recvPointerInput();
294 
299  void recvCutText();
300 
304  void sendFrameBufferResized();
305 
307 
308  public:
309  void setDirty() override;
310  void frameBufferResized() override;
311 };
312 
313 #endif
int number
Definition: vncserver.hh:171
VncServerParams Params
Definition: vncserver.hh:182
static const uint32_t AuthInvalid
Authentication modes.
Definition: vncserver.hh:70
DataEvent to read data from vnc.
Definition: vncserver.hh:158
PixelFormat pixelFormat
The one and only pixel format we support.
Definition: vncserver.hh:197
void requestFbUpdate()
Receive message from client asking for updated frame buffer.
Definition: vncserver.cc:552
ListenSocket listener
Definition: vncserver.hh:174
int dataFd
Definition: vncserver.hh:172
void data()
Definition: vncserver.cc:223
void sendFrameBufferResized()
Tell the client that the frame buffer resized.
Definition: vncserver.cc:683
void listen(int port)
Definition: vncserver.cc:163
VncServer(const Params *p)
VncServer.
Definition: vncserver.cc:121
ConnectionState curState
The rfb prototol state the connection is in.
Definition: vncserver.hh:190
friend class DataEvent
Definition: vncserver.hh:168
VncServer * vncserver
Definition: vncserver.hh:147
EncodingTypes
Encoding types.
Definition: vncserver.hh:85
void setEncodings()
Receive encodings message from client and process it.
Definition: vncserver.cc:516
Bitfield< 63 > val
Definition: misc.hh:771
Bitfield< 9, 5 > vs
void sendError(const char *error_msg)
vnc client Interface
Definition: vncserver.cc:371
void checkSecurity()
Check that the security exchange was successful.
Definition: vncserver.cc:432
ServerMessages
Server -> Client message IDs.
Definition: vncserver.hh:77
void setPixelFormat()
Receive pixel foramt message from client and process it.
Definition: vncserver.cc:484
bool read1(uint8_t *buf, size_t len)
Read len -1 bytes from the client into the buffer provided + 1 assert that we read enough bytes...
Definition: vncserver.cc:305
void accept()
Definition: vncserver.cc:186
DataEvent * dataEvent
Definition: vncserver.hh:169
void recvPointerInput()
Recv message from client providing new mouse movement or button click.
Definition: vncserver.cc:588
void frameBufferResized() override
Definition: vncserver.cc:725
static const PixelConverter pixelConverter
Definition: vncserver.hh:306
ListenEvent * listenEvent
Definition: vncserver.hh:155
Bitfield< 18, 16 > len
bool supportsRawEnc
If the vnc client supports receiving raw data.
Definition: vncserver.hh:200
void setDirty() override
The frame buffer uses this call to notify the vnc server that the frame buffer has been updated and a...
Definition: vncserver.cc:716
void sendServerInit()
Send client our idea about what the frame buffer looks like.
Definition: vncserver.cc:454
struct VncServer::ServerInitMsg M5_ATTR_PACKED
friend class ListenEvent
Definition: vncserver.hh:154
bool read(uint8_t *buf, size_t len)
Read some data from the client.
Definition: vncserver.cc:284
void recvKeyboardInput()
Receive message from client providing new keyboard input.
Definition: vncserver.cc:572
void sendFrameBufferUpdate()
Send a updated frame buffer to the client.
Definition: vncserver.cc:630
static const uint32_t AuthNone
Definition: vncserver.hh:71
Bitfield< 9 > e
ListenEvent to accept a vnc client connection.
Definition: vncserver.hh:144
void checkProtocolVersion()
Check the client&#39;s protocol verion for compatibility and send the security types we support...
Definition: vncserver.cc:380
Declaration of a VNC input.
MouseEvents
keyboard/mouse support
Definition: vncserver.hh:93
bool sendUpdate
An update needs to be sent to the client.
Definition: vncserver.hh:194
void recvCutText()
Receive message from client that there is text in it&#39;s paste buffer.
Definition: vncserver.cc:606
Configurable RGB pixel converter.
Definition: pixel.hh:89
Bitfield< 14, 12 > fd
Definition: types.hh:160
Bitfield< 0 > p
const char * vncVersion() const
Definition: vncserver.hh:99
bool write(const uint8_t *buf, size_t len)
Write a buffer to the client.
Definition: vncserver.cc:320
VncServer * vncserver
Definition: vncserver.hh:161
void detach()
Definition: vncserver.cc:351
static const uint32_t VncOK
Error conditions.
Definition: vncserver.hh:74
bool supportsResizeEnc
If the vnc client supports the desktop resize command.
Definition: vncserver.hh:203

Generated on Fri Feb 28 2020 16:26:58 for gem5 by doxygen 1.8.13