Implement reload method

This commit is contained in:
PixlOne 2020-04-12 22:25:39 -04:00 committed by pixl
parent 6316b89840
commit 526ffec61a
No known key found for this signature in database
GPG Key ID: 1866C148CD593B6E
2 changed files with 41 additions and 9 deletions

View File

@ -1,13 +1,7 @@
#include <hidpp/SimpleDispatcher.h>
#include <hidpp/DispatcherThread.h>
#include <hidpp20/Device.h>
#include <hidpp20/Error.h>
#include <hidpp20/IReprogControls.h>
#include <hidpp20/UnsupportedFeature.h>
#include <hid/DeviceMonitor.h>
#include <algorithm>
#include <cstdio>
#include <cstdlib>
#include <mutex>
#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;
}
}

14
src/logid/logid.h Normal file
View File

@ -0,0 +1,14 @@
#ifndef LOGID_LOGID_H
#define LOGID_LOGID_H
#include <mutex>
namespace logid
{
void reload();
extern bool kill_logid;
extern std::mutex finder_reloading;
}
#endif //LOGID_LOGID_H