2019-07-17 05:53:51 +00:00
|
|
|
#include <hidpp/SimpleDispatcher.h>
|
|
|
|
#include <hidpp/DispatcherThread.h>
|
|
|
|
#include <hidpp20/Device.h>
|
|
|
|
#include <hidpp20/Error.h>
|
2019-07-22 23:47:09 +00:00
|
|
|
#include <hidpp20/IReprogControls.h>
|
2019-07-17 05:53:51 +00:00
|
|
|
#include <hidpp20/UnsupportedFeature.h>
|
|
|
|
#include <hid/DeviceMonitor.h>
|
|
|
|
#include <algorithm>
|
|
|
|
#include <cstdio>
|
|
|
|
#include <cstdlib>
|
|
|
|
|
|
|
|
#include "util.h"
|
|
|
|
#include "Device.h"
|
|
|
|
#include "Actions.h"
|
|
|
|
#include "Configuration.h"
|
|
|
|
#include "EvdevDevice.h"
|
|
|
|
#include "DeviceFinder.h"
|
|
|
|
|
|
|
|
#define evdev_name "logid"
|
|
|
|
|
2019-08-09 02:13:50 +00:00
|
|
|
LogLevel global_verbosity = INFO;
|
2019-07-17 05:53:51 +00:00
|
|
|
Configuration* global_config;
|
|
|
|
EvdevDevice* global_evdev;
|
2019-07-28 06:08:18 +00:00
|
|
|
DeviceFinder* finder;
|
2019-07-17 05:53:51 +00:00
|
|
|
|
2019-08-09 02:13:50 +00:00
|
|
|
enum class Option
|
|
|
|
{
|
|
|
|
None,
|
|
|
|
Verbose,
|
|
|
|
Config,
|
|
|
|
Help
|
|
|
|
};
|
|
|
|
|
2019-07-17 05:53:51 +00:00
|
|
|
int main(int argc, char** argv)
|
|
|
|
{
|
2019-08-09 02:13:50 +00:00
|
|
|
char* config_file = "/etc/logid.cfg";
|
|
|
|
for(int i = 1; i < argc; i++)
|
|
|
|
{
|
|
|
|
Option option = Option::None;
|
|
|
|
if(argv[i][0] == '-') // Option
|
|
|
|
{
|
|
|
|
switch(argv[i][1])
|
|
|
|
{
|
|
|
|
case '-': // Full option name
|
|
|
|
{
|
|
|
|
std::string op_str = argv[i];
|
|
|
|
if (op_str == "--verbose") option = Option::Verbose;
|
|
|
|
if (op_str == "--config") option = Option::Config;
|
|
|
|
if (op_str == "--help") option = Option::Help;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
case 'v': // Verbosity
|
|
|
|
option = Option::Verbose;
|
|
|
|
break;
|
|
|
|
case 'c': // Config file path
|
|
|
|
option = Option::Config;
|
|
|
|
break;
|
|
|
|
case 'h': // Help
|
|
|
|
option = Option::Help;
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
log_printf(WARN, "%s is not a valid option, ignoring.", argv[1]);
|
|
|
|
}
|
|
|
|
switch(option)
|
|
|
|
{
|
|
|
|
case Option::Verbose:
|
|
|
|
{
|
|
|
|
if (++i >= argc)
|
|
|
|
{
|
|
|
|
global_verbosity = DEBUG; // Assume debug verbosity
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
std::string loglevel = argv[i];
|
|
|
|
try { global_verbosity = string_to_loglevel(argv[i]); }
|
|
|
|
catch (std::invalid_argument &e)
|
|
|
|
{
|
|
|
|
if (argv[i][0] == '-')
|
|
|
|
global_verbosity = DEBUG; // Assume debug verbosity
|
|
|
|
else
|
|
|
|
{
|
|
|
|
log_printf(WARN, e.what());
|
|
|
|
printf("Valid verbosity levels are: Debug, Info, Warn/Warning, or Error.\n");
|
|
|
|
return EXIT_FAILURE;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
case Option::Config:
|
|
|
|
{
|
|
|
|
if (++i >= argc)
|
|
|
|
{
|
|
|
|
log_printf(ERROR, "Config file is not specified.");
|
|
|
|
return EXIT_FAILURE;
|
|
|
|
}
|
|
|
|
config_file = argv[i];
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
case Option::Help:
|
|
|
|
printf(R"(Usage: %s [options]
|
|
|
|
Possible options are:
|
|
|
|
-v,--verbose [level] Set log level to debug/info/warn/error (leave blank for debug)
|
|
|
|
-c,--config [file path] Change config file from default at %s
|
|
|
|
-h,--help Print this message.
|
|
|
|
)", argv[0], config_file);
|
|
|
|
|
|
|
|
return EXIT_SUCCESS;
|
|
|
|
case Option::None:
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-07-17 05:53:51 +00:00
|
|
|
// Read config
|
2019-08-09 02:13:50 +00:00
|
|
|
try { global_config = new Configuration(config_file); }
|
2019-07-17 05:53:51 +00:00
|
|
|
catch (std::exception &e) { return EXIT_FAILURE; }
|
|
|
|
|
|
|
|
//Create an evdev device called 'logid'
|
|
|
|
try { global_evdev = new EvdevDevice(evdev_name); }
|
|
|
|
catch(std::system_error& e)
|
|
|
|
{
|
|
|
|
log_printf(ERROR, "Could not create evdev device: %s", e.what());
|
|
|
|
return EXIT_FAILURE;
|
|
|
|
}
|
|
|
|
|
2019-07-28 06:08:18 +00:00
|
|
|
// Scan devices, create listeners, handlers, etc.
|
|
|
|
finder = new DeviceFinder();
|
|
|
|
finder->run();
|
2019-07-17 05:53:51 +00:00
|
|
|
|
|
|
|
return EXIT_SUCCESS;
|
|
|
|
}
|