Skip to content

Commit

Permalink
wip: Replace sigc++ with fastdelgate
Browse files Browse the repository at this point in the history
  • Loading branch information
jaagr committed Oct 12, 2016
1 parent 536281d commit 13a8118
Show file tree
Hide file tree
Showing 4 changed files with 95 additions and 95 deletions.
12 changes: 4 additions & 8 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@ option(BUILD_EXAMPLES "Build example executables" OFF)
# Process dependencies {{{

find_package(PkgConfig)
pkg_check_modules(SIGCPP REQUIRED sigc++-2.0)
pkg_check_modules(JSONCPP REQUIRED jsoncpp>=1.7.0)

# }}}
Expand All @@ -28,15 +27,13 @@ set_property(TARGET ${PROJECT_NAME} PROPERTY CXX_STANDARD 11)
set_property(TARGET ${PROJECT_NAME} PROPERTY CXX_STANDARD_REQUIRED ON)

target_link_libraries(${PROJECT_NAME}
${JSONCPP_LIBRARIES}
${SIGCPP_LIBRARIES})
${JSONCPP_LIBRARIES})

target_include_directories(${PROJECT_NAME} PUBLIC
${PROJECT_SOURCE_DIR}/include
${JSONCPP_INCLUDE_DIRS}
${SIGCPP_INCLUDE_DIRS})
${JSONCPP_INCLUDE_DIRS})

target_compile_options(${PROJECT_NAME} PRIVATE -Wall -Wextra -Wno-unused-parameter)
target_compile_options(${PROJECT_NAME} PRIVATE -Wall -Wextra -Wno-unused-parameter -Wno-unused-local-typedefs)
target_compile_options(${PROJECT_NAME} PRIVATE $<$<CONFIG:Debug>:-g3 -DDEBUG>)
target_compile_options(${PROJECT_NAME} PRIVATE $<$<CONFIG:Release>:-O3>)

Expand All @@ -48,8 +45,7 @@ if(HAS_PARENT)
set(I3IPCPP_LIBRARIES ${PROJECT_NAME} PARENT_SCOPE)
set(I3IPCPP_INCLUDE_DIRS
${PROJECT_SOURCE_DIR}/include
${JSONCPP_INCLUDE_DIRS}
${SIGCPP_INCLUDE_DIRS})
${JSONCPP_INCLUDE_DIRS})
endif()

# }}}
Expand Down
17 changes: 10 additions & 7 deletions include/i3ipc++/ipc.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,9 @@
#include <string>
#include <memory>
#include <vector>
#include <list>

#include <sigc++/sigc++.h>
#include <fastdelegate/fastdelegate.hpp>

