Formating
This commit is contained in:
@@ -45,6 +45,7 @@ namespace gaconnector
|
||||
std::unique_ptr<websocket::Websocket> connector;
|
||||
|
||||
websocket::data toSend;
|
||||
bool simSupported = false;
|
||||
|
||||
std::queue<std::function<void()>> &messageQueue()
|
||||
{
|
||||
@@ -67,6 +68,7 @@ namespace gaconnector
|
||||
void handleMessages();
|
||||
std::shared_ptr<file::config::Config> getConfiguration() const;
|
||||
void loadDatabase(int simVersion);
|
||||
bool getSupportedState() const;
|
||||
};
|
||||
} // namespace recorder
|
||||
} // namespace gaconnector
|
||||
|
||||
+40
-27
@@ -6,6 +6,8 @@ namespace gaconnector
|
||||
{
|
||||
namespace recorder
|
||||
{
|
||||
#pragma clang diagnostic push
|
||||
#pragma clang diagnostic ignored "-Wunused-parameter"
|
||||
Recorder::Recorder(int simVersion,
|
||||
std::function<void(const std::string)> toLog)
|
||||
: toLog(std::move(toLog))
|
||||
@@ -16,15 +18,7 @@ namespace gaconnector
|
||||
|
||||
// Database
|
||||
#ifdef XP
|
||||
char hash[2 * MD5LEN + 1] = "";
|
||||
if (utilities::generateMD5(XPLANE_CUSTOM_SCENERY, hash, this->toLog) ==
|
||||
0) {
|
||||
this->database =
|
||||
std::make_unique<file::simdata::SimDatabase>(simVersion,
|
||||
hash,
|
||||
this->configuration,
|
||||
this->toLog);
|
||||
}
|
||||
this->loadDatabase(simVersion);
|
||||
#endif
|
||||
|
||||
// WebSocket
|
||||
@@ -44,28 +38,29 @@ namespace gaconnector
|
||||
this->recordingThread = std::thread(&Recorder::recordingWorker, this);
|
||||
this->toLog("Workers started");
|
||||
}
|
||||
#pragma clang diagnostic pop
|
||||
|
||||
Recorder::~Recorder()
|
||||
{
|
||||
wantsExit = true;
|
||||
serverThread.join();
|
||||
recordingThread.join();
|
||||
this->wantsExit.store(true);
|
||||
this->serverThread.join();
|
||||
this->recordingThread.join();
|
||||
}
|
||||
|
||||
void Recorder::setData(websocket::data &data)
|
||||
{
|
||||
const std::lock_guard<std::mutex> lock(mutex);
|
||||
const std::lock_guard<std::mutex> lock(this->mutex);
|
||||
|
||||
std::memcpy(&this->toSend, &data, sizeof(websocket::data));
|
||||
}
|
||||
|
||||
void Recorder::handleMessages()
|
||||
{
|
||||
const std::lock_guard<std::mutex> lock(mutex);
|
||||
const std::lock_guard<std::mutex> lock(this->mutex);
|
||||
|
||||
if (!messageQueue().empty()) {
|
||||
auto op = std::move(messageQueue().front());
|
||||
messageQueue().pop();
|
||||
if (!this->messageQueue().empty()) {
|
||||
auto op = std::move(this->messageQueue().front());
|
||||
this->messageQueue().pop();
|
||||
op();
|
||||
}
|
||||
}
|
||||
@@ -77,11 +72,24 @@ namespace gaconnector
|
||||
|
||||
void Recorder::loadDatabase(int simVersion)
|
||||
{
|
||||
#ifdef XP
|
||||
char hash[2 * MD5LEN + 1] = "";
|
||||
if (utilities::generateMD5(XPLANE_CUSTOM_SCENERY, hash, this->toLog) ==
|
||||
0) {
|
||||
this->database =
|
||||
std::make_unique<file::simdata::SimDatabase>(simVersion,
|
||||
hash,
|
||||
this->configuration,
|
||||
this->toLog);
|
||||
}
|
||||
#endif
|
||||
|
||||
#if defined(IBM) && not defined(XP)
|
||||
if (simVersion == MSFS_VERSION) {
|
||||
this->simSupported = strcmp(BIT, "64") == 0;
|
||||
return;
|
||||
}
|
||||
|
||||
#if defined(IBM) && not defined(XP)
|
||||
this->toLog("Loading database for " +
|
||||
SimConnect::resolveVersion(simVersion));
|
||||
|
||||
@@ -98,14 +106,14 @@ namespace gaconnector
|
||||
|
||||
std::string path(nstring);
|
||||
path.append(SimConnect::resolveScenery(simVersion));
|
||||
this->toLog(path);
|
||||
this->toLog("Scenery path: " + path);
|
||||
|
||||
delete[] nstring;
|
||||
CoTaskMemFree(folder);
|
||||
|
||||
char hash[2 * MD5LEN + 1] = "";
|
||||
if (utilities::generateMD5(path.c_str(), hash, toLog) == 0) {
|
||||
database =
|
||||
this->database =
|
||||
std::make_unique<file::simdata::SimDatabase>(simVersion,
|
||||
hash,
|
||||
this->configuration,
|
||||
@@ -115,8 +123,13 @@ namespace gaconnector
|
||||
this->test();
|
||||
}
|
||||
#endif
|
||||
|
||||
// Only here can we be sure to have a supported sim
|
||||
this->simSupported = true;
|
||||
}
|
||||
|
||||
bool Recorder::getSupportedState() const { return this->simSupported; }
|
||||
|
||||
void Recorder::serverWorker()
|
||||
{
|
||||
utilities::setThreadName("GAServerWorker");
|
||||
@@ -124,17 +137,17 @@ namespace gaconnector
|
||||
while (!wantsExit) {
|
||||
struct websocket::data copy;
|
||||
{
|
||||
const std::lock_guard<std::mutex> lock(mutex);
|
||||
const std::lock_guard<std::mutex> lock(this->mutex);
|
||||
|
||||
std::memcpy(©, &toSend, sizeof(websocket::data));
|
||||
std::memcpy(©, &this->toSend, sizeof(websocket::data));
|
||||
}
|
||||
|
||||
connector->sendData(copy);
|
||||
this->connector->sendData(copy);
|
||||
|
||||
std::this_thread::sleep_for(std::chrono::milliseconds(250));
|
||||
}
|
||||
|
||||
toLog("Server thread stopped");
|
||||
this->toLog("Server thread stopped");
|
||||
}
|
||||
|
||||
void Recorder::recordingWorker()
|
||||
@@ -148,9 +161,9 @@ namespace gaconnector
|
||||
while (!wantsExit) {
|
||||
struct websocket::data copy;
|
||||
{
|
||||
const std::lock_guard<std::mutex> lock(mutex);
|
||||
const std::lock_guard<std::mutex> lock(this->mutex);
|
||||
|
||||
std::memcpy(©, &toSend, sizeof(websocket::data));
|
||||
std::memcpy(©, &this->toSend, sizeof(websocket::data));
|
||||
}
|
||||
|
||||
file::recording::RecordingEntry currentPath(
|
||||
@@ -171,7 +184,7 @@ namespace gaconnector
|
||||
}
|
||||
|
||||
path.toFile("flight.rec");
|
||||
toLog("Recording thread stopped");
|
||||
this->toLog("Recording thread stopped");
|
||||
}
|
||||
|
||||
void Recorder::test() const
|
||||
|
||||
Reference in New Issue
Block a user