*/
#include <context_mgr.h>
-#include <timer_mgr.h>
-#include <timer_util.h>
#include "system_types.h"
#include "alarm.h"
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);
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);
}
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;
}
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;
}
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;
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;
}
/* 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;
{
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);
}
}
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;
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);
#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);
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);
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);
*/
#include <context_mgr.h>
-#include <timer_util.h>
+#include <TimerManager.h>
#include "system_types.h"
#include "time.h"
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);
}
}
-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);
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()
#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"
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,
/* TIMER */
int timer_id;
time_t timer_timestamp;
+ TimerManager __timerManager;
timer_purpose_e timer_purpose;
void set_next_timer();
void active_request_timer_start();
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();
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();
#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"
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;
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);
#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"
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");
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");
}
#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 {
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);
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("");
// 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();
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);
}
void ctx::WifiLogger::timer_restart()
{
- timer_manager::remove(timer_id);
+ __timerManager.remove(timer_id);
timer_start(interval_minutes);
}
#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"
namespace ctx {
- class WifiLogger : public timer_listener_iface, public IVisitListener {
+ class WifiLogger : public ITimerListener, public IVisitListener {
public:
WifiLogger(IWifiListener * listener_ = nullptr,
bool connected_to_wifi_ap;
bool started;
bool running;
+ TimerManager __timerManager;
void _start_logging();
void _stop_logging();
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);
#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"
, 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()
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;
#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);
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 */