Add set callback API to get Wi-Fi Direct state using vconf 84/72084/10
authorYu Jiung <jiung.yu@samsung.com>
Mon, 30 May 2016 11:25:50 +0000 (20:25 +0900)
committertaesubkim <taesub.kim@samsung.com>
Thu, 16 Jun 2016 04:24:42 +0000 (13:24 +0900)
Description : Add following APIs which don't need to
invoke wfd-manager daemon to get Wi-Fi Direct state
wifi_direct_set_state_changed_cb()
wifi_direct_unset_state_changed_cb()

Change-Id: I74ac2d17b768386a5083cbf9bbba29366fdafdb3
Signed-off-by: Yu jiung <jiung.yu@samsung.com>
include/wifi-direct.h
packaging/capi-network-wifi-direct.spec
src/include/wifi-direct-client-proxy.h
src/wifi-direct-client-proxy.c
test/test-wifi-direct.c

index 15fdb75..21afc89 100755 (executable)
@@ -443,6 +443,19 @@ typedef void (*wifi_direct_service_state_changed_cb) (int error_code,
                                                const char *mac_address, void *user_data);
 
 /**
+ * @brief Called when the state of Wi-FI Direct is changed.
+ * @since_tizen 3.0
+ * @param[in] state  The Wi-Fi Direct state
+ * @param[in] user_data  The user data passed from the callback registration function
+ * @pre Changes in Wi-Fi Direct state will invoke this callback
+ * if you register this callback using wifi_direct_set_state_changed_cb().
+ * @see wifi_direct_set_state_changed_cb()
+ * @see wifi_direct_unset_state_changed_cb()
+ */
+typedef void (*wifi_direct_state_changed_cb)  (wifi_direct_state_e state,
+               void *user_data);
+
+/**
  * @brief Initializes Wi-Fi Direct service.
  * @since_tizen 2.3
  * @privlevel public
@@ -640,6 +653,30 @@ int wifi_direct_set_service_state_changed_cb(wifi_direct_service_state_changed_c
 int wifi_direct_unset_service_state_changed_cb(void);
 
 /**
+ * @brief Registers the callback called when the state of Wi-Fi Direct is changed.
+ * @since_tizen 3.0
+ * @param[in] cb  The callback function to invoke
+ * @param[in] user_data  The user data to be passed to the callback function
+ * @return 0 on success, otherwise a negative error value
+ * @retval #WIFI_DIRECT_ERROR_NONE  Successful
+ * @retval #WIFI_DIRECT_ERROR_INVALID_PARAMETER  Invalid parameter
+ * @retval #WIFI_DIRECT_ERROR_OPERATION_FAILED Operation Failed
+ * @see wifi_direct_unset_state_changed_cb()
+ */
+int wifi_direct_set_state_changed_cb(wifi_direct_state_changed_cb cb, void *user_data);
+
+/**
+ * @brief Unregisters the callback called when the state of Wi-Fi Direct is changed.
+ * @since_tizen 3.0
+ * @return 0 on success, otherwise a negative error value
+ * @retval #WIFI_DIRECT_ERROR_NONE  Successful
+ * @retval #WIFI_DIRECT_ERROR_OPERATION_FAILED Operation Failed
+ * @see wifi_direct_initialize()
+ * @see wifi_direct_set_state_changed_cb()
+ */
+int wifi_direct_unset_state_changed_cb(void);
+
+/**
  * @brief Activates the Wi-Fi Direct service, asynchronous.
  * @since_tizen 2.3
  * @privlevel public
index fb42254..ef98f3c 100644 (file)
@@ -1,6 +1,6 @@
 Name:       capi-network-wifi-direct
 Summary:    Network WiFi-Direct Library
-Version:    1.2.65
+Version:    1.2.66
 Release:    1
 Group:      Network & Connectivity/API
 License:    Apache-2.0
index 764359b..f04bde2 100755 (executable)
@@ -63,6 +63,7 @@ typedef struct {
        wifi_direct_connection_state_changed_cb connection_cb;
        wifi_direct_client_ip_address_assigned_cb ip_assigned_cb;
        wifi_direct_peer_found_cb peer_found_cb;
+       wifi_direct_state_changed_cb state_cb;
 
        void *user_data_for_cb_activation;
        void *user_data_for_cb_discover;
@@ -70,6 +71,7 @@ typedef struct {
        void *user_data_for_cb_ip_assigned;
        void *user_data_for_cb_peer_found;
        void *user_data_for_cb_device_name;
+       void *user_data_for_cb_state;
 
 #ifdef TIZEN_FEATURE_SERVICE_DISCOVERY
        wifi_direct_service_state_changed_cb service_cb;
index ffbfb55..8edcfcc 100755 (executable)
@@ -67,6 +67,7 @@
 /*****************************************************************************
  *  Global Variables
  *****************************************************************************/
