2 * Copyright (c) 2000 - 2015 Samsung Electronics Co., Ltd. All rights reserved.
4 * Licensed under the Apache License, Version 2.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
8 * http://www.apache.org/licenses/LICENSE-2.0
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.
17 #include <Elementary.h>
20 #include <sys/types.h>
40 alarm_id_t alarm_id; /* -1 : None, others : set alarm */
47 static int _alarm_delete_cb(alarm_id_t id, void *user_param)
49 int ret = ALARMMGR_RESULT_SUCCESS;
51 ret = alarmmgr_remove_alarm(id);
52 if(ret != ALARMMGR_RESULT_SUCCESS) {
53 _E("alarmmgr_enum_alarm_ids() failed");
61 static void _alarm_unset(void *data)
63 int ret = ALARMMGR_RESULT_SUCCESS;
65 if (s_hourly_alert.alarm_id != -1) {
66 _D("try to delete alarm_id(%d)", s_hourly_alert.alarm_id);
67 ret = alarmmgr_remove_alarm(s_hourly_alert.alarm_id);
68 if(ret != ALARMMGR_RESULT_SUCCESS) {
69 ret = alarmmgr_enum_alarm_ids(_alarm_delete_cb, NULL);
70 if(ret != ALARMMGR_RESULT_SUCCESS) {
71 _E("alarmmgr_enum_alarm_ids() failed");
74 s_hourly_alert.alarm_id = -1;
80 static int _alarm_set(void *data)
82 int ret = ALARMMGR_RESULT_SUCCESS;
85 alarm_entry_t *alarm_info = NULL;
87 alarm_date_t alarm_time;
89 /* delete before registering alarm ids */
95 current_time += 3600; // +1 hour
97 localtime_r(¤t_time, ¤t_tm);
99 alarm_info = alarmmgr_create_alarm();
100 if(alarm_info == NULL) {
101 _E("alarmmgr_create_alarm() is failed\n");
105 alarm_time.year = current_tm.tm_year;
106 alarm_time.month = current_tm.tm_mon;
107 alarm_time.day = current_tm.tm_mday;
108 alarm_time.hour = current_tm.tm_hour;
112 //alarmmgr_set_repeat_mode(alarm_info, ALARM_REPEAT_MODE_ONCE, 0);
113 ret = alarmmgr_set_repeat_mode(alarm_info, ALARM_REPEAT_MODE_REPEAT, 60*60);
114 if(ret != ALARMMGR_RESULT_SUCCESS) {
115 _E("alarmmgr_set_repeat_mode() failed");
116 alarmmgr_free_alarm(alarm_info) ;
119 alarmmgr_set_time(alarm_info, alarm_time);
120 alarmmgr_set_type(alarm_info, ALARM_TYPE_VOLATILE);
122 ret = alarmmgr_add_alarm_with_localtime(alarm_info, NULL, &alarm_id);
123 if(ret != ALARMMGR_RESULT_SUCCESS) {
124 _E("alarmmgr_add_alarm_with_localtime() failed");
125 alarmmgr_free_alarm(alarm_info) ;
129 s_hourly_alert.alarm_id = alarm_id;
130 alarmmgr_free_alarm(alarm_info);
137 static int _alarm_cb(alarm_id_t alarm_id, void *data)
139 _D("hourly_alert alarm callback called");
141 feedback_initialize();
142 feedback_play(FEEDBACK_PATTERN_NONE);
143 feedback_deinitialize();
150 static int _alarm_init(void *data)
154 ret = alarmmgr_init("starter");
157 ret = alarmmgr_set_cb(_alarm_cb, NULL);
160 s_hourly_alert.alarm_id = -1;
165 static void _alarm_fini(void *data)
173 static Eina_Bool _register_hourly_alert_alarm(void)
177 ret = _alarm_init(NULL);
178 retv_if(ret < 0, EINA_FALSE);
188 static int _unregister_hourly_alert_alarm(void)
196 static void _hourly_alert_changed_cb(keynode_t* node, void *data)
198 int hourly_alert = -1;
200 _D("%s, %d", __func__, __LINE__);
203 hourly_alert = vconf_keynode_get_bool(node);
205 if (vconf_get_int(VCONFKEY_SETAPPL_HOURLY_ALERT_BOOL, &hourly_alert) < 0) {
206 _E("Failed to get %s", VCONFKEY_SETAPPL_HOURLY_ALERT_BOOL);
211 if (hourly_alert == 1) {
212 _E("hourly_alert is set");
213 _register_hourly_alert_alarm();
215 _E("hourly_alert is unset");
216 _unregister_hourly_alert_alarm();
223 static void _hourly_system_time_changed_cb(keynode_t *node, void *data)
230 void hourly_alert_init(void)
232 int hourly_alert = -1;
235 ret = vconf_get_bool(VCONFKEY_SETAPPL_HOURLY_ALERT_BOOL, &hourly_alert);
237 _E("can't get vconfkey value of [%s], ret=[%d]", VCONFKEY_SETAPPL_HOURLY_ALERT_BOOL, ret);
239 } else if (hourly_alert == 1) {
240 _D("[%s] value is [%d], hourly_alert is set..!!", VCONFKEY_SETAPPL_HOURLY_ALERT_BOOL, hourly_alert);
241 if (_register_hourly_alert_alarm() == EINA_FALSE) {
242 _E("_register_hourly_alert_alarm is failed..!!");
246 if (vconf_notify_key_changed(VCONFKEY_SETAPPL_HOURLY_ALERT_BOOL, _hourly_alert_changed_cb, NULL) < 0) {
247 _E("Failed to add the callback for %s changed", VCONFKEY_SETAPPL_HOURLY_ALERT_BOOL);
249 /* for time revision */
250 if (vconf_notify_key_changed(VCONFKEY_SYSTEM_TIME_CHANGED, _hourly_system_time_changed_cb, NULL) < 0) {
251 _E("Failed to add the callback for %s changed", VCONFKEY_SYSTEM_TIME_CHANGED);
257 void hourly_alert_fini(void)
259 _unregister_hourly_alert_alarm();
261 if (vconf_ignore_key_changed(VCONFKEY_SETAPPL_HOURLY_ALERT_BOOL, _hourly_alert_changed_cb) < 0) {
262 _E("Failed to ignore the callback for %s changed", VCONFKEY_SETAPPL_HOURLY_ALERT_BOOL);
265 if (vconf_ignore_key_changed(VCONFKEY_SYSTEM_TIME_CHANGED, _hourly_system_time_changed_cb) < 0) {
266 _E("Failed to ignore the callback for %s changed", VCONFKEY_SYSTEM_TIME_CHANGED);