From: Niraj Kumar Goit Date: Fri, 10 Mar 2017 09:19:58 +0000 (+0530) Subject: Added handling to notify scan started event. X-Git-Tag: submit/tizen/20170324.043751~1^2 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=51e8dc11075bfc56f7f4fd1c547cf2242f5bc672;p=platform%2Fcore%2Fapi%2Fwifi-manager.git Added handling to notify scan started event. Change-Id: I8cdf07f461218f7c286edbdb945cc7ffc39bb70d Signed-off-by: Niraj Kumar Goit --- diff --git a/include/network_interface.h b/include/network_interface.h index 3a13463..cf66c54 100755 --- a/include/network_interface.h +++ b/include/network_interface.h @@ -51,6 +51,7 @@ typedef enum { NET_EVENT_NET_STATE_IND, NET_EVENT_WIFI_SCAN_RSP, NET_EVENT_WIFI_SCAN_IND, + NET_EVENT_WIFI_SCAN_STARTED, NET_EVENT_WIFI_MAC_ID_IND, /** This is deprecated Event and maintained only for compatibility */ NET_EVENT_WIFI_POWER_RSP, NET_EVENT_WIFI_POWER_IND, diff --git a/include/network_internal.h b/include/network_internal.h index 05dfa40..d17c5fd 100755 --- a/include/network_internal.h +++ b/include/network_internal.h @@ -85,6 +85,7 @@ extern "C" { #define SIGNAL_TECHNOLOGY_REMOVED "TechnologyRemoved" #define SIGNAL_SERVICES_CHANGED "ServicesChanged" #define SIGNAL_SCAN_DONE "ScanDone" +#define SIGNAL_SCAN_STARTED "ScanStarted" #define CONNMAN_WIFI_TECHNOLOGY_PREFIX CONNMAN_PATH "/technology/wifi" diff --git a/include/wifi-manager.h b/include/wifi-manager.h index 87567dc..a9139ed 100755 --- a/include/wifi-manager.h +++ b/include/wifi-manager.h @@ -198,6 +198,15 @@ typedef enum { WIFI_MANAGER_RSSI_LEVEL_4 = 4, /**< level 4 */ } wifi_manager_rssi_level_e; +/** + * @brief Enumeration for the wifi scanning state. + * @since_tizen 4.0 + */ +typedef enum { + WIFI_MANAGER_SCAN_STATE_NOT_SCANNING = 0, /**< Scan is not running */ + WIFI_MANAGER_SCAN_STATE_SCANNING = 1, /**< Scan is in progress */ +} wifi_manager_scan_state_e; + /** * @} */ @@ -623,6 +632,16 @@ typedef bool(*wifi_manager_found_ap_cb)(wifi_manager_ap_h ap, void *user_data); */ typedef void(*wifi_manager_scan_finished_cb)(wifi_manager_error_e error_code, void *user_data); +/** + * @brief Called when the scanning state is changed. + * @since_tizen 4.0 + * @param[in] scan_state The wifi scanning status + * @param[in] user_data The user data passed from the callback registration function + * @see wifi_manager_set_scan_state_changed_cb() + * @see wifi_manager_unset_scan_state_changed_cb() + */ +typedef void(*wifi_manager_scan_state_changed_cb)(wifi_manager_scan_state_e state, void *user_data); + /** * @brief Called after wifi_manager_activate() or wifi_manager_activate_with_wifi_picker_tested() is completed. * @since_tizen 3.0 @@ -1372,6 +1391,33 @@ int wifi_manager_set_background_scan_cb(wifi_manager_h wifi, */ int wifi_manager_unset_background_scan_cb(wifi_manager_h wifi); +/** + * @brief Registers the callback called when the scanning state is changed. + * @since_tizen 4.0 + * @param[in] wifi The wifi handle + * @param[in] callback The callback function to be called + * @param[in] user_data The user data passed to the callback function + * @return 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_NOT_SUPPORTED Not supported + */ +int wifi_manager_set_scan_state_changed_cb(wifi_manager_h wifi, + wifi_manager_scan_state_changed_cb callback, void *user_data); + +/** + * @brief Unregisters the callback called when the scanning state is changed. + * @since_tizen 4.0 + * @param[in] wifi The wifi handle + * @return 0 on success, otherwise negative error value + * @retval #WIFI_MANAGER_ERROR_NONE Successful + * @retval #WIFI_MANAGER_ERROR_INVALID_PARAMETER Invalid parameter + * @retval #WIFI_MANAGER_ERROR_INVALID_OPERATION Invalid operation + * @retval #WIFI_MANAGER_ERROR_NOT_SUPPORTED Not supported + */ +int wifi_manager_unset_scan_state_changed_cb(wifi_manager_h wifi); + /** * @brief Registers the callback called when the connection state is changed. * @since_tizen 3.0 diff --git a/include/wifi_internal.h b/include/wifi_internal.h index 3d9e3e0..a59fc12 100755 --- a/include/wifi_internal.h +++ b/include/wifi_internal.h @@ -88,6 +88,7 @@ typedef enum { WIFI_DEVICE_STATE_CB, WIFI_BG_SCAN_CB, WIFI_SCAN_REQUEST_CB, + WIFI_SCAN_STARTED_CB, WIFI_SPECIFIC_SCAN_CB, WIFI_MANAGER_CONNECTION_STATE_CB, WIFI_ACTIVATED_CB, @@ -140,6 +141,8 @@ typedef struct { void *bg_scan_user_data; wifi_manager_scan_finished_cb scan_request_cb; void *scan_request_user_data; + wifi_manager_scan_state_changed_cb scan_started_cb; + void *scan_started_user_data; wifi_manager_scan_finished_cb specific_scan_cb; void *specific_scan_user_data; wifi_manager_connection_state_changed_cb connection_state_cb; diff --git a/src/network_signal.c b/src/network_signal.c index 32a4577..324ea8c 100755 --- a/src/network_signal.c +++ b/src/network_signal.c @@ -27,6 +27,7 @@ static __thread int net_service_error = NET_ERR_NONE; static __thread guint gdbus_conn_subscribe_id_connman_state = 0; static __thread guint gdbus_conn_subscribe_id_connman_error = 0; static __thread guint gdbus_conn_subscribe_id_connman_scandone = 0; +static __thread guint gdbus_conn_subscribe_id_connman_scanstarted = 0; static __thread guint gdbus_conn_subscribe_id_netconfig_wifi = 0; static __thread guint gdbus_conn_subscribe_id_netconfig = 0; static __thread int net_dpm_wifi_state = -1; @@ -615,6 +616,20 @@ static int __net_handle_service_set_error(const char *key, const char *error) return NET_ERR_NONE; } +static int __net_handle_scan_started(GVariant *param) +{ + net_event_info_s event_data = { 0, }; + + event_data.Event = NET_EVENT_WIFI_SCAN_STARTED; + event_data.Error = NET_ERR_NONE; + event_data.Datalength = 0; + event_data.Data = NULL; + + _net_client_callback(&event_data); + + return NET_ERR_NONE; +} + static int __net_handle_scan_done(GVariant *param) { net_event_info_s event_data = { 0, }; @@ -854,7 +869,9 @@ static void __net_connman_manager_signal_filter(GDBusConnection *conn, const gchar *name, const gchar *path, const gchar *interface, const gchar *sig, GVariant *param, gpointer user_data) { - if (g_strcmp0(sig, SIGNAL_SCAN_DONE) == 0) + if (g_strcmp0(sig, SIGNAL_SCAN_STARTED) == 0) + __net_handle_scan_started(param); + else if (g_strcmp0(sig, SIGNAL_SCAN_DONE) == 0) __net_handle_scan_done(param); } @@ -1001,6 +1018,8 @@ int _net_deregister_signal(void) gdbus_conn_subscribe_id_connman_error); g_dbus_connection_signal_unsubscribe(connection, gdbus_conn_subscribe_id_connman_scandone); + g_dbus_connection_signal_unsubscribe(connection, + gdbus_conn_subscribe_id_connman_scanstarted); g_dbus_connection_signal_unsubscribe(connection, gdbus_conn_subscribe_id_netconfig_wifi); g_dbus_connection_signal_unsubscribe(connection, @@ -1087,6 +1106,19 @@ int _net_register_signal(void) NULL, NULL); + /* Create connman service scanstarted connection */ + gdbus_conn_subscribe_id_connman_scanstarted = g_dbus_connection_signal_subscribe( + connection, + CONNMAN_SERVICE, + CONNMAN_MANAGER_INTERFACE, + "ScanStarted", + CONNMAN_MANAGER_PATH, + NULL, + G_DBUS_SIGNAL_FLAGS_NONE, + __net_connman_manager_signal_filter, + NULL, + NULL); + /* Create net-config service connection */ gdbus_conn_subscribe_id_netconfig_wifi = g_dbus_connection_signal_subscribe( connection, @@ -1104,6 +1136,7 @@ int _net_register_signal(void) gdbus_conn_subscribe_id_connman_error == 0 || gdbus_conn_subscribe_id_netconfig == 0 || gdbus_conn_subscribe_id_connman_scandone == 0 || + gdbus_conn_subscribe_id_connman_scanstarted == 0 || gdbus_conn_subscribe_id_netconfig_wifi == 0) { WIFI_LOG(WIFI_ERROR, "Failed register signals " //LCOV_EXCL_LINE "connman_state(%d), connman_error(%d), netconfig(%d), " @@ -1112,6 +1145,7 @@ int _net_register_signal(void) gdbus_conn_subscribe_id_connman_error, gdbus_conn_subscribe_id_netconfig, gdbus_conn_subscribe_id_connman_scandone, + gdbus_conn_subscribe_id_connman_scanstarted, gdbus_conn_subscribe_id_netconfig_wifi); Error = NET_ERR_NOT_SUPPORTED; //LCOV_EXCL_LINE } diff --git a/src/wifi_internal.c b/src/wifi_internal.c index a68423a..7aab542 100755 --- a/src/wifi_internal.c +++ b/src/wifi_internal.c @@ -574,6 +574,32 @@ static void __scan_cb(net_event_info_s *event_cb, bool is_requested) } } +static void __scan_started_cb(net_event_info_s *event_cb) +{ + GSList *list; + wifi_manager_scan_state_e scan_state; + + if (net_check_ref_count() != true) { + WIFI_LOG(WIFI_ERROR, "Application is not registered" + "If multi-threaded, thread integrity be broken."); + return; + } + + if (event_cb->Error != NET_ERR_NONE) { + WIFI_LOG(WIFI_ERROR, "Scan failed[%d]", event_cb->Error); + scan_state = WIFI_MANAGER_SCAN_STATE_NOT_SCANNING; + } else + scan_state = WIFI_MANAGER_SCAN_STATE_SCANNING; + + if (_wifi_get_callback_count_from_handle_list(WIFI_SCAN_STARTED_CB)) { + for (list = wifi_manager_handle_list; list; list = list->next) { + wifi_manager_handle_s *local_handle = (wifi_manager_handle_s *)list->data; + if (local_handle->scan_started_cb) + local_handle->scan_started_cb(scan_state, local_handle->scan_started_user_data); + } + } +} + static void __specific_scan_cb(net_event_info_s *event_cb) { GSList *list; @@ -815,6 +841,10 @@ static void _wifi_evt_cb(net_event_info_s *event_cb, void *user_data) WIFI_LOG(WIFI_INFO, "Got Wi-Fi specific scan IND\n"); __specific_scan_cb(event_cb); break; + case NET_EVENT_WIFI_SCAN_STARTED: + WIFI_LOG(WIFI_INFO, "Got Wi-Fi scan started event\n"); + __scan_started_cb(event_cb); + break; case NET_EVENT_WIFI_POWER_RSP: is_requested = true; /* fall through */ @@ -896,6 +926,10 @@ int _wifi_get_callback_count_from_handle_list(wifi_manager_handle_cb_e e) if (local_handle->bg_scan_cb) ++count; break; + case WIFI_SCAN_STARTED_CB: + if (local_handle->scan_started_cb) + ++count; + break; case WIFI_SCAN_REQUEST_CB: if (local_handle->scan_request_cb) ++count; diff --git a/src/wifi_manager.c b/src/wifi_manager.c index 5a79fb4..f0d5a9a 100755 --- a/src/wifi_manager.c +++ b/src/wifi_manager.c @@ -61,6 +61,17 @@ static int __wifi_set_background_scan_cb(wifi_manager_h wifi, return WIFI_MANAGER_ERROR_NONE; } +static int __wifi_set_scan_state_changed_cb(wifi_manager_h wifi, + void *callback, void *user_data) +{ + wifi_manager_handle_s *local_handle = (wifi_manager_handle_s *)wifi; + + local_handle->scan_started_cb = callback; + local_handle->scan_started_user_data = user_data; + + return WIFI_MANAGER_ERROR_NONE; +} + static int __wifi_set_connection_state_changed_cb(wifi_manager_h wifi, void *callback, void *user_data) { @@ -607,6 +618,31 @@ EXPORT_API int wifi_manager_unset_background_scan_cb(wifi_manager_h wifi) return __wifi_set_background_scan_cb(wifi, NULL, NULL); } +EXPORT_API int wifi_manager_set_scan_state_changed_cb(wifi_manager_h wifi, + wifi_manager_scan_state_changed_cb callback, void* user_data) +{ + CHECK_FEATURE_SUPPORTED(WIFI_FEATURE); + + 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_scan_state_changed_cb(wifi, callback, user_data); +} + +EXPORT_API int wifi_manager_unset_scan_state_changed_cb(wifi_manager_h wifi) +{ + CHECK_FEATURE_SUPPORTED(WIFI_FEATURE); + + 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_scan_state_changed_cb(wifi, NULL, NULL); +} + EXPORT_API int wifi_manager_set_connection_state_changed_cb(wifi_manager_h wifi, wifi_manager_connection_state_changed_cb callback, void *user_data) { diff --git a/test/wifi_manager_test.c b/test/wifi_manager_test.c index f7a9867..2682f59 100755 --- a/test/wifi_manager_test.c +++ b/test/wifi_manager_test.c @@ -105,6 +105,11 @@ static void __test_device_state_callback(wifi_manager_device_state_e state, void printf(", state : Deactivated\n"); } +static void __test_scan_started_callback(wifi_manager_scan_state_e state, void* user_data) +{ + printf("Scan Started, scan state : %d\n", state); +} + static void __test_bg_scan_completed_callback(wifi_manager_error_e error_code, void* user_data) { printf("[%s] Background Scan Completed, error code : %s\n", @@ -1095,6 +1100,7 @@ int test_wifi_manager_init(void) if (rv == WIFI_MANAGER_ERROR_NONE) { wifi_manager_set_device_state_changed_cb(wifi, __test_device_state_callback, "1"); + wifi_manager_set_scan_state_changed_cb(wifi, __test_scan_started_callback, "1"); wifi_manager_set_background_scan_cb(wifi, __test_bg_scan_completed_callback, "1"); wifi_manager_set_connection_state_changed_cb(wifi, __test_connection_state_callback, "1"); wifi_manager_set_rssi_level_changed_cb(wifi, __test_rssi_level_callback, "1");