X-Plane Remote Access Plugin and Client Library
RequestQueue.h
1 // Copyright (c) 2013 by István Váradi
2 
3 // This file is part of XPLRA, a remote-access plugin for X-Plane
4 
5 // Redistribution and use in source and binary forms, with or without
6 // modification, are permitted provided that the following conditions are met:
7 
8 // 1. Redistributions of source code must retain the above copyright notice, this
9 // list of conditions and the following disclaimer.
10 // 2. Redistributions in binary form must reproduce the above copyright notice,
11 // this list of conditions and the following disclaimer in the documentation
12 // and/or other materials provided with the distribution.
13 
14 // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
15 // ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
16 // WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
17 // DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR
18 // ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
19 // (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
20 // LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
21 // ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
22 // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
23 // SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
24 
25 // The views and conclusions contained in the software and documentation are those
26 // of the authors and should not be interpreted as representing official policies,
27 // either expressed or implied, of the FreeBSD Project.
28 
29 #ifndef XPLRA_REQUESTQUEUE_H
30 #define XPLRA_REQUESTQUEUE_H
31 //------------------------------------------------------------------------------
32 
33 #include <hu/varadiistvan/scpl/Mutex.h>
34 #include <hu/varadiistvan/scpl/CondVar.h>
35 
36 #include <XPLMProcessing.h>
37 
38 #include <vector>
39 
40 //------------------------------------------------------------------------------
41 
42 // Define to 1, if the new XPLMScheduleFlightLoop function should be
43 // used to schedule the flight loop only on-demand
44 #define USE_SCHEDULE_FLIGHTLOOP 0
45 
46 //------------------------------------------------------------------------------
47 
48 namespace xplra {
49 
50 //------------------------------------------------------------------------------
51 
52 class Request;
53 
54 //------------------------------------------------------------------------------
55 
67 {
68 private:
72  typedef std::vector<Request*> requests_t;
73 
74 #if !USE_SCHEDULE_FLIGHTLOOP
78  static constexpr float flightLoopInterval = 0.1;
79 #endif
80 
84  static float flightLoop(float inElapsedSinceLastCall,
85  float inElapsedTimeSinceLastFlightLoop,
86  int inCounter, void* inRefCon);
87 
88 #if USE_SCHEDULE_FLIGHTLOOP
92  XPLMFlightLoopID flightLoopID;
93 #endif
94 
98  hu::varadiistvan::scpl::Mutex mutex;
99 
104  hu::varadiistvan::scpl::CondVar requestsDone;
105 
109  volatile bool enabled;
110 
115 
116 public:
121  RequestQueue();
122 
133  bool execute(Request* request);
134 
141  void disable();
142 
143 private:
154  void run();
155 };
156 
157 //------------------------------------------------------------------------------
158 
159 } /* namespace xplra */
160 
161 //------------------------------------------------------------------------------
162 #endif // XPLRA_REQUESTQUEUE_H
163 
164 // Local Variables:
165 // mode: C++
166 // c-basic-offset: 4
167 // indent-tabs-mode: nil
168 // End:
static constexpr float flightLoopInterval
Definition: RequestQueue.h:78
hu::varadiistvan::scpl::CondVar requestsDone
Definition: RequestQueue.h:104
bool execute(Request *request)
Definition: RequestQueue.cc:79
std::vector< Request * > requests_t
Definition: RequestQueue.h:72
volatile bool enabled
Definition: RequestQueue.h:109
static float flightLoop(float inElapsedSinceLastCall, float inElapsedTimeSinceLastFlightLoop, int inCounter, void *inRefCon)
Definition: RequestQueue.cc:45
hu::varadiistvan::scpl::Mutex mutex
Definition: RequestQueue.h:98
Python client module for the X-Plane Remote Access plugin.
Definition: DataRefTask.h:41