refactor: avoid unneeded json parsing

This commit is contained in:
Alex
2019-05-07 13:43:48 +02:00
parent 74137befba
commit 5a44c8c6de
8 changed files with 27 additions and 32 deletions

View File

@ -9,7 +9,6 @@
#include <memory>
#include <mutex>
#include "ipc.hpp"
#include "util/json.hpp"
namespace waybar::modules::sway {
@ -21,11 +20,11 @@ class Ipc {
struct ipc_response {
uint32_t size;
uint32_t type;
Json::Value payload;
std::string payload;
};
sigc::signal<void, const struct ipc_response&> signal_event;
sigc::signal<void, const struct ipc_response&> signal_cmd;
sigc::signal<void, const struct ipc_response &> signal_event;
sigc::signal<void, const struct ipc_response &> signal_cmd;
void sendCmd(uint32_t type, const std::string &payload = "");
void subscribe(const std::string &payload);
@ -40,12 +39,10 @@ class Ipc {
struct ipc_response send(int fd, uint32_t type, const std::string &payload = "");
struct ipc_response recv(int fd);
int fd_;
int fd_event_;
std::mutex mutex_;
std::mutex mutex_event_;
std::mutex mutex_parser_;
util::JsonParser parser_;
int fd_;
int fd_event_;
std::mutex mutex_;
std::mutex mutex_event_;
};
} // namespace waybar::modules::sway

View File

@ -6,6 +6,7 @@
#include "client.hpp"
#include "modules/sway/ipc/client.hpp"
#include "util/sleeper_thread.hpp"
#include "util/json.hpp"
namespace waybar::modules::sway {
@ -22,6 +23,7 @@ class Mode : public ALabel {
waybar::util::SleeperThread thread_;
Ipc ipc_;
std::string mode_;
util::JsonParser parser_;
};
} // namespace waybar::modules::sway

View File

@ -7,6 +7,7 @@
#include "client.hpp"
#include "modules/sway/ipc/client.hpp"
#include "util/sleeper_thread.hpp"
#include "util/json.hpp"
namespace waybar::modules::sway {
@ -29,6 +30,7 @@ class Window : public ALabel {
std::string window_;
int windowId_;
std::string app_id_;
util::JsonParser parser_;
};
} // namespace waybar::modules::sway

View File

@ -8,6 +8,7 @@
#include "client.hpp"
#include "modules/sway/ipc/client.hpp"
#include "util/sleeper_thread.hpp"
#include "util/json.hpp"
namespace waybar::modules::sway {
@ -38,6 +39,7 @@ class Workspaces : public IModule {
std::mutex mutex_;
Gtk::Box box_;
Ipc ipc_;
util::JsonParser parser_;
bool scrolling_;
std::unordered_map<std::string, Gtk::Button> buttons_;
};