X-Plane Remote Access Plugin and Client Library
Public Member Functions | Private Types | Private Member Functions | Private Attributes | Static Private Attributes | Friends | List of all members
hu::varadiistvan::xplra::XPlane Class Reference

#include <XPlane.h>

Public Member Functions

 XPlane () noexcept
 
 ~XPlane () noexcept
 
void connect ()
 
void connectTCP (const std::string &address, unsigned short port=defaultTCPPort)
 
bool isConnected () const noexcept
 
void disconnect () noexcept
 
MultiGettercreateMultiGetter () noexcept
 
MultiSettercreateMultiSetter () noexcept
 
bool destroyMultiBuffer (MultiBuffer &buffer)
 
void getVersions (int &xplaneVersion, int &xplmVersion, int &xplraVersion)
 
void reloadPlugins ()
 
void saveSituation (const char *path)
 
int getInt (const char *name)
 
float getFloat (const char *name)
 
double getDouble (const char *name)
 
size_t getFloatArray (const char *name, float *dest, size_t length, size_t offset=0)
 
float * getFloatArray (const char *name, size_t &length, size_t offset=0)
 
size_t getIntArray (const char *name, int32_t *dest, size_t length, size_t offset=0)
 
int32_t * getIntArray (const char *name, size_t &length, size_t offset=0)
 
size_t getByteArray (const char *name, uint8_t *dest, size_t length, size_t offset=0)
 
uint8_t * getByteArray (const char *name, size_t &length, size_t offset=0)
 
std::string getString (const char *name, size_t offset=0)
 
void setInt (const char *name, int value)
 
void setFloat (const char *name, float value)
 
void setDouble (const char *name, double value)
 
void setFloatArray (const char *name, const float *values, size_t length, size_t offset=0)
 
void setIntArray (const char *name, const int32_t *values, size_t length, size_t offset=0)
 
void setByteArray (const char *name, const uint8_t *values, size_t length, size_t offset=0)
 
void setString (const char *name, const char *value, size_t length, size_t offset=0)
 
void showMessage (const char *message, float duration)
 
void registerHotkeys (const uint16_t *codes, size_t length)
 
void queryHotkeys (uint8_t *states, size_t length)
 
void unregisterHotkeys ()
 

Private Types

typedef std::set< MultiBuffer * > multiBuffers_t
 

Private Member Functions

void checkStream ()
 
void checkResult (uint8_t result, bool hasParameter=false, long parameter=0)
 
void checkResult (bool multi=false)
 
void getScalar (const char *name, uint8_t type)
 
size_t getArray (const char *name, uint8_t type, ssize_t length, size_t offset)
 
void setScalar (const char *name, uint8_t type)
 
void setArray (const char *name, uint8_t type, size_t length, size_t offset)
 
template<class ClientSocket >
void connect (std::unique_ptr< ClientSocket > clientSocket)
 

Private Attributes

scpl::io::Waiter waiter
 
scpl::io::BufferedStream * socket
 
scpl::io::DataStream * stream
 
multiBuffers_t multiBuffers
 

Static Private Attributes

static const unsigned short defaultTCPPort = 0x5852
 

Friends

class MultiBuffer
 
class MultiGetter
 
class MultiSetter
 

Detailed Description

The main class to access X-Plane.

The calls are synchronous and not thread-safe.

Definition at line 68 of file XPlane.h.

Member Typedef Documentation

◆ multiBuffers_t

Type for the set of multi-dataref buffers.

Definition at line 79 of file XPlane.h.

Constructor & Destructor Documentation

◆ XPlane()

hu::varadiistvan::xplra::XPlane::XPlane ( )
inlinenoexcept

Construct the object. It will not be connected to the simulator yet.

Definition at line 393 of file XPlane.h.

◆ ~XPlane()

XPlane::~XPlane ( )
noexcept

Destroy the object. If connected, the connection will be closed. It destroys all existing buffers, so their references become invalid.

Definition at line 169 of file XPlane.cc.

Member Function Documentation

◆ checkResult() [1/2]

void XPlane::checkResult ( bool  multi = false)
private

Read and check the result. If it signifies an error, throw a ProtocolException with the correct error code. If there is some problem with the stream, an IOException is thrown.

Definition at line 151 of file XPlane.cc.

◆ checkResult() [2/2]

void XPlane::checkResult ( uint8_t  result,
bool  hasParameter = false,
long  parameter = 0 
)
private

Check the given protocol result. If it signifies an error, throw a ProtocolException with the correct error code.

Definition at line 113 of file XPlane.cc.

◆ checkStream()

void XPlane::checkStream ( )
private

Check if we have a stream and if it has not failed.

Definition at line 102 of file XPlane.cc.

◆ connect() [1/2]

void XPlane::connect ( )

Connect to the simulator locally.

