From 97ab0167c2f062d89096af00fd01895d4e98938a Mon Sep 17 00:00:00 2001 From: Saurav Babu Date: Mon, 11 Sep 2017 08:53:55 +0530 Subject: [PATCH] Add user_data in wifi_mesh_event_cb Change-Id: I884101ffd3f55b57679b395754bafc7ac49372a2 Signed-off-by: Saurav Babu --- include/wifi-mesh.h | 8 ++++++-- include/wifi-mesh_dbus.h | 3 ++- include/wifi-mesh_private.h | 1 + src/wifi-mesh-dbus.c | 19 +++++++++++++------ src/wifi-mesh.c | 5 +++-- test/main.c | 3 ++- test/wifi-mesh-device.c | 5 +++-- 7 files changed, 30 insertions(+), 14 deletions(-) diff --git a/include/wifi-mesh.h b/include/wifi-mesh.h index 99b7783..e0abd97 100644 --- a/include/wifi-mesh.h +++ b/include/wifi-mesh.h @@ -651,12 +651,14 @@ int wifi_mesh_deinitialize(wifi_mesh_h handle); * * @param[out] event_type The event identification * @param[out] event parameter data pointer + * @param[in] user_data The user data passed from callback registration function * * @pre The callback must be registered with wifi_mesh_enable() * * @see wifi_mesh_set_event_cb() */ -typedef void (*wifi_mesh_event_cb)(wifi_mesh_event_e event_type, wifi_mesh_event_data_s* event); +typedef void (*wifi_mesh_event_cb)(wifi_mesh_event_e event_type, + wifi_mesh_event_data_s* event, void *user_data); /** * @brief Sets event handler for the Wi-Fi mesh network service. @@ -666,6 +668,7 @@ typedef void (*wifi_mesh_event_cb)(wifi_mesh_event_e event_type, wifi_mesh_event * * @param[in] handle The Wi-Fi mesh handle * @param[in] event_handler The event handler + * @param[in] user_data The user data to be paased to event handler * * @return 0 on success, otherwise a negative error value. * @retval #WIFI_MESH_ERROR_NONE Successful @@ -677,7 +680,8 @@ typedef void (*wifi_mesh_event_cb)(wifi_mesh_event_e event_type, wifi_mesh_event * @see wifi_mesh_deinitialize() * */ -int wifi_mesh_set_event_cb(wifi_mesh_h handle, wifi_mesh_event_cb event_handler); +int wifi_mesh_set_event_cb(wifi_mesh_h handle, + wifi_mesh_event_cb event_handler, void *user_data); /** * @brief Enable the Wi-Fi mesh service. diff --git a/include/wifi-mesh_dbus.h b/include/wifi-mesh_dbus.h index 8e878d2..3eb46b5 100644 --- a/include/wifi-mesh_dbus.h +++ b/include/wifi-mesh_dbus.h @@ -37,7 +37,8 @@ extern "C" { int _mesh_dbus_start(wifi_mesh_h m); int _mesh_dbus_stop(wifi_mesh_h m); -int _wifi_mesh_set_event_cb(wifi_mesh_h handle, wifi_mesh_event_cb event_handler); +int _wifi_mesh_set_event_cb(wifi_mesh_h handle, + wifi_mesh_event_cb event_handler, void *user_data); int _wifi_mesh_enable(wifi_mesh_h handle); int _wifi_mesh_disable(wifi_mesh_h handle); int _wifi_mesh_scan(wifi_mesh_h handle); diff --git a/include/wifi-mesh_private.h b/include/wifi-mesh_private.h index d7b975c..d4c3e73 100644 --- a/include/wifi-mesh_private.h +++ b/include/wifi-mesh_private.h @@ -56,6 +56,7 @@ typedef struct mesh_handle { GCancellable *ca; GList *dbus_sub_ids; wifi_mesh_event_cb event_handler; + void *event_handler_user_data; /* TODO: Below members are related with event callback * Need to be considered */ diff --git a/src/wifi-mesh-dbus.c b/src/wifi-mesh-dbus.c index 3cdddd5..02821ef 100644 --- a/src/wifi-mesh-dbus.c +++ b/src/wifi-mesh-dbus.c @@ -357,10 +357,12 @@ static void _mesh_signal_handler(GDBusConnection *connection, ev.data.wifi_mesh_enable->result = __convert_service_error_type(result); - h->event_handler(WIFI_MESH_EVENT_ENABLED, &ev); + h->event_handler(WIFI_MESH_EVENT_ENABLED, &ev, + h->event_handler_user_data); free(ev.data.wifi_mesh_enable); } else if (0 == g_strcmp0(signal_name, "scan_done")) { - h->event_handler(WIFI_MESH_EVENT_SCAN_DONE, NULL); + h->event_handler(WIFI_MESH_EVENT_SCAN_DONE, NULL, + h->event_handler_user_data); } else if (0 == g_strcmp0(signal_name, "connection_state")) { char *mesh_id = NULL; char *bssid = NULL; @@ -380,7 +382,8 @@ static void _mesh_signal_handler(GDBusConnection *connection, ev.data.connection_state->security = (wifi_mesh_security_type_e)security; ev.data.connection_state->state = (wifi_mesh_connection_state_e)state; - h->event_handler(WIFI_MESH_EVENT_CONNECTION_STATE, &ev); + h->event_handler(WIFI_MESH_EVENT_CONNECTION_STATE, &ev, + h->event_handler_user_data); free(ev.data.connection_state); } else if (0 == g_strcmp0(signal_name, "sta_joined")) { char *bssid = NULL; @@ -390,7 +393,8 @@ static void _mesh_signal_handler(GDBusConnection *connection, LOGE("Failed to memory allocation !"); // LCOV_EXCL_LINE g_variant_get(parameters, "(s)", &bssid); memcpy(ev.data.sta_info->bssid, bssid, MAX_BSSID_LEN); - h->event_handler(WIFI_MESH_EVENT_STATION_JOIN, &ev); + h->event_handler(WIFI_MESH_EVENT_STATION_JOIN, &ev, + h->event_handler_user_data); free(ev.data.sta_info); } else if (0 == g_strcmp0(signal_name, "sta_left")) { char *bssid = NULL; @@ -401,7 +405,8 @@ static void _mesh_signal_handler(GDBusConnection *connection, LOGE("Failed to memory allocation !"); // LCOV_EXCL_LINE g_variant_get(parameters, "(s)", &bssid); memcpy(ev.data.sta_info->bssid, bssid, MAX_BSSID_LEN); - h->event_handler(WIFI_MESH_EVENT_STATION_LEFT, &ev); + h->event_handler(WIFI_MESH_EVENT_STATION_LEFT, &ev, + h->event_handler_user_data); free(ev.data.sta_info); } } @@ -585,13 +590,15 @@ static void _mesh_remove_mpath() g_mpath.count = 0; } -int _wifi_mesh_set_event_cb(wifi_mesh_h handle, wifi_mesh_event_cb event_handler) +int _wifi_mesh_set_event_cb(wifi_mesh_h handle, + wifi_mesh_event_cb event_handler, void *user_data) { struct mesh_handle *h = handle; /* LCOV_EXCL_START */ RETV_IF(NULL == h, WIFI_MESH_ERROR_INVALID_PARAMETER); /* LCOV_EXCL_STOP */ h->event_handler = event_handler; + h->event_handler_user_data = user_data; return WIFI_MESH_ERROR_NONE; } diff --git a/src/wifi-mesh.c b/src/wifi-mesh.c index f59da7e..be35e73 100644 --- a/src/wifi-mesh.c +++ b/src/wifi-mesh.c @@ -491,7 +491,8 @@ EXPORT_API int wifi_mesh_deinitialize(wifi_mesh_h handle) return rv; } -EXPORT_API int wifi_mesh_set_event_cb(wifi_mesh_h handle, wifi_mesh_event_cb event_handler) +EXPORT_API int wifi_mesh_set_event_cb(wifi_mesh_h handle, + wifi_mesh_event_cb event_handler, void *user_data) { int rv = 0; CHECK_FEATURE_SUPPORTED(MESH_FEATURE); @@ -503,7 +504,7 @@ EXPORT_API int wifi_mesh_set_event_cb(wifi_mesh_h handle, wifi_mesh_event_cb eve /* LCOV_EXCL_STOP */ } - rv = _wifi_mesh_set_event_cb(handle, event_handler); + rv = _wifi_mesh_set_event_cb(handle, event_handler, user_data); return rv; } diff --git a/test/main.c b/test/main.c index 1aa3c46..3af4b59 100644 --- a/test/main.c +++ b/test/main.c @@ -86,7 +86,8 @@ const char* wifi_mesh_connection_event_to_string(wifi_mesh_connection_state_e e) } } -void event_cb(wifi_mesh_event_e event_type, wifi_mesh_event_data_s* event) +void event_cb(wifi_mesh_event_e event_type, wifi_mesh_event_data_s* event, + void *user_data) { msg(""); msgp("Event received [%s]", _wifi_mesh_event_to_string(event_type)); diff --git a/test/wifi-mesh-device.c b/test/wifi-mesh-device.c index c5f4d44..ad19d9a 100644 --- a/test/wifi-mesh-device.c +++ b/test/wifi-mesh-device.c @@ -28,7 +28,8 @@ #include "common.h" extern wifi_mesh_h mesh; -extern void event_cb(wifi_mesh_event_e event_type, wifi_mesh_event_data_s* event); +extern void event_cb(wifi_mesh_event_e event_type, + wifi_mesh_event_data_s* event, void *user_data); static int run_mesh_create(MManager *mm, struct menu_data *menu) { @@ -67,7 +68,7 @@ static int run_wifi_mesh_enable(MManager *mm, struct menu_data *menu) int ret; msg("enable"); - ret = wifi_mesh_set_event_cb(mesh, event_cb); + ret = wifi_mesh_set_event_cb(mesh, event_cb, NULL); if (WIFI_MESH_ERROR_NONE != ret) { msgr("Failed to set callback for mesh network: [%s(0x%X)]", wifi_mesh_error_to_string(ret), ret); -- 2.34.1