From 2cfeeeed9120711c0b1dab359e22602b904b1866 Mon Sep 17 00:00:00 2001 From: Mu-Woong Lee Date: Wed, 24 Feb 2016 15:24:36 +0900 Subject: [PATCH] Replace timer_manager & timer_util with TimerManager Change-Id: I5dc43ccbfb90ef3025c495f0c350327d0e27aafe Signed-off-by: Mu-Woong Lee --- src/device/system/alarm.cpp | 28 +++++++++---------- src/device/system/alarm.h | 7 +++-- src/device/system/time.cpp | 4 +-- .../user_places/location_logger.cpp | 6 ++-- .../recognition/user_places/location_logger.h | 8 +++--- .../user_places/places_detector.cpp | 2 +- .../recognition/user_places/places_detector.h | 6 ++-- .../recognition/user_places/user_places.cpp | 7 ++--- .../recognition/user_places/user_places.h | 6 ++-- .../recognition/user_places/wifi_logger.cpp | 8 +++--- .../recognition/user_places/wifi_logger.h | 8 +++--- src/statistics/social/log_aggregator.cpp | 7 ++--- src/statistics/social/log_aggregator.h | 7 +++-- 13 files changed, 52 insertions(+), 52 deletions(-) diff --git a/src/device/system/alarm.cpp b/src/device/system/alarm.cpp index bd800ee..d1c6f26 100644 --- a/src/device/system/alarm.cpp +++ b/src/device/system/alarm.cpp @@ -15,8 +15,6 @@ */ #include -#include -#include #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(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(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(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); diff --git a/src/device/system/alarm.h b/src/device/system/alarm.h index 8f51836..8d640e3 100644 --- a/src/device/system/alarm.h +++ b/src/device/system/alarm.h @@ -20,12 +20,12 @@ #include #include #include -#include +#include #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); diff --git a/src/device/system/time.cpp b/src/device/system/time.cpp index 65ba55a..7f5515a 100644 --- a/src/device/system/time.cpp +++ b/src/device/system/time.cpp @@ -15,7 +15,7 @@ */ #include -#include +#include #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); diff --git a/src/place/recognition/user_places/location_logger.cpp b/src/place/recognition/user_places/location_logger.cpp index 1a5ef29..6bee94b 100644 --- a/src/place/recognition/user_places/location_logger.cpp +++ b/src/place/recognition/user_places/location_logger.cpp @@ -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() diff --git a/src/place/recognition/user_places/location_logger.h b/src/place/recognition/user_places/location_logger.h index 21bcec6..f27bd31 100644 --- a/src/place/recognition/user_places/location_logger.h +++ b/src/place/recognition/user_places/location_logger.h @@ -17,9 +17,8 @@ #ifndef __CONTEXT_PLACE_STATUS_LOCATION_LOGGER_H__ #define __CONTEXT_PLACE_STATUS_LOCATION_LOGGER_H__ -#include #include -#include "timer_mgr.h" +#include #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(); diff --git a/src/place/recognition/user_places/places_detector.cpp b/src/place/recognition/user_places/places_detector.cpp index a5163e4..4890db1 100644 --- a/src/place/recognition/user_places/places_detector.cpp +++ b/src/place/recognition/user_places/places_detector.cpp @@ -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(); diff --git a/src/place/recognition/user_places/places_detector.h b/src/place/recognition/user_places/places_detector.h index 9adeb92..703f830 100644 --- a/src/place/recognition/user_places/places_detector.h +++ b/src/place/recognition/user_places/places_detector.h @@ -18,7 +18,7 @@ #define __CONTEXT_PLACE_STATUS_PLACES_DETECTOR__ #include "visit_detector.h" -#include "timer_listener_iface.h" +#include #include #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& records); diff --git a/src/place/recognition/user_places/user_places.cpp b/src/place/recognition/user_places/user_places.cpp index bba0f1d..c0bb736 100644 --- a/src/place/recognition/user_places/user_places.cpp +++ b/src/place/recognition/user_places/user_places.cpp @@ -19,7 +19,6 @@ #include #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"); } diff --git a/src/place/recognition/user_places/user_places.h b/src/place/recognition/user_places/user_places.h index d2c66da..b7084d8 100644 --- a/src/place/recognition/user_places/user_places.h +++ b/src/place/recognition/user_places/user_places.h @@ -17,11 +17,12 @@ #ifndef __CONTEXT_PLACE_STATUS_USER_PLACES_ENGINE_H__ #define __CONTEXT_PLACE_STATUS_USER_PLACES_ENGINE_H__ +#include +#include +#include #include "visit_detector.h" #include "places_detector.h" -#include #include "user_places_types.h" -#include 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); diff --git a/src/place/recognition/user_places/wifi_logger.cpp b/src/place/recognition/user_places/wifi_logger.cpp index 92bcdd4..5a6dfba 100644 --- a/src/place/recognition/user_places/wifi_logger.cpp +++ b/src/place/recognition/user_places/wifi_logger.cpp @@ -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); } diff --git a/src/place/recognition/user_places/wifi_logger.h b/src/place/recognition/user_places/wifi_logger.h index 4db601c..6b9ecb6 100644 --- a/src/place/recognition/user_places/wifi_logger.h +++ b/src/place/recognition/user_places/wifi_logger.h @@ -17,12 +17,11 @@ #ifndef __CONTEXT_PLACE_STATUS_WIFI_LOGGER_H__ #define __CONTEXT_PLACE_STATUS_WIFI_LOGGER_H__ -#include #include #include -#include "timer_mgr.h" #include #include +#include #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); diff --git a/src/statistics/social/log_aggregator.cpp b/src/statistics/social/log_aggregator.cpp index 309316f..fadd8cf 100644 --- a/src/statistics/social/log_aggregator.cpp +++ b/src/statistics/social/log_aggregator.cpp @@ -17,7 +17,6 @@ #include #include #include -#include #include #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; diff --git a/src/statistics/social/log_aggregator.h b/src/statistics/social/log_aggregator.h index e7aefb7..6f7583f 100644 --- a/src/statistics/social/log_aggregator.h +++ b/src/statistics/social/log_aggregator.h @@ -19,14 +19,15 @@ #include #include -#include +#include 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& records); - bool on_timer_expired(int timer_id, void* user_data); + bool onTimerExpired(int timer_id); }; /* class phone_contact_log_aggregator */ -- 2.34.1