From baaba4adf99fa552704aa4d278f10ab54883a390 Mon Sep 17 00:00:00 2001 From: Michael Carlberg Date: Mon, 26 Dec 2016 10:36:14 +0100 Subject: [PATCH] refactor(ipc): Rename signals --- include/components/controller.hpp | 10 +++++----- include/events/signal.hpp | 6 +++--- include/events/signal_fwd.hpp | 9 ++++++--- include/modules/ipc.hpp | 2 +- src/components/controller.cpp | 19 +++++++++---------- src/components/ipc.cpp | 14 ++++---------- src/modules/ipc.cpp | 4 ++-- 7 files changed, 30 insertions(+), 34 deletions(-) diff --git a/include/components/controller.hpp b/include/components/controller.hpp index fd3d54a6..7af3f14d 100644 --- a/include/components/controller.hpp +++ b/include/components/controller.hpp @@ -43,8 +43,8 @@ namespace sig_ui = signals::ui; namespace sig_ipc = signals::ipc; class controller : public signal_receiver { + sig_ev::update, sig_ev::notify_change, sig_ev::check_state, sig_ipc::action, sig_ipc::command, + sig_ipc::hook, sig_ui::button_press> { public: using make_type = unique_ptr; static make_type make(unique_ptr&& ipc, unique_ptr&& config_watch); @@ -69,9 +69,9 @@ class controller : public signal_receiver +class signal_receiver; + namespace signals { namespace eventqueue { struct exit_terminate; @@ -13,9 +16,9 @@ namespace signals { struct update; } namespace ipc { - struct process_command; - struct process_hook; - struct process_action; + struct command; + struct hook; + struct action; } namespace ui { struct tick; diff --git a/include/modules/ipc.hpp b/include/modules/ipc.hpp index ca463430..35454997 100644 --- a/include/modules/ipc.hpp +++ b/include/modules/ipc.hpp @@ -31,7 +31,7 @@ namespace modules { void update() {} string get_output(); bool build(builder* builder, const string& tag) const; - void on_message(const ipc_hook& message); + void on_message(const string& message); private: static constexpr auto TAG_OUTPUT = ""; diff --git a/src/components/controller.cpp b/src/components/controller.cpp index f89ff589..0c00419b 100644 --- a/src/components/controller.cpp +++ b/src/components/controller.cpp @@ -9,18 +9,19 @@ #include "components/types.hpp" #include "events/signal.hpp" #include "events/signal_emitter.hpp" +#include "events/signal_receiver.hpp" #include "modules/meta/event_handler.hpp" #include "modules/meta/factory.hpp" #include "utils/command.hpp" #include "utils/factory.hpp" #include "utils/inotify.hpp" -#include "utils/process.hpp" #include "utils/string.hpp" #include "utils/time.hpp" #include "x11/connection.hpp" +#include "x11/events.hpp" #include "x11/extensions/all.hpp" #include "x11/tray_manager.hpp" -#include "x11/xutils.hpp" +#include "x11/types.hpp" POLYBAR_NS @@ -543,9 +544,8 @@ bool controller::on(const sig_ui::button_press& evt) { /** * Process ipc action messages */ -bool controller::on(const sig_ipc::process_action& evt) { - string action{(*evt()).payload}; - action.erase(0, strlen(ipc_action::prefix)); +bool controller::on(const sig_ipc::action& evt) { + string action{*evt()}; if (action.empty()) { m_log.err("Cannot enqueue empty ipc action"); @@ -560,9 +560,8 @@ bool controller::on(const sig_ipc::process_action& evt) { /** * Process ipc command messages */ -bool controller::on(const sig_ipc::process_command& evt) { - string command{(*evt()).payload}; - command.erase(0, strlen(ipc_command::prefix)); +bool controller::on(const sig_ipc::command& evt) { + string command{*evt()}; if (command.empty()) { return false; @@ -582,8 +581,8 @@ bool controller::on(const sig_ipc::process_command& evt) { /** * Process ipc hook messages */ -bool controller::on(const sig_ipc::process_hook& evt) { - const ipc_hook hook{*evt()}; +bool controller::on(const sig_ipc::hook& evt) { + string hook{*evt()}; for (const auto& block : m_modules) { for (const auto& module : block.second) { diff --git a/src/components/ipc.cpp b/src/components/ipc.cpp index f2061c61..506bfb23 100644 --- a/src/components/ipc.cpp +++ b/src/components/ipc.cpp @@ -13,7 +13,7 @@ POLYBAR_NS -using namespace signals::ipc; +namespace sig_ipc = signals::ipc; /** * Create instance @@ -68,17 +68,11 @@ void ipc::receive_message() { string payload{string_util::trim(string{buffer}, '\n')}; if (payload.find(ipc_command::prefix) == 0) { - ipc_command msg{}; - memcpy(msg.payload, &payload[0], payload.size()); - m_sig.emit(process_command{move(msg)}); + m_sig.emit(sig_ipc::command{payload.substr(strlen(ipc_command::prefix))}); } else if (payload.find(ipc_hook::prefix) == 0) { - ipc_hook msg{}; - memcpy(msg.payload, &payload[0], payload.size()); - m_sig.emit(process_hook{move(msg)}); + m_sig.emit(sig_ipc::hook{payload.substr(strlen(ipc_hook::prefix))}); } else if (payload.find(ipc_action::prefix) == 0) { - ipc_action msg{}; - memcpy(msg.payload, &payload[0], payload.size()); - m_sig.emit(process_action{move(msg)}); + m_sig.emit(sig_ipc::action{payload.substr(strlen(ipc_action::prefix))}); } else if (!payload.empty()) { m_log.warn("Received unknown ipc message: (payload=%s)", payload); } diff --git a/src/modules/ipc.cpp b/src/modules/ipc.cpp index c886e45e..bf555524 100644 --- a/src/modules/ipc.cpp +++ b/src/modules/ipc.cpp @@ -80,11 +80,11 @@ namespace modules { * configured from the user config and * execute its command */ - void ipc_module::on_message(const ipc_hook& message) { + void ipc_module::on_message(const string& message) { bool match = false; for (auto&& hook : m_hooks) { - if (ipc_hook::prefix + hook->payload != message.payload) { + if (hook->payload != message) { continue; }