add gathering stop function
authorJeonghoon Park <jh1979.park@samsung.com>
Mon, 27 Aug 2018 11:01:46 +0000 (20:01 +0900)
committerJeonghoon Park <jh1979.park@samsung.com>
Mon, 27 Aug 2018 11:01:46 +0000 (20:01 +0900)
src/co2.c

index 7af53b9..82d164f 100644 (file)
--- a/src/co2.c
+++ b/src/co2.c
@@ -91,19 +91,25 @@ static Eina_Bool __get_co2(void *data)
        return ECORE_CALLBACK_RENEW;
 }
 
-static void gathering_start(void *data)
+static void gathering_stop(void *data)
 {
        app_data *ad = data;
        ret_if(!ad);
 
-       if (ad->getter_co2)
+       if (ad->getter_co2) {
                ecore_timer_del(ad->getter_co2);
+               ad->getter_co2 = NULL;
+       }
+}
+
+static void gathering_start(void *data)
+{
+       app_data *ad = data;
+       ret_if(!ad);
 
        ad->getter_co2 = ecore_timer_add(SENSOR_GATHER_INTERVAL, __get_co2, ad);
        if (!ad->getter_co2)
                _E("Failed to add getter_co2");
-
-       return;
 }
 
 #ifdef USE_ST_SDK
@@ -130,6 +136,8 @@ static void handle_things_status_change(st_things_status_e things_status)
 
        if (things_status == ST_THINGS_STATUS_REGISTERED_TO_CLOUD)
                ecore_main_loop_thread_safe_call_async(gathering_start, g_ad);
+       else
+               ecore_main_loop_thread_safe_call_async(gathering_stop, g_ad);
 }
 
 static bool handle_get_request(st_things_get_request_message_s* req_msg, st_things_representation_s* resp_rep)
@@ -245,8 +253,10 @@ static bool service_app_create(void *user_data)
 static void service_app_control(app_control_h app_control, void *user_data)
 {
 #ifdef USE_ST_SDK
+       __things_stop();
        __things_start();
 #else
+       gathering_stop(user_data);
        gathering_start(user_data);
 #endif
 }
@@ -258,9 +268,6 @@ static void service_app_terminate(void *user_data)
        if (!ad)
                return;
 
-       if (ad->getter_co2)
-               ecore_timer_del(ad->getter_co2);
-
 #ifdef USE_ST_SDK
        __things_stop();
        __things_deinit();