mirror of
https://github.com/rad4day/Waybar.git
synced 2023-12-21 10:22:59 +01:00
Clean (#31)
This commit is contained in:
@ -70,26 +70,13 @@ struct SleeperThread {
|
||||
condvar_.notify_all();
|
||||
}
|
||||
|
||||
void emit()
|
||||
{
|
||||
Glib::signal_idle().connect_once([this] {
|
||||
sig_update.emit();
|
||||
});
|
||||
}
|
||||
|
||||
~SleeperThread()
|
||||
{
|
||||
do_run_ = false;
|
||||
condvar_.notify_all();
|
||||
auto native_handle = thread_.native_handle();
|
||||
pthread_cancel(native_handle);
|
||||
if (thread_.joinable()) {
|
||||
thread_.join();
|
||||
}
|
||||
thread_.detach();
|
||||
}
|
||||
|
||||
sigc::signal<void> sig_update;
|
||||
|
||||
private:
|
||||
std::thread thread_;
|
||||
std::condition_variable condvar_;
|
||||
|
@ -7,32 +7,25 @@ namespace waybar::util {
|
||||
struct JsonParser {
|
||||
|
||||
JsonParser()
|
||||
: _reader(_builder.newCharReader())
|
||||
: reader_(builder_.newCharReader())
|
||||
{}
|
||||
|
||||
Json::Value parse(const std::string data)
|
||||
const Json::Value parse(const std::string data) const
|
||||
{
|
||||
Json::Value root;
|
||||
std::string err;
|
||||
if (_reader == nullptr) {
|
||||
throw std::runtime_error("Unable to parse");
|
||||
}
|
||||
bool res =
|
||||
_reader->parse(data.c_str(), data.c_str() + data.size(), &root, &err);
|
||||
reader_->parse(data.c_str(), data.c_str() + data.size(), &root, &err);
|
||||
if (!res)
|
||||
throw std::runtime_error(err);
|
||||
return root;
|
||||
}
|
||||
|
||||
~JsonParser()
|
||||
{
|
||||
delete _reader;
|
||||
_reader = nullptr;
|
||||
}
|
||||
~JsonParser() = default;
|
||||
|
||||
private:
|
||||
Json::CharReaderBuilder _builder;
|
||||
Json::CharReader *_reader;
|
||||
Json::CharReaderBuilder builder_;
|
||||
std::unique_ptr<Json::CharReader> const reader_;
|
||||
};
|
||||
|
||||
}
|
||||
|
Reference in New Issue
Block a user