gem5  v22.1.0.0
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 
42 #ifndef __BASE_VNC_VNC_SERVER_HH__
43 #define __BASE_VNC_VNC_SERVER_HH__
44 
45 #include <iostream>
46 
47 #include "base/circlebuf.hh"
48 #include "base/compiler.hh"
49 #include "base/pollevent.hh"
50 #include "base/socket.hh"
51 #include "base/vnc/vncinput.hh"
52 #include "params/VncServer.hh"
53 #include "sim/sim_object.hh"
54 
59 namespace gem5
60 {
61 
62 class VncServer : public VncInput
63 {
64  public:
65 
71  const static uint32_t AuthInvalid = 0;
72  const static uint32_t AuthNone = 1;
73 
75  const static uint32_t VncOK = 0;
76 
79  {
83  ServerCutText = 3
84  };
85 
88  {
92  EncodingDesktopSize = -223
93  };
94 
97  {
100  MouseMiddleButton = 0x4
101  };
102 
103  const char* vncVersion() const
104  {
105  return "RFB 003.008\n";
106  }
107 
109  {
115  };
116 
118  {
119  uint16_t fbWidth;
120  uint16_t fbHeight;
122  uint32_t namelen;
123  char name[2]; // just to put M5 in here
124  };
125 
127  {
128  uint8_t type;
129  uint8_t padding;
130  uint16_t num_rects;
131  };
132 
134  {
135  uint16_t x;
136  uint16_t y;
137  uint16_t width;
138  uint16_t height;
139  int32_t encoding;
140  };
141 
143  {
144  uint8_t type;
145  uint8_t padding[3];
146  uint32_t length;
147  };
148 
151  protected:
153  class ListenEvent: public PollEvent
154  {
155  protected:
157 
158  public:
159  ListenEvent(VncServer *vs, int fd, int e);
160  void process(int revent);
161  };
162 
163  friend class ListenEvent;
165 
167  class DataEvent: public PollEvent
168  {
169  protected:
171 
172  public:
173  DataEvent(VncServer *vs, int fd, int e);
174  void process(int revent);
175  };
176 
177  friend class DataEvent;
179 
180  int number;
181  int dataFd; // data stream file describer
182 
184 
185  void listen(int port);
186  void accept();
187  void data();
188  void detach();
189 
190  public:
191  typedef VncServerParams Params;
192  VncServer(const Params &p);
193  ~VncServer();
194 
195  // RFB
196  protected:
197 
200 
204 
207 
210 
213 
214  protected:
222  void sendError(const char* error_msg);
223 
229  bool read(uint8_t *buf, size_t len);
230 
239  bool read1(uint8_t *buf, size_t len);
240 
241 
246  template <typename T> bool read(T* val);
247 
248 
254  bool write(const uint8_t *buf, size_t len);
255 
260  template <typename T> bool write(T* val);
261 
265  bool write(const char* str);
266 
270  void checkProtocolVersion();
271 
274  void checkSecurity();
275 
277  void sendServerInit();
278 
282  void sendError(std::string error_msg);
283 
287  void sendFrameBufferUpdate();
288 
290  void setPixelFormat();
291 
293  void setEncodings();
294 
296  void requestFbUpdate();
297 
299  void recvKeyboardInput();
300 
302  void recvPointerInput();
303 
308  void recvCutText();
309 
313  void sendFrameBufferResized();
314 
316 
317  public:
318  void setDirty() override;
319  void frameBufferResized() override;
320 };
321 
322 } // namespace gem5
323 
324 #endif
virtual std::string name() const
Definition: named.hh:47
Configurable RGB pixel converter.
Definition: pixel.hh:92
VncInputParams Params
Definition: vncinput.hh:166
DataEvent to read data from vnc.
Definition: vncserver.hh:168
void process(int revent)
Definition: vncserver.cc:107
DataEvent(VncServer *vs, int fd, int e)
Poll event for the data socket.
Definition: vncserver.cc:101
ListenEvent to accept a vnc client connection.
Definition: vncserver.hh:154
void process(int revent)
Definition: vncserver.cc:93
ListenEvent(VncServer *vs, int fd, int e)
Poll event for the listen socket.
Definition: vncserver.cc:87
void recvKeyboardInput()
Receive message from client providing new keyboard input.
Definition: vncserver.cc:571
ListenSocket listener
Definition: vncserver.hh:183
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:302
void sendServerInit()
Send client our idea about what the frame buffer looks like.
Definition: vncserver.cc:453
void setEncodings()
Receive encodings message from client and process it.
Definition: vncserver.cc:515
ListenEvent * listenEvent
Definition: vncserver.hh:164
bool write(const uint8_t *buf, size_t len)
Write a buffer to the client.
Definition: vncserver.cc:317
bool supportsResizeEnc
If the vnc client supports the desktop resize command.
Definition: vncserver.hh:212
void frameBufferResized() override
Definition: vncserver.cc:724
void sendFrameBufferResized()
Tell the client that the frame buffer resized.
Definition: vncserver.cc:682
void setPixelFormat()
Receive pixel foramt message from client and process it.
Definition: vncserver.cc:483
DataEvent * dataEvent
Definition: vncserver.hh:178
void checkSecurity()
Check that the security exchange was successful.
Definition: vncserver.cc:431
void sendError(std::string error_msg)
Send an error message to the client when something goes wrong.
void requestFbUpdate()
Receive message from client asking for updated frame buffer.
Definition: vncserver.cc:551
void listen(int port)
Definition: vncserver.cc:160
VncServerParams Params
Definition: vncserver.hh:191
void sendFrameBufferUpdate()
Send a updated frame buffer to the client.
Definition: vncserver.cc:629
void recvPointerInput()
Recv message from client providing new mouse movement or button click.
Definition: vncserver.cc:587
void recvCutText()
Receive message from client that there is text in it's paste buffer.
Definition: vncserver.cc:605
bool supportsRawEnc
If the vnc client supports receiving raw data.
Definition: vncserver.hh:209
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:715
static const PixelConverter pixelConverter
Definition: vncserver.hh:315
void sendError(const char *error_msg)
vnc client Interface
Definition: vncserver.cc:368
void checkProtocolVersion()
Check the client's protocol verion for compatibility and send the security types we support.
Definition: vncserver.cc:377
bool read(uint8_t *buf, size_t len)
Read some data from the client.
Definition: vncserver.cc:281
PixelFormat pixelFormat
The one and only pixel format we support.
Definition: vncserver.hh:206
VncServer(const Params &p)
VncServer.
Definition: vncserver.cc:118
ConnectionState curState
The rfb prototol state the connection is in.
Definition: vncserver.hh:199
bool sendUpdate
An update needs to be sent to the client.
Definition: vncserver.hh:203
EncodingTypes
Encoding types.
Definition: vncserver.hh:88
ServerMessages
Server -> Client message IDs.
Definition: vncserver.hh:79
const char * vncVersion() const
Definition: vncserver.hh:103
MouseEvents
keyboard/mouse support
Definition: vncserver.hh:97
static const uint32_t VncOK
Error conditions.
Definition: vncserver.hh:75
static const uint32_t AuthInvalid
Authentication modes.
Definition: vncserver.hh:71
static const uint32_t AuthNone
Definition: vncserver.hh:72
@ ServerSetColorMapEntries
Definition: vncserver.hh:81
@ ServerFrameBufferUpdate
Definition: vncserver.hh:80
uint16_t len
Definition: helpers.cc:62
Bitfield< 14, 12 > fd
Definition: types.hh:150
Bitfield< 9 > e
Definition: misc_types.hh:65
Bitfield< 19 > vs
Definition: misc_types.hh:576
Bitfield< 54 > p
Definition: pagetable.hh:70
Bitfield< 63 > val
Definition: misc.hh:776
Reference material can be found at the JEDEC website: UFS standard http://www.jedec....
PM4 packets.
Definition: pm4_defines.hh:78
Declaration of a VNC input.

Generated on Wed Dec 21 2022 10:22:29 for gem5 by doxygen 1.9.1