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