Definition at line 183 of file XPlane.cc.

◆ connect() [2/2]

template<class ClientSocket >
void XPlane::connect ( std::unique_ptr< ClientSocket >  clientSocket)
private

Connect with the given socket.

Definition at line 71 of file XPlane.cc.

◆ connectTCP()

void XPlane::connectTCP ( const std::string &  address,
unsigned short  port = defaultTCPPort 
)

Connect to the simulator on TCP to the given address.

Definition at line 194 of file XPlane.cc.

◆ createMultiGetter()

MultiGetter & XPlane::createMultiGetter ( )
noexcept

Create a new getter of multiple datarefs and return a reference to it.

Definition at line 216 of file XPlane.cc.

◆ createMultiSetter()

MultiSetter & XPlane::createMultiSetter ( )
noexcept

Create a new setter of multiple datarefs and return a reference to it.

Definition at line 225 of file XPlane.cc.

◆ destroyMultiBuffer()

bool XPlane::destroyMultiBuffer ( MultiBuffer buffer)

Destroy the given getter or setter of multiple datarefs. As the buffer is unregistered, if it has been registered previously, and unregistration may fail, this function might throw an exception.

Returns
if the buffer was found and could be destroyed

Definition at line 234 of file XPlane.cc.

◆ disconnect()

void XPlane::disconnect ( )
noexcept

Disconnect from the simulator.

Definition at line 206 of file XPlane.cc.

◆ getArray()

size_t XPlane::getArray ( const char *  name,
uint8_t  type,
ssize_t  length,
size_t  offset 
)
private

Issue the command to get an array of values of the given type. It checks the result and retrieves the number of value items available.

Returns
the number of value items available

Definition at line 328 of file XPlane.cc.

◆ getByteArray() [1/2]

uint8_t * XPlane::getByteArray ( const char *  name,
size_t &  length,
size_t  offset = 0 
)

Get a possibly partial array of bytes. The result array will be created with a length needed to hold the returned value.

Parameters
namethe name of the dataref
lengthwill contain the number of bytes read on return
offsetthe offset from which to get the array

Definition at line 410 of file XPlane.cc.

◆ getByteArray() [2/2]

size_t XPlane::getByteArray ( const char *  name,
uint8_t *  dest,
size_t  length,
size_t  offset = 0 
)

Get a possibly partial array of bytes.

Parameters
namethe name of the dataref
destthe destination buffer
lengththe length of the destination buffer
offsetthe offset from which to get the array
Returns
the number of values acquired actually

Definition at line 398 of file XPlane.cc.

◆ getDouble()

double XPlane::getDouble ( const char *  name)

Get a double value.

Definition at line 317 of file XPlane.cc.

◆ getFloat()

float XPlane::getFloat ( const char *  name)

Get a float value.

Definition at line 306 of file XPlane.cc.

◆ getFloatArray() [1/2]

size_t XPlane::getFloatArray ( const char *  name,
float *  dest,
size_t  length,
size_t  offset = 0 
)

Get a possibly partial array of floats.

Parameters
namethe name of the dataref
destthe destination buffer
lengththe length of the destination buffer
offsetthe offset from which to get the array
Returns
the number of values acquired actually

Definition at line 350 of file XPlane.cc.

◆ getFloatArray() [2/2]

float * XPlane::getFloatArray ( const char *  name,
size_t &  length,
size_t  offset = 0 
)

Get a possibly partial array of floats. The result array will be created with a length needed to hold the returned value.

Parameters
namethe name of the dataref
lengthwill contain the number of floats read
offsetthe offset from which to get the array

Definition at line 362 of file XPlane.cc.

◆ getInt()

int XPlane::getInt ( const char *  name)

Get the integer value of the dataref with the given name.

Definition at line 295 of file XPlane.cc.

◆ getIntArray() [1/2]

size_t XPlane::getIntArray ( const char *  name,
int32_t *  dest,
size_t  length,
size_t  offset = 0 
)

Get a possibly partial array of integers.

Parameters
namethe name of the dataref
destthe destination buffer
lengththe length of the destination buffer
offsetthe offset from which to get the array
Returns
the number of values acquired actually

Definition at line 374 of file XPlane.cc.

◆ getIntArray() [2/2]

int32_t * XPlane::getIntArray ( const char *  name,
size_t &  length,
size_t  offset = 0 
)

Get a possibly partial array of integers. The result array will be created with a length needed to hold the returned value.

Parameters
namethe name of the dataref
lengthwill contain the number of integers read
offsetthe offset from which to get the array

Definition at line 386 of file XPlane.cc.

◆ getScalar()

void XPlane::getScalar ( const char *  name,
uint8_t  type 
)
private

Issue the command to get a single, scalar value. The result is also checked, but the value should be read by the caller.

Definition at line 281 of file XPlane.cc.

◆ getString()

