Move codes 02/210602/2
authorInkyun Kil <inkyun.kil@samsung.com>
Tue, 23 Jul 2019 01:57:20 +0000 (10:57 +0900)
committerInkyun Kil <inkyun.kil@samsung.com>
Wed, 21 Aug 2019 03:57:30 +0000 (12:57 +0900)
- Move codes related to timer from alarm-manager.c to
alarm-manager-timer.c

Change-Id: I9ce2bcc3de74391f45e2bd47ac41626f994bd9eb
Signed-off-by: Inkyun Kil <inkyun.kil@samsung.com>
include/alarm-internal.h
server/alarm-manager-schedule.c
server/alarm-manager-timer.c
server/alarm-manager.c

index 9331667..82ba453 100755 (executable)
@@ -167,13 +167,17 @@ void _alarm_schedule();
 void _clear_scheduled_alarm_list();
 void _add_to_scheduled_alarm_list(__alarm_info_t *__alarm_info);
 
-void _alarm_set_timer(__alarm_server_context_t *alarm_context, int timer, time_t due_time);
-void _alarm_disable_timer(__alarm_server_context_t alarm_context);
+void _alarm_set_timer(int timer, time_t due_time);
+void _alarm_disable_timer();
+int _initialize_timer();
 
 void _alarm_initialize();
 time_t _get_periodic_alarm_standard_time(void);
 bool _can_skip_expired_cb(alarm_id_t alarm_id);
 
+void _alarm_expired();
+void _rtc_set();
+
 int alarm_manager_alarm_create(GVariant *parameters, uid_t uid, pid_t pid, int *alarm_id);
 int alarm_manager_alarm_create_appsvc(GVariant *parameters, uid_t uid, pid_t pid, int *alarm_id);
 int alarm_manager_alarm_create_periodic(GVariant *parameters, uid_t uid, pid_t pid, int *alarm_id);
index 171db5b..8fd4091 100644 (file)
@@ -512,6 +512,6 @@ void _alarm_schedule()
                                _add_to_scheduled_alarm_list(entry);
                }
 
-               _alarm_set_timer(&alarm_context, alarm_context.timer, min_time);
+               _alarm_set_timer(alarm_context.timer, min_time);
        }
 }
index 498a8cb..94b70f8 100644 (file)
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2000 - 2017 Samsung Electronics Co., Ltd All Rights Reserved
+ * Copyright (c) 2000 - 2019 Samsung Electronics Co., Ltd All Rights Reserved
  *
  * Licensed under the Apache License, Version 2.0 (the "License");
  * you may not use this file except in compliance with the License.
 #include <string.h>
 #include <sys/types.h>
 #include <errno.h>
+#include <stdint.h>
 #include <sys/timerfd.h>
 #include <glib.h>
 
 #include "alarm.h"
 #include "alarm-internal.h"
+#include "alarm-manager-dbus.h"
 
-extern bool g_dummy_timer_is_set;
+extern __alarm_server_context_t alarm_context;
 
