2 * Copyright 2012 Samsung Electronics Co., Ltd
4 * Licensed under the Flora License, Version 1.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
8 * http://www.tizenopensource.org/license
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
17 #define __KIES_FWK_ALARMMGR_C__
19 #include "kies_fwk_alarmmgr.h"
22 /**********************************************************************
23 ******************define, struct ,typedef, union, enum, global val *************************************
24 ***********************************************************************/
26 /**********************************************************************
27 ******************Local function declear, extern function declear*************************************
28 ***********************************************************************/
30 /**********************************************************************
31 ******************Local function ref*************************************
32 ***********************************************************************/
33 /**********************************************************************
34 ******************Global function ref*************************************
35 ***********************************************************************/
39 * This function is used to create mgr
40 * @param data[in] pointer to struct alarm_data
41 * @return when success, return true or false if error
44 int kies_fwk_alarmmgr_create(struct alarm_data *alarm)
48 alarm_entry_t *alarm_entry = NULL;
49 alarm_date_t alarm_data;
51 KIES_RETVM_IF(!alarm, FAILED, "para error");
53 alarm_entry = alarmmgr_create_alarm();
54 KIES_RETVM_IF(!alarm_entry, FAILED, "alarmmgr_create_alarm error");
57 localtime_r((__const time_t *) &alarm->atime, &pt);
58 SET_TIME_DATA_T(&alarm_data, pt.tm_year + 1900, pt.tm_mon + 1,
59 pt.tm_mday, pt.tm_hour, pt.tm_min, pt.tm_sec);
60 nErr = alarmmgr_set_time(alarm_entry, alarm_data);
61 KIES_RETVM_IF(nErr != SUCCESS, FAILED, "alarmmgr_set_time error");
64 alarm_repeat_mode_t repeat_mode = 0;
65 if (alarm->repeat_once) {
66 repeat_mode = ALARM_REPEAT_MODE_ONCE;
67 } else if (alarm->repeat_weekly) {
68 repeat_mode = ALARM_REPEAT_MODE_WEEKLY;
70 repeat_value = alarm->repeat_weekly;
71 nErr = alarmmgr_set_repeat_mode(alarm_entry, repeat_mode, repeat_value);
72 KIES_RETVM_IF(nErr != SUCCESS, FAILED,
73 "alarmmgr_set_repeat_mode error");
75 nErr = alarmmgr_set_type(alarm_entry, ALARM_TYPE_DEFAULT);
76 KIES_RETVM_IF(nErr != SUCCESS, FAILED, "alarmmgr_set_type error");
79 KIES_INFO_PURPLE("%s", ALARMRING_PKGNAME);
81 alarmmgr_add_alarm_with_localtime(alarm_entry, ALARMRING_PKGNAME,
83 KIES_RETVM_IF(SUCCESS != nErr, FAILED,
84 "alarmmgr_add_alarm_with_localtime error,nErr=%d", nErr);
86 alarm->alarm_mgr_id = alarm_mgr_id;
87 KIES_INFO_CYAN("alarm_mgr_id = %d", alarm->alarm_mgr_id);
90 alarmmgr_free_alarm(alarm_entry);
98 * This function is used to remove mgr
99 * @param data[in] pointer to struct alarm_data
100 * @return when success, return true or false if error
103 int kies_fwk_alarmmgr_remove(struct alarm_data *alarm)
106 ret = alarmmgr_remove_alarm(alarm->alarm_mgr_id);
107 if (ret != SUCCESS) {
108 KIES_INFO_RED("Failed to remove alarm[%d], error code: %d\n",
109 alarm->alarm_mgr_id, ret);
111 alarm->alarm_mgr_id = -1;
117 * This function is used to update mgr
118 * @param data[in] pointer to struct alarm_data
119 * @return when success, return true or false if error
122 int kies_fwk_alarmmgr_update(struct alarm_data *alarm)
125 ret = kies_fwk_alarmmgr_remove(alarm);
126 ret |= kies_fwk_alarmmgr_create(alarm);