X-Plane Remote Access Plugin and Client Library
|
#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 |
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.
|
private |
Type for the collection of the queued requests.
Definition at line 72 of file RequestQueue.h.
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.
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.
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.
Definition at line 79 of file RequestQueue.cc.
|
staticprivate |
The flight loop function.
Definition at line 45 of file RequestQueue.cc.
|
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.
|
private |
Indicate if the queue is enabled or not.
Definition at line 109 of file RequestQueue.h.
|
staticconstexprprivate |
The interval of the flight loop.
Definition at line 78 of file RequestQueue.h.
|
private |
The mutex protecting the queue.
Definition at line 98 of file RequestQueue.h.
|
private |
The vector of the queued requests.
Definition at line 114 of file RequestQueue.h.
|
private |
A conditional variable to notify the threads waiting for their request to be executed.
Definition at line 104 of file RequestQueue.h.