Replace timer_manager & timer_util with TimerManager 99/60199/2
authorMu-Woong Lee <muwoong.lee@samsung.com>
Wed, 24 Feb 2016 06:24:36 +0000 (15:24 +0900)
committerMu-Woong Lee <muwoong.lee@samsung.com>
Mon, 29 Feb 2016 02:25:30 +0000 (11:25 +0900)
Change-Id: I5dc43ccbfb90ef3025c495f0c350327d0e27aafe
Signed-off-by: Mu-Woong Lee <muwoong.lee@samsung.com>
13 files changed:
src/device/system/alarm.cpp
src/device/system/alarm.h
src/device/system/time.cpp
src/place/recognition/user_places/location_logger.cpp
src/place/recognition/user_places/location_logger.h
src/place/recognition/user_places/places_detector.cpp
src/place/recognition/user_places/places_detector.h
src/place/recognition/user_places/user_places.cpp
src/place/recognition/user_places/user_places.h
src/place/recognition/user_places/wifi_logger.cpp
src/place/recognition/user_places/wifi_logger.h
src/statistics/social/log_aggregator.cpp
src/statistics/social/log_aggregator.h

index bd800eea4a66e60e24cbedfc8c496d50b3b653a4..d1c6f2628e9fa4f4a4bd712e38822eb5dccd4705 100644 (file)
@@ -15,8 +15,6 @@
  */
 
 #include <context_mgr.h>
-#include <timer_mgr.h>
-#include <timer_util.h>
 #include "system_types.h"
 #include "alarm.h"
 
@@ -122,7 +120,7 @@ int ctx::device_status_alarm::get_arranged_day_of_week(ctx::Json& option)
 
        std::string tmp_d;
        for (int i = 0; option.getAt(NULL, DEVICE_ST_DAY_OF_WEEK, i, &tmp_d); i++) {
-               dow |= ctx::timer_util::convert_day_of_week_string_to_int(tmp_d);
+               dow |= ctx::TimerManager::dowToInt(tmp_d);
        }
        _D("Requested day of week (%#x)", dow);
 
