2016-11-13 18:05:30 +00:00
|
|
|
#pragma once
|
|
|
|
|
|
|
|
#include "common.hpp"
|
|
|
|
#include "components/logger.hpp"
|
2016-12-05 19:41:00 +00:00
|
|
|
#include "events/signal_emitter.hpp"
|
2016-11-20 22:04:31 +00:00
|
|
|
#include "utils/concurrency.hpp"
|
2016-11-25 07:42:31 +00:00
|
|
|
#include "utils/functional.hpp"
|
2016-11-13 18:05:30 +00:00
|
|
|
|
2016-11-19 05:22:44 +00:00
|
|
|
POLYBAR_NS
|
2016-11-13 18:05:30 +00:00
|
|
|
|
2016-11-14 08:21:18 +00:00
|
|
|
/**
|
|
|
|
* Message types
|
|
|
|
*/
|
|
|
|
struct ipc_command {
|
2016-11-20 22:29:42 +00:00
|
|
|
static constexpr const char* prefix{"cmd:"};
|
2016-12-05 19:41:00 +00:00
|
|
|
char payload[EVENT_SIZE]{'\0'};
|
2016-11-14 08:21:18 +00:00
|
|
|
};
|
|
|
|
struct ipc_hook {
|
2016-11-20 22:29:42 +00:00
|
|
|
static constexpr const char* prefix{"hook:"};
|
2016-12-05 19:41:00 +00:00
|
|
|
char payload[EVENT_SIZE]{'\0'};
|
2016-11-14 08:21:18 +00:00
|
|
|
};
|
2016-11-18 17:37:52 +00:00
|
|
|
struct ipc_action {
|
2016-11-20 22:29:42 +00:00
|
|
|
static constexpr const char* prefix{"action:"};
|
2016-12-05 19:41:00 +00:00
|
|
|
char payload[EVENT_SIZE]{'\0'};
|
2016-11-18 17:37:52 +00:00
|
|
|
};
|
2016-11-14 08:21:18 +00:00
|
|
|
|
2016-11-13 18:05:30 +00:00
|
|
|
/**
|
|
|
|
* 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:
|
2016-12-09 08:40:46 +00:00
|
|
|
using make_type = unique_ptr<ipc>;
|
|
|
|
static make_type make();
|
2016-12-09 08:02:47 +00:00
|
|
|
|
2016-12-05 19:41:00 +00:00
|
|
|
explicit ipc(signal_emitter& emitter, const logger& logger) : m_sig(emitter), m_log(logger) {}
|
2016-11-13 18:05:30 +00:00
|
|
|
~ipc();
|
|
|
|
|
|
|
|
void receive_messages();
|
|
|
|
|
|
|
|
protected:
|
2016-11-14 08:21:18 +00:00
|
|
|
void parse(const string& payload) const;
|
2016-11-13 18:05:30 +00:00
|
|
|
|
|
|
|
private:
|
2016-12-05 19:41:00 +00:00
|
|
|
signal_emitter& m_sig;
|
2016-11-13 18:05:30 +00:00
|
|
|
const logger& m_log;
|
|
|
|
string m_fifo;
|
|
|
|
int m_fd;
|
2016-12-05 19:41:00 +00:00
|
|
|
stateflag m_running{false};
|
2016-11-13 18:05:30 +00:00
|
|
|
};
|
|
|
|
|
2016-11-19 05:22:44 +00:00
|
|
|
POLYBAR_NS_END
|