This commit is contained in:
Alex
2018-08-20 14:50:45 +02:00
committed by GitHub
parent b7e3d10fb7
commit 49232eed8d
30 changed files with 261 additions and 235 deletions

View File

@ -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_;

View File

@ -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_;
};
}