alarm_info_t *alarm_info, int update_flag, int *error_code);
static bool __alarm_remove_from_list(uid_t uid, alarm_id_t alarm_id,
int *error_code);
-static bool __alarm_set_start_and_end_time(alarm_info_t *alarm_info,
+static void __alarm_set_start_and_end_time(alarm_info_t *alarm_info,
__alarm_info_t *__alarm_info);
-static bool __alarm_update_due_time_of_all_items_in_list(double diff_time);
+static void __alarm_update_due_time_of_all_items_in_list(double diff_time);
static bool __alarm_create(alarm_info_t *alarm_info, alarm_id_t *alarm_id, uid_t uid,
int pid, periodic_method_e method, long requested_interval, int is_ref,
char *app_service_name, char *app_service_name_mod,
static void __initialize_timer();
static void __initialize_alarm_list();
static void __initialize_scheduled_alarm_list();
-static bool __initialize_noti();
+static void __initialize_noti();
void _release_alarm_info_t(__alarm_info_t *entry);
static notification_h __get_notification(guchar *data, int datalen);
#ifdef _APPFW_FEATURE_ALARM_MANAGER_MODULE_LOG
static void __initialize_module_log(void);
-static bool __save_module_log(const char *tag, const char *messgae);
+static void __save_module_log(const char *tag, const char *messgae);
#endif
-int __set_time(time_t _time);
-
static bool __get_caller_unique_name(int pid, char *unique_name, int size, bool *is_app, uid_t uid)
{
char caller_appid[MAX_APP_ID_LEN] = {0,};
return;
}
-int __set_time(time_t _time)
+static bool __set_time(time_t _time)
{
int ret = 0;
struct timeval tv;
tv.tv_usec = 0;
gmtime_res = gmtime_r(&(tv.tv_sec), &tm);
- if (!gmtime_res)
+ if (!gmtime_res) {
ALARM_MGR_EXCEPTION_PRINT("gmtime_r is failed. [%d]", errno);
+ return false;
+ }
ret = settimeofday(&tv, NULL);
- if (ret < 0)
+ if (ret < 0) {
ALARM_MGR_EXCEPTION_PRINT("settimeofday is failed.[%d]", errno);
+ return false;
+ }
if (_APPFW_FEATURE_WAKEUP_USING_RTC) {
const char *rtc0 = default_rtc;
struct rtc_time _rtc_time;
+ char buf[1024];
#ifdef _APPFW_FEATURE_ALARM_MANAGER_MODULE_LOG
char log_tag[ALARMMGR_LOG_TAG_SIZE] = {0,};
char log_message[ALARMMGR_LOG_MESSAGE_SIZE] = {0,};
+ char *timebuf = ctime(&_time);
+ if (timebuf) {
+ timebuf[strlen(timebuf) - 1] = '\0'; /* to avoid new line */
+ snprintf(log_message, sizeof(log_message), "RTC & OS =%d, %s", (int)_time, timebuf);
+ }
+
#endif
- char buf[1024];
if (gfd < 0) {
gfd = open(rtc0, O_RDWR);
if (gfd < 0) {
ALARM_MGR_EXCEPTION_PRINT("Opening the /dev/rtc is failed.");
- perror("\t");
- return 1;
+ return false;
}
}
ALARM_MGR_EXCEPTION_PRINT("ALARM_SET_RTC ioctl is failed. errno = %s", strerror_r(errno, buf, sizeof(buf)));
#ifdef _APPFW_FEATURE_ALARM_MANAGER_MODULE_LOG
strncpy(log_tag, "FAIL: SET RTC", sizeof(log_tag) - 1);
+ __save_module_log(log_tag, log_message);
#endif
- perror("\t");
- }
+ } else {
+ ALARM_MGR_LOG_PRINT("ALARM_SET_RTC ioctl is succeed. [%d]", (int)_time);
#ifdef _APPFW_FEATURE_ALARM_MANAGER_MODULE_LOG
- else
strncpy(log_tag, "SET RTC", sizeof(log_tag) - 1);
-
- char *timebuf = ctime(&_time);
- if (timebuf) {
- timebuf[strlen(timebuf) - 1] = '\0'; /* to avoid new line */
- snprintf(log_message, sizeof(log_message), "RTC & OS =%d, %s", (int)_time, timebuf);
- }
-
- __save_module_log(log_tag, log_message);
+ __save_module_log(log_tag, log_message);
#endif
+ return false;
+ }
} else {
ALARM_MGR_LOG_PRINT("[alarm-server] RTC does not work.");
}
- return 1;
+ return true;
}
bool __alarm_clean_list()
ALARM_MGR_LOG_PRINT("[alarm-server]:Remove alarm id(%d)", entry->alarm_id);
- if (!(alarm_info->alarm_type & ALARM_TYPE_VOLATILE))
- _delete_alarms(alarm_id);
+ if (!(alarm_info->alarm_type & ALARM_TYPE_VOLATILE)) {
+ if (!_delete_alarms(alarm_id))
+ break;
+ }
alarm_context.alarms = g_slist_remove(alarm_context.alarms, iter->data);
_release_alarm_info_t(entry);
found = true;
break;
}
-
}
ALARM_MGR_LOG_PRINT("[alarm-server]: after del\n");
return true;
}
-static bool __alarm_set_start_and_end_time(alarm_info_t *alarm_info,
+static void __alarm_set_start_and_end_time(alarm_info_t *alarm_info,
__alarm_info_t *__alarm_info)
{
alarm_date_t *start = &alarm_info->start;
} else {
__alarm_info->end = 0;
}
-
- return true;
}
-static bool __alarm_update_due_time_of_all_items_in_list(double diff_time)
+static void __alarm_update_due_time_of_all_items_in_list(double diff_time)
{
time_t current_time;
time_t min_time = -1;
}
}
}
- _alarm_next_duetime(entry);
+ _alarm_set_next_duetime(entry);
}
time(¤t_time);
alarm_context.c_due_time = min_time;
g_idle_add(_update_relative_alarms, NULL);
- return true;
}
static void __set_caller_info(bundle *b, uid_t uid,
long requested_interval, uid_t uid, int pid, char *bundle_data, int *error_code)
{
time_t current_time;
- time_t due_time;
struct tm ts_ret;
char due_time_r[100] = { 0 };
char app_name[MAX_APP_ID_LEN] = { 0 };
alarm_context.c_due_time = -1;
}
- due_time = _alarm_next_duetime(__alarm_info);
+ _alarm_set_next_duetime(__alarm_info);
__alarm_add_to_list(__alarm_info);
- if (due_time == 0) {
+ if (__alarm_info->due_time == 0) {
ALARM_MGR_EXCEPTION_PRINT("[alarm-server]:Create a new alarm: "
- "due_time is 0, alarm(%d) \n", *alarm_id);
+ "__alarm_info->due_time is 0, alarm(%d) \n", *alarm_id);
return true;
- } else if (current_time == due_time) {
+ } else if (current_time == __alarm_info->due_time) {
ALARM_MGR_EXCEPTION_PRINT("[alarm-server]:Create alarm: "
- "current_time(%ld) is same as due_time(%ld)", current_time,
- due_time);
+ "current_time(%ld) is same as __alarm_info->due_time(%ld)", current_time,
+ __alarm_info->due_time);
return true;
- } else if (difftime(due_time, current_time) < 0) {
- ALARM_MGR_EXCEPTION_PRINT("[alarm-server]: Expired Due Time.[Due time=%ld, Current Time=%ld]!!!Do not add to schedule list\n", due_time, current_time);
+ } else if (difftime(__alarm_info->due_time, current_time) < 0) {
+ ALARM_MGR_EXCEPTION_PRINT("[alarm-server]: Expired Due Time.\
+ [Due time=%ld, Current Time=%ld]!!!Do not add to schedule list\n",
+ __alarm_info->due_time, current_time);
return true;
} else {
- localtime_r(&due_time, &ts_ret);
+ localtime_r(&(__alarm_info->due_time), &ts_ret);
strftime(due_time_r, 30, "%c", &ts_ret);
SECURE_LOGD("[alarm-server]:Create a new alarm: "
- "alarm(%d) due_time(%s)", *alarm_id,
+ "alarm(%d) __alarm_info->due_time(%s)", *alarm_id,
due_time_r);
}
- ALARM_MGR_LOG_PRINT("[alarm-server]:alarm_context.c_due_time(%ld), due_time(%ld)", alarm_context.c_due_time, due_time);
+ ALARM_MGR_LOG_PRINT("[alarm-server]:alarm_context.c_due_time(%ld),\
+ __alarm_info->due_time(%ld)",
+ alarm_context.c_due_time, __alarm_info->due_time);
- if (alarm_context.c_due_time == -1 || due_time < alarm_context.c_due_time) {
+ 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, due_time);
- alarm_context.c_due_time = due_time;
+ _alarm_set_timer(&alarm_context, alarm_context.timer, __alarm_info->due_time);
__rtc_set();
- } else if (due_time == alarm_context.c_due_time) {
+ } else if (__alarm_info->due_time == alarm_context.c_due_time) {
_add_to_scheduled_alarm_list(__alarm_info);
}
int *error_code)
{
time_t current_time;
- time_t due_time;
char unique_name[MAX_APP_ID_LEN] = { 0 };
bool caller_is_app = false;
+ char due_time_r[100] = { 0 };
+ struct tm ts_ret;
__alarm_info_t *__alarm_info = NULL;
alarm_context.c_due_time = -1;
}
- due_time = _alarm_next_duetime(__alarm_info);
+ _alarm_set_next_duetime(__alarm_info);
__alarm_add_to_list(__alarm_info);
- if (due_time == 0) {
+ if (__alarm_info->due_time == 0) {
ALARM_MGR_EXCEPTION_PRINT("[alarm-server]:Create a new alarm: due_time is 0, alarm(%d).", *alarm_id);
return true;
- } else if (current_time == due_time) {
- ALARM_MGR_EXCEPTION_PRINT("[alarm-server]:Create alarm: current_time(%ld) is same as due_time(%ld).",
- current_time, due_time);
+ } else if (current_time == __alarm_info->due_time) {
+ ALARM_MGR_EXCEPTION_PRINT("[alarm-server]:Create alarm: current_time(%ld)\
+ is same as due_time(%ld).", current_time, __alarm_info->due_time);
return true;
- } else if (difftime(due_time, current_time) < 0) {
- ALARM_MGR_EXCEPTION_PRINT("[alarm-server]: Expired Due Time.[Due time=%ld, Current Time=%ld]!!!Do not add to schedule list.",
- due_time, current_time);
+ } else if (difftime(__alarm_info->due_time, current_time) < 0) {
+ ALARM_MGR_EXCEPTION_PRINT("[alarm-server]: Expired Due Time.[Due time=%ld,\
+ Current Time=%ld]!!!Do not add to schedule list.",
+ __alarm_info->due_time, current_time);
return true;
} else {
- char due_time_r[100] = { 0 };
- struct tm ts_ret;
- localtime_r(&due_time, &ts_ret);
+ localtime_r(&(__alarm_info->due_time), &ts_ret);
strftime(due_time_r, 30, "%c", &ts_ret);
- SECURE_LOGD("[alarm-server]:Create a new alarm: alarm(%d) due_time(%s)", *alarm_id, due_time_r);
+ SECURE_LOGD("[alarm-server]:Create a new alarm: alarm(%d) due_time(%s)",
+ *alarm_id, due_time_r);
}
- ALARM_MGR_LOG_PRINT("[alarm-server]:alarm_context.c_due_time(%ld), due_time(%ld)", alarm_context.c_due_time, due_time);
+ ALARM_MGR_LOG_PRINT("[alarm-server]:alarm_context.c_due_time(%ld), due_time(%ld)",
+ alarm_context.c_due_time, __alarm_info->due_time);
- if (alarm_context.c_due_time == -1 || due_time < alarm_context.c_due_time) {
+ 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, due_time);
- alarm_context.c_due_time = due_time;
+ _alarm_set_timer(&alarm_context, alarm_context.timer, __alarm_info->due_time);
__rtc_set();
- } else if (due_time == alarm_context.c_due_time) {
+ } else if (__alarm_info->due_time == alarm_context.c_due_time) {
_add_to_scheduled_alarm_list(__alarm_info);
}
long requested_interval, uid_t uid, int pid, char *noti_data, int *error_code)
{
time_t current_time;
- time_t due_time;
struct tm ts_ret;
char due_time_r[100] = { 0 };
char app_name[MAX_APP_ID_LEN] = { 0 };
alarm_context.c_due_time = -1;
}
- due_time = _alarm_next_duetime(__alarm_info);
+ _alarm_set_next_duetime(__alarm_info);
__alarm_add_to_list(__alarm_info);
- if (due_time == 0) {
+ if (__alarm_info->due_time == 0) {
ALARM_MGR_EXCEPTION_PRINT("[alarm-server]:Create a new alarm: due_time is 0, alarm(%d).", *alarm_id);
return true;
- } else if (current_time == due_time) {
- ALARM_MGR_EXCEPTION_PRINT("[alarm-server]:Create alarm: current_time(%ld) is same as due_time(%ld).",
- current_time, due_time);
+ } else if (current_time == __alarm_info->due_time) {
+ ALARM_MGR_EXCEPTION_PRINT("[alarm-server]:Create alarm: current_time(%ld)\
+ is same as due_time(%ld).", current_time, __alarm_info->due_time);
return true;
- } else if (difftime(due_time, current_time) < 0) {
- ALARM_MGR_EXCEPTION_PRINT("[alarm-server]: Expired Due Time.[Due time=%ld, Current Time=%ld]!!!Do not add to schedule list.",
- due_time, current_time);
+ } else if (difftime(__alarm_info->due_time, current_time) < 0) {
+ ALARM_MGR_EXCEPTION_PRINT("[alarm-server]: Expired Due Time.[Due time=%ld,\
+ Current Time=%ld]!!!Do not add to schedule list.",
+ __alarm_info->due_time, current_time);
return true;
} else {
- localtime_r(&due_time, &ts_ret);
+ localtime_r(&(__alarm_info->due_time), &ts_ret);
strftime(due_time_r, 30, "%c", &ts_ret);
SECURE_LOGD("[alarm-server]:Create a new alarm: alarm(%d) due_time(%s)", *alarm_id, due_time_r);
}
- ALARM_MGR_LOG_PRINT("[alarm-server]:alarm_context.c_due_time(%ld), due_time(%ld)", alarm_context.c_due_time, due_time);
+ ALARM_MGR_LOG_PRINT("[alarm-server]:alarm_context.c_due_time(%ld), due_time(%ld)",
+ alarm_context.c_due_time, __alarm_info->due_time);
- if (alarm_context.c_due_time == -1 || due_time < alarm_context.c_due_time) {
+ 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, due_time);
- alarm_context.c_due_time = due_time;
+ _alarm_set_timer(&alarm_context, alarm_context.timer, __alarm_info->due_time);
__rtc_set();
- } else if (due_time == alarm_context.c_due_time) {
+ } else if (__alarm_info->due_time == alarm_context.c_due_time) {
_add_to_scheduled_alarm_list(__alarm_info);
}
alarm_info_t *alarm_info, int update_flag, int *error_code)
{
time_t current_time;
- time_t due_time;
-
+ char due_time_r[100] = { 0 };
+ struct tm ts_ret;
__alarm_info_t *__alarm_info = NULL;
bool result = false;
return false;
}
- due_time = _alarm_next_duetime(__alarm_info);
+ _alarm_set_next_duetime(__alarm_info);
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);
__rtc_set();
- if (due_time == 0)
+ if (__alarm_info->due_time == 0)
ALARM_MGR_EXCEPTION_PRINT("[alarm-server]:Update alarm: due_time is 0.");
return true;
}
- if (due_time == 0) {
+ if (__alarm_info->due_time == 0) {
ALARM_MGR_EXCEPTION_PRINT("[alarm-server]:Update alarm: "
"due_time is 0, alarm(%d)\n", alarm_id);
return true;
- } else if (current_time == due_time) {
+ } else if (current_time == __alarm_info->due_time) {
ALARM_MGR_EXCEPTION_PRINT("[alarm-server]:Update alarm: "
"current_time(%ld) is same as due_time(%ld)", current_time,
- due_time);
+ __alarm_info->due_time);
return true;
- } else if (difftime(due_time, current_time) < 0) {
- ALARM_MGR_EXCEPTION_PRINT("[alarm-server]: Expired Due Time.[Due time=%ld, Current Time=%ld]!!!Do not add to schedule list\n", due_time, current_time);
+ } else if (difftime(__alarm_info->due_time, current_time) < 0) {
+ ALARM_MGR_EXCEPTION_PRINT("[alarm-server]: Expired Due Time.[Due time=%ld,\
+ Current Time=%ld]!!!Do not add to schedule list\n",
+ __alarm_info->due_time, current_time);
return true;
} else {
- char due_time_r[100] = { 0 };
- struct tm ts_ret;
- localtime_r(&due_time, &ts_ret);
+ localtime_r(&(__alarm_info->due_time), &ts_ret);
strftime(due_time_r, 30, "%c", &ts_ret);
SECURE_LOGD("[alarm-server]:Update alarm: alarm(%d) "
"due_time(%s)\n", alarm_id, due_time_r);
}
- ALARM_MGR_LOG_PRINT("[alarm-server]:alarm_context.c_due_time(%ld), due_time(%ld)", alarm_context.c_due_time, due_time);
+ ALARM_MGR_LOG_PRINT("[alarm-server]:alarm_context.c_due_time(%ld), due_time(%ld)",
+ alarm_context.c_due_time, __alarm_info->due_time);
- if (alarm_context.c_due_time == -1 || due_time < alarm_context.c_due_time) {
+ 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, due_time);
- alarm_context.c_due_time = due_time;
+ _alarm_set_timer(&alarm_context, 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, due_time);
- } else if (due_time == 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) {
_add_to_scheduled_alarm_list(__alarm_info);
ALARM_MGR_LOG_PRINT("[alarm-server2]:alarm_context.c_due_time "
- "(%ld), due_time(%ld)", alarm_context.c_due_time, due_time);
+ "(%ld), due_time(%ld)", alarm_context.c_due_time, __alarm_info->due_time);
}
__rtc_set();
if (__alarm_info->alarm_info.mode.repeat == ALARM_REPEAT_MODE_ONCE)
__alarm_remove_from_list(__alarm_info->uid, alarm_id, NULL);
else
- _alarm_next_duetime(__alarm_info);
+ _alarm_set_next_duetime(__alarm_info);
}
done:
ALARM_MGR_LOG_PRINT("1.alarm_context.c_due_time is %ld\n",
alarm_context.c_due_time);
- __set_time(cur_time);
+ if (!__set_time(cur_time)) { /* Change both OS time and RTC */
+ ALARM_MGR_EXCEPTION_PRINT("Failed to change both OS time and RTC");
+ _clear_scheduled_alarm_list();
+ _alarm_schedule();
+ __rtc_set();
+ return;
+ }
vconf_set_int(VCONFKEY_SYSTEM_TIME_CHANGED, (int)diff_time);
bundle *b = NULL;
GSList *gs_iter = NULL;
__alarm_info_t *entry = NULL;
- int duetime = 0;
bool is_restored = false;
if (key && strncmp(key, "end", 3) == 0 && val && strncmp(val, "ok", 2) == 0) {
gs_iter = g_slist_next(gs_iter);
if (strncmp(appid, entry->app_unique_name, strlen(appid)) == 0) {
- duetime = _alarm_next_duetime(entry);
- SECURE_LOGD("Restore alarm_id(%d) duetime(%d) appid(%s)", entry->alarm_id, duetime, appid);
+ _alarm_set_next_duetime(entry);
+ SECURE_LOGD("Restore alarm_id(%d) duetime(%d) appid(%s)",
+ entry->alarm_id, (int)(entry->due_time), appid);
alarm_context.alarms = g_slist_append(alarm_context.alarms, entry);
g_disabled_alarm_list = g_slist_remove(g_disabled_alarm_list, entry);
return;
}
-static bool __save_module_log(const char *tag, const char *message)
+static void __save_module_log(const char *tag, const char *message)
{
char buffer[ALARMMGR_LOG_BUFFER_STRING_SIZE] = {0,};
time_t now;
if (log_fd == -1) {
ALARM_MGR_EXCEPTION_PRINT("The file is not ready.");
- return false;
+ return;
}
if (log_index != 0)
int ret = write(log_fd, buffer, strlen(buffer));
if (ret < 0) {
ALARM_MGR_EXCEPTION_PRINT("Writing the alarmmgr log is failed. err: %s", strerror_r(errno, buf, sizeof(buf)));
- return false;
+ return;
}
if (++log_index >= ALARMMGR_LOG_BUFFER_SIZE)
log_index = 0;
-
- return true;
}
#endif /* _APPFW_FEATURE_ALARM_MANAGER_MODULE_LOG */
int alarm_manager_alarm_set_rtc_time(GVariant *parameters)
{
-/* Indentation ingored to help understand the patch. */
-if (_APPFW_FEATURE_WAKEUP_USING_RTC) {
- const char *rtc = default_rtc;
- struct rtc_wkalrm rtc_wkalarm;
- int retval = 0;
- struct tm tm, *alarm_tm = NULL;
+ if (_APPFW_FEATURE_WAKEUP_USING_RTC) {
+ const char *rtc = default_rtc;
+ struct rtc_wkalrm rtc_wkalarm;
+ int retval = 0;
+ struct tm tm, *alarm_tm = NULL;
#ifdef _APPFW_FEATURE_ALARM_MANAGER_MODULE_LOG
- char log_tag[ALARMMGR_LOG_TAG_SIZE] = {0,};
- char log_message[ALARMMGR_LOG_MESSAGE_SIZE] = {0,};
+ char log_tag[ALARMMGR_LOG_TAG_SIZE] = {0,};
+ char log_message[ALARMMGR_LOG_MESSAGE_SIZE] = {0,};
#endif
- /*extract day of the week, day in the year & daylight saving time from system*/
- time_t current_time;
- char buf[1024];
- int year, mon, day, hour, min, sec;
- int return_code = ALARMMGR_RESULT_SUCCESS;
+ /*extract day of the week, day in the year & daylight saving time from system*/
+ time_t current_time;
+ char buf[1024];
+ int year, mon, day, hour, min, sec;
+ int return_code = ALARMMGR_RESULT_SUCCESS;
- g_variant_get(parameters, "(iiiiii)", &year, &mon, &day, &hour, &min, &sec);
+ g_variant_get(parameters, "(iiiiii)", &year, &mon, &day, &hour, &min, &sec);
- current_time = time(NULL);
- alarm_tm = gmtime_r(¤t_time, &tm);
- if (alarm_tm == NULL) {
- ALARM_MGR_EXCEPTION_PRINT("alarm_tm is NULL");
- return ERR_ALARM_SYSTEM_FAIL;
- }
+ current_time = time(NULL);
+ alarm_tm = gmtime_r(¤t_time, &tm);
+ if (alarm_tm == NULL) {
+ ALARM_MGR_EXCEPTION_PRINT("alarm_tm is NULL");
+ return ERR_ALARM_SYSTEM_FAIL;
+ }
- alarm_tm->tm_year = year;
- alarm_tm->tm_mon = mon;
- alarm_tm->tm_mday = day;
- alarm_tm->tm_hour = hour;
- alarm_tm->tm_min = min;
- alarm_tm->tm_sec = sec;
+ alarm_tm->tm_year = year;
+ alarm_tm->tm_mon = mon;
+ alarm_tm->tm_mday = day;
+ alarm_tm->tm_hour = hour;
+ alarm_tm->tm_min = min;
+ alarm_tm->tm_sec = sec;
- /*convert to calendar time representation*/
- time_t rtc_time = mktime(alarm_tm);
+ /*convert to calendar time representation*/
+ time_t rtc_time = mktime(alarm_tm);
- if (gfd < 0) {
- gfd = open(rtc, O_RDWR);
if (gfd < 0) {
- ALARM_MGR_EXCEPTION_PRINT("RTC open failed.");
- return ERR_ALARM_SYSTEM_FAIL;
+ gfd = open(rtc, O_RDWR);
+ if (gfd < 0) {
+ ALARM_MGR_EXCEPTION_PRINT("RTC open failed.");
+ return ERR_ALARM_SYSTEM_FAIL;
+ }
}
- }
- rtc_wkalarm.enabled = 1;
- rtc_wkalarm.time.tm_year = year;
- rtc_wkalarm.time.tm_mon = mon;
- rtc_wkalarm.time.tm_mday = day;
- rtc_wkalarm.time.tm_hour = hour;
- rtc_wkalarm.time.tm_min = min;
- rtc_wkalarm.time.tm_sec = sec;
+ rtc_wkalarm.enabled = 1;
+ rtc_wkalarm.time.tm_year = year;
+ rtc_wkalarm.time.tm_mon = mon;
+ rtc_wkalarm.time.tm_mday = day;
+ rtc_wkalarm.time.tm_hour = hour;
+ rtc_wkalarm.time.tm_min = min;
+ rtc_wkalarm.time.tm_sec = sec;
- retval = ioctl(gfd, RTC_WKALM_SET, &rtc_wkalarm);
- if (retval == -1) {
- if (errno == ENOTTY)
- ALARM_MGR_EXCEPTION_PRINT("Alarm IRQs is not supported.");
+ retval = ioctl(gfd, RTC_WKALM_SET, &rtc_wkalarm);
+ if (retval == -1) {
+ if (errno == ENOTTY)
+ ALARM_MGR_EXCEPTION_PRINT("Alarm IRQs is not supported.");
- ALARM_MGR_EXCEPTION_PRINT("RTC ALARM_SET ioctl is failed. errno = %s", strerror_r(errno, buf, sizeof(buf)));
- return_code = ERR_ALARM_SYSTEM_FAIL;
+ ALARM_MGR_EXCEPTION_PRINT("RTC ALARM_SET ioctl is failed. errno = %s", strerror_r(errno, buf, sizeof(buf)));
+ return_code = ERR_ALARM_SYSTEM_FAIL;
#ifdef _APPFW_FEATURE_ALARM_MANAGER_MODULE_LOG
- strncpy(log_tag, "FAIL: SET RTC", sizeof(log_tag) - 1);
+ strncpy(log_tag, "FAIL: SET RTC", sizeof(log_tag) - 1);
#endif
- } else {
- ALARM_MGR_LOG_PRINT("[alarm-server]RTC alarm is setted");
+ } else {
+ ALARM_MGR_LOG_PRINT("[alarm-server]RTC alarm is setted");
#ifdef _APPFW_FEATURE_ALARM_MANAGER_MODULE_LOG
- strncpy(log_tag, "SET RTC", sizeof(log_tag) - 1);
+ strncpy(log_tag, "SET RTC", sizeof(log_tag) - 1);
#endif
- }
+ }
#ifdef _APPFW_FEATURE_ALARM_MANAGER_MODULE_LOG
- snprintf(log_message, sizeof(log_message), "wakeup rtc time: %d, %s", (int)rtc_time, ctime(&rtc_time));
- __save_module_log(log_tag, log_message);
+ snprintf(log_message, sizeof(log_message), "wakeup rtc time: %d, %s", (int)rtc_time, ctime(&rtc_time));
+ __save_module_log(log_tag, log_message);
#endif
- return return_code;
-} else {
- ALARM_MGR_LOG_PRINT("[alarm-server] RTC does not work.");
- return ERR_ALARM_SYSTEM_FAIL;
-}
+ return return_code;
+ } else {
+ ALARM_MGR_LOG_PRINT("[alarm-server] RTC does not work.");
+ return ERR_ALARM_SYSTEM_FAIL;
+ }
}
static int accrue_msec = 0; /* To check a millisecond part of current time at changing the system time(sec) */
diff_time = difftime(time_sec, cur_time.tv_sec);
}
- __set_time(time_sec); /* Change both OS time and RTC */
+ if (!__set_time(time_sec)) { /* Change both OS time and RTC */
+ ALARM_MGR_EXCEPTION_PRINT("Failed to change both OS time and RTC");
+ _clear_scheduled_alarm_list();
+ _alarm_schedule();
+ __rtc_set();
+ return ERR_ALARM_SYSTEM_FAIL;
+ }
+
ALARM_MGR_LOG_PRINT("[TIMESTAMP]Current time(%ld), New time(%d)(%s), diff_time(%f)",
cur_time.tv_sec, time_sec, ctime((const time_t *)&time_sec), diff_time);
nanosleep(&sleep_time, NULL); /* Wait until 0 nsec to match both OS time and RTC(sec) */
- __set_time(real_newtime); /* Change both OS time and RTC */
+ if (!__set_time(real_newtime)) { /* Change both OS time and RTC */
+ ALARM_MGR_EXCEPTION_PRINT("Failed to change both OS time and RTC");
+ _clear_scheduled_alarm_list();
+ _alarm_schedule();
+ __rtc_set();
+ return ERR_ALARM_SYSTEM_FAIL;
+ }
diff_time = difftime(real_newtime, cur_time.tv_sec);
ALARM_MGR_LOG_PRINT("[TIMESTAMP]Current time(%ld.%09ld), New time(%d.%09d), Real Newtime(%d), diff_time(%f)",
if (b == NULL) {
int ret_bundle = get_last_result();
ALARM_MGR_EXCEPTION_PRINT("Failed to decode bundle_data[Error:%d]\n", ret_bundle);
- return_code = ERR_ALARM_SYSTEM_FAIL;
- return return_code;
+ return ERR_ALARM_SYSTEM_FAIL;
} else {
callee_appid = appsvc_get_appid(b);
if (_compare_api_version(&result, pid, uid) < 0) {
ALARM_MGR_EXCEPTION_PRINT("Unable to check api version\n");
- return_code = ERR_ALARM_SYSTEM_FAIL;
bundle_free(b);
- return return_code;
+ return ERR_ALARM_SYSTEM_FAIL;
}
if (result < 0) {
} else { /* Since 2.4 */
if (!_is_permitted(callee_appid, alarm_type, uid)) {
ALARM_MGR_EXCEPTION_PRINT("[%s] is not permitted \n", callee_appid);
- return_code = ERR_ALARM_NOT_PERMITTED_APP;
bundle_free(b);
- return return_code;
+ return ERR_ALARM_NOT_PERMITTED_APP;
}
}
GSList *gs_iter = NULL;
__alarm_info_t *entry = NULL;
__alarm_info_t *find_item = NULL;
- time_t _duetime = 0;
int alarm_id;
if (uid < 0)
return ERR_ALARM_INVALID_ID;
}
- _duetime = _alarm_next_duetime(find_item);
- ALARM_MGR_LOG_PRINT("Next duetime : %s", ctime(&_duetime));
+ _alarm_set_next_duetime(find_item);
+ ALARM_MGR_LOG_PRINT("Next duetime : %s", ctime(&(find_item->due_time)));
- *duetime = (int)_duetime;
+ *duetime = (int)(find_item->due_time);
return ALARMMGR_RESULT_SUCCESS;
}
static void __initialize_scheduled_alarm_list()
{
- _init_scheduled_alarm_list();
+ _clear_scheduled_alarm_list();
}
-static bool __initialize_noti()
+static void __initialize_noti()
{
/* VCONFKEY_SYSTEM_TIMECHANGE_EXTERNAL is set by OSP app-service. */
if (vconf_notify_key_changed
pkgmgr_client_set_status_type(pc, PKGMGR_CLIENT_STATUS_DISABLE_APP);
pkgmgr_client_listen_app_status(pc, __on_app_disable_cb, NULL);
- return true;
}
void _alarm_initialize()
#endif
__initialize_scheduled_alarm_list();
- _initialize_db();
+ if (_initialize_db() == false) {
+ ALARM_MGR_EXCEPTION_PRINT("_initialize_db failed, "
+ "alarm cannot be stored to database.\n");
+ }
__initialize_alarm_list();
__initialize_noti();
if (!caller_appid_cache_table) {
- caller_appid_cache_table = g_hash_table_new_full(g_int_hash, g_int_equal,
- NULL, __free_cached_value);
+ caller_appid_cache_table = g_hash_table_new_full(g_direct_hash,
+ g_direct_equal, NULL, __free_cached_value);
}
}