feat(ipc): New ipc module

Add a new module that allow users to configure hooks
on received ipc messages. The hook will execute the defined
shell script and the output of the script will be used
as the module content.

Ref 
This commit is contained in:
Michael Carlberg 2016-11-14 09:21:18 +01:00
parent 04fac96d78
commit e3065d0e6c
7 changed files with 230 additions and 36 deletions
include/components

View file

@ -17,13 +17,12 @@ LEMONBUDDY_NS
class controller {
public:
explicit controller(connection& conn, const logger& logger, const config& config, unique_ptr<eventloop> eventloop,
unique_ptr<bar> bar, unique_ptr<ipc> ipc, inotify_util::watch_t& confwatch)
unique_ptr<bar> bar, inotify_util::watch_t& confwatch)
: m_connection(conn)
, m_log(logger)
, m_conf(config)
, m_eventloop(forward<decltype(eventloop)>(eventloop))
, m_bar(forward<decltype(bar)>(bar))
, m_ipc(forward<decltype(ipc)>(ipc))
, m_confwatch(confwatch) {}
~controller();
@ -85,8 +84,7 @@ namespace {
configure_logger(),
configure_config(),
configure_eventloop(),
configure_bar(),
configure_ipc());
configure_bar());
// clang-format on
}
}

View file

@ -5,6 +5,18 @@
LEMONBUDDY_NS
/**
* Message types
*/
struct ipc_command {
static constexpr auto prefix{"cmd:"};
string payload;
};
struct ipc_hook {
static constexpr auto prefix{"hook:"};
string payload;
};
/**
* Component used for inter-process communication.
*
@ -14,27 +26,24 @@ LEMONBUDDY_NS
*/
class ipc {
public:
struct message_internal {
static constexpr auto prefix{"app:"};
};
struct message_command {
static constexpr auto prefix{"cmd:"};
};
struct message_custom {
static constexpr auto prefix{"custom:"};
};
explicit ipc(const logger& logger) : m_log(logger) {}
~ipc();
void attach_callback(callback<const ipc_command&>&& cb);
void attach_callback(callback<const ipc_hook&>&& cb);
void receive_messages();
protected:
void parse(string payload);
void parse(const string& payload) const;
void delegate(const ipc_command& msg) const;
void delegate(const ipc_hook& msg) const;
private:
const logger& m_log;
vector<callback<const ipc_command&>> m_command_callbacks;
vector<callback<const ipc_hook&>> m_hook_callbacks;
stateflag m_running{false};
string m_fifo;