source: xplra/src/client/c/hu/varadiistvan/xplra/xplra.h@ 36:29e3b676c0c2

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

Added a new command to query the versions

File size: 24.2 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#define INVALID_DATAREF_ID ((size_t)-1)
99
100/*----------------------------------------------------------------------------*/
101
102/**
103 * Get the last error code with the subcode.
104 *
105 * @return the last error code, or -1 if the given connection ID is invalid.
106 */
107int xplra_get_last_error(int connectionID, unsigned long* subCode);
108
109/**
110 * Get a string representation of the last error.
111 *
112 * @return the string representation of the last error, or 0 if there
113 * was no last error, or the connection ID is invalid.
114 */
115const char* xplra_get_last_error_string(int connectionID);
116
117/**
118 * Clear the last error.
119 */
120void xplra_clear_last_error(int connectionID);
121
122/*----------------------------------------------------------------------------*/
123
124/**
125 * Connect to the simulator.
126 *
127 * @return an ID for the created connection, or -1 on error.
128 */
129int xplra_connect();
130
131/*----------------------------------------------------------------------------*/
132
133/**
134 * Get the versions of X-Plane, the XPLM library and XPLRA
135 */
136int xplra_get_versions(int connectionID,
137 int* xplaneVersion, int* xplmVersion,
138 int* xplraVersion);
139
140/*----------------------------------------------------------------------------*/
141/* Single dataref support */
142/*----------------------------------------------------------------------------*/
143
144/**
145 * Get an integer value from the simulator.
146 *
147 * @return 0 on success, -1 on error
148 */
149int xplra_get_int(int* value, int connectionID, const char* name);
150
151/*----------------------------------------------------------------------------*/
152
153/**
154 * Get a float value from the simulator.
155 *
156 * @return 0 on success, -1 on error
157 */
158int xplra_get_float(float* value, int connectionID, const char* name);
159
160/*----------------------------------------------------------------------------*/
161
162/**
163 * Get a double value from the simulator.
164 *
165 * @return 0 on success, -1 on error
166 */
167int xplra_get_double(double* value, int connectionID, const char* name);
168
169/*----------------------------------------------------------------------------*/
170
171/**
172 * Get an array of floats into a buffer.
173 *
174 * @param dest the array into which to get the data
175 * @param length the length of the destination buffer
176 * @param offset the offset from which to query the array
177 *
178 * @return the actual number of elements returned in case of success,
179 * -1 on error
180 */
181ssize_t xplra_get_float_array(float* dest, size_t length, size_t offset,
182 int connectionID, const char* name);
183
184/*----------------------------------------------------------------------------*/
185
186/**
187 * Get an array of floats into a newly allocated buffer.
188 *
189 * @param length pointer to a variable containing the length to
190 * query. On return it will be set to the actual length, which can be
191 * less than or equal to the input value.
192 * @param offset the offset from which to query the array
193 *
194 * @return the new array on success, 0 on error
195 */
196float* xplra_get_float_array_new(size_t* length, size_t offset,
197 int connectionID, const char* name);
198
199/*----------------------------------------------------------------------------*/
200
201/**
202 * Get an array of integers into a buffer.
203 *
204 * @param dest the array into which to get the data
205 * @param length the length of the destination buffer
206 * @param offset the offset from which to query the array
207 *
208 * @return the actual number of elements returned in case of success,
209 * -1 on error
210 */
211ssize_t xplra_get_int_array(int32_t* dest, size_t length, size_t offset,
212 int connectionID, const char* name);
213
214/*----------------------------------------------------------------------------*/
215
216/**
217 * Get an array of integers into a newly allocated buffer.
218 *
219 * @param length pointer to a variable containing the length to
220 * query. On return it will be set to the actual length, which can be
221 * less than or equal to the input value.
222 * @param offset the offset from which to query the array
223 *
224 * @return the new array on success, 0 on error
225 */
226int32_t* xplra_get_int_array_new(size_t* length, size_t offset,
227 int connectionID, const char* name);
228
229/*----------------------------------------------------------------------------*/
230
231/**
232 * Get an array of bytes into a buffer.
233 *
234 * @param dest the array into which to get the data
235 * @param length the length of the destination buffer
236 * @param offset the offset from which to query the array
237 *
238 * @return the actual number of elements returned in case of success,
239 * -1 on error
240 */
241ssize_t xplra_get_byte_array(void* dest, size_t length, size_t offset,
242 int connectionID, const char* name);
243
244/*----------------------------------------------------------------------------*/
245
246/**
247 * Get an array of bytes into a newly allocated buffer.
248 *
249 * @param length pointer to a variable containing the length to
250 * query. On return it will be set to the actual length, which can be
251 * less than or equal to the input value.
252 * @param offset the offset from which to query the array
253 *
254 * @return the new array on success, 0 on error
255 */
256uint8_t* xplra_get_byte_array_new(size_t* length, size_t offset,
257 int connectionID, const char* name);
258
259/*----------------------------------------------------------------------------*/
260
261/**
262 * Set the integer dataref with the given name to the given value.
263 *
264 * @return 0 on success, -1 on error.
265 */
266int xplra_set_int(int connectionID, const char* name, int value);
267
268/*----------------------------------------------------------------------------*/
269
270/**
271 * Set the float dataref with the given name to the given value.
272 *
273 * @return 0 on success, -1 on error.
274 */
275int xplra_set_float(int connectionID, const char* name, float value);
276
277/*----------------------------------------------------------------------------*/
278
279/**
280 * Set the double dataref with the given name to the given value.
281 *
282 * @return 0 on success, -1 on error.
283 */
284int xplra_set_double(int connectionID, const char* name, double value);
285
286/*----------------------------------------------------------------------------*/
287
288/**
289 * Set the array of float values with the given name from the given
290 * buffer.
291 *
292 * @return 0 on success, -1 on error.
293 */
294int xplra_set_float_array(int connectionID, const char* name,
295 const float* values, size_t length, size_t offset);
296
297/*----------------------------------------------------------------------------*/
298
299/**
300 * Set the array of integer values with the given name from the given
301 * buffer.
302 *
303 * @return 0 on success, -1 on error.
304 */
305int xplra_set_int_array(int connectionID, const char* name,
306 const int32_t* values, size_t length, size_t offset);
307
308/*----------------------------------------------------------------------------*/
309
310/**
311 * Set the array of byte values with the given name from the given
312 * buffer.
313 *
314 * @return 0 on success, -1 on error.
315 */
316int xplra_set_byte_array(int connectionID, const char* name,
317 const void* values, size_t length, size_t offset);
318
319/*----------------------------------------------------------------------------*/
320
321/**
322 * Set the array of byte values with the given name from the given
323 * string. The string will be padded with 0 if it has a length less
324 * than the given length.
325 *
326 * @return 0 on success, -1 on error.
327 */
328int xplra_set_string(int connectionID, const char* name,
329 const char* value, size_t length, size_t offset);
330
331/*----------------------------------------------------------------------------*/
332/* Multi-dataref support */
333/*----------------------------------------------------------------------------*/
334
335/**
336 * Create a multi-dataref getter for the given connection.
337 *
338 * @return the ID of the new getter, or -1 on error
339 */
340int xplra_multi_create_getter(int connectionID);
341
342/*----------------------------------------------------------------------------*/
343
344/**
345 * Create a multi-dataref setter for the given connection.
346 *
347 * @return the ID of the new setter, or -1 on error
348 */
349int xplra_multi_create_setter(int connectionID);
350
351/*----------------------------------------------------------------------------*/
352
353/**
354 * Add an integer dataref to a multi-dataref buffer.
355 *
356 * @return the ID of the dataref that can be used later. If the buffer
357 * ID is invalid, INVALID_DATAREF_ID is returned.
358 */
359size_t xplra_multi_add_int(int bufferID, const char* name);
360
361/*----------------------------------------------------------------------------*/
362
363/**
364 * Add a float dataref to a multi-dataref buffer.
365 *
366 * @return the ID of the dataref that can be used later. If the buffer
367 * ID is invalid, INVALID_DATAREF_ID is returned.
368 */
369size_t xplra_multi_add_float(int bufferID, const char* name);
370
371/*----------------------------------------------------------------------------*/
372
373/**
374 * Add a double dataref to a multi-dataref buffer.
375 *
376 * @return the ID of the dataref that can be used later. If the buffer
377 * ID is invalid, INVALID_DATAREF_ID is returned.
378 */
379size_t xplra_multi_add_double(int bufferID, const char* name);
380
381/*----------------------------------------------------------------------------*/
382
383/**
384 * Add a float array dataref to a multi-dataref buffer.
385 *
386 * @return the ID of the dataref that can be used later. If the buffer
387 * ID is invalid, INVALID_DATAREF_ID is returned.
388 */
389size_t xplra_multi_add_float_array(int bufferID, const char* name,
390 size_t length, size_t offset);
391
392/*----------------------------------------------------------------------------*/
393
394/**
395 * Add an integer array dataref to a multi-dataref buffer.
396 *
397 * @return the ID of the dataref that can be used later. If the buffer
398 * ID is invalid, INVALID_DATAREF_ID is returned.
399 */
400size_t xplra_multi_add_int_array(int bufferID, const char* name,
401 size_t length, size_t offset);
402
403/*----------------------------------------------------------------------------*/
404
405/**
406 * Add a byte array dataref to a multi-dataref buffer.
407 *
408 * @return the ID of the dataref that can be used later. If the buffer
409 * ID is invalid, INVALID_DATAREF_ID is returned.
410 */
411size_t xplra_multi_add_byte_array(int bufferID, const char* name,
412 size_t length, size_t offset);
413
414/*----------------------------------------------------------------------------*/
415
416/**
417 * Finalize the given buffer, if not finalized yet.
418 *
419 * @return -1 on error (if the buffer ID is invalid), 0 if there is no
420 * data in the buffer, 1 if there is data in it.
421 */
422int xplra_multi_finalize(int bufferID);
423
424/*----------------------------------------------------------------------------*/
425
426/**
427 * Register the buffer with the given ID in X-Plane. If needed, it
428 * will be finalized too.
429 *
430 * @return 0 on success, -1 on error
431 */
432int xplra_multi_register(int bufferID);
433
434/*----------------------------------------------------------------------------*/
435
436/**
437 * Unregister the buffer with the given ID from X-Plane. If needed, it
438 * will be finalized too.
439 *
440 * @return 0 on success, -1 on error
441 */
442int xplra_multi_unregister(int bufferID);
443
444/*----------------------------------------------------------------------------*/
445
446/**
447 * Execute the buffer with the given ID. If the buffer is not
448 * finalized, it will be finalized. If it is not finalized, but
449 * registered, the registration will be cleared, and it will be
450 * re-registered after finalizing.
451 *
452 * @return 0 on success, -1 on error
453 */
454int xplra_multi_execute(int bufferID);
455
456/*----------------------------------------------------------------------------*/
457
458/**
459 * Set the value of an integer dataref with the given ID.
460 *
461 * @return 0 on success, -1 on error.
462 */
463int xplra_multi_set_int(int bufferID, size_t datarefID, int value);
464
465/*----------------------------------------------------------------------------*/
466
467/**
468 * Get the value of an integer dataref with the given ID.
469 *
470 * @param dest pointer to the variable that will receive the value
471 *
472 * @return 0 on success, -1 on error.
473 */
474int xplra_multi_get_int(int* dest, int bufferID, size_t datarefID);
475
476/*----------------------------------------------------------------------------*/
477
478/**
479 * Get a const pointer to the integer dataref with the given ID
480 *
481 * @return the pointer or success, 0 on error.
482 */
483const int32_t* xplra_multi_get_int_const_ptr(int bufferID, size_t datarefID);
484
485/*----------------------------------------------------------------------------*/
486
487/**
488 * Get a pointer to the integer dataref with the given ID
489 *
490 * @return the pointer or success, 0 on error.
491 */
492int32_t* xplra_multi_get_int_ptr(int bufferID, size_t datarefID);
493
494/*----------------------------------------------------------------------------*/
495
496/**
497 * Set the value of a float dataref with the given ID.
498 *
499 * @return 0 on success, -1 on error.
500 */
501int xplra_multi_set_float(int bufferID, size_t datarefID, float value);
502
503/*----------------------------------------------------------------------------*/
504
505/**
506 * Get the value of a float dataref with the given ID.
507 *
508 * @param dest pointer to the variable that will receive the value
509 *
510 * @return 0 on success, -1 on error.
511 */
512int xplra_multi_get_float(float* dest, int bufferID, size_t datarefID);
513
514/*----------------------------------------------------------------------------*/
515
516/**
517 * Get a const pointer to the float dataref with the given ID
518 *
519 * @return the pointer or success, 0 on error.
520 */
521const float* xplra_multi_get_float_const_ptr(int bufferID, size_t datarefID);
522
523/*----------------------------------------------------------------------------*/
524
525/**
526 * Get a pointer to the float dataref with the given ID
527 *
528 * @return the pointer or success, 0 on error.
529 */
530float* xplra_multi_get_float_ptr(int bufferID, size_t datarefID);
531
532/*----------------------------------------------------------------------------*/
533
534/**
535 * Set the value of a double dataref with the given ID.
536 *
537 * @return 0 on success, -1 on error.
538 */
539int xplra_multi_set_double(int bufferID, size_t datarefID, double value);
540
541/*----------------------------------------------------------------------------*/
542
543/**
544 * Get the value of a double dataref with the given ID.
545 *
546 * @param dest pointer to the variable that will receive the value
547 *
548 * @return 0 on success, -1 on error.
549 */
550int xplra_multi_get_double(double* dest, int bufferID, size_t datarefID);
551
552/*----------------------------------------------------------------------------*/
553
554/**
555 * Get a const pointer to the double dataref with the given ID
556 *
557 * @return the pointer or success, 0 on error.
558 */
559const double* xplra_multi_get_double_const_ptr(int bufferID, size_t datarefID);
560
561/*----------------------------------------------------------------------------*/
562
563/**
564 * Get a pointer to the double dataref with the given ID
565 *
566 * @return the pointer or success, 0 on error.
567 */
568double* xplra_multi_get_double_ptr(int bufferID, size_t datarefID);
569
570/*----------------------------------------------------------------------------*/
571
572/**
573 * Set the contents of the float array dataref with the given ID.
574 *
575 * @param length the amount of data. If 0, it is assumed to be the
576 * length of the data in the buffer minus the offset.
577 * @param offset the offset within the buffer to set the data from
578 *
579 * @return the number of data items set, or -1 on error.
580 */
581ssize_t xplra_multi_set_float_array(int bufferID, size_t datarefID,
582 const float* value, size_t length,
583 size_t offset);
584
585/*----------------------------------------------------------------------------*/
586
587/**
588 * Get the contents of the float array with the given ID.
589 *
590 * @param length the amount of data. If 0, it is assumed to be the
591 * length of the data in the buffer minus the offset.
592 * @param offset the offset within the buffer to get the data from
593 *
594 * @return the number of data items retrieved, or -1 on error.
595 */
596ssize_t xplra_multi_get_float_array(float* value,
597 size_t length, size_t offset,
598 int bufferID, size_t datarefID);
599
600/*----------------------------------------------------------------------------*/
601
602/**
603 * Get a pointer to the float array with the given ID.
604 *
605 * @param offset the offset within the buffer.
606 *
607 * @return the pointer on success, 0 on error.
608 */
609const float* xplra_multi_get_float_array_ptr(int bufferID, size_t datarefID,
610 size_t offset);
611
612/*----------------------------------------------------------------------------*/
613
614/**
615 * Set the contents of the integer array dataref with the given ID.
616 *
617 * @param length the amount of data. If 0, it is assumed to be the
618 * length of the data in the buffer minus the offset.
619 * @param offset the offset within the buffer to set the data from
620 *
621 * @return the number of data items set, or -1 on error.
622 */
623ssize_t xplra_multi_set_int_array(int bufferID, size_t datarefID,
624 const int32_t* value, size_t length,
625 size_t offset);
626
627/*----------------------------------------------------------------------------*/
628
629/**
630 * Get the contents of the integer array with the given ID.
631 *
632 * @param length the amount of data. If 0, it is assumed to be the
633 * length of the data in the buffer minus the offset.
634 * @param offset the offset within the buffer to get the data from
635 *
636 * @return the number of data items retrieved, or -1 on error.
637 */
638ssize_t xplra_multi_get_int_array(int32_t* value,
639 size_t length, size_t offset,
640 int bufferID, size_t datarefID);
641
642/*----------------------------------------------------------------------------*/
643
644/**
645 * Get a pointer to the integer array with the given ID.
646 *
647 * @param offset the offset within the buffer.
648 *
649 * @return the pointer on success, 0 on error.
650 */
651const int32_t* xplra_multi_get_int_array_ptr(int bufferID, size_t datarefID,
652 size_t offset);
653
654/*----------------------------------------------------------------------------*/
655
656/**
657 * Set the contents of the byte array dataref with the given ID.
658 *
659 * @param length the amount of data. If 0, it is assumed to be the
660 * length of the data in the buffer minus the offset.
661 * @param offset the offset within the buffer to set the data from
662 *
663 * @return the number of data items set, or -1 on error.
664 */
665ssize_t xplra_multi_set_byte_array(int bufferID, size_t datarefID,
666 const void* value, size_t length,
667 size_t offset);
668
669/*----------------------------------------------------------------------------*/
670
671/**
672 * Get the contents of the byte array with the given ID.
673 *
674 * @param length the amount of data. If 0, it is assumed to be the
675 * length of the data in the buffer minus the offset.
676 * @param offset the offset within the buffer to get the data from
677 *
678 * @return the number of data items retrieved, or -1 on error.
679 */
680ssize_t xplra_multi_get_byte_array(void* value,
681 size_t length, size_t offset,
682 int bufferID, size_t datarefID);
683
684/*----------------------------------------------------------------------------*/
685
686/**
687 * Get a pointer to the byte array with the given ID.
688 *
689 * @param offset the offset within the buffer.
690 *
691 * @return the pointer on success, 0 on error.
692 */
693const uint8_t* xplra_multi_get_byte_array_ptr(int bufferID, size_t datarefID,
694 size_t offset);
695
696/*----------------------------------------------------------------------------*/
697
698/**
699 * Set the value of the byte array with the given ID from the given
700 * string. If the string is shorter than the array, the rest will be
701 * filled with 0s.
702 *
703 * @return the number of bytes set, or -1 on error
704 */
705ssize_t xplra_multi_set_string(int bufferID, size_t datarefID,
706 const char* value, size_t offset);
707
708/*----------------------------------------------------------------------------*/
709
710/**
711 * Get a pointer as a string pointer to the byte array with the given
712 * ID.
713 *
714 * @return the pointer on success, 0 on error.
715 */
716const char* xplra_multi_get_string_ptr(int bufferID, size_t datarefID,
717 size_t offset);
718
719/*----------------------------------------------------------------------------*/
720
721/**
722 * Destruy a multi-dataref buffer for the given connection.
723 *
724 * @param connectionID the ID of the connection for which the buffer
725 * has been created.
726 *
727 * @return 0 on success, -1 on error.
728 */
729int xplra_multi_destroy_buffer(int connectionID, int bufferID);
730
731/*----------------------------------------------------------------------------*/
732
733/**
734 * Destroy the connection with the given ID.
735 *
736 * @return 0 on success, -1 on error.
737 */
738int xplra_disconnect(int connectionID);
739
740/*----------------------------------------------------------------------------*/
741
742#ifdef __cplusplus
743} // extern "C"
744#endif
745
746/*----------------------------------------------------------------------------*/
747#endif // HU_VARADIISTVAN_XPLRA_XPLRA_H
Note: See TracBrowser for help on using the repository browser.