X-Plane Remote Access Plugin and Client Library
Classes | Public Member Functions | Protected Member Functions | Protected Attributes | Private Member Functions | Friends | List of all members
hu::varadiistvan::xplra::MultiBuffer Class Referenceabstract

#include <MultiBuffer.h>

Inheritance diagram for hu::varadiistvan::xplra::MultiBuffer:
hu::varadiistvan::xplra::MultiGetter hu::varadiistvan::xplra::MultiSetter

Classes

class  DataRef
 

Public Member Functions

XPlanegetXPlane () 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< DataRefdataRefs
 
unsigned char * data
 
XPlanexplane
 
uint8_t registerCommand
 
uint8_t unregisterCommand
 
int registeredID
 

Private Member Functions

void unfinalize () noexcept
 
void forgetRegistration () noexcept
 
const DataRefgetLastDataRef () const noexcept
 
const DataRefgetDataRef (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
 

Detailed Description

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.

Constructor & Destructor Documentation

◆ MultiBuffer()

MultiBuffer::MultiBuffer ( XPlane xplane,
uint8_t  registerCommand,
uint8_t  unregisterCommand 
)
protectednoexcept

Construct an empty buffer for the given XPlane instance.

Definition at line 235 of file MultiBuffer.cc.

◆ ~MultiBuffer()

MultiBuffer::~MultiBuffer ( )
protectedvirtualnoexcept

Destroy the buffer. If it is registered, an attempt will be made to unregister it.

Definition at line 247 of file MultiBuffer.cc.

Member Function Documentation

◆ addByteArray()

size_t MultiBuffer::addByteArray ( const std::string &  name,
size_t  length,
size_t  offset = 0 
)
noexcept

Add a byte array dataref.

Returns
the ID of the dataref, that can be used later to set or get the value.

Definition at line 304 of file MultiBuffer.cc.

◆ addDouble()

size_t MultiBuffer::addDouble ( const std::string &  name)
noexcept

Add a double dataref.

Returns
the ID of the dataref, that can be used later to set or get the value.

Definition at line 273 of file MultiBuffer.cc.

◆ addFloat()

size_t MultiBuffer::addFloat ( const std::string &  name)
noexcept

Add a float dataref.

Returns
the ID of the dataref, that can be used later to set or get the value.

Definition at line 264 of file MultiBuffer.cc.

◆ addFloatArray()

size_t MultiBuffer::addFloatArray ( const std::string &  name,
size_t  length,
size_t  offset = 0 
)
noexcept

Add a float array dataref.

Returns
the ID of the dataref, that can be used later to set or get the value.

Definition at line 282 of file MultiBuffer.cc.

◆ addInt()

size_t MultiBuffer::addInt ( const std::string &  name)
noexcept

Add an integer dataref.

Returns
the ID of the dataref, that can be used later to set or get the value.

Definition at line 255 of file MultiBuffer.cc.

◆ addIntArray()

size_t MultiBuffer::addIntArray ( const std::string &  name,
size_t  length,
size_t  offset = 0 
)
noexcept

Add an integer array dataref.

Returns
the ID of the dataref, that can be used later to set or get the value.

Definition at line 293 of file MultiBuffer.cc.

◆ doExecute()

virtual void hu::varadiistvan::xplra::MultiBuffer::doExecute ( )
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.

◆ doExecuteUnregistered()

virtual void hu::varadiistvan::xplra::MultiBuffer::doExecuteUnregistered ( )
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.

◆ execute()

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.

◆ finalize()

bool MultiBuffer::finalize ( ) const

Finalize the buffer, if not finalized yet.

Returns
if there is any data in it

Definition at line 315 of file MultiBuffer.cc.

◆ forgetRegistration()

void MultiBuffer::forgetRegistration ( )
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.

◆ getArray() [1/2]

template<typename T , uint8_t type>
const T * MultiBuffer::getArray ( size_t  id,
size_t  offset 
) const
inlineprivate

Template function for getting the elements of an array of a certain type.

Definition at line 224 of file MultiBuffer.cc.

◆ getArray() [2/2]

template<typename T , uint8_t type>
size_t MultiBuffer::getArray ( size_t  id,
T *  value,
size_t  length,
size_t  offset 
) const
inlineprivate

Template function for getting the elements of an array of a certain type.

Definition at line 205 of file MultiBuffer.cc.

◆ getByteArray() [1/2]

const uint8_t * MultiBuffer::getByteArray ( size_t  id,
size_t  offset = 0 
) const

Get the array of byte values as a directly readable buffer.

Parameters
idthe ID of the byte array dataref
offsetthe 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.

◆ getByteArray() [2/2]

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

Parameters
idthe ID of the byte array dataref
valuethe destination buffer
lengththe size of the buffer. If 0, it is assumed to be the length of the data in the buffer minus the offset (see below).
offsetthe offset within the buffer to get the data from
Returns
the number of data items retrieved.

Definition at line 529 of file MultiBuffer.cc.

◆ getData() [1/2]

void * MultiBuffer::getData ( size_t  id,
uint8_t  type 
)
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.

◆ getData() [2/2]

const void * MultiBuffer::getData ( size_t  id,
uint8_t  type 
) const
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.

◆ getDataRef()

const MultiBuffer::DataRef & MultiBuffer::getDataRef ( size_t  id,
uint8_t  type 
) const
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.

◆ getDouble()

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.

◆ getDoubleRef() [1/2]

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.

◆ getDoubleRef() [2/2]

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.

◆ getFloat()

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.

◆ getFloatArray() [1/2]

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

Parameters
idthe ID of the float array dataref
valuethe destination buffer
lengththe size of the buffer. If 0, it is assumed to be the length of the data in the buffer minus the offset (see below).
offsetthe offset within the buffer to get the data from
Returns
the number of data items retrieved.

Definition at line 482 of file MultiBuffer.cc.

◆ getFloatArray() [2/2]

const float * MultiBuffer::getFloatArray ( size_t  id,
size_t  offset = 0 
) const

Get the array of floating point values as a directly readable buffer.

Parameters
idthe ID of the float array dataref
offsetthe 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.

◆ getFloatRef() [1/2]

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.

◆ getFloatRef() [2/2]

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.

◆ getInt()

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.

◆ getIntArray() [1/2]

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

Parameters
idthe ID of the integer array dataref
valuethe destination buffer
lengththe size of the buffer. If 0, it is assumed to be the length of the data in the buffer minus the offset (see below).
offsetthe offset within the buffer to get the data from
Returns
the number of data items retrieved.

Definition at line 506 of file MultiBuffer.cc.

◆ getIntArray() [2/2]

const int32_t * MultiBuffer::getIntArray ( size_t  id,
size_t  offset = 0 
) const

Get the array of integer values as a directly readable buffer.

Parameters
idthe ID of the float array dataref
offsetthe 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.

◆ getIntRef() [1/2]

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.

◆ getIntRef() [2/2]

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.

◆ getLastDataRef()

const MultiBuffer::DataRef * MultiBuffer::getLastDataRef ( ) const
inlineprivatenoexcept

Get the last dataref, or 0 if there are not datarefs yet.

Definition at line 150 of file MultiBuffer.cc.

◆ getString()

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.

◆ getStringPtr()

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.

◆ getXPlane()

XPlane & hu::varadiistvan::xplra::MultiBuffer::getXPlane ( ) const
inlinenoexcept

Get the X-Plane object this buffer belongs to.

Definition at line 559 of file MultiBuffer.h.

◆ registerInXPlane()

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.

◆ reregisterInXPlane()

void MultiBuffer::reregisterInXPlane ( )
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.

◆ setArray()

template<typename T , uint8_t type>
size_t MultiBuffer::setArray ( size_t  id,
const T *  value,
size_t  length,
size_t  offset 
)
inlineprivate

Template function for setting an array of a certain type.

Definition at line 186 of file MultiBuffer.cc.

◆ setByteArray()

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.

Parameters
idthe ID of the byte array dataref
valuethe source buffer
lengththe 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).
offsetthe offset within the buffer to set the data from
Returns
the number of data items set