+
 wifi_direct_client_info_s g_client_info = {
        .is_registered = FALSE,
        .client_id = -1,
@@ -77,12 +78,14 @@ wifi_direct_client_info_s g_client_info = {
        .connection_cb = NULL,
        .ip_assigned_cb = NULL,
        .peer_found_cb = NULL,
+       .state_cb = NULL,
        .user_data_for_cb_activation = NULL,
        .user_data_for_cb_discover = NULL,
        .user_data_for_cb_connection = NULL,
        .user_data_for_cb_ip_assigned = NULL,
        .user_data_for_cb_peer_found = NULL,
        .user_data_for_cb_device_name = NULL,
+       .user_data_for_cb_state = NULL,
 #ifdef TIZEN_FEATURE_SERVICE_DISCOVERY
        .service_cb = NULL,
        .user_data_for_cb_service = NULL,
@@ -139,6 +142,47 @@ static int __net_wifidirect_gerror_to_enum(GError* error)
        return ret;
 }
 
+void __wfd_vconf_state_changed_cb(keynode_t *key, void *data)
+{
+       __WDC_LOG_FUNC_START__;
+       int state = 0;
+       int res = 0;
+
+       if (!g_client_info.state_cb) {
+               WDC_LOGI("g_state_cb is NULL!!");
+               __WDC_LOG_FUNC_END__;
+               return; //LCOV_EXCL_LINE
+       }
+
+       res = vconf_get_int(VCONFKEY_WIFI_DIRECT_STATE, &state);
+       if (res < 0) {
+               WDC_LOGE("Failed to get vconf value [%s]\n", VCONFKEY_WIFI_DIRECT_STATE);
+               __WDC_LOG_FUNC_END__;
+               return;
+       }
+
+       if (state == VCONFKEY_WIFI_DIRECT_ACTIVATED) {
+               state = WIFI_DIRECT_STATE_ACTIVATED;
+       } else if (state == VCONFKEY_WIFI_DIRECT_DEACTIVATED) {
+               state = WIFI_DIRECT_STATE_DEACTIVATED;
+       } else if (state == VCONFKEY_WIFI_DIRECT_CONNECTED) {
+               state = WIFI_DIRECT_STATE_CONNECTED;
+       } else if (state == VCONFKEY_WIFI_DIRECT_GROUP_OWNER) {
+               state = WIFI_DIRECT_STATE_GROUP_OWNER;
+       } else if (state == VCONFKEY_WIFI_DIRECT_DISCOVERING) {
+               state = WIFI_DIRECT_STATE_DISCOVERING;
+       } else {
+               WDC_LOGE("This state cannot be set as wifi_direct vconf state[%d]", state);
+               __WDC_LOG_FUNC_END__;
+               return;
+       }
+
+       g_client_info.state_cb(state, g_client_info.user_data_for_cb_state);
+
+       __WDC_LOG_FUNC_END__;
+       return;
+}
+
 /* Manage */
 void wifi_direct_process_manage_activation(GDBusConnection *connection,
                const gchar *object_path, GVariant *parameters)
@@ -1001,6 +1045,56 @@ int wifi_direct_unset_client_ip_address_assigned_cb(void)
        return WIFI_DIRECT_ERROR_NONE;
 }
 
