X-Plane Remote Access Plugin and Client Library
|
The C++ client API's central class is hu::varadiistvan::xplra::XPlane. To communicate with the XPLRA plugin in X-Plane, create an instance of it. This, however, does not establish the connection yet. To actually connect, call the connect member function. If the connection is established, it returns otherwise it throws a hu::varadiistvan::xplra::IOException.
IOException
is part of the exception hierarchy of the client API. The hierarchy begins with hu::varadiistvan::xplra::Exception. The what
function is implemented for all exception classes, so you can always get a string representation of the problem for logging or to display it. IOException
further makes available an error code, which is the standard operating system-specific fault code of the I/O error that occured.
hu::varadiistvan::xplra::ProtocolException is thrown for errors returned by the plugin usually due to some incorrect parameter. See also the Protocol description for the meaning and applicability of these error codes.
The XPlane
object can be reused in the sense, that after you have made a connection, you can disconnect and then connect again. This may be useful, if X-Plane crashes for some reason, and you can then reconnect if the user has restarted it.
The createMultiGetter function can be used to create a multi-dataref query object. It returns an instance of MultiGetter, which can be used to store a number of datarefs and then execute a multi-dataref query for those datarefs. Before execution, the query can be registered in the plugin, so that the client does not have to send all the dataref information whenever the query is executed.
The XPlane
object knows about any multi-dataref query objects. Therefore if you register such a multi-dataref query, and then the connection breaks, and then you reconnect, the query will-be re-registered too, i.e. you don't have to do it yourself.
Similarly, the createMultiSetter function can be used to create a multi-dataref update object. They are handled the same way by XPlane
as the query objects when it comes to registration and re-registration.
The other functions of XPlane
are mostly self-explanatory: they perform the operations defined by the protocol. Several operations have more than one corresponding functions with different parameters for convenience.
The C API is a wrapper over the C++ one, so its logic is essentially the same. To connect to X-Plane, call xplra_connect. It returns a non-negative handle, which can be used to refer to the connection (i.e. the underlying XPlane
object) in the other functions.
In case of error, it, and most other functions of the C returns -1. To check what the last error was, call xplra_get_last_error or xplra_get_last_error_string.
You can create multi-dataref buffers with C API as well with xplra_multi_create_getter and xplra_multi_create_setter. These return a buffer ID on success, and you should use that buffer ID later on to manipulate the buffer.