Update WifiStateProvider to use WifiWrapper instead the Wifi Native API directly 11/69611/1
authorMu-Woong Lee <muwoong.lee@samsung.com>
Mon, 16 May 2016 06:24:19 +0000 (15:24 +0900)
committerMu-Woong Lee <muwoong.lee@samsung.com>
Mon, 16 May 2016 06:24:19 +0000 (15:24 +0900)
Wifi Native API does not support multiple sessions in one process.
The wrapper is a walkaround of this limitation.

Change-Id: I249294e6675446979a74a9877507e408cb1ff3ac
Signed-off-by: Mu-Woong Lee <muwoong.lee@samsung.com>
src/wifi/Wifi.cpp
src/wifi/Wifi.h

index ff501bf..9ebcdfe 100644 (file)
@@ -23,7 +23,6 @@ using namespace ctx;
 WifiStateProvider::WifiStateProvider() :
        BasicProvider(SUBJ_STATE_WIFI),
        __lastState(UNKNOWN),
-       __isInitialized(false),
        __isActivated(false),
        __connState(WIFI_CONNECTION_STATE_FAILURE)
 {
@@ -54,16 +53,11 @@ bool WifiStateProvider::__getCurrentState()
 {
        int err;
 
-       if (!__isInitialized) {
-               err = wifi_initialize();
-               IF_FAIL_RETURN_TAG(err == WIFI_ERROR_NONE, false, _E, "wifi_initialize() failed");
-       }
-
-       err = wifi_is_activated(&__isActivated);
-       IF_FAIL_RETURN_TAG(err == WIFI_ERROR_NONE, false, _E, "wifi_is_activated() failed");
+       err = __wrapper.isActivated(&__isActivated);
+       IF_FAIL_RETURN_TAG(err == WIFI_ERROR_NONE, false, _E, "isActivated() failed");
 
-       err = wifi_get_connection_state(&__connState);
-       IF_FAIL_RETURN_TAG(err == WIFI_ERROR_NONE, false, _E, "wifi_get_connection_state() failed");
+       err = __wrapper.getConnectionState(&__connState);
+       IF_FAIL_RETURN_TAG(err == WIFI_ERROR_NONE, false, _E, "getConnectionState() failed");
 
        if (__isActivated) {
                if (__connState == WIFI_CONNECTION_STATE_CONNECTED) {
@@ -78,9 +72,6 @@ bool WifiStateProvider::__getCurrentState()
                __clearBssid();
        }
 
-       if (!__isInitialized)
-               wifi_deinitialize();
-
        return true;
 }
 
@@ -90,14 +81,14 @@ bool WifiStateProvider::__getBssid()
        char *strBuf = NULL;
        wifi_ap_h ap = NULL;
 
-       err = wifi_get_connected_ap(&ap);
-       IF_FAIL_RETURN_TAG(err == WIFI_ERROR_NONE, false, _E, "wifi_get_connected_ap() failed");
+       err = __wrapper.getConnectedAP(&ap);
+       IF_FAIL_RETURN_TAG(err == WIFI_ERROR_NONE, false, _E, "getConnectedAP() failed");
 
-       wifi_ap_get_bssid(ap, &strBuf);
+       __wrapper.getBssidFromAP(ap, &strBuf);
        __bssid = (strBuf != NULL ? strBuf : "");
        g_free(strBuf);
 
-       wifi_ap_destroy(ap);
+       __wrapper.destroyAP(ap);
 
        if (__bssid.empty())
                _W("Failed to get BSSID");
@@ -153,34 +144,21 @@ int WifiStateProvider::read()
 
 bool WifiStateProvider::__startMonitor()
 {
-       IF_FAIL_RETURN(!__isInitialized, true);
-
        int err;
-       err = wifi_initialize();
-       IF_FAIL_RETURN_TAG(err == WIFI_ERROR_NONE, false, _E, "wifi_initialize() failed");
 
-       err = wifi_set_device_state_changed_cb(__deviceStateChangedCb, this);
-       IF_FAIL_CATCH_TAG(err == WIFI_ERROR_NONE, _E, "wifi_set_device_state_changed_cb() failed");
+       err = __wrapper.setDeviceStateChangedCb(__deviceStateChangedCb, this);
+       IF_FAIL_RETURN_TAG(err == WIFI_ERROR_NONE, false, _E, "setDeviceStateChangedCb() failed");
 
-       err = wifi_set_connection_state_changed_cb(__connectionStateChangedCb, this);
-       IF_FAIL_CATCH_TAG(err == WIFI_ERROR_NONE, _E, "wifi_set_connection_state_changed_cb() failed");
+       err = __wrapper.setConnectionStateChangedCb(__connectionStateChangedCb, this);
+       IF_FAIL_RETURN_TAG(err == WIFI_ERROR_NONE, false, _E, "setConnectionStateChangedCb() failed");
 
-       __isInitialized = true;
        return true;
-
-CATCH:
-       wifi_deinitialize();
-       return false;
 }
 
 void WifiStateProvider::__stopMonitor()
 {
-       IF_FAIL_VOID(__isInitialized);
-
-       wifi_unset_device_state_changed_cb();
-       wifi_unset_connection_state_changed_cb();
-       wifi_deinitialize();
-       __isInitialized = false;
+       __wrapper.unsetDeviceStateChangedCb();
+       __wrapper.unsetConnectionStateChangedCb();
 }
 
 int WifiStateProvider::subscribe()
index 22695ca..360facb 100644 (file)
@@ -18,9 +18,9 @@
 #define _CONTEXT_WIFI_STATE_PROVIDER_H_
 
 #include <string>
-#include <wifi.h>
 #include <BasicProvider.h>
 #include <ProviderTypes.h>
+#include <WifiWrapper.h>
 
 namespace ctx {
 
@@ -45,10 +45,10 @@ namespace ctx {
                };
 
                int __lastState;
-               bool __isInitialized;
                bool __isActivated;
                wifi_connection_state_e __connState;
                std::string __bssid;
+               WifiWrapper __wrapper;
 
                bool __getCurrentState();
                bool __getBssid();