-void _alarm_disable_timer(__alarm_server_context_t alarm_context)
+bool g_dummy_timer_is_set = false;
+
+static gboolean __alarm_handler_idle(gpointer user_data)
+{
+       GPollFD *gpollfd = (GPollFD *) user_data;
+       uint64_t exp;
+       time_t current_time;
+
+#ifdef TIZEN_TEST_GCOV
+       void __gcov_flush(void);
+       __gcov_flush();
+#endif
+
+       if (gpollfd == NULL) {
+               ALARM_MGR_EXCEPTION_PRINT("gpollfd is NULL");
+               return false;
+       }
+
+       if (read(gpollfd->fd, &exp, sizeof(uint64_t)) < 0) {
+               ALARM_MGR_EXCEPTION_PRINT("Reading the fd is failed.");
+               return false;
+       }
+
+       ALARM_MGR_LOG_PRINT("Lock the display not to enter LCD OFF");
+       if (_display_lock_state(DEVICED_LCD_OFF, DEVICED_STAY_CUR_STATE, 0) != ALARMMGR_RESULT_SUCCESS)
+               ALARM_MGR_EXCEPTION_PRINT("_display_lock_state() is failed");
+
+       if (g_dummy_timer_is_set == true) {
+               ALARM_MGR_LOG_PRINT("dummy alarm timer has expired.");
+       } else {
+               ALARM_MGR_LOG_PRINT("__alarm_handler_idle");
+               _alarm_expired();
+       }
+
+       _alarm_schedule();
+
+       /*
+        * Previous alarm can be expired late as tolerance of RTC.
+        * In this case, Expire alarms forcibly if real duetime is same to current time.
+        */
+       time(&current_time);
+       if (alarm_context.c_due_time == current_time) {
+               ALARM_MGR_LOG_PRINT("Expire alarms forcibly when duetime is same to current time(%ld).", current_time);
+               _alarm_expired();
+               _alarm_schedule();
+       }
+
+       _rtc_set();
+
+       ALARM_MGR_LOG_PRINT("Unlock the display from LCD OFF");
+       if (_display_unlock_state(DEVICED_LCD_OFF, DEVICED_SLEEP_MARGIN) != ALARMMGR_RESULT_SUCCESS)
+               ALARM_MGR_EXCEPTION_PRINT("_display_unlock_state() is failed");
+
+       return false;
+}
+
+
+static void __timer_glib_finalize(GSource *src)
+{
+       GSList *fd_list;
+       GPollFD *tmp;
+
+       fd_list = src->poll_fds;
+       do {
+               tmp = (GPollFD *) fd_list->data;
+               g_free(tmp);
+
+               fd_list = fd_list->next;
+       } while (fd_list);
+
+       return;
+}
+
+static gboolean __timer_glib_check(GSource *src)
+{
+       GSList *fd_list;
+       GPollFD *tmp;
+
+       fd_list = src->poll_fds;
+       do {
+               tmp = (GPollFD *) fd_list->data;
+               if (tmp->revents & (G_IO_IN | G_IO_PRI))
+                       return TRUE;
+
+               fd_list = fd_list->next;
+       } while (fd_list);
+
+       return FALSE;
+}
+
+static gboolean __timer_glib_dispatch(GSource *src, GSourceFunc callback,
+                                 gpointer data)
+{
+       callback(data);
+       return TRUE;
+}
+
+static gboolean __timer_glib_prepare(GSource *src, gint *timeout)
+{
+       return FALSE;
+}
+
+GSourceFuncs funcs = {
+       .prepare = __timer_glib_prepare,
+       .check = __timer_glib_check,
+       .dispatch = __timer_glib_dispatch,
+       .finalize = __timer_glib_finalize
+};
+
+int _initialize_timer()
+{
+       int fd;
+       GSource *src;
+       GPollFD *gpollfd;
+       int ret;
+
+       fd = timerfd_create(CLOCK_REALTIME, 0);
+       if (fd == -1) {
+               ALARM_MGR_EXCEPTION_PRINT("timerfd_create() is failed.\n");
+               return -1;
+       }
+       src = g_source_new(&funcs, sizeof(GSource));
+
+       gpollfd = (GPollFD *) g_malloc(sizeof(GPollFD));
+       if (gpollfd == NULL) {
+               ALARM_MGR_EXCEPTION_PRINT("Out of memory\n");
+               return -1;
+       }
+       gpollfd->events = G_IO_IN;
+       gpollfd->fd = fd;
+
+       g_source_add_poll(src, gpollfd);
+       g_source_set_callback(src, (GSourceFunc) __alarm_handler_idle,
+                             (gpointer) gpollfd, NULL);
+       g_source_set_priority(src, G_PRIORITY_HIGH);
+
+       ret = g_source_attach(src, NULL);
+       if (ret == 0) {
+               ALARM_MGR_EXCEPTION_PRINT("g_source_attach() is failed.\n");
+               return -1;
+       }
+
+       g_source_unref(src);
+
+       return fd;
+}
+
+void _alarm_disable_timer()
 {
        struct itimerspec time_spec;
 
@@ -40,14 +189,13 @@ void _alarm_disable_timer(__alarm_server_context_t alarm_context)
                ALARM_MGR_EXCEPTION_PRINT("timerfd_settime has failed : errno(%d).", errno);
 }
 
