refactor(ipc): Rename signals

This commit is contained in:
Michael Carlberg 2016-12-26 10:36:14 +01:00
parent 334c454eec
commit baaba4adf9
7 changed files with 30 additions and 34 deletions

View File

@ -43,8 +43,8 @@ namespace sig_ui = signals::ui;
namespace sig_ipc = signals::ipc;
class controller : public signal_receiver<SIGN_PRIORITY_CONTROLLER, sig_ev::exit_terminate, sig_ev::exit_reload,
sig_ev::update, sig_ev::notify_change, sig_ev::check_state, sig_ipc::process_action,
sig_ipc::process_command, sig_ipc::process_hook, sig_ui::button_press> {
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<controller>;
static make_type make(unique_ptr<ipc>&& ipc, unique_ptr<inotify_watch>&& config_watch);
@ -69,9 +69,9 @@ class controller : public signal_receiver<SIGN_PRIORITY_CONTROLLER, sig_ev::exit
bool on(const sig_ev::exit_reload& evt);
bool on(const sig_ev::check_state& evt);
bool on(const sig_ui::button_press& evt);
bool on(const sig_ipc::process_action& evt);
bool on(const sig_ipc::process_command& evt);
bool on(const sig_ipc::process_hook& evt);
bool on(const sig_ipc::action& evt);
bool on(const sig_ipc::command& evt);
bool on(const sig_ipc::hook& evt);
private:
connection& m_connection;

View File

@ -100,9 +100,9 @@ namespace signals {
}
namespace ipc {
DEFINE_VALUE_SIGNAL(20, process_command, ipc_command);
DEFINE_VALUE_SIGNAL(21, process_hook, ipc_hook);
DEFINE_VALUE_SIGNAL(22, process_action, ipc_action);
DEFINE_VALUE_SIGNAL(20, command, string);
DEFINE_VALUE_SIGNAL(21, hook, string);
DEFINE_VALUE_SIGNAL(22, action, string);
}
namespace ui {

View File

@ -4,6 +4,9 @@
POLYBAR_NS
template <uint8_t Priority, typename Signal, typename... Signals>
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;

View File

@ -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 = "<output>";

View File

@ -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) {

View File

@ -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);
}

View File

@ -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;
}