Apply clang-tidy inspections
This commit is contained in:
parent
937225b6f2
commit
d3d4a2755a
|
@ -42,15 +42,7 @@ Configuration::Configuration(const std::string& config_file)
|
||||||
}
|
}
|
||||||
|
|
||||||
const Setting &root = _config.getRoot();
|
const Setting &root = _config.getRoot();
|
||||||
Setting* devices;
|
|
||||||
|
|
||||||
try { devices = &root["devices"]; }
|
|
||||||
catch(const SettingNotFoundException &e) {
|
|
||||||
logPrintf(WARN, "No devices listed in config file.");
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
_worker_threads = LOGID_DEFAULT_WORKER_COUNT;
|
|
||||||
try {
|
try {
|
||||||
auto& worker_count = root["workers"];
|
auto& worker_count = root["workers"];
|
||||||
if(worker_count.getType() == Setting::TypeInt) {
|
if(worker_count.getType() == Setting::TypeInt) {
|
||||||
|
@ -66,7 +58,6 @@ Configuration::Configuration(const std::string& config_file)
|
||||||
// Ignore
|
// Ignore
|
||||||
}
|
}
|
||||||
|
|
||||||
_io_timeout = LOGID_DEFAULT_RAWDEVICE_TIMEOUT;
|
|
||||||
try {
|
try {
|
||||||
auto& timeout = root["io_timeout"];
|
auto& timeout = root["io_timeout"];
|
||||||
if(timeout.isNumber()) {
|
if(timeout.isNumber()) {
|
||||||
|
@ -82,30 +73,37 @@ Configuration::Configuration(const std::string& config_file)
|
||||||
// Ignore
|
// Ignore
|
||||||
}
|
}
|
||||||
|
|
||||||
for(int i = 0; i < devices->getLength(); i++) {
|
try {
|
||||||
const Setting &device = (*devices)[i];
|
auto& devices = root["devices"];
|
||||||
|
|
||||||
|
for(int i = 0; i < devices.getLength(); i++) {
|
||||||
|
const Setting& device = devices[i];
|
||||||
std::string name;
|
std::string name;
|
||||||
try {
|
try {
|
||||||
if(!device.lookupValue("name", name)) {
|
if(!device.lookupValue("name", name)) {
|
||||||
logPrintf(WARN, "Line %d: 'name' must be a string, skipping "
|
logPrintf(WARN, "Line %d: 'name' must be a string, skipping"
|
||||||
"device.", device["name"].getSourceLine());
|
" device.", device["name"].getSourceLine());
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
} catch(SettingNotFoundException &e) {
|
} catch(SettingNotFoundException &e) {
|
||||||
logPrintf(WARN, "Line %d: Missing 'name' field, skipping device."
|
logPrintf(WARN, "Line %d: Missing name field, skipping device."
|
||||||
, device.getSourceLine());
|
, device.getSourceLine());
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
_device_paths.insert({name, device.getPath()});
|
_device_paths.insert({name, device.getPath()});
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
catch(const SettingNotFoundException &e) {
|
||||||
|
logPrintf(WARN, "No devices listed in config file.");
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
libconfig::Setting& Configuration::getSetting(std::string path)
|
libconfig::Setting& Configuration::getSetting(const std::string& path)
|
||||||
{
|
{
|
||||||
return _config.lookup(path);
|
return _config.lookup(path);
|
||||||
}
|
}
|
||||||
|
|
||||||
std::string Configuration::getDevice(std::string name)
|
std::string Configuration::getDevice(const std::string& name)
|
||||||
{
|
{
|
||||||
auto it = _device_paths.find(name);
|
auto it = _device_paths.find(name);
|
||||||
if(it == _device_paths.end())
|
if(it == _device_paths.end())
|
||||||
|
|
|
@ -24,7 +24,7 @@
|
||||||
#include <memory>
|
#include <memory>
|
||||||
#include <chrono>
|
#include <chrono>
|
||||||
|
|
||||||
#define LOGID_DEFAULT_RAWDEVICE_TIMEOUT std::chrono::seconds(2)
|
#define LOGID_DEFAULT_IO_TIMEOUT std::chrono::seconds(2)
|
||||||
#define LOGID_DEFAULT_WORKER_COUNT 4
|
#define LOGID_DEFAULT_WORKER_COUNT 4
|
||||||
|
|
||||||
namespace logid
|
namespace logid
|
||||||
|
@ -34,8 +34,8 @@ namespace logid
|
||||||
public:
|
public:
|
||||||
explicit Configuration(const std::string& config_file);
|
explicit Configuration(const std::string& config_file);
|
||||||
Configuration() = default;
|
Configuration() = default;
|
||||||
libconfig::Setting& getSetting(std::string path);
|
libconfig::Setting& getSetting(const std::string& path);
|
||||||
std::string getDevice(std::string name);
|
std::string getDevice(const std::string& name);
|
||||||
|
|
||||||
class DeviceNotFound : public std::exception
|
class DeviceNotFound : public std::exception
|
||||||
{
|
{
|
||||||
|
@ -50,8 +50,8 @@ namespace logid
|
||||||
int workerCount() const;
|
int workerCount() const;
|
||||||
private:
|
private:
|
||||||
std::map<std::string, std::string> _device_paths;
|
std::map<std::string, std::string> _device_paths;
|
||||||
std::chrono::milliseconds _io_timeout = LOGID_DEFAULT_RAWDEVICE_TIMEOUT;
|
std::chrono::milliseconds _io_timeout = LOGID_DEFAULT_IO_TIMEOUT;
|
||||||
int _worker_threads;
|
int _worker_threads = LOGID_DEFAULT_WORKER_COUNT;
|
||||||
libconfig::Config _config;
|
libconfig::Config _config;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
|
@ -113,7 +113,10 @@ void Device::_makeResetMechanism()
|
||||||
try {
|
try {
|
||||||
hidpp20::Reset reset(&_hidpp20);
|
hidpp20::Reset reset(&_hidpp20);
|
||||||
_reset_mechanism = std::make_unique<std::function<void()>>(
|
_reset_mechanism = std::make_unique<std::function<void()>>(
|
||||||
[dev=&this->_hidpp20]{ hidpp20::Reset(dev).reset(); });
|
[dev=&this->_hidpp20]{
|
||||||
|
hidpp20::Reset reset(dev);
|
||||||
|
reset.reset(reset.getProfile());
|
||||||
|
});
|
||||||
} catch(hidpp20::UnsupportedFeature& e) {
|
} catch(hidpp20::UnsupportedFeature& e) {
|
||||||
// Reset unsupported, ignore.
|
// Reset unsupported, ignore.
|
||||||
}
|
}
|
||||||
|
@ -130,7 +133,7 @@ DeviceConfig::DeviceConfig(const std::shared_ptr<Configuration>& config, Device*
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
libconfig::Setting& DeviceConfig::getSetting(std::string path)
|
libconfig::Setting& DeviceConfig::getSetting(const std::string& path)
|
||||||
{
|
{
|
||||||
return _config->getSetting(_root_setting + '/' + path);
|
return _config->getSetting(_root_setting + '/' + path);
|
||||||
}
|
}
|
||||||
|
|
|
@ -35,7 +35,7 @@ namespace logid
|
||||||
public:
|
public:
|
||||||
DeviceConfig(const std::shared_ptr<Configuration>& config, Device*
|
DeviceConfig(const std::shared_ptr<Configuration>& config, Device*
|
||||||
device);
|
device);
|
||||||
libconfig::Setting& getSetting(std::string path);
|
libconfig::Setting& getSetting(const std::string& path);
|
||||||
private:
|
private:
|
||||||
Device* _device;
|
Device* _device;
|
||||||
std::string _root_setting;
|
std::string _root_setting;
|
||||||
|
@ -72,8 +72,8 @@ namespace logid
|
||||||
try {
|
try {
|
||||||
return std::dynamic_pointer_cast<T>(it->second);
|
return std::dynamic_pointer_cast<T>(it->second);
|
||||||
} catch(std::bad_cast& e) {
|
} catch(std::bad_cast& e) {
|
||||||
logPrintf(ERROR, "bad_cast while getting device feature %s: "
|
logPrintf(ERROR, "bad_cast while getting device feature %s: %s",
|
||||||
"%s", name.c_str(), e.what());
|
name.c_str(), e.what());
|
||||||
return nullptr;
|
return nullptr;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -23,11 +23,8 @@
|
||||||
#include "Receiver.h"
|
#include "Receiver.h"
|
||||||
#include "util/log.h"
|
#include "util/log.h"
|
||||||
#include "backend/hidpp10/Error.h"
|
#include "backend/hidpp10/Error.h"
|
||||||
#include "backend/dj/Receiver.h"
|
|
||||||
#include "backend/Error.h"
|
#include "backend/Error.h"
|
||||||
|
|
||||||
#define NON_WIRELESS_DEV(index) (index) == HIDPP::DefaultDevice ? "default" : "corded"
|
|
||||||
|
|
||||||
using namespace logid;
|
using namespace logid;
|
||||||
using namespace logid::backend;
|
using namespace logid::backend;
|
||||||
|
|
||||||
|
|
|
@ -17,7 +17,6 @@
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#include <system_error>
|
#include <system_error>
|
||||||
#include <utility>
|
|
||||||
|
|
||||||
#include "InputDevice.h"
|
#include "InputDevice.h"
|
||||||
|
|
||||||
|
@ -25,13 +24,13 @@ extern "C"
|
||||||
{
|
{
|
||||||
#include <libevdev/libevdev.h>
|
#include <libevdev/libevdev.h>
|
||||||
#include <libevdev/libevdev-uinput.h>
|
#include <libevdev/libevdev-uinput.h>
|
||||||
};
|
}
|
||||||
|
|
||||||
using namespace logid;
|
using namespace logid;
|
||||||
|
|
||||||
InputDevice::InvalidEventCode::InvalidEventCode(std::string name)
|
InputDevice::InvalidEventCode::InvalidEventCode(const std::string& name) :
|
||||||
|
_what ("Invalid event code " + name)
|
||||||
{
|
{
|
||||||
_what = "Invalid event code " + name;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
const char* InputDevice::InvalidEventCode::what() const noexcept
|
const char* InputDevice::InvalidEventCode::what() const noexcept
|
||||||
|
@ -46,10 +45,10 @@ InputDevice::InputDevice(const char* name)
|
||||||
|
|
||||||
///TODO: Is it really a good idea to enable all events?
|
///TODO: Is it really a good idea to enable all events?
|
||||||
libevdev_enable_event_type(device, EV_KEY);
|
libevdev_enable_event_type(device, EV_KEY);
|
||||||
for(int i = 0; i < KEY_CNT; i++)
|
for(unsigned int i = 0; i < KEY_CNT; i++)
|
||||||
libevdev_enable_event_code(device, EV_KEY, i, nullptr);
|
libevdev_enable_event_code(device, EV_KEY, i, nullptr);
|
||||||
libevdev_enable_event_type(device, EV_REL);
|
libevdev_enable_event_type(device, EV_REL);
|
||||||
for(int i = 0; i < REL_CNT; i++)
|
for(unsigned int i = 0; i < REL_CNT; i++)
|
||||||
libevdev_enable_event_code(device, EV_REL, i, nullptr);
|
libevdev_enable_event_code(device, EV_REL, i, nullptr);
|
||||||
|
|
||||||
int err = libevdev_uinput_create_from_device(device,
|
int err = libevdev_uinput_create_from_device(device,
|
||||||
|
@ -80,14 +79,14 @@ void InputDevice::releaseKey(uint code)
|
||||||
_sendEvent(EV_KEY, code, 0);
|
_sendEvent(EV_KEY, code, 0);
|
||||||
}
|
}
|
||||||
|
|
||||||
uint InputDevice::toKeyCode(std::string name)
|
uint InputDevice::toKeyCode(const std::string& name)
|
||||||
{
|
{
|
||||||
return _toEventCode(EV_KEY, std::move(name));
|
return _toEventCode(EV_KEY, name);
|
||||||
}
|
}
|
||||||
|
|
||||||
uint InputDevice::toAxisCode(std::string name)
|
uint InputDevice::toAxisCode(const std::string& name)
|
||||||
{
|
{
|
||||||
return _toEventCode(EV_REL, std::move(name));
|
return _toEventCode(EV_REL, name);
|
||||||
}
|
}
|
||||||
|
|
||||||
uint InputDevice::_toEventCode(uint type, const std::string& name)
|
uint InputDevice::_toEventCode(uint type, const std::string& name)
|
||||||
|
|
|
@ -25,22 +25,20 @@ extern "C"
|
||||||
{
|
{
|
||||||
#include <libevdev/libevdev.h>
|
#include <libevdev/libevdev.h>
|
||||||
#include <libevdev/libevdev-uinput.h>
|
#include <libevdev/libevdev-uinput.h>
|
||||||
};
|
}
|
||||||
|
|
||||||
namespace logid
|
namespace logid
|
||||||
{
|
{
|
||||||
typedef uint keycode;
|
|
||||||
|
|
||||||
class InputDevice
|
class InputDevice
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
class InvalidEventCode : public std::exception
|
class InvalidEventCode : public std::exception
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
explicit InvalidEventCode(std::string name);
|
explicit InvalidEventCode(const std::string& name);
|
||||||
const char* what() const noexcept override;
|
const char* what() const noexcept override;
|
||||||
private:
|
private:
|
||||||
std::string _what;
|
const std::string _what;
|
||||||
};
|
};
|
||||||
explicit InputDevice(const char *name);
|
explicit InputDevice(const char *name);
|
||||||
~InputDevice();
|
~InputDevice();
|
||||||
|
@ -49,15 +47,15 @@ namespace logid
|
||||||
void pressKey(uint code);
|
void pressKey(uint code);
|
||||||
void releaseKey(uint code);
|
void releaseKey(uint code);
|
||||||
|
|
||||||
static uint toKeyCode(std::string name);
|
static uint toKeyCode(const std::string& name);
|
||||||
static uint toAxisCode(std::string name);
|
static uint toAxisCode(const std::string& name);
|
||||||
private:
|
private:
|
||||||
void _sendEvent(uint type, uint code, int value);
|
void _sendEvent(uint type, uint code, int value);
|
||||||
|
|
||||||
static uint _toEventCode(uint type, const std::string& name);
|
static uint _toEventCode(uint type, const std::string& name);
|
||||||
|
|
||||||
libevdev* device;
|
libevdev* device;
|
||||||
libevdev_uinput* ui_device;
|
libevdev_uinput* ui_device{};
|
||||||
};
|
};
|
||||||
|
|
||||||
extern std::unique_ptr<InputDevice> virtual_input;
|
extern std::unique_ptr<InputDevice> virtual_input;
|
||||||
|
|
|
@ -16,7 +16,6 @@
|
||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#include <cassert>
|
|
||||||
#include "Receiver.h"
|
#include "Receiver.h"
|
||||||
#include "util/log.h"
|
#include "util/log.h"
|
||||||
#include "backend/hidpp10/Error.h"
|
#include "backend/hidpp10/Error.h"
|
||||||
|
@ -26,7 +25,8 @@
|
||||||
using namespace logid;
|
using namespace logid;
|
||||||
using namespace logid::backend;
|
using namespace logid::backend;
|
||||||
|
|
||||||
Receiver::Receiver(std::string path) : dj::ReceiverMonitor(path), _path (path)
|
Receiver::Receiver(const std::string& path) :
|
||||||
|
dj::ReceiverMonitor(path), _path (path)
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -28,7 +28,7 @@ namespace logid
|
||||||
class Receiver : public backend::dj::ReceiverMonitor
|
class Receiver : public backend::dj::ReceiverMonitor
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
Receiver(std::string path);
|
Receiver(const std::string& path);
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
void addDevice(backend::hidpp::DeviceConnectionEvent event) override;
|
void addDevice(backend::hidpp::DeviceConnectionEvent event) override;
|
||||||
|
|
|
@ -40,6 +40,11 @@ ReceiverMonitor::ReceiverMonitor(std::string path) : _receiver (
|
||||||
_receiver->enableHidppNotifications(notification_flags);
|
_receiver->enableHidppNotifications(notification_flags);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
ReceiverMonitor::~ReceiverMonitor()
|
||||||
|
{
|
||||||
|
this->stop();
|
||||||
|
}
|
||||||
|
|
||||||
void ReceiverMonitor::run()
|
void ReceiverMonitor::run()
|
||||||
{
|
{
|
||||||
_receiver->listen();
|
_receiver->listen();
|
||||||
|
|
|
@ -33,6 +33,7 @@ namespace dj
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
explicit ReceiverMonitor(std::string path);
|
explicit ReceiverMonitor(std::string path);
|
||||||
|
~ReceiverMonitor();
|
||||||
|
|
||||||
void enumerate();
|
void enumerate();
|
||||||
void run();
|
void run();
|
||||||
|
|
|
@ -16,8 +16,8 @@
|
||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#ifndef LOGID_HIDPP_DEFS_H
|
#ifndef LOGID_BACKEND_HIDPP_DEFS_H
|
||||||
#define LOGID_HIDPP_DEFS_H
|
#define LOGID_BACKEND_HIDPP_DEFS_H
|
||||||
|
|
||||||
#define LOGID_HIDPP_SOFTWARE_ID 0
|
#define LOGID_HIDPP_SOFTWARE_ID 0
|
||||||
|
|
||||||
|
@ -52,4 +52,4 @@ namespace hidpp
|
||||||
static constexpr std::size_t LongParamLength = 16;
|
static constexpr std::size_t LongParamLength = 16;
|
||||||
} } }
|
} } }
|
||||||
|
|
||||||
#endif //LOGID_HIDPP_DEFS_H
|
#endif //LOGID_BACKEND_HIDPP_DEFS_H
|
|
@ -16,8 +16,8 @@
|
||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#ifndef LOGID_HIDPP20_DEVICE_H
|
#ifndef LOGID_BACKEND_HIDPP20_DEVICE_H
|
||||||
#define LOGID_HIDPP20_DEVICE_H
|
#define LOGID_BACKEND_HIDPP20_DEVICE_H
|
||||||
|
|
||||||
#include "../hidpp/Device.h"
|
#include "../hidpp/Device.h"
|
||||||
#include <cstdint>
|
#include <cstdint>
|
||||||
|
@ -37,4 +37,4 @@ namespace hidpp20 {
|
||||||
};
|
};
|
||||||
}}}
|
}}}
|
||||||
|
|
||||||
#endif //LOGID_HIDPP20_DEVICE_H
|
#endif //LOGID_BACKEND_HIDPP20_DEVICE_H
|
|
@ -17,7 +17,6 @@
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#include <cassert>
|
#include <cassert>
|
||||||
#include <cstring>
|
|
||||||
#include "Error.h"
|
#include "Error.h"
|
||||||
|
|
||||||
using namespace logid::backend::hidpp20;
|
using namespace logid::backend::hidpp20;
|
||||||
|
|
|
@ -16,8 +16,8 @@
|
||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#ifndef LOGID_HIDPP20_ESSENTIAL_FEATURE_H
|
#ifndef LOGID_BACKEND_HIDPP20_ESSENTIAL_FEATURE_H
|
||||||
#define LOGID_HIDPP20_ESSENTIAL_FEATURE_H
|
#define LOGID_BACKEND_HIDPP20_ESSENTIAL_FEATURE_H
|
||||||
|
|
||||||
// WARNING: UNSAFE
|
// WARNING: UNSAFE
|
||||||
|
|
||||||
|
@ -47,4 +47,4 @@ namespace hidpp20
|
||||||
};
|
};
|
||||||
}}}
|
}}}
|
||||||
|
|
||||||
#endif //LOGID_HIDPP20_ESSENTIAL_FEATURE_H
|
#endif //LOGID_BACKEND_HIDPP20_ESSENTIAL_FEATURE_H
|
|
@ -16,8 +16,8 @@
|
||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#ifndef LOGID_HIDPP20_FEATURE_H
|
#ifndef LOGID_BACKEND_HIDPP20_FEATURE_H
|
||||||
#define LOGID_HIDPP20_FEATURE_H
|
#define LOGID_BACKEND_HIDPP20_FEATURE_H
|
||||||
|
|
||||||
#include <cstdint>
|
#include <cstdint>
|
||||||
#include "Device.h"
|
#include "Device.h"
|
||||||
|
@ -51,4 +51,4 @@ namespace hidpp20 {
|
||||||
};
|
};
|
||||||
}}}
|
}}}
|
||||||
|
|
||||||
#endif //LOGID_HIDPP20_FEATURE_H
|
#endif //LOGID_BACKEND_HIDPP20_FEATURE_H
|
|
@ -85,7 +85,6 @@ namespace hidpp20
|
||||||
void setMode(uint8_t mode);
|
void setMode(uint8_t mode);
|
||||||
bool getRatchetState();
|
bool getRatchetState();
|
||||||
|
|
||||||
///TODO: Event handlers
|
|
||||||
static WheelStatus wheelMovementEvent(const hidpp::Report& report);
|
static WheelStatus wheelMovementEvent(const hidpp::Report& report);
|
||||||
static RatchetState ratchetSwitchEvent(const hidpp::Report& report);
|
static RatchetState ratchetSwitchEvent(const hidpp::Report& report);
|
||||||
};
|
};
|
||||||
|
|
|
@ -44,10 +44,10 @@ DEFINE_REPROG(ReprogControlsV4, ReprogControlsV3)
|
||||||
|
|
||||||
std::shared_ptr<ReprogControls> ReprogControls::autoVersion(Device *dev)
|
std::shared_ptr<ReprogControls> ReprogControls::autoVersion(Device *dev)
|
||||||
{
|
{
|
||||||
MAKE_REPROG(ReprogControlsV4, dev);
|
MAKE_REPROG(ReprogControlsV4, dev)
|
||||||
MAKE_REPROG(ReprogControlsV3, dev);
|
MAKE_REPROG(ReprogControlsV3, dev)
|
||||||
MAKE_REPROG(ReprogControlsV2_2, dev);
|
MAKE_REPROG(ReprogControlsV2_2, dev)
|
||||||
MAKE_REPROG(ReprogControlsV2, dev);
|
MAKE_REPROG(ReprogControlsV2, dev)
|
||||||
|
|
||||||
// If base version cannot be made, throw error
|
// If base version cannot be made, throw error
|
||||||
return std::make_shared<ReprogControls>(dev);
|
return std::make_shared<ReprogControls>(dev);
|
||||||
|
|
|
@ -43,7 +43,7 @@ RemapButton::~RemapButton()
|
||||||
void RemapButton::configure()
|
void RemapButton::configure()
|
||||||
{
|
{
|
||||||
///TODO: DJ reporting trickery if cannot be remapped
|
///TODO: DJ reporting trickery if cannot be remapped
|
||||||
for(auto& i : _config.buttons()) {
|
for(const auto& i : _config.buttons()) {
|
||||||
hidpp20::ReprogControls::ControlInfo info{};
|
hidpp20::ReprogControls::ControlInfo info{};
|
||||||
try {
|
try {
|
||||||
info = _reprog_controls->getControlIdInfo(i.first);
|
info = _reprog_controls->getControlIdInfo(i.first);
|
||||||
|
@ -89,23 +89,23 @@ void RemapButton::listen()
|
||||||
report));
|
report));
|
||||||
else { // RawXY
|
else { // RawXY
|
||||||
auto divertedXY = _reprog_controls->divertedRawXYEvent(report);
|
auto divertedXY = _reprog_controls->divertedRawXYEvent(report);
|
||||||
for(auto& button : this->_config.buttons())
|
for(const auto& button : this->_config.buttons())
|
||||||
if(button.second->pressed())
|
if(button.second->pressed())
|
||||||
button.second->move(divertedXY.x, divertedXY.y);
|
button.second->move(divertedXY.x, divertedXY.y);
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
_device->hidpp20().addEventHandler(EVENTHANDLER_NAME, handler);
|
_device->hidpp20().addEventHandler(EVENTHANDLER_NAME, handler);
|
||||||
};
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void RemapButton::_buttonEvent(std::set<uint16_t> new_state)
|
void RemapButton::_buttonEvent(const std::set<uint16_t>& new_state)
|
||||||
{
|
{
|
||||||
// Ensure I/O doesn't occur while updating button state
|
// Ensure I/O doesn't occur while updating button state
|
||||||
std::lock_guard<std::mutex> lock(_button_lock);
|
std::lock_guard<std::mutex> lock(_button_lock);
|
||||||
|
|
||||||
// Press all added buttons
|
// Press all added buttons
|
||||||
for(auto& i : new_state) {
|
for(const auto& i : new_state) {
|
||||||
auto old_i = _pressed_buttons.find(i);
|
auto old_i = _pressed_buttons.find(i);
|
||||||
if(old_i != _pressed_buttons.end()) {
|
if(old_i != _pressed_buttons.end()) {
|
||||||
_pressed_buttons.erase(old_i);
|
_pressed_buttons.erase(old_i);
|
||||||
|
|
|
@ -44,7 +44,7 @@ namespace features
|
||||||
std::map<uint8_t, std::shared_ptr<actions::Action>> _buttons;
|
std::map<uint8_t, std::shared_ptr<actions::Action>> _buttons;
|
||||||
};
|
};
|
||||||
private:
|
private:
|
||||||
void _buttonEvent(std::set<uint16_t> new_state);
|
void _buttonEvent(const std::set<uint16_t>& new_state);
|
||||||
Config _config;
|
Config _config;
|
||||||
std::shared_ptr<backend::hidpp20::ReprogControls> _reprog_controls;
|
std::shared_ptr<backend::hidpp20::ReprogControls> _reprog_controls;
|
||||||
std::set<uint16_t> _pressed_buttons;
|
std::set<uint16_t> _pressed_buttons;
|
||||||
|
|
|
@ -37,7 +37,10 @@
|
||||||
|
|
||||||
using namespace logid;
|
using namespace logid;
|
||||||
|
|
||||||
std::string config_file = DEFAULT_CONFIG_FILE;
|
struct CmdlineOptions
|
||||||
|
{
|
||||||
|
std::string config_file = DEFAULT_CONFIG_FILE;
|
||||||
|
};
|
||||||
|
|
||||||
LogLevel logid::global_loglevel = INFO;
|
LogLevel logid::global_loglevel = INFO;
|
||||||
std::shared_ptr<Configuration> logid::global_config;
|
std::shared_ptr<Configuration> logid::global_config;
|
||||||
|
@ -72,7 +75,7 @@ void logid::reload()
|
||||||
}
|
}
|
||||||
*/
|
*/
|
||||||
|
|
||||||
void readCliOptions(int argc, char** argv)
|
void readCliOptions(const int argc, char** argv, CmdlineOptions& options)
|
||||||
{
|
{
|
||||||
for(int i = 1; i < argc; i++) {
|
for(int i = 1; i < argc; i++) {
|
||||||
Option option = Option::None;
|
Option option = Option::None;
|
||||||
|
@ -132,7 +135,7 @@ void readCliOptions(int argc, char** argv)
|
||||||
logPrintf(ERROR, "Config file is not specified.");
|
logPrintf(ERROR, "Config file is not specified.");
|
||||||
exit(EXIT_FAILURE);
|
exit(EXIT_FAILURE);
|
||||||
}
|
}
|
||||||
config_file = argv[i];
|
options.config_file = argv[i];
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
case Option::Help:
|
case Option::Help:
|
||||||
|
@ -157,16 +160,18 @@ Possible options are:
|
||||||
|
|
||||||
int main(int argc, char** argv)
|
int main(int argc, char** argv)
|
||||||
{
|
{
|
||||||
readCliOptions(argc, argv);
|
CmdlineOptions options{};
|
||||||
|
readCliOptions(argc, argv, options);
|
||||||
|
|
||||||
// Read config
|
// Read config
|
||||||
try {
|
try {
|
||||||
global_config = std::make_shared<Configuration>(config_file);
|
global_config = std::make_shared<Configuration>(options.config_file);
|
||||||
}
|
}
|
||||||
catch (std::exception &e) {
|
catch (std::exception &e) {
|
||||||
global_config = std::make_shared<Configuration>();
|
global_config = std::make_shared<Configuration>();
|
||||||
}
|
}
|
||||||
global_workqueue = std::make_shared<workqueue>(global_config->workerCount());
|
global_workqueue = std::make_shared<workqueue>(
|
||||||
|
global_config->workerCount());
|
||||||
|
|
||||||
//Create a virtual input device
|
//Create a virtual input device
|
||||||
try {
|
try {
|
||||||
|
|
|
@ -45,8 +45,8 @@ void thread::spawn(const std::function<void()>& function,
|
||||||
|
|
||||||
void thread::run()
|
void thread::run()
|
||||||
{
|
{
|
||||||
_thread = std::make_shared<std::thread>([f=this->_function,
|
_thread = std::make_shared<std::thread>(
|
||||||
eh=this->_exception_handler]() {
|
[f=this->_function,eh=this->_exception_handler]() {
|
||||||
try {
|
try {
|
||||||
(*f)();
|
(*f)();
|
||||||
} catch (std::exception& e) {
|
} catch (std::exception& e) {
|
||||||
|
|
|
@ -28,7 +28,7 @@ workqueue::workqueue(std::size_t thread_count) : _manager_thread (
|
||||||
)), _continue_run (false), _worker_count (thread_count)
|
)), _continue_run (false), _worker_count (thread_count)
|
||||||
{
|
{
|
||||||
_workers.reserve(_worker_count);
|
_workers.reserve(_worker_count);
|
||||||
for(std::size_t i = 0; i < thread_count; i++)
|
for(std::size_t i = 0; i < _worker_count; i++)
|
||||||
_workers.push_back(std::make_unique<worker_thread>(this, i));
|
_workers.push_back(std::make_unique<worker_thread>(this, i));
|
||||||
_manager_thread->run();
|
_manager_thread->run();
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue
Block a user