-void _alarm_set_timer(__alarm_server_context_t *alarm_context, int timer, time_t due_time)
+void _alarm_set_timer(int timer, time_t due_time)
 {
        struct itimerspec time_spec;
        time_t current_time;
        double interval;
        char due_time_r[100] = { 0 };
        struct tm ts_ret;
-       extern int errno;
 
        time(&current_time);
 
@@ -79,5 +227,5 @@ void _alarm_set_timer(__alarm_server_context_t *alarm_context, int timer, time_t
 
        /* we set c_due_time to due_time due to allow newly created alarm can
           be schedlued when its interval is less than the current alarm */
-       alarm_context->c_due_time = due_time;
+       alarm_context.c_due_time = due_time;
 }
index ed9e489..49f6adb 100755 (executable)
@@ -22,9 +22,6 @@
 #include <sys/stat.h>
 #include <sys/time.h>
 #include <unistd.h>
-#include <sys/timerfd.h>
-#include <poll.h>
-#include <stdint.h>
 #include <errno.h>
 #include <linux/rtc.h>
 #include <sys/ioctl.h>
@@ -80,7 +77,8 @@ static const char default_rtc[] = "/dev/rtc";
 static int gfd = -1;
 
 __alarm_server_context_t alarm_context;
-bool g_dummy_timer_is_set = FALSE;
+
+extern bool g_dummy_timer_is_set;
 
 GSList *g_scheduled_alarm_list;
 GSList *g_expired_alarm_list;
@@ -122,10 +120,7 @@ static bool __alarm_create_appsvc(alarm_info_t *alarm_info, alarm_id_t *alarm_id
 static bool __alarm_delete(uid_t uid, alarm_id_t alarm_id, int *error_code);
 static bool __alarm_update(uid_t uid, alarm_id_t alarm_id,
                           alarm_info_t *alarm_info, int update_flag, int *error_code);
-static void __alarm_expired();
-static gboolean __alarm_handler_idle(gpointer user_data);
 static void __on_system_time_external_changed(keynode_t *node, void *data);
-static void __initialize_timer();
 static void __initialize_alarm_list();
 static void __initialize_scheduled_alarm_list();
 static void __initialize_noti();
@@ -259,7 +254,7 @@ void __free_cached_value(gpointer data)
        }
 }
 
