source: xplra/src/plugin/src/xplra/Protocol.h@ 99:bb320ead601d

Last change on this file since 99:bb320ead601d was 98:496e56f242ea, checked in by István Váradi <ivaradi@…>, 5 years ago

Added missing include to Protocol.h

File size: 8.1 KB
Line 
1// Copyright (c) 2013 by István Váradi
2
3// This file is part of XPLRA, a remote-access plugin for X-Plane
4
5// Redistribution and use in source and binary forms, with or without
6// modification, are permitted provided that the following conditions are met:
7
8// 1. Redistributions of source code must retain the above copyright notice, this
9// list of conditions and the following disclaimer.
10// 2. Redistributions in binary form must reproduce the above copyright notice,
11// this list of conditions and the following disclaimer in the documentation
12// and/or other materials provided with the distribution.
13
14// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
15// ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
16// WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
17// DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR
18// ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
19// (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
20// LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
21// ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
22// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
23// SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
24
25// The views and conclusions contained in the software and documentation are those
26// of the authors and should not be interpreted as representing official policies,
27// either expressed or implied, of the FreeBSD Project.
28
29#ifndef XPLRA_PROTOCOL_H
30#define XPLRA_PROTOCOL_H
31//------------------------------------------------------------------------------
32
33#include <inttypes.h>
34
35//------------------------------------------------------------------------------
36
37namespace xplra {
38
39//------------------------------------------------------------------------------
40
41/**
42 * Constants and helpers for the protocol.
43 */
44class Protocol
45{
46public:
47 /**
48 * Command: get the value of a single dataref.
49 */
50 static const uint8_t COMMAND_GET_SINGLE = 0x01;
51
52 /**
53 * Command: set the value of a single dataref.
54 */
55 static const uint8_t COMMAND_SET_SINGLE = 0x02;
56
57 /**
58 * Command: get the value of a multiple datarefs.
59 */
60 static const uint8_t COMMAND_GET_MULTI = 0x03;
61
62 /**
63 * Command: set the value of a multiple datarefs.
64 */
65 static const uint8_t COMMAND_SET_MULTI = 0x04;
66
67 /**
68 * Command: register a multiple-data query request
69 */
70 static const uint8_t COMMAND_REGISTER_GET_MULTI = 0x11;
71
72 /**
73 * Command: unregister a multiple-data query request
74 */
75 static const uint8_t COMMAND_UNREGISTER_GET_MULTI = 0x12;
76
77 /**
78 * Command: execute a registered multiple-data query request
79 */
80 static const uint8_t COMMAND_EXECUTE_GET_MULTI = 0x13;
81
82 /**
83 * Command: register a multiple-data update request
84 */
85 static const uint8_t COMMAND_REGISTER_SET_MULTI = 0x21;
86
87 /**
88 * Command: unregister a multiple-data update request
89 */
90 static const uint8_t COMMAND_UNREGISTER_SET_MULTI = 0x22;
91
92 /**
93 * Command: execute a registered multiple-data update request
94 */
95 static const uint8_t COMMAND_EXECUTE_SET_MULTI = 0x23;
96
97 /**
98 * Command: get the versions of the simulator
99 */
100 static const uint8_t COMMAND_GET_VERSIONS = 0x31;
101
102 /**
103 * Command: reload the plugins
104 */
105 static const uint8_t COMMAND_RELOAD_PLUGINS = 0x32;
106
107 /**
108 * Command: save the current situation.
109 *
110 * Followed by a string containing the path of the file to save
111 * relative to the X-System directory.
112 */
113 static const uint8_t COMMAND_SAVE_SITUATION = 0x33;
114
115 /**
116 * Command: show a message in the message window.
117 */
118 static const uint8_t COMMAND_SHOW_MESSAGE = 0x41;
119
120 /**
121 * Command: register a set of hotkeys for the client. Old hotkeys,
122 * if any, are forgotten.
123 *
124 * The command is followed by the following data:
125 * - The number of the hotkeys defined (U32).
126 * - The code of the hotkeys (U16*number of the hotkeys).
127 * The lower byte is the same as the X-Plane virtual key code
128 * (the same as the ASCII code for numbers and upper-case letters),
129 * the upper one is a logical OR of the HOTKEY_MODIFIER_XXX
130 * codes.
131 *
132 * The reply consists of a result code only. It may fail with an
133 * invalid length code if the number of hotkeys is too large.
134 */
135 static const uint8_t COMMAND_REGISTER_HOTKEYS = 0x51;
136
137 /**
138 * Command: query the hotkeys.
139 *
140 * The reply consists of a result code, followed by the following
141 * data, if the result code is RESULT_OK:
142 * - The number of hotkeys defined (U32).
143 * - An array of U8 values each being 0 or 1 depending on whether
144 * the corresponding hotkey has been pressed since the last
145 * query (or the registration, whichever is later). The value at
146 * index i corresponds to the hotkey code at index i in the
147 * array passed with COMMAND_REGISTER_HOTKEYS.
148 *
149 * If not hotkey has been registered, the number of hotkeys is
150 * returned as 0.
151 */
152 static const uint8_t COMMAND_QUERY_HOTKEYS = 0x52;
153
154 /**
155 * Command: unregister the previously registered hotkeys.
156 *
157 * The reply is a result code.
158 */
159 static const uint8_t COMMAND_UNREGISTER_HOTKEYS = 0x53;
160
161 /**
162 * Data type: int
163 */
164 static const uint8_t TYPE_INT = 0x01;
165
166 /**
167 * Data type: float
168 */
169 static const uint8_t TYPE_FLOAT = 0x02;
170
171 /**
172 * Data type: double
173 */
174 static const uint8_t TYPE_DOUBLE = 0x03;
175
176 /**
177 * Data type: float array
178 */
179 static const uint8_t TYPE_FLOAT_ARRAY = 0x11;
180
181 /**
182 * Data type: int array
183 */
184 static const uint8_t TYPE_INT_ARRAY = 0x12;
185
186 /**
187 * Data type: byte array
188 */
189 static const uint8_t TYPE_BYTE_ARRAY = 0x13;
190
191 /**
192 * Result code: no error, everything is OK.
193 */
194 static const uint8_t RESULT_OK = 0x00;
195
196 /**
197 * Result code: invalid command
198 */
199 static const uint8_t RESULT_INVALID_COMMAND = 0x01;
200
201 /**
202 * Result code: unknown dataref
203 */
204 static const uint8_t RESULT_UNKNOWN_DATAREF = 0x02;
205
206 /**
207 * Result code: invalid type
208 */
209 static const uint8_t RESULT_INVALID_TYPE = 0x03;
210
211 /**
212 * Result code: invalid length
213 */
214 static const uint8_t RESULT_INVALID_LENGTH = 0x04;
215
216 /**
217 * Result code: invalid offset
218 */
219 static const uint8_t RESULT_INVALID_OFFSET = 0x05;
220
221 /**
222 * Result code: invalid count
223 */
224 static const uint8_t RESULT_INVALID_COUNT = 0x06;
225
226 /**
227 * Result code: invalid ID
228 */
229 static const uint8_t RESULT_INVALID_ID = 0x07;
230
231 /**
232 * Result code: invalid duration
233 */
234 static const uint8_t RESULT_INVALID_DURATION = 0x08;
235
236 /**
237 * Result code: other error
238 */
239 static const uint8_t RESULT_OTHER_ERROR = 0xff;
240
241 /**
242 * Hotkey modifier: shift
243 */
244 static const uint16_t HOTKEY_MODIFIER_SHIFT = 0x0100;
245
246 /**
247 * Hotkey modifier: control
248 */
249 static const uint16_t HOTKEY_MODIFIER_CONTROL = 0x0200;
250
251 /**
252 * The maximal length we accept (in order to protect ourselves).
253 */
254 static const int MAX_LENGTH = 2048;
255
256 /**
257 * The maximal count of requests in a multiple-data query or
258 * update.
259 */
260 static const size_t MAX_MULTI_COUNT = 1024;
261
262 /**
263 * The maximal message duration
264 */
265 static constexpr float MAX_MESSAGE_DURATION = 5*60;
266
267 /**
268 * The maximal number of hotkeys that can be registered for a
269 * client.
270 */
271 static const size_t MAX_HOTKEY_COUNT = 128;
272
273 /**
274 * The version of the plugin.
275 */
276 static const int version = 10;
277};
278
279//------------------------------------------------------------------------------
280
281} /* namespace xplra */
282
283//------------------------------------------------------------------------------
284#endif // XPLRA_PROTOCOL_H
285
286// Local Variables:
287// mode: C++
288// c-basic-offset: 4
289// indent-tabs-mode: nil
290// End:
Note: See TracBrowser for help on using the repository browser.