X-Plane Remote Access Plugin and Client Library
ServerThread.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_SERVERTHREAD_H
30 #define XPLRA_SERVERTHREAD_H
31 //------------------------------------------------------------------------------
32 
33 #include "HotkeyHandler.h"
34 
35 #include <hu/varadiistvan/scpl/Thread.h>
36 
37 #include <hu/varadiistvan/scpl/io/Waiter.h>
38 #include <hu/varadiistvan/scpl/io/BufferedStream.h>
39 #include <hu/varadiistvan/scpl/io/DataStream.h>
40 #include <hu/varadiistvan/scpl/io/BufferedStreamAcceptor.h>
41 
42 #include <hu/varadiistvan/scpl/Mutex.h>
43 
44 #include <set>
45 #include <map>
46 
47 //------------------------------------------------------------------------------
48 
49 namespace xplra {
50 
51 //------------------------------------------------------------------------------
52 
53 class ListenThread;
54 
55 class RequestQueue;
56 
57 class GetMultiDataRefRequest;
58 class SetMultiDataRefRequest;
59 
60 //------------------------------------------------------------------------------
61 
65 class ServerThread : public hu::varadiistvan::scpl::Thread
66 {
67 private:
71  typedef std::set<ServerThread*> instances_t;
72 
76  typedef std::map<size_t, GetMultiDataRefRequest*> getMultiRequests_t;
77 
81  typedef std::map<size_t, SetMultiDataRefRequest*> setMultiRequests_t;
82 
86  static hu::varadiistvan::scpl::Mutex instancesMutex;
87 
92 
93 public:
97  static void quitAll();
98 
99 private:
104 
109 
113  hu::varadiistvan::scpl::io::Waiter waiter;
114 
118  hu::varadiistvan::scpl::io::BufferedStream* bufferedStream;
119 
123  hu::varadiistvan::scpl::io::DataStream stream;
124 
129 
134 
139 
144 
149 
150 public:
156  hu::varadiistvan::scpl::io::BufferedStreamAcceptor& acceptor);
157 
161  virtual ~ServerThread();
162 
166  void quit();
167 
171  virtual void run();
172 
173 private:
179  bool handleGetSingle();
180 
186  bool handleSetSingle();
187 
193  bool handleGetMulti();
194 
200  bool handleSetMulti();
201 
207  bool handleRegisterGetMulti();
208 
215 
221  bool handleExecuteGetMulti();
222 
228  bool handleRegisterSetMulti();
229 
236 
242  bool handleExecuteSetMulti();
243 
249  bool handleGetVersions();
250 
256  bool handleReloadPlugins();
257 
258 #ifdef XPLM200
264  bool handleSaveSituation();
265 #endif
266 
272  bool handleShowMessage();
273 
280  bool handleRegisterHotkeys();
281 
288  bool handleQueryHotkeys();
289 
297 
298 private:
304  bool destroyHotkeys();
305 };
306 
307 //------------------------------------------------------------------------------
308 
309 } /* namespace xplra */
310 
311 //------------------------------------------------------------------------------
312 #endif // XPLRA_SERVERTHREAD_H
313 
314 // Local Variables:
315 // mode: C++
316 // c-basic-offset: 4
317 // indent-tabs-mode: nil
318 // End:
ServerThread(ListenThread &listenThread, RequestQueue &requestQueue, hu::varadiistvan::scpl::io::BufferedStreamAcceptor &acceptor)
Definition: ServerThread.cc:98
setMultiRequests_t setMultiRequests
Definition: ServerThread.h:143
static instances_t instances
Definition: ServerThread.h:91
HotkeyHandler::Hotkeys * hotkeys
Definition: ServerThread.h:148
std::map< size_t, SetMultiDataRefRequest * > setMultiRequests_t
Definition: ServerThread.h:81
bool handleUnregisterSetMulti()
std::map< size_t, GetMultiDataRefRequest * > getMultiRequests_t
Definition: ServerThread.h:76
ListenThread & listenThread
Definition: ServerThread.h:103
static hu::varadiistvan::scpl::Mutex instancesMutex
Definition: ServerThread.h:86
RequestQueue & requestQueue
Definition: ServerThread.h:108
static void quitAll()
Definition: ServerThread.cc:70
size_t nextSetMultiRequestID
Definition: ServerThread.h:138
std::set< ServerThread * > instances_t
Definition: ServerThread.h:71
hu::varadiistvan::scpl::io::BufferedStream * bufferedStream
Definition: ServerThread.h:118
bool handleUnregisterHotkeys()
hu::varadiistvan::scpl::io::Waiter waiter
Definition: ServerThread.h:113
virtual void run()
size_t nextGetMultiRequestID
Definition: ServerThread.h:128
bool handleUnregisterGetMulti()
hu::varadiistvan::scpl::io::DataStream stream
Definition: ServerThread.h:123
getMultiRequests_t getMultiRequests
Definition: ServerThread.h:133
Python client module for the X-Plane Remote Access plugin.
Definition: DataRefTask.h:41