Definition at line 521 of file MultiBuffer.cc.

◆ setDouble()

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.

◆ setFloat()

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.

◆ setFloatArray()

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.

Parameters
idthe ID of the float array dataref
valuethe source buffer
lengththe 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).
offsetthe offset within the buffer to set the data from
Returns
the number of data items set

Definition at line 474 of file MultiBuffer.cc.

◆ setInt()

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.

◆ setIntArray()

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.

Parameters
idthe ID of the integer array dataref
valuethe source buffer
lengththe 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).
offsetthe offset within the buffer to set the data from
Returns
the number of data items set

Definition at line 497 of file MultiBuffer.cc.

◆ setString()

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.

Returns
the number of bytes set

Definition at line 544 of file MultiBuffer.cc.

◆ unfinalize()

void MultiBuffer::unfinalize ( )
inlineprivatenoexcept

Unfinalize the buffer, if it is finalized.

Definition at line 136 of file MultiBuffer.cc.

◆ unregisterFromXPlane()

void MultiBuffer::unregisterFromXPlane ( )

Unregister this buffer from X-Plane.

Definition at line 346 of file MultiBuffer.cc.

◆ unregisterSafelyFromXPlane()

bool MultiBuffer::unregisterSafelyFromXPlane ( )
noexcept

Unregister this buffer from X-Plane safely, i.e. without throwing any exceptions. If unregistration fails, the registered ID will be cleared anyway.

Returns
whether unregistration succeeded.

Definition at line 359 of file MultiBuffer.cc.

◆ writeSpec()

void MultiBuffer::writeSpec ( uint8_t  command) const
protected

Write the data specification with the given command. It also checks the result

Definition at line 578 of file MultiBuffer.cc.

Member Data Documentation

◆ data

unsigned char* hu::varadiistvan::xplra::MultiBuffer::data
mutableprotected

The data buffer.

Definition at line 127 of file MultiBuffer.h.

◆ dataRefs

std::vector<DataRef> hu::varadiistvan::xplra::MultiBuffer::dataRefs
protected

The datarefs.

Definition at line 122 of file MultiBuffer.h.

◆ registerCommand

uint8_t hu::varadiistvan::xplra::MultiBuffer::registerCommand
protected

The command to use for registering the buffer.

Definition at line 137 of file MultiBuffer.h.

◆ registeredID

int hu::varadiistvan::xplra::MultiBuffer::registeredID
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.

◆ unregisterCommand

uint8_t hu::varadiistvan::xplra::MultiBuffer::unregisterCommand
protected

The command to unregister the buffer.

Definition at line 142 of file MultiBuffer.h.

◆ xplane

XPlane& hu::varadiistvan::xplra::MultiBuffer::xplane
protected

The XPlane object this buffer belongs to.

Definition at line 132 of file MultiBuffer.h.


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