xbmc
EventPacket.h
1 /*
2  * Copyright (C) 2005-2018 Team Kodi
3  * This file is part of Kodi - https://kodi.tv
4  *
5  * SPDX-License-Identifier: GPL-2.0-or-later
6  * See LICENSES/README.md for more information.
7  */
8 
9 #pragma once
10 
11 #include <cstdint>
12 #include <stdlib.h>
13 #include <vector>
14 
15 namespace EVENTPACKET
16 {
17  const int PACKET_SIZE = 1024;
18  const int HEADER_SIZE = 32;
19  const char HEADER_SIG[] = "XBMC";
20  const int HEADER_SIG_LENGTH = 4;
21 
22  /************************************************************************/
23  /* */
24  /* - Generic packet structure (maximum 1024 bytes per packet) */
25  /* - Header is 32 bytes long, so 992 bytes available for payload */
26  /* - large payloads can be split into multiple packets using H4 and H5 */
27  /* H5 should contain total no. of packets in such a case */
28  /* - H6 contains length of P1, which is limited to 992 bytes */
29  /* - if H5 is 0 or 1, then H4 will be ignored (single packet msg) */
30  /* - H7 must be set to zeros for now */
31  /* */
32  /* ----------------------------- */
33  /* | -H1 Signature ("XBMC") | - 4 x CHAR 4B */
34  /* | -H2 Version (eg. 2.0) | - 2 x UNSIGNED CHAR 2B */
35  /* | -H3 PacketType | - 1 x UNSIGNED SHORT 2B */
36  /* | -H4 Sequence number | - 1 x UNSIGNED LONG 4B */
37  /* | -H5 No. of packets in msg | - 1 x UNSIGNED LONG 4B */
38  /* | -H6 Payload size | - 1 x UNSIGNED SHORT 2B */
39  /* | -H7 Client's unique token | - 1 x UNSIGNED LONG 4B */
40  /* | -H8 Reserved | - 10 x UNSIGNED CHAR 10B */
41  /* |---------------------------| */
42  /* | -P1 payload | - */
43  /* ----------------------------- */
44  /************************************************************************/
45 
46  /************************************************************************
47  The payload format for each packet type is described below each
48  packet type.
49 
50  Legend:
51  %s - null terminated ASCII string (strlen + '\0' bytes)
52  (empty string is represented as a single byte NULL '\0')
53  %c - single byte
54  %i - network byte ordered short unsigned integer (2 bytes)
55  %d - network byte ordered long unsigned integer (4 bytes)
56  XX - binary data prefixed with %d size
57  (can span multiple packets with <raw>)
58  raw - raw binary data
59  ************************************************************************/
60 
61  enum LogoType
62  {
63  LT_NONE = 0x00,
64  LT_JPEG = 0x01,
65  LT_PNG = 0x02,
66  LT_GIF = 0x03
67  };
68 
69  enum ButtonFlags
70  {
71  PTB_USE_NAME = 0x01,
72  PTB_DOWN = 0x02,
73  PTB_UP = 0x04,
74  PTB_USE_AMOUNT = 0x08,
75  PTB_QUEUE = 0x10,
76  PTB_NO_REPEAT = 0x20,
77  PTB_VKEY = 0x40,
78  PTB_AXIS = 0x80,
79  PTB_AXISSINGLE = 0x100,
80  PTB_UNICODE = 0x200
81  };
82 
83  enum MouseFlags
84  {
85  PTM_ABSOLUTE = 0x01
86  /* PTM_RELATIVE = 0x02 */
87  };
88 
89  enum ActionType
90  {
91  AT_EXEC_BUILTIN = 0x01,
92  AT_BUTTON = 0x02
93  };
94 
95  enum PacketType
96  {
97  PT_HELO = 0x01,
98  /************************************************************************/
99  /* Payload format */
100  /* %s - device name (max 128 chars) */
101  /* %c - icontype ( 0=>NOICON, 1=>JPEG , 2=>PNG , 3=>GIF ) */
102  /* %s - my port ( 0=>not listening ) */
103  /* %d - reserved1 ( 0 ) */
104  /* %d - reserved2 ( 0 ) */
105  /* XX - imagedata ( can span multiple packets ) */
106  /************************************************************************/
107 
108  PT_BYE = 0x02,
109  /************************************************************************/
110  /* no payload */
111  /************************************************************************/
112 
113  PT_BUTTON = 0x03,
114  /************************************************************************/
115  /* Payload format */
116  /* %i - button code */
117  /* %i - flags 0x01 => use button map/name instead of code */
118  /* 0x02 => btn down */
119  /* 0x04 => btn up */
120  /* 0x08 => use amount */
121  /* 0x10 => queue event */
122  /* 0x20 => do not repeat */
123  /* 0x40 => virtual key */
124  /* 0x80 => axis key */
125  /* %i - amount ( 0 => 65k maps to -1 => 1 ) */
126  /* %s - device map (case sensitive and required if flags & 0x01) */
127  /* "KB" - Standard keyboard map */
128  /* "XG" - Xbox Gamepad */
129  /* "R1" - Xbox Remote */
130  /* "R2" - Xbox Universal Remote */
131  /* "LI:devicename" - valid LIRC device map where 'devicename' */
132  /* is the actual name of the LIRC device */
133  /* "JS<num>:joyname" - valid Joystick device map where */
134  /* 'joyname' is the name specified in */
135  /* the keymap. JS only supports button code */
136  /* and not button name currently (!0x01). */
137  /* %s - button name (required if flags & 0x01) */
138  /************************************************************************/
139 
140  PT_MOUSE = 0x04,
141  /************************************************************************/
142  /* Payload format */
143  /* %c - flags */
144  /* - 0x01 absolute position */
145  /* %i - mousex (0-65535 => maps to screen width) */
146  /* %i - mousey (0-65535 => maps to screen height) */
147  /************************************************************************/
148 
149  PT_PING = 0x05,
150  /************************************************************************/
151  /* no payload */
152  /************************************************************************/
153 
154  PT_BROADCAST = 0x06,
155  /************************************************************************/
156  /* @todo implement */
157  /* Payload format: TODO */
158  /************************************************************************/
159 
160  PT_NOTIFICATION = 0x07,
161  /************************************************************************/
162  /* Payload format: */
163  /* %s - caption */
164  /* %s - message */
165  /* %c - icontype ( 0=>NOICON, 1=>JPEG , 2=>PNG , 3=>GIF ) */
166  /* %d - reserved ( 0 ) */
167  /* XX - imagedata ( can span multiple packets ) */
168  /************************************************************************/
169 
170  PT_BLOB = 0x08,
171  /************************************************************************/
172  /* Payload format */
173  /* raw - raw binary data */
174  /************************************************************************/
175 
176  PT_LOG = 0x09,
177  /************************************************************************/
178  /* Payload format */
179  /* %c - log type */
180  /* %s - message */
181  /************************************************************************/
182  PT_ACTION = 0x0A,
183  /************************************************************************/
184  /* Payload format */
185  /* %c - action type */
186  /* %s - action message */
187  /************************************************************************/
188  PT_DEBUG = 0xFF,
189  /************************************************************************/
190  /* Payload format: */
191  /************************************************************************/
192 
193  PT_LAST // NO-OP
194  };
195 
197  {
198  public:
199  CEventPacket() = default;
200 
201  explicit CEventPacket(int datasize, const void* data) { Parse(datasize, data); }
202 
203  virtual ~CEventPacket() = default;
204  virtual bool Parse(int datasize, const void *data);
205  bool IsValid() const { return m_bValid; }
206  PacketType Type() const { return m_eType; }
207  unsigned int Size() const { return m_iTotalPackets; }
208  unsigned int Sequence() const { return m_iSeq; }
209  const uint8_t* Payload() const { return m_pPayload.data(); }
210  unsigned int PayloadSize() const { return m_pPayload.size(); }
211  unsigned int ClientToken() const { return m_iClientToken; }
212  void SetPayload(std::vector<uint8_t> payload);
213 
214  protected:
215  bool m_bValid{false};
216  unsigned int m_iSeq{0};
217  unsigned int m_iTotalPackets{0};
218  unsigned char m_header[32];
219  std::vector<uint8_t> m_pPayload;
220  unsigned int m_iClientToken{0};
221  unsigned char m_cMajVer{'0'};
222  unsigned char m_cMinVer{'0'};
223  PacketType m_eType{PT_LAST};
224  };
225 
226 }
227 
Definition: EventPacket.h:196
Definition: EventPacket.h:15