Added callback CAPIs to get WiFi Module State event 09/132209/15
authorManeesh Jain <maneesh.jain@samsung.com>
Thu, 1 Jun 2017 12:54:15 +0000 (18:24 +0530)
committerManeesh Jain <maneesh.jain@samsung.com>
Thu, 22 Jun 2017 04:57:35 +0000 (10:27 +0530)
Description: Added support of following to get the Wi-Fi
Module state changed event while module insert or remove.
    1. wifi_manager_set_module_state_changed_cb()
    2. wifi_manager_unset_module_state_changed_cb()

Change-Id: Ifdfb6523383466187245013f71593d9c7aae4dee
Signed-off-by: Maneesh Jain <maneesh.jain@samsung.com>
include/wifi-manager.h
include/wifi_internal.h
src/wifi_internal.c
src/wifi_manager.c
test/wifi_manager_test.c

index 5576b8df383a4f78a8f16c5066118ac24cba4e28..a5bdf463688ffc037a5c1caff6ef17c001d742da 100755 (executable)
@@ -780,6 +780,17 @@ typedef void(*wifi_manager_connection_state_changed_cb)(wifi_manager_connection_
  */
 typedef void(*wifi_manager_rssi_level_changed_cb)(wifi_manager_rssi_level_e rssi_level, void *user_data);
 
+/**
+ * @brief Called when the Wi-Fi Module state is changed.
+ * @since_tizen 4.0
+ * @param[in] wifi_module_state    The Wi-Fi Module state
+ * @param[in] user_data            The user data passed from the callback registration function
+ * @see wifi_manager_set_module_state_changed_cb()
+ * @see wifi_manager_unset_module_state_changed_cb()
+ */
+typedef void(*wifi_manager_module_state_changed_cb)(wifi_manager_module_state_e wifi_module_state,
+               void *user_data);
+
 /**
 * @}
 */
@@ -1541,6 +1552,39 @@ int wifi_manager_set_rssi_level_changed_cb(wifi_manager_h wifi,
  */
 int wifi_manager_unset_rssi_level_changed_cb(wifi_manager_h wifi);
 
+/**
+ * @brief Registers a callback called when the Wi-Fi Module state is changed.
+ * @since_tizen 4.0
+ * @param[in] wifi            The Wi-Fi handle
+ * @param[in] callback        The callback function to be called
+ * @param[in] user_data       The user data passed to the callback function
+ * @return @c 0 on success, otherwise negative error value
+ * @retval #WIFI_MANAGER_ERROR_NONE                 Successful
+ * @retval #WIFI_MANAGER_ERROR_INVALID_OPERATION    Invalid operation
+ * @retval #WIFI_MANAGER_ERROR_INVALID_PARAMETER    Invalid parameter
+ * @retval #WIFI_MANAGER_ERROR_OPERATION_FAILED     Operation failed
+ * @retval #WIFI_MANAGER_ERROR_NOT_SUPPORTED        Not supported
+ * @see wifi_manager_module_state_changed_cb()
+ * @see wifi_manager_unset_module_state_changed_cb()
+*/
+int wifi_manager_set_module_state_changed_cb(wifi_manager_h wifi,
+               wifi_manager_module_state_changed_cb callback, void *user_data);
+
+/**
+ * @brief Unregisters the callback called when the Wi-Fi Module state is changed.
+ * @since_tizen 4.0
+ * @param[in] wifi            The Wi-Fi handle
+ * @return @c 0 on success, otherwise negative error value
+ * @retval #WIFI_MANAGER_ERROR_NONE                 Successful
+ * @retval #WIFI_MANAGER_ERROR_INVALID_OPERATION    Invalid operation
+ * @retval #WIFI_MANAGER_ERROR_INVALID_PARAMETER    Invalid parameter
+ * @retval #WIFI_MANAGER_ERROR_OPERATION_FAILED     Operation failed
+ * @retval #WIFI_MANAGER_ERROR_NOT_SUPPORTED        Not supported
+ * @see wifi_manager_module_state_changed_cb()
+ * @see wifi_manager_set_module_state_changed_cb()
+ */
+int wifi_manager_unset_module_state_changed_cb(wifi_manager_h wifi);
+
 /**
  * @brief Gets the Wi-Fi Module state.
  * @since_tizen 4.0
index e0baa4c26b9b5195e856457b3d9a8c0bfcb558f1..1b2b45270e4687b7618ec090f692c5df75448979 100755 (executable)
@@ -158,13 +158,15 @@ typedef struct {
        void *connected_user_data;
        wifi_manager_disconnected_cb disconnected_cb;
        void *disconnected_user_data;
-
        wifi_manager_rssi_level_changed_cb rssi_level_changed_cb;
        void *rssi_level_changed_user_data;
        wifi_manager_tdls_state_changed_cb tdls_state_changed_cb;
        void *tdls_state_changed_user_data;
        wifi_manager_tdls_discovered_cb tdls_discovered_cb;
        void *tdls_discovered_user_data;
+       wifi_manager_module_state_changed_cb module_state_changed_cb;
+       void *module_state_changed_user_data;
+
 } wifi_manager_handle_s;
 
 
@@ -252,6 +254,7 @@ int _wifi_set_background_scan_mode(wifi_manager_autoscan_mode_e mode);
 int _wifi_get_autoscan(bool *autoscan);
 int _wifi_get_autoscanmode(wifi_manager_autoscan_mode_e *autoscanmode);
 int _wifi_get_module_state(wifi_manager_module_state_e *state);
+void _wifi_module_state_changed_cb(keynode_t *node, void *user_data);
 
 
 
index 30ba76ffe5ce0f8981f5c6f9bdabc52bb31276a5..25fbce0b3c5c4d0a37a8897006489a8689e111ed 100755 (executable)
@@ -2233,4 +2233,35 @@ int _wifi_get_module_state(wifi_manager_module_state_e *state)
        return WIFI_MANAGER_ERROR_NONE;
 }
 
+void _wifi_module_state_changed_cb(keynode_t *node, void *user_data)
+{
+       GSList *list;
+       wifi_manager_handle_s *handle;
+       int wifi_device_status = 0;
+
+       if (net_check_ref_count() != true) {
+               WIFI_LOG(WIFI_ERROR, "Application is not registered"
+                               "If multi-threaded, thread integrity be broken.");
+               return;
+       }
+
+       for (list = wifi_manager_handle_list; list; list = list->next) {
+               handle = (wifi_manager_handle_s *)list->data;
+
+               if (__wifi_check_handle_validity((wifi_manager_h)handle) != true)
+                       return;
+
+               if (vconf_get_int(VCONFKEY_WIFI_DEVICE_STATUS_UEVENT, &wifi_device_status) < 0) {
+                       WIFI_LOG(WIFI_ERROR, "Unable to read status from vconf key\n");
+                       return;
+               }
+
+               WIFI_LOG(WIFI_ERROR, "Wi-Fi Module State [%d]\n", wifi_device_status);
+
+               if (handle->module_state_changed_cb)
+                       handle->module_state_changed_cb(wifi_device_status,
+                                       handle->module_state_changed_user_data);
+       }
+}
+
 //LCOV_EXCL_STOP
index 43069c6804b97b3e585ccb5cd6aa335bbf5cfc9b..e447074caf7bd08bd6021a84ed854d5cd319d2ba 100755 (executable)
@@ -121,6 +121,41 @@ static int __wifi_get_handle_count(void)
 {
        return _wifi_get_count_from_handle_list();
 }
+
+static int __wifi_set_module_state_changed_cb(wifi_manager_h wifi,
+                       void *callback, void *user_data)
+{
+       static __thread gint refcount = 0;
+       wifi_manager_handle_s *local_handle;
+
+       local_handle = (wifi_manager_handle_s *)wifi;
+
+       if (callback) {
+               if (refcount == 0)
+                       vconf_notify_key_changed(VCONFKEY_WIFI_DEVICE_STATUS_UEVENT,
+                                       _wifi_module_state_changed_cb, NULL);
+
+               refcount++;
+               WIFI_LOG(WIFI_INFO, "Successfully registered(%d)", refcount);
+       } else {
+               if (refcount > 0 && local_handle->module_state_changed_cb) {
+                       if (--refcount == 0) {
+                               if (vconf_ignore_key_changed(VCONFKEY_WIFI_DEVICE_STATUS_UEVENT,
+                                               _wifi_module_state_changed_cb) < 0) {
+                                       WIFI_LOG(WIFI_ERROR, "Error to de-register vconf callback(%d)", refcount);
+                               } else {
+                                       WIFI_LOG(WIFI_INFO, "Successfully de-registered(%d)", refcount);
+                               }
+                       }
+               }
+       }
+
+       local_handle->module_state_changed_cb = callback;
+       local_handle->module_state_changed_user_data = user_data;
+
+       return WIFI_MANAGER_ERROR_NONE;
+}
+
 //LCOV_EXCL_STOP
 
 EXPORT_API int wifi_manager_initialize(wifi_manager_h *wifi)
@@ -846,12 +881,48 @@ EXPORT_API int wifi_manager_get_autoscan_mode(wifi_manager_h wifi,
 }
 //LCOV_EXCL_STOP
 
+EXPORT_API int wifi_manager_set_module_state_changed_cb(wifi_manager_h wifi,
+                    wifi_manager_module_state_changed_cb callback, void* user_data)
+{
+
+       CHECK_FEATURE_SUPPORTED(WIFI_FEATURE);
+
+       if (_get_tizen_profile() != TIZEN_PROFILE_TV)
+               return WIFI_MANAGER_ERROR_NOT_SUPPORTED;
+
+       if (callback == NULL || !(__wifi_check_handle_validity(wifi))) {
+               WIFI_LOG(WIFI_ERROR, "Invalid parameter"); //LCOV_EXCL_LINE
+               return WIFI_MANAGER_ERROR_INVALID_PARAMETER; //LCOV_EXCL_LINE
+       }
+
+       return __wifi_set_module_state_changed_cb(wifi, callback, user_data);
+
+}
+
+EXPORT_API int wifi_manager_unset_module_state_changed_cb(wifi_manager_h wifi)
+{
+       CHECK_FEATURE_SUPPORTED(WIFI_FEATURE);
+
+       if (_get_tizen_profile() != TIZEN_PROFILE_TV)
+               return WIFI_MANAGER_ERROR_NOT_SUPPORTED;
+
+       if (!(__wifi_check_handle_validity(wifi))) {
+               WIFI_LOG(WIFI_ERROR, "Invalid parameter"); //LCOV_EXCL_LINE
+               return WIFI_MANAGER_ERROR_INVALID_PARAMETER; //LCOV_EXCL_LINE
+       }
+
+       return __wifi_set_module_state_changed_cb(wifi, NULL, NULL);
+}
+
 EXPORT_API int wifi_manager_get_module_state(wifi_manager_h wifi,
                                        wifi_manager_module_state_e *state)
 
 {
        CHECK_FEATURE_SUPPORTED(WIFI_FEATURE);
 
+       if (_get_tizen_profile() != TIZEN_PROFILE_TV)
+               return WIFI_MANAGER_ERROR_NOT_SUPPORTED;
+
        if (state == NULL || !(__wifi_check_handle_validity(wifi))) {
                WIFI_LOG(WIFI_ERROR, "Invalid parameter"); //LCOV_EXCL_LINE
                return WIFI_MANAGER_ERROR_INVALID_PARAMETER; //LCOV_EXCL_LINE
index 9c6a281b62966b4fab08b9bf11bdc6558972f35b..0cecc86c486c0030f9444df2df772045c301730f 100755 (executable)
@@ -212,6 +212,16 @@ static void __test_tdls_discover_callback(wifi_manager_tdls_discovery_state_e st
                printf(", Discovery is finished");
 }
 
+static void __test_get_wifi_module_state_callback(wifi_manager_module_state_e state, void *user_data)
+{
+       printf("Wi-Fi Module State Changed callback : %d", state);
+
+       if (state == WIFI_MANAGER_MODULE_STATE_ATTACHED)
+               printf(", Wi-Fi Module Attached\n");
+       else
+               printf(", Wi-Fi Module Detached\n");
+}
+
 static void __test_tdls_state_callback(wifi_manager_tdls_state_e state, char *peer_mac_add, void *user_data)
 {
        printf("[%s] TDLS state changed callback", (char *)user_data);
@@ -1256,6 +1266,8 @@ int test_wifi_manager_init(void)
                wifi_manager_set_rssi_level_changed_cb(wifi, __test_rssi_level_callback, "1");
                wifi_manager_tdls_set_state_changed_cb(wifi, __test_tdls_state_callback, "1");
                wifi_manager_tdls_set_discovered_cb(wifi, __test_tdls_discover_callback, "1");
+               wifi_manager_set_module_state_changed_cb(wifi, __test_get_wifi_module_state_callback, "1");
+
        } else {
                printf("[1] Wifi init failed [%s]\n", __test_convert_error_to_string(rv));
                return -1;
@@ -1270,6 +1282,7 @@ int test_wifi_manager_init(void)
                wifi_manager_set_rssi_level_changed_cb(wifi2, __test_rssi_level_callback, "2");
                wifi_manager_tdls_set_state_changed_cb(wifi2, __test_tdls_state_callback, "2");
                wifi_manager_tdls_set_discovered_cb(wifi, __test_tdls_discover_callback, "2");
+               wifi_manager_set_module_state_changed_cb(wifi, __test_get_wifi_module_state_callback, "2");
        } else {
                printf("[2] Wifi init failed [%s]\n", __test_convert_error_to_string(rv));
                return -1;