-static void __rtc_set()
+void _rtc_set()
 {
        if (_APPFW_FEATURE_WAKEUP_USING_RTC) {
                const char *rtc = default_rtc;
@@ -885,8 +880,8 @@ static bool __alarm_create_appsvc(alarm_info_t *alarm_info, alarm_id_t *alarm_id
        if (alarm_context.c_due_time == -1 || __alarm_info->due_time < alarm_context.c_due_time) {
                _clear_scheduled_alarm_list();
                _add_to_scheduled_alarm_list(__alarm_info);
-               _alarm_set_timer(&alarm_context, alarm_context.timer, __alarm_info->due_time);
-               __rtc_set();
+               _alarm_set_timer(alarm_context.timer, __alarm_info->due_time);
+               _rtc_set();
        } else if (__alarm_info->due_time == alarm_context.c_due_time) {
                _add_to_scheduled_alarm_list(__alarm_info);
        }
@@ -992,8 +987,8 @@ static bool __alarm_create(alarm_info_t *alarm_info, alarm_id_t *alarm_id, uid_t
        if (alarm_context.c_due_time == -1 || __alarm_info->due_time < alarm_context.c_due_time) {
                _clear_scheduled_alarm_list();
                _add_to_scheduled_alarm_list(__alarm_info);
-               _alarm_set_timer(&alarm_context, alarm_context.timer, __alarm_info->due_time);
-               __rtc_set();
+               _alarm_set_timer(alarm_context.timer, __alarm_info->due_time);
+               _rtc_set();
        } else if (__alarm_info->due_time == alarm_context.c_due_time) {
                _add_to_scheduled_alarm_list(__alarm_info);
        }
@@ -1143,8 +1138,8 @@ static bool __alarm_create_noti(alarm_info_t *alarm_info, alarm_id_t *alarm_id,
        if (alarm_context.c_due_time == -1 || __alarm_info->due_time < alarm_context.c_due_time) {
                _clear_scheduled_alarm_list();
                _add_to_scheduled_alarm_list(__alarm_info);
-               _alarm_set_timer(&alarm_context, alarm_context.timer, __alarm_info->due_time);
-               __rtc_set();
+               _alarm_set_timer(alarm_context.timer, __alarm_info->due_time);
+               _rtc_set();
        } else if (__alarm_info->due_time == alarm_context.c_due_time) {
                _add_to_scheduled_alarm_list(__alarm_info);
        }
@@ -1182,12 +1177,12 @@ static bool __alarm_update(uid_t uid, alarm_id_t alarm_id,
        result = _remove_from_scheduled_alarm_list(uid, alarm_id);
        if (result == true && g_slist_length(g_scheduled_alarm_list) == 0) {
                /*there is no scheduled alarm */
-               _alarm_disable_timer(alarm_context);
+               _alarm_disable_timer();
                _alarm_schedule();
 
                ALARM_MGR_LOG_PRINT("[alarm-server]:Update alarm: alarm(%d).", alarm_id);
 
-               __rtc_set();
+               _rtc_set();
 
                if (__alarm_info->due_time == 0)
                        ALARM_MGR_EXCEPTION_PRINT("[alarm-server]:Update alarm: due_time is 0.");
@@ -1222,7 +1217,7 @@ static bool __alarm_update(uid_t uid, alarm_id_t alarm_id,
        if (alarm_context.c_due_time == -1 || __alarm_info->due_time < alarm_context.c_due_time) {
                _clear_scheduled_alarm_list();
                _add_to_scheduled_alarm_list(__alarm_info);
-               _alarm_set_timer(&alarm_context, alarm_context.timer, __alarm_info->due_time);
+               _alarm_set_timer(alarm_context.timer, __alarm_info->due_time);
                ALARM_MGR_LOG_PRINT("[alarm-server1]:alarm_context.c_due_time "
                     "(%ld), due_time(%ld)", alarm_context.c_due_time, __alarm_info->due_time);
        } else if (__alarm_info->due_time == alarm_context.c_due_time) {
@@ -1231,7 +1226,7 @@ static bool __alarm_update(uid_t uid, alarm_id_t alarm_id,
                     "(%ld), due_time(%ld)", alarm_context.c_due_time, __alarm_info->due_time);
        }
 
-       __rtc_set();
+       _rtc_set();
 
        return true;
 }
@@ -1253,9 +1248,9 @@ static bool __alarm_delete(uid_t uid, alarm_id_t alarm_id, int *error_code)
        }
 
        if (result == true && g_slist_length(g_scheduled_alarm_list) == 0) {
-               _alarm_disable_timer(alarm_context);
+               _alarm_disable_timer();
                _alarm_schedule();
-               __rtc_set();
+               _rtc_set();
        }
 
        return true;
@@ -1412,7 +1407,7 @@ static int __app_info_iter(const aul_app_info *info, void *data)
        return 0;
 }
 
-static void __alarm_expired()
+void _alarm_expired()
 {
        int ret;
        bool is_app = false;
@@ -1654,66 +1649,13 @@ done:
        ALARM_MGR_LOG_PRINT("[alarm-server]: Leave");
 }
 
-static gboolean __alarm_handler_idle(gpointer user_data)
-{
-       GPollFD *gpollfd = (GPollFD *) user_data;
-       uint64_t exp;
-       time_t current_time;
-
-#ifdef TIZEN_TEST_GCOV
-       void __gcov_flush(void);
-       __gcov_flush();
-#endif
-
-       if (gpollfd == NULL) {
-               ALARM_MGR_EXCEPTION_PRINT("gpollfd is NULL");
-               return false;
-       }
-
-       if (read(gpollfd->fd, &exp, sizeof(uint64_t)) < 0) {
-               ALARM_MGR_EXCEPTION_PRINT("Reading the fd is failed.");
-               return false;
-       }
-
-       ALARM_MGR_LOG_PRINT("Lock the display not to enter LCD OFF");
-       if (_display_lock_state(DEVICED_LCD_OFF, DEVICED_STAY_CUR_STATE, 0) != ALARMMGR_RESULT_SUCCESS)
-               ALARM_MGR_EXCEPTION_PRINT("_display_lock_state() is failed");
-
-       if (g_dummy_timer_is_set == true) {
-               ALARM_MGR_LOG_PRINT("dummy alarm timer has expired.");
-       } else {
-               ALARM_MGR_LOG_PRINT("__alarm_handler_idle");
-               __alarm_expired();
-       }
-
-       _alarm_schedule();
-
-       /*
-        * Previous alarm can be expired late as tolerance of RTC.
-        * In this case, Expire alarms forcibly if real duetime is same to current time.
-        */
-       time(&current_time);
-       if (alarm_context.c_due_time == current_time) {
-               ALARM_MGR_LOG_PRINT("Expire alarms forcibly when duetime is same to current time(%ld).", current_time);
-               __alarm_expired();
-               _alarm_schedule();
-       }
-
-       __rtc_set();
-
-       ALARM_MGR_LOG_PRINT("Unlock the display from LCD OFF");
-       if (_display_unlock_state(DEVICED_LCD_OFF, DEVICED_SLEEP_MARGIN) != ALARMMGR_RESULT_SUCCESS)
-               ALARM_MGR_EXCEPTION_PRINT("_display_unlock_state() is failed");
-
-       return false;
-}
 
 static void __on_system_time_external_changed(keynode_t *node, void *data)
 {
        double diff_time = 0.0;
        time_t cur_time = 0;
 
-       _alarm_disable_timer(alarm_context);
+       _alarm_disable_timer();
 
        if (node) {
                diff_time = vconf_keynode_get_dbl(node);
@@ -1737,7 +1679,7 @@ static void __on_system_time_external_changed(keynode_t *node, void *data)
                ALARM_MGR_EXCEPTION_PRINT("Failed to change both OS time and RTC");
                _clear_scheduled_alarm_list();
                _alarm_schedule();
-               __rtc_set();
+               _rtc_set();
                return;
        }
 
@@ -1754,7 +1696,7 @@ static void __on_system_time_external_changed(keynode_t *node, void *data)
                            alarm_context.c_due_time);
        _clear_scheduled_alarm_list();
        _alarm_schedule();
-       __rtc_set();
+       _rtc_set();
 
        return;
 }
@@ -1789,10 +1731,10 @@ static int __on_app_enable_cb(uid_t target_uid, int req_id,
                }
 
                if (is_restored) {
-                       _alarm_disable_timer(alarm_context);
+                       _alarm_disable_timer();
                        _clear_scheduled_alarm_list();
                        _alarm_schedule();
-                       __rtc_set();
+                       _rtc_set();
                }
        }
 
@@ -1828,7 +1770,7 @@ static int __on_app_disable_cb(uid_t target_uid, int req_id,
                        _alarm_disable_timer(alarm_context);
                        _clear_scheduled_alarm_list();
                        _alarm_schedule();
-                       __rtc_set();
+                       _rtc_set();
                }
        }
 
@@ -1877,9 +1819,9 @@ static int __on_app_uninstalled(uid_t target_uid, int req_id, const char *pkg_ty
                }
 
                if (is_deleted && (g_slist_length(g_scheduled_alarm_list) == 0)) {
-                       _alarm_disable_timer(alarm_context);
+                       _alarm_disable_timer();
                        _alarm_schedule();
-                       __rtc_set();
+                       _rtc_set();
                }
        }
 
@@ -1979,11 +1921,11 @@ gboolean __alarm_expired_directly(gpointer user_data)
                        ALARM_MGR_LOG_PRINT("dummy alarm timer has expired.");
                } else {
                        ALARM_MGR_LOG_PRINT("due_time=%ld is expired.", alarm_info->due_time);
-                       __alarm_expired();
+                       _alarm_expired();
                }
 
                _alarm_schedule();
