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

#include <RequestQueue.h>

Public Member Functions

 RequestQueue ()
 
bool execute (Request *request)
 
void disable ()
 

Private Types

typedef std::vector< Request * > requests_t
 

Private Member Functions

void run ()
 

Static Private Member Functions

static float flightLoop (float inElapsedSinceLastCall, float inElapsedTimeSinceLastFlightLoop, int inCounter, void *inRefCon)
 

Private Attributes

hu::varadiistvan::scpl::Mutex mutex
 
hu::varadiistvan::scpl::CondVar requestsDone
 
volatile bool enabled
 
requests_t requests
 

Static Private Attributes

static constexpr float flightLoopInterval = 0.1
 

Detailed Description

The queue of the requests. Client serving threads can add requests to the queue. The queue provides a flight loop callback, which it automatically schedules if a request is added to it, unless we are already disabled.

An instance of the queue should be created in the plugin enable callback. The disable callback should disable the queue, so that it will not accept any further requests.

Definition at line 66 of file RequestQueue.h.

Member Typedef Documentation

◆ requests_t

typedef std::vector<Request*> xplra::RequestQueue::requests_t
private

Type for the collection of the queued requests.

Definition at line 72 of file RequestQueue.h.

Constructor & Destructor Documentation

◆ RequestQueue()

RequestQueue::RequestQueue ( )

Construct the queue. It creates the flight loop, so it should be called from a plugin callback.

Definition at line 60 of file RequestQueue.cc.

Member Function Documentation

◆ disable()

void RequestQueue::disable ( )

Disable the queue. It sets the flag indicating that the queue is disabled, and wakes up all waiters waiting on the conditional variable. It should be called from a plugin callback, as it also destroys the flight loop.

Definition at line 109 of file RequestQueue.cc.

◆ execute()

bool RequestQueue::execute ( Request request)

Execute the given request. It will be enqueued, and then this function will wait until the request is executed or the request queue is disabled.

If the queue is already disabled when calling this function, it returns immediately with false.

Returns
if the request was executed

Definition at line 79 of file RequestQueue.cc.

◆ flightLoop()

float RequestQueue::flightLoop ( float  inElapsedSinceLastCall,
float  inElapsedTimeSinceLastFlightLoop,
int  inCounter,
void *  inRefCon 
)
staticprivate

The flight loop function.

Definition at line 45 of file RequestQueue.cc.

◆ run()

void RequestQueue::run ( )
private

Run the queue.

It locks the mutex, swaps the vector of requests with an empty one, unlocks the mutex and runs the requests one by one. When all requests are executed, it wakes up all waiters waiting on the conditional variable.

It is called from the flight loop function.

Definition at line 124 of file RequestQueue.cc.

Member Data Documentation

◆ enabled

volatile bool xplra::RequestQueue::enabled
private

Indicate if the queue is enabled or not.

Definition at line 109 of file RequestQueue.h.

◆ flightLoopInterval

constexpr float xplra::RequestQueue::flightLoopInterval = 0.1
staticconstexprprivate

The interval of the flight loop.

Definition at line 78 of file RequestQueue.h.

◆ mutex

hu::varadiistvan::scpl::Mutex xplra::RequestQueue::mutex
private

The mutex protecting the queue.

Definition at line 98 of file RequestQueue.h.

◆ requests

requests_t xplra::RequestQueue::requests
private

The vector of the queued requests.

Definition at line 114 of file RequestQueue.h.

◆ requestsDone

hu::varadiistvan::scpl::CondVar xplra::RequestQueue::requestsDone
private

A conditional variable to notify the threads waiting for their request to be executed.

Definition at line 104 of file RequestQueue.h.


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