From 7c460feb59ac1718ed926e8d198b39d333d35294 Mon Sep 17 00:00:00 2001 From: Krzysztof Sasiak Date: Fri, 9 Aug 2013 12:45:46 +0200 Subject: [PATCH] Sync add_filter & match for dbus watch deviced added message filter unconditionally when it's starting. Without adding dbus match, It's no checking logic. Now Add dbus filter only when there is match request. Change-Id: Icf1356d985f5cb9638afd7c82ac9ef67813c1ce1 Signed-off-by: Krzysztof Sasiak --- src/core/edbus-handler.c | 99 ++++++++++++++++++++++++++++-------------------- 1 file changed, 57 insertions(+), 42 deletions(-) diff --git a/src/core/edbus-handler.c b/src/core/edbus-handler.c index 7546175..87c70d2 100644 --- a/src/core/edbus-handler.c +++ b/src/core/edbus-handler.c @@ -242,46 +242,6 @@ int broadcast_edbus_signal(const char *path, const char *interface, return 0; } -int register_edbus_watch(DBusMessage *msg) -{ - char match[256]; - const char *sender, *watch; - Eina_List *l; - - if (!msg) { - _E("invalid argument!"); - return -EINVAL; - } - - sender = dbus_message_get_sender(msg); - if (!sender) { - _E("invalid sender!"); - return -EINVAL; - } - - /* check the sender is already registered */ - EINA_LIST_FOREACH(edbus_watch_list, l, watch) { - if (strcmp(sender, watch)) continue; - - _I("%s is already watched!", watch); - return 0; - } - - watch = strndup(sender, strlen(sender)); - if (!watch) { - _E("Malloc failed"); - return -ENOMEM; - } - - /* Add sender to watch list */ - EINA_LIST_APPEND(edbus_watch_list, watch); - - snprintf(match, sizeof(match), NAME_OWNER_MATCH, watch); - dbus_bus_add_match(conn, match, NULL); - - _I("%s is watched by dbus!", watch); -} - static DBusHandlerResult message_filter(DBusConnection *connection, DBusMessage *message, void *data) { @@ -325,9 +285,66 @@ static DBusHandlerResult message_filter(DBusConnection *connection, break; } + if (eina_list_count(edbus_watch_list) == 0) { + dbus_connection_remove_filter(conn, message_filter, NULL); + _I("remove message filter, no watcher!"); + } + return DBUS_HANDLER_RESULT_HANDLED; } +int register_edbus_watch(DBusMessage *msg) +{ + char match[256]; + const char *sender, *watch; + Eina_List *l; + int ret; + + if (!msg) { + _E("invalid argument!"); + return -EINVAL; + } + + sender = dbus_message_get_sender(msg); + if (!sender) { + _E("invalid sender!"); + return -EINVAL; + } + + /* check the sender is already registered */ + EINA_LIST_FOREACH(edbus_watch_list, l, watch) { + if (strcmp(sender, watch)) continue; + + _I("%s is already watched!", watch); + return 0; + } + + watch = strndup(sender, strlen(sender)); + if (!watch) { + _E("Malloc failed"); + return -ENOMEM; + } + + /* Add message filter */ + if (eina_list_count(edbus_watch_list) == 0) { + ret = dbus_connection_add_filter(conn, message_filter, NULL, NULL); + if (!ret) { + _E("fail to add message filter!"); + free(watch); + return -ENOMEM; + } + _I("success to add message filter!"); + } + + /* Add sender to watch list */ + EINA_LIST_APPEND(edbus_watch_list, watch); + + snprintf(match, sizeof(match), NAME_OWNER_MATCH, watch); + dbus_bus_add_match(conn, match, NULL); + + _I("%s is watched by dbus!", watch); +} + static unregister_edbus_watch_all(void) { char match[256]; @@ -387,8 +404,6 @@ static void edbus_init(void *data) _I("add new obj for %s", edbus_objects[i].interface); } - - _D("start edbus service"); return; err_dbus_close: -- 2.7.4