Use action interface names as static vars

This commit is contained in:
pixl 2022-01-28 20:50:16 -05:00
parent f25a1e4657
commit 3808f0a6cf
No known key found for this signature in database
GPG Key ID: 1866C148CD593B6E
20 changed files with 54 additions and 12 deletions

@ -1 +1 @@
Subproject commit 22559236d8c6e30aac640f79b8d4983467ba5cc8
Subproject commit e86f1987bc40c840d3cef758619783e5bdec1c41

View File

@ -52,25 +52,25 @@ std::shared_ptr<Action> _makeAction(
Device *device, const std::string &name,
std::optional<T>& config)
{
if(name == "pizza.pixl.LogiOps.Action.ChangeDPI") {
if(name == ChangeDPI::interface_name) {
config = config::ChangeDPI();
return Action::makeAction(device, config.value());
} else if(name == "pizza.pixl.LogiOps.Action.ChangeHost") {
} else if(name == ChangeHostAction::interface_name) {
config = config::ChangeHost();
return Action::makeAction(device, config.value());
} else if(name == "pizza.pixl.LogiOps.Action.CycleDPI") {
} else if(name == CycleDPI::interface_name) {
config = config::CycleDPI();
return Action::makeAction(device, config.value());
} else if(name == "pizza.pixl.LogiOps.Action.Keypress") {
} else if(name == KeypressAction::interface_name) {
config = config::KeypressAction();
return Action::makeAction(device, config.value());
} else if(name == "pizza.pixl.LogiOps.Action.None") {
} else if(name == NullAction::interface_name) {
config = config::NoAction();
return Action::makeAction(device, config.value());
} else if(name == "pizza.pixl.LogiOps.Action.ToggleHiresScroll") {
} else if(name == ToggleHiresScroll::interface_name) {
config = config::ToggleHiresScroll();
return Action::makeAction(device, config.value());
} else if(name == "pizza.pixl.LogiOps.Action.ToggleSmartShift") {
} else if(name == ToggleSmartShift::interface_name) {
config = config::ToggleHiresScroll();
return Action::makeAction(device, config.value());
} else if(name == "pizza.pixl.LogiOps.Action.Default") {
@ -94,7 +94,7 @@ std::shared_ptr<Action> Action::makeAction(
try {
return _makeAction(device, name, config);
} catch(actions::InvalidAction& e) {
if(name == "pizza.pixl.LogiOps.Action.Gesture") {
if(name == GestureAction::interface_name) {
config = config::GestureAction();
return makeAction(device, config.value());
}

View File

@ -24,6 +24,9 @@
using namespace logid::actions;
const char* ChangeDPI::interface_name =
"pizza.pixl.LogiOps.Action.ChangeDPI";
ChangeDPI::ChangeDPI(Device *device, config::ChangeDPI& config) :
Action(device), _config (config)
{

View File

@ -27,6 +27,8 @@ namespace logid {
class ChangeDPI : public Action
{
public:
static const char* interface_name;
explicit ChangeDPI(Device* device, config::ChangeDPI& setting);
virtual void press();

View File

@ -24,6 +24,9 @@
using namespace logid::actions;
using namespace logid::backend;
const char* ChangeHostAction::interface_name =
"pizza.pixl.LogiOps.Action.ChangeHost";
ChangeHostAction::ChangeHostAction(Device *device, config::ChangeHost& config)
: Action(device), _config (config)
{

View File

@ -28,6 +28,8 @@ namespace actions
class ChangeHostAction : public Action
{
public:
static const char* interface_name;
ChangeHostAction(Device* device, config::ChangeHost& config);
virtual void press();

View File

@ -25,6 +25,9 @@
using namespace logid::actions;
using namespace libconfig;
const char* CycleDPI::interface_name =
"pizza.pixl.LogiOps.Action.CycleDPI";
CycleDPI::CycleDPI(Device* device, config::CycleDPI& config) :
Action (device), _config (config), _current_dpi (_config.dpis.begin())
{

View File

@ -27,6 +27,8 @@ namespace actions {
class CycleDPI : public Action
{
public:
static const char* interface_name;
explicit CycleDPI(Device* device, config::CycleDPI& setting);
virtual void press();

View File

@ -24,6 +24,9 @@ using namespace logid::actions;
using namespace logid;
using namespace logid::backend;
const char* GestureAction::interface_name =
"pizza.pixl.LogiOps.Action.Gesture";
GestureAction::Direction GestureAction::toDirection(std::string direction)
{
std::transform(direction.begin(), direction.end(), direction.begin(),

View File

@ -28,6 +28,8 @@ namespace actions {
class GestureAction : public Action
{
public:
static const char* interface_name;
enum Direction
{
None,

View File

@ -24,6 +24,9 @@
using namespace logid::actions;
using namespace logid::backend;
const char* KeypressAction::interface_name =
"pizza.pixl.LogiOps.Action.Keypress";
KeypressAction::KeypressAction(Device *device, config::KeypressAction& config) :
Action(device), _config (config)
{

View File

@ -27,6 +27,8 @@ namespace actions {
class KeypressAction : public Action
{
public:
static const char* interface_name;
KeypressAction(Device* dev, config::KeypressAction& config);
virtual void press();

View File

@ -21,6 +21,9 @@
using namespace logid::actions;
const char* NullAction::interface_name =
"pizza.pixl.LogiOps.Action.None";
NullAction::NullAction(Device* device) : Action(device)
{
}

View File

@ -26,6 +26,8 @@ namespace actions
class NullAction : public Action
{
public:
static const char* interface_name;
explicit NullAction(Device* device);
NullAction(Device* device, [[maybe_unused]] config::NoAction& config) :
NullAction(device) { }

View File

@ -23,6 +23,9 @@
using namespace logid::actions;
using namespace logid::backend;
const char* ToggleHiresScroll::interface_name =
"pizza.pixl.LogiOps.Action.ToggleHiresScroll";
ToggleHiresScroll::ToggleHiresScroll(Device *dev) : Action (dev)
{
_hires_scroll = _device->getFeature<features::HiresScroll>("hiresscroll");

View File

@ -27,6 +27,8 @@ namespace actions
class ToggleHiresScroll : public Action
{
public:
static const char* interface_name;
explicit ToggleHiresScroll(Device* dev);
ToggleHiresScroll(Device* device,
[[maybe_unused]] config::ToggleHiresScroll& action) :

View File

@ -23,6 +23,9 @@
using namespace logid::actions;
using namespace logid::backend;
const char* ToggleSmartShift::interface_name =
"pizza.pixl.LogiOps.Action.ToggleSmartShift";
ToggleSmartShift::ToggleSmartShift(Device *dev) : Action (dev)
{
_smartshift = _device->getFeature<features::SmartShift>("smartshift");

View File

@ -27,6 +27,8 @@ namespace actions {
class ToggleSmartShift : public Action
{
public:
static const char* interface_name;
explicit ToggleSmartShift(Device* dev);
ToggleSmartShift(Device* device,
[[maybe_unused]] config::ToggleSmartShift& action) :

View File

@ -66,9 +66,9 @@ IOMonitor::IOMonitor() : _epoll_fd (epoll_create1(0)),
throw std::runtime_error("eventfd error");
}));
std::thread([this](){
_io_thread = std::make_unique<std::thread>([this](){
_listen();
}).detach();
});
}
IOMonitor::~IOMonitor() noexcept
@ -124,7 +124,7 @@ void IOMonitor::_stop() noexcept
_interrupt();
_is_running = false;
_continue();
std::lock_guard<std::mutex> run_lock(_run_lock);
_io_thread->join();
}
bool IOMonitor::_running() const

View File

@ -52,6 +52,8 @@ namespace logid::backend::raw {
void _interrupt() noexcept;
void _continue() noexcept;
std::unique_ptr<std::thread> _io_thread;
std::map<int, IOHandler> _fds;
std::mutex _io_lock, _ctl_lock;
mutable std::mutex _run_lock;