From ba8c375c5c67db319b97db9cf5d1164a99236493 Mon Sep 17 00:00:00 2001 From: jongmyeongko Date: Thu, 17 Mar 2016 09:23:18 +0900 Subject: [PATCH 01/16] add mms value for incoming_msg event Change-Id: I4ba30714b94f012d809618ec4dee1d275a259f4f Signed-off-by: jongmyeongko --- include/eventsystem_internal.h | 1 + 1 file changed, 1 insertion(+) diff --git a/include/eventsystem_internal.h b/include/eventsystem_internal.h index 4cd65f6..154e2cb 100644 --- a/include/eventsystem_internal.h +++ b/include/eventsystem_internal.h @@ -166,6 +166,7 @@ extern "C" { #define EVT_KEY_MSG_TYPE "msg_type" /* value */ #define EVT_VAL_SMS "sms" +#define EVT_VAL_MMS "mms" #define EVT_VAL_PUSH "push" #define EVT_VAL_CB "cb" /* key */ -- 2.7.4 From ecd5ee1e74538f83a71c4714ade2a8279ccbcaf5 Mon Sep 17 00:00:00 2001 From: jongmyeongko Date: Fri, 12 Feb 2016 14:27:57 +0900 Subject: [PATCH 02/16] fix g_varinent_get related leak Change-Id: Ic49c6928a6d7dcc601475e755f37b9e75b36e5c8 Signed-off-by: jongmyeongko --- include/eventsystem.h | 8 -------- src/eventsystem.c | 12 ++++++++++-- 2 files changed, 10 insertions(+), 10 deletions(-) diff --git a/include/eventsystem.h b/include/eventsystem.h index ae4b723..e6e1467 100644 --- a/include/eventsystem.h +++ b/include/eventsystem.h @@ -45,14 +45,6 @@ typedef enum _eventsystem_event_type { ES_TYPE_SYSTEM /* system event */ } eventsystem_event_type; -#define FREE_AND_NULL(ptr) do { \ - if (ptr) { \ - free((void *)ptr); \ - ptr = NULL; \ - } \ -} while (0) - - /** * APIs for Application Framework. */ diff --git a/src/eventsystem.c b/src/eventsystem.c index 1cef92c..6b61845 100644 --- a/src/eventsystem.c +++ b/src/eventsystem.c @@ -23,6 +23,13 @@ #define VALID_LAST_COUNT_FOR_EVENTNAME (VALID_COUNT_OF_EVENTNAME_TOKEN + 1) #define MAX_COUNT_FOR_EVENTNAME_CHECK (VALID_LAST_COUNT_FOR_EVENTNAME + 1) +#define FREE_AND_NULL(ptr) do { \ + if (ptr) { \ + free((void *)ptr); \ + ptr = NULL; \ + } \ +} while (0) + #define _E(fmt, arg...) LOGE(fmt, ##arg) #define _D(fmt, arg...) LOGD(fmt, ##arg) #define _W(fmt, arg...) LOGW(fmt, ##arg) @@ -280,6 +287,7 @@ static int __check_validation_usrevent_sender(int sender_pid, key = strdup(interface_name); if (key == NULL) { _E("out of memory"); + g_free(sender_id); return ES_R_ENOMEM; } @@ -287,10 +295,12 @@ static int __check_validation_usrevent_sender(int sender_pid, if (val == NULL) { _E("out of memory"); free(key); + g_free(sender_id); return ES_R_ENOMEM; } g_hash_table_insert(filter_tbl, key, val); + g_free(sender_id); return ES_R_OK; } @@ -1316,7 +1326,6 @@ static int __eventsystem_setup_trusted_peer(const char *event_name, const char * } param = g_variant_new("(ss)", event_name, dest_bus_name); - value = g_dbus_proxy_call_sync(proxy, "SetupTrustedPeer", param, G_DBUS_CALL_FLAGS_NONE, -1, NULL, &error); if (error != NULL) { @@ -1375,7 +1384,6 @@ static int __eventsystem_requet_destination_list(const char *event_name, GList * } param = g_variant_new("(s)", event_name); - value = g_dbus_proxy_call_sync(proxy, "GetTrustedPeerList", param, G_DBUS_CALL_FLAGS_NONE, -1, NULL, &error); if (error != NULL) { -- 2.7.4 From d20cbfa6da9ec348df0a7b1356502892ed62bd5a Mon Sep 17 00:00:00 2001 From: Jiwoong Im Date: Wed, 6 Apr 2016 19:13:01 +0900 Subject: [PATCH 03/16] fix memory problem - access ptr_last after free temp_name Change-Id: Ic075c1b38c96fb5df9d122f22fde5ff65b5183af Signed-off-by: Jiwoong Im --- src/eventsystem.c | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/src/eventsystem.c b/src/eventsystem.c index 6b61845..99d72c1 100644 --- a/src/eventsystem.c +++ b/src/eventsystem.c @@ -242,10 +242,10 @@ static char *__get_member_name_from_eventname(char *event_name) ptr_last = ptr; count++; } - FREE_AND_NULL(temp_name); if (count != VALID_LAST_COUNT_FOR_EVENTNAME) { _E("invalid event_name(%s), count(%d)", event_name, count); + FREE_AND_NULL(temp_name); return NULL; } @@ -254,15 +254,18 @@ static char *__get_member_name_from_eventname(char *event_name) member_name = strdup(ptr_last); if (!member_name) { _E("out_of_memory"); + FREE_AND_NULL(temp_name); return NULL; } } else { _E("ptr_last is NULL"); + FREE_AND_NULL(temp_name); return NULL; } _D("member_name(%s)", member_name); + FREE_AND_NULL(temp_name); return member_name; } -- 2.7.4 From 1e4b42f70ebca5ce16c7b1a4283d63634b388d5c Mon Sep 17 00:00:00 2001 From: Jiwoong Im Date: Wed, 29 Jun 2016 22:49:14 +0900 Subject: [PATCH 04/16] add eventsystem_keep_last_event_data api - To keep last event data for future event receiver Change-Id: Ib7b72fc44977a7f61c9ec6cb6011a03d181d7e71 Signed-off-by: Jiwoong Im --- include/eventsystem.h | 4 + include/eventsystem_internal.h | 7 ++ src/eventsystem.c | 252 ++++++++++++++++++++++++++++++++++++++++- 3 files changed, 261 insertions(+), 2 deletions(-) diff --git a/include/eventsystem.h b/include/eventsystem.h index e6e1467..90cbb79 100644 --- a/include/eventsystem.h +++ b/include/eventsystem.h @@ -161,6 +161,10 @@ API int eventsystem_send_system_event(const char *event_name, bundle *data); */ API int eventsystem_request_sending_system_event(const char *event_name, bundle *data); +/** + * function : Request to keep last event data + */ +API int eventsystem_keep_last_event_data(const char *event_name); #ifdef __cplusplus } diff --git a/include/eventsystem_internal.h b/include/eventsystem_internal.h index 154e2cb..ccbc2de 100644 --- a/include/eventsystem_internal.h +++ b/include/eventsystem_internal.h @@ -39,6 +39,13 @@ extern "C" { #define EVT_VAL_ESD_STARTED "started" #define EVT_VAL_ESD_STOPPED "stopped" +/** esd : for sending saved event date request */ +#define SYS_EVENT_REQUEST_LAST_DATA "tizen.system.event.request_last_data" +/* key */ +#define EVT_KEY_KEPT_EVENT_NAME "kept_event_name" +#define EVT_KEY_KEPT_OWN_NAME "kept_own_name" +#define EVT_KEY_KEPT_IS_TRUSTED "kept_is_trusted" + /** battery : charger status */ #define SYS_EVENT_BATTERY_CHARGER_STATUS "tizen.system.event.battery_charger_status" /* key */ diff --git a/src/eventsystem.c b/src/eventsystem.c index 99d72c1..963e974 100644 --- a/src/eventsystem.c +++ b/src/eventsystem.c @@ -64,6 +64,13 @@ static GList *system_event_list; static int _initialized; static GHashTable *check_tbl; static GHashTable *filter_tbl; +static GHashTable *last_data_tbl; + +struct last_data_item { + char *event_name; + GVariant *param; + GVariant *trusted_param; +}; typedef struct eventmap { char *event_name; @@ -85,6 +92,7 @@ typedef struct eventinfo { char *object_path; char *member_name; bool is_user_event; + bool is_trusted; bundle *event_data; } eventinfo_s; @@ -843,14 +851,14 @@ static int __eventsystem_send_event(GDBusConnection *conn, eventinfo_s *evti, bu _D("object_path(%s)", evti->object_path); _D("member_name(%s)", evti->member_name); - bundle_free_encoded_rawdata(&raw); - if (ret == FALSE) { _E("Unable to connect to dbus: %s", error->message); g_error_free(error); return ES_R_ERROR; } + bundle_free_encoded_rawdata(&raw); + return ES_R_OK; } @@ -900,6 +908,9 @@ int eventsystem_send_user_event(const char *event_name, bundle *data, bool is_tr { int ret = 0; eventinfo_s *evti = NULL; + struct last_data_item *item; + bundle_raw *raw = NULL; + int len; /* check validation */ retvm_if(!event_name, ES_R_EINVAL, "Invalid argument : event_name is NULL"); @@ -946,6 +957,7 @@ int eventsystem_send_user_event(const char *event_name, bundle *data, bool is_tr evti->destination_name = NULL; evti->is_user_event = true; + evti->is_trusted = is_trusted; GDBusConnection *conn = NULL; if (__get_gdbus_shared_connection(&conn, G_BUS_TYPE_SESSION, ES_TYPE_USER) == ES_R_OK) { @@ -962,6 +974,27 @@ int eventsystem_send_user_event(const char *event_name, bundle *data, bool is_tr } else { ret = __eventsystem_send_event(conn, evti, data); } + + if (bundle_encode(data, &raw, &len)) { + _E("Unable to encode bundle"); + ret = ES_R_ERROR; + goto out_5; + } + + item = (struct last_data_item *)g_hash_table_lookup(last_data_tbl, + evti->event_name); + if (item) { + if (!evti->is_trusted) { + if (item->param) + g_variant_unref(item->param); + item->param = g_variant_new("(us)", len, raw); + } + if (item->trusted_param) + g_variant_unref(item->trusted_param); + item->trusted_param = g_variant_new("(us)", len, raw); + } + + bundle_free_encoded_rawdata(&raw); } else { _E("getting gdbus-connetion error"); ret = ES_R_ERROR; @@ -970,6 +1003,7 @@ int eventsystem_send_user_event(const char *event_name, bundle *data, bool is_tr if (conn) g_object_unref(conn); +out_5: FREE_AND_NULL(evti->object_path); out_4: FREE_AND_NULL(evti->member_name); @@ -1492,6 +1526,198 @@ out_1: } #endif +static int __request_esd_for_last_data(const char *event_name, bool check) +{ + int ret = 0; + GDBusConnection *conn = NULL; + GError *error = NULL; + GDBusProxy *proxy = NULL; + GVariant *param = NULL; + GVariant *value = NULL; + gint result = 0; + + if (!_initialized) + __initialize(); + + if (__get_gdbus_shared_connection(&conn, G_BUS_TYPE_SYSTEM, + ES_TYPE_SYSTEM) < 0) { + _E("getting gdbus-connetion error"); + ret = ES_R_ERROR; + goto out_1; + } + + proxy = g_dbus_proxy_new_sync(conn, + G_DBUS_PROXY_FLAGS_NONE, NULL, + ESD_BUS_NAME, ESD_OBJECT_PATH, ESD_INTERFACE_NAME, + NULL, &error); + + if (proxy == NULL) { + _E("failed to create new proxy, error(%s)", error->message); + g_error_free(error); + ret = ES_R_ERROR; + goto out_1; + } + + param = g_variant_new("(ss)", event_name, + check ? s_info.own_name_session_bus : + s_info.own_name_system_bus); + value = g_dbus_proxy_call_sync(proxy, + check ? "CheckLastData" : "KeepLastData", param, + G_DBUS_CALL_FLAGS_NONE, -1, NULL, &error); + + if (error != NULL) { + _E("proxy call sync error(%s)", error->message); + g_error_free(error); + ret = ES_R_ERROR; + goto out_2; + } + + g_variant_get(value, "(i)", &result); + + _D("result(%d)", result); + + ret = result; + +out_2: + g_variant_unref(value); +out_1: + if (conn) + g_object_unref(conn); + + return ret; +} + +static void _send_last_user_event(const char *event_name, + bundle *data, void *user_data) +{ + GDBusConnection *conn = NULL; + GError *error = NULL; + eventinfo_s *evti = NULL; + int ret; + struct last_data_item *item; + const char *is_trusted; + + _D("send last data"); + + if (g_strcmp0(event_name, SYS_EVENT_REQUEST_LAST_DATA) != 0) + return; + + evti = calloc(1, sizeof(eventinfo_s)); + if (!evti) { + _E("memory alloc failed"); + return; + } + + evti->event_name = (char *)bundle_get_val(data, + EVT_KEY_KEPT_EVENT_NAME); + if (!evti->event_name) { + _E("memory alloc failed"); + goto out_1; + } + + item = (struct last_data_item *)g_hash_table_lookup(last_data_tbl, + evti->event_name); + if (!item) + goto out_1; + + evti->interface_name = __get_encoded_interface_name(evti->event_name); + if (!evti->interface_name) { + _E("interface_name is NULL"); + goto out_1; + } + + evti->member_name = strdup(EVENT_SYSTEM_MEMBER); + if (!evti->member_name) { + _E("memory alloc failed"); + goto out_2; + } + + evti->object_path = __get_object_path(evti->interface_name); + if (!evti->object_path) { + _E("object_path is NULL"); + goto out_3; + } + + evti->destination_name = (char *)bundle_get_val(data, + EVT_KEY_KEPT_OWN_NAME); + if (!evti->destination_name) { + _E("object_path is NULL"); + goto out_4; + } + + is_trusted = bundle_get_val(data, EVT_KEY_KEPT_IS_TRUSTED); + if (!is_trusted) { + _E("object_path is NULL"); + goto out_4; + } + + if (strncmp("true", is_trusted, sizeof("true")) != 0) { + if (!item->trusted_param) + goto out_4; + evti->is_trusted = true; + } else { + if (!item->param) + goto out_4; + evti->is_trusted = false; + } + + if (__get_gdbus_shared_connection(&conn, G_BUS_TYPE_SESSION, + ES_TYPE_USER) == ES_R_OK) { + ret = g_dbus_connection_emit_signal(conn, + evti->destination_name, + evti->object_path, + evti->interface_name, + evti->member_name, + evti->is_trusted ? item->trusted_param : item->param, + &error); + if (ret == FALSE) { + _E("Unable to connect to dbus: %s", error->message); + g_error_free(error); + } + } + + if (conn) + g_object_unref(conn); + +out_4: + FREE_AND_NULL(evti->object_path); +out_3: + FREE_AND_NULL(evti->member_name); +out_2: + FREE_AND_NULL(evti->interface_name); +out_1: + FREE_AND_NULL(evti); +} + +int eventsystem_keep_last_event_data(const char *event_name) +{ + int ret = 0; + unsigned int reg_id; + struct last_data_item *item; + + if (last_data_tbl == NULL) + last_data_tbl = g_hash_table_new(g_str_hash, g_str_equal); + + ret = __request_esd_for_last_data(event_name, false); + if (ret != ES_R_OK) + return ret; + + item = calloc(1, sizeof(*item)); + if (!item) + return ES_R_ENOMEM; + + item->event_name = strdup(event_name); + item->param = NULL; + item->trusted_param = NULL; + + g_hash_table_insert(last_data_tbl, (char *)event_name, item); + + ret = eventsystem_register_event(SYS_EVENT_REQUEST_LAST_DATA, + ®_id, _send_last_user_event, NULL); + + return ret; +} + int eventsystem_register_application_event(const char *event_name, unsigned int *reg_id, int *event_type, eventsystem_cb callback, void *user_data) { @@ -1662,6 +1888,8 @@ int eventsystem_register_application_event(const char *event_name, unsigned int if (conn) g_object_unref(conn); + __request_esd_for_last_data(event_name, true); + return ret; } @@ -1759,6 +1987,26 @@ int eventsystem_application_finalize(void) g_hash_table_unref(filter_tbl); } + if (last_data_tbl) { + g_hash_table_iter_init(&iter, last_data_tbl); + + while (g_hash_table_iter_next(&iter, &key, &value)) { + key_item = (char *)key; + if (key_item) + free(key_item); + else + _E("last_data_tbl, val_item is NULL"); + + val_item = (char *)value; + if (val_item) + free(val_item); + else + _E("last_data_tbl, val_item is NULL"); + g_hash_table_iter_remove(&iter); + } + g_hash_table_unref(check_tbl); + } + FREE_AND_NULL(s_info.own_name_system_bus); FREE_AND_NULL(s_info.own_name_session_bus); -- 2.7.4 From 488a44820e019dda774d4339bc3e5757bd97f502 Mon Sep 17 00:00:00 2001 From: Jiwoong Im Date: Fri, 18 Nov 2016 10:43:49 +0900 Subject: [PATCH 05/16] Fix CMakeLists.txt To make extendible for adding source & header files. Change-Id: Ibb73e9f65212fc384393cc4a1fee5a743e26946d Signed-off-by: Jiwoong Im --- CMakeLists.txt | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 08cad00..e44e3be 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -1,6 +1,7 @@ CMAKE_MINIMUM_REQUIRED(VERSION 2.6) PROJECT(eventsystem C) +AUX_SOURCE_DIRECTORY(src/ SRCS) SET(VERSION 0.0.1) SET(VERSION_MAJOR 0) @@ -35,9 +36,7 @@ SET(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} ${EXTRA_CFLAGS}") SET(CMAKE_EXE_LINKER_FLAGS "-Wl,--as-needed") ## build eventsystem library -add_library(eventsystem SHARED - src/eventsystem.c - ) +add_library(eventsystem SHARED ${SRCS}) #TARGET_LINK_LIBRARIES(eventsystem "-ldl") TARGET_LINK_LIBRARIES(eventsystem ${libpkgs_LDFLAGS}) @@ -50,5 +49,7 @@ configure_file(eventsystem.manifest.in eventsystem.manifest @ONLY) INSTALL(TARGETS eventsystem DESTINATION ${LIB_INSTALL_DIR} COMPONENT RuntimeLibraries) INSTALL(FILES ${CMAKE_CURRENT_BINARY_DIR}/eventsystem.pc DESTINATION ${LIB_INSTALL_DIR}/pkgconfig) -INSTALL(FILES ${CMAKE_CURRENT_SOURCE_DIR}/include/eventsystem.h DESTINATION include) -INSTALL(FILES ${CMAKE_CURRENT_SOURCE_DIR}/include/eventsystem_internal.h DESTINATION include) +INSTALL(DIRECTORY ${CMAKE_SOURCE_DIR}/include/ DESTINATION include/ + FILES_MATCHING + PATTERN "*.h" + ) -- 2.7.4 From be37651f61d590983489063e78e13f27212f0d5d Mon Sep 17 00:00:00 2001 From: Jiwoong Im Date: Thu, 22 Dec 2016 08:14:50 +0900 Subject: [PATCH 06/16] Fix memory leak - Fix memory leak in using g_dbus_proxy_new_sync() API Change-Id: I2344392d63dddea0f13d1469b51feea297dbd586 Signed-off-by: Jiwoong Im --- src/eventsystem.c | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/src/eventsystem.c b/src/eventsystem.c index 963e974..cc316b0 100644 --- a/src/eventsystem.c +++ b/src/eventsystem.c @@ -1158,6 +1158,7 @@ int eventsystem_request_sending_system_event(const char *event_name, bundle *dat ret = ES_R_OK; out_2: + g_object_unref(proxy); g_variant_unref(value); out_1: if (conn) @@ -1214,6 +1215,7 @@ static int __eventsystem_check_sender_validation(int sender_pid, const char *eve if (result == 1) ret = ES_R_OK; out_2: + g_object_unref(proxy); g_variant_unref(value); out_1: if (conn) @@ -1269,6 +1271,7 @@ static int __eventsystem_check_user_send_validation(const char *event_name) if (result == 1) ret = ES_R_OK; out_2: + g_object_unref(proxy); g_variant_unref(value); out_1: if (conn) @@ -1324,6 +1327,7 @@ static int __eventsystem_check_privilege_validation(const char *event_name) if (result == 1) ret = ES_R_OK; out_2: + g_object_unref(proxy); g_variant_unref(value); out_1: if (conn) @@ -1379,6 +1383,7 @@ static int __eventsystem_setup_trusted_peer(const char *event_name, const char * if (result == 1) ret = ES_R_OK; out_2: + g_object_unref(proxy); g_variant_unref(value); out_1: if (conn) @@ -1451,6 +1456,7 @@ static int __eventsystem_requet_destination_list(const char *event_name, GList * g_variant_iter_free(iter); out_2: + g_object_unref(proxy); g_variant_unref(value); out_1: if (conn) @@ -1517,6 +1523,7 @@ static int __eventsystem_request_earlier_data(const char *event_name, ret = ES_R_OK; out_2: + g_object_unref(proxy); g_variant_unref(value); out_1: if (conn) @@ -1579,6 +1586,7 @@ static int __request_esd_for_last_data(const char *event_name, bool check) ret = result; out_2: + g_object_unref(proxy); g_variant_unref(value); out_1: if (conn) -- 2.7.4 From 23792796e351e43b004d5877420565a881bb2fa7 Mon Sep 17 00:00:00 2001 From: Jiwoong Im Date: Thu, 29 Dec 2016 16:16:10 +0900 Subject: [PATCH 07/16] Fix double free - g_variant_free is called repeatedly. Change-Id: I0b74943a1a68fa3e78527ed1024c674232df2749 Signed-off-by: Jiwoong Im --- src/eventsystem.c | 1 - 1 file changed, 1 deletion(-) diff --git a/src/eventsystem.c b/src/eventsystem.c index cc316b0..e51db0b 100644 --- a/src/eventsystem.c +++ b/src/eventsystem.c @@ -1511,7 +1511,6 @@ static int __eventsystem_request_earlier_data(const char *event_name, } g_variant_get(value, "(iis)", &result, &len, &raw); - g_variant_unref(value); _D("result(%d), len(%d)", result, len); -- 2.7.4 From a0741f99a3780f4a000f69433891044dd2a24844 Mon Sep 17 00:00:00 2001 From: Jiwoong Im Date: Fri, 24 Feb 2017 12:53:49 +0900 Subject: [PATCH 08/16] Release version 0.1.0 - Fix double free - Fix memory leak Change-Id: Ifbbbb47928d7db7132d3a917564c3c36e6d2b85b Signed-off-by: Jiwoong Im --- CMakeLists.txt | 7 ++----- packaging/eventsystem.spec | 6 ++++-- 2 files changed, 6 insertions(+), 7 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index e44e3be..5a43a4b 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -3,9 +3,6 @@ CMAKE_MINIMUM_REQUIRED(VERSION 2.6) PROJECT(eventsystem C) AUX_SOURCE_DIRECTORY(src/ SRCS) -SET(VERSION 0.0.1) -SET(VERSION_MAJOR 0) - SET(PREFIX ${CMAKE_INSTALL_PREFIX}) SET(EXEC_PREFIX "\${prefix}") SET(LIBDIR "\${prefix}/lib") @@ -40,8 +37,8 @@ add_library(eventsystem SHARED ${SRCS}) #TARGET_LINK_LIBRARIES(eventsystem "-ldl") TARGET_LINK_LIBRARIES(eventsystem ${libpkgs_LDFLAGS}) -SET_TARGET_PROPERTIES(eventsystem PROPERTIES SOVERSION ${VERSION_MAJOR}) -SET_TARGET_PROPERTIES(eventsystem PROPERTIES VERSION ${VERSION}) +SET_TARGET_PROPERTIES(${PROJECT_NAME} PROPERTIES SOVERSION ${MAJORVER}) +SET_TARGET_PROPERTIES(${PROJECT_NAME} PROPERTIES VERSION ${FULLVER}) # pkgconfig file CONFIGURE_FILE(${CMAKE_SOURCE_DIR}/eventsystem.pc.in ${CMAKE_BINARY_DIR}/eventsystem.pc @ONLY) diff --git a/packaging/eventsystem.spec b/packaging/eventsystem.spec index f23d124..d384fdb 100644 --- a/packaging/eventsystem.spec +++ b/packaging/eventsystem.spec @@ -1,6 +1,6 @@ Name: eventsystem Summary: Event system library -Version: 0.0.1 +Version: 0.1.0 Release: 1 Group: Application Framework/Libraries License: Apache-2.0 @@ -35,8 +35,10 @@ export CFLAGS="$CFLAGS -DTIZEN_DEBUG_ENABLE" export CXXFLAGS="$CXXFLAGS -DTIZEN_DEBUG_ENABLE" export FFLAGS="$FFLAGS -DTIZEN_DEBUG_ENABLE" +MAJORVER=`echo %{version} | awk 'BEGIN {FS="."}{print $1}'` + +%cmake . -DFULLVER=%{version} -DMAJORVER=${MAJORVER} -%cmake . make %{?jobs:-j%jobs} %install -- 2.7.4 From 07f7405da8fa1ff5f44feb9e1bb859629a2819d7 Mon Sep 17 00:00:00 2001 From: Jiwoong Im Date: Fri, 24 Mar 2017 08:36:48 +0900 Subject: [PATCH 09/16] Set license using %license macro Change-Id: I84b05029636160eabb08ac7f35726eee2eefaa26 Signed-off-by: Jiwoong Im --- packaging/eventsystem.spec | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) diff --git a/packaging/eventsystem.spec b/packaging/eventsystem.spec index d384fdb..76d5262 100644 --- a/packaging/eventsystem.spec +++ b/packaging/eventsystem.spec @@ -45,9 +45,6 @@ make %{?jobs:-j%jobs} rm -rf %{buildroot} %make_install -mkdir -p %{buildroot}/usr/share/license -cp LICENSE %{buildroot}/usr/share/license/%{name} - %post -p /sbin/ldconfig %postun -p /sbin/ldconfig @@ -56,7 +53,7 @@ cp LICENSE %{buildroot}/usr/share/license/%{name} %manifest eventsystem.manifest %defattr(-,root,root,-) %{_libdir}/libeventsystem.so.* -/usr/share/license/%{name} +%license LICENSE %files devel %defattr(-,root,root,-) -- 2.7.4 From ab0c46b6b1cf8c36a1c38f072a52080fa993324b Mon Sep 17 00:00:00 2001 From: Jiwoong Im Date: Mon, 27 Mar 2017 18:31:36 +0900 Subject: [PATCH 10/16] Release version 0.1.1 Changes: - Set license using %license macro Change-Id: I8d29f1f56eedda36b8e146039774fcb8fb8f9a06 Signed-off-by: Jiwoong Im --- packaging/eventsystem.spec | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packaging/eventsystem.spec b/packaging/eventsystem.spec index 76d5262..f395496 100644 --- a/packaging/eventsystem.spec +++ b/packaging/eventsystem.spec @@ -1,6 +1,6 @@ Name: eventsystem Summary: Event system library -Version: 0.1.0 +Version: 0.1.1 Release: 1 Group: Application Framework/Libraries License: Apache-2.0 -- 2.7.4 From b150ed52f6e1bf3c921ac42fe83092f6de339b90 Mon Sep 17 00:00:00 2001 From: jusung son Date: Tue, 10 Oct 2017 18:01:05 +0900 Subject: [PATCH 11/16] Fix memory leak Change-Id: Ib81bbeabfcd374de1e505b05d93d876686863b2c Signed-off-by: jusung son --- src/eventsystem.c | 30 ++++++++++++++++-------------- 1 file changed, 16 insertions(+), 14 deletions(-) mode change 100644 => 100755 src/eventsystem.c diff --git a/src/eventsystem.c b/src/eventsystem.c old mode 100644 new mode 100755 index e51db0b..56d210c --- a/src/eventsystem.c +++ b/src/eventsystem.c @@ -851,14 +851,14 @@ static int __eventsystem_send_event(GDBusConnection *conn, eventinfo_s *evti, bu _D("object_path(%s)", evti->object_path); _D("member_name(%s)", evti->member_name); + bundle_free_encoded_rawdata(&raw); + if (ret == FALSE) { _E("Unable to connect to dbus: %s", error->message); g_error_free(error); return ES_R_ERROR; } - bundle_free_encoded_rawdata(&raw); - return ES_R_OK; } @@ -1717,7 +1717,7 @@ int eventsystem_keep_last_event_data(const char *event_name) item->param = NULL; item->trusted_param = NULL; - g_hash_table_insert(last_data_tbl, (char *)event_name, item); + g_hash_table_insert(last_data_tbl, item->event_name, item); ret = eventsystem_register_event(SYS_EVENT_REQUEST_LAST_DATA, ®_id, _send_last_user_event, NULL); @@ -1953,6 +1953,7 @@ int eventsystem_application_finalize(void) GHashTableIter iter; char *key_item; char *val_item; + struct last_data_item *last_item; _D("release all resouces"); @@ -1998,20 +1999,21 @@ int eventsystem_application_finalize(void) g_hash_table_iter_init(&iter, last_data_tbl); while (g_hash_table_iter_next(&iter, &key, &value)) { - key_item = (char *)key; - if (key_item) - free(key_item); - else - _E("last_data_tbl, val_item is NULL"); - - val_item = (char *)value; - if (val_item) - free(val_item); - else + last_item = (struct last_data_item *)value; + if (last_item) { + if (last_item->event_name) + free(last_item->event_name); + if (last_item->param) + g_variant_unref(last_item->param); + if (last_item->trusted_param) + g_variant_unref(last_item->trusted_param); + free(last_item); + } else { _E("last_data_tbl, val_item is NULL"); + } g_hash_table_iter_remove(&iter); } - g_hash_table_unref(check_tbl); + g_hash_table_unref(last_data_tbl); } FREE_AND_NULL(s_info.own_name_system_bus); -- 2.7.4 From 2bf6227565a37a7384466b00aaf2bfe72509204a Mon Sep 17 00:00:00 2001 From: jusung son Date: Wed, 11 Oct 2017 15:22:22 +0900 Subject: [PATCH 12/16] Fix wrong log format Change-Id: I95e8894d894c1b0a1e99054388c43eeafaeaa373 Signed-off-by: jusung son --- src/eventsystem.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/eventsystem.c b/src/eventsystem.c index 56d210c..29480c1 100755 --- a/src/eventsystem.c +++ b/src/eventsystem.c @@ -774,7 +774,7 @@ int eventsystem_register_event(const char *event_name, unsigned int *reg_id, *reg_id = em->reg_id; ret = ES_R_OK; } else { - _E("error, ret(%d), em(%s)", ret, em); + _E("error, ret(%d), event_name(%s)", ret, event_name); } return ret; -- 2.7.4 From 276f27c11fa8a8f16b0d30b3c3ba3bd457905d3f Mon Sep 17 00:00:00 2001 From: jusung son Date: Thu, 12 Oct 2017 13:46:54 +0900 Subject: [PATCH 13/16] Release version 0.1.2 Changes: - Fix wrong log format - Fix memory leak Change-Id: I63b3168b34d619c9241fe8cb3a43cc8407ca9126 Signed-off-by: jusung son --- packaging/eventsystem.spec | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) mode change 100644 => 100755 packaging/eventsystem.spec diff --git a/packaging/eventsystem.spec b/packaging/eventsystem.spec old mode 100644 new mode 100755 index f395496..c046442 --- a/packaging/eventsystem.spec +++ b/packaging/eventsystem.spec @@ -1,6 +1,6 @@ Name: eventsystem Summary: Event system library -Version: 0.1.1 +Version: 0.1.2 Release: 1 Group: Application Framework/Libraries License: Apache-2.0 -- 2.7.4 From 772bbc5699de4d39f18bc32f92f1c0c149b02a6b Mon Sep 17 00:00:00 2001 From: jusung son Date: Fri, 6 Jul 2018 16:39:49 +0900 Subject: [PATCH 14/16] Fix dbus proxy creation code Add G_DBUS_PROXY_FLAGS_DO_NOT_LOAD_PROPERTIES flag. esd does not provide object which has properties. Without this flag, g_dbus_proxy_new_sync() will try to load properties using GetAll method, and this call will be denied by default dbus policy. Change-Id: I82fa44b201ba948e348be107e1b0e14b36a38e25 Signed-off-by: jusung son --- src/eventsystem.c | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/src/eventsystem.c b/src/eventsystem.c index 29480c1..90e7e91 100755 --- a/src/eventsystem.c +++ b/src/eventsystem.c @@ -1129,7 +1129,7 @@ int eventsystem_request_sending_system_event(const char *event_name, bundle *dat } proxy = g_dbus_proxy_new_sync(conn, - G_DBUS_PROXY_FLAGS_NONE, NULL, + G_DBUS_PROXY_FLAGS_DO_NOT_LOAD_PROPERTIES, NULL, ESD_BUS_NAME, ESD_OBJECT_PATH, ESD_INTERFACE_NAME, NULL, &error); if (proxy == NULL) { @@ -1188,7 +1188,7 @@ static int __eventsystem_check_sender_validation(int sender_pid, const char *eve } proxy = g_dbus_proxy_new_sync(conn, - G_DBUS_PROXY_FLAGS_NONE, NULL, + G_DBUS_PROXY_FLAGS_DO_NOT_LOAD_PROPERTIES, NULL, ESD_BUS_NAME, ESD_OBJECT_PATH, ESD_INTERFACE_NAME, NULL, &error); if (proxy == NULL) { @@ -1244,7 +1244,7 @@ static int __eventsystem_check_user_send_validation(const char *event_name) } proxy = g_dbus_proxy_new_sync(conn, - G_DBUS_PROXY_FLAGS_NONE, NULL, + G_DBUS_PROXY_FLAGS_DO_NOT_LOAD_PROPERTIES, NULL, ESD_BUS_NAME, ESD_OBJECT_PATH, ESD_INTERFACE_NAME, NULL, &error); if (proxy == NULL) { @@ -1300,7 +1300,7 @@ static int __eventsystem_check_privilege_validation(const char *event_name) } proxy = g_dbus_proxy_new_sync(conn, - G_DBUS_PROXY_FLAGS_NONE, NULL, + G_DBUS_PROXY_FLAGS_DO_NOT_LOAD_PROPERTIES, NULL, ESD_BUS_NAME, ESD_OBJECT_PATH, ESD_INTERFACE_NAME, NULL, &error); if (proxy == NULL) { @@ -1356,7 +1356,7 @@ static int __eventsystem_setup_trusted_peer(const char *event_name, const char * } proxy = g_dbus_proxy_new_sync(conn, - G_DBUS_PROXY_FLAGS_NONE, NULL, + G_DBUS_PROXY_FLAGS_DO_NOT_LOAD_PROPERTIES, NULL, ESD_BUS_NAME, ESD_OBJECT_PATH, ESD_INTERFACE_NAME, NULL, &error); if (proxy == NULL) { @@ -1415,7 +1415,7 @@ static int __eventsystem_requet_destination_list(const char *event_name, GList * } proxy = g_dbus_proxy_new_sync(conn, - G_DBUS_PROXY_FLAGS_NONE, NULL, + G_DBUS_PROXY_FLAGS_DO_NOT_LOAD_PROPERTIES, NULL, ESD_BUS_NAME, ESD_OBJECT_PATH, ESD_INTERFACE_NAME, NULL, &error); if (proxy == NULL) { @@ -1489,7 +1489,7 @@ static int __eventsystem_request_earlier_data(const char *event_name, } proxy = g_dbus_proxy_new_sync(conn, - G_DBUS_PROXY_FLAGS_NONE, NULL, + G_DBUS_PROXY_FLAGS_DO_NOT_LOAD_PROPERTIES, NULL, ESD_BUS_NAME, ESD_OBJECT_PATH, ESD_INTERFACE_NAME, NULL, &error); @@ -1553,7 +1553,7 @@ static int __request_esd_for_last_data(const char *event_name, bool check) } proxy = g_dbus_proxy_new_sync(conn, - G_DBUS_PROXY_FLAGS_NONE, NULL, + G_DBUS_PROXY_FLAGS_DO_NOT_LOAD_PROPERTIES, NULL, ESD_BUS_NAME, ESD_OBJECT_PATH, ESD_INTERFACE_NAME, NULL, &error); -- 2.7.4 From bcf5fa318b8be128e33bac916d3ef21feedb7d91 Mon Sep 17 00:00:00 2001 From: jusung son Date: Fri, 6 Jul 2018 16:48:37 +0900 Subject: [PATCH 15/16] Release version 0.1.3 Changes: - Fix dbus proxy creation code Change-Id: Ifa796dd1b6e43726e7a6987caa4c919cf55b3ffd Signed-off-by: jusung son --- packaging/eventsystem.spec | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packaging/eventsystem.spec b/packaging/eventsystem.spec index c046442..349e4a0 100755 --- a/packaging/eventsystem.spec +++ b/packaging/eventsystem.spec @@ -1,6 +1,6 @@ Name: eventsystem Summary: Event system library -Version: 0.1.2 +Version: 0.1.3 Release: 1 Group: Application Framework/Libraries License: Apache-2.0 -- 2.7.4 From 79150acb1e20f0d13d7fbb16e8f6e8b04d1c4ea8 Mon Sep 17 00:00:00 2001 From: Hwankyu Jhun Date: Wed, 17 Oct 2018 13:20:36 +0900 Subject: [PATCH 16/16] Fixed a bug about finding callback function Change-Id: If81fb645267dd181e56bf2cf3a4d40f0bfcf4cf3 Signed-off-by: Hwankyu Jhun --- src/eventsystem.c | 288 ++++++++++++++++++++++++++++-------------------------- 1 file changed, 151 insertions(+), 137 deletions(-) diff --git a/src/eventsystem.c b/src/eventsystem.c index 90e7e91..aea30f5 100755 --- a/src/eventsystem.c +++ b/src/eventsystem.c @@ -83,6 +83,7 @@ typedef struct eventmap { eventsystem_cb es_cb; eventsystem_handler ep_cb; }; + void *user_data; } eventmap_s; typedef struct eventinfo { @@ -108,14 +109,10 @@ static int __eventsystem_check_user_send_validation(const char *event_name); static int __eventsystem_requet_destination_list(const char *event_name, GList **dest_list); static int __eventsystem_check_sender_validation(int sender_pid, const char *event_name, char **sender); - -static int __event_compare_name_cb(gconstpointer a, gconstpointer b) -{ - eventmap_s *key1 = (eventmap_s *)a; - eventmap_s *key2 = (eventmap_s *)b; - return strcmp(key1->interface_name, key2->interface_name) | - strcmp(key1->member_name, key2->member_name); -} +static eventmap_s *__create_eventmap(const char *interface_name, + const char *member_name, const char *event_name, + int event_type, eventsystem_cb callback, void *user_data); +static void __destroy_eventmap(gpointer data); static int __event_compare_reg_id_cb(gconstpointer a, gconstpointer b) { @@ -468,19 +465,20 @@ static void __eventsystem_event_handler(GDBusConnection *connection, GVariant *parameters, gpointer user_data) { int len; - eventmap_s em; + eventmap_s *em = (eventmap_s *)user_data; GList *cb_list = NULL; bundle *buf = NULL; bundle_raw *raw = NULL; - em.interface_name = (char *)interface_name; - em.member_name = (char *)signal_name; + if (!em) { + _E("Critical error!"); + return; + } _D("sender_name(%s), interface_name(%s), signal_name(%s)", sender_name, interface_name, signal_name); - cb_list = g_list_find_custom(system_event_list, &em, - (GCompareFunc)__event_compare_name_cb); + cb_list = g_list_find(system_event_list, em); if (cb_list == NULL) return; @@ -488,10 +486,8 @@ static void __eventsystem_event_handler(GDBusConnection *connection, buf = bundle_decode((bundle_raw *)raw, len); - em.event_name = ((eventmap_s *)cb_list->data)->event_name; - em.ep_cb = ((eventmap_s *)cb_list->data)->ep_cb; - if (em.ep_cb) - em.ep_cb(em.event_name, buf, user_data); + if (em->ep_cb) + em->ep_cb(em->event_name, buf, em->user_data); bundle_free_encoded_rawdata(&raw); bundle_free(buf); @@ -501,36 +497,33 @@ static void __eventsystem_application_event_handler(int sender_pid, const gchar *interface_name, const gchar *signal_name, GVariant *parameters, gpointer user_data) { - GList *cb_list = NULL; - eventmap_s em; + GList *cb_list; + eventmap_s *em = (eventmap_s *)user_data; bundle_raw *raw = NULL; int len; - em.interface_name = (char *)interface_name; - em.member_name = (char *)signal_name; - - cb_list = g_list_find_custom(system_event_list, &em, - (GCompareFunc)__event_compare_name_cb); + if (!em) { + _E("Critical error!"); + return; + } + cb_list = g_list_find(system_event_list, em); if (cb_list == NULL) { _E("not interested event"); return; } - em.event_name = ((eventmap_s *)cb_list->data)->event_name; - if (sender_pid > 0 && __check_interface_validation_user((char *)interface_name)) { if (__check_validation_usrevent_sender(sender_pid, - (const char *)interface_name, em.event_name) < 0) { + (const char *)interface_name, em->event_name) < 0) { _E("invalid sender"); return; } } g_variant_get(parameters, "(us)", &len, &raw); - em.es_cb = ((eventmap_s *)cb_list->data)->es_cb; - if (em.es_cb) - em.es_cb(em.event_name, raw, len, user_data); + if (em->es_cb) + em->es_cb(em->event_name, raw, len, em->user_data); bundle_free_encoded_rawdata(&raw); } @@ -612,10 +605,10 @@ static void __eventsystem_filter_sysevent_for_internal(GDBusConnection *connecti static int __eventsystem_register_event_internal(const char *event_name, eventmap_s **em_s, void *user_data) { - eventmap_s *em = NULL; - char *interface_name = NULL; - char *object_path = NULL; - char *member_name = NULL; + eventmap_s *em; + char *interface_name; + char *object_path; + char *member_name; char *sender_name = NULL; GDBusSignalCallback filter; GBusType bus_type; @@ -691,6 +684,13 @@ static int __eventsystem_register_event_internal(const char *event_name, goto out_4; } + em = __create_eventmap(interface_name, member_name, event_name, + evt_type, NULL, user_data); + if (!em) { + ret = ES_R_ENOMEM; + goto out_4; + } + subscription_id = g_dbus_connection_signal_subscribe(conn, sender_name, /* sender */ interface_name, @@ -699,7 +699,7 @@ static int __eventsystem_register_event_internal(const char *event_name, NULL, /* arg0 */ G_DBUS_SIGNAL_FLAGS_NONE, filter, - user_data, + em, NULL); /* user_data_free_func */ _D("event_name(%s), interface_name(%s)", event_name, interface_name); @@ -707,33 +707,14 @@ static int __eventsystem_register_event_internal(const char *event_name, member_name, subscription_id, bus_type); if (subscription_id != 0) { - em = calloc(1, sizeof(eventmap_s)); - if (!em) { - _E("memory alloc failed"); - ret = ES_R_ENOMEM; - } else { - em->interface_name = strdup(interface_name); - em->member_name = strdup(member_name); - em->event_name = strdup(event_name); - em->bus_type = bus_type; - em->reg_id = subscription_id; - em->event_type = evt_type; - - if (!em->interface_name || !em->member_name || !em->event_name) { - _E("out_of_memory"); - FREE_AND_NULL(em->interface_name); - FREE_AND_NULL(em->member_name); - FREE_AND_NULL(em->event_name); - FREE_AND_NULL(em); - ret = ES_R_ENOMEM; - goto out_4; - } + em->bus_type = bus_type; + em->reg_id = subscription_id; - *em_s = em; - ret = ES_R_OK; - } + *em_s = em; + ret = ES_R_OK; } else { _D("dbus subscribe: error(%d), event(%s)", subscription_id, event_name); + __destroy_eventmap(em); ret = ES_R_ERROR; } @@ -816,10 +797,7 @@ int eventsystem_unregister_event(unsigned int reg_id) system_event_list = g_list_remove(system_event_list, cb_list->data); - FREE_AND_NULL(em_data->interface_name); - FREE_AND_NULL(em_data->member_name); - FREE_AND_NULL(em_data->event_name); - FREE_AND_NULL(em_data); + __destroy_eventmap(em_data); g_object_unref(conn); } @@ -1725,17 +1703,73 @@ int eventsystem_keep_last_event_data(const char *event_name) return ret; } +static void __destroy_eventmap(gpointer data) +{ + eventmap_s *em = (eventmap_s *)data; + + if (!em) + return; + + if (em->interface_name) + free(em->interface_name); + if (em->member_name) + free(em->member_name); + if (em->event_name) + free(em->event_name); + free(em); +} + +static eventmap_s *__create_eventmap(const char *interface_name, + const char *member_name, const char *event_name, + int event_type, eventsystem_cb callback, void *user_data) +{ + eventmap_s *em; + + em = calloc(1, sizeof(eventmap_s)); + if (!em) { + _E("Out of memory"); + return NULL; + } + + em->interface_name = strdup(interface_name); + if (!em->interface_name) { + _E("Failed to duplicate interface name"); + __destroy_eventmap(em); + return NULL; + } + + em->member_name = strdup(member_name); + if (!em->member_name) { + _E("Failed to duplicate member name"); + __destroy_eventmap(em); + return NULL; + } + + em->event_name = strdup(event_name); + if (!em->event_name) { + _E("Failed to duplicate event name"); + __destroy_eventmap(em); + return NULL; + } + + em->event_type = event_type; + em->es_cb = callback; + em->user_data = user_data; + + return em; +} + int eventsystem_register_application_event(const char *event_name, unsigned int *reg_id, int *event_type, eventsystem_cb callback, void *user_data) { eventmap_s *em; - char *interface_name = NULL; - char *object_path = NULL; - char *member_name = NULL; + char *interface_name; + char *object_path; + char *member_name; char *sender_name = NULL; GDBusSignalCallback filter; GBusType bus_type; - guint subscription_id = 0; + guint subscription_id = 0; int ret = 0; GDBusConnection *conn = NULL; @@ -1805,9 +1839,8 @@ int eventsystem_register_application_event(const char *event_name, unsigned int object_path = __get_object_path(interface_name); if (!object_path) { _E("failed get object_path"); - FREE_AND_NULL(interface_name); - FREE_AND_NULL(member_name); - return ES_R_ERROR; + ret = ES_R_ERROR; + goto end; } sender_name = NULL; @@ -1817,16 +1850,21 @@ int eventsystem_register_application_event(const char *event_name, unsigned int if (__get_gdbus_shared_connection(&conn, bus_type, *event_type) < 0) { _E("getting gdbus-connetion error"); - FREE_AND_NULL(interface_name); - FREE_AND_NULL(object_path); - FREE_AND_NULL(member_name); - return ES_R_ERROR; + ret = ES_R_ERROR; + goto end; } #ifdef APPFW_EVENT_SYSTEM_EARLIER_FEATURE __eventsystem_request_earlier_data(event_name, callback, user_data); #endif + em = __create_eventmap(interface_name, member_name, event_name, + *event_type, callback, user_data); + if (!em) { + ret = ES_R_ENOMEM; + goto end; + } + subscription_id = g_dbus_connection_signal_subscribe(conn, sender_name, /* sender */ interface_name, @@ -1835,77 +1873,56 @@ int eventsystem_register_application_event(const char *event_name, unsigned int NULL, /* arg0 */ G_DBUS_SIGNAL_FLAGS_NONE, filter, - user_data, + em, NULL); /* user_data_free_func */ _D("event_name(%s), subscription_id(%d)", event_name, subscription_id); if (subscription_id != 0) { - em = calloc(1, sizeof(eventmap_s)); - if (!em) { - _E("memory alloc failed"); - ret = ES_R_ENOMEM; - } else { - em->interface_name = strdup(interface_name); - em->member_name = strdup(member_name); - em->event_name = strdup(event_name); - em->es_cb = callback; - em->bus_type = bus_type; - em->reg_id = subscription_id; - em->event_type = *event_type; - - if (!em->interface_name || !em->member_name || - !em->event_name) { - _E("out_of_memory"); - FREE_AND_NULL(em->interface_name); - FREE_AND_NULL(em->member_name); - FREE_AND_NULL(em->event_name); - FREE_AND_NULL(em); - ret = ES_R_ENOMEM; + em->bus_type = bus_type; + em->reg_id = subscription_id; + + system_event_list = g_list_append(system_event_list, em); + *reg_id = subscription_id; + + ret = ES_R_OK; + + if (em->bus_type == G_BUS_TYPE_SESSION && + em->event_type == ES_TYPE_USER) { + if (s_info.own_name_session_bus == NULL) { + _E("session bus is not ready"); + ret = ES_R_ERROR; } else { - system_event_list = - g_list_append(system_event_list, em); - *reg_id = subscription_id; - - ret = ES_R_OK; - - if (em->bus_type == G_BUS_TYPE_SESSION && - em->event_type == ES_TYPE_USER) { - if (s_info.own_name_session_bus == NULL) { - _E("session bus is not ready"); - ret = ES_R_ERROR; - } else { - if (__eventsystem_setup_trusted_peer(event_name, + if (__eventsystem_setup_trusted_peer(event_name, s_info.own_name_session_bus) < 0) { - _E("failed to setup trusted peer"); - ret = ES_R_ERROR; - } - } + _E("failed to setup trusted peer"); + ret = ES_R_ERROR; } } } } else { _E("dbus subscribe: error(%d)", subscription_id); + __destroy_eventmap(em); ret = ES_R_ERROR; } + __request_esd_for_last_data(event_name, true); +end: FREE_AND_NULL(interface_name); FREE_AND_NULL(object_path); FREE_AND_NULL(member_name); if (conn) g_object_unref(conn); - __request_esd_for_last_data(event_name, true); - return ret; } int eventsystem_unregister_application_event(unsigned int reg_id) { eventmap_s em; - eventmap_s *em_data = NULL; + eventmap_s *em_data; GBusType bus_type; - GList *cb_list = NULL; + GList *cb_list; GDBusConnection *conn = NULL; eventsystem_event_type evt_type; @@ -1916,32 +1933,29 @@ int eventsystem_unregister_application_event(unsigned int reg_id) em.reg_id = reg_id; cb_list = g_list_find_custom(system_event_list, &em, - (GCompareFunc)__event_compare_reg_id_cb); - if (cb_list) { - em_data = (eventmap_s *)cb_list->data; + (GCompareFunc)__event_compare_reg_id_cb); + if (!cb_list) { + _E("not found matched item"); + return ES_R_ERROR; + } - bus_type = em_data->bus_type; - evt_type = em_data->event_type; + em_data = (eventmap_s *)cb_list->data; - _D("unsubscribe: reg_id(%d), bus_type(%d)", reg_id, bus_type); + bus_type = em_data->bus_type; + evt_type = em_data->event_type; - if (__get_gdbus_shared_connection(&conn, bus_type, evt_type) < 0) { - _E("getting gdbus-connetion error"); - return ES_R_ERROR; - } - g_dbus_connection_signal_unsubscribe(conn, reg_id); + _D("unsubscribe: reg_id(%d), bus_type(%d)", reg_id, bus_type); - system_event_list = g_list_remove(system_event_list, cb_list->data); - - FREE_AND_NULL(em_data->interface_name); - FREE_AND_NULL(em_data->member_name); - FREE_AND_NULL(em_data->event_name); - FREE_AND_NULL(em_data); - g_object_unref(conn); - } else { - _E("not found matched item"); + if (__get_gdbus_shared_connection(&conn, bus_type, evt_type) < 0) { + _E("getting gdbus-connetion error"); return ES_R_ERROR; } + g_dbus_connection_signal_unsubscribe(conn, reg_id); + + system_event_list = g_list_remove(system_event_list, cb_list->data); + + __destroy_eventmap(em_data); + g_object_unref(conn); return ES_R_OK; } -- 2.7.4