X-Plane Remote Access Plugin and Client Library
xplra.h
Go to the documentation of this file.
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 
36 /*----------------------------------------------------------------------------*/
37 
38 #include <stdlib.h>
39 #include <inttypes.h>
40 
41 /*----------------------------------------------------------------------------*/
42 
43 #ifdef __cplusplus
44 extern "C" {
45 #endif
46 
47 /*----------------------------------------------------------------------------*/
48 
50 #define ERROR_NONE 0
51 
56 #define ERROR_IO 1
57 
62 #define ERROR_PROTOCOL 2
63 
65 #define ERROR_PROTOCOL_INVALID_COMMAND = 1
66 
68 #define ERROR_PROTOCOL_UNKNOWN_DATAREF = 2
69 
71 #define ERROR_PROTOCOL_INVALID_TYPE = 3
72 
74 #define ERROR_PROTOCOL_INVALID_LENGTH = 4
75 
77 #define ERROR_PROTOCOL_INVALID_OFFSET = 5
78 
80 #define ERROR_PROTOCOL_INVALID_COUNT = 6
81 
83 #define ERROR_PROTOCOL_INVALID_ID = 7
84 
86 #define ERROR_PROTOCOL_INVALID_DURATION = 8
87 
89 #define ERROR_PROTOCOL_OTHER = 255
90 
92 #define ERROR_NOT_CONNECTED 3
93 
95 #define ERROR_TYPE_MISMATCH 4
96 
98 #define ERROR_INVALID_ID 5
99 
101 #define ERROR_OTHER 255
102 
103 /*----------------------------------------------------------------------------*/
104 
106 #define HOTKEY_MODIFIER_SHIFT 0x01
107 
109 #define HOTKEY_MODIFIER_CONTROL 0x02
110 
111 /*----------------------------------------------------------------------------*/
112 
117 #define INVALID_DATAREF_ID ((size_t)-1)
118 
119 /*----------------------------------------------------------------------------*/
120 
126 int xplra_get_last_error(int connectionID, unsigned long* subCode);
127 
134 const char* xplra_get_last_error_string(int connectionID);
135 
139 void xplra_clear_last_error(int connectionID);
140 
141 /*----------------------------------------------------------------------------*/
142 
148 int xplra_connect();
149 
150 /*----------------------------------------------------------------------------*/
151 
157 int xplra_connect_tcp(const char* address);
158 
159 /*----------------------------------------------------------------------------*/
160 
166 int xplra_connect_tcp_port(const char* address, unsigned short port);
167 
168 /*----------------------------------------------------------------------------*/
169 
173 int xplra_get_versions(int connectionID,
174  int* xplaneVersion, int* xplmVersion,
175  int* xplraVersion);
176 
177 /*----------------------------------------------------------------------------*/
178 
182 int xplra_reload_plugins(int connectionID);
183 
184 /*----------------------------------------------------------------------------*/
185 
190 int xplra_save_situation(int connectionID, const char* path);
191 
192 /*----------------------------------------------------------------------------*/
193 /* Single dataref support */
194 /*----------------------------------------------------------------------------*/
195 
201 int xplra_get_int(int* value, int connectionID, const char* name);
202 
203 /*----------------------------------------------------------------------------*/
204 
210 int xplra_get_float(float* value, int connectionID, const char* name);
211 
212 /*----------------------------------------------------------------------------*/
213 
219 int xplra_get_double(double* value, int connectionID, const char* name);
220 
221 /*----------------------------------------------------------------------------*/
222 
235 ssize_t xplra_get_float_array(float* dest, size_t length, size_t offset,
236  int connectionID, const char* name);
237 
238 /*----------------------------------------------------------------------------*/
239 
252 float* xplra_get_float_array_new(size_t* length, size_t offset,
253  int connectionID, const char* name);
254 
255 /*----------------------------------------------------------------------------*/
256 
269 ssize_t xplra_get_int_array(int32_t* dest, size_t length, size_t offset,
270  int connectionID, const char* name);
271 
272 /*----------------------------------------------------------------------------*/
273 
286 int32_t* xplra_get_int_array_new(size_t* length, size_t offset,
287  int connectionID, const char* name);
288 
289 /*----------------------------------------------------------------------------*/
290 
303 ssize_t xplra_get_byte_array(void* dest, size_t length, size_t offset,
304  int connectionID, const char* name);
305 
306 /*----------------------------------------------------------------------------*/
307 
320 uint8_t* xplra_get_byte_array_new(size_t* length, size_t offset,
321  int connectionID, const char* name);
322 
323 /*----------------------------------------------------------------------------*/
324 
330 int xplra_set_int(int connectionID, const char* name, int value);
331 
332 /*----------------------------------------------------------------------------*/
333 
339 int xplra_set_float(int connectionID, const char* name, float value);
340 
341 /*----------------------------------------------------------------------------*/
342 
348 int xplra_set_double(int connectionID, const char* name, double value);
349 
350 /*----------------------------------------------------------------------------*/
351 
358 int xplra_set_float_array(int connectionID, const char* name,
359  const float* values, size_t length, size_t offset);
360 
361 /*----------------------------------------------------------------------------*/
362 
369 int xplra_set_int_array(int connectionID, const char* name,
370  const int32_t* values, size_t length, size_t offset);
371 
372 /*----------------------------------------------------------------------------*/
373 
380 int xplra_set_byte_array(int connectionID, const char* name,
381  const void* values, size_t length, size_t offset);
382 
383 /*----------------------------------------------------------------------------*/
384 
392 int xplra_set_string(int connectionID, const char* name,
393  const char* value, size_t length, size_t offset);
394 
395 /*----------------------------------------------------------------------------*/
396 /* Multi-dataref support */
397 /*----------------------------------------------------------------------------*/
398 
404 int xplra_multi_create_getter(int connectionID);
405 
406 /*----------------------------------------------------------------------------*/
407 
413 int xplra_multi_create_setter(int connectionID);
414 
415 /*----------------------------------------------------------------------------*/
416 
423 size_t xplra_multi_add_int(int bufferID, const char* name);
424 
425 /*----------------------------------------------------------------------------*/
426 
433 size_t xplra_multi_add_float(int bufferID, const char* name);
434 
435 /*----------------------------------------------------------------------------*/
436 
443 size_t xplra_multi_add_double(int bufferID, const char* name);
444 
445 /*----------------------------------------------------------------------------*/
446 
453 size_t xplra_multi_add_float_array(int bufferID, const char* name,
454  size_t length, size_t offset);
455 
456 /*----------------------------------------------------------------------------*/
457 
464 size_t xplra_multi_add_int_array(int bufferID, const char* name,
465  size_t length, size_t offset);
466 
467 /*----------------------------------------------------------------------------*/
468 
475 size_t xplra_multi_add_byte_array(int bufferID, const char* name,
476  size_t length, size_t offset);
477 
478 /*----------------------------------------------------------------------------*/
479 
486 int xplra_multi_finalize(int bufferID);
487 
488 /*----------------------------------------------------------------------------*/
489 
496 int xplra_multi_register(int bufferID);
497 
498 /*----------------------------------------------------------------------------*/
499 
505 int xplra_multi_unregister(int bufferID);
506 
507 /*----------------------------------------------------------------------------*/
508 
516 int xplra_multi_unregister_safely(int bufferID);
517 
518 /*----------------------------------------------------------------------------*/
519 
528 int xplra_multi_execute(int bufferID);
529 
530 /*----------------------------------------------------------------------------*/
531 
537 int xplra_multi_set_int(int bufferID, size_t datarefID, int value);
538 
539 /*----------------------------------------------------------------------------*/
540 
550 int xplra_multi_get_int(int* dest, int bufferID, size_t datarefID);
551 
552 /*----------------------------------------------------------------------------*/
553 
559 const int32_t* xplra_multi_get_int_const_ptr(int bufferID, size_t datarefID);
560 
561 /*----------------------------------------------------------------------------*/
562 
568 int32_t* xplra_multi_get_int_ptr(int bufferID, size_t datarefID);
569 
570 /*----------------------------------------------------------------------------*/
571 
577 int xplra_multi_set_float(int bufferID, size_t datarefID, float value);
578 
579 /*----------------------------------------------------------------------------*/
580 
590 int xplra_multi_get_float(float* dest, int bufferID, size_t datarefID);
591 
592 /*----------------------------------------------------------------------------*/
593 
599 const float* xplra_multi_get_float_const_ptr(int bufferID, size_t datarefID);
600 
601 /*----------------------------------------------------------------------------*/
602 
608 float* xplra_multi_get_float_ptr(int bufferID, size_t datarefID);
609 
610 /*----------------------------------------------------------------------------*/
611 
617 int xplra_multi_set_double(int bufferID, size_t datarefID, double value);
618 
619 /*----------------------------------------------------------------------------*/
620 
630 int xplra_multi_get_double(double* dest, int bufferID, size_t datarefID);
631 
632 /*----------------------------------------------------------------------------*/
633 
639 const double* xplra_multi_get_double_const_ptr(int bufferID, size_t datarefID);
640 
641 /*----------------------------------------------------------------------------*/
642 
648 double* xplra_multi_get_double_ptr(int bufferID, size_t datarefID);
649 
650 /*----------------------------------------------------------------------------*/
651 
664 ssize_t xplra_multi_set_float_array(int bufferID, size_t datarefID,
665  const float* value, size_t length,
666  size_t offset);
667 
668 /*----------------------------------------------------------------------------*/
669 
682 ssize_t xplra_multi_get_float_array(float* value,
683  size_t length, size_t offset,
684  int bufferID, size_t datarefID);
685 
686 /*----------------------------------------------------------------------------*/
687 
697 const float* xplra_multi_get_float_array_ptr(int bufferID, size_t datarefID,
698  size_t offset);
699 
700 /*----------------------------------------------------------------------------*/
701 
714 ssize_t xplra_multi_set_int_array(int bufferID, size_t datarefID,
715  const int32_t* value, size_t length,
716  size_t offset);
717 
718 /*----------------------------------------------------------------------------*/
719 
732 ssize_t xplra_multi_get_int_array(int32_t* value,
733  size_t length, size_t offset,
734  int bufferID, size_t datarefID);
735 
736 /*----------------------------------------------------------------------------*/
737 
747 const int32_t* xplra_multi_get_int_array_ptr(int bufferID, size_t datarefID,
748  size_t offset);
749 
750 /*----------------------------------------------------------------------------*/
751 
764 ssize_t xplra_multi_set_byte_array(int bufferID, size_t datarefID,
765  const void* value, size_t length,
766  size_t offset);
767 
768 /*----------------------------------------------------------------------------*/
769 
782 ssize_t xplra_multi_get_byte_array(void* value,
783  size_t length, size_t offset,
784  int bufferID, size_t datarefID);
785 
786 /*----------------------------------------------------------------------------*/
787 
797 const uint8_t* xplra_multi_get_byte_array_ptr(int bufferID, size_t datarefID,
798  size_t offset);
799 
800 /*----------------------------------------------------------------------------*/
801 
809 ssize_t xplra_multi_set_string(int bufferID, size_t datarefID,
810  const char* value, size_t offset);
811 
812 /*----------------------------------------------------------------------------*/
813 
820 const char* xplra_multi_get_string_ptr(int bufferID, size_t datarefID,
821  size_t offset);
822 
823 /*----------------------------------------------------------------------------*/
824 
834 int xplra_multi_destroy_buffer(int connectionID, int bufferID);
835 
836 /*----------------------------------------------------------------------------*/
837 /*----------------------------------------------------------------------------*/
838 
842 int xplra_show_message(int connectionID, const char* message, float duration);
843 
844 /*----------------------------------------------------------------------------*/
845 /*----------------------------------------------------------------------------*/
846 
851 int xplra_register_hotkeys(int connectionID,
852  const uint16_t* codes, size_t length);
853 
854 /*----------------------------------------------------------------------------*/
855 
859 int xplra_query_hotkeys(int connectionID, uint8_t* states, size_t length);
860 
861 /*----------------------------------------------------------------------------*/
862 
866 int xplra_unregister_hotkeys(int connectionID);
867 
868 /*----------------------------------------------------------------------------*/
869 /*----------------------------------------------------------------------------*/
870 
876 int xplra_disconnect(int connectionID);
877 
878 /*----------------------------------------------------------------------------*/
879 
886 int xplra_reconnect(int connectionID);
887 
888 /*----------------------------------------------------------------------------*/
889 
895 int xplra_destroy(int connectionID);
896 
897 /*----------------------------------------------------------------------------*/
898 
899 #ifdef __cplusplus
900 } // extern "C"
901 #endif
902 
903 /*----------------------------------------------------------------------------*/
904 #endif // HU_VARADIISTVAN_XPLRA_XPLRA_H
int xplra_connect_tcp_port(const char *address, unsigned short port)
Definition: xplra.cc:513
int xplra_multi_finalize(int bufferID)
Definition: xplra.cc:896
size_t xplra_multi_add_int_array(int bufferID, const char *name, size_t length, size_t offset)
Definition: xplra.cc:876
int xplra_set_byte_array(int connectionID, const char *name, const void *values, size_t length, size_t offset)
Definition: xplra.cc:790
int xplra_query_hotkeys(int connectionID, uint8_t *states, size_t length)
Definition: xplra.cc:1377
const int32_t * xplra_multi_get_int_array_ptr(int bufferID, size_t datarefID, size_t offset)
Definition: xplra.cc:1226
int32_t * xplra_get_int_array_new(size_t *length, size_t offset, int connectionID, const char *name)
Definition: xplra.cc:664
size_t xplra_multi_add_float_array(int bufferID, const char *name, size_t length, size_t offset)
Definition: xplra.cc:866
int xplra_set_double(int connectionID, const char *name, double value)
Definition: xplra.cc:740
const float * xplra_multi_get_float_const_ptr(int bufferID, size_t datarefID)
Definition: xplra.cc:1050
int xplra_get_double(double *value, int connectionID, const char *name)
Definition: xplra.cc:603
int xplra_disconnect(int connectionID)
Definition: xplra.cc:1411
int xplra_multi_unregister_safely(int bufferID)
Definition: xplra.cc:934
int xplra_reconnect(int connectionID)
Definition: xplra.cc:1424
int xplra_register_hotkeys(int connectionID, const uint16_t *codes, size_t length)
Definition: xplra.cc:1360
int xplra_set_float(int connectionID, const char *name, float value)
Definition: xplra.cc:725
int xplra_show_message(int connectionID, const char *message, float duration)
Definition: xplra.cc:1342
int xplra_set_string(int connectionID, const char *name, const char *value, size_t length, size_t offset)
Definition: xplra.cc:808
ssize_t xplra_multi_set_float_array(int bufferID, size_t datarefID, const float *value, size_t length, size_t offset)
Definition: xplra.cc:1142
ssize_t xplra_multi_get_byte_array(void *value, size_t length, size_t offset, int bufferID, size_t datarefID)
Definition: xplra.cc:1261
uint8_t * xplra_get_byte_array_new(size_t *length, size_t offset, int connectionID, const char *name)
Definition: xplra.cc:695
const char * xplra_multi_get_string_ptr(int bufferID, size_t datarefID, size_t offset)
Definition: xplra.cc:1311
void xplra_clear_last_error(int connectionID)
Definition: xplra.cc:479
int xplra_get_int(int *value, int connectionID, const char *name)
Definition: xplra.cc:573
ssize_t xplra_multi_set_string(int bufferID, size_t datarefID, const char *value, size_t offset)
Definition: xplra.cc:1295
int xplra_multi_execute(int bufferID)
Definition: xplra.cc:942
int xplra_get_last_error(int connectionID, unsigned long *subCode)
Definition: xplra.cc:463
size_t xplra_multi_add_int(int bufferID, const char *name)
Definition: xplra.cc:842
int xplra_connect_tcp(const char *address)
Definition: xplra.cc:500
ssize_t xplra_get_float_array(float *dest, size_t length, size_t offset, int connectionID, const char *name)
Definition: xplra.cc:619
ssize_t xplra_get_byte_array(void *dest, size_t length, size_t offset, int connectionID, const char *name)
Definition: xplra.cc:679
ssize_t xplra_multi_set_byte_array(int bufferID, size_t datarefID, const void *value, size_t length, size_t offset)
Definition: xplra.cc:1242
int xplra_multi_set_int(int bufferID, size_t datarefID, int value)
Definition: xplra.cc:957
int xplra_multi_create_setter(int connectionID)
Definition: xplra.cc:834
int32_t * xplra_multi_get_int_ptr(int bufferID, size_t datarefID)
Definition: xplra.cc:1003
int xplra_set_int_array(int connectionID, const char *name, const int32_t *values, size_t length, size_t offset)
Definition: xplra.cc:773
int xplra_multi_set_double(int bufferID, size_t datarefID, double value)
Definition: xplra.cc:1080
int xplra_reload_plugins(int connectionID)
Definition: xplra.cc:543
int xplra_multi_get_float(float *dest, int bufferID, size_t datarefID)
Definition: xplra.cc:1034
const uint8_t * xplra_multi_get_byte_array_ptr(int bufferID, size_t datarefID, size_t offset)
Definition: xplra.cc:1280
ssize_t xplra_multi_set_int_array(int bufferID, size_t datarefID, const int32_t *value, size_t length, size_t offset)
Definition: xplra.cc:1192
const char * xplra_get_last_error_string(int connectionID)
Definition: xplra.cc:471
int xplra_destroy(int connectionID)
Definition: xplra.cc:1440
float * xplra_get_float_array_new(size_t *length, size_t offset, int connectionID, const char *name)
Definition: xplra.cc:634
double * xplra_multi_get_double_ptr(int bufferID, size_t datarefID)
Definition: xplra.cc:1127
size_t xplra_multi_add_double(int bufferID, const char *name)
Definition: xplra.cc:858
int xplra_connect()
Definition: xplra.cc:487
int xplra_get_float(float *value, int connectionID, const char *name)
Definition: xplra.cc:588
const int32_t * xplra_multi_get_int_const_ptr(int bufferID, size_t datarefID)
Definition: xplra.cc:988
ssize_t xplra_get_int_array(int32_t *dest, size_t length, size_t offset, int connectionID, const char *name)
Definition: xplra.cc:649
ssize_t xplra_multi_get_float_array(float *value, size_t length, size_t offset, int bufferID, size_t datarefID)
Definition: xplra.cc:1159
int xplra_multi_get_int(int *dest, int bufferID, size_t datarefID)
Definition: xplra.cc:972
int xplra_set_int(int connectionID, const char *name, int value)
Definition: xplra.cc:710
int xplra_multi_create_getter(int connectionID)
Definition: xplra.cc:826
int xplra_multi_set_float(int bufferID, size_t datarefID, float value)
Definition: xplra.cc:1018
size_t xplra_multi_add_float(int bufferID, const char *name)
Definition: xplra.cc:850
int xplra_get_versions(int connectionID, int *xplaneVersion, int *xplmVersion, int *xplraVersion)
Definition: xplra.cc:526
const double * xplra_multi_get_double_const_ptr(int bufferID, size_t datarefID)
Definition: xplra.cc:1112
float * xplra_multi_get_float_ptr(int bufferID, size_t datarefID)
Definition: xplra.cc:1065
int xplra_unregister_hotkeys(int connectionID)
Definition: xplra.cc:1394
int xplra_multi_get_double(double *dest, int bufferID, size_t datarefID)
Definition: xplra.cc:1096
int xplra_multi_unregister(int bufferID)
Definition: xplra.cc:919
int xplra_multi_destroy_buffer(int connectionID, int bufferID)
Definition: xplra.cc:1326
int xplra_multi_register(int bufferID)
Definition: xplra.cc:904
int xplra_save_situation(int connectionID, const char *path)
Definition: xplra.cc:558
const float * xplra_multi_get_float_array_ptr(int bufferID, size_t datarefID, size_t offset)
Definition: xplra.cc:1176
int xplra_set_float_array(int connectionID, const char *name, const float *values, size_t length, size_t offset)
Definition: xplra.cc:756
ssize_t xplra_multi_get_int_array(int32_t *value, size_t length, size_t offset, int bufferID, size_t datarefID)
Definition: xplra.cc:1209
size_t xplra_multi_add_byte_array(int bufferID, const char *name, size_t length, size_t offset)
Definition: xplra.cc:886