Modify WiFi context provider to keep ctx::shared::wifi_bssid up-to-date. 08/47708/1
authorSomin Kim <somin926.kim@samsung.com>
Tue, 8 Sep 2015 06:22:04 +0000 (15:22 +0900)
committerSomin Kim <somin926.kim@samsung.com>
Tue, 8 Sep 2015 06:22:04 +0000 (15:22 +0900)
Change-Id: I3a1b478d921662380b58db26db13f9bb6735423c
Signed-off-by: Mu-Woong <muwoong.lee@samsung.com>
Signed-off-by: Somin Kim <somin926.kim@samsung.com>
src/device_context_provider.cpp
src/device_status/wifi.cpp
src/device_status/wifi.h

index d0665fe..c2c7fba 100644 (file)
@@ -102,5 +102,8 @@ EXTAPI bool ctx::init_device_context_provider()
        register_provider<user_activity_in_vehicle>(USER_ACT_SUBJ_IN_VEHICLE, NULL);
 #endif
 
+       /* Create context providers, which need to be initiated before being subscribed */
+       device_status_wifi::create(NULL);
+
        return true;
 }
index 6064b74..fa6ae49 100644 (file)
  * limitations under the License.
  */
 
+#include <shared_vars.h>
 #include <context_mgr.h>
 #include "device_status_types.h"
 #include "wifi.h"
 
-GENERATE_PROVIDER_COMMON_IMPL(device_status_wifi);
+ctx::device_status_wifi *ctx::device_status_wifi::__instance = NULL;
 
 ctx::device_status_wifi::device_status_wifi()
        : last_state(_UNKNOWN)
        , is_initialized(false)
        , is_activated(false)
 {
+       IF_FAIL_VOID_TAG(start_monitor(), _W, "WiFi monitor initialization failed");
+
+       if (!get_current_state()) {
+               stop_monitor();
+               _W("Getting current WiFi status failed");
+       }
 }
 
 ctx::device_status_wifi::~device_status_wifi()
 {
 }
 
+ctx::context_provider_iface *ctx::device_status_wifi::create(void *data)
+{
+       CREATE_INSTANCE(device_status_wifi);
+}
+
+void ctx::device_status_wifi::destroy(void *data)
+{
+       __instance->stop_monitor();
+       DESTROY_INSTANCE();
+}
+
+void ctx::device_status_wifi::destroy_self()
+{
+       /* WiFi status will be monitored continuously, even if no client is subscribing it */
+}
+
 bool ctx::device_status_wifi::is_supported()
 {
        return get_system_info_bool("tizen.org/feature/network.wifi");
@@ -67,9 +90,11 @@ bool ctx::device_status_wifi::get_current_state()
                        get_bssid();
                } else {
                        last_state = _UNCONNECTED;
+                       clear_bssid();
                }
        } else {
                last_state = _DISABLED;
+               clear_bssid();
        }
 
        if (!is_initialized)
@@ -96,9 +121,19 @@ bool ctx::device_status_wifi::get_bssid()
        if (bssid.empty())
                _W("Failed to get BSSID");
 
+       ctx::shared::wifi_bssid = bssid;
+       _D("BSSID: %s", bssid.c_str());
+
        return !bssid.empty();
 }
 
+void ctx::device_status_wifi::clear_bssid()
+{
+       bssid.clear();
+       ctx::shared::wifi_bssid.clear();
+       _D("No WiFi connection");
+}
+
 bool ctx::device_status_wifi::get_response_packet(ctx::json &data)
 {
        switch (last_state) {
@@ -170,18 +205,22 @@ void ctx::device_status_wifi::stop_monitor()
 
 int ctx::device_status_wifi::subscribe()
 {
+#if 0
        IF_FAIL_RETURN(start_monitor(), ERR_OPERATION_FAILED);
        if (!get_current_state()) {
                stop_monitor();
                return ERR_OPERATION_FAILED;
        }
+#endif
 
        return ERR_NONE;
 }
 
 int ctx::device_status_wifi::unsubscribe()
 {
+#if 0
        stop_monitor();
+#endif
        return ERR_NONE;
 }
 
@@ -200,11 +239,14 @@ void ctx::device_status_wifi::aggregate_updated_data()
        }
 
        if (last_state != prev_state) {
-               if (last_state == _CONNECTED)
+               if (last_state == _CONNECTED) {
                        get_bssid();
+               } else {
+                       clear_bssid();
+               }
 
                ctx::json data;
-               if (get_response_packet(data))
+               if (being_subscribed && get_response_packet(data))
                        context_manager::publish(DEVICE_ST_SUBJ_WIFI, NULL, ERR_NONE, data);
        }
 }
index 2fff2ba..6dc505d 100644 (file)
@@ -53,6 +53,7 @@ namespace ctx {
 
                bool get_current_state();
                bool get_bssid();
+               void clear_bssid();
                bool get_response_packet(json &data);
                void aggregate_updated_data();
                bool start_monitor();