Add user_data in wifi_mesh_event_cb 18/148818/1
authorSaurav Babu <saurav.babu@samsung.com>
Mon, 11 Sep 2017 03:23:55 +0000 (08:53 +0530)
committerSaurav Babu <saurav.babu@samsung.com>
Mon, 11 Sep 2017 03:23:55 +0000 (08:53 +0530)
Change-Id: I884101ffd3f55b57679b395754bafc7ac49372a2
Signed-off-by: Saurav Babu <saurav.babu@samsung.com>
include/wifi-mesh.h
include/wifi-mesh_dbus.h
include/wifi-mesh_private.h
src/wifi-mesh-dbus.c
src/wifi-mesh.c
test/main.c
test/wifi-mesh-device.c

index 99b778382456a1630a713779f4f644a0fee97c3f..e0abd9738934259c46b6d59523538b06eb7b9afa 100644 (file)
@@ -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.
index 8e878d2d33a76bd8fb3f44586e771c4540b5f311..3eb46b5a17e821033cf682672bd2c5dee5752b36 100644 (file)
@@ -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);
index d7b975c0222f3d1c87eb2c354b3cdf421b7a761d..d4c3e7367ac26cc2553dbd9b41878dffb112d1e6 100644 (file)
@@ -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
  */
index 3cdddd55aff3f40816af57402ebbeb1a178f1edb..02821efad2076706e6387b2c7b7eb78552d33517 100644 (file)
@@ -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;
 }
 
index f59da7e2c5559a696d475b7c4326fb10606f88ff..be35e73a1447ae08e19121d69613ad29b71dd9ce 100644 (file)
@@ -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;
 }
 
index 1aa3c4600c5cb7ee169621ef9ccd223830dcdb52..3af4b5966b59f477a5fc7fe3954a36999c978d76 100644 (file)
@@ -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));
index c5f4d442f4233932fa36095ca8772416a9bacf53..ad19d9adcdbe0e91a434ae6bd5dae15d56c06708 100644 (file)
@@ -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);