3 * Copyright 2012 Samsung Electronics Co., Ltd
5 * Licensed under the Flora License, Version 1.0 (the "License");
6 * you may not use this file except in compliance with the License.
7 * You may obtain a copy of the License at
9 * http://www.tizenopensource.org/license
11 * Unless required by applicable law or agreed to in writing, software
12 * distributed under the License is distributed on an "AS IS" BASIS,
13 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 * See the License for the specific language governing permissions and
15 * limitations under the License.
18 #define __KIES_FWK_ALARMMGR_C__
20 #include "kies_fwk_alarmmgr.h"
23 /**********************************************************************
24 ******************define, struct ,typedef, union, enum, global val *************************************
25 ***********************************************************************/
27 /**********************************************************************
28 ******************Local function declear, extern function declear*************************************
29 ***********************************************************************/
31 /**********************************************************************
32 ******************Local function ref*************************************
33 ***********************************************************************/
34 /**********************************************************************
35 ******************Global function ref*************************************
36 ***********************************************************************/
40 * This function is used to create mgr
41 * @param data[in] pointer to struct alarm_data
42 * @return when success, return true or false if error
45 int kies_fwk_alarmmgr_create(struct alarm_data *alarm)
49 alarm_entry_t *alarm_entry = NULL;
50 alarm_date_t alarm_data;
52 KIES_RETVM_IF(!alarm, FAILED, "para error");
54 alarm_entry = alarmmgr_create_alarm();
55 KIES_RETVM_IF(!alarm_entry, FAILED, "alarmmgr_create_alarm error");
58 localtime_r((__const time_t *) &alarm->atime, &pt);
59 SET_TIME_DATA_T(&alarm_data, pt.tm_year + 1900, pt.tm_mon + 1,
60 pt.tm_mday, pt.tm_hour, pt.tm_min, pt.tm_sec);
61 nErr = alarmmgr_set_time(alarm_entry, alarm_data);
62 KIES_RETVM_IF(nErr != SUCCESS, FAILED, "alarmmgr_set_time error");
65 alarm_repeat_mode_t repeat_mode = 0;
66 if (alarm->repeat_once) {
67 repeat_mode = ALARM_REPEAT_MODE_ONCE;
68 } else if (alarm->repeat_weekly) {
69 repeat_mode = ALARM_REPEAT_MODE_WEEKLY;
71 repeat_value = alarm->repeat_weekly;
72 nErr = alarmmgr_set_repeat_mode(alarm_entry, repeat_mode, repeat_value);
73 KIES_RETVM_IF(nErr != SUCCESS, FAILED,
74 "alarmmgr_set_repeat_mode error");
76 nErr = alarmmgr_set_type(alarm_entry, ALARM_TYPE_DEFAULT);
77 KIES_RETVM_IF(nErr != SUCCESS, FAILED, "alarmmgr_set_type error");
80 KIES_INFO_PURPLE("%s", ALARMRING_PKGNAME);
82 alarmmgr_add_alarm_with_localtime(alarm_entry, ALARMRING_PKGNAME,
84 KIES_RETVM_IF(SUCCESS != nErr, FAILED,
85 "alarmmgr_add_alarm_with_localtime error,nErr=%d", nErr);
87 alarm->alarm_mgr_id = alarm_mgr_id;
88 KIES_INFO_CYAN("alarm_mgr_id = %d", alarm->alarm_mgr_id);
91 alarmmgr_free_alarm(alarm_entry);
99 * This function is used to remove mgr
100 * @param data[in] pointer to struct alarm_data
101 * @return when success, return true or false if error
104 int kies_fwk_alarmmgr_remove(struct alarm_data *alarm)
107 ret = alarmmgr_remove_alarm(alarm->alarm_mgr_id);
108 if (ret != SUCCESS) {
109 KIES_INFO_RED("Failed to remove alarm[%d], error code: %d\n",
110 alarm->alarm_mgr_id, ret);
112 alarm->alarm_mgr_id = -1;
118 * This function is used to update mgr
119 * @param data[in] pointer to struct alarm_data
120 * @return when success, return true or false if error
123 int kies_fwk_alarmmgr_update(struct alarm_data *alarm)
126 ret = kies_fwk_alarmmgr_remove(alarm);
127 ret |= kies_fwk_alarmmgr_create(alarm);