From 526ffec61aa03f4f49b1f249160c53ab3bd6e6f2 Mon Sep 17 00:00:00 2001 From: PixlOne <8843371+PixlOne@users.noreply.github.com> Date: Sun, 12 Apr 2020 22:25:39 -0400 Subject: [PATCH] Implement reload method --- src/logid/logid.cpp | 36 +++++++++++++++++++++++++++--------- src/logid/logid.h | 14 ++++++++++++++ 2 files changed, 41 insertions(+), 9 deletions(-) create mode 100644 src/logid/logid.h diff --git a/src/logid/logid.cpp b/src/logid/logid.cpp index ba36241..891574b 100644 --- a/src/logid/logid.cpp +++ b/src/logid/logid.cpp @@ -1,13 +1,7 @@ -#include -#include -#include -#include -#include -#include -#include #include #include #include +#include #include "util.h" #include "Device.h" @@ -15,6 +9,8 @@ #include "Configuration.h" #include "EvdevDevice.h" #include "DeviceFinder.h" +#include "IPCServer.h" +#include "logid.h" #define evdev_name "logid" #define DEFAULT_CONFIG_FILE "/etc/logid.cfg" @@ -33,6 +29,9 @@ Configuration* logid::global_config; EvdevDevice* logid::global_evdev; DeviceFinder* logid::finder; +bool logid::kill_logid = false; +std::mutex logid::finder_reloading; + enum class Option { None, @@ -42,6 +41,19 @@ enum class Option Version }; +void logid::reload() +{ + log_printf(INFO, "Reloading logid..."); + finder_reloading.lock(); + finder->stop(); + Configuration* old_config = global_config; + global_config = new Configuration(config_file.c_str()); + delete(old_config); + delete(finder); + finder = new DeviceFinder(); + finder_reloading.unlock(); +} + void read_cli_options(int argc, char** argv) { for(int i = 1; i < argc; i++) @@ -155,7 +167,13 @@ int main(int argc, char** argv) // Scan devices, create listeners, handlers, etc. finder = new DeviceFinder(); - finder->run(); + + while(!kill_logid) + { + finder_reloading.lock(); + finder_reloading.unlock(); + finder->run(); + } return EXIT_SUCCESS; -} \ No newline at end of file +} diff --git a/src/logid/logid.h b/src/logid/logid.h new file mode 100644 index 0000000..a5dc790 --- /dev/null +++ b/src/logid/logid.h @@ -0,0 +1,14 @@ +#ifndef LOGID_LOGID_H +#define LOGID_LOGID_H + +#include + +namespace logid +{ + void reload(); + + extern bool kill_logid; + extern std::mutex finder_reloading; +} + +#endif //LOGID_LOGID_H \ No newline at end of file