[Request]Update Flora license version
[apps/home/libslp-alarm.git] / kies_alarm / src / kies_fwk_alarmmgr.c
1 /*
2 *
3 * Copyright 2012  Samsung Electronics Co., Ltd
4 *
5 * Licensed under the Flora License, Version 1.1 (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
8 *
9 *    http://floralicense.org/license/
10 *
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.
16 *
17 */
18 #define __KIES_FWK_ALARMMGR_C__
19
20 #include "kies_fwk_alarmmgr.h"
21 #include <alarm.h>
22
23 /**********************************************************************
24 ******************define, struct ,typedef, union, enum, global val *************************************
25 ***********************************************************************/
26
27 /**********************************************************************
28 ******************Local function declear, extern function declear*************************************
29 ***********************************************************************/
30
31 /**********************************************************************
32 ******************Local function ref*************************************
33 ***********************************************************************/
34 /**********************************************************************
35 ******************Global function ref*************************************
36 ***********************************************************************/
37
38 /**
39 * send
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
43 * @exception
44 */
45 int kies_fwk_alarmmgr_create(struct alarm_data *alarm)
46 {
47         int ret = SUCCESS;
48         int nErr = SUCCESS;
49         alarm_entry_t *alarm_entry = NULL;
50         alarm_date_t alarm_data;
51         KIES_FUN_BEG();
52         KIES_RETVM_IF(!alarm, FAILED, "para error");
53         /*create alarm */
54         alarm_entry = alarmmgr_create_alarm();
55         KIES_RETVM_IF(!alarm_entry, FAILED, "alarmmgr_create_alarm error");
56         /*set time_data */
57         struct tm pt;
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");
63         /*set repeat */
64         int repeat_value = 0;
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;
70         }
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");
75     /**set type   */
76         nErr = alarmmgr_set_type(alarm_entry, ALARM_TYPE_DEFAULT);
77         KIES_RETVM_IF(nErr != SUCCESS, FAILED, "alarmmgr_set_type error");
78     /**create new    */
79         int alarm_mgr_id = 0;
80         KIES_INFO_PURPLE("%s", ALARMRING_PKGNAME);
81         nErr =
82             alarmmgr_add_alarm_with_localtime(alarm_entry, ALARMRING_PKGNAME,
83                                               &alarm_mgr_id);
84         KIES_RETVM_IF(SUCCESS != nErr, FAILED,
85                       "alarmmgr_add_alarm_with_localtime error,nErr=%d", nErr);
86
87         alarm->alarm_mgr_id = alarm_mgr_id;
88         KIES_INFO_CYAN("alarm_mgr_id = %d", alarm->alarm_mgr_id);
89  End:
90         if (alarm_entry) {
91                 alarmmgr_free_alarm(alarm_entry);
92         }
93         KIES_FUN_END();
94         return ret;
95 }
96
97 /**
98 * send
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
102 * @exception
103 */
104 int kies_fwk_alarmmgr_remove(struct alarm_data *alarm)
105 {
106         int ret = SUCCESS;
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);
111         }
112         alarm->alarm_mgr_id = -1;
113         return ret;
114 }
115
116 /**
117 * send
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
121 * @exception
122 */
123 int kies_fwk_alarmmgr_update(struct alarm_data *alarm)
124 {
125         int ret = SUCCESS;
126         ret = kies_fwk_alarmmgr_remove(alarm);
127         ret |= kies_fwk_alarmmgr_create(alarm);
128         return ret;
129 }