extern "C" {
#include <i3/ipc.h>
Expand Down Expand Up @@ -253,13 +254,15 @@ class connection {
int get_main_socket_fd();
int get_event_socket_fd();

sigc::signal<void, const workspace_event_t&> signal_workspace_event; ///< Workspace event signal
sigc::signal<void> signal_output_event; ///< Output event signal
sigc::signal<void> signal_mode_event; ///< Output mode event signal
sigc::signal<void, const window_event_t&> signal_window_event; ///< Window event signal
sigc::signal<void> signal_barconfig_update_event; ///< Barconfig update event signal
sigc::signal<void, EventType, const std::shared_ptr<const buf_t>&> signal_event; ///< i3 event signal @note Default handler routes event to signal according to type
delegate::Signal1<const workspace_event_t&> signal_workspace_event; ///< Workspace event signal
delegate::Signal0<> signal_output_event; ///< Output event signal
delegate::Signal0<> signal_mode_event; ///< Output mode event signal
delegate::Signal1<const window_event_t&> signal_window_event; ///< Window event signal
delegate::Signal0<> signal_barconfig_update_event; ///< Barconfig update event signal
delegate::Signal2<EventType, const std::shared_ptr<const buf_t>&> signal_event; ///< i3 event signal @note Default handler routes event to signal according to type
private:
void signal_event_handler(EventType event_type, const std::shared_ptr<const buf_t>& buf);

const int32_t m_main_socket;
int32_t m_event_socket;
int32_t m_subscriptions;
Expand Down
2 changes: 1 addition & 1 deletion include/log.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ inline void log(const auss_t& data, const bool err) {
*/
#define I3IPC_WARN(T) I3IPC_LOG(auss_t() << "W: " << T, true)

#ifdef DEBUG
#ifdef I3IPCPP_DEBUG

/**
* Put debug message to log
Expand Down
159 changes: 80 additions & 79 deletions src/ipc.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -180,89 +180,90 @@ std::string get_socketpath() {


connection::connection(const std::string& socket_path) : m_main_socket(i3_connect(socket_path)), m_event_socket(-1), m_subscriptions(0), m_socket_path(socket_path) {
signal_event.connect(this, &connection::signal_event_handler);
}
void connection::signal_event_handler(EventType event_type, const std::shared_ptr<const buf_t>& buf) {
#define i3IPC_TYPE_STR "i3's event"
signal_event.connect([this](EventType event_type, const std::shared_ptr<const buf_t>& buf) {
switch (event_type) {
case ET_WORKSPACE: {
workspace_event_t ev;
Json::Value root;
IPC_JSON_READ(root);
std::string change = root["change"].asString();
if (change == "focus") {
ev.type = WorkspaceEventType::FOCUS;
} else if (change == "init") {
ev.type = WorkspaceEventType::INIT;
} else if (change == "empty") {
ev.type = WorkspaceEventType::EMPTY;
} else if (change == "urgent") {
ev.type = WorkspaceEventType::URGENT;
} else {
I3IPC_WARN("Unknown workspace event type " << change)
break;
}
I3IPC_DEBUG("WORKSPACE " << change)

Json::Value current = root["current"];
Json::Value old = root["current"];

if (!current.isNull()) {
ev.current = parse_workspace_from_json(current);
}
if (!old.isNull()) {
ev.old = parse_workspace_from_json(old);
}

signal_workspace_event.emit(ev);
switch (event_type) {
case ET_WORKSPACE: {
workspace_event_t ev;
Json::Value root;
IPC_JSON_READ(root);
std::string change = root["change"].asString();
if (change == "focus") {
ev.type = WorkspaceEventType::FOCUS;
} else if (change == "init") {
ev.type = WorkspaceEventType::INIT;
} else if (change == "empty") {
ev.type = WorkspaceEventType::EMPTY;
} else if (change == "urgent") {
ev.type = WorkspaceEventType::URGENT;
} else {
I3IPC_WARN("Unknown workspace event type " << change)
break;
}
case ET_OUTPUT:
I3IPC_DEBUG("OUTPUT")
signal_output_event.emit();
break;
case ET_MODE:
I3IPC_DEBUG("MODE")
signal_mode_event.emit();
break;
case ET_WINDOW: {
window_event_t ev;
Json::Value root;
IPC_JSON_READ(root);
std::string change = root["change"].asString();
if (change == "new") {
ev.type = WindowEventType::NEW;
} else if (change == "close") {
ev.type = WindowEventType::CLOSE;
} else if (change == "focus") {
ev.type = WindowEventType::FOCUS;
} else if (change == "title") {
ev.type = WindowEventType::TITLE;
} else if (change == "fullscreen_mode") {
ev.type = WindowEventType::FULLSCREEN_MODE;
} else if (change == "move") {
ev.type = WindowEventType::MOVE;
} else if (change == "floating") {
ev.type = WindowEventType::FLOATING;
} else if (change == "urgent") {
ev.type = WindowEventType::URGENT;
}
I3IPC_DEBUG("WINDOW " << change)

Json::Value container = root["container"];
if (!container.isNull()) {
ev.container = parse_container_from_json(container);
}

signal_window_event.emit(ev);
break;
I3IPC_DEBUG("WORKSPACE " << change)

Json::Value current = root["current"];
Json::Value old = root["current"];

if (!current.isNull()) {
ev.current = parse_workspace_from_json(current);
}
case ET_BARCONFIG_UPDATE:
I3IPC_DEBUG("BARCONFIG_UPDATE")
signal_barconfig_update_event.emit();
break;
};
});
if (!old.isNull()) {
ev.old = parse_workspace_from_json(old);
}

signal_workspace_event.emit(ev);
break;
}
case ET_OUTPUT:
I3IPC_DEBUG("OUTPUT")
signal_output_event.emit();
break;
case ET_MODE:
I3IPC_DEBUG("MODE")
signal_mode_event.emit();
break;
case ET_WINDOW: {
window_event_t ev;
Json::Value root;
IPC_JSON_READ(root);
std::string change = root["change"].asString();
if (change == "new") {
ev.type = WindowEventType::NEW;
} else if (change == "close") {
ev.type = WindowEventType::CLOSE;
} else if (change == "focus") {
ev.type = WindowEventType::FOCUS;
} else if (change == "title") {
ev.type = WindowEventType::TITLE;
} else if (change == "fullscreen_mode") {
ev.type = WindowEventType::FULLSCREEN_MODE;
} else if (change == "move") {
ev.type = WindowEventType::MOVE;
} else if (change == "floating") {
ev.type = WindowEventType::FLOATING;
} else if (change == "urgent") {
ev.type = WindowEventType::URGENT;
}
I3IPC_DEBUG("WINDOW " << change)

Json::Value container = root["container"];
if (!container.isNull()) {
ev.container = parse_container_from_json(container);
}

signal_window_event.emit(ev);
break;
}
case ET_BARCONFIG_UPDATE:
I3IPC_DEBUG("BARCONFIG_UPDATE")
signal_barconfig_update_event.emit();
break;
};
#undef i3IPC_TYPE_STR
}
};
connection::~connection() {
i3_disconnect(m_main_socket);
if (m_event_socket > 0)
Expand All @@ -278,7 +279,7 @@ void connection::handle_event() {
if (m_event_socket <= 0) {
throw std::runtime_error("event_socket_fd <= 0");
}
auto buf = i3_recv(m_event_socket);
auto buf = i3_recv(m_event_socket);

this->signal_event.emit(static_cast<EventType>(1 << (buf->header->type & 0x7f)), std::static_pointer_cast<const buf_t>(buf));
}
Expand Down

0 comments on commit 13a8118

Please sign in to comment.