Replace timer_manager & timer_util with TimerManager 03/60203/2
authorMu-Woong Lee <muwoong.lee@samsung.com>
Wed, 24 Feb 2016 06:31:53 +0000 (15:31 +0900)
committerMu-Woong Lee <muwoong.lee@samsung.com>
Mon, 29 Feb 2016 02:27:34 +0000 (11:27 +0900)
Change-Id: I7864674c5c166a530c10817dbb735fe80d6b120e
Signed-off-by: Mu-Woong Lee <muwoong.lee@samsung.com>
CMakeLists.txt
packaging/context-service.spec
src/context_trigger/timer.cpp
src/server.cpp
src/timer_mgr_impl.cpp [deleted file]
src/timer_mgr_impl.h [deleted file]

index bb79b74..8c07132 100644 (file)
@@ -17,7 +17,6 @@ SET(DEPS
        capi-system-info
        capi-appfw-app-manager
        appsvc
-       alarm-service
        notification
        capi-system-system-settings
        cynara-creds-gdbus
index c500ce8..a29c663 100644 (file)
@@ -16,7 +16,6 @@ BuildRequires: pkgconfig(sqlite3)
 BuildRequires: pkgconfig(capi-system-info)
 BuildRequires: pkgconfig(capi-appfw-app-manager)
 BuildRequires: pkgconfig(appsvc)
-BuildRequires: pkgconfig(alarm-service)
 BuildRequires: pkgconfig(notification)
 BuildRequires: pkgconfig(capi-system-system-settings)
 
index 0a14b58..0d9635b 100644 (file)
@@ -17,7 +17,7 @@
 #include <context_trigger.h>
 #include <context_trigger_types_internal.h>
 #include <types_internal.h>
-#include <timer_util.h>
+#include <TimerManager.h>
 #include "timer.h"
 
 #define TIMER_DAY_OF_WEEK "DayOfWeek"
@@ -29,22 +29,22 @@ static int arrange_day_of_week(ctx::Json day_info)
 
        std::string key_op;
        if (!day_info.get(NULL, CT_RULE_DATA_KEY_OPERATOR, &key_op)) {
-               result = ctx::timer_util::convert_day_of_week_string_to_int(TIMER_TYPES_EVERYDAY);
+               result = ctx::TimerManager::dowToInt(DOW_EVERYDAY);
                return result;
        }
 
        if (key_op.compare("and") == 0) {
-               result = ctx::timer_util::convert_day_of_week_string_to_int(TIMER_TYPES_EVERYDAY);
+               result = ctx::TimerManager::dowToInt(DOW_EVERYDAY);
        }
 
        std::string tmp_d;
        for (int i = 0; day_info.getAt(NULL, CT_RULE_DATA_VALUE_ARR, i, &tmp_d); i++) {
-               int dow = ctx::timer_util::convert_day_of_week_string_to_int(tmp_d);
+               int dow = ctx::TimerManager::dowToInt(tmp_d);
                std::string op;
                day_info.getAt(NULL, CT_RULE_DATA_VALUE_OPERATOR_ARR, i, &op);
 
                if (op.compare(CONTEXT_TRIGGER_NOT_EQUAL_TO) == 0) {
-                       dow = ctx::timer_util::convert_day_of_week_string_to_int(TIMER_TYPES_EVERYDAY) & ~dow;
+                       dow = ctx::TimerManager::dowToInt(DOW_EVERYDAY) & ~dow;
                }
 
                if (key_op.compare("and") == 0) {
@@ -82,10 +82,10 @@ void ctx::trigger_timer::handle_timer_event(ctx::Json& rule)
                        day_info.set(NULL, CT_RULE_DATA_KEY, TIMER_DAY_OF_WEEK);
                        day_info.set(NULL, CT_RULE_DATA_KEY_OPERATOR, "or");
 
-                       for (int j = 0; j < MAX_DAY; j++) {
+                       for (int j = 0; j < DAYS_PER_WEEK; j++) {
                                int d = 0x01 << j;
                                if (dow & d) {
-                                       std::string day = ctx::timer_util::convert_day_of_week_int_to_string(d);
+                                       std::string day = ctx::TimerManager::dowToStr(d);
                                        day_info.append(NULL, CT_RULE_DATA_VALUE_ARR, day);
                                        day_info.append(NULL, CT_RULE_DATA_VALUE_OPERATOR_ARR, CONTEXT_TRIGGER_EQUAL_TO);
 
index ece6e6b..c759f8e 100644 (file)
@@ -22,7 +22,6 @@
 #include <types_internal.h>
 #include "DBusServer.h"
 #include "db_mgr_impl.h"
-#include "timer_mgr_impl.h"
 #include "context_mgr_impl.h"
 #include "context_trigger/trigger.h"
 #include "server.h"
@@ -31,7 +30,6 @@ static GMainLoop *mainloop = NULL;
 static bool started = false;
 
 static ctx::context_manager_impl *context_mgr = NULL;
-static ctx::timer_manager_impl *timer_mgr = NULL;
 static ctx::db_manager_impl *database_mgr = NULL;
 static ctx::DBusServer *dbus_handle = NULL;
 static ctx::context_trigger *trigger = NULL;
@@ -58,13 +56,6 @@ void ctx::server::activate()
 
        bool result = false;
 
-       _I("Init Timer Manager");
-       timer_mgr = new(std::nothrow) ctx::timer_manager_impl();
-       IF_FAIL_CATCH_TAG(timer_mgr, _E, "Memory allocation failed");
-       timer_manager::set_instance(timer_mgr);
-       result = timer_mgr->init();
-       IF_FAIL_CATCH_TAG(result, _E, "Initialization Failed");
-
        _I("Init Database Manager");
        database_mgr = new(std::nothrow) ctx::db_manager_impl();
        IF_FAIL_CATCH_TAG(database_mgr, _E, "Memory allocation failed");
@@ -115,17 +106,12 @@ void ctx::server::release()
        if (database_mgr)
                database_mgr->release();
 
-       _I("Release Timer Manager");
-       if (timer_mgr)
-               timer_mgr->release();
-
        g_main_loop_unref(mainloop);
 
        delete trigger;
        delete context_mgr;
        delete dbus_handle;
        delete database_mgr;
-       delete timer_mgr;
 }
 
 static gboolean postpone_request_assignment(gpointer data)
diff --git a/src/timer_mgr_impl.cpp b/src/timer_mgr_impl.cpp
deleted file mode 100644 (file)
index 8bb3cdd..0000000
+++ /dev/null
@@ -1,224 +0,0 @@
-/*
- * Copyright (c) 2015 Samsung Electronics Co., Ltd.
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-#include <map>
-#include <alarm.h>
-#include <ScopeMutex.h>
-#include <types_internal.h>
-#include <timer_types.h>
-#include "timer_mgr_impl.h"
-
-#define IDENTIFIER "contextd"
-
-struct listener_info_s {
-       int timer_id;
-       ctx::timer_listener_iface* listener;
-       void* user_data;
-};
-
-typedef std::map<alarm_id_t, listener_info_s> listener_map_t;
-static listener_map_t *listener_map = NULL;
-static GMutex listener_map_mutex;
-
-static int generate_timer_id()
-{
-       static int tid = 0;
-
-       tid ++;
-       if (tid < 0) {
-               _W("Overflow");
-               tid = 1;
-       }
-
-       return tid;
-}
-
-static int alarm_expired_cb(alarm_id_t alarm_id, void* cb_data)
-{
-       int timer_id = 0;
-       ctx::timer_listener_iface *listener = NULL;
-       void* user_data;
-
-       {
-               ctx::ScopeMutex sm1(&listener_map_mutex);
-               listener_map_t::iterator mit = listener_map->find(alarm_id);
-               IF_FAIL_RETURN_TAG(mit != listener_map->end(), 0, _W, "Unknown Alarm %d", alarm_id);
-               timer_id = mit->second.timer_id;
-               listener = mit->second.listener;
-               user_data = mit->second.user_data;
-       }
-
-       _D("Timer %d expired", timer_id);
-       bool repeat = listener->on_timer_expired(timer_id, user_data);
-
-       if (!repeat) {
-               _D("Stop repeating Timer %d (Alarm %d)", timer_id, alarm_id);
-               ctx::ScopeMutex sm2(&listener_map_mutex);
-               alarmmgr_remove_alarm(alarm_id);
-               listener_map->erase(alarm_id);
-       }
-
-       return 0;
-}
-
-ctx::timer_manager_impl::timer_manager_impl()
-       : initialized(false)
-{
-}
-
-ctx::timer_manager_impl::~timer_manager_impl()
-{
-       release();
-}
-
-bool ctx::timer_manager_impl::init()
-{
-       IF_FAIL_RETURN_TAG(!initialized, true, _W, "Re-initialization");
-
-       listener_map = new(std::nothrow) listener_map_t;
-       IF_FAIL_RETURN_TAG(listener_map, false, _E, "Memory allocation failed");
-
-       int result = alarmmgr_init(IDENTIFIER);
-       IF_FAIL_RETURN_TAG(result == ALARMMGR_RESULT_SUCCESS, false, _E, "Alarm manager initialization failed");
-
-       result = alarmmgr_set_cb(alarm_expired_cb, this);
-       if (result != ALARMMGR_RESULT_SUCCESS) {
-               alarmmgr_fini();
-               _E("Alarm callback registration failed");
-               return false;
-       }
-
-       alarmmgr_remove_all();
-       initialized = true;
-       return true;
-}
-
-void ctx::timer_manager_impl::release()
-{
-       if (initialized) {
-               alarmmgr_remove_all();
-               alarmmgr_fini();
-               delete listener_map;
-               listener_map = NULL;
-               initialized = false;
-       }
-}
-
-int ctx::timer_manager_impl::set_for(int interval, timer_listener_iface* listener, void* user_data)
-{
-       IF_FAIL_RETURN_TAG(interval > 0 && listener, false, _E, "Invalid parameter");
-
-       alarm_id_t alarm_id;
-       int result;
-
-#if 0
-       // Implementation for Tizen 2.3
-       time_t trigger_time;
-       time(&trigger_time);
-       // time_t is in seconds.. It is the POSIX specification.
-       trigger_time += (interval * 60);
-
-       result = alarmmgr_add_alarm(ALARM_TYPE_VOLATILE, trigger_time, interval * 60, NULL, &alarm_id);
-#endif
-
-       result = alarmmgr_add_periodic_alarm_withcb(interval, QUANTUMIZE, alarm_expired_cb, this, &alarm_id);
-       IF_FAIL_RETURN_TAG(result == ALARMMGR_RESULT_SUCCESS, ERR_OPERATION_FAILED, _E, "Alarm initialization failed");
-
-       ctx::ScopeMutex sm(&listener_map_mutex);
-
-       listener_info_s info;
-       info.timer_id = generate_timer_id();
-       info.listener = listener;
-       info.user_data = user_data;
-       (*listener_map)[alarm_id] = info;
-
-       _D("Timer %d was set for %dm interval", info.timer_id, interval);
-
-       return info.timer_id;
-}
-
-int ctx::timer_manager_impl::set_at(int hour, int min, int day_of_week, timer_listener_iface* listener, void* user_data)
-{
-       IF_FAIL_RETURN_TAG(
-                       hour < 24 && hour >= 0 &&
-                       min < 60 && min >= 0 &&
-                       day_of_week > 0 && day_of_week <= timer_types::EVERYDAY &&
-                       listener, false, _E, "Invalid parameter");
-
-       int repeat = 0;
-       if (day_of_week & timer_types::SUN) repeat |= ALARM_WDAY_SUNDAY;
-       if (day_of_week & timer_types::MON) repeat |= ALARM_WDAY_MONDAY;
-       if (day_of_week & timer_types::TUE) repeat |= ALARM_WDAY_TUESDAY;
-       if (day_of_week & timer_types::WED) repeat |= ALARM_WDAY_WEDNESDAY;
-       if (day_of_week & timer_types::THU) repeat |= ALARM_WDAY_THURSDAY;
-       if (day_of_week & timer_types::FRI) repeat |= ALARM_WDAY_FRIDAY;
-       if (day_of_week & timer_types::SAT) repeat |= ALARM_WDAY_SATURDAY;
-
-       alarm_entry_t *alarm_info = alarmmgr_create_alarm();
-       IF_FAIL_RETURN_TAG(alarm_info, ERR_OPERATION_FAILED, _E, "Memory allocation failed");
-
-       time_t current_time;
-       struct tm current_tm;
-       time(&current_time);
-       tzset();
-       localtime_r(&current_time, &current_tm);
-
-       alarm_date_t alarm_time;
-       alarm_time.year = current_tm.tm_year + 1900;
-       alarm_time.month = current_tm.tm_mon + 1;
-       alarm_time.day = current_tm.tm_mday;
-       alarm_time.hour = hour;
-       alarm_time.min = min;
-       alarm_time.sec = 0;
-
-       alarmmgr_set_time(alarm_info, alarm_time);
-       alarmmgr_set_repeat_mode(alarm_info, ALARM_REPEAT_MODE_WEEKLY, repeat);
-       alarmmgr_set_type(alarm_info, ALARM_TYPE_VOLATILE);
-
-       alarm_id_t alarm_id;
-       int ret = alarmmgr_add_alarm_with_localtime(alarm_info, NULL, &alarm_id);
-       alarmmgr_free_alarm(alarm_info);
-
-       IF_FAIL_RETURN_TAG(ret == ALARMMGR_RESULT_SUCCESS, ERR_OPERATION_FAILED, _E, "Alarm initialization failed");
-
-       ctx::ScopeMutex sm(&listener_map_mutex);
-
-       listener_info_s info;
-       info.timer_id = generate_timer_id();
-       info.listener = listener;
-       info.user_data = user_data;
-
-       (*listener_map)[alarm_id] = info;
-
-       _D("Timer %d was set at %02d:%02d:00 (day of week: %#x)", info.timer_id, hour, min, day_of_week);
-
-       return info.timer_id;
-}
-
-void ctx::timer_manager_impl::remove(int timer_id)
-{
-       ctx::ScopeMutex sm(&listener_map_mutex);
-
-       listener_map_t::iterator it;
-       for (it = listener_map->begin(); it != listener_map->end(); ++it) {
-               if (it->second.timer_id == timer_id) {
-                       alarmmgr_remove_alarm(it->first);
-                       listener_map->erase(it);
-                       _D("Timer %d was removed", timer_id);
-                       break;
-               }
-       }
-}
diff --git a/src/timer_mgr_impl.h b/src/timer_mgr_impl.h
deleted file mode 100644 (file)
index 2b15f2e..0000000
+++ /dev/null
@@ -1,43 +0,0 @@
-/*
- * Copyright (c) 2015 Samsung Electronics Co., Ltd.
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-#ifndef __CONTEXT_TIMER_MANAGER_IMPL_H__
-#define __CONTEXT_TIMER_MANAGER_IMPL_H__
-
-#include <timer_listener_iface.h>
-#include <timer_mgr_iface.h>
-
-namespace ctx {
-
-       class timer_manager_impl : public timer_manager_iface {
-               private:
-                       bool initialized;
-
-               public:
-                       timer_manager_impl();
-                       ~timer_manager_impl();
-
-                       bool init();
-                       void release();
-
-                       int set_for(int interval, timer_listener_iface* listener, void* user_data);
-                       int set_at(int hour, int min, int day_of_week, timer_listener_iface* listener, void* user_data);
-                       void remove(int timer_id);
-
-       };      /* class timer_manager */
-}
-
-#endif /* __CONTEXT_TIMER_MANAGER_IMPL_H__ */