string XPlane::getString ( const char *  name,
size_t  offset = 0 
)

Get a string. A string is a byte array.

Definition at line 422 of file XPlane.cc.

◆ getVersions()

void XPlane::getVersions ( int &  xplaneVersion,
int &  xplmVersion,
int &  xplraVersion 
)

Get the versions of X-Plane, XPLM and the XPLRA plugin.

Definition at line 247 of file XPlane.cc.

◆ isConnected()

bool hu::varadiistvan::xplra::XPlane::isConnected ( ) const
inlinenoexcept

Check if we are connected to the simulator.

Definition at line 401 of file XPlane.h.

◆ queryHotkeys()

void XPlane::queryHotkeys ( uint8_t *  states,
size_t  length 
)

Query the registered hotkeys whether they were pressed.

Definition at line 555 of file XPlane.cc.

◆ registerHotkeys()

void XPlane::registerHotkeys ( const uint16_t *  codes,
size_t  length 
)

Register the given hotkey codes for listening. If there is an existing set of hotkeys registered, those will be overwritten.

Definition at line 543 of file XPlane.cc.

◆ reloadPlugins()

void XPlane::reloadPlugins ( )

Reload the plugins loaded in X-Plane. After this the connection fails.

Definition at line 262 of file XPlane.cc.

◆ saveSituation()

void XPlane::saveSituation ( const char *  path)

Save the current situation into the file with the given path, which is relative to the directory of X-Plane.

Definition at line 271 of file XPlane.cc.

◆ setArray()

void XPlane::setArray ( const char *  name,
uint8_t  type,
size_t  length,
size_t  offset 
)
private

Issue the command to set an array value of the given type.

Definition at line 470 of file XPlane.cc.

◆ setByteArray()

void XPlane::setByteArray ( const char *  name,
const uint8_t *  values,
size_t  length,
size_t  offset = 0 
)

Set the given byte array to values in the given buffer.

Definition at line 504 of file XPlane.cc.

◆ setDouble()

void XPlane::setDouble ( const char *  name,
double  value 
)

Set the given dataref to the given double value.

Definition at line 460 of file XPlane.cc.

◆ setFloat()

void XPlane::setFloat ( const char *  name,
float  value 
)

Set the given dataref to the given float value.

Definition at line 450 of file XPlane.cc.

◆ setFloatArray()

void XPlane::setFloatArray ( const char *  name,
const float *  values,
size_t  length,
size_t  offset = 0 
)

Set the given float array to values in the given buffer.

Definition at line 482 of file XPlane.cc.

◆ setInt()

void XPlane::setInt ( const char *  name,
int  value 
)

Set the given dataref to the given integer value.

Definition at line 440 of file XPlane.cc.

◆ setIntArray()

void XPlane::setIntArray ( const char *  name,
const int32_t *  values,
size_t  length,
size_t  offset = 0 
)

Set the given integer array to values in the given buffer.

Definition at line 493 of file XPlane.cc.

◆ setScalar()

void XPlane::setScalar ( const char *  name,
uint8_t  type 
)
private

Issue the command to set a scalar value of the given type.

Definition at line 431 of file XPlane.cc.

◆ setString()

void XPlane::setString ( const char *  name,
const char *  value,
size_t  length,
size_t  offset = 0 
)

Set the given string to the given value. Since strings are byte arrays, and the bytes after the string should be zeroed, the length must be given. The string will be converted to a byte array of the given length, padded with 0s.

Definition at line 515 of file XPlane.cc.

◆ showMessage()

void XPlane::showMessage ( const char *  message,
float  duration 
)

Show a textual message for a certain duration.

Definition at line 532 of file XPlane.cc.

◆ unregisterHotkeys()

void XPlane::unregisterHotkeys ( )

Unregister the hotkeys.

Definition at line 577 of file XPlane.cc.

Member Data Documentation

◆ defaultTCPPort

const unsigned short XPlane::defaultTCPPort = 0x5852
staticprivate

The default TCP port.

Definition at line 74 of file XPlane.h.

◆ multiBuffers

multiBuffers_t hu::varadiistvan::xplra::XPlane::multiBuffers
private

The buffers created by this object.

Definition at line 99 of file XPlane.h.

◆ socket

scpl::io::BufferedStream* hu::varadiistvan::xplra::XPlane::socket
private

The client socket as a stream, over which we are communicating with X-Plane.

Definition at line 89 of file XPlane.h.

◆ stream

scpl::io::DataStream* hu::varadiistvan::xplra::XPlane::stream
private

The data stream to handle the data conversions.

Definition at line 94 of file XPlane.h.

◆ waiter

scpl::io::Waiter hu::varadiistvan::xplra::XPlane::waiter
private

The waiter to use.

Definition at line 84 of file XPlane.h.


The documentation for this class was generated from the following files: