From: Maneesh Jain Date: Thu, 1 Jun 2017 12:54:15 +0000 (+0530) Subject: Added callback CAPIs to get WiFi Module State event X-Git-Tag: submit/tizen/20170703.005838^2 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=65c7d425b5ab9352ef4a823f879fe87d3228c7fc;p=platform%2Fcore%2Fapi%2Fwifi-manager.git Added callback CAPIs to get WiFi Module State event 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 --- diff --git a/include/wifi-manager.h b/include/wifi-manager.h index 5576b8d..a5bdf46 100755 --- a/include/wifi-manager.h +++ b/include/wifi-manager.h @@ -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 diff --git a/include/wifi_internal.h b/include/wifi_internal.h index e0baa4c..1b2b452 100755 --- a/include/wifi_internal.h +++ b/include/wifi_internal.h @@ -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); diff --git a/src/wifi_internal.c b/src/wifi_internal.c index 30ba76f..25fbce0 100755 --- a/src/wifi_internal.c +++ b/src/wifi_internal.c @@ -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 diff --git a/src/wifi_manager.c b/src/wifi_manager.c index 43069c6..e447074 100755 --- a/src/wifi_manager.c +++ b/src/wifi_manager.c @@ -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 diff --git a/test/wifi_manager_test.c b/test/wifi_manager_test.c index 9c6a281..0cecc86 100755 --- a/test/wifi_manager_test.c +++ b/test/wifi_manager_test.c @@ -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;