31 #include "ServerThread.h"
33 #include "ListenThread.h"
34 #include "RequestQueue.h"
36 #include "GetDataRefTask.h"
37 #include "SetDataRefTask.h"
38 #include "TaskRequest.h"
39 #include "GetMultiDataRefRequest.h"
40 #include "SetMultiDataRefRequest.h"
41 #include "ReloadPluginsRequest.h"
43 #include "SaveSituationRequest.h"
45 #include "MessageRequest.h"
48 #include <hu/varadiistvan/xplcommon/Util.h>
56 using hu::varadiistvan::scpl::io::BufferedStreamAcceptor;
57 using hu::varadiistvan::scpl::Mutex;
58 using hu::varadiistvan::xplcommon::Util;
64 Mutex ServerThread::instancesMutex;
66 ServerThread::instances_t ServerThread::instances;
70 void ServerThread::quitAll()
100 BufferedStreamAcceptor& acceptor) :
101 listenThread(listenThread),
102 requestQueue(requestQueue),
103 bufferedStream(acceptor.getAcceptedBufferedStream(&waiter)),
104 stream(*bufferedStream),
105 nextGetMultiRequestID(1),
106 nextSetMultiRequestID(1),
144 Util::debug(
"hu.varadiistvan.xplra.ServerThread[%p]::run\n",
this);
146 uint8_t command =
stream.readU8();
178 if (!handleSaveSituation())
break;
196 Util::debug(
"hu.varadiistvan.xplra.ServerThread[%p]::run: quitting\n",
this);
208 }
else if (task==0) {
235 }
else if (task==0) {
328 uint32_t
id =
stream.readU32();
329 if (!
stream)
return false;
348 uint32_t
id =
stream.readU32();
349 if (!
stream)
return false;
389 uint32_t
id =
stream.readU32();
390 if (!
stream)
return false;
409 uint32_t
id =
stream.readU32();
410 if (!
stream)
return false;
429 int xplaneVersion = 0;
435 stream.writeS32(xplaneVersion);
436 stream.writeS32(xplmVersion);
458 bool ServerThread::handleSaveSituation()
460 string path =
stream.readString();
476 string message =
stream.readString();
477 float duration =
stream.readFloat();
478 if (!
stream)
return false;
497 size_t numHotkeys =
stream.readU32();
498 if (!
stream)
return false;
virtual void writeValue(hu::varadiistvan::scpl::io::DataStream &stream)=0
static GetDataRefTask * create(uint8_t &result, hu::varadiistvan::scpl::io::DataStream &stream)
void writeResult(hu::varadiistvan::scpl::io::DataStream &stream) const
void getVersions(int &xplaneV, int &xplmV) const
MessageWindow & getMessageWindow()
HotkeyHandler & getHotkeyHandler()
void writePressed(hu::varadiistvan::scpl::io::DataStream &stream)
void unregisterHotkeys(Hotkeys *hotkeys)
void registerHotkeys(Hotkeys *hotkeys)
static const uint8_t COMMAND_UNREGISTER_GET_MULTI
static const uint8_t COMMAND_EXECUTE_GET_MULTI
static const uint8_t COMMAND_REGISTER_GET_MULTI
static const uint8_t RESULT_INVALID_LENGTH
static const uint8_t COMMAND_QUERY_HOTKEYS
static const uint8_t RESULT_OK
static const uint8_t COMMAND_SET_SINGLE
static constexpr float MAX_MESSAGE_DURATION
static const uint8_t COMMAND_REGISTER_HOTKEYS
static const uint8_t COMMAND_GET_SINGLE
static const uint8_t COMMAND_SET_MULTI
static const uint8_t COMMAND_UNREGISTER_HOTKEYS
static const uint8_t RESULT_OTHER_ERROR
static const uint8_t COMMAND_REGISTER_SET_MULTI
static const uint8_t RESULT_INVALID_COMMAND
static const uint8_t RESULT_INVALID_ID
static const uint8_t RESULT_UNKNOWN_DATAREF
static const uint8_t COMMAND_GET_MULTI
static const uint8_t COMMAND_GET_VERSIONS
static const uint8_t COMMAND_UNREGISTER_SET_MULTI
static const uint8_t COMMAND_SHOW_MESSAGE
static const uint8_t COMMAND_EXECUTE_SET_MULTI
static const size_t MAX_HOTKEY_COUNT
static const uint8_t COMMAND_SAVE_SITUATION
static const uint8_t COMMAND_RELOAD_PLUGINS
static const uint8_t RESULT_INVALID_DURATION
bool execute(Request *request)
ServerThread(ListenThread &listenThread, RequestQueue &requestQueue, hu::varadiistvan::scpl::io::BufferedStreamAcceptor &acceptor)
setMultiRequests_t setMultiRequests
static instances_t instances
HotkeyHandler::Hotkeys * hotkeys
bool handleReloadPlugins()
bool handleQueryHotkeys()
bool handleUnregisterSetMulti()
bool handleRegisterSetMulti()
ListenThread & listenThread
static hu::varadiistvan::scpl::Mutex instancesMutex
bool handleRegisterHotkeys()
RequestQueue & requestQueue
bool handleExecuteGetMulti()
size_t nextSetMultiRequestID
hu::varadiistvan::scpl::io::BufferedStream * bufferedStream
bool handleUnregisterHotkeys()
bool handleExecuteSetMulti()
size_t nextGetMultiRequestID
bool handleUnregisterGetMulti()
hu::varadiistvan::scpl::io::DataStream stream
getMultiRequests_t getMultiRequests
bool handleRegisterGetMulti()
static SetDataRefTask * create(uint8_t &result, hu::varadiistvan::scpl::io::DataStream &stream)
virtual void readValue(hu::varadiistvan::scpl::io::DataStream &stream)=0
void readValues(hu::varadiistvan::scpl::io::DataStream &stream)
void writeResult(hu::varadiistvan::scpl::io::DataStream &stream) const