Added handling to notify scan started event. 31/118431/5
authorNiraj Kumar Goit <niraj.g@samsung.com>
Fri, 10 Mar 2017 09:19:58 +0000 (14:49 +0530)
committerNiraj Kumar Goit <niraj.g@samsung.com>
Tue, 21 Mar 2017 04:25:38 +0000 (21:25 -0700)
Change-Id: I8cdf07f461218f7c286edbdb945cc7ffc39bb70d
Signed-off-by: Niraj Kumar Goit <niraj.g@samsung.com>
include/network_interface.h
include/network_internal.h
include/wifi-manager.h
include/wifi_internal.h
src/network_signal.c
src/wifi_internal.c
src/wifi_manager.c
test/wifi_manager_test.c

index 3a13463bb5d3bcc0d51b9f9ce4c3c20d88377ad8..cf66c54fd68a755ee9d2cbd7b57d331f2c80a311 100755 (executable)
@@ -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,
index 05dfa4076e407ff27d620317cf88969972d9e0fc..d17c5fda762bffa6e8966ce506852af315c8778f 100755 (executable)
@@ -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"
 
index 87567dca1155986981ef21e1152b7008561f0d0d..a9139ed3d75bdef0923f6c9ca8aabd254f845ce6 100755 (executable)
@@ -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
index 3d9e3e020c99f6133a246645ab8a19ea9dd99378..a59fc124df32f357c81bbc4c93317d0ab7588cf9 100755 (executable)
@@ -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;
index 32a45777ed72c452b580c19f7c0b463c8de41383..324ea8cf3d9ba81e815c48c235a048bf56b01ff6 100755 (executable)
@@ -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
        }
index a68423abcc2f7221649d7cf3e5ae47cec719b1d3..7aab542e3888718218f0193b9d958fc21bd59f4a 100755 (executable)
@@ -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;
index 5a79fb4ed43831da3fac100c2dcf33113bc3dc54..f0d5a9aa556099f6e9169443f1c888c86df61c64 100755 (executable)
@@ -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)
 {
index f7a98679a3e7d36068854c145aebf5bdf665ffd3..2682f592f968dee1dad9f7aac4ba0de583e0648e 100755 (executable)
@@ -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");