-               __rtc_set();
+               _rtc_set();
 
                if (_display_unlock_state(DEVICED_LCD_OFF, DEVICED_SLEEP_MARGIN) != ALARMMGR_RESULT_SUCCESS)
                        ALARM_MGR_EXCEPTION_PRINT("_display_unlock_state() is failed");
@@ -2010,7 +1952,7 @@ void __reschedule_alarms_with_newtime(int cur_time, int new_time, double diff_ti
 
        _clear_scheduled_alarm_list();
        _alarm_schedule();
-       __rtc_set();
+       _rtc_set();
 
 #ifdef _APPFW_FEATURE_ALARM_MANAGER_MODULE_LOG
        char *timebuf = ctime((const time_t *)&new_time);
@@ -2158,7 +2100,7 @@ int alarm_manager_alarm_set_time(GVariant* parameters)
 
        g_variant_get(parameters, "(i)", &time_sec);
 
-       _alarm_disable_timer(alarm_context); /* Disable the timer to reschedule the alarm before the time is changed. */
+       _alarm_disable_timer(); /* Disable the timer to reschedule the alarm before the time is changed. */
 
        tzset();
        gettimeofday(&cur_time, NULL);
@@ -2175,7 +2117,7 @@ int alarm_manager_alarm_set_time(GVariant* parameters)
                ALARM_MGR_EXCEPTION_PRINT("Failed to change both OS time and RTC");
                _clear_scheduled_alarm_list();
                _alarm_schedule();
-               __rtc_set();
+               _rtc_set();
                return ERR_ALARM_SYSTEM_FAIL;
        }
 
