source: xplra/src/client/c/hu/varadiistvan/xplra/xplra.h@ 27:a228b1e1e16a

Last change on this file since 27:a228b1e1e16a was 27:a228b1e1e16a, checked in by István Váradi <ivaradi@…>, 11 years ago

Made the class Slot into a template

File size: 11.0 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
30#ifndef HU_VARADIISTVAN_XPLRA_XPLRA_H
31#define HU_VARADIISTVAN_XPLRA_XPLRA_H
32/*----------------------------------------------------------------------------*/
33
34#include <stdlib.h>
35#include <inttypes.h>
36
37/*----------------------------------------------------------------------------*/
38
39#ifdef __cplusplus
40extern "C" {
41#endif
42
43/*----------------------------------------------------------------------------*/
44
45/** No error occured */
46#define ERROR_NONE 0
47
48/**
49 * An I/O error has occured. The subcode is the errno value on Linux, or the
50 * Windows error code.
51 */
52#define ERROR_IO 1
53
54/**
55 * A protocol error has occured. The subcode is one of the
56 * ERROR_PROTOCOL_XXX values.
57 */
58#define ERROR_PROTOCOL 2
59
60/** Invalid command was passed to the plugin */
61#define ERROR_PROTOCOL_INVALID_COMMAND = 1
62
63/** An unknown dataref was specified */
64#define ERROR_PROTOCOL_UNKNOWN_DATAREF = 2
65
66/** An invalid type was specified */
67#define ERROR_PROTOCOL_INVALID_TYPE = 3
68
69/** An invalid length was specified */
70#define ERROR_PROTOCOL_INVALID_LENGTH = 4
71
72/** An invalid offset was specified */
73#define ERROR_PROTOCOL_INVALID_OFFSET = 5
74
75/** An invalid count was specified */
76#define ERROR_PROTOCOL_INVALID_COUNT = 6
77
78/** An invalid ID was specified */
79#define ERROR_PROTOCOL_INVALID_ID = 7
80
81/** Other protocol error */
82#define ERROR_PROTOCOL_OTHER = 8
83
84/** A function requiring a connection is called without a connection */
85#define ERROR_NOT_CONNECTED 3
86
87/** A type-specific function was called for a dataref of a different type */
88#define ERROR_TYPE_MISMATCH 4
89
90/** An invalid ID was passed to a function */
91#define ERROR_INVALID_ID 5
92
93/** Some other error */
94#define ERROR_OTHER 255
95
96/*----------------------------------------------------------------------------*/
97
98/**
99 * Get the last error code with the subcode.
100 *
101 * @return the last error code, or -1 if the given connection ID is invalid.
102 */
103int xplra_get_last_error(int connectionID, unsigned long* subCode);
104
105/**
106 * Get a string representation of the last error.
107 *
108 * @return the string representation of the last error, or 0 if there
109 * was no last error, or the connection ID is invalid.
110 */
111const char* xplra_get_last_error_string(int connectionID);
112
113/**
114 * Clear the last error.
115 */
116void xplra_clear_last_error(int connectionID);
117
118/*----------------------------------------------------------------------------*/
119
120/**
121 * Connect to the simulator.
122 *
123 * @return an ID for the created connection, or -1 on error.
124 */
125int xplra_connect();
126
127/*----------------------------------------------------------------------------*/
128/* Single dataref support */
129/*----------------------------------------------------------------------------*/
130
131/**
132 * Get an integer value from the simulator.
133 *
134 * @return 0 on success, -1 on error
135 */
136int xplra_get_int(int* value, int connectionID, const char* name);
137
138/*----------------------------------------------------------------------------*/
139
140/**
141 * Get a float value from the simulator.
142 *
143 * @return 0 on success, -1 on error
144 */
145int xplra_get_float(float* value, int connectionID, const char* name);
146
147/*----------------------------------------------------------------------------*/
148
149/**
150 * Get a double value from the simulator.
151 *
152 * @return 0 on success, -1 on error
153 */
154int xplra_get_double(double* value, int connectionID, const char* name);
155
156/*----------------------------------------------------------------------------*/
157
158/**
159 * Get an array of floats into a buffer.
160 *
161 * @param dest the array into which to get the data
162 * @param length the length of the destination buffer
163 * @param offset the offset from which to query the array
164 *
165 * @return the actual number of elements returned in case of success,
166 * -1 on error
167 */
168ssize_t xplra_get_float_array(float* dest, size_t length, size_t offset,
169 int connectionID, const char* name);
170
171/*----------------------------------------------------------------------------*/
172
173/**
174 * Get an array of floats into a newly allocated buffer.
175 *
176 * @param length pointer to a variable containing the length to
177 * query. On return it will be set to the actual length, which can be
178 * less than or equal to the input value.
179 * @param offset the offset from which to query the array
180 *
181 * @return the new array on success, 0 on error
182 */
183float* xplra_get_float_array_new(size_t* length, size_t offset,
184 int connectionID, const char* name);
185
186/*----------------------------------------------------------------------------*/
187
188/**
189 * Get an array of integers into a buffer.
190 *
191 * @param dest the array into which to get the data
192 * @param length the length of the destination buffer
193 * @param offset the offset from which to query the array
194 *
195 * @return the actual number of elements returned in case of success,
196 * -1 on error
197 */
198ssize_t xplra_get_int_array(int32_t* dest, size_t length, size_t offset,
199 int connectionID, const char* name);
200
201/*----------------------------------------------------------------------------*/
202
203/**
204 * Get an array of integers into a newly allocated buffer.
205 *
206 * @param length pointer to a variable containing the length to
207 * query. On return it will be set to the actual length, which can be
208 * less than or equal to the input value.
209 * @param offset the offset from which to query the array
210 *
211 * @return the new array on success, 0 on error
212 */
213int32_t* xplra_get_int_array_new(size_t* length, size_t offset,
214 int connectionID, const char* name);
215
216/*----------------------------------------------------------------------------*/
217
218/**
219 * Get an array of bytes into a buffer.
220 *
221 * @param dest the array into which to get the data
222 * @param length the length of the destination buffer
223 * @param offset the offset from which to query the array
224 *
225 * @return the actual number of elements returned in case of success,
226 * -1 on error
227 */
228ssize_t xplra_get_byte_array(void* dest, size_t length, size_t offset,
229 int connectionID, const char* name);
230
231/*----------------------------------------------------------------------------*/
232
233/**
234 * Get an array of bytes into a newly allocated buffer.
235 *
236 * @param length pointer to a variable containing the length to
237 * query. On return it will be set to the actual length, which can be
238 * less than or equal to the input value.
239 * @param offset the offset from which to query the array
240 *
241 * @return the new array on success, 0 on error
242 */
243uint8_t* xplra_get_byte_array_new(size_t* length, size_t offset,
244 int connectionID, const char* name);
245
246/*----------------------------------------------------------------------------*/
247
248/**
249 * Set the integer dataref with the given name to the given value.
250 *
251 * @return 0 on success, -1 on error.
252 */
253int xplra_set_int(int connectionID, const char* name, int value);
254
255/*----------------------------------------------------------------------------*/
256
257/**
258 * Set the float dataref with the given name to the given value.
259 *
260 * @return 0 on success, -1 on error.
261 */
262int xplra_set_float(int connectionID, const char* name, float value);
263
264/*----------------------------------------------------------------------------*/
265
266/**
267 * Set the double dataref with the given name to the given value.
268 *
269 * @return 0 on success, -1 on error.
270 */
271int xplra_set_double(int connectionID, const char* name, double value);
272
273/*----------------------------------------------------------------------------*/
274
275/**
276 * Set the array of float values with the given name from the given
277 * buffer.
278 *
279 * @return 0 on success, -1 on error.
280 */
281int xplra_set_float_array(int connectionID, const char* name,
282 const float* values, size_t length, size_t offset);
283
284/*----------------------------------------------------------------------------*/
285
286/**
287 * Set the array of integer values with the given name from the given
288 * buffer.
289 *
290 * @return 0 on success, -1 on error.
291 */
292int xplra_set_int_array(int connectionID, const char* name,
293 const int32_t* values, size_t length, size_t offset);
294
295/*----------------------------------------------------------------------------*/
296
297/**
298 * Set the array of byte values with the given name from the given
299 * buffer.
300 *
301 * @return 0 on success, -1 on error.
302 */
303int xplra_set_byte_array(int connectionID, const char* name,
304 const void* values, size_t length, size_t offset);
305
306/*----------------------------------------------------------------------------*/
307
308/**
309 * Set the array of byte values with the given name from the given
310 * string. The string will be padded with 0 if it has a length less
311 * than the given length.
312 *
313 * @return 0 on success, -1 on error.
314 */
315int xplra_set_string(int connectionID, const char* name,
316 const char* value, size_t length, size_t offset);
317
318/*----------------------------------------------------------------------------*/
319/* Multi-dataref support */
320/*----------------------------------------------------------------------------*/
321
322
323
324/*----------------------------------------------------------------------------*/
325
326/**
327 * Destroy the connection with the given ID.
328 *
329 * @return 0 on success, -1 on error.
330 */
331int xplra_disconnect(int connectionID);
332
333/*----------------------------------------------------------------------------*/
334
335#ifdef __cplusplus
336} // extern "C"
337#endif
338
339/*----------------------------------------------------------------------------*/
340#endif // HU_VARADIISTVAN_XPLRA_XPLRA_H
Note: See TracBrowser for help on using the repository browser.