2020-08-16 03:39:05 +02:00
|
|
|
#pragma once
|
|
|
|
#include <json.hpp>
|
|
|
|
#include <thread>
|
2020-09-24 19:36:57 +02:00
|
|
|
#include <string>
|
2020-10-07 22:44:54 +02:00
|
|
|
#include <mutex>
|
2021-04-21 18:39:47 +02:00
|
|
|
#include <condition_variable>
|
2020-08-16 03:39:05 +02:00
|
|
|
|
|
|
|
using nlohmann::json;
|
|
|
|
|
2020-09-24 19:36:57 +02:00
|
|
|
class ConfigManager {
|
|
|
|
public:
|
|
|
|
ConfigManager();
|
2020-12-08 04:36:37 +01:00
|
|
|
~ConfigManager();
|
2020-09-24 19:36:57 +02:00
|
|
|
void setPath(std::string file);
|
2020-09-24 19:50:22 +02:00
|
|
|
void load(json def, bool lock = true);
|
2020-09-24 19:36:57 +02:00
|
|
|
void save(bool lock = true);
|
|
|
|
void enableAutoSave();
|
|
|
|
void disableAutoSave();
|
2021-07-09 20:24:07 +02:00
|
|
|
void acquire();
|
2021-07-29 15:07:22 +02:00
|
|
|
void release(bool modified = false);
|
2020-09-24 19:36:57 +02:00
|
|
|
|
|
|
|
json conf;
|
|
|
|
|
|
|
|
private:
|
2021-07-29 15:07:22 +02:00
|
|
|
void autoSaveWorker();
|
2020-09-24 19:36:57 +02:00
|
|
|
|
|
|
|
std::string path = "";
|
2021-07-29 15:07:22 +02:00
|
|
|
volatile bool changed = false;
|
|
|
|
volatile bool autoSaveEnabled = false;
|
2020-09-24 19:36:57 +02:00
|
|
|
std::thread autoSaveThread;
|
|
|
|
std::mutex mtx;
|
2020-08-16 03:39:05 +02:00
|
|
|
|
2021-04-21 18:36:45 +02:00
|
|
|
std::mutex termMtx;
|
|
|
|
std::condition_variable termCond;
|
2021-07-29 15:07:22 +02:00
|
|
|
volatile bool termFlag = false;
|
2021-04-21 18:36:45 +02:00
|
|
|
|
2020-08-16 03:39:05 +02:00
|
|
|
};
|