Implement reload method
This commit is contained in:
		@@ -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 <algorithm>
 | 
				
			||||||
#include <cstdio>
 | 
					#include <cstdio>
 | 
				
			||||||
#include <cstdlib>
 | 
					#include <cstdlib>
 | 
				
			||||||
 | 
					#include <mutex>
 | 
				
			||||||
 | 
					
 | 
				
			||||||
#include "util.h"
 | 
					#include "util.h"
 | 
				
			||||||
#include "Device.h"
 | 
					#include "Device.h"
 | 
				
			||||||
@@ -15,6 +9,8 @@
 | 
				
			|||||||
#include "Configuration.h"
 | 
					#include "Configuration.h"
 | 
				
			||||||
#include "EvdevDevice.h"
 | 
					#include "EvdevDevice.h"
 | 
				
			||||||
#include "DeviceFinder.h"
 | 
					#include "DeviceFinder.h"
 | 
				
			||||||
 | 
					#include "IPCServer.h"
 | 
				
			||||||
 | 
					#include "logid.h"
 | 
				
			||||||
 | 
					
 | 
				
			||||||
#define evdev_name "logid"
 | 
					#define evdev_name "logid"
 | 
				
			||||||
#define DEFAULT_CONFIG_FILE "/etc/logid.cfg"
 | 
					#define DEFAULT_CONFIG_FILE "/etc/logid.cfg"
 | 
				
			||||||
@@ -33,6 +29,9 @@ Configuration* logid::global_config;
 | 
				
			|||||||
EvdevDevice* logid::global_evdev;
 | 
					EvdevDevice* logid::global_evdev;
 | 
				
			||||||
DeviceFinder* logid::finder;
 | 
					DeviceFinder* logid::finder;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					bool logid::kill_logid = false;
 | 
				
			||||||
 | 
					std::mutex logid::finder_reloading;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
enum class Option
 | 
					enum class Option
 | 
				
			||||||
{
 | 
					{
 | 
				
			||||||
    None,
 | 
					    None,
 | 
				
			||||||
@@ -42,6 +41,19 @@ enum class Option
 | 
				
			|||||||
    Version
 | 
					    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)
 | 
					void read_cli_options(int argc, char** argv)
 | 
				
			||||||
{
 | 
					{
 | 
				
			||||||
    for(int i = 1; i < argc; i++)
 | 
					    for(int i = 1; i < argc; i++)
 | 
				
			||||||
@@ -155,7 +167,13 @@ int main(int argc, char** argv)
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
    // Scan devices, create listeners, handlers, etc.
 | 
					    // Scan devices, create listeners, handlers, etc.
 | 
				
			||||||
    finder = new DeviceFinder();
 | 
					    finder = new DeviceFinder();
 | 
				
			||||||
    finder->run();
 | 
					
 | 
				
			||||||
 | 
					    while(!kill_logid)
 | 
				
			||||||
 | 
					    {
 | 
				
			||||||
 | 
					        finder_reloading.lock();
 | 
				
			||||||
 | 
					        finder_reloading.unlock();
 | 
				
			||||||
 | 
					        finder->run();
 | 
				
			||||||
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    return EXIT_SUCCESS;
 | 
					    return EXIT_SUCCESS;
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
							
								
								
									
										14
									
								
								src/logid/logid.h
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										14
									
								
								src/logid/logid.h
									
									
									
									
									
										Normal 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
 | 
				
			||||||
		Reference in New Issue
	
	Block a user