2022-10-04 21:59:06 +02:00

77 lines
1.8 KiB
C++

#ifndef GERMANAIRLINESVA_GACONNECTOR_RECORDER_RECORDER_H
#define GERMANAIRLINESVA_GACONNECTOR_RECORDER_RECORDER_H
#include <atomic>
#include <functional>
#include <mutex>
#include <queue>
#include <thread>
#include "constants.h"
#include "websocket.h"
#if defined(IBM) && not defined(XP)
#include "_simconnect.h"
#include <shlobj.h>
#include <stdlib.h>
#include <windows.h>
#endif
#include "config/config.hpp"
#include "logbook/logbook.hpp"
#include "recording/recording.hpp"
#include "simdata/simDatabase.hpp"
namespace germanairlinesva
{
namespace gaconnector
{
namespace recorder
{
class Recorder
{
private:
std::function<void(const std::string)> toLog;
std::mutex mutex;
std::thread serverThread;
std::thread recordingThread;
std::atomic<bool> wantsExit{false};
std::shared_ptr<file::config::Config> configuration;
std::unique_ptr<file::simdata::SimDatabase> database;
std::unique_ptr<websocket::Websocket> connector;
websocket::data toSend;
bool simSupported = false;
std::queue<std::function<void()>> &messageQueue()
{
static std::queue<std::function<void()>> _messageQueue;
return _messageQueue;
}
void serverWorker();
void recordingWorker();
// For Testing
void test() const;
public:
Recorder(int simVersion, std::function<void(const std::string)> toLog);
~Recorder();
void setData(websocket::data &data);
void handleMessages();
std::shared_ptr<file::config::Config> getConfiguration() const;
void loadDatabase(int simVersion);
bool getSupportedState() const;
};
} // namespace recorder
} // namespace gaconnector
} // namespace germanairlinesva
#endif