2016-11-20 17:04:31 -05:00
|
|
|
#pragma once
|
|
|
|
|
|
|
|
#include "modules/meta/base.hpp"
|
|
|
|
|
|
|
|
POLYBAR_NS
|
|
|
|
|
|
|
|
namespace modules {
|
|
|
|
template <class Impl>
|
|
|
|
class event_module : public module<Impl> {
|
|
|
|
public:
|
|
|
|
using module<Impl>::module;
|
|
|
|
|
2016-12-21 03:21:35 -05:00
|
|
|
void start() {
|
|
|
|
this->m_mainthread = thread(&event_module::runner, this);
|
|
|
|
}
|
2016-11-20 17:04:31 -05:00
|
|
|
|
|
|
|
protected:
|
2016-12-21 03:21:35 -05:00
|
|
|
void runner() {
|
2017-01-27 07:29:10 -05:00
|
|
|
this->m_log.trace("%s: Thread id = %i", this->name(), concurrency_util::thread_id(this_thread::get_id()));
|
2016-12-21 03:21:35 -05:00
|
|
|
try {
|
2017-01-27 07:29:10 -05:00
|
|
|
// warm up module output before entering the loop
|
|
|
|
std::unique_lock<std::mutex> guard(this->m_updatelock);
|
|
|
|
CAST_MOD(Impl)->update();
|
|
|
|
CAST_MOD(Impl)->broadcast();
|
|
|
|
guard.unlock();
|
2016-12-21 03:21:35 -05:00
|
|
|
|
2017-01-27 07:29:10 -05:00
|
|
|
const auto check = [&]() -> bool {
|
2016-12-21 03:21:35 -05:00
|
|
|
std::lock_guard<std::mutex> guard(this->m_updatelock);
|
2017-01-27 07:29:10 -05:00
|
|
|
return CAST_MOD(Impl)->has_event() && CAST_MOD(Impl)->update();
|
|
|
|
};
|
2016-12-21 03:21:35 -05:00
|
|
|
|
2017-01-27 07:29:10 -05:00
|
|
|
while (this->running()) {
|
|
|
|
if (check()) {
|
|
|
|
CAST_MOD(Impl)->broadcast();
|
2016-12-21 03:21:35 -05:00
|
|
|
}
|
2017-01-27 07:29:10 -05:00
|
|
|
CAST_MOD(Impl)->idle();
|
2016-12-21 03:21:35 -05:00
|
|
|
}
|
|
|
|
} catch (const exception& err) {
|
|
|
|
CAST_MOD(Impl)->halt(err.what());
|
|
|
|
}
|
|
|
|
}
|
2016-11-20 17:04:31 -05:00
|
|
|
};
|
|
|
|
}
|
|
|
|
|
|
|
|
POLYBAR_NS_END
|