4 * Copyright (c) 2000 - 2011 Samsung Electronics Co., Ltd. All rights reserved.
6 * Contact: Venkatesha Sarpangala <sarpangala.v@samsung.com>, Jayoun Lee <airjany@samsung.com>,
7 * Sewook Park <sewook7.park@samsung.com>, Jaeho Lee <jaeho81.lee@samsung.com>
9 * Licensed under the Apache License, Version 2.0 (the "License");
10 * you may not use this file except in compliance with the License.
11 * You may obtain a copy of the License at
13 * http://www.apache.org/licenses/LICENSE-2.0
15 * Unless required by applicable law or agreed to in writing, software
16 * distributed under the License is distributed on an "AS IS" BASIS,
17 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
18 * See the License for the specific language governing permissions and
19 * limitations under the License.
27 @defgroup SLP_PG_ALARM_MANAGER AlarmManager
30 <h1 class="pg">Introduction</h1>
32 <h2 class="pg">Purpose of this document</h2>
33 The purpose of this document is to describe how applications can use Alarm Manager APIs for handling alarms. This document gives programming guidelines to application engineers.
35 <h2 class="pg">Scope</h2>
36 The scope of this document is limited to Alarm Manager API usage.
39 <h1 class="pg">Architecture</h1>
41 <h2 class="pg">Architecture overview</h2>
42 The Alarm Manager provides functionality for applications to create, delete and configure alarms. Applications register alarm information and the Alarm Manager manages the alarm information, generates timer and schedule alarms. When the timer expires, the Alarm Manager sends an event to the applications.
44 Refer to Picture 1. for Overview.
46 <h1 class="pg">AlarmManager Overview</h1>
47 \image html SLP_Alarm_PG_overview.png "Picture 1. AlarmManager Overview"
48 \image rtf SLP_Alarm_PG_overview.png "Picture 1. AlarmManager Overview"
50 <h1 class="pg">AlarmManager Process view</h1>
52 <h2 class="pg">AlarmManager Process view</h2>
53 Applications register alarm information using AlarmManager API's. Alarm Manager manages the alarm information in DB, generates timer and schedule alarms. When the timer expires, the Alarm Manager sends an event to the application. If auto-activation of application is enabled then, alarm manager launches the application using app-svc.
55 Refer to Picture 2. for AlarmManager Process view.
57 <h1 class="pg">AlarmManager Process view</h1>
58 \image html SLP_Alarm_PG_processview.png "Picture 1. AlarmManager Process view"
59 \image rtf SLP_Alarm_PG_processview.png "Picture 1. AlarmManager Process view"
62 <h2 class="pg">SLP Features</h2>
63 - The Alarm Manager exposes a high level interface that is used by applications.
64 - The Alarm Manager and applications use D-Bus as its underlying IPC mechanism.
65 - The Alarm Manager uses DB to store the alarm information internally.
66 - The Alarm Manager uses system timers for setting expiration time.
69 <h1 class="pg">Alarm manager properties</h1>
71 <h2 class="pg">Time</h2>
72 There are two types of alarm. The alarm type is distinguished by the following APIs
73 - alarmmgr_add_alarm_with_localtime
74 - The alarm expires at a specified time. The localtime is set by the application in the alarm_entry_t parameter through alarmmgr_set_time().
76 - The alarm expires after a specified interval (in seconds).
78 <h2 class="pg">Repeat mode</h2>
80 - ONCE: In this mode, the alarm expires only once. After it expires, the alarm is removed from alarm server.
81 - REPEAT: In this mode, the alarm is expires repeatly.
82 - WEEKLY: In this mode, the alarm expires weekly on the days specified by the day_of_week parameter.
83 - MONTHLY: In this mode, the alarm expires once a month from the start date.
84 - ANNUALY: In this mode, the alarm expires once a year from the start date.
87 - ALARM_REPEAT_MODE_REPEAT : In this mode, the alarm is repeated at a interval specified in the interval parameter
88 - ALARM_REPEAT_MODE_WEEKLY : In this mode, the alarm is repeated at a weekly interval
94 ALARM_WDAY_SUNDAY=0x01,
95 ALARM_WDAY_MONDAY=0x02,
96 ALARM_WDAY_TUESDAY=0x04,
97 ALARM_WDAY_WEDNESDAY=0x08,
98 ALARM_WDAY_THURSDAY=0x10,
99 ALARM_WDAY_FRIDAY=0x20,
100 ALARM_WDAY_SATURDAY=0x40,
101 }alarm_day_of_week_t;
105 <h2 class="pg">Alarm type</h2>
106 - ALARM_TYPE_DEFAULT : The alarm information is saved using DB. After a device reboot, the alarm still exists.
107 - ALARM_TYPE_VOLATILE : The alarm information is not saved using DB. After a device reboot, the alarm no longer exists.
111 <h1 class="pg">Alarm manager features with sample code</h3>
113 <h2 class="pg">Add an Alarm to the server</h2>
114 An application can add an alarm to the alarm server by using below two ways.
116 1. by alarmmgr_add_alarm
118 int alarmmgr_add_alarm(int alarm_type,
119 time_t trigger_at_time,
121 const char* destination,
122 alarm_id_t* alarm_id);
124 As shown in the sample code below, alrmmgr_init is used to initalize the alarm library. alarmmgr_set_cb is called to set the callback for handling the alarm events. create_test function is called to create an alarm. In the create_test function the alarmmgr_add_alarm() function is called.
128 - Trigger_at_time is the interval after which the alarm is triggered.
129 - If the package that receives the events is different from the package to add an alarm, the application has to write the destination package name.
130 - If the interval is zero, the repeat_mode is ALARM_REPEAT_MODE_ONCE.
131 - If the interval is >0, the repeat_mode is ALARM_REPEAT_MODE_REPEAT.
140 int callback(alarm_id_t alarm_id,void* user_param)
146 printf("Alarm[%d] has expired at %s\n", alarm_id, ctime(¤t_time));
160 printf("current time: %s\n", ctime(¤t_time));
163 alarmmgr_add_alarm(ALARM_TYPE_DEFAULT, 60, 10, NULL,& alarm_id);
164 if(result != ALARMMGR_RESULT_SUCCESS)
165 printf("fail to alarmmgr_create : error_code : %d\n",result);
169 int main(int argc, char** argv)
177 mainloop = g_main_loop_new(NULL, FALSE);
179 result = alarmmgr_init("org.tizen.test");
181 if(result != ALARMMGR_RESULT_SUCCESS)
183 printf("fail to alarmmgr_init : error_code : %d\n",result);
187 result = alarmmgr_set_cb(callback,NULL);
189 if(result != ALARMMGR_RESULT_SUCCESS)
191 printf("fail to alarmmgr_set_cb : error_code : %d\n",result);
198 g_main_loop_run(mainloop);
202 2. by alarmmgr_add_alarm_with_localtime
204 alarm_entry_t* alarmmgr_create_alarm(void);
206 int alarmmgr_set_time(alarm_entry_t* alarm, alarm_date_t time);
208 int alarmmgr_set_repeat_mode(alarm_entry_t* alarm,
209 alarm_repeat_mode_t repeat_mode,
212 int alarmmgr_set_type(alarm_entry_t* alarm, int alarm_type);
214 int alarmmgr_add_alarm_with_localtime(alarm_entry_t* alarm,
215 const char* destination,
216 alarm_id_t* alarm_id);
217 int alarmmgr_remove_alarm(alarm_id_t alarm_id);
219 In this sample code, the application creates an alarm object using the alarmmgr_create_alarm function. Then the alarmmgr_set_*() functions are used to set the attributes of the alarm entry. Finally, the application adds an alarm to the alarm server using alarmmgr_add_alarm_with_localtime. If the application doesn't need the object (alarm entry), the application has to free the memory using the alarmmgr_remove_alarm() function.
222 - Time is localtime. For example, if the alarm is set to expire at 2010/10/3 15:00, even if the system time is changed or the timezone is changed, the alarm will expire at 2010/10/3 15:00.
223 - If the package that receives the events is different from the package to add an alarm, the application has to write the destination package name.
224 - ALARM_REPEAT_MODE_REPEAT : In this mode, the alarm is repeated at a interval specified in the interval parameter
225 - ALARM_REPEAT_MODE_WEEKLY : In this mode, the alarm is repeated at a weekly interval
234 int callback(alarm_id_t alarm_id,void* user_param)
240 printf("Alarm[%d] has expired at %s\n", alarm_id, ctime(¤t_time));
249 struct tm current_tm;
250 alarm_entry_t* alarm_info;
253 alarm_date_t test_time;
257 printf("current time: %s\n", ctime(¤t_time));
258 localtime_r(¤t_time, ¤t_tm);
260 alarm_info = alarmmgr_create_alarm();
266 test_time.hour = current_tm.tm_hour;
267 test_time.min = current_tm.tm_min+1;
271 alarmmgr_set_time(alarm_info,test_time);
272 alarmmgr_set_repeat_mode(alarm_info,ALARM_REPEAT_MODE_WEEKLY,ALARM_WDAY_MONDAY| \
273 ALARM_WDAY_TUESDAY|ALARM_WDAY_WEDNESDAY| \
274 ALARM_WDAY_THURSDAY|ALARM_WDAY_FRIDAY );
276 alarmmgr_set_type(alarm_info,ALARM_TYPE_VOLATILE);
277 alarmmgr_add_alarm_with_localtime(alarm_info,NULL,&alarm_id);
278 if(result != ALARMMGR_RESULT_SUCCESS)
279 printf("fail to alarmmgr_create : error_code : %d\n",result);
283 int main(int argc, char** argv)
291 mainloop = g_main_loop_new(NULL, FALSE);
293 result = alarmmgr_init("org.tizen.test");
295 if(result != ALARMMGR_RESULT_SUCCESS)
297 printf("fail to alarmmgr_init : error_code : %d\n",result);
301 result = alarmmgr_set_cb(callback,NULL);
303 if(result != ALARMMGR_RESULT_SUCCESS)
305 printf("fail to alarmmgr_set_cb : error_code : %d\n",result);
312 g_main_loop_run(mainloop);
316 <h2 class="pg">Get alarm info</h2>
317 The application can retrieve alarm information from the alarm server using the alarmmgr_get_info & alarmmgr_enum_alarm_ids APIs
326 int test_callback (alarm_id_t id, void* user_param)
328 alarm_entry_t* alarm;
329 alarm = alarmmgr_create_alarm();
330 int* n = (int*)user_param;
331 printf("[%d]alarm id : %d\n",*n,id);
333 alarmmgr_get_info(id, alarm); //the application use this object(alarm)
338 alarmmgr_enum_alarm_ids(test_callback,(void*)&n);