Make wifi_direct_get_state API work without any precondition 83/72083/5
authorYu Jiung <jiung.yu@samsung.com>
Mon, 30 May 2016 11:21:01 +0000 (20:21 +0900)
committerYu Jiung <jiung.yu@samsung.com>
Mon, 13 Jun 2016 07:44:34 +0000 (16:44 +0900)
Description : wifi_direct_get_state API uses vconf to get
Wi-Fi Direct state. Applications can use this API without
triggering DBUS method or launching wfd-manager daemon

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

index b65863d..15fdb75 100755 (executable)
@@ -1219,13 +1219,9 @@ int wifi_direct_get_mac_address(char **mac_address);
  * @retval #WIFI_DIRECT_ERROR_NONE  Successful
  * @retval #WIFI_DIRECT_ERROR_INVALID_PARAMETER  Invalid parameter
  * @retval #WIFI_DIRECT_ERROR_OPERATION_FAILED  Operation failed
- * @retval #WIFI_DIRECT_ERROR_COMMUNICATION_FAILED  Communication failed
  * @retval #WIFI_DIRECT_ERROR_NOT_PERMITTED  Operation not permitted
  * @retval #WIFI_DIRECT_ERROR_NOT_SUPPORTED  Not supported
- * @retval #WIFI_DIRECT_ERROR_NOT_INITIALIZED  Not initialized
  * @retval #WIFI_DIRECT_ERROR_RESOURCE_BUSY  Device or resource busy
- * @pre Wi-Fi Direct service must be initialized by wifi_direct_initialize().
- * @see wifi_direct_initialize()
  */
 int wifi_direct_get_state(wifi_direct_state_e *state);
 
index 599ecbb..fb42254 100644 (file)
@@ -1,6 +1,6 @@
 Name:       capi-network-wifi-direct
 Summary:    Network WiFi-Direct Library
-Version:    1.2.64
+Version:    1.2.65
 Release:    1
 Group:      Network & Connectivity/API
 License:    Apache-2.0
index 283c316..ffbfb55 100755 (executable)
@@ -612,7 +612,7 @@ int wifi_direct_initialize(void)
        GError* error = NULL;
        GVariant *reply = NULL;
        bool wifi_direct_enable;
-       int state = 0;
+       bool val;
        int res = 0;
 
        if (g_client_info.is_registered == TRUE) {
@@ -639,15 +639,15 @@ int wifi_direct_initialize(void)
                return WIFI_DIRECT_ERROR_OPERATION_FAILED; //LCOV_EXCL_LINE
        }
 
-       reply = wifi_direct_dbus_method_call_sync(WFD_MANAGER_MANAGE_INTERFACE,
-                                                 "GetState", NULL, &error);
+       reply = wifi_direct_dbus_method_call_sync(WFD_MANAGER_GROUP_INTERFACE,
+                                                 "IsGroupOwner", NULL, &error);
 
        res = __net_wifidirect_gerror_to_enum(error);
        if (res != WIFI_DIRECT_ERROR_NONE)
                return res;
 
-       g_variant_get(reply, "(ii)", &res, &state);
-       WDC_LOGD("State = [%d]", state);
+       g_variant_get(reply, "(b)", &val);
+       WDC_LOGD("is group owner [%s]", val ? "YES" : "NO");
 
        g_client_info.is_registered = TRUE;
 
@@ -2746,44 +2746,42 @@ int wifi_direct_get_mac_address(char **mac_address)
        return ret;
 }
 
-
 int wifi_direct_get_state(wifi_direct_state_e *state)
 {
        __WDC_LOG_FUNC_START__;
 
        CHECK_FEATURE_SUPPORTED(WIFIDIRECT_FEATURE);
 
-       GError* error = NULL;
-       GVariant *reply = NULL;
        int val = 0;
        int ret = WIFI_DIRECT_ERROR_NONE;
 
-       if (g_client_info.is_registered == false) {
-               WDC_LOGE("Client is NOT registered");
-               __WDC_LOG_FUNC_END__;
-               return WIFI_DIRECT_ERROR_NOT_INITIALIZED;
-       }
-
        if (!state) {
                WDC_LOGE("Invalid Parameter");
                __WDC_LOG_FUNC_END__;
                return WIFI_DIRECT_ERROR_INVALID_PARAMETER;
        }
 
-       reply = wifi_direct_dbus_method_call_sync(WFD_MANAGER_MANAGE_INTERFACE,
-                                                 "GetState", NULL, &error);
-
-       ret = __net_wifidirect_gerror_to_enum(error);
-       if (ret != WIFI_DIRECT_ERROR_NONE)
-               return ret;
+       ret = vconf_get_int(VCONFKEY_WIFI_DIRECT_STATE, &val);
+       if (ret < 0) {
+               WDC_LOGE("Failed to get vconf value [%s]\n", VCONFKEY_WIFI_DIRECT_STATE);
+               __WDC_LOG_FUNC_END__;
+               return WIFI_DIRECT_ERROR_OPERATION_FAILED;
+       }
 
-       g_variant_get(reply, "(ii)", &ret, &val);
-       *state = (wifi_direct_state_e) val;
-       /* for CAPI : there is no WIFI_DIRECT_STATE_GROUP_OWNER type in CAPI */
-       if (*state == WIFI_DIRECT_STATE_GROUP_OWNER)
+       if (val == VCONFKEY_WIFI_DIRECT_ACTIVATED) {
+               *state = WIFI_DIRECT_STATE_ACTIVATED;
+       } else if (val == VCONFKEY_WIFI_DIRECT_DEACTIVATED) {
+               *state= WIFI_DIRECT_STATE_DEACTIVATED;
+       } else if (val == VCONFKEY_WIFI_DIRECT_CONNECTED) {
                *state = WIFI_DIRECT_STATE_CONNECTED;
-
-       g_variant_unref(reply);
+       } else if (val == VCONFKEY_WIFI_DIRECT_GROUP_OWNER) {
+               *state = WIFI_DIRECT_STATE_GROUP_OWNER;
+       } else if (val == VCONFKEY_WIFI_DIRECT_DISCOVERING) {
+               *state = WIFI_DIRECT_STATE_DISCOVERING;
+       } else {
+               WDC_LOGE("This state cannot be set as wifi_direct vconf state[%d]", val);
+               return WIFI_DIRECT_ERROR_OPERATION_FAILED;
+       }
 
        WDC_LOGD("State = [%d]", *state);
        WDC_LOGD("%s() return : [%d]", __func__, ret);
@@ -2791,7 +2789,6 @@ int wifi_direct_get_state(wifi_direct_state_e *state)
        return ret;
 }
 
-
 int wifi_direct_is_discoverable(bool* discoverable)
 {
        __WDC_LOG_FUNC_START__;