tizen 2.4 release
[apps/home/settings.git] / setting-common / src / setting-common-alarmmgr.c
1 /*
2  * setting
3  *
4  * Copyright (c) 2000 - 2011 Samsung Electronics Co., Ltd.
5  *
6  * Contact: MyoungJune Park <mj2004.park@samsung.com>
7  *
8  * Licensed under the Apache License, Version 2.0 (the "License");
9  * you may not use this file except in compliance with the License.
10  * You may obtain a copy of the License at
11  *
12  * http://www.apache.org/licenses/LICENSE-2.0
13  *
14  * Unless required by applicable law or agreed to in writing, software
15  * distributed under the License is distributed on an "AS IS" BASIS,
16  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
17  * See the License for the specific language governing permissions and
18  * limitations under the License.
19  *
20  */
21 #include <setting-debug.h>
22 #include <setting-common-alarmmgr.h>
23 #define EXPORT_PUBLIC __attribute__((visibility("default")))
24
25
26 /**********************************************************************
27 ******************Global function ref*************************************
28 ***********************************************************************/
29
30 /**
31 * send
32 * This function is  used to create mgr
33 * @param           data[in]         pointer to AData
34 * @return          when success, return EINA_TRUE or EINA_FALSE if error
35 * @exception
36 */
37 EXPORT_PUBLIC
38 int setting_common_alarmmgr_create(BM_AData *alarm)
39 {
40         /*SETTING_TRACE_BEGIN; */
41         int nErr = -1;  /*no err */
42         alarm_entry_t *alarm_entry = NULL;
43         alarm_date_t alarm_data;
44
45         /*create alarm */
46         alarm_entry = alarmmgr_create_alarm();
47         /*set repeat */
48         int repeat_value = 0;
49         alarm_repeat_mode_t repeat_mode = 0;
50         setting_retvm_if(NULL == alarm_entry, 0, "alarm_entry is NULL");
51
52         nErr = alarmmgr_set_repeat_mode(alarm_entry, repeat_mode, repeat_value);
53
54         /*set time_data */
55         struct tm pt;
56         memset(&pt, 0, sizeof(struct tm));
57         time_t ctime = time(NULL);
58         if (NULL == localtime_r(&ctime, &pt)) {
59                 SETTING_TRACE_ERROR("fail to call localtime_r");
60         }
61
62         SETTING_TRACE("alarm->hour[%d], alarm->min[%d]", alarm->hour, alarm->min);
63         pt.tm_hour = alarm->hour;
64         pt.tm_min = alarm->min;
65         SET_BM_TIME_DATA_T(&alarm_data, pt.tm_year + 1900, pt.tm_mon + 1, pt.tm_mday, pt.tm_hour, pt.tm_min, 0);
66         nErr |= alarmmgr_set_time(alarm_entry, alarm_data);
67
68         /*set type   */
69         nErr = alarmmgr_set_type(alarm_entry, ALARM_TYPE_DEFAULT);
70
71         /* bundle */
72         /*bundle *b = NULL; */
73         /*b = bundle_create(); */
74         /*appsvc_set_operation(b, APPSVC_OPERATION_DEFAULT); */
75         /*appsvc_set_pkgname(b, SETTING_BM_ALARM_APP); */
76
77         /*create new    */
78         int alarm_mgr_id = 0;
79         nErr = alarmmgr_add_alarm_with_localtime(alarm_entry, SETTING_BM_ALARM_APP, &alarm_mgr_id);
80         /*nErr = alarmmgr_add_alarm_appsvc_with_localtime(alarm_entry, (void *)b, &alarm_mgr_id); */
81         SETTING_TRACE("alarm_mgr_id [%d]", alarm_mgr_id);
82         if (nErr) {
83                 SETTING_TRACE("*** [ERR] alarmmgr_add_alarm_with_localtime failed ***");
84         }
85
86         alarm->alarm_mgr_id = alarm_mgr_id;
87         /*vconf_set_int(VCONFKEY_SETAPPL_BM_ALARM_ID_START, alarm->alarm_mgr_id); */
88
89         if (alarm_entry) {
90                 alarmmgr_free_alarm(alarm_entry);
91         }
92         return nErr;
93 }
94
95 /**
96 * send
97 * This function is  used to update mgr
98 * @param           data[in]         pointer to AData
99 * @return          when success, return EINA_TRUE or EINA_FALSE if error
100 * @exception
101 */
102 EXPORT_PUBLIC
103 int setting_common_alarmmgr_update(BM_AData *alarm)
104 {
105         /*SETTING_TRACE_BEGIN; */
106         int ret = -1;
107         ret = setting_common_alarmmgr_create(alarm);
108         SETTING_TRACE("*** [ERR] setting_common_alarmmgr_update failed ***");
109
110         return ret;
111 }