+int wifi_direct_set_state_changed_cb(wifi_direct_state_changed_cb cb, void *user_data)
+{
+       __WDC_LOG_FUNC_START__;
+       int ret = WIFI_DIRECT_ERROR_NONE;
+
+       CHECK_FEATURE_SUPPORTED(WIFIDIRECT_FEATURE);
+
+       if (!cb) {
+               WDC_LOGE("Callback is NULL");
+               __WDC_LOG_FUNC_END__;
+               return WIFI_DIRECT_ERROR_INVALID_PARAMETER;
+       }
+
+       ret = vconf_notify_key_changed(VCONFKEY_WIFI_DIRECT_STATE,
+                       __wfd_vconf_state_changed_cb, NULL);
+       if (ret) {
+               WDC_LOGE("Failed to set vconf notification callback");
+               __WDC_LOG_FUNC_END__;
+               return WIFI_DIRECT_ERROR_OPERATION_FAILED;
+       }
+
+       g_client_info.state_cb = cb;
+       g_client_info.user_data_for_cb_state = user_data;
+
+       __WDC_LOG_FUNC_END__;
+       return WIFI_DIRECT_ERROR_NONE;
+}
+
+int wifi_direct_unset_state_changed_cb(void)
+{
+       __WDC_LOG_FUNC_START__;
+       int ret = WIFI_DIRECT_ERROR_NONE;
+
+       CHECK_FEATURE_SUPPORTED(WIFIDIRECT_FEATURE);
+
+       ret = vconf_ignore_key_changed(VCONFKEY_WIFI_DIRECT_STATE,
+                       __wfd_vconf_state_changed_cb);
+       if (ret) {
+               WDC_LOGE("Failed to ignore vconf notification callback");
+               __WDC_LOG_FUNC_END__;
+               return WIFI_DIRECT_ERROR_OPERATION_FAILED;
+       }
+
+       g_client_info.state_cb = NULL;
+       g_client_info.user_data_for_cb_state = NULL;
+
+       __WDC_LOG_FUNC_END__;
+       return WIFI_DIRECT_ERROR_NONE;
+}
+
 int wifi_direct_activate(void)
 {
        __WDC_LOG_FUNC_START__;
@@ -2771,7 +2865,7 @@ int wifi_direct_get_state(wifi_direct_state_e *state)
        if (val == VCONFKEY_WIFI_DIRECT_ACTIVATED) {
                *state = WIFI_DIRECT_STATE_ACTIVATED;
        } else if (val == VCONFKEY_WIFI_DIRECT_DEACTIVATED) {
-               *state= WIFI_DIRECT_STATE_DEACTIVATED;
+               *state = WIFI_DIRECT_STATE_DEACTIVATED;
        } else if (val == VCONFKEY_WIFI_DIRECT_CONNECTED) {
                *state = WIFI_DIRECT_STATE_CONNECTED;
        } else if (val == VCONFKEY_WIFI_DIRECT_GROUP_OWNER) {
index 5b7b2fc..26bd399 100755 (executable)
@@ -127,12 +127,14 @@ enum {
        CMD_SET_CONNECTION_CB,
        CMD_SET_PEER_FOUND_CB,
        CMD_SET_DEVICE_NAME_CB,
+       CMD_SET_STATE_CB,
        CMD_UNSET_ACTIVATION_CB,
        CMD_UNSET_DISCOVER_CB,
        CMD_UNSET_SERVICE_CB,
        CMD_UNSET_CONNECTION_CB,
        CMD_UNSET_PEER_FOUND_CB,
        CMD_UNSET_DEVICE_NAME_CB,
+       CMD_UNSET_STATE_CB,
        CMD_GET_NETWORK_IF_NAME,
        CMD_GET_SUBNET_MASK,
        CMD_GET_GATEWAY_ADDR,
@@ -238,10 +240,12 @@ menu_str_t g_menu_str[] = {
                { CMD_SET_CONNECTION_CB, "CMD_SET_CONNECTION_CB" },
                { CMD_SET_PEER_FOUND_CB, "CMD_SET_PEER_FOUND_CB" },
                { CMD_SET_DEVICE_NAME_CB, "CMD_SET_DEVICE_NAME_CB"},
+               { CMD_SET_STATE_CB, "CMD_SET_STATE_CB"},
                { CMD_UNSET_ACTIVATION_CB, "CMD_UNSET_ACTIVATION_CB" },
                { CMD_UNSET_DISCOVER_CB, "CMD_UNSET_DISCOVER_CB" },
                { CMD_UNSET_CONNECTION_CB, "CMD_UNSET_CONNECTION_CB" },
                { CMD_UNSET_PEER_FOUND_CB, "CMD_UNSET_PEER_FOUND_CB" },
+               { CMD_UNSET_STATE_CB, "CMD_UNSET_STATE_CB" },
                { CMD_GET_NETWORK_IF_NAME, "CMD_GET_NETWORK_IF_NAME" },
                { CMD_GET_SUBNET_MASK, "CMD_GET_SUBNET_MASK" },
                { CMD_GET_GATEWAY_ADDR, "CMD_GET_GATEWAY_ADDR" },
@@ -1048,6 +1052,13 @@ bool _cb_foreach_supported_wps_impl(wifi_direct_wps_type_e type, void* user_data
        return true; /* continue with the next iteration of the loop */
 }
 
+void _cb_state_changed(wifi_direct_state_e state,
+               void *user_data)
+{
+       printf("State Changed [%s]\n", print_link_state(state));
+       return;
+}
+
 int init_wfd_client(struct appdata *ad)
 {
        int ret;
@@ -1073,6 +1084,9 @@ int init_wfd_client(struct appdata *ad)
        ret = wifi_direct_set_peer_found_cb(_cb_peer_found, (void*)ad);
        printf("wifi_direct_set_peer_found_cb() result=[%d]\n", ret);
 
+       ret = wifi_direct_set_state_changed_cb(_cb_state_changed, (void*)ad);
+       printf("wifi_direct_set_state_changed_cb() result=[%d]\n", ret);
+
        return ret;
 }
 
@@ -1165,7 +1179,18 @@ void process_input(const char *input, gpointer user_data)
                printf("wifi_direct_unset_peer_found_cb() result=[%d]\n", result);
        }
        break;
-
+       case CMD_SET_STATE_CB:
+       {
+               result = wifi_direct_set_state_changed_cb(_cb_state_changed, (void*)ad);
+               printf("wifi_direct_set_state_changed_cb() result=[%d]\n", result);
+       }
+       break;
+       case CMD_UNSET_STATE_CB:
+       {
+               result = wifi_direct_unset_state_changed_cb();
+               printf("wifi_direct_unset_state_changed_cb() result=[%d]\n", result);
+       }
+       break;
        case CMD_DEINITIALIZE:
                result = wifi_direct_deinitialize();
                printf("wifi_direct_deinitialize() result=[%d]\n", result);