parent
a914526949
commit
e47e439954
@ -39,9 +39,9 @@ namespace sig_ev = signals::eventqueue;
|
|||||||
namespace sig_ui = signals::ui;
|
namespace sig_ui = signals::ui;
|
||||||
namespace sig_ipc = signals::ipc;
|
namespace sig_ipc = signals::ipc;
|
||||||
|
|
||||||
class controller : public signal_receiver<SIGN_PRIORITY_CONTROLLER, sig_ev::process_update, sig_ev::process_input,
|
class controller : public signal_receiver<SIGN_PRIORITY_CONTROLLER, sig_ev::process_broadcast, sig_ev::process_update,
|
||||||
sig_ev::process_quit, sig_ev::process_check, sig_ipc::process_action, sig_ipc::process_command,
|
sig_ev::process_input, sig_ev::process_quit, sig_ev::process_check, sig_ipc::process_action,
|
||||||
sig_ipc::process_hook, sig_ui::button_press> {
|
sig_ipc::process_command, sig_ipc::process_hook, sig_ui::button_press> {
|
||||||
public:
|
public:
|
||||||
using make_type = unique_ptr<controller>;
|
using make_type = unique_ptr<controller>;
|
||||||
static make_type make(unique_ptr<ipc>&& ipc, unique_ptr<inotify_watch>&& config_watch);
|
static make_type make(unique_ptr<ipc>&& ipc, unique_ptr<inotify_watch>&& config_watch);
|
||||||
@ -60,6 +60,7 @@ class controller : public signal_receiver<SIGN_PRIORITY_CONTROLLER, sig_ev::proc
|
|||||||
void process_eventqueue();
|
void process_eventqueue();
|
||||||
void process_inputdata();
|
void process_inputdata();
|
||||||
|
|
||||||
|
bool on(const sig_ev::process_broadcast& evt);
|
||||||
bool on(const sig_ev::process_update& evt);
|
bool on(const sig_ev::process_update& evt);
|
||||||
bool on(const sig_ev::process_input& evt);
|
bool on(const sig_ev::process_input& evt);
|
||||||
bool on(const sig_ev::process_quit& evt);
|
bool on(const sig_ev::process_quit& evt);
|
||||||
|
@ -96,6 +96,7 @@ namespace signals {
|
|||||||
DEFINE_VALUE_SIGNAL(2, process_update, event);
|
DEFINE_VALUE_SIGNAL(2, process_update, event);
|
||||||
DEFINE_VALUE_SIGNAL(3, process_input, string);
|
DEFINE_VALUE_SIGNAL(3, process_input, string);
|
||||||
DEFINE_SIGNAL(4, process_check);
|
DEFINE_SIGNAL(4, process_check);
|
||||||
|
DEFINE_SIGNAL(5, process_broadcast);
|
||||||
}
|
}
|
||||||
|
|
||||||
namespace ipc {
|
namespace ipc {
|
||||||
|
@ -10,6 +10,7 @@ namespace signals {
|
|||||||
struct process_update;
|
struct process_update;
|
||||||
struct process_input;
|
struct process_input;
|
||||||
struct process_check;
|
struct process_check;
|
||||||
|
struct process_broadcast;
|
||||||
}
|
}
|
||||||
namespace ipc {
|
namespace ipc {
|
||||||
struct process_command;
|
struct process_command;
|
||||||
|
@ -3,12 +3,10 @@
|
|||||||
#include <algorithm>
|
#include <algorithm>
|
||||||
#include <chrono>
|
#include <chrono>
|
||||||
#include <condition_variable>
|
#include <condition_variable>
|
||||||
#include <mutex>
|
|
||||||
#include <map>
|
#include <map>
|
||||||
|
#include <mutex>
|
||||||
|
|
||||||
#include "common.hpp"
|
#include "common.hpp"
|
||||||
#include "components/config.hpp"
|
|
||||||
#include "components/logger.hpp"
|
|
||||||
#include "components/types.hpp"
|
#include "components/types.hpp"
|
||||||
#include "errors.hpp"
|
#include "errors.hpp"
|
||||||
#include "utils/concurrency.hpp"
|
#include "utils/concurrency.hpp"
|
||||||
@ -46,6 +44,9 @@ namespace drawtypes {
|
|||||||
}
|
}
|
||||||
|
|
||||||
class builder;
|
class builder;
|
||||||
|
class config;
|
||||||
|
class logger;
|
||||||
|
class signal_emitter;
|
||||||
|
|
||||||
// }}}
|
// }}}
|
||||||
|
|
||||||
@ -108,9 +109,6 @@ namespace modules {
|
|||||||
virtual void stop() = 0;
|
virtual void stop() = 0;
|
||||||
virtual void halt(string error_message) = 0;
|
virtual void halt(string error_message) = 0;
|
||||||
virtual string contents() = 0;
|
virtual string contents() = 0;
|
||||||
|
|
||||||
virtual void set_update_cb(callback<>&& cb) = 0;
|
|
||||||
virtual void set_stop_cb(callback<>&& cb) = 0;
|
|
||||||
};
|
};
|
||||||
|
|
||||||
// }}}
|
// }}}
|
||||||
@ -141,9 +139,7 @@ namespace modules {
|
|||||||
string get_output();
|
string get_output();
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
callback<> m_update_callback;
|
signal_emitter& m_sig;
|
||||||
callback<> m_stop_callback;
|
|
||||||
|
|
||||||
const bar_settings m_bar;
|
const bar_settings m_bar;
|
||||||
const logger& m_log;
|
const logger& m_log;
|
||||||
const config& m_conf;
|
const config& m_conf;
|
||||||
|
@ -1,15 +1,20 @@
|
|||||||
#include "components/builder.hpp"
|
#include "components/builder.hpp"
|
||||||
#include "components/logger.hpp"
|
#include "components/logger.hpp"
|
||||||
#include "components/config.hpp"
|
#include "components/config.hpp"
|
||||||
|
#include "events/signal.hpp"
|
||||||
|
#include "events/signal_emitter.hpp"
|
||||||
|
|
||||||
POLYBAR_NS
|
POLYBAR_NS
|
||||||
|
|
||||||
|
namespace sig_ev = signals::eventqueue;
|
||||||
|
|
||||||
namespace modules {
|
namespace modules {
|
||||||
// module<Impl> public {{{
|
// module<Impl> public {{{
|
||||||
|
|
||||||
template <typename Impl>
|
template <typename Impl>
|
||||||
module<Impl>::module(const bar_settings bar, string name)
|
module<Impl>::module(const bar_settings bar, string name)
|
||||||
: m_bar(bar)
|
: m_sig(signal_emitter::make())
|
||||||
|
, m_bar(bar)
|
||||||
, m_log(logger::make())
|
, m_log(logger::make())
|
||||||
, m_conf(config::make())
|
, m_conf(config::make())
|
||||||
, m_name("module/" + name)
|
, m_name("module/" + name)
|
||||||
@ -30,16 +35,6 @@ namespace modules {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
template <typename Impl>
|
|
||||||
void module<Impl>::set_update_cb(callback<>&& cb) {
|
|
||||||
m_update_callback = forward<decltype(cb)>(cb);
|
|
||||||
}
|
|
||||||
|
|
||||||
template <typename Impl>
|
|
||||||
void module<Impl>::set_stop_cb(callback<>&& cb) {
|
|
||||||
m_stop_callback = forward<decltype(cb)>(cb);
|
|
||||||
}
|
|
||||||
|
|
||||||
template <typename Impl>
|
template <typename Impl>
|
||||||
string module<Impl>::name() const {
|
string module<Impl>::name() const {
|
||||||
return m_name;
|
return m_name;
|
||||||
@ -66,9 +61,7 @@ namespace modules {
|
|||||||
CAST_MOD(Impl)->wakeup();
|
CAST_MOD(Impl)->wakeup();
|
||||||
CAST_MOD(Impl)->teardown();
|
CAST_MOD(Impl)->teardown();
|
||||||
|
|
||||||
if (m_stop_callback) {
|
m_sig.emit(sig_ev::process_check{});
|
||||||
m_stop_callback();
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -97,11 +90,7 @@ namespace modules {
|
|||||||
}
|
}
|
||||||
|
|
||||||
m_cache = CAST_MOD(Impl)->get_output();
|
m_cache = CAST_MOD(Impl)->get_output();
|
||||||
|
m_sig.emit(sig_ev::process_broadcast{});
|
||||||
if (m_update_callback)
|
|
||||||
m_update_callback();
|
|
||||||
else
|
|
||||||
m_log.info("%s: No handler, ignoring broadcast...", name());
|
|
||||||
}
|
}
|
||||||
|
|
||||||
template <typename Impl>
|
template <typename Impl>
|
||||||
|
@ -162,8 +162,6 @@ bool controller::run(bool writeback) {
|
|||||||
try {
|
try {
|
||||||
m_log.info("Starting %s", module->name());
|
m_log.info("Starting %s", module->name());
|
||||||
module->start();
|
module->start();
|
||||||
module->set_update_cb([&] { enqueue(make_update_evt(false)); });
|
|
||||||
module->set_stop_cb([&] { enqueue(make_check_evt()); });
|
|
||||||
started_modules++;
|
started_modules++;
|
||||||
} catch (const application_error& err) {
|
} catch (const application_error& err) {
|
||||||
m_log.err("Failed to start '%s' (reason: %s)", module->name(), err.what());
|
m_log.err("Failed to start '%s' (reason: %s)", module->name(), err.what());
|
||||||
@ -352,16 +350,20 @@ void controller::process_inputdata() {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Process broadcast events
|
||||||
|
*/
|
||||||
|
bool controller::on(const sig_ev::process_broadcast&) {
|
||||||
|
enqueue(make_update_evt(false));
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Process eventqueue update event
|
* Process eventqueue update event
|
||||||
*/
|
*/
|
||||||
bool controller::on(const sig_ev::process_update& evt) {
|
bool controller::on(const sig_ev::process_update& evt) {
|
||||||
bool force{evt.data()->flag};
|
bool force{evt.data()->flag};
|
||||||
|
|
||||||
if (!m_bar) {
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
const bar_settings& bar{m_bar->settings()};
|
const bar_settings& bar{m_bar->settings()};
|
||||||
string contents;
|
string contents;
|
||||||
string separator{bar.separator};
|
string separator{bar.separator};
|
||||||
|
Loading…
Reference in New Issue
Block a user