tizen 2.3 release
[apps/home/settings.git] / setting-syspopup / src / mode-syspopup-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 <mode-syspopup-alarmmgr.h>
22 /**********************************************************************
23 ******************Global function ref*************************************
24 ***********************************************************************/
25
26 /**
27 * send
28 * This function is  used to create mgr
29 * @param           data[in]         pointer to AData
30 * @return          when success, return EINA_TRUE or EINA_FALSE if error
31 * @exception
32 */
33 int mode_syspopup_alarmmgr_create(MODE_BM_AData * alarm)
34 {
35         int nErr = -1;  //no err
36         alarm_entry_t *alarm_entry = NULL;
37         alarm_date_t alarm_data;
38
39         /*create alarm */
40         alarm_entry = alarmmgr_create_alarm();
41         /*set repeat */
42         int repeat_value = 0;
43         alarm_repeat_mode_t repeat_mode = 0;
44         nErr = alarmmgr_set_repeat_mode(alarm_entry, repeat_mode, repeat_value);
45         /*set time_data */
46         struct tm pt;
47         memset(&pt, 0, sizeof(struct tm));
48         time_t ctime = time(NULL);
49         if (NULL == localtime_r(&ctime, &pt)) {
50                 _DBG("fail to call localtime_r");
51         }
52
53         _DBG("alarm->hour[%d], alarm->min[%d]",alarm->hour, alarm->min);
54         pt.tm_hour = alarm->hour;
55         pt.tm_min = alarm->min;
56         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);
57         nErr |= alarmmgr_set_time(alarm_entry, alarm_data);
58
59         /*set type   */
60         nErr = alarmmgr_set_type(alarm_entry, ALARM_TYPE_DEFAULT);
61
62         /*create new    */
63         int alarm_mgr_id = 0;
64         nErr = alarmmgr_add_alarm_with_localtime(alarm_entry, SETTING_BM_ALARM_APP, &alarm_mgr_id);
65         //nErr = alarmmgr_add_alarm_appsvc_with_localtime(alarm_entry, (void *)b, &alarm_mgr_id);
66         _DBG("alarm_mgr_id [%d]", alarm_mgr_id);
67         if(nErr)
68         {
69                 _DBG("*** [ERR] alarmmgr_add_alarm_with_localtime failed ***");
70         }
71
72         alarm->alarm_mgr_id = alarm_mgr_id;
73         //vconf_set_int(VCONFKEY_SETAPPL_BM_ALARM_ID_START, alarm->alarm_mgr_id);
74
75         if (alarm_entry) {
76                 alarmmgr_free_alarm(alarm_entry);
77         }
78         return nErr;
79 }
80
81 /**
82 * send
83 * This function is  used to remove mgr
84 * @param           data[in]         pointer to AData
85 * @return          when success, return EINA_TRUE or EINA_FALSE if error
86 * @exception
87 */
88 int mode_syspopup_alarmmgr_remove(MODE_BM_AData * alarm)
89 {
90
91         int start_block_id = -1;
92         int end_block_id = -1;
93         vconf_get_int(VCONFKEY_SETAPPL_BM_ALARM_ID_START, &start_block_id);
94         vconf_get_int(VCONFKEY_SETAPPL_BM_ALARM_ID_END, &end_block_id);
95         _DBG("alarm->alarm_mgr_id [%d]",alarm->alarm_mgr_id);
96         int ret = -1;
97         if(start_block_id==alarm->alarm_mgr_id) {
98                 _DBG("start id remove");
99                 ret = alarmmgr_remove_alarm(alarm->alarm_mgr_id);
100                 vconf_set_int(VCONFKEY_SETAPPL_BM_ALARM_ID_START, -1);
101         }
102         else if(end_block_id==alarm->alarm_mgr_id)      {
103                 _DBG("end id remove");
104                 ret = alarmmgr_remove_alarm(alarm->alarm_mgr_id);
105                 vconf_set_int(VCONFKEY_SETAPPL_BM_ALARM_ID_END, -1);
106         }
107         else
108         {
109                 _DBG("nothing to remove just create");
110         }
111
112         if(ret)
113         {
114                 _DBG("*** [ERR] alarmmgr_remove_alarm failed : err_code=[%d]", ret);
115         }
116
117         return ret;
118 }
119
120 /**
121 * send
122 * This function is  used to update mgr
123 * @param           data[in]         pointer to AData
124 * @return          when success, return EINA_TRUE or EINA_FALSE if error
125 * @exception
126 */
127 int mode_syspopup_alarmmgr_update(MODE_BM_AData * alarm)
128 {
129         int ret = -1;
130         ret = mode_syspopup_alarmmgr_remove(alarm);
131         ret = mode_syspopup_alarmmgr_create(alarm);
132         _DBG("*** [ERR] mode_syspopup_alarmmgr_update failed ***");
133
134         return ret;
135 }