@@ -2198,7 +2140,7 @@ int alarm_manager_alarm_set_time_with_propagation_delay(GVariant* parameters)
 
        g_variant_get(parameters, "(uuuu)", &new_sec, &new_nsec, &req_sec, &req_nsec);
 
-       _alarm_disable_timer(alarm_context); /* Disable the timer to reschedule the alarm before the time is changed. */
+       _alarm_disable_timer(); /* Disable the timer to reschedule the alarm before the time is changed. */
 
        tzset();
        clock_gettime(CLOCK_REALTIME, &cur_time);
@@ -2233,7 +2175,7 @@ int alarm_manager_alarm_set_time_with_propagation_delay(GVariant* parameters)
                ALARM_MGR_EXCEPTION_PRINT("Failed to change both OS time and RTC");
                _clear_scheduled_alarm_list();
                _alarm_schedule();
-               __rtc_set();
+               _rtc_set();
                return ERR_ALARM_SYSTEM_FAIL;
        }
 
@@ -2287,13 +2229,13 @@ int alarm_manager_alarm_set_timezone(GVariant* parameters)
        tzset();
 
        /* Rescheduling alarms */
-       _alarm_disable_timer(alarm_context);
+       _alarm_disable_timer();
        __alarm_update_due_time_of_all_items_in_list(0);
        ALARM_MGR_LOG_PRINT("next expiring due_time is %ld", alarm_context.c_due_time);
 
        _clear_scheduled_alarm_list();
        _alarm_schedule();
-       __rtc_set();
+       _rtc_set();
 
        vconf_set_int(VCONFKEY_SYSTEM_TIME_CHANGED, 0);
        b = bundle_create();
@@ -2757,7 +2699,7 @@ int alarm_manager_alarm_delete_all(GVariant *parameters, uid_t uid, pid_t pid)
        }
 
        if (is_deleted && (g_slist_length(g_scheduled_alarm_list) == 0)) {
-               _alarm_disable_timer(alarm_context);
+               _alarm_disable_timer();
                _alarm_schedule();
        }
 
@@ -2766,7 +2708,7 @@ int alarm_manager_alarm_delete_all(GVariant *parameters, uid_t uid, pid_t pid)
        __save_module_log("DELETE ALL", log_message);
 #endif
 
-       __rtc_set();
+       _rtc_set();
        return ALARMMGR_RESULT_SUCCESS;
 }
 
