4 * Copyright (c) 2000 - 2011 Samsung Electronics Co., Ltd. All rights reserved.
6 * Contact: Venkatesha Sarpangala <sarpangala.v@samsung.com>, Jayoun Lee <airjany@samsung.com>,
7 * Sewook Park <sewook7.park@samsung.com>, Jaeho Lee <jaeho81.lee@samsung.com>
9 * Licensed under the Apache License, Version 2.0 (the "License");
10 * you may not use this file except in compliance with the License.
11 * You may obtain a copy of the License at
13 * http://www.apache.org/licenses/LICENSE-2.0
15 * Unless required by applicable law or agreed to in writing, software
16 * distributed under the License is distributed on an "AS IS" BASIS,
17 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
18 * See the License for the specific language governing permissions and
19 * limitations under the License.
25 #define _BSD_SOURCE /*for localtime_r*/
36 #include<dbus/dbus-glib-lowlevel.h>
38 #if !GLIB_CHECK_VERSION (2, 31, 0)
39 #include <glib/gmacros.h>
43 /*#include "global-gconf.h"*/
45 #include"alarm-internal.h"
47 /*#include"limo-event-delivery.h"*/
52 #include <security-server.h>
55 #include <vconf-keys.h>
57 #define SIG_TIMER 0x32
58 #define WAKEUP_ALARM_APP_ID "org.tizen.alarm.ALARM"
59 /* alarm ui application's alarm's dbus_service name instead of 21
60 (alarm application's app_id) value */
61 #define WAKEUP_ALARMBOOTING_APP_ID "org.tizen.alarmboot.ui.ALARM"
62 /*alrmbooting ui application's dbus_service name instead of 121(alarmbooting
63 application's app_id) value */
65 #include "tapi_misc_ext.h"
67 #include "tapi_misc_data.h"
68 #include "tapi_power.h"
73 __alarm_server_context_t alarm_context;
74 bool g_dummy_timer_is_set = FALSE;
76 GSList *g_scheduled_alarm_list = NULL;
78 GSList *g_expired_alarm_list = NULL;
80 #ifndef RTC_WKALM_BOOT_SET
81 #define RTC_WKALM_BOOT_SET _IOW('p', 0x80, struct rtc_wkalrm)
85 bool enable_power_on_alarm;
87 time_t ab_due_time = -1;
88 bool poweron_alarm_expired = false;
91 /* 2008. 6. 3 sewook7.park
92 When the alarm becoms sleeping mode, alarm timer is not expired.
93 So using RTC, phone is awaken before alarm rings.
95 #define __WAKEUP_USING_RTC__
96 #ifdef __WAKEUP_USING_RTC__
98 #include <linux/rtc.h>
99 #include <sys/ioctl.h>
102 static const char default_rtc[] = "/dev/rtc1";
103 static const char power_rtc[] = "/dev/rtc0";
105 #endif /*__WAKEUP_USING_RTC__*/
107 static bool __alarm_add_to_list(__alarm_info_t *__alarm_info,
108 alarm_id_t *alarm_id);
109 static bool __alarm_update_in_list(int pid, alarm_id_t alarm_id,
110 __alarm_info_t *__alarm_info,
112 static bool __alarm_remove_from_list(int pid, alarm_id_t alarm_id,
114 static bool __alarm_set_start_and_end_time(alarm_info_t *alarm_info,
115 __alarm_info_t *__alarm_info);
116 static bool __alarm_update_due_time_of_all_items_in_list(double diff_time);
117 static bool __alarm_create(alarm_info_t *alarm_info, alarm_id_t *alarm_id,
118 int pid, char *app_service_name, char *app_service_name_mod,
119 const char *dst_service_name, const char *dst_service_name_mod, int *error_code);
120 static bool __alarm_create_appsvc(alarm_info_t *alarm_info, alarm_id_t *alarm_id,
121 int pid, char *bundle_data, int *error_code);
123 static bool __alarm_delete(int pid, alarm_id_t alarm_id, int *error_code);
124 static bool __alarm_update(int pid, char *app_service_name, alarm_id_t alarm_id,
125 alarm_info_t *alarm_info, int *error_code);
126 static bool __alarm_power_on(int app_id, bool on_off, int *error_code);
127 static bool __alarm_power_off(int app_id, int *error_code);
128 static bool __alarm_check_next_duetime(int app_id, int *error_code);
129 static void __alarm_send_noti_to_application(const char *app_service_name,
130 alarm_id_t alarm_id);
131 static void __alarm_expired();
132 static gboolean __alarm_handler_idle();
133 static void __alarm_handler(int sigNum, siginfo_t *pSigInfo, void *pUContext);
134 static void __clean_registry();
135 static bool __alarm_manager_reset();
136 static void __on_system_time_changed(keynode_t *node, void *data);
137 static void __initialize_timer();
138 static void __initialize_alarm_list();
139 static void __initialize_scheduled_alarm_lsit();
140 static void __hibernation_leave_callback();
141 static bool __initialize_noti();
143 static bool __initialize_dbus();
144 static bool __initialize_db();
145 static void __initialize();
146 static bool __check_false_alarm();
147 static DBusHandlerResult __alarm_server_filter(DBusConnection *connection,
148 DBusMessage *message,
151 static void __rtc_set()
153 #ifdef __WAKEUP_USING_RTC__
155 const char *rtc = default_rtc;
157 struct rtc_time rtc_tm;
158 struct rtc_wkalrm rtc_wk;
161 #ifdef _SIMUL /*if build is simulator, we don't need to set
162 RTC because RTC does not work in simulator.*/
163 ALARM_MGR_EXCEPTION_PRINT("because it is simulator's mode, "
164 "we don't set RTC.\n");
168 fd = open(rtc, O_RDONLY);
170 ALARM_MGR_EXCEPTION_PRINT("RTC open failed.\n");
174 /* Read the RTC time/date */
175 int retval = ioctl(fd, RTC_RD_TIME, &rtc_tm);
177 ALARM_MGR_EXCEPTION_PRINT("RTC_RD_TIME ioctl failed");
182 ALARM_MGR_LOG_PRINT("\n\nCurrent RTC date/time is %d-%d-%d, "
183 "%02d:%02d:%02d.\n", rtc_tm.tm_mday, rtc_tm.tm_mon + 1,
184 rtc_tm.tm_year + 1900, rtc_tm.tm_hour, rtc_tm.tm_min,
187 ALARM_MGR_LOG_PRINT("alarm_context.c_due_time is %d\n", \
188 alarm_context.c_due_time);
190 if (alarm_context.c_due_time != -1) {
191 time_t due_time = alarm_context.c_due_time - 1;
192 gmtime_r(&due_time, &due_tm);
194 rtc_tm.tm_mday = due_tm.tm_mday;
195 rtc_tm.tm_mon = due_tm.tm_mon;
196 rtc_tm.tm_year = due_tm.tm_year;
197 rtc_tm.tm_hour = due_tm.tm_hour;
198 rtc_tm.tm_min = due_tm.tm_min;
199 rtc_tm.tm_sec = due_tm.tm_sec;
200 memcpy(&rtc_wk.time, &rtc_tm, sizeof(rtc_tm));
204 ALARM_MGR_LOG_PRINT("\n\nSetted RTC Alarm date/time is "
205 "%d-%d-%d, %02d:%02d:%02d.\n", rtc_tm.tm_mday,
206 rtc_tm.tm_mon + 1, rtc_tm.tm_year + 1900,
207 rtc_tm.tm_hour, rtc_tm.tm_min, rtc_tm.tm_sec);
209 retval = ioctl(fd, RTC_WKALM_SET, &rtc_wk);
211 if (errno == ENOTTY) {
212 ALARM_MGR_EXCEPTION_PRINT("\nAlarm IRQs not"
215 ALARM_MGR_EXCEPTION_PRINT("RTC_ALM_SET ioctl");
219 ALARM_MGR_LOG_PRINT("[alarm-server]RTC alarm is setted");
221 /* Enable alarm interrupts */
222 retval = ioctl(fd, RTC_AIE_ON, 0);
224 ALARM_MGR_EXCEPTION_PRINT("RTC_AIE_ON ioctl failed");
228 ALARM_MGR_LOG_PRINT("[alarm-server]RTC alarm is on");
230 ALARM_MGR_LOG_PRINT("[alarm-server]alarm_context.c_due_time is"
231 "less than 10 sec. RTC alarm does not need to be set\n");
235 #endif /* __WAKEUP_USING_RTC__ */
238 int _set_rtc_time(time_t _time)
244 struct rtc_time rtc_tm;
245 const char *rtc0 = power_rtc;
246 const char *rtc1 = default_rtc;
250 fd0 = open(rtc0, O_RDONLY);
251 fd1 = open(rtc1, O_RDONLY);
254 ALARM_MGR_LOG_PRINT("error to open /dev/rtc0.");
259 ALARM_MGR_LOG_PRINT("error to open /dev/rtc1.");
263 memset(&rtc_tm, 0, sizeof(struct rtc_time));
266 _tm = gmtime_r(&_time, &time_r);
268 /* Write the RTC time/date 2008:05:21 19:20:00 */
271 rtc_tm.tm_mday = time_r.tm_mday;
272 rtc_tm.tm_mon = time_r.tm_mon;
273 rtc_tm.tm_year = time_r.tm_year;
274 rtc_tm.tm_hour = time_r.tm_hour;
275 rtc_tm.tm_min = time_r.tm_min;
279 retval0 = ioctl(fd0, RTC_SET_TIME, &rtc_tm);
283 ALARM_MGR_LOG_PRINT("error to ioctl fd0.");
288 retval1 = ioctl(fd1, RTC_SET_TIME, &rtc_tm);
292 ALARM_MGR_LOG_PRINT("error to ioctl fd1.");
300 bool __alarm_clean_list()
304 for (iter = alarm_context.alarms; iter != NULL;
305 iter = g_slist_next(iter)) {
309 g_slist_free(alarm_context.alarms);
313 static bool __alarm_add_to_list(__alarm_info_t *__alarm_info,
314 alarm_id_t *alarm_id)
317 bool unique_id = false;
318 alarm_info_t *alarm_info = &__alarm_info->alarm_info;
319 __alarm_info_t *entry = NULL;
323 /* FIXME: alarm id must be unique. */
324 __alarm_info->alarm_id = (int)(void *)__alarm_info;
325 ALARM_MGR_LOG_PRINT("__alarm_info->alarm_id is %d", \
326 __alarm_info->alarm_id);
328 while (unique_id == false) {
331 for (iter = alarm_context.alarms; iter != NULL;
332 iter = g_slist_next(iter)) {
334 if (entry->alarm_id == __alarm_info->alarm_id) {
335 __alarm_info->alarm_id++;
343 ALARM_MGR_LOG_PRINT("[alarm-server]: before add\n");
344 for (iter = alarm_context.alarms; iter != NULL;
345 iter = g_slist_next(iter)) {
347 /*ALARM_MGR_LOG_PRINT("[alarm-server]: alarm_id(%d)\n",
351 alarm_context.alarms =
352 g_slist_append(alarm_context.alarms, __alarm_info);
354 ALARM_MGR_LOG_PRINT("[alarm-server]: after add\n");
355 for (iter = alarm_context.alarms; iter != NULL;
356 iter = g_slist_next(iter)) {
358 ALARM_MGR_LOG_PRINT("[alarm-server]: alarm_id(%d)\n",
362 if (!(alarm_info->alarm_type & ALARM_TYPE_VOLATILE)) {
363 _save_alarms(__alarm_info);
366 *alarm_id = __alarm_info->alarm_id;
371 static bool __alarm_update_in_list(int pid, alarm_id_t alarm_id,
372 __alarm_info_t *__alarm_info,
376 alarm_info_t *alarm_info = &__alarm_info->alarm_info;
378 __alarm_info_t *entry = NULL;
380 for (iter = alarm_context.alarms; iter != NULL;
381 iter = g_slist_next(iter)) {
383 if (entry->alarm_id == alarm_id) {
386 __alarm_info->quark_app_unique_name =
387 entry->quark_app_unique_name;
388 __alarm_info->quark_dst_service_name =
389 entry->quark_dst_service_name;
390 memcpy(entry, __alarm_info, sizeof(__alarm_info_t));
398 *error_code = ERR_ALARM_INVALID_ID;
402 if (!(alarm_info->alarm_type & ALARM_TYPE_VOLATILE)) {
403 _update_alarms(__alarm_info);
409 static bool __alarm_remove_from_list(int pid, alarm_id_t alarm_id,
414 alarm_info_t *alarm_info = NULL;
417 __alarm_info_t *entry = NULL;
420 ALARM_MGR_LOG_PRINT("[alarm-server]: before del : alarm id(%d)\n",
423 for (iter = alarm_context.alarms; iter != NULL;
424 iter = g_slist_next(iter)) {
426 if (entry->alarm_id == alarm_id) {
427 alarm_info = &entry->alarm_info;
429 ALARM_MGR_LOG_PRINT("[alarm-server]: "
430 "__alarm_remove_from_list : alarm id(%d)\n",
433 if (!(alarm_info->alarm_type & ALARM_TYPE_VOLATILE)) {
434 _delete_alarms(alarm_id);
437 alarm_context.alarms =
438 g_slist_remove(alarm_context.alarms, iter->data);
445 ALARM_MGR_LOG_PRINT("[alarm-server]: after del\n");
449 *error_code = ERR_ALARM_INVALID_ID;
456 static bool __alarm_set_start_and_end_time(alarm_info_t *alarm_info,
457 __alarm_info_t *__alarm_info)
459 alarm_date_t *start = &alarm_info->start;
460 alarm_date_t *end = &alarm_info->end;
462 struct tm alarm_tm = { 0, };
464 if (start->year != 0) {
465 alarm_tm.tm_year = start->year - 1900;
466 alarm_tm.tm_mon = start->month - 1;
467 alarm_tm.tm_mday = start->day;
469 alarm_tm.tm_hour = 0;
473 __alarm_info->start = mktime(&alarm_tm);
475 __alarm_info->start = 0;
478 if (end->year != 0) {
479 alarm_tm.tm_year = end->year - 1900;
480 alarm_tm.tm_mon = end->month - 1;
481 alarm_tm.tm_mday = end->day;
483 alarm_tm.tm_hour = 23;
484 alarm_tm.tm_min = 59;
485 alarm_tm.tm_sec = 59;
487 __alarm_info->end = mktime(&alarm_tm);
489 __alarm_info->end = 0;
496 static bool alarm_get_tz_info(int *gmt_idx, int *dst)
498 GConfValue *value1 = NULL;
499 GConfValue *value2 = NULL;
500 GConfClient* gConfClient = NULL;
503 gConfClient = gconf_client_get_default();
506 value1 = gconf_client_get(gConfClient, SETTINGS_CLOCKTIMEZONE,
509 ALARM_MGR_LOG_PRINT("__on_system_time_changed:
510 gconf_client_get() failed:
511 error:[%s]\n", err->message);
515 *gmt_idx = gconf_value_get_int(value1);
516 ALARM_MGR_LOG_PRINT("gconf return gmt_idx =%d\n ", *gmt_idx);
518 value2 = gconf_client_get(gConfClient,
519 SETTINGS_DAYLIGHTSTATUS, &err);
521 ALARM_MGR_LOG_PRINT("__on_system_time_changed:
522 gconf_client_get() failed: error:[%s]\n", err->message);
527 *dst = gconf_value_get_int(value2);
528 ALARM_MGR_LOG_PRINT("gconf return dst =%d\n ", *dst);
530 if(gConfClient != NULL) {
531 g_object_unref(gConfClient);
536 ALARM_MGR_LOG_PRINT("check the gconf setting failed!!!!! \n ");
539 gconf_value_free(value1);
543 gconf_value_free(value2);
551 static bool __alarm_update_due_time_of_all_items_in_list(double diff_time)
554 time_t min_time = -1;
557 __alarm_info_t *entry = NULL;
558 struct tm *p_time = NULL ;
559 struct tm due_time_result ;
560 struct tm fixed_time ;
562 for (iter = alarm_context.alarms; iter != NULL;
563 iter = g_slist_next(iter)) {
565 alarm_info_t *alarm_info = &(entry->alarm_info);
566 if (alarm_info->alarm_type & ALARM_TYPE_RELATIVE) {
567 /*diff_time ó¸® */
569 entry->due_time += diff_time;
571 alarm_date_t *start = &alarm_info->start; /**< start
573 alarm_date_t *end = &alarm_info->end;;
574 /**< end time of the alarm */
577 p_time = localtime_r(&entry->due_time, &due_time_result);
578 if (p_time != NULL) {
579 start->year = p_time->tm_year + 1900;
580 start->month = p_time->tm_mon + 1;
581 start->day = p_time->tm_mday;
582 start->hour = p_time->tm_hour;
583 start->min = p_time->tm_min;
584 start->sec = p_time->tm_sec;
586 end->year = p_time->tm_year + 1900;
587 end->month = p_time->tm_mon + 1;
588 end->day = p_time->tm_mday;
591 memset(&fixed_time, 0, sizeof(fixed_time));
592 fixed_time.tm_year = p_time->tm_year;
593 fixed_time.tm_mon = p_time->tm_mon;
594 fixed_time.tm_mday = p_time->tm_mday;
595 fixed_time.tm_hour = 0;
596 fixed_time.tm_min = 0;
597 fixed_time.tm_sec = 0;
599 entry->start = mktime(&fixed_time);
601 fixed_time.tm_hour = 23;
602 fixed_time.tm_min = 59;
603 fixed_time.tm_sec = 59;
605 entry->end = mktime(&fixed_time);
607 ALARM_MGR_LOG_PRINT("alarm_info->alarm_type is "
608 "ALARM_TYPE_RELATIVE\n");
610 _update_alarms(entry);
613 _alarm_next_duetime(entry);
614 ALARM_MGR_LOG_PRINT("entry->due_time is %d\n", entry->due_time);
619 for (iter = alarm_context.alarms; iter != NULL;
620 iter = g_slist_next(iter)) {
622 due_time = entry->due_time;
626 ALARM_MGR_LOG_PRINT("alarm[%d] with duetime(%u) at "
627 "current(%u)\n", entry->alarm_id, due_time, current_time);
628 if (due_time == 0) { /* 0 means this alarm has been
633 interval = difftime(due_time, current_time);
636 ALARM_MGR_LOG_PRINT("this may be error.. alarm[%d]\n", \
641 interval = difftime(due_time, min_time);
643 if ((interval < 0) || min_time == -1) {
649 alarm_context.c_due_time = min_time;
654 static bool __alarm_create_appsvc(alarm_info_t *alarm_info, alarm_id_t *alarm_id,
655 int pid,char *bundle_data, int *error_code){
660 char due_time_r[100] = { 0 };
661 char proc_file[512] = { 0 };
662 char process_name[512] = { 0 };
663 char app_name[512] = { 0 };
665 char *proc_name_ptr = NULL;
670 __alarm_info_t *__alarm_info = NULL;
672 __alarm_info = malloc(sizeof(__alarm_info_t));
673 if (__alarm_info == NULL) {
674 ALARM_MGR_EXCEPTION_PRINT("Caution!! app_pid=%d, malloc "
675 "failed. it seems to be OOM\n", pid);
676 *error_code = -1; /* -1 means that system
677 failed internally. */
680 __alarm_info->pid = pid;
681 __alarm_info->alarm_id = -1;
684 /* we should consider to check whether pid is running or Not
686 memset(process_name, '\0', 512);
687 memset(proc_file, '\0', 512);
688 snprintf(proc_file, 512, "/proc/%d/cmdline", pid);
690 fd = open(proc_file, O_RDONLY);
692 ret = read(fd, process_name, 512);
696 ALARM_MGR_EXCEPTION_PRINT("Unable to get application name\n");
701 while (process_name[i] != '\0') {
702 if (process_name[i] == ' ') {
703 process_name[i] = '\0';
709 word = strtok_r(process_name, "/", &proc_name_ptr);
710 while (word != NULL) {
711 memset(app_name, 0, 512);
712 snprintf(app_name, 512, "%s", word);
713 word = strtok_r(NULL, "/", &proc_name_ptr);
715 __alarm_info->quark_app_unique_name =
716 g_quark_from_string(app_name);
717 } else { /* failure */
718 ALARM_MGR_EXCEPTION_PRINT("Caution!! app_pid(%d) seems to be "
719 "killed, so we failed to get proc file(%s) and do not create "
720 "alarm_info\n", pid, proc_file);
721 *error_code = -1; /*-1 means that system failed
727 __alarm_info->quark_bundle=g_quark_from_string(bundle_data);
728 __alarm_info->quark_app_service_name = g_quark_from_string("null");
729 __alarm_info->quark_dst_service_name = g_quark_from_string("null");
730 __alarm_info->quark_app_service_name_mod = g_quark_from_string("null");
731 __alarm_info->quark_dst_service_name_mod = g_quark_from_string("null");
733 __alarm_set_start_and_end_time(alarm_info, __alarm_info);
734 memcpy(&(__alarm_info->alarm_info), alarm_info, sizeof(alarm_info_t));
738 if (alarm_context.c_due_time < current_time) {
739 ALARM_MGR_EXCEPTION_PRINT("Caution!! alarm_context.c_due_time "
740 "(%d) is less than current time(%d)", alarm_context.c_due_time,
742 alarm_context.c_due_time = -1;
745 due_time = _alarm_next_duetime(__alarm_info);
746 if (__alarm_add_to_list(__alarm_info, alarm_id) == false) {
753 ALARM_MGR_EXCEPTION_PRINT("[alarm-server]:Create a new alarm: "
754 "due_time is 0, alarm(%d) \n", *alarm_id);
756 } else if (current_time == due_time) {
757 ALARM_MGR_EXCEPTION_PRINT("[alarm-server]:Create alarm: "
758 "current_time(%d) is same as due_time(%d)", current_time,
761 }else if (difftime(due_time, current_time) < 0){
762 ALARM_MGR_EXCEPTION_PRINT("[alarm-server]: Expired Due Time.[Due time=%d, Current Time=%d]!!!Do not add to schedule list\n", due_time, current_time);
765 localtime_r(&due_time, &ts_ret);
766 strftime(due_time_r, 30, "%c", &ts_ret);
767 ALARM_MGR_LOG_PRINT("[alarm-server]:Create a new alarm: "
768 "alarm(%d) due_time(%s)", *alarm_id,
772 ALARM_MGR_LOG_PRINT("[alarm-server]:alarm_context.c_due_time(%d), "
773 "due_time(%d)", alarm_context.c_due_time, due_time);
775 if (alarm_context.c_due_time == -1
776 || due_time < alarm_context.c_due_time) {
777 _clear_scheduled_alarm_list();
778 _add_to_scheduled_alarm_list(__alarm_info);
779 _alarm_set_timer(&alarm_context, alarm_context.timer, due_time,
781 alarm_context.c_due_time = due_time;
783 } else if (due_time == alarm_context.c_due_time) {
784 _add_to_scheduled_alarm_list(__alarm_info);
792 if (enable_power_on_alarm) {
793 __alarm_power_on(0, enable_power_on_alarm, NULL);
801 static bool __alarm_create(alarm_info_t *alarm_info, alarm_id_t *alarm_id,
802 int pid, char *app_service_name, char *app_service_name_mod,
803 const char *dst_service_name,const char *dst_service_name_mod, int *error_code)
808 char proc_file[256] = { 0 };
809 char process_name[512] = { 0 };
810 char app_name[256] = { 0 };
812 char *proc_name_ptr = NULL;
814 __alarm_info_t *__alarm_info = NULL;
816 __alarm_info = malloc(sizeof(__alarm_info_t));
817 if (__alarm_info == NULL) {
818 ALARM_MGR_EXCEPTION_PRINT("Caution!! app_pid=%d, malloc "
819 "failed. it seems to be OOM\n", pid);
820 *error_code = -1; /* -1 means that system
821 failed internally. */
824 __alarm_info->pid = pid;
825 __alarm_info->alarm_id = -1;
827 /* we should consider to check whether pid is running or Not
829 memset(process_name, '\0', 512);
830 memset(proc_file, '\0', 256);
831 snprintf(proc_file, 256, "/proc/%d/cmdline", pid);
836 fd = open(proc_file, O_RDONLY);
838 ret = read(fd, process_name, 512);
840 while (process_name[i] != '\0') {
841 if (process_name[i] == ' ') {
842 process_name[i] = '\0';
847 /* if (readlink(proc_file, process_name, 256)!=-1) */
850 word = strtok_r(process_name, "/", &proc_name_ptr);
851 while (word != NULL) {
852 memset(app_name, 0, 256);
853 snprintf(app_name, 256, "%s", word);
854 word = strtok_r(NULL, "/", &proc_name_ptr);
856 __alarm_info->quark_app_unique_name =
857 g_quark_from_string(app_name);
858 } else { /* failure */
860 __alarm_info->quark_app_unique_name =
861 g_quark_from_string("unknown");
862 ALARM_MGR_EXCEPTION_PRINT("Caution!! app_pid(%d) seems to be "
863 "killed, so we failed to get proc file(%s) and do not create "
864 "alarm_info\n", pid, proc_file);
865 *error_code = -1; /*-1 means that system failed
871 __alarm_info->quark_app_service_name =
872 g_quark_from_string(app_service_name);
873 __alarm_info->quark_app_service_name_mod =
874 g_quark_from_string(app_service_name_mod);
875 __alarm_info->quark_dst_service_name =
876 g_quark_from_string(dst_service_name);
877 __alarm_info->quark_dst_service_name_mod =
878 g_quark_from_string(dst_service_name_mod);
879 __alarm_info->quark_bundle = g_quark_from_string("null");
882 __alarm_set_start_and_end_time(alarm_info, __alarm_info);
883 memcpy(&(__alarm_info->alarm_info), alarm_info, sizeof(alarm_info_t));
887 ALARM_MGR_LOG_PRINT("[alarm-server]:pid=%d, app_unique_name=%s, "
888 "app_service_name=%s,dst_service_name=%s, c_due_time=%d", \
889 pid, g_quark_to_string(__alarm_info->quark_app_unique_name), \
890 g_quark_to_string(__alarm_info->quark_app_service_name), \
891 g_quark_to_string(__alarm_info->quark_dst_service_name), \
892 alarm_context.c_due_time);
894 if (alarm_context.c_due_time < current_time) {
895 ALARM_MGR_EXCEPTION_PRINT("Caution!! alarm_context.c_due_time "
896 "(%d) is less than current time(%d)", alarm_context.c_due_time,
898 alarm_context.c_due_time = -1;
901 due_time = _alarm_next_duetime(__alarm_info);
902 if (__alarm_add_to_list(__alarm_info, alarm_id) == false) {
908 ALARM_MGR_EXCEPTION_PRINT("[alarm-server]:Create a new alarm: "
909 "due_time is 0, alarm(%d) \n", *alarm_id);
911 } else if (current_time == due_time) {
912 ALARM_MGR_EXCEPTION_PRINT("[alarm-server]:Create alarm: "
913 "current_time(%d) is same as due_time(%d)", current_time,
916 }else if (difftime(due_time, current_time) < 0){
917 ALARM_MGR_EXCEPTION_PRINT("[alarm-server]: Expired Due Time.[Due time=%d, Current Time=%d]!!!Do not add to schedule list\n", due_time, current_time);
920 char due_time_r[100] = { 0 };
922 localtime_r(&due_time, &ts_ret);
923 strftime(due_time_r, 30, "%c", &ts_ret);
924 ALARM_MGR_LOG_PRINT("[alarm-server]:Create a new alarm: "
925 "alarm(%d) due_time(%s)", *alarm_id,
929 ALARM_MGR_LOG_PRINT("[alarm-server]:alarm_context.c_due_time(%d), "
930 "due_time(%d)", alarm_context.c_due_time, due_time);
932 if (alarm_context.c_due_time == -1
933 || due_time < alarm_context.c_due_time) {
934 _clear_scheduled_alarm_list();
935 _add_to_scheduled_alarm_list(__alarm_info);
936 _alarm_set_timer(&alarm_context, alarm_context.timer, due_time,
938 alarm_context.c_due_time = due_time;
940 } else if (due_time == alarm_context.c_due_time) {
941 _add_to_scheduled_alarm_list(__alarm_info);
949 if (enable_power_on_alarm) {
950 /* orginally first arg's value was 21(app_id, WAKEUP_ALARM_APP_ID) in a
951 * platform with app-server.because __alarm_power_on(..) fuction don't
952 * use first parameter internally, we set this value to 0(zero)
954 __alarm_power_on(0, enable_power_on_alarm, NULL);
960 static bool __alarm_update(int pid, char *app_service_name, alarm_id_t alarm_id,
961 alarm_info_t *alarm_info, int *error_code)
966 __alarm_info_t *__alarm_info = NULL;
969 __alarm_info = malloc(sizeof(__alarm_info_t));
970 if (__alarm_info == NULL) {
971 ALARM_MGR_EXCEPTION_PRINT("Caution!! app_pid=%d, "
972 "malloc failed. it seems to be OOM\n", pid);
973 *error_code = -1; /*-1 means that system failed
978 __alarm_info->pid = pid;
979 __alarm_info->alarm_id = alarm_id;
981 /* we should consider to check whether pid is running or Not
984 __alarm_info->quark_app_service_name =
985 g_quark_from_string(app_service_name);
986 __alarm_set_start_and_end_time(alarm_info, __alarm_info);
987 memcpy(&(__alarm_info->alarm_info), alarm_info, sizeof(alarm_info_t));
991 if (alarm_context.c_due_time < current_time) {
992 ALARM_MGR_EXCEPTION_PRINT("Caution!! alarm_context.c_due_time "
993 "(%d) is less than current time(%d)", alarm_context.c_due_time,
995 alarm_context.c_due_time = -1;
998 due_time = _alarm_next_duetime(__alarm_info);
999 if (!__alarm_update_in_list(pid, alarm_id, __alarm_info, error_code)) {
1001 ALARM_MGR_EXCEPTION_PRINT("[alarm-server]: requested alarm_id "
1002 "(%d) does not exist. so this value is invalid id.", alarm_id);
1005 /* ALARM_MGR_LOG_PRINT("[alarm-server]:request_pid=%d, alarm_id=%d,
1006 * app_unique_name=%s, app_service_name=%s, dst_service_name=%s,
1007 * c_due_time=%d", pid, alarm_id, g_quark_to_string
1008 * (__alarm_info->quark_app_unique_name), g_quark_to_string
1009 * (__alarm_info->quark_app_service_name), g_quark_to_string
1010 * (__alarm_info->quark_dst_service_name), alarm_context.c_due_time);
1013 result = _remove_from_scheduled_alarm_list(pid, alarm_id);
1015 if (result == true && g_slist_length(g_scheduled_alarm_list) == 0) {
1016 /*there is no scheduled alarm */
1017 _alarm_disable_timer(alarm_context);
1020 ALARM_MGR_LOG_PRINT("[alarm-server]:Update alarm: alarm(%d)\n",
1027 if (enable_power_on_alarm) {
1028 /* orginally first arg's value was 21(app_id, WAKEUP_ALARM_APP_ID) in
1029 * a platform with app-server.because __alarm_power_on(..) fuction don't
1030 * use first parameter internally, we set this value to 0(zero)
1032 __alarm_power_on(0, enable_power_on_alarm, NULL);
1036 if (due_time == 0) {
1037 ALARM_MGR_EXCEPTION_PRINT("[alarm-server]:Update alarm: "
1044 if (due_time == 0) {
1045 ALARM_MGR_EXCEPTION_PRINT("[alarm-server]:Update alarm: "
1046 "due_time is 0, alarm(%d)\n", alarm_id);
1049 } else if (current_time == due_time) {
1050 ALARM_MGR_EXCEPTION_PRINT("[alarm-server]:Update alarm: "
1051 "current_time(%d) is same as due_time(%d)", current_time,
1055 }else if (difftime(due_time, current_time)< 0){
1056 ALARM_MGR_EXCEPTION_PRINT("[alarm-server]: Expired Due Time.[Due time=%d, Current Time=%d]!!!Do not add to schedule list\n", due_time, current_time);
1059 char due_time_r[100] = { 0 };
1061 localtime_r(&due_time, &ts_ret);
1062 strftime(due_time_r, 30, "%c", &ts_ret);
1063 ALARM_MGR_LOG_PRINT("[alarm-server]:Update alarm: alarm(%d) "
1064 "due_time(%s)\n", alarm_id, due_time_r);
1067 ALARM_MGR_LOG_PRINT("[alarm-server]:alarm_context.c_due_time(%d), "
1068 "due_time(%d)", alarm_context.c_due_time, due_time);
1070 if (alarm_context.c_due_time == -1
1071 || due_time < alarm_context.c_due_time) {
1072 _clear_scheduled_alarm_list();
1073 _add_to_scheduled_alarm_list(__alarm_info);
1074 _alarm_set_timer(&alarm_context, alarm_context.timer, due_time,
1076 alarm_context.c_due_time = due_time;
1077 ALARM_MGR_LOG_PRINT("[alarm-server1]:alarm_context.c_due_time "
1078 "(%d), due_time(%d)", alarm_context.c_due_time, due_time);
1079 } else if (due_time == alarm_context.c_due_time) {
1080 _add_to_scheduled_alarm_list(__alarm_info);
1081 ALARM_MGR_LOG_PRINT("[alarm-server2]:alarm_context.c_due_time "
1082 "(%d), due_time(%d)", alarm_context.c_due_time, due_time);
1089 if (enable_power_on_alarm) {
1090 /* orginally first arg's value was 21(app_id, WAKEUP_ALARM_APP_ID)
1091 * in a platform with app-server.because __alarm_power_on(..) fuction
1092 * don't use first parameter internally, we set this value to 0(zero)
1094 __alarm_power_on(0, enable_power_on_alarm, NULL);
1101 static bool __alarm_delete(int pid, alarm_id_t alarm_id, int *error_code)
1103 bool result = false;
1105 ALARM_MGR_LOG_PRINT("[alarm-server]:delete alarm: alarm(%d) pid(%d)\n",\
1107 result = _remove_from_scheduled_alarm_list(pid, alarm_id);
1109 if (!__alarm_remove_from_list(pid, alarm_id, error_code)) {
1111 ALARM_MGR_EXCEPTION_PRINT("[alarm-server]:delete alarm: "
1112 "alarm(%d) pid(%d) has failed with error_code(%d)\n",
1113 alarm_id, pid, *error_code);
1117 if (result == true && g_slist_length(g_scheduled_alarm_list) == 0) {
1118 _alarm_disable_timer(alarm_context);
1126 if (enable_power_on_alarm) {
1127 /* orginally first arg's value was 21(app_id, WAKEUP_ALARM_APP_ID) in a
1128 * platform with app-server.because __alarm_power_on(..) fuction don't
1129 * use first parameter internally, we set this value to 0(zero)
1131 __alarm_power_on(0, enable_power_on_alarm, NULL);
1138 static bool __alarm_power_on(int app_id, bool on_off, int *error_code)
1141 time_t min_time = 0;
1142 time_t current_time = 0;
1143 struct tm *temp_info;
1144 struct rtc_time rtc_tm = { 0, };
1145 struct tm min_time_r;
1149 enable_power_on_alarm = on_off;
1150 /*_update_power_on(on_off); */ /*currently its empty*/
1152 fd = open(power_rtc, O_RDONLY);
1154 ALARM_MGR_EXCEPTION_PRINT("cannot open /dev/rtc0\n");
1158 if (on_off == true) {
1159 if (_alarm_find_mintime_power_on(&min_time) == true) {
1161 ab_due_time = min_time;
1163 min_time = min_time - 60;
1165 time(¤t_time);
1167 if (min_time <= current_time)
1168 min_time = current_time + 5;
1170 temp_info = gmtime_r(&min_time, &min_time_r);
1172 ALARM_MGR_LOG_PRINT("__alarm_power_on : %d %d %d %d "
1174 min_time_r.tm_year,\
1176 min_time_r.tm_mday,\
1177 min_time_r.tm_hour,\
1179 ALARM_MGR_LOG_PRINT("__alarm_power_on : %d %d %d %d "
1181 min_time_r.tm_year,\
1183 min_time_r.tm_mday,\
1184 min_time_r.tm_hour,\
1187 rtc_tm.tm_mday = min_time_r.tm_mday;
1188 rtc_tm.tm_mon = min_time_r.tm_mon;
1189 rtc_tm.tm_year = min_time_r.tm_year;
1190 rtc_tm.tm_hour = min_time_r.tm_hour;
1191 rtc_tm.tm_min = min_time_r.tm_min;
1192 rtc_tm.tm_sec = min_time_r.tm_sec;
1193 /*set_info.time_zone = 0; */
1194 /*set_info.u_interval.day_of_week = 0; */
1196 /*ALARM_MGR_LOG_PRINT("####__alarm_power_on : %d %d
1197 %d %d %d\n",set_info.year,set_info.month,set_info.day,
1198 set_info.hour,set_info.minute); */
1200 ALARM_MGR_LOG_PRINT("due_time : %d \n", ab_due_time);
1202 ALARM_MGR_LOG_PRINT("\n\nSetted RTC Alarm date/time is "
1203 "%d-%d-%d, %02d:%02d:%02d.\n",
1204 rtc_tm.tm_mday, rtc_tm.tm_mon + 1,
1205 rtc_tm.tm_year + 1900, rtc_tm.tm_hour,
1206 rtc_tm.tm_min, rtc_tm.tm_sec);
1208 retval = ioctl(fd, RTC_ALM_SET, &rtc_tm);
1210 if (errno == ENOTTY) {
1211 ALARM_MGR_EXCEPTION_PRINT(
1212 "\n...Alarm IRQs not supported.\n");
1214 ALARM_MGR_EXCEPTION_PRINT("RTC_ALM_SET ioctl");
1218 ALARM_MGR_LOG_PRINT("[alarm-server]RTC "
1219 "alarm(POWER ON) is setted");
1221 /* Enable alarm interrupts */
1222 retval = ioctl(fd, RTC_AIE_ON, 0);
1224 ALARM_MGR_EXCEPTION_PRINT(
1225 "RTC_AIE_ON ioctl failed");
1229 ALARM_MGR_LOG_PRINT("[alarm-server]RTC(POWER ON) "
1233 retval = ioctl(fd, RTC_AIE_OFF, 0);
1235 ALARM_MGR_LOG_PRINT("__alarm_power_on : off\n");
1236 retval = ioctl(fd, RTC_AIE_OFF, 0);
1240 #endif /* #ifdef __ALARM_BOOT */
1245 static bool __alarm_power_off(int app_id, int *error_code)
1249 #endif /* #ifdef __ALARM_BOOT */
1253 static bool __alarm_check_next_duetime(int app_id, int *error_code)
1256 time_t current_time;
1259 time(¤t_time);
1261 interval = ab_due_time - current_time;
1263 ALARM_MGR_LOG_PRINT("due_time : %d / current_time %d\n", ab_due_time,
1266 if (interval > 0 && interval <= 60)
1270 #else /* #ifdef __ALARM_BOOT */
1275 static void __alarm_send_noti_to_application(const char *app_service_name,
1276 alarm_id_t alarm_id)
1280 char service_name[MAX_SERVICE_NAME_LEN];
1281 char object_name[MAX_SERVICE_NAME_LEN];
1283 DBusMessage *message;
1284 DBusMessageIter iter;
1286 if (app_service_name == NULL || strlen(app_service_name) == 0) {
1287 ALARM_MGR_EXCEPTION_PRINT("This alarm destination is "
1291 memset(service_name, 0, MAX_SERVICE_NAME_LEN);
1292 memcpy(service_name, app_service_name, strlen(app_service_name));
1294 snprintf(object_name, MAX_SERVICE_NAME_LEN,
1295 "/org/tizen/alarm/client");
1297 ALARM_MGR_LOG_PRINT("[alarm server][send expired_alarm(alarm_id=%d)to"
1298 "app_service_name(%s), object_name(%s), interface_name(%s)]\n",\
1299 alarm_id, service_name, object_name, "org.tizen.alarm.client");
1301 message = dbus_message_new_method_call(service_name,
1303 "org.tizen.alarm.client",
1305 if (message == NULL) {
1306 ALARM_MGR_EXCEPTION_PRINT("[alarm server] "
1307 "dbus_message_new_method_call faild. maybe OOM!.\n");
1308 ALARM_MGR_EXCEPTION_PRINT("[alarm server] so we cannot "
1309 "send expired alarm to %s\n", service_name);
1313 dbus_message_set_no_reply(message, TRUE);
1314 /* if(service_name[0]==':') */
1315 /* we don't need auto activation in a case that
1316 destination_app_service_name starts with a charactor like (:) */
1317 dbus_message_set_auto_start(message, FALSE);
1319 dbus_message_iter_init_append(message, &iter);
1320 if (!dbus_message_iter_append_basic
1321 (&iter, DBUS_TYPE_INT32, &alarm_id)) {
1322 dbus_message_unref(message);
1323 ALARM_MGR_EXCEPTION_PRINT("[alarm server] "
1324 "dbus_message_iter_append_basic faild. maybe OOM!.\n");
1328 dbus_connection_send(dbus_g_connection_get_connection
1329 (alarm_context.bus), message, NULL);
1330 dbus_connection_flush(dbus_g_connection_get_connection
1331 (alarm_context.bus));
1332 dbus_message_unref(message);
1336 static void __alarm_expired()
1338 const char *destination_app_service_name = NULL;
1339 alarm_id_t alarm_id = -1;
1341 __alarm_info_t *__alarm_info = NULL;
1342 char alarm_id_val[32]={0,};
1346 ALARM_MGR_LOG_PRINT("[alarm-server]: Enter \n");
1348 time_t current_time;
1351 time(¤t_time);
1353 interval = difftime(alarm_context.c_due_time, current_time);
1354 ALARM_MGR_LOG_PRINT("[alarm-server]: c_due_time(%d), "
1355 "current_time(%d), interval(%d)\n", alarm_context.c_due_time,
1356 current_time, interval);
1358 if (alarm_context.c_due_time > current_time) {
1359 ALARM_MGR_LOG_PRINT("[alarm-server]: False Alarm\n");
1363 GSList *iter = NULL;
1364 __scheduled_alarm_t *alarm = NULL;
1366 for (iter = g_scheduled_alarm_list; iter != NULL;
1367 iter = g_slist_next(iter)) {
1369 alarm_id = alarm->alarm_id;
1371 __alarm_info = alarm->__alarm_info;
1373 app_pid = __alarm_info->pid;
1376 (g_quark_to_string(__alarm_info->quark_bundle),
1379 b_len = strlen(g_quark_to_string(__alarm_info->quark_bundle));
1381 b = bundle_decode((bundle_raw *)g_quark_to_string(__alarm_info->quark_bundle), b_len);
1385 ALARM_MGR_EXCEPTION_PRINT("Error!!!..Unable to decode the bundle!!\n");
1389 snprintf(alarm_id_val,31,"%d",alarm_id);
1391 if (bundle_add(b,"http://tizen.org/appcontrol/data/alarm_id", alarm_id_val)){
1392 ALARM_MGR_EXCEPTION_PRINT("Unable to add alarm id to the bundle\n");
1396 if ( appsvc_run_service(b, 0, NULL, NULL) < 0)
1398 ALARM_MGR_EXCEPTION_PRINT("Unable to run app svc\n");
1402 ALARM_MGR_LOG_PRINT("Successfuly ran app svc\n");
1412 (g_quark_to_string(__alarm_info->quark_dst_service_name),
1414 ALARM_MGR_LOG_PRINT("[alarm-server]:destination is "
1415 "null, so we send expired alarm to %s(%u)\n",\
1417 __alarm_info->quark_app_service_name),
1418 __alarm_info->quark_app_service_name);
1419 destination_app_service_name = g_quark_to_string(
1420 __alarm_info->quark_app_service_name_mod);
1422 ALARM_MGR_LOG_PRINT("[alarm-server]:destination "
1425 __alarm_info->quark_dst_service_name),
1426 __alarm_info->quark_dst_service_name);
1427 destination_app_service_name = g_quark_to_string(
1428 __alarm_info->quark_dst_service_name_mod);
1432 /* orginally this code had if(__alarm_info->app_id==21) in a
1433 platform with app-server. */
1434 /*if(__alarm_info->quark_dst_service_name ==
1435 g_quark_from_string (WAKEUP_ALARM_APP_ID)) */
1437 (g_quark_to_string(__alarm_info->quark_dst_service_name),
1438 WAKEUP_ALARM_APP_ID) == 0) {
1440 fd = open(power_rtc, O_RDONLY);
1442 ALARM_MGR_LOG_PRINT("cannot open /dev/rtc0\n");
1444 ioctl(fd, RTC_AIE_OFF, 0);
1451 * we should consider a situation that
1452 * destination_app_service_name is owner_name like (:xxxx) and
1453 * application's pid which registered this alarm was killed.In that case,
1454 * we don't need to send the expire event because the process was killed.
1455 * this causes needless message to be sent.
1457 ALARM_MGR_LOG_PRINT("[alarm-server]: "
1458 "destination_app_service_name :%s, app_pid=%d\n",
1459 destination_app_service_name, app_pid);
1460 /* the following is a code that checks the above situation.
1461 please verify this code. */
1463 if (dbus_bus_name_has_owner(
1464 dbus_g_connection_get_connection(alarm_context.bus),
1465 destination_app_service_name, NULL) == FALSE) {
1466 __expired_alarm_t *expire_info;
1467 char appid[MAX_SERVICE_NAME_LEN] = { 0, };
1468 char alarm_id_str[32] = { 0, };
1470 expire_info = malloc(sizeof(__expired_alarm_t));
1471 if (G_UNLIKELY(NULL == expire_info)){
1472 ALARM_MGR_ASSERT_PRINT("[alarm-server]:Malloc failed!Can't notify alarm expiry info\n");
1475 strncpy(expire_info->service_name,
1476 destination_app_service_name,
1477 MAX_SERVICE_NAME_LEN);
1478 expire_info->alarm_id = alarm_id;
1479 g_expired_alarm_list =
1480 g_slist_append(g_expired_alarm_list, expire_info);
1484 (g_quark_to_string(__alarm_info->quark_dst_service_name),
1486 strncpy(appid,g_quark_to_string(__alarm_info->quark_app_service_name),strlen(g_quark_to_string(__alarm_info->quark_app_service_name))-6);
1490 strncpy(appid,g_quark_to_string(__alarm_info->quark_dst_service_name),strlen(g_quark_to_string(__alarm_info->quark_dst_service_name))-6);
1493 snprintf(alarm_id_str, 31, "%d", alarm_id);
1495 ALARM_MGR_LOG_PRINT("before aul_launch appid(%s) "
1496 "alarm_id_str(%s)\n", appid, alarm_id_str);
1499 kb = bundle_create();
1500 bundle_add(kb, "__ALARM_MGR_ID", alarm_id_str);
1501 aul_launch_app(appid, kb);
1504 ALARM_MGR_LOG_PRINT(
1505 "before alarm_send_noti_to_application\n");
1506 __alarm_send_noti_to_application(
1507 destination_app_service_name, alarm_id);
1510 ALARM_MGR_LOG_PRINT("after __alarm_send_noti_to_application\n");
1512 /* if( !(__alarm_info->alarm_info.alarm_type
1513 & ALARM_TYPE_VOLATILE) ) {
1514 __alarm_remove_from_list(__alarm_info->pid,
1518 if (__alarm_info->alarm_info.mode.repeat
1519 == ALARM_REPEAT_MODE_ONCE) {
1520 /* _alarm_next_duetime(__alarm_info);*/
1521 /* _update_alarms(__alarm_info);*/
1522 __alarm_remove_from_list(__alarm_info->pid, alarm_id,
1526 _alarm_next_duetime(__alarm_info);
1527 /* _update_alarms(__alarm_info);*/
1533 _clear_scheduled_alarm_list();
1534 alarm_context.c_due_time = -1;
1536 ALARM_MGR_LOG_PRINT("[alarm-server]: Leave \n");
1539 static gboolean __alarm_handler_idle()
1541 if (g_dummy_timer_is_set == true) {
1542 ALARM_MGR_LOG_PRINT("dummy alarm timer has expired\n");
1544 ALARM_MGR_LOG_PRINT("__alarm_handler \n");
1545 ALARM_MGR_LOG_PRINT("__alarm_handler \n");
1557 if (enable_power_on_alarm) {
1558 /* orginally first arg's value was 21(app_id, WAKEUP_ALARM_APP_ID)
1559 *in a platform with app-server.because __alarm_power_on(..) fuction
1560 *don't use first parameter internally, we set this value to 0(zero)
1562 __alarm_power_on(0, enable_power_on_alarm, NULL);
1565 pm_unlock_state(LCD_OFF, PM_SLEEP_MARGIN);
1570 static void __alarm_handler(int sigNum, siginfo_t *pSigInfo, void *pUContext)
1573 pm_lock_state(LCD_OFF, STAY_CUR_STATE, 0);
1575 /* we moved __alarm_expired() function to __alarm_handler_idle GSource
1576 because of signal safety. */
1577 g_idle_add_full(G_PRIORITY_HIGH_IDLE, __alarm_handler_idle, NULL, NULL);
1580 static void __clean_registry()
1583 /*TODO:remove all db entries */
1586 static bool __alarm_manager_reset()
1589 _alarm_disable_timer(alarm_context);
1591 __alarm_clean_list();
1593 _clear_scheduled_alarm_list();
1599 static void __on_system_time_changed(keynode_t *node, void *data)
1605 _alarm_disable_timer(alarm_context);
1608 _time = vconf_keynode_get_int(node);
1610 vconf_get_int(VCONFKEY_SYSTEM_TIMECHANGE, (int *)&_time);
1614 diff_time = difftime(_time, before);
1618 ALARM_MGR_ASSERT_PRINT("diff_time is %f\n", diff_time);
1620 ALARM_MGR_LOG_PRINT("[alarm-server] System time has been changed\n");
1621 ALARM_MGR_LOG_PRINT("1.alarm_context.c_due_time is %d\n",
1622 alarm_context.c_due_time);
1626 vconf_set_dbl(VCONFKEY_SYSTEM_TIMEDIFF, diff_time);
1627 vconf_set_int(VCONFKEY_SYSTEM_TIME_CHANGED,(int)diff_time);
1629 if (heynoti_publish(SYSTEM_TIME_CHANGED))
1630 ALARM_MGR_EXCEPTION_PRINT("alarm-server: Unable to publish heynoti for system time change\n");
1632 __alarm_update_due_time_of_all_items_in_list(diff_time);
1634 ALARM_MGR_LOG_PRINT("2.alarm_context.c_due_time is %d\n",
1635 alarm_context.c_due_time);
1636 _clear_scheduled_alarm_list();
1641 if (enable_power_on_alarm) {
1642 /* orginally first arg's value was 21(app_id, WAKEUP_ALARM_
1643 APP_ID) in a platform with app-server. because _alarm_power_
1644 on(..) fuction don't use first parameter internally, we set
1645 this value to 0(zero)
1647 __alarm_power_on(0, enable_power_on_alarm, NULL);
1653 gboolean alarm_manager_alarm_set_rtc_time(void *pObject, int pid,
1654 int year, int mon, int day,
1655 int hour, int min, int sec, char *e_cookie,
1657 guchar *cookie = NULL;
1660 gboolean result = true;
1663 const char *rtc = power_rtc;
1665 struct rtc_time rtc_tm = {0,};
1666 struct rtc_wkalrm rtc_wk;
1667 struct tm *alarm_tm = NULL;
1668 struct tm due_tm = {0,};
1672 *return_code = ALARMMGR_RESULT_SUCCESS;
1675 cookie = g_base64_decode(e_cookie, &size);
1679 *return_code = ERR_ALARM_NO_PERMISSION;
1680 ALARM_MGR_EXCEPTION_PRINT("Unable to decode cookie!!!\n");
1684 call_gid = security_server_get_gid("alarm");
1686 ALARM_MGR_LOG_PRINT("call_gid : %d\n", call_gid);
1688 retval = security_server_check_privilege((const char *)cookie, call_gid);
1690 if (retval == SECURITY_SERVER_API_ERROR_ACCESS_DENIED) {
1691 ALARM_MGR_EXCEPTION_PRINT(
1692 "%s", "access has been denied\n");
1694 ALARM_MGR_EXCEPTION_PRINT("Error has occurred in security_server_check_privilege()\n");
1696 *return_code = ERR_ALARM_NO_PERMISSION;
1700 /*extract day of the week, day in the year &
1701 daylight saving time from system*/
1704 alarm_tm = localtime(&ctime);
1706 alarm_tm->tm_year = year;
1707 alarm_tm->tm_mon = mon;
1708 alarm_tm->tm_mday = day;
1709 alarm_tm->tm_hour = hour;
1710 alarm_tm->tm_min = min;
1711 alarm_tm->tm_sec = sec;
1713 /*convert to calendar time representation*/
1714 time_t rtc_time = mktime(alarm_tm);
1716 /*convert to Coordinated Universal Time (UTC)*/
1717 gmtime_r(&rtc_time, &due_tm);
1719 fd = open(rtc, O_RDONLY);
1721 ALARM_MGR_EXCEPTION_PRINT("RTC open failed.\n");
1723 *return_code = ERR_ALARM_SYSTEM_FAIL;
1727 /* Read the RTC time/date */
1728 retval = ioctl(fd, RTC_RD_TIME, &rtc_tm);
1730 ALARM_MGR_EXCEPTION_PRINT("RTC_RD_TIME ioctl failed");
1733 *return_code = ERR_ALARM_SYSTEM_FAIL;
1737 rtc_tm.tm_mday = due_tm.tm_mday;
1738 rtc_tm.tm_mon = due_tm.tm_mon;
1739 rtc_tm.tm_year = due_tm.tm_year;
1740 rtc_tm.tm_hour = due_tm.tm_hour;
1741 rtc_tm.tm_min = due_tm.tm_min;
1742 rtc_tm.tm_sec = due_tm.tm_sec;
1744 memcpy(&rtc_wk.time, &rtc_tm, sizeof(rtc_tm));
1749 retval = ioctl(fd, RTC_WKALM_BOOT_SET, &rtc_wk);
1751 if (errno == ENOTTY) {
1752 ALARM_MGR_EXCEPTION_PRINT("\nAlarm IRQs not"
1755 ALARM_MGR_EXCEPTION_PRINT("RTC_ALM_SET ioctl");
1758 *return_code = ERR_ALARM_SYSTEM_FAIL;
1761 ALARM_MGR_LOG_PRINT("[alarm-server]RTC alarm is setted");
1762 /* Enable alarm interrupts */
1763 retval = ioctl(fd, RTC_AIE_ON, 0);
1765 ALARM_MGR_EXCEPTION_PRINT("RTC_AIE_ON ioctl failed");
1767 *return_code = ERR_ALARM_SYSTEM_FAIL;
1782 gboolean alarm_manager_alarm_create_appsvc(void *pObject, int pid,
1784 int start_month, int start_day,
1785 int start_hour, int start_min,
1786 int start_sec, int end_year, int end_month,
1787 int end_day, int mode_day_of_week,
1788 int mode_repeat, int alarm_type,
1790 char *bundle_data, char *e_cookie,
1791 int *alarm_id, int *return_code)
1793 alarm_info_t alarm_info;
1794 guchar *cookie = NULL;
1798 gboolean result = true;
1800 alarm_info.start.year = start_year;
1801 alarm_info.start.month = start_month;
1802 alarm_info.start.day = start_day;
1803 alarm_info.start.hour = start_hour;
1804 alarm_info.start.min = start_min;
1805 alarm_info.start.sec = start_sec;
1807 alarm_info.end.year = end_year;
1808 alarm_info.end.month = end_month;
1809 alarm_info.end.day = end_day;
1811 alarm_info.mode.u_interval.day_of_week = mode_day_of_week;
1812 alarm_info.mode.repeat = mode_repeat;
1814 alarm_info.alarm_type = alarm_type;
1815 alarm_info.reserved_info = reserved_info;
1819 cookie = g_base64_decode(e_cookie, &size);
1823 ALARM_MGR_EXCEPTION_PRINT("Unable to decode cookie!!!\n");
1827 call_gid = security_server_get_gid("alarm");
1829 ALARM_MGR_LOG_PRINT("call_gid : %d\n", call_gid);
1831 retval = security_server_check_privilege((const char *)cookie, call_gid);
1833 if (retval == SECURITY_SERVER_API_ERROR_ACCESS_DENIED) {
1834 ALARM_MGR_EXCEPTION_PRINT(
1835 "%s", "access has been denied\n");
1837 ALARM_MGR_EXCEPTION_PRINT("Error has occurred in security_server_check_privilege()\n");
1842 result = __alarm_create_appsvc(&alarm_info, alarm_id, pid,
1843 bundle_data, return_code);
1844 if (false == result)
1846 ALARM_MGR_EXCEPTION_PRINT("Unable to create alarm!\n");
1858 gboolean alarm_manager_alarm_create(void *pObject, int pid,
1859 char *app_service_name, char *app_service_name_mod, int start_year,
1860 int start_month, int start_day,
1861 int start_hour, int start_min,
1862 int start_sec, int end_year, int end_month,
1863 int end_day, int mode_day_of_week,
1864 int mode_repeat, int alarm_type,
1866 char *reserved_service_name, char *reserved_service_name_mod, char *e_cookie,
1867 int *alarm_id, int *return_code)
1869 alarm_info_t alarm_info;
1875 alarm_info.start.year = start_year;
1876 alarm_info.start.month = start_month;
1877 alarm_info.start.day = start_day;
1878 alarm_info.start.hour = start_hour;
1879 alarm_info.start.min = start_min;
1880 alarm_info.start.sec = start_sec;
1882 alarm_info.end.year = end_year;
1883 alarm_info.end.month = end_month;
1884 alarm_info.end.day = end_day;
1886 alarm_info.mode.u_interval.day_of_week = mode_day_of_week;
1887 alarm_info.mode.repeat = mode_repeat;
1889 alarm_info.alarm_type = alarm_type;
1890 alarm_info.reserved_info = reserved_info;
1894 cookie = g_base64_decode(e_cookie, &size);
1895 call_gid = security_server_get_gid("alarm");
1897 ALARM_MGR_LOG_PRINT("call_gid : %d\n", call_gid);
1899 retval = security_server_check_privilege((const char *)cookie, call_gid);
1901 if (retval == SECURITY_SERVER_API_ERROR_ACCESS_DENIED) {
1902 ALARM_MGR_EXCEPTION_PRINT(
1903 "%s", "access has been denied\n");
1905 ALARM_MGR_EXCEPTION_PRINT("%s", "Error has occurred\n");
1911 /* return valule and return_code should be checked */
1912 __alarm_create(&alarm_info, alarm_id, pid, app_service_name,app_service_name_mod,
1913 reserved_service_name, reserved_service_name_mod, return_code);
1921 gboolean alarm_manager_alarm_delete(void *pObject, int pid, alarm_id_t alarm_id,
1922 char *e_cookie, int *return_code)
1929 cookie = g_base64_decode(e_cookie, &size);
1930 call_gid = security_server_get_gid("alarm");
1932 ALARM_MGR_LOG_PRINT("call_gid : %d\n", call_gid);
1934 retval = security_server_check_privilege((const char *)cookie, call_gid);
1936 if (retval == SECURITY_SERVER_API_ERROR_ACCESS_DENIED) {
1937 ALARM_MGR_EXCEPTION_PRINT("%s",
1938 "access has been denied\n");
1940 ALARM_MGR_EXCEPTION_PRINT("%s", "Error has occurred\n");
1946 __alarm_delete(pid, alarm_id, return_code);
1954 gboolean alarm_manager_alarm_power_on(void *pObject, int pid, bool on_off,
1958 return __alarm_power_on(pid, on_off, return_code);
1961 gboolean alarm_manager_alarm_power_off(void *pObject, int pid, int *return_code)
1964 return __alarm_power_off(pid, return_code);
1967 bool alarm_manager_alarm_check_next_duetime(void *pObject, int pid,
1970 return __alarm_check_next_duetime(pid, return_code);
1973 gboolean alarm_manager_alarm_update(void *pObject, int pid,
1974 char *app_service_name, alarm_id_t alarm_id,
1975 int start_year, int start_month,
1976 int start_day, int start_hour,
1977 int start_min, int start_sec, int end_year,
1978 int end_month, int end_day,
1979 int mode_day_of_week, int mode_repeat,
1980 int alarm_type, int reserved_info,
1983 alarm_info_t alarm_info;
1984 alarm_info.start.year = start_year;
1985 alarm_info.start.month = start_month;
1986 alarm_info.start.day = start_day;
1987 alarm_info.start.hour = start_hour;
1988 alarm_info.start.min = start_min;
1989 alarm_info.start.sec = start_sec;
1991 alarm_info.end.year = end_year;
1992 alarm_info.end.month = end_month;
1993 alarm_info.end.day = end_day;
1995 alarm_info.mode.u_interval.day_of_week = mode_day_of_week;
1996 alarm_info.mode.repeat = mode_repeat;
1998 alarm_info.alarm_type = alarm_type;
1999 alarm_info.reserved_info = reserved_info;
2003 __alarm_update(pid, app_service_name, alarm_id, &alarm_info,
2009 gboolean alarm_manager_alarm_get_number_of_ids(void *pObject, int pid,
2013 GSList *gs_iter = NULL;
2014 GQuark quark_app_unique_name; /* the fullpath of pid(pid) is
2015 converted to quark value. */
2016 char proc_file[256] = { 0 };
2017 char process_name[512] = { 0 };
2018 char app_name[256] = { 0 };
2020 __alarm_info_t *entry = NULL;
2021 char *proc_name_ptr = NULL;
2026 /* we should consider to check whether pid is running or Not
2028 memset(process_name, '\0', 512);
2029 memset(proc_file, '\0', 256);
2030 snprintf(proc_file, 256, "/proc/%d/cmdline", pid);
2035 fd = open(proc_file, O_RDONLY);
2037 ret = read(fd, process_name, 512);
2039 while (process_name[i] != '\0') {
2040 if (process_name[i] == ' ') {
2041 process_name[i] = '\0';
2046 /*if (readlink(proc_file, process_name, 256)!=-1) */
2049 word = strtok_r(process_name, "/", &proc_name_ptr);
2050 while (word != NULL) {
2051 memset(app_name, 0, 256);
2052 snprintf(app_name, 256, "%s", word);
2053 word = strtok_r(NULL, "/", &proc_name_ptr);
2055 quark_app_unique_name = g_quark_from_string(app_name);
2056 } else { /* failure */
2058 quark_app_unique_name = g_quark_from_string("unknown");
2059 memcpy(app_name, "unknown", strlen("unknown") + 1);
2061 ALARM_MGR_EXCEPTION_PRINT("Caution!! app_pid(%d) seems to be "
2062 "killed, so we failed to get proc file(%s) \n",
2064 *return_code = -1; /* -1 means that system
2065 failed internally. */
2069 ALARM_MGR_LOG_PRINT("called for app(pid:%d, name=%s)\n",
2072 for (gs_iter = alarm_context.alarms; gs_iter != NULL;
2073 gs_iter = g_slist_next(gs_iter)) {
2074 entry = gs_iter->data;
2075 ALARM_MGR_LOG_PRINT("alarm_manager_alarm_get_number_of_ids(): "
2076 "app_name=%s,quark_app_unique_name=%s\n",
2077 app_name, g_quark_to_string(entry->quark_app_unique_name));
2080 g_quark_to_string(entry->quark_app_unique_name)) == 0
2081 && strcmp(app_name, "unknown") != 0) {
2083 ALARM_MGR_LOG_PRINT("inc number of alarms of app "
2084 "(pid:%d, name:%s) is %d\n",
2085 pid, app_name, *num_of_ids);
2089 ALARM_MGR_LOG_PRINT("number of alarms of app(pid:%d, name:%s) is %d\n",
2090 pid, app_name, *num_of_ids);
2094 gboolean alarm_manager_alarm_get_list_of_ids(void *pObject, int pid,
2095 int max_number_of_ids,
2096 GArray **arr, int *num_of_ids,
2099 GSList *gs_iter = NULL;
2100 GQuark quark_app_unique_name; /* the fullpath of pid(pid) is converted
2102 char proc_file[256] = { 0 };
2103 char process_name[512] = { 0 };
2104 char app_name[256] = { 0 };
2106 __alarm_info_t *entry = NULL;
2108 char *proc_name_ptr = NULL;
2112 GArray *garray = NULL;
2116 garray = g_array_new(false, true, sizeof(alarm_id_t));
2118 /* we should check that there is a resource leak.
2119 * Now we don't have free code for g_array_new().
2121 if (max_number_of_ids <= 0) {
2123 ALARM_MGR_EXCEPTION_PRINT("called for pid(%d), but "
2124 "max_number_of_ids(%d) is less than 0.\n",
2125 pid, max_number_of_ids);
2129 /* we should consider to check whether pid is running or Not
2131 memset(process_name, '\0', 512);
2132 memset(proc_file, '\0', 256);
2133 snprintf(proc_file, 256, "/proc/%d/cmdline", pid);
2135 fd = open(proc_file, O_RDONLY);
2137 ret = read(fd, process_name, 512);
2139 while (process_name[i] != '\0') {
2140 if (process_name[i] == ' ') {
2141 process_name[i] = '\0';
2146 /* if (readlink(proc_file, process_name, 256)!=-1) */
2149 word = strtok_r(process_name, "/", &proc_name_ptr);
2150 while (word != NULL) {
2151 memset(app_name, 0, 256);
2152 snprintf(app_name, 256, "%s", word);
2153 word = strtok_r(NULL, "/", &proc_name_ptr);
2155 quark_app_unique_name = g_quark_from_string(app_name);
2156 } else { /* failure */
2158 quark_app_unique_name = g_quark_from_string("unknown");
2159 memcpy(app_name, "unknown", strlen("unknown") + 1);
2161 ALARM_MGR_EXCEPTION_PRINT("Caution!! app_pid(%d) seems to be "
2162 "killed, so we failed to get proc file(%s)\n", pid, proc_file);
2164 /* -1 means that system failed internally. */
2168 ALARM_MGR_LOG_PRINT("called for app(pid:%d, name=%s)\n",
2171 for (gs_iter = alarm_context.alarms; gs_iter != NULL;
2172 gs_iter = g_slist_next(gs_iter)) {
2173 entry = gs_iter->data;
2176 g_quark_to_string(entry->quark_app_unique_name)) == 0
2177 && strcmp(app_name, "unknown") != 0) {
2178 g_array_append_val(garray, entry->alarm_id);
2182 *num_of_ids = index;
2189 gboolean alarm_manager_alarm_get_appsvc_info(void *pObject, int pid, alarm_id_t alarm_id,
2190 char *e_cookie, gchar **b_data, int *return_code)
2194 GSList *gs_iter = NULL;
2195 __alarm_info_t *entry = NULL;
2197 guchar *cookie = NULL;
2202 ALARM_MGR_LOG_PRINT("called for pid(%d) and alarm_id(%d)\n", pid,
2205 cookie = g_base64_decode(e_cookie, &size);
2209 *return_code = ERR_ALARM_SYSTEM_FAIL;
2210 ALARM_MGR_EXCEPTION_PRINT("Unable to decode cookie!!!\n");
2213 call_gid = security_server_get_gid("alarm");
2215 ALARM_MGR_LOG_PRINT("call_gid : %d\n", call_gid);
2217 retval = security_server_check_privilege((const char *)cookie, call_gid);
2219 if (retval == SECURITY_SERVER_API_ERROR_ACCESS_DENIED) {
2220 ALARM_MGR_EXCEPTION_PRINT(
2221 "%s", "access has been denied\n");
2223 ALARM_MGR_EXCEPTION_PRINT("%s", "Error has occurred\n");
2226 *return_code = ERR_ALARM_NO_PERMISSION;
2237 for (gs_iter = alarm_context.alarms; gs_iter != NULL;
2238 gs_iter = g_slist_next(gs_iter)) {
2239 entry = gs_iter->data;
2240 if (entry->alarm_id == alarm_id) {
2242 *b_data = g_strdup(g_quark_to_string(entry->quark_bundle));
2248 if ( *b_data && strlen(*b_data) == 4 && strncmp(*b_data,"null",4) == 0){
2249 ALARM_MGR_EXCEPTION_PRINT("Regular alarm,not svc alarm");
2251 *return_code = ERR_ALARM_INVALID_TYPE;
2255 *return_code = ERR_ALARM_INVALID_ID;
2264 gboolean alarm_manager_alarm_get_info(void *pObject, int pid,
2265 alarm_id_t alarm_id, int *start_year,
2266 int *start_month, int *start_day,
2267 int *start_hour, int *start_min,
2268 int *start_sec, int *end_year,
2269 int *end_month, int *end_day,
2270 int *mode_day_of_week, int *mode_repeat,
2271 int *alarm_type, int *reserved_info,
2274 ALARM_MGR_LOG_PRINT("called for pid(%d) and alarm_id(%d)\n", pid,
2277 GSList *gs_iter = NULL;
2278 __alarm_info_t *entry = NULL;
2280 alarm_info_t *alarm_info = NULL;
2283 for (gs_iter = alarm_context.alarms; gs_iter != NULL;
2284 gs_iter = g_slist_next(gs_iter)) {
2285 entry = gs_iter->data;
2286 if (entry->alarm_id == alarm_id) {
2287 alarm_info = &(entry->alarm_info);
2292 if (alarm_info == NULL)
2294 ALARM_MGR_EXCEPTION_PRINT("alarm id(%d) was not found\n",
2296 *return_code = ERR_ALARM_INVALID_ID;
2298 ALARM_MGR_LOG_PRINT("alarm was found\n");
2299 *start_year = alarm_info->start.year;
2300 *start_month = alarm_info->start.month;
2301 *start_day = alarm_info->start.day;
2302 *start_hour = alarm_info->start.hour;
2303 *start_min = alarm_info->start.min;
2304 *start_sec = alarm_info->start.sec;
2306 *end_year = alarm_info->end.year;
2307 *end_year = alarm_info->end.month;
2308 *end_year = alarm_info->end.day;
2310 *mode_day_of_week = alarm_info->mode.u_interval.day_of_week;
2311 *mode_repeat = alarm_info->mode.repeat;
2313 *alarm_type = alarm_info->alarm_type;
2314 *reserved_info = alarm_info->reserved_info;
2321 #include "alarm-skeleton.h"
2323 typedef struct AlarmManagerObject AlarmManagerObject;
2324 typedef struct AlarmManagerObjectClass AlarmManagerObjectClass;
2325 GType Server_Object_get_type(void);
2326 struct AlarmManagerObject {
2329 struct AlarmManagerObjectClass {
2330 GObjectClass parent;
2333 #define DBUS_NAME_FLAG_PROHIBIT_REPLACEMENT 0
2335 #define ALARM_MANAGER_TYPE_OBJECT (Server_Object_get_type())
2336 #define ALARM_MANAGER_OBJECT(object) (G_TYPE_CHECK_INSTANCE_CAST \
2337 ((object), ALARM_MANAGER_TYPE_OBJECT, AlarmManagerObject))
2338 #define ALARM_MANAGER_OBJECT_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST \
2339 ((klass), ALARM_MANAGER_TYPE_OBJECT, AlarmManagerObjectClass))
2340 #define ALARM_MANAGER_IS_OBJECT(object) (G_TYPE_CHECK_INSTANCE_TYPE \
2341 ((object), ALARM_MANAGER_TYPE_OBJECT))
2342 #define ALARM_MANAGER_IS_OBJECT_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE \
2343 ((klass), ALARM_MANAGER_TYPE_OBJECT))
2344 #define ALARM_MANAGER_OBJECT_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS \
2345 ((obj), ALARM_MANAGER_TYPE_OBJECT, AlarmManagerObjectClass))
2346 G_DEFINE_TYPE(AlarmManagerObject, Server_Object, G_TYPE_OBJECT)
2347 static void Server_Object_init(AlarmManagerObject * obj)
2352 static void Server_Object_class_init(AlarmManagerObjectClass *klass)
2357 static void __initialize_timer()
2359 struct sigaction sig_timer;
2360 sigemptyset(&sig_timer.sa_mask);
2361 sig_timer.sa_flags = SA_SIGINFO;
2362 sig_timer.sa_sigaction = (void *)__alarm_handler;
2363 sigaction(SIG_TIMER, &sig_timer, NULL);
2365 alarm_context.timer = _alarm_create_timer();
2369 static void __initialize_alarm_list()
2372 alarm_context.alarms = NULL;
2373 alarm_context.c_due_time = -1;
2375 _load_alarms_from_registry();
2377 __rtc_set(); /*Set RTC1 Alarm with alarm due time for alarm-manager initialization*/
2382 if (enable_power_on_alarm) {
2383 /* orginally first arg's value was 21(app_id, WAKEUP_ALARM_APP_ID) in a
2384 * platform with app-server. because __alarm_power_on(..) fuction don't
2385 * use first parameter internally, we set this value to 0(zero)
2387 __alarm_power_on(0, enable_power_on_alarm, NULL);
2392 static void __initialize_scheduled_alarm_lsit()
2394 _init_scheduled_alarm_list();
2398 static void __hibernation_leave_callback()
2401 __initialize_scheduled_alarm_lsit();
2403 __alarm_clean_list();
2405 __initialize_alarm_list();
2408 static bool __initialize_noti()
2411 int fd = heynoti_init();
2413 ALARM_MGR_EXCEPTION_PRINT("fail to heynoti_init\n");
2416 heynoti_subscribe(fd, "HIBERNATION_LEAVE", __hibernation_leave_callback,
2418 heynoti_attach_handler(fd);
2420 if (vconf_notify_key_changed
2421 (VCONFKEY_SYSTEM_TIMECHANGE, __on_system_time_changed, NULL) < 0) {
2422 ALARM_MGR_LOG_PRINT(
2423 "Failed to add callback for time changing event\n");
2425 /*system state change noti ó¸® */
2431 static DBusHandlerResult __alarm_server_filter(DBusConnection *connection,
2432 DBusMessage *message,
2436 if (dbus_message_is_signal
2437 (message, DBUS_INTERFACE_DBUS, "NameOwnerChanged")) {
2442 __expired_alarm_t *expire_info;
2444 dbus_message_get_args(message,
2446 DBUS_TYPE_STRING, &service,
2447 DBUS_TYPE_STRING, &old_owner,
2448 DBUS_TYPE_STRING, &new_owner,
2451 for (entry = g_expired_alarm_list; entry; entry = entry->next) {
2453 expire_info = (__expired_alarm_t *) entry->data;
2455 if (strcmp(expire_info->service_name, service)
2457 ALARM_MGR_EXCEPTION_PRINT(
2458 "__alarm_server_filter : "
2459 "service name(%s) alarm_id (%d)\n",
2460 expire_info->service_name,\
2461 expire_info->alarm_id);
2463 __alarm_send_noti_to_application(
2464 expire_info->service_name,
2465 expire_info->alarm_id);
2466 g_expired_alarm_list =
2467 g_slist_remove(g_expired_alarm_list,
2474 return DBUS_HANDLER_RESULT_NOT_YET_HANDLED;
2477 return DBUS_HANDLER_RESULT_NOT_YET_HANDLED;
2480 static bool __initialize_dbus()
2482 GError *error = NULL;
2483 GObject *obj = NULL;
2484 DBusGConnection *connection = NULL;
2486 int request_name_result = 0;
2488 dbus_g_object_type_install_info(ALARM_MANAGER_TYPE_OBJECT,
2489 &dbus_glib_alarm_manager_object_info);
2491 connection = dbus_g_bus_get(DBUS_BUS_SYSTEM, &error);
2494 ALARM_MGR_EXCEPTION_PRINT("dbus_g_bus_get failed\n");
2498 dbus_error_init(&derror);
2500 request_name_result =
2501 dbus_bus_request_name(dbus_g_connection_get_connection(connection),
2502 "org.tizen.alarm.manager",
2503 DBUS_NAME_FLAG_PROHIBIT_REPLACEMENT, &derror);
2504 if (dbus_error_is_set(&derror)) { /* failure */
2505 ALARM_MGR_EXCEPTION_PRINT("Failed to dbus_bus_request_name "
2506 "(org.tizen.alarm.manager): %s\n", derror.message);
2507 dbus_error_free(&derror);
2511 if (!(obj = g_object_new(ALARM_MANAGER_TYPE_OBJECT, NULL))) {
2512 ALARM_MGR_EXCEPTION_PRINT("Could not allocate new object\n");
2516 dbus_g_connection_register_g_object(connection,
2517 "/org/tizen/alarm/manager",
2520 /*dbus_bus_add_match (dbus_g_connection_get_connection(connection),
2521 "type='signal',member='NameOwnerChanged'",NULL); */
2523 dbus_bus_add_match(dbus_g_connection_get_connection(connection),
2524 "type='signal',sender='" DBUS_SERVICE_DBUS
2525 "',path='" DBUS_PATH_DBUS
2526 "',interface='" DBUS_INTERFACE_DBUS
2527 "',member='NameOwnerChanged'", NULL);
2529 if (!dbus_connection_add_filter
2530 (dbus_g_connection_get_connection(connection),
2531 __alarm_server_filter, NULL, NULL)) {
2532 ALARM_MGR_EXCEPTION_PRINT("add __expire_alarm_filter failed\n");
2537 alarm_context.bus = connection;
2541 #define ALARMMGR_DB_FILE "/opt/dbspace/.alarmmgr.db"
2542 sqlite3 *alarmmgr_db;
2543 #define QUERY_CREATE_TABLE_ALARMMGR "create table alarmmgr \
2544 (alarm_id integer primary key,\
2548 app_unique_name text,\
2549 app_service_name text,\
2550 app_service_name_mod text,\
2558 day_of_week integer,\
2560 alarm_type integer,\
2561 reserved_info integer,\
2562 dst_service_name text, \
2563 dst_service_name_mod text \
2566 static bool __initialize_db()
2568 char *error_message = NULL;
2571 if (access("/opt/dbspace/.alarmmgr.db", F_OK) == 0) {
2573 db_util_open(ALARMMGR_DB_FILE, &alarmmgr_db,
2574 DB_UTIL_REGISTER_HOOK_METHOD);
2576 if (ret != SQLITE_OK) {
2577 ALARM_MGR_EXCEPTION_PRINT(
2578 "====>>>> connect menu_db [%s] failed!\n",
2587 db_util_open(ALARMMGR_DB_FILE, &alarmmgr_db,
2588 DB_UTIL_REGISTER_HOOK_METHOD);
2590 if (ret != SQLITE_OK) {
2591 ALARM_MGR_EXCEPTION_PRINT(
2592 "====>>>> connect menu_db [%s] failed!\n",
2598 sqlite3_exec(alarmmgr_db, QUERY_CREATE_TABLE_ALARMMGR, NULL, NULL,\
2600 ALARM_MGR_EXCEPTION_PRINT("Don't execute query = %s, "
2601 "error message = %s\n", QUERY_CREATE_TABLE_ALARMMGR,
2609 static void __initialize()
2618 fp = fopen("/proc/alarm_boot", "r");
2623 size = fread(&temp, 1, 1, fp);
2628 alarm_boot = atoi(temp);
2636 struct rtc_time rtc_tm;
2639 fd = open(power_rtc, O_RDONLY);
2641 ALARM_MGR_EXCEPTION_PRINT("cannot open /dev/rtc0\n");
2644 retval = ioctl(fd, RTC_RD_TIME, &rtc_tm);
2647 fd2 = open(default_rtc, O_RDWR);
2649 ALARM_MGR_EXCEPTION_PRINT("cannot open /dev/rtc1\n");
2652 retval = ioctl(fd2, RTC_SET_TIME, &rtc_tm);
2655 __initialize_timer();
2656 if (__initialize_dbus() == false) { /* because dbus's initialize
2657 failed, we cannot continue any more. */
2658 ALARM_MGR_EXCEPTION_PRINT("because __initialize_dbus failed, "
2659 "alarm-server cannot be runned.\n");
2662 __initialize_scheduled_alarm_lsit();
2664 __initialize_alarm_list();
2665 __initialize_noti();
2670 static bool __check_false_alarm()
2672 time_t current_time;
2675 time(¤t_time);
2677 interval = ab_due_time - current_time;
2679 ALARM_MGR_LOG_PRINT("due_time : %d / current_time %d\n", \
2680 alarm_context.c_due_time, current_time);
2682 if (interval > 0 && interval <= 30) {
2684 } else if (!poweron_alarm_expired) {
2685 /* originally, first arguement's value was 121(app_id) which means
2686 * alarm_booting ui application.and this application's dbus-service
2687 * name had a org.tizen.alarmboot.ui in a platform with app-server.
2688 * so we set "org.tizen.alarmboot.ui.ALARM" instead of 121.
2690 __alarm_send_noti_to_application(
2691 WAKEUP_ALARMBOOTING_APP_ID, -1);
2701 GMainLoop *mainloop = NULL;
2703 ALARM_MGR_LOG_PRINT("Enter main loop\n");
2705 mainloop = g_main_loop_new(NULL, FALSE);
2711 __check_false_alarm();
2715 g_main_loop_run(mainloop);