#pragma once #include "common.hpp" #include "components/logger.hpp" 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. * * A unique messaging channel will be setup for each * running process which will allow messages and * events to be sent to the process externally. */ class ipc { public: explicit ipc(const logger& logger) : m_log(logger) {} ~ipc(); void attach_callback(callback&& cb); void attach_callback(callback&& cb); void receive_messages(); protected: 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> m_command_callbacks; vector> m_hook_callbacks; stateflag m_running{false}; string m_fifo; int m_fd; }; namespace { /** * Configure injection module */ template > di::injector configure_ipc() { return di::make_injector(configure_logger()); } } LEMONBUDDY_NS_END