From d626302b25a961df964b5a93385f431c51735208 Mon Sep 17 00:00:00 2001 From: Nishant Chaprana Date: Sat, 20 Aug 2016 11:19:53 +0530 Subject: [PATCH] Upgrading signal subscription logic. Currently there is a common signal handler which receives signal and then checks signal name to call signals handler function. This process is done for every received signal. If we register signals seperately then dbus will directly call signal handler function. Change-Id: Id3b641a19782da2163f1c3e5aebb63776738f849 Signed-off-by: Nishant Chaprana --- packaging/capi-network-wifi-direct.spec | 2 +- src/include/wifi-direct-client-proxy.h | 117 ++++++++++++++++++++++++++++---- src/wifi-direct-client-proxy.c | 105 ++++++++++++++++++++++++---- src/wifi-direct-dbus.c | 89 ++++++++++++------------ 4 files changed, 238 insertions(+), 75 deletions(-) diff --git a/packaging/capi-network-wifi-direct.spec b/packaging/capi-network-wifi-direct.spec index e1df9a4..ecf503a 100644 --- a/packaging/capi-network-wifi-direct.spec +++ b/packaging/capi-network-wifi-direct.spec @@ -1,6 +1,6 @@ Name: capi-network-wifi-direct Summary: Network WiFi-Direct Library -Version: 1.2.71 +Version: 1.2.72 Release: 1 Group: Network & Connectivity/API License: Apache-2.0 diff --git a/src/include/wifi-direct-client-proxy.h b/src/include/wifi-direct-client-proxy.h index 3ccab11..7515041 100644 --- a/src/include/wifi-direct-client-proxy.h +++ b/src/include/wifi-direct-client-proxy.h @@ -84,38 +84,125 @@ extern char *wfd_debug_print(char *file, int line, char *format, ...); /* Manage */ void wifi_direct_process_manage_activation(GDBusConnection *connection, - const gchar *object_path, GVariant *parameters); + const gchar *sender, + const gchar *object_path, + const gchar *interface, + const gchar *signal, + GVariant *parameters, + gpointer user_data); + void wifi_direct_process_manage_deactivation(GDBusConnection *connection, - const gchar *object_path, GVariant *parameters); + const gchar *sender, + const gchar *object_path, + const gchar *interface, + const gchar *signal, + GVariant *parameters, + gpointer user_data); + void wifi_direct_process_manage_connection(GDBusConnection *connection, - const gchar *object_path, GVariant *parameters); + const gchar *sender, + const gchar *object_path, + const gchar *interface, + const gchar *signal, + GVariant *parameters, + gpointer user_data); + void wifi_direct_process_manage_disconnection(GDBusConnection *connection, - const gchar *object_path, GVariant *parameters); + const gchar *sender, + const gchar *object_path, + const gchar *interface, + const gchar *signal, + GVariant *parameters, + gpointer user_data); + void wifi_direct_process_manage_peer_ip_assigned(GDBusConnection *connection, - const gchar *object_path, GVariant *parameters); + const gchar *sender, + const gchar *object_path, + const gchar *interface, + const gchar *signal, + GVariant *parameters, + gpointer user_data); + void wifi_direct_process_manage_listen_started(GDBusConnection *connection, - const gchar *object_path, GVariant *parameters); + const gchar *sender, + const gchar *object_path, + const gchar *interface, + const gchar *signal, + GVariant *parameters, + gpointer user_data); + void wifi_direct_process_manage_discovery_started(GDBusConnection *connection, - const gchar *object_path, GVariant *parameters); + const gchar *sender, + const gchar *object_path, + const gchar *interface, + const gchar *signal, + GVariant *parameters, + gpointer user_data); + void wifi_direct_process_manage_discovery_finished(GDBusConnection *connection, - const gchar *object_path, GVariant *parameters); + const gchar *sender, + const gchar *object_path, + const gchar *interface, + const gchar *signal, + GVariant *parameters, + gpointer user_data); + void wifi_direct_process_manage_peer_found(GDBusConnection *connection, - const gchar *object_path, GVariant *parameters); + const gchar *sender, + const gchar *object_path, + const gchar *interface, + const gchar *signal, + GVariant *parameters, + gpointer user_data); + void wifi_direct_process_manage_peer_lost(GDBusConnection *connection, - const gchar *object_path, GVariant *parameters); + const gchar *sender, + const gchar *object_path, + const gchar *interface, + const gchar *signal, + GVariant *parameters, + gpointer user_data); /* Group */ void wifi_direct_process_group_created(GDBusConnection *connection, - const gchar *object_path, GVariant *parameters); + const gchar *sender, + const gchar *object_path, + const gchar *interface, + const gchar *signal, + GVariant *parameters, + gpointer user_data); + void wifi_direct_process_group_destroyed(GDBusConnection *connection, - const gchar *object_path, GVariant *parameters); + const gchar *sender, + const gchar *object_path, + const gchar *interface, + const gchar *signal, + GVariant *parameters, + gpointer user_data); /* Service */ void wifi_direct_process_service_discovery_started(GDBusConnection *connection, - const gchar *object_path, GVariant *parameters); + const gchar *sender, + const gchar *object_path, + const gchar *interface, + const gchar *signal, + GVariant *parameters, + gpointer user_data); + void wifi_direct_process_service_discovery_found(GDBusConnection *connection, - const gchar *object_path, GVariant *parameters); + const gchar *sender, + const gchar *object_path, + const gchar *interface, + const gchar *signal, + GVariant *parameters, + gpointer user_data); + void wifi_direct_process_service_discovery_finished(GDBusConnection *connection, - const gchar *object_path, GVariant *parameters); + const gchar *sender, + const gchar *object_path, + const gchar *interface, + const gchar *signal, + GVariant *parameters, + gpointer user_data); #endif /** __WIFI_DIRECT_CLIENT_PROXY_H_ */ diff --git a/src/wifi-direct-client-proxy.c b/src/wifi-direct-client-proxy.c index 7131174..5cefcec 100644 --- a/src/wifi-direct-client-proxy.c +++ b/src/wifi-direct-client-proxy.c @@ -164,7 +164,12 @@ void __wfd_vconf_state_changed_cb(keynode_t *key, void *data) /* Manage */ void wifi_direct_process_manage_activation(GDBusConnection *connection, - const gchar *object_path, GVariant *parameters) + const gchar *sender, + const gchar *object_path, + const gchar *interface, + const gchar *signal, + GVariant *parameters, + gpointer user_data) { __WDC_LOG_FUNC_START__; int error_code; @@ -190,7 +195,12 @@ void wifi_direct_process_manage_activation(GDBusConnection *connection, } void wifi_direct_process_manage_deactivation(GDBusConnection *connection, - const gchar *object_path, GVariant *parameters) + const gchar *sender, + const gchar *object_path, + const gchar *interface, + const gchar *signal, + GVariant *parameters, + gpointer user_data) { __WDC_LOG_FUNC_START__; int error_code; @@ -218,7 +228,12 @@ void wifi_direct_process_manage_deactivation(GDBusConnection *connection, //LCOV_EXCL_START void wifi_direct_process_manage_connection(GDBusConnection *connection, - const gchar *object_path, GVariant *parameters) + const gchar *sender, + const gchar *object_path, + const gchar *interface, + const gchar *signal, + GVariant *parameters, + gpointer user_data) { __WDC_LOG_FUNC_START__; int error_code; @@ -249,7 +264,12 @@ void wifi_direct_process_manage_connection(GDBusConnection *connection, } void wifi_direct_process_manage_disconnection(GDBusConnection *connection, - const gchar *object_path, GVariant *parameters) + const gchar *sender, + const gchar *object_path, + const gchar *interface, + const gchar *signal, + GVariant *parameters, + gpointer user_data) { __WDC_LOG_FUNC_START__; int error_code; @@ -280,7 +300,12 @@ void wifi_direct_process_manage_disconnection(GDBusConnection *connection, } void wifi_direct_process_manage_peer_ip_assigned(GDBusConnection *connection, - const gchar *object_path, GVariant *parameters) + const gchar *sender, + const gchar *object_path, + const gchar *interface, + const gchar *signal, + GVariant *parameters, + gpointer user_data) { __WDC_LOG_FUNC_START__; char *get_str = NULL; @@ -330,7 +355,12 @@ void wifi_direct_process_manage_peer_ip_assigned(GDBusConnection *connection, } void wifi_direct_process_manage_listen_started(GDBusConnection *connection, - const gchar *object_path, GVariant *parameters) + const gchar *sender, + const gchar *object_path, + const gchar *interface, + const gchar *signal, + GVariant *parameters, + gpointer user_data) { __WDC_LOG_FUNC_START__; wifi_direct_client_info_s *client = __wfd_get_control(); @@ -349,7 +379,12 @@ void wifi_direct_process_manage_listen_started(GDBusConnection *connection, } void wifi_direct_process_manage_discovery_started(GDBusConnection *connection, - const gchar *object_path, GVariant *parameters) + const gchar *sender, + const gchar *object_path, + const gchar *interface, + const gchar *signal, + GVariant *parameters, + gpointer user_data) { __WDC_LOG_FUNC_START__; wifi_direct_client_info_s *client = __wfd_get_control(); @@ -368,7 +403,12 @@ void wifi_direct_process_manage_discovery_started(GDBusConnection *connection, } void wifi_direct_process_manage_discovery_finished(GDBusConnection *connection, - const gchar *object_path, GVariant *parameters) + const gchar *sender, + const gchar *object_path, + const gchar *interface, + const gchar *signal, + GVariant *parameters, + gpointer user_data) { __WDC_LOG_FUNC_START__; wifi_direct_client_info_s *client = __wfd_get_control(); @@ -387,7 +427,12 @@ void wifi_direct_process_manage_discovery_finished(GDBusConnection *connection, } void wifi_direct_process_manage_peer_found(GDBusConnection *connection, - const gchar *object_path, GVariant *parameters) + const gchar *sender, + const gchar *object_path, + const gchar *interface, + const gchar *signal, + GVariant *parameters, + gpointer user_data) { __WDC_LOG_FUNC_START__; const gchar *peer_mac_address = NULL; @@ -423,7 +468,12 @@ void wifi_direct_process_manage_peer_found(GDBusConnection *connection, } void wifi_direct_process_manage_peer_lost(GDBusConnection *connection, - const gchar *object_path, GVariant *parameters) + const gchar *sender, + const gchar *object_path, + const gchar *interface, + const gchar *signal, + GVariant *parameters, + gpointer user_data) { __WDC_LOG_FUNC_START__; const gchar *peer_mac_address = NULL; @@ -460,7 +510,12 @@ void wifi_direct_process_manage_peer_lost(GDBusConnection *connection, /* Group */ void wifi_direct_process_group_created(GDBusConnection *connection, - const gchar *object_path, GVariant *parameters) + const gchar *sender, + const gchar *object_path, + const gchar *interface, + const gchar *signal, + GVariant *parameters, + gpointer user_data) { __WDC_LOG_FUNC_START__; wifi_direct_client_info_s *client = __wfd_get_control(); @@ -480,7 +535,12 @@ void wifi_direct_process_group_created(GDBusConnection *connection, } void wifi_direct_process_group_destroyed(GDBusConnection *connection, - const gchar *object_path, GVariant *parameters) + const gchar *sender, + const gchar *object_path, + const gchar *interface, + const gchar *signal, + GVariant *parameters, + gpointer user_data) { __WDC_LOG_FUNC_START__; wifi_direct_client_info_s *client = __wfd_get_control(); @@ -502,7 +562,12 @@ void wifi_direct_process_group_destroyed(GDBusConnection *connection, #ifdef TIZEN_FEATURE_SERVICE_DISCOVERY /* Service */ void wifi_direct_process_service_discovery_started(GDBusConnection *connection, - const gchar *object_path, GVariant *parameters) + const gchar *sender, + const gchar *object_path, + const gchar *interface, + const gchar *signal, + GVariant *parameters, + gpointer user_data) { __WDC_LOG_FUNC_START__; wifi_direct_client_info_s *client = __wfd_get_control(); @@ -524,7 +589,12 @@ void wifi_direct_process_service_discovery_started(GDBusConnection *connection, } void wifi_direct_process_service_discovery_found(GDBusConnection *connection, - const gchar *object_path, GVariant *parameters) + const gchar *sender, + const gchar *object_path, + const gchar *interface, + const gchar *signal, + GVariant *parameters, + gpointer user_data) { __WDC_LOG_FUNC_START__; wifi_direct_service_type_e service_type; @@ -557,7 +627,12 @@ void wifi_direct_process_service_discovery_found(GDBusConnection *connection, } void wifi_direct_process_service_discovery_finished(GDBusConnection *connection, - const gchar *object_path, GVariant *parameters) + const gchar *sender, + const gchar *object_path, + const gchar *interface, + const gchar *signal, + GVariant *parameters, + gpointer user_data) { __WDC_LOG_FUNC_START__; wifi_direct_client_info_s *client = __wfd_get_control(); diff --git a/src/wifi-direct-dbus.c b/src/wifi-direct-dbus.c index 2d4107e..cc9750e 100644 --- a/src/wifi-direct-dbus.c +++ b/src/wifi-direct-dbus.c @@ -37,122 +37,117 @@ typedef struct { static __thread gdbus_connection_data gdbus_conn = {NULL, 0}; static struct { + int sub_id; const char *interface; const char *member; void (*function) (GDBusConnection *connection, + const gchar *sender, const gchar *object_path, - GVariant *parameters); + const gchar *interface, + const gchar *signal, + GVariant *parameters, + gpointer user_data); } wifi_direct_dbus_signal_map[] = { { + 0, WFD_MANAGER_MANAGE_INTERFACE, "Activation", wifi_direct_process_manage_activation }, { + 0, WFD_MANAGER_MANAGE_INTERFACE, "Deactivation", wifi_direct_process_manage_deactivation }, { + 0, WFD_MANAGER_MANAGE_INTERFACE, "Connection", wifi_direct_process_manage_connection }, { + 0, WFD_MANAGER_MANAGE_INTERFACE, "Disconnection", wifi_direct_process_manage_disconnection }, { + 0, WFD_MANAGER_MANAGE_INTERFACE, "PeerIPAssigned", wifi_direct_process_manage_peer_ip_assigned }, { + 0, WFD_MANAGER_MANAGE_INTERFACE, "DiscoveryStarted", wifi_direct_process_manage_discovery_started }, { + 0, WFD_MANAGER_MANAGE_INTERFACE, "ListenStarted", wifi_direct_process_manage_listen_started }, { + 0, WFD_MANAGER_MANAGE_INTERFACE, "DiscoveryFinished", wifi_direct_process_manage_discovery_finished }, { + 0, WFD_MANAGER_MANAGE_INTERFACE, "PeerFound", wifi_direct_process_manage_peer_found }, { + 0, WFD_MANAGER_MANAGE_INTERFACE, "PeerLost", wifi_direct_process_manage_peer_lost }, { + 0, WFD_MANAGER_GROUP_INTERFACE, "Created", wifi_direct_process_group_created }, { + 0, WFD_MANAGER_GROUP_INTERFACE, "Destroyed", wifi_direct_process_group_destroyed }, #ifdef TIZEN_FEATURE_SERVICE_DISCOVERY { + 0, WFD_MANAGER_SERVICE_INTERFACE, "DiscoveryStarted", wifi_direct_process_service_discovery_started }, { + 0, WFD_MANAGER_SERVICE_INTERFACE, "DiscoveryFound", wifi_direct_process_service_discovery_found }, { + 0, WFD_MANAGER_SERVICE_INTERFACE, "DiscoveryFinished", wifi_direct_process_service_discovery_finished }, #endif /* TIZEN_FEATURE_SERVICE_DISCOVERY */ { + 0, NULL, NULL, NULL } }; -static void _wifi_direct_dbus_signal_cb(GDBusConnection *connection, - const gchar *sender, - const gchar *object_path, - const gchar *interface, - const gchar *signal, - GVariant *parameters, - gpointer user_data) -{ - int i = 0; - - WDC_LOGD("Signal Name [%s]", signal); - DBUS_DEBUG_VARIANT(parameters); - - for (i = 0; wifi_direct_dbus_signal_map[i].member != NULL; i++) { - if (!g_strcmp0(signal, wifi_direct_dbus_signal_map[i].member) && - !g_strcmp0(interface, - wifi_direct_dbus_signal_map[i].interface) && - wifi_direct_dbus_signal_map[i].function != NULL) { - wifi_direct_dbus_signal_map[i].function(connection, - object_path, - parameters); - break; - } - } -} - GVariant *wifi_direct_dbus_method_call_sync_debug(const char* interface_name, const char* method, GVariant *params, @@ -188,8 +183,9 @@ GVariant *wifi_direct_dbus_method_call_sync_debug(const char* interface_name, gboolean wifi_direct_dbus_init(void) { GError *Error = NULL; + int i = 0; - if (gdbus_conn.signal_subscribe_id > 0) { + if (gdbus_conn.connection != NULL) { WDC_LOGI("GDbusConnection already initialized"); return TRUE; } @@ -202,32 +198,37 @@ gboolean wifi_direct_dbus_init(void) } /* subscribe signal handler */ - gdbus_conn.signal_subscribe_id = - g_dbus_connection_signal_subscribe(gdbus_conn.connection, - WFD_MANAGER_SERVICE, /* bus name */ - NULL, /* interface */ - NULL, /* member */ - WFD_MANAGER_PATH, /* object_path */ - NULL, /* arg0 */ - G_DBUS_SIGNAL_FLAGS_NONE, - _wifi_direct_dbus_signal_cb, - NULL, - NULL); - WDC_LOGI("Subscribed dbus signals [%d]", - gdbus_conn.signal_subscribe_id); + for (i = 0; wifi_direct_dbus_signal_map[i].member != NULL; i++) { + wifi_direct_dbus_signal_map[i].sub_id = + g_dbus_connection_signal_subscribe(gdbus_conn.connection, + WFD_MANAGER_SERVICE, /* bus name */ + wifi_direct_dbus_signal_map[i].interface, /* interface */ + wifi_direct_dbus_signal_map[i].member, /* member */ + WFD_MANAGER_PATH, /* object_path */ + NULL, /* arg0 */ + G_DBUS_SIGNAL_FLAGS_NONE, + wifi_direct_dbus_signal_map[i].function, + NULL, + NULL); + WDC_LOGD("Subscribed dbus signals [%d]", wifi_direct_dbus_signal_map[i].sub_id); + } return TRUE; } void wifi_direct_dbus_deinit(void) { + int i = 0; + if (gdbus_conn.connection == NULL) return; /* unsubscribe signal handler */ - g_dbus_connection_signal_unsubscribe(gdbus_conn.connection, - gdbus_conn.signal_subscribe_id); - gdbus_conn.signal_subscribe_id = 0; + for (i = 0; wifi_direct_dbus_signal_map[i].member != NULL; i++) { + g_dbus_connection_signal_unsubscribe(gdbus_conn.connection, + wifi_direct_dbus_signal_map[i].sub_id); + wifi_direct_dbus_signal_map[i].sub_id = 0; + } /* unref gdbus connection */ g_object_unref(gdbus_conn.connection); -- 2.7.4