@@ -131,14 +129,14 @@ int ctx::device_status_alarm::get_arranged_day_of_week(ctx::Json& option)
 
 ctx::device_status_alarm::ref_count_array_s::ref_count_array_s()
 {
-       memset(count, 0, sizeof(int) * MAX_DAY);
+       memset(count, 0, sizeof(int) * DAYS_PER_WEEK);
 }
 
 int ctx::device_status_alarm::merge_day_of_week(int* ref_cnt)
 {
        int day_of_week = 0;
 
-       for (int d = 0; d < MAX_DAY; ++d) {
+       for (int d = 0; d < DAYS_PER_WEEK; ++d) {
                if (ref_cnt[d] > 0) {
                        day_of_week |= (0x01 << d);
                }
@@ -150,12 +148,12 @@ int ctx::device_status_alarm::merge_day_of_week(int* ref_cnt)
 bool ctx::device_status_alarm::add(int minute, int day_of_week)
 {
        IF_FAIL_RETURN_TAG(minute >=0 && minute < 1440 &&
-                       day_of_week > 0 && day_of_week <= timer_types::EVERYDAY,
+                       day_of_week > 0 && day_of_week <= static_cast<int>(DayOfWeek::EVERYDAY),
                        false, _E, "Invalid parameter");
 
        ref_count_array_s &ref = ref_count_map[minute];
 
-       for (int d = 0; d < MAX_DAY; ++d) {
+       for (int d = 0; d < DAYS_PER_WEEK; ++d) {
                if ((day_of_week & (0x01 << d)) != 0) {
                        ref.count[d] += 1;
                }
@@ -167,12 +165,12 @@ bool ctx::device_status_alarm::add(int minute, int day_of_week)
 bool ctx::device_status_alarm::remove(int minute, int day_of_week)
 {
        IF_FAIL_RETURN_TAG(minute >=0 && minute < 1440 &&
-                       day_of_week > 0 && day_of_week <= timer_types::EVERYDAY,
+                       day_of_week > 0 && day_of_week <= static_cast<int>(DayOfWeek::EVERYDAY),
                        false, _E, "Invalid parameter");
 
        ref_count_array_s &ref = ref_count_map[minute];
 
-       for (int d = 0; d < MAX_DAY; ++d) {
+       for (int d = 0; d < DAYS_PER_WEEK; ++d) {
                if ((day_of_week & (0x01 << d)) != 0 && ref.count[d] > 0) {
                        ref.count[d] -= 1;
                }
@@ -193,7 +191,7 @@ bool ctx::device_status_alarm::reset_timer(int minute)
 
        if (day_of_week == 0 && timer.timer_id > 0) {
                /* Turn off the timer at hour, if it is not necessray anymore. */
-               timer_manager::remove(timer.timer_id);
+               __timerManager.remove(timer.timer_id);
                timer_state_map.erase(minute);
                ref_count_map.erase(minute);
                return true;
@@ -201,7 +199,7 @@ bool ctx::device_status_alarm::reset_timer(int minute)
 
        if (timer.timer_id > 0) {
                /* Turn off the current timer, to set a new one. */
-               timer_manager::remove(timer.timer_id);
+               __timerManager.remove(timer.timer_id);
                timer.timer_id = -1;
                timer.day_of_week = 0;
        }
@@ -209,7 +207,7 @@ bool ctx::device_status_alarm::reset_timer(int minute)
        /* Create a new timer, w.r.t. the new day_of_week value. */
        int h = minute / 60;
        int m = minute - h * 60;
-       int tid = timer_manager::set_at(h, m, day_of_week, this);
+       int tid = __timerManager.setAt(h, m, static_cast<DayOfWeek>(day_of_week), this);
        IF_FAIL_RETURN_TAG(tid > 0, false, _E, "Timer setting failed");
 
        timer.timer_id = tid;
@@ -222,7 +220,7 @@ void ctx::device_status_alarm::clear()
 {
        for (timer_state_map_t::iterator it = timer_state_map.begin(); it != timer_state_map.end(); ++it) {
                if (it->second.timer_id > 0) {
-                       timer_manager::remove(it->second.timer_id);
+                       __timerManager.remove(it->second.timer_id);
                }
        }
 
@@ -230,7 +228,7 @@ void ctx::device_status_alarm::clear()
        ref_count_map.clear();
 }
 
-bool ctx::device_status_alarm::on_timer_expired(int timer_id, void* user_data)
+bool ctx::device_status_alarm::onTimerExpired(int timer_id)
 {
        time_t rawtime;
        struct tm timeinfo;
@@ -254,7 +252,7 @@ void ctx::device_status_alarm::on_timer_expired(int hour, int min, int day_of_we
 
        ctx::Json data_read;
        int result_time = hour * 60 + min;
-       std::string result_day = ctx::timer_util::convert_day_of_week_int_to_string(day_of_week);
+       std::string result_day = ctx::TimerManager::dowToStr(day_of_week);
        data_read.set(NULL, DEVICE_ST_TIME_OF_DAY, result_time);
        data_read.set(NULL, DEVICE_ST_DAY_OF_WEEK, result_day);
 
index 8f518367fbb96ebd8195a723c8967a96d48a6dc8..8d640e306663e50197caf8ce60fda4568f121ecf 100644 (file)
 #include <map>
 #include <set>
 #include <provider_iface.h>
-#include <timer_listener_iface.h>
+#include <TimerManager.h>
 #include "../provider_base.h"
 
 namespace ctx {
 
-       class device_status_alarm : public context_provider_iface, timer_listener_iface {
+       class device_status_alarm : public context_provider_iface, ITimerListener {
 
                GENERATE_PROVIDER_COMMON_DECL(device_status_alarm);
 
@@ -65,6 +65,7 @@ namespace ctx {
                ref_count_map_t ref_count_map;
                timer_state_map_t timer_state_map;
                option_t option_set;
+               TimerManager __timerManager;
 
                bool add(int minute, int day_of_week);
                bool remove(int minute, int day_of_week);
@@ -74,7 +75,7 @@ namespace ctx {
                int merge_day_of_week(int *ref_cnt);
                bool reset_timer(int hour);
                void on_timer_expired(int hour, int min, int day_of_week);
-               bool on_timer_expired(int timer_id, void *user_data);
+               bool onTimerExpired(int timer_id);
 
                bool is_matched(ctx::Json& option, int time, std::string day);
                option_t::iterator find_option(ctx::Json& option);
index 65ba55a886b94475f68d78b1e4b8a17eb053d597..7f5515af54fee36f54573211adc4d16229603e4a 100644 (file)
@@ -15,7 +15,7 @@
  */
 
 #include <context_mgr.h>
-#include <timer_util.h>
+#include <TimerManager.h>
 #include "system_types.h"
 #include "time.h"
 
@@ -66,7 +66,7 @@ int ctx::device_status_time::read()
 
        int day_of_month = timeinfo.tm_mday;
        int minute_of_day = timeinfo.tm_hour * 60 + timeinfo.tm_min;
-       std::string day_of_week = ctx::timer_util::convert_day_of_week_int_to_string(0x01 << timeinfo.tm_wday);
+       std::string day_of_week = ctx::TimerManager::dowToStr(0x01 << timeinfo.tm_wday);
 
        ctx::Json data_read;
        data_read.set(NULL, DEVICE_ST_DAY_OF_MONTH, day_of_month);
index 1a5ef291485ee8e298ba28907d44fbadeb4d0251..6bee94b8f5e43a76d277e785009c7cea3e9c89e8 100644 (file)
@@ -486,7 +486,7 @@ void ctx::LocationLogger::broadcast(ctx::location_event_s location_event)
        }
 }
 
-bool ctx::LocationLogger::on_timer_expired(int id, void* user_data)
+bool ctx::LocationLogger::onTimerExpired(int id)
 {
        time_t now = time(nullptr);
        double seconds = difftime(now, timer_timestamp);
@@ -564,14 +564,14 @@ void ctx::LocationLogger::passive_interval_timer_start()
 void ctx::LocationLogger::timer_start(time_t minutes)
 {
        timer_timestamp = time(nullptr);
-       timer_id = timer_manager::set_for(minutes, this, NULL);
+       timer_id = __timerManager.setFor(minutes, this);
        _D("%s (minutes=%d) timer_id = %d", timer_id >= 0 ? "SUCCESS" : "ERROR", minutes, timer_id);
 }
 
 void ctx::LocationLogger::timer_stop()
 {
        _D("");
-       timer_manager::remove(timer_id);
+       __timerManager.remove(timer_id);
 }
 
 void ctx::LocationLogger::start_logging()
index 21bcec64c9722bf1f978f81d3e03f3c63158ed28..f27bd314edeb494c0b7616f360dc89f13f2c4935 100644 (file)
@@ -17,9 +17,8 @@
 #ifndef __CONTEXT_PLACE_STATUS_LOCATION_LOGGER_H__
 #define __CONTEXT_PLACE_STATUS_LOCATION_LOGGER_H__
 
-#include <timer_listener_iface.h>
 #include <locations.h>
-#include "timer_mgr.h"
+#include <TimerManager.h>
 #include "visit_listener_iface.h"
 #include "location_listener_iface.h"
 
@@ -63,7 +62,7 @@ namespace ctx {
                LOCATION_LOGGER_WAITING_FOR_PASSIVE_INTERVAL = 4
        } timer_purpose_e;
 
-       class LocationLogger : public timer_listener_iface, public IVisitListener {
+       class LocationLogger : public ITimerListener, public IVisitListener {
 
        public:
                LocationLogger(ILocationListener *listener_ = nullptr,
@@ -103,6 +102,7 @@ namespace ctx {
                /* TIMER */
                int timer_id;
                time_t timer_timestamp;
+               TimerManager __timerManager;
                timer_purpose_e timer_purpose;
                void set_next_timer();
                void active_request_timer_start();
@@ -111,7 +111,7 @@ namespace ctx {
                void passive_interval_timer_start();
                void timer_start(time_t minutes);
                void timer_stop();
-               bool on_timer_expired(int timer_id, void* user_data);
+               bool onTimerExpired(int timerId);
 
                /* DATABASE */
                static int create_table();
index a5163e4d9fddf6169d74d5a4742ed025c76998bf..4890db155d1cf38feecf65ab0735c783dd53d85e 100644 (file)
@@ -70,7 +70,7 @@
        PLACE_COLUMN_WIFI_APS " STRING, "\
        PLACE_COLUMN_CREATE_DATE " timestamp"
 
-bool ctx::PlacesDetector::on_timer_expired(int timer_id, void* user_data)
+bool ctx::PlacesDetector::onTimerExpired(int timerId)
 {
        _D("");
        db_delete_places();
index 9adeb920d5a2b2f7ab13813b3e5d0d41df24cab2..703f8306acd108b8b4ab2df49817e8589480ce29 100644 (file)
@@ -18,7 +18,7 @@
 #define __CONTEXT_PLACE_STATUS_PLACES_DETECTOR__
 
 #include "visit_detector.h"
-#include "timer_listener_iface.h"
+#include <ITimerListener.h>
 #include <cstdint>
 #include "db_listener_iface.h"
 #include "user_places_types.h"
@@ -36,7 +36,7 @@ namespace ctx {
                PLACES_DETECTOR_QUERY_ID_GET_PLACES = 6
        };
 
-       class PlacesDetector : public timer_listener_iface, public db_listener_iface {
+       class PlacesDetector : public ITimerListener, public db_listener_iface {
 
        private:
                bool test_mode;
@@ -65,7 +65,7 @@ namespace ctx {
                void process_visits(visits_t &visits);
                static void merge_location(const visits_t &merged_visits, Place &place);
                PlacesDetector(bool test_mode_ = false);
-               bool on_timer_expired(int timer_id, void* user_data);
+               bool onTimerExpired(int timerId);
                void on_creation_result_received(unsigned int query_id, int error) {}
                void on_insertion_result_received(unsigned int query_id, int error, int64_t row_id) {}
                void on_query_result_received(unsigned int query_id, int error, std::vector<Json>& records);
index bba0f1d2fb8469cd7cf9ecf1324ba7e649f43bcb..c0bb7369ab8841bae113f8d80072eea7a34a0180 100644 (file)
@@ -19,7 +19,6 @@
 #include <types_internal.h>
 #include "user_places.h"
 #include "places_detector.h"
-#include "timer_mgr.h"
 #include "../place_recognition_types.h"
 #include "db_mgr.h"
 
@@ -41,10 +40,10 @@ ctx::UserPlaces::UserPlaces(place_recog_mode_e energy_mode)
                return;
        }
 
-       places_detector_timer_id = timer_manager::set_at( // execute once every night
+       places_detector_timer_id = __timerManager.setAt( // execute once every night
                        PLACES_DETECTOR_TASK_START_HOUR,
                        PLACES_DETECTOR_TASK_START_MINUTE,
-                       timer_types::EVERYDAY,
+                       DayOfWeek::EVERYDAY,
                        places_detector);
        if (places_detector_timer_id < 0) {
                _E("PlacesDetector timer set FAIL");
@@ -57,7 +56,7 @@ ctx::UserPlaces::UserPlaces(place_recog_mode_e energy_mode)
 ctx::UserPlaces::~UserPlaces()
 {
        if (places_detector_timer_id >= 0) {
-               timer_manager::remove(places_detector_timer_id);
+               __timerManager.remove(places_detector_timer_id);
                _D("PlacesDetector timer removed");
        }
 
index d2c66daac0104d3379aa4e42fa487681e4aae4c4..b7084d8a7f149d77e138369c1629c86006166874 100644 (file)
 #ifndef __CONTEXT_PLACE_STATUS_USER_PLACES_ENGINE_H__
 #define __CONTEXT_PLACE_STATUS_USER_PLACES_ENGINE_H__
 
+#include <vector>
+#include <Json.h>
+#include <TimerManager.h>
 #include "visit_detector.h"
 #include "places_detector.h"
-#include <vector>
 #include "user_places_types.h"
-#include <Json.h>
 
 namespace ctx {
 
@@ -31,6 +32,7 @@ namespace ctx {
                VisitDetector *visit_detector;
                PlacesDetector *places_detector;
                int places_detector_timer_id;
+               TimerManager __timerManager;
 
        public:
                UserPlaces(place_recog_mode_e energy_mode = PLACE_RECOG_HIGH_ACCURACY_MODE);
index 92bcdd489c017b14d85f04e04bc65b0420a24cf3..5a6dfba22d0db682731df73208433f9c8c96206e 100644 (file)
@@ -337,7 +337,7 @@ bool ctx::WifiLogger::check_timer_time(time_t now)
        return true;
 }
 
-bool ctx::WifiLogger::on_timer_expired(int id, void* user_data)
+bool ctx::WifiLogger::onTimerExpired(int id)
 {
        time_t now = time(nullptr);
        _D("");
@@ -414,7 +414,7 @@ void ctx::WifiLogger::_stop_logging()
                // Unset timer
                timer_on = false;
                // Remove timer
-               timer_manager::remove(timer_id);
+               __timerManager.remove(timer_id);
        }
        if (WIFI_LOGGER_PASSIVE_SCANNING) {
                wifi_unset_background_scan_cb();
@@ -425,7 +425,7 @@ void ctx::WifiLogger::_stop_logging()
 void ctx::WifiLogger::timer_start(time_t minutes)
 {
        timer_on = true;
-       timer_id = timer_manager::set_for(minutes, this, NULL);
+       timer_id = __timerManager.setFor(minutes, this);
        _D("%s (minutes=%d)", timer_id >= 0 ? "SUCCESS" : "ERROR", minutes);
 }
 
@@ -458,7 +458,7 @@ void ctx::WifiLogger::set_interval(place_recog_mode_e energy_mode)
 
 void ctx::WifiLogger::timer_restart()
 {
-       timer_manager::remove(timer_id);
+       __timerManager.remove(timer_id);
        timer_start(interval_minutes);
 }
 
index 4db601c25105e966db19cc19eafb8e1a7e26a84d..6b9ecb6532e474e13cb5485424b18e3c88572e17 100644 (file)
 #ifndef __CONTEXT_PLACE_STATUS_WIFI_LOGGER_H__
 #define __CONTEXT_PLACE_STATUS_WIFI_LOGGER_H__
 
-#include <timer_listener_iface.h>
 #include <wifi.h>
 #include <time.h>
-#include "timer_mgr.h"
 #include <vector>
 #include <set>
+#include <TimerManager.h>
 #include "wifi_listener_iface.h"
 #include "visit_listener_iface.h"
 #include "user_places_params.h"
@@ -48,7 +47,7 @@
 
 namespace ctx {
 
-       class WifiLogger : public timer_listener_iface, public IVisitListener {
+       class WifiLogger : public ITimerListener, public IVisitListener {
 
        public:
                WifiLogger(IWifiListener * listener_ = nullptr,
@@ -78,6 +77,7 @@ namespace ctx {
                bool connected_to_wifi_ap;
                bool started;
                bool running;
+               TimerManager __timerManager;
 
                void _start_logging();
                void _stop_logging();
@@ -85,7 +85,7 @@ namespace ctx {
 
                bool check_timer_id(int id);
                bool check_timer_time(time_t now);
-               bool on_timer_expired(int timer_id, void* user_data);
+               bool onTimerExpired(int timerId);
                static int create_table();
                int db_insert_logs();
                static void wifi_device_state_changed_cb(wifi_device_state_e state, void *user_data);
index 309316f7a41f831a7afd660ac861c387f3d1ebf5..fadd8cfa43b39733047c9ec6c709b1212cd75d38 100644 (file)
@@ -17,7 +17,6 @@
 #include <sstream>
 #include <Json.h>
 #include <db_mgr.h>
-#include <timer_mgr.h>
 #include <types_internal.h>
 #include "social_stats_types.h"
 #include "log_aggregator.h"
@@ -27,12 +26,12 @@ ctx::contact_log_aggregator::contact_log_aggregator()
        , time_diff(0)
 {
        create_table();
-       timer_id = timer_manager::set_at(3, 0, timer_types::EVERYDAY, this, NULL);
+       timer_id = __timerManager.setAt(3, 0, DayOfWeek::EVERYDAY, this);
 }
 
 ctx::contact_log_aggregator::~contact_log_aggregator()
 {
-       timer_manager::remove(timer_id);
+       __timerManager.remove(timer_id);
 }
 
 void ctx::contact_log_aggregator::create_table()
@@ -46,7 +45,7 @@ void ctx::contact_log_aggregator::create_table()
        done = true;
 }
 
-bool ctx::contact_log_aggregator::on_timer_expired(int timer, void* user_data)
+bool ctx::contact_log_aggregator::onTimerExpired(int timer)
 {
        aggregate_contact_log();
        return true;
index e7aefb726fb60cbcf9177b1433ec1b0cf7629050..6f7583f8afb8b68383c3b9b89305ea0fe6fb14c5 100644 (file)
 
 #include <contacts.h>
 #include <db_listener_iface.h>
-#include <timer_listener_iface.h>
+#include <TimerManager.h>
 
 namespace ctx {
 
-       class contact_log_aggregator : public db_listener_iface, public timer_listener_iface {
+       class contact_log_aggregator : public db_listener_iface, public ITimerListener {
                private:
                        int timer_id;
                        int time_diff;
+                       TimerManager __timerManager;
                        void create_table();
                        void get_updated_contact_log_list(int last_time, contacts_list_h *list);
                        void insert_contact_log_list(contacts_list_h list);
@@ -42,7 +43,7 @@ namespace ctx {
                        void on_creation_result_received(unsigned int query_id, int error) {}
                        void on_insertion_result_received(unsigned int query_id, int error, int64_t row_id) {}
                        void on_query_result_received(unsigned int query_id, int error, std::vector<Json>& records);
-                       bool on_timer_expired(int timer_id, void* user_data);
+                       bool onTimerExpired(int timer_id);
 
        };      /* class phone_contact_log_aggregator */