polybar-dwm/include/modules/meta/event_module.hpp
Patrick Ziegler d5be8cad97
Add compiler warning for missing override specifier (#2341)
* build: Add -Wsuggest-override

We should always use the override specifier when overriding virtual
functions. This helps prevent errors when a subclass tries to create a
function with the same name as a virtual function in a super-class but
with a different purpose.

* clang-format

* Upload logs on failure

* Add override to unsupported.hpp

* cmake: Make -Wsuggest-override flag conditional
2021-01-04 10:38:43 +01:00

46 lines
1.1 KiB
C++

#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;
void start() override {
this->m_mainthread = thread(&event_module::runner, this);
}
protected:
void runner() {
this->m_log.trace("%s: Thread id = %i", this->name(), concurrency_util::thread_id(this_thread::get_id()));
try {
// 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();
const auto check = [&]() -> bool {
std::lock_guard<std::mutex> guard(this->m_updatelock);
return CAST_MOD(Impl)->has_event() && CAST_MOD(Impl)->update();
};
while (this->running()) {
if (check()) {
CAST_MOD(Impl)->broadcast();
}
CAST_MOD(Impl)->idle();
}
} catch (const exception& err) {
CAST_MOD(Impl)->halt(err.what());
}
}
};
} // namespace modules
POLYBAR_NS_END