@@ -3155,96 +3097,6 @@ int alarm_manager_alarm_get_global(GVariant *parameters, gboolean *global)
        return ALARMMGR_RESULT_SUCCESS;
 }
 
-static void __timer_glib_finalize(GSource *src)
-{
-       GSList *fd_list;
-       GPollFD *tmp;
-
-       fd_list = src->poll_fds;
-       do {
-               tmp = (GPollFD *) fd_list->data;
-               g_free(tmp);
-
-               fd_list = fd_list->next;
-       } while (fd_list);
-
-       return;
-}
-
-static gboolean __timer_glib_check(GSource *src)
-{
-       GSList *fd_list;
-       GPollFD *tmp;
-
-       fd_list = src->poll_fds;
-       do {
-               tmp = (GPollFD *) fd_list->data;
-               if (tmp->revents & (POLLIN | POLLPRI))
-                       return TRUE;
-
-               fd_list = fd_list->next;
-       } while (fd_list);
-
-       return FALSE;
-}
-
-static gboolean __timer_glib_dispatch(GSource *src, GSourceFunc callback,
-                                 gpointer data)
-{
-       callback(data);
-       return TRUE;
-}
-
-static gboolean __timer_glib_prepare(GSource *src, gint *timeout)
-{
-       return FALSE;
-}
-
-GSourceFuncs funcs = {
-       .prepare = __timer_glib_prepare,
-       .check = __timer_glib_check,
-       .dispatch = __timer_glib_dispatch,
-       .finalize = __timer_glib_finalize
-};
-
-static void __initialize_timer()
-{
-       int fd;
-       GSource *src;
-       GPollFD *gpollfd;
-       int ret;
-
-       fd = timerfd_create(CLOCK_REALTIME, 0);
-       if (fd == -1) {
-               ALARM_MGR_EXCEPTION_PRINT("timerfd_create() is failed.\n");
-               exit(1);
-       }
-       src = g_source_new(&funcs, sizeof(GSource));
-
-       gpollfd = (GPollFD *) g_malloc(sizeof(GPollFD));
-       if (gpollfd == NULL) {
-               ALARM_MGR_EXCEPTION_PRINT("Out of memory\n");
-               exit(1);
-       }
-       gpollfd->events = POLLIN;
-       gpollfd->fd = fd;
-
-       g_source_add_poll(src, gpollfd);
-       g_source_set_callback(src, (GSourceFunc) __alarm_handler_idle,
-                             (gpointer) gpollfd, NULL);
-       g_source_set_priority(src, G_PRIORITY_HIGH);
-
-       ret = g_source_attach(src, NULL);
-       if (ret == 0) {
-               ALARM_MGR_EXCEPTION_PRINT("g_source_attach() is failed.\n");
-               return;
-       }
-
-       g_source_unref(src);
-
-       alarm_context.timer = fd;
-}
-
 static void __initialize_alarm_list()
 {
        alarm_context.alarms = NULL;
@@ -3252,7 +3104,7 @@ static void __initialize_alarm_list()
 
        _load_alarms_from_db();
 
-       __rtc_set();    /*Set RTC1 Alarm with alarm due time for alarm-manager initialization*/
+       _rtc_set();     /*Set RTC1 Alarm with alarm due time for alarm-manager initialization*/
 }
 
 static void __initialize_scheduled_alarm_list()
@@ -3291,7 +3143,13 @@ void _alarm_initialize()
        vconf_get_int(VCONFKEY_ALARM_EXPIRE_MODE, &expire_mode);
        ALARM_MGR_LOG_PRINT("alarm_expire_mode : %d", expire_mode);
 
-       __initialize_timer();
+       alarm_context.timer = _initialize_timer();
+       if (alarm_context.timer == -1) {
+               ALARM_MGR_EXCEPTION_PRINT("because _initialize_timer failed, "
+                                         "alarm-server cannot be runned.\n");
+               exit(1);
+       }
+
        if (_initialize_dbus() == false) {
                /* because dbus's initialize
                 * failed, we cannot continue any more. */