X-Plane Remote Access Plugin and Client Library
|
#include <MultiBuffer.h>
Classes | |
class | DataRef |
Public Member Functions | |
XPlane & | getXPlane () const noexcept |
size_t | addInt (const std::string &name) noexcept |
size_t | addFloat (const std::string &name) noexcept |
size_t | addDouble (const std::string &name) noexcept |
size_t | addFloatArray (const std::string &name, size_t length, size_t offset=0) noexcept |
size_t | addIntArray (const std::string &name, size_t length, size_t offset=0) noexcept |
size_t | addByteArray (const std::string &name, size_t length, size_t offset=0) noexcept |
bool | finalize () const |
void | registerInXPlane () |
void | unregisterFromXPlane () |
bool | unregisterSafelyFromXPlane () noexcept |
void | execute () |
void | setInt (size_t id, int value) |
int | getInt (size_t id) const |
const int32_t & | getIntRef (size_t id) const |
int32_t & | getIntRef (size_t id) |
void | setFloat (size_t id, float value) |
float | getFloat (size_t id) const |
const float & | getFloatRef (size_t id) const |
float & | getFloatRef (size_t id) |
void | setDouble (size_t id, double value) |
double | getDouble (size_t id) const |
const double & | getDoubleRef (size_t id) const |
double & | getDoubleRef (size_t id) |
size_t | setFloatArray (size_t id, const float *value, size_t length=0, size_t offset=0) |
size_t | getFloatArray (size_t id, float *value, size_t length=0, size_t offset=0) const |
const float * | getFloatArray (size_t id, size_t offset=0) const |
size_t | setIntArray (size_t id, const int32_t *value, size_t length=0, size_t offset=0) |
size_t | getIntArray (size_t id, int32_t *value, size_t length=0, size_t offset=0) const |
const int32_t * | getIntArray (size_t id, size_t offset=0) const |
size_t | setByteArray (size_t id, const uint8_t *value, size_t length=0, size_t offset=0) |
size_t | getByteArray (size_t id, uint8_t *value, size_t length=0, size_t offset=0) const |
const uint8_t * | getByteArray (size_t id, size_t offset=0) const |
size_t | setString (size_t id, const std::string &value, size_t offset=0) |
std::string | getString (size_t id, size_t offset=0) const |
const char * | getStringPtr (size_t id, size_t offset=0) const |
Protected Member Functions | |
MultiBuffer (XPlane &xplane, uint8_t registerCommand, uint8_t unregisterCommand) noexcept | |
virtual | ~MultiBuffer () noexcept |
virtual void | doExecute ()=0 |
virtual void | doExecuteUnregistered ()=0 |
void | writeSpec (uint8_t command) const |
void | reregisterInXPlane () |
Protected Attributes | |
std::vector< DataRef > | dataRefs |
unsigned char * | data |
XPlane & | xplane |
uint8_t | registerCommand |
uint8_t | unregisterCommand |
int | registeredID |
Private Member Functions | |
void | unfinalize () noexcept |
void | forgetRegistration () noexcept |
const DataRef * | getLastDataRef () const noexcept |
const DataRef & | getDataRef (size_t id, uint8_t type) const |
void * | getData (size_t id, uint8_t type) |
const void * | getData (size_t id, uint8_t type) const |
template<typename T , uint8_t type> | |
size_t | setArray (size_t id, const T *value, size_t length, size_t offset) |
template<typename T , uint8_t type> | |
size_t | getArray (size_t id, T *value, size_t length, size_t offset) const |
template<typename T , uint8_t type> | |
const T * | getArray (size_t id, size_t offset) const |
Friends | |
class | XPlane |
Base class for the multi-get and multi-set handlers. It contains the meta-data of the datarefs as well as a buffer for storing the data.
Definition at line 55 of file MultiBuffer.h.
|
protectednoexcept |
Construct an empty buffer for the given XPlane instance.
Definition at line 235 of file MultiBuffer.cc.
|
protectedvirtualnoexcept |
Destroy the buffer. If it is registered, an attempt will be made to unregister it.
Definition at line 247 of file MultiBuffer.cc.
|
noexcept |
Add a byte array dataref.
Definition at line 304 of file MultiBuffer.cc.
|
noexcept |
Add a double dataref.
Definition at line 273 of file MultiBuffer.cc.
|
noexcept |
Add a float dataref.
Definition at line 264 of file MultiBuffer.cc.
|
noexcept |
Add a float array dataref.
Definition at line 282 of file MultiBuffer.cc.
|
noexcept |
Add an integer dataref.
Definition at line 255 of file MultiBuffer.cc.
|
noexcept |
Add an integer array dataref.
Definition at line 293 of file MultiBuffer.cc.
|
protectedpure virtual |
Perform the main part of the execution if the buffer is registered.
Implemented in hu::varadiistvan::xplra::MultiSetter, and hu::varadiistvan::xplra::MultiGetter.
|
protectedpure virtual |
Perform the main part of the execution if the buffer is not registered.
Implemented in hu::varadiistvan::xplra::MultiSetter, and hu::varadiistvan::xplra::MultiGetter.
void MultiBuffer::execute | ( | ) |
Execute the buffer by either reading or writing it. If the buffer is not finalized, it will be finalized. If it is not finalized, but registered, the registration will be cleared, and it will be re-registered after finalizing.
Definition at line 372 of file MultiBuffer.cc.
bool MultiBuffer::finalize | ( | ) | const |
Finalize the buffer, if not finalized yet.
Definition at line 315 of file MultiBuffer.cc.
|
privatenoexcept |
Forget the registration of this buffer. This is called from the destructor of the XPlane object, since that closes the connection anyway, so there is no need to unregister the multi-buffers.
Definition at line 143 of file MultiBuffer.cc.
|
inlineprivate |
Template function for getting the elements of an array of a certain type.
Definition at line 224 of file MultiBuffer.cc.
|
inlineprivate |
Template function for getting the elements of an array of a certain type.
Definition at line 205 of file MultiBuffer.cc.
const uint8_t * MultiBuffer::getByteArray | ( | size_t | id, |
size_t | offset = 0 |
||
) | const |
Get the array of byte values as a directly readable buffer.
id | the ID of the byte array dataref |
offset | the offset within the buffer. If it is not less than the length of the buffer, 0 is returned. |
Definition at line 537 of file MultiBuffer.cc.
size_t MultiBuffer::getByteArray | ( | size_t | id, |
uint8_t * | value, | ||
size_t | length = 0 , |
||
size_t | offset = 0 |
||
) | const |
Get the value of the byte array dataref with the given ID
id | the ID of the byte array dataref |
value | the destination buffer |
length | the size of the buffer. If 0, it is assumed to be the length of the data in the buffer minus the offset (see below). |
offset | the offset within the buffer to get the data from |
Definition at line 529 of file MultiBuffer.cc.
|
inlineprivate |
Get the data area belonging to the given dataref it is of the given type. If the buffer is not finalized yet, it will be.
Definition at line 167 of file MultiBuffer.cc.
|
inlineprivate |
Get the data area belonging to the given dataref it is of the given type. If the buffer is not finalized yet, it will be.
Definition at line 176 of file MultiBuffer.cc.
|
inlineprivate |
Get the dataref with the given ID if it is of the given type. Otherwise throw an exception.
Definition at line 157 of file MultiBuffer.cc.
double MultiBuffer::getDouble | ( | size_t | id | ) | const |
Get the value of a double dataref with the given ID.
Definition at line 453 of file MultiBuffer.cc.
double & MultiBuffer::getDoubleRef | ( | size_t | id | ) |
Get a reference to the double dataref with the given ID
Definition at line 467 of file MultiBuffer.cc.
const double & MultiBuffer::getDoubleRef | ( | size_t | id | ) | const |
Get a reference to the double dataref with the given ID
Definition at line 460 of file MultiBuffer.cc.
float MultiBuffer::getFloat | ( | size_t | id | ) | const |
Get the value of a float dataref with the given ID.
Definition at line 425 of file MultiBuffer.cc.
size_t MultiBuffer::getFloatArray | ( | size_t | id, |
float * | value, | ||
size_t | length = 0 , |
||
size_t | offset = 0 |
||
) | const |
Get the value of the float array dataref with the given ID
id | the ID of the float array dataref |
value | the destination buffer |
length | the size of the buffer. If 0, it is assumed to be the length of the data in the buffer minus the offset (see below). |
offset | the offset within the buffer to get the data from |
Definition at line 482 of file MultiBuffer.cc.
const float * MultiBuffer::getFloatArray | ( | size_t | id, |
size_t | offset = 0 |
||
) | const |
Get the array of floating point values as a directly readable buffer.
id | the ID of the float array dataref |
offset | the offset within the buffer. If it is not less than the length of the buffer, 0 is returned. |
Definition at line 490 of file MultiBuffer.cc.
float & MultiBuffer::getFloatRef | ( | size_t | id | ) |
Get a reference to the integer dataref with the given ID
Definition at line 439 of file MultiBuffer.cc.
const float & MultiBuffer::getFloatRef | ( | size_t | id | ) | const |
Get a reference to the float dataref with the given ID
Definition at line 432 of file MultiBuffer.cc.
int MultiBuffer::getInt | ( | size_t | id | ) | const |
Get the value of an integer dataref with the given ID.
Definition at line 397 of file MultiBuffer.cc.
size_t MultiBuffer::getIntArray | ( | size_t | id, |
int32_t * | value, | ||
size_t | length = 0 , |
||
size_t | offset = 0 |
||
) | const |
Get the value of the integer array dataref with the given ID
id | the ID of the integer array dataref |
value | the destination buffer |
length | the size of the buffer. If 0, it is assumed to be the length of the data in the buffer minus the offset (see below). |
offset | the offset within the buffer to get the data from |
Definition at line 506 of file MultiBuffer.cc.
const int32_t * MultiBuffer::getIntArray | ( | size_t | id, |
size_t | offset = 0 |
||
) | const |
Get the array of integer values as a directly readable buffer.
id | the ID of the float array dataref |
offset | the offset within the buffer. If it is not less than the length of the buffer, 0 is returned. |
Definition at line 514 of file MultiBuffer.cc.
int32_t & MultiBuffer::getIntRef | ( | size_t | id | ) |
Get a reference to the integer dataref with the given ID
Definition at line 411 of file MultiBuffer.cc.
const int32_t & MultiBuffer::getIntRef | ( | size_t | id | ) | const |
Get a reference to the integer dataref with the given ID
Definition at line 404 of file MultiBuffer.cc.
|
inlineprivatenoexcept |
Get the last dataref, or 0 if there are not datarefs yet.
Definition at line 150 of file MultiBuffer.cc.
string MultiBuffer::getString | ( | size_t | id, |
size_t | offset = 0 |
||
) | const |
Get the value of the byte array dataref with the given ID as a string.
Definition at line 553 of file MultiBuffer.cc.
const char * MultiBuffer::getStringPtr | ( | size_t | id, |
size_t | offset = 0 |
||
) | const |
Get a string pointer to the value of the byte array dataref with the given ID.
Definition at line 571 of file MultiBuffer.cc.
|
inlinenoexcept |
Get the X-Plane object this buffer belongs to.
Definition at line 559 of file MultiBuffer.h.
void MultiBuffer::registerInXPlane | ( | ) |
Register this buffer in X-Plane the for either getting or setting, depending on the actual subclass. It will be finalized too.
Definition at line 330 of file MultiBuffer.cc.
|
protected |
Re-register the buffer in X-Plane, if it has been registered earlier.
it has not been registered, nothing is done. Otherwise the buffer gets registered, and the old ID is forgotten. This function is meant to be used by the XPlane object when it creates a new connection. If the registration fails, the original ID is restored, so that this function could be called again
Definition at line 601 of file MultiBuffer.cc.
|
inlineprivate |
Template function for setting an array of a certain type.
Definition at line 186 of file MultiBuffer.cc.
size_t MultiBuffer::setByteArray | ( | size_t | id, |
const uint8_t * | value, | ||
size_t | length = 0 , |
||
size_t | offset = 0 |
||
) |
Set the value of the byte array dataref with the given ID.
id | the ID of the byte array dataref |
value | the source buffer |
length | the amount of data, i.e. you can set only a part of the data in the buffer. If 0, it is assumed to be the length of the data in the buffer minus the offset (see below). |
offset | the offset within the buffer to set the data from |
Definition at line 521 of file MultiBuffer.cc.
void MultiBuffer::setDouble | ( | size_t | id, |
double | value | ||
) |
Set the value of a double dataref with the given ID.
Definition at line 446 of file MultiBuffer.cc.
void MultiBuffer::setFloat | ( | size_t | id, |
float | value | ||
) |
Set the value of a float dataref with the given ID.
Definition at line 418 of file MultiBuffer.cc.
size_t MultiBuffer::setFloatArray | ( | size_t | id, |
const float * | value, | ||
size_t | length = 0 , |
||
size_t | offset = 0 |
||
) |
Set the value of the float array dataref with the given ID.
id | the ID of the float array dataref |
value | the source buffer |
length | the amount of data, i.e. you can set only a part of the data in the buffer. If 0, it is assumed to be the length of the data in the buffer minus the offset (see below). |
offset | the offset within the buffer to set the data from |
Definition at line 474 of file MultiBuffer.cc.
void MultiBuffer::setInt | ( | size_t | id, |
int | value | ||
) |
Set the value of an integer dataref with the given ID.
Definition at line 390 of file MultiBuffer.cc.
size_t MultiBuffer::setIntArray | ( | size_t | id, |
const int32_t * | value, | ||
size_t | length = 0 , |
||
size_t | offset = 0 |
||
) |
Set the value of the integer array dataref with the given ID.
id | the ID of the integer array dataref |
value | the source buffer |
length | the amount of data, i.e. you can set only a part of the data in the buffer. If 0, it is assumed to be the length of the data in the buffer minus the offset (see below). |
offset | the offset within the buffer to set the data from |
Definition at line 497 of file MultiBuffer.cc.
size_t MultiBuffer::setString | ( | size_t | id, |
const std::string & | value, | ||
size_t | offset = 0 |
||
) |
Set the value of the byte array dataref with the given ID from the given string. If the string contains less characters than the array's length, the rest will be filled with 0s.
Definition at line 544 of file MultiBuffer.cc.
|
inlineprivatenoexcept |
Unfinalize the buffer, if it is finalized.
Definition at line 136 of file MultiBuffer.cc.
void MultiBuffer::unregisterFromXPlane | ( | ) |
Unregister this buffer from X-Plane.
Definition at line 346 of file MultiBuffer.cc.
|
noexcept |
Unregister this buffer from X-Plane safely, i.e. without throwing any exceptions. If unregistration fails, the registered ID will be cleared anyway.
Definition at line 359 of file MultiBuffer.cc.
|
protected |
Write the data specification with the given command. It also checks the result
Definition at line 578 of file MultiBuffer.cc.
|
mutableprotected |
The data buffer.
Definition at line 127 of file MultiBuffer.h.
|
protected |
The datarefs.
Definition at line 122 of file MultiBuffer.h.
|
protected |
The command to use for registering the buffer.
Definition at line 137 of file MultiBuffer.h.
|
protected |
The ID with which this buffer is registered in the plugin. If negative, the buffer is not registerd yet.
Definition at line 148 of file MultiBuffer.h.
|
protected |
The command to unregister the buffer.
Definition at line 142 of file MultiBuffer.h.
|
protected |
The XPlane object this buffer belongs to.
Definition at line 132 of file MultiBuffer.h.