added json-c lib and implemented IPC get_version

This commit is contained in:
minus 2015-08-26 23:49:38 +02:00
parent 357af228d6
commit 2289029fab
2 changed files with 17 additions and 0 deletions

View File

@ -22,12 +22,15 @@ find_package(XKBCommon REQUIRED)
find_package(WLC REQUIRED) find_package(WLC REQUIRED)
find_package(A2X REQUIRED) find_package(A2X REQUIRED)
find_package(PCRE REQUIRED) find_package(PCRE REQUIRED)
find_package(PkgConfig REQUIRED)
pkg_check_modules(JSON REQUIRED json-c)
FILE(GLOB sources ${PROJECT_SOURCE_DIR}/sway/*.c) FILE(GLOB sources ${PROJECT_SOURCE_DIR}/sway/*.c)
include_directories( include_directories(
${WLC_INCLUDE_DIRS} ${WLC_INCLUDE_DIRS}
${PCRE_INCLUDE_DIRS} ${PCRE_INCLUDE_DIRS}
${JSON_INCLUDE_DIRS}
include/ include/
) )
@ -39,6 +42,7 @@ target_link_libraries(sway
${WLC_LIBRARIES} ${WLC_LIBRARIES}
${XKBCOMMON_LIBRARIES} ${XKBCOMMON_LIBRARIES}
${PCRE_LIBRARIES} ${PCRE_LIBRARIES}
${JSON_LIBRARIES}
) )
INSTALL( INSTALL(

View File

@ -12,6 +12,7 @@
#include <sys/ioctl.h> #include <sys/ioctl.h>
#include <fcntl.h> #include <fcntl.h>
#include <ctype.h> #include <ctype.h>
#include <json-c/json.h>
#include "ipc.h" #include "ipc.h"
#include "log.h" #include "log.h"
#include "config.h" #include "config.h"
@ -226,6 +227,18 @@ void ipc_client_handle_command(struct ipc_client *client) {
free(json); free(json);
break; break;
} }
case IPC_GET_VERSION:
{
json_object *json = json_object_new_object();
json_object_object_add(json, "human_readable", json_object_new_string(SWAY_GIT_VERSION));
json_object_object_add(json, "major", json_object_new_int(0));
json_object_object_add(json, "minor", json_object_new_int(0));
json_object_object_add(json, "patch", json_object_new_int(1));
const char *json_string = json_object_to_json_string(json);
ipc_send_reply(client, json_string, (uint32_t) strlen(json_string));
json_object_put(json); // free
break;
}
default: default:
sway_log(L_INFO, "Unknown IPC command type %i", client->current_command); sway_log(L_INFO, "Unknown IPC command type %i", client->current_command);
ipc_client_disconnect(client); ipc_client_disconnect(client);