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.
31 * @addtogroup APPLICATION_FRAMEWORK
34 * @defgroup AlarmManager
38 * Alarm supports APIs that add, delete, and update an alarm.
39 * @n An application can use alarm APIs by including @c alarm.h. The definitions
40 * of APIs are defined as follows:
42 * @li @c #alarmmgr_init initialize alarm library
43 * @li @c #alarmmgr_set_cb set the callback for an alarm event
44 * @li @c #alarmmgr_create_alarm create an alarm entry
45 * @li @c #alarmmgr_free_alarm free an alarm entry
46 * @li @c #alarmmgr_set_time set a time will be expired
47 * @li @c #alarmmgr_get_time get a time will be expired
48 * @li @c #alarmmgr_set_repeat_mode set repeat mode
49 * @li @c #alarmmgr_get_repeat_mode get repeat mode
50 * @li @c #alarmmgr_set_type set type
51 * @li @c #alarmmgr_get_type get type
52 * @li @c #alarmmgr_add_alarm_with_localtime add an alarm with localtime
53 * @li @c #alarmmgr_add_alarm add an alarm
54 * @li @c #alarmmgr_remove_alarm remove an alarm from alarm server
55 * @li @c #alarmmgr_enum_alarm_ids get the list of alarm ids
56 * @li @c #alarmmgr_get_info get the information of an alarm
57 * @li @c #alarmmgr_fini de-initialize alarm library
60 * The following code shows how to initialize alarm library, how to register the alarm handler, and how to add an alarm. It first calls alarm_init to initialize the alarm library and sets the callback to handle an alarm event it received. In create_test fucnction, the application add an alarm which will be expired in one minute from it execute and will expire everyday at same time.
70 int callback(alarm_id_t alarm_id, void *user_param)
76 printf("Alarm[%d] has expired at %s\n", alarm_id, ctime(¤t_time));
84 alarm_entry_t* alarm_info;
87 alarm_date_t test_time;
91 printf("current time: %s\n", ctime(¤t_time));
92 localtime_r(¤t_time, ¤t_tm);
94 alarm_info = alarmmgr_create_alarm();
96 test_time.year = current_tm.tm_year+1900;
97 test_time.month = current_tm.tm_mon+1;
98 test_time.day = current_tm.tm_mday;
99 test_time.hour = current_tm.tm_hour;
100 test_time.min = current_tm.tm_min+1;
103 alarmmgr_set_time(alarm_info,test_time);
104 alarmmgr_set_repeat_mode(alarm_info,ALARM_REPEAT_MODE_WEEKLY,
106 ALARM_WDAY_TUESDAY|ALARM_WDAY_WEDNESDAY| \
107 ALARM_WDAY_THURSDAY|ALARM_WDAY_FRIDAY );
109 alarmmgr_set_type(alarm_info,ALARM_TYPE_VOLATILE);
110 alarmmgr_add_alarm_with_localtime(alarm_info,NULL,&alarm_id);
112 if(result != ALARMMGR_RESULT_SUCCESS)
113 printf("fail to alarmmgr_create : error_code : %d\n",result);
117 int main(int argc, char** argv)
124 mainloop = g_main_loop_new(NULL, FALSE);
125 result = alarmmgr_init("org.tizen.test");
127 if(result != ALARMMGR_RESULT_SUCCESS) {
128 printf("fail to alarmmgr_init : error_code : %d\n",result);
131 result = alarmmgr_set_cb(callback,NULL);
132 if(result != ALARMMGR_RESULT_SUCCESS) {
133 printf("fail to alarmmgr_set_cb : error_code :
140 g_main_loop_run(mainloop);
148 * @addtogroup AlarmManager
152 #include <sys/types.h>
161 * Type of an alarm id
163 typedef int alarm_id_t;
165 * The prototype of alarm handler.
166 * param [in] alarm_id the id of expired alarm
168 typedef int (*alarm_cb_t) (alarm_id_t alarm_id, void *user_param);
170 typedef int (*alarm_enum_fn_t) (alarm_id_t alarm_id, void *user_param);
173 * This enumeration has day of a week of alarm
176 ALARM_WDAY_SUNDAY = 0x01, /**< enalbe alarm on Sunday*/
177 ALARM_WDAY_MONDAY = 0x02, /**< enalbe alarm on Monday*/
178 ALARM_WDAY_TUESDAY = 0x04, /**< enable alarm on Tuesday*/
179 ALARM_WDAY_WEDNESDAY = 0x08, /**< enalbe alarm on Wednesday*/
180 ALARM_WDAY_THURSDAY = 0x10, /**< enable alarm on Thursday*/
181 ALARM_WDAY_FRIDAY = 0x20, /**< enable alarm on Friday*/
182 ALARM_WDAY_SATURDAY = 0x40,/**< enable alarm on Saturday*/
183 } alarm_day_of_week_t;
186 * This enumeration has error codes of alarm
189 ERR_ALARM_NOT_PERMITTED_APP = -11,
190 ERR_ALARM_INVALID_PARAM = -10,
191 /**<Invalid parameter*/
192 ERR_ALARM_INVALID_ID, /**<Invalid id*/
193 ERR_ALARM_INVALID_REPEAT,
194 /**<Invalid repeat mode*/
195 ERR_ALARM_INVALID_TIME, /**<Invalid time. */
196 ERR_ALARM_INVALID_DATE, /**<Invalid date. */
197 ERR_ALARM_NO_SERVICE_NAME,
198 /**<there is no alarm service
199 for this applicaation. */
200 ERR_ALARM_INVALID_TYPE, /*Invalid type*/
201 ERR_ALARM_NO_PERMISSION, /*No permission*/
202 ERR_ALARM_SYSTEM_FAIL = -1,
203 ALARMMGR_RESULT_SUCCESS = 0,
207 * This enumeration has repeat mode of alarm
210 ALARM_REPEAT_MODE_ONCE = 0, /**<once : the alarm will be expired
212 ALARM_REPEAT_MODE_REPEAT, /**<repeat : the alarm will be expired
214 ALARM_REPEAT_MODE_WEEKLY, /**<weekly*/
215 ALARM_REPEAT_MODE_MONTHLY, /**< monthly*/
216 ALARM_REPEAT_MODE_ANNUALLY, /**< annually*/
217 ALARM_REPEAT_MODE_MAX,
218 } alarm_repeat_mode_t;
227 #define ALARM_TYPE_DEFAULT 0x0 /*< non volatile */
228 #define ALARM_TYPE_VOLATILE 0x02 /*< volatile */
229 #define ALARM_TYPE_NOLAUNCH 0x04 /*<without launch */
230 #define ALARM_TYPE_INEXACT 0x08 /*<inexact alarm */
234 * This struct has date information
237 int year; /**< specifies the year */
238 int month; /**< specifies the month */
239 int day; /**< specifies the day */
240 int hour; /**< specifies the hour */
241 int min; /**< specifies the minute*/
242 int sec; /**< specifies the second*/
246 typedef struct alarm_info_t alarm_entry_t;
251 * This function initializes alarm library. It connects to system bus and registers the application's service name.
253 * @param [in] pkg_name a package of application
255 * @return On success, ALARMMGR_RESULT_SUCCESS is returned. On error, a negative number is returned
260 * @remark An application must call this function before using other alarm APIs.
267 int ret_val = ALARMMGR_RESULT_SUCCESS;
268 const char* pkg_name = "org.tizen.test";
272 ret_val =alarmmgr_init(pkg_name) ;
273 if(ret_val == ALARMMGR_RESULT_SUCCESS)
275 //alarmmgr_init() is successful
279 //alarmmgr_init () failed
284 int alarmmgr_init(const char *appid);
288 * This function de-initializes alarm library. It un-registers the application's service name and dis-connects from system bus.
294 * @pre Alarm manager is initialized
295 * @post Alarm manager is de-initialized
296 * @remark An application must call this function once it is done with alarmmanger usage
303 // Initialize alarmmanager
311 void alarmmgr_fini();
315 * This function registers handler which handles an alarm event. An application should register the alarm handler
316 * before it enters mainloop.
318 * @param [in] handler Callback function
319 * @param [in] user_param User Parameter
321 * @return This function returns ALARMMGR_RESULT_SUCCESS on success or a negative number on failure.
323 * @pre alarmmgr_init().
326 * @remark An application can have only one alarm handler. If an application
327 * calls this function more than one times, the handler regitered during the
328 * last call of this funiction will be called when an alarm event has occured.
334 // Call back function
335 int callback(alarm_id_t alarm_id,void* user_param)
340 printf("Alarm[%d] has expired at %s\n", alarm_id, ctime(¤t_time));
348 int ret_val = ALARMMGR_RESULT_SUCCESS;
349 void *user_param = NULL;
351 ret_val = alarmmgr_set_cb( callback, user_param);
352 if(ret_val == ALARMMGR_RESULT_SUCCESS)
354 //alarmmgr_set_cb() is successful
358 //alarmmgr_set_cb () failed
364 int alarmmgr_set_cb(alarm_cb_t handler, void *user_param);
368 * This function creates a new alarm entry, will not be known to the server until alarmmgr_add_alarm is called.
370 * @return This function returns the pointer of alarm_entry_t
375 * @remark After an application use this object, an application free this pointer through alarmmgr_free_alarm
383 alarm_entry_t* alarm;
385 alarm = alarmmgr_create_alarm() ;
388 //alarmmgr_create_alarm() is successful
392 //alarmmgr_create_alarm () failed
399 alarm_entry_t *alarmmgr_create_alarm(void);
403 * This function frees an alarm entry.
405 * @param [in] alarm alarm entry
407 * @return This function returns ALARMMGR_RESULT_SUCCESS on success or a negative number on failure.
420 int ret_val = ALARMMGR_RESULT_SUCCESS;
421 alarm_entry_t* alarm;
423 alarm = alarmmgr_create_alarm() ;
426 //alarmmgr_create_alarm () failed
431 ret_val = alarmmgr_free_alarm( alarm) ;
432 if(ret_val == ALARMMGR_RESULT_SUCCESS)
434 //alarmmgr_free_alarm() is successful
438 //alarmmgr_free_alarm() failed
445 int alarmmgr_free_alarm(alarm_entry_t *alarm);
449 * This function sets time that alarm should be expried.
451 * @param [in] alarm alarm entry
452 * @param [in] time time the alarm should first go off
454 * @return This function returns ALARMMGR_RESULT_SUCCESS on success or a negative number on failure.
467 int ret_val = ALARMMGR_RESULT_SUCCESS;
468 alarm_entry_t* alarm;
470 struct tm current_tm;
471 alarm_date_t test_time;
475 localtime_r(¤t_time, ¤t_tm);
477 alarm = alarmmgr_create_alarm();
480 //alarmmgr_create_alarm () failed
483 test_time.year = current_tm.tm_year;
484 test_time.month = current_tm.tm_mon;
485 test_time.day = current_tm.tm_mday;
487 test_time.hour = current_tm.tm_hour;
488 test_time.min = current_tm.tm_min+1;
491 ret_val=alarmmgr_set_time(alarm,test_time);
492 if(ret_val == ALARMMGR_RESULT_SUCCESS)
494 //alarmmgr_set_time() is successful
498 //alarmmgr_set_time() failed
500 alarmmgr_free_alarm( alarm) ;
506 int alarmmgr_set_time(alarm_entry_t *alarm, alarm_date_t time);
509 * This function gives an application time that alarm should be expried.
511 * @param [in] alarm alarm entry
512 * @param [out] time time the alarm should first go off
514 * @return This function returns ALARMMGR_RESULT_SUCCESS on success or a negative number on failure.
519 * @remark But an application does not need to specify year, month, and day field of alarm_info. If an application sets
520 * those fields with zero, the function sets them with proper values.
528 int ret_val = ALARMMGR_RESULT_SUCCESS;
529 alarm_entry_t* alarm;
532 struct tm current_tm;
533 alarm_date_t test_time;
534 alarm_date_t new_time;
538 localtime_r(¤t_time, ¤t_tm);
540 alarm = alarmmgr_create_alarm();
542 //alarmmgr_create_alarm () failed
545 test_time.year = current_tm.tm_year;
546 test_time.month = current_tm.tm_mon;
547 test_time.day = current_tm.tm_mday;
549 test_time.hour = current_tm.tm_hour;
550 test_time.min = current_tm.tm_min+1;
553 ret_val = alarmmgr_set_time(alarm,test_time);
554 if(ret_val == ALARMMGR_RESULT_SUCCESS) {
555 //alarmmgr_set_time() is successful
558 //alarmmgr_set_time() failed
561 ret_val = alarmmgr_get_time(alarm, &new_time);
562 if(ret_val == ALARMMGR_RESULT_SUCCESS) {
563 //alarmmgr_get_time() is successful
566 //alarmmgr_get_time() failed
568 alarmmgr_free_alarm( alarm) ;
574 int alarmmgr_get_time(const alarm_entry_t *alarm, alarm_date_t *time);
577 * This function sets an alarm repeat mode
579 * @param [in] alarm alarm entry
580 * @param [in] repeat_mode one of ALARM_REPEAT_MODE_ONCE, ALARM_REPEAT_MODE_REPEAT,
581 * ALARM_REPEAT_MODE_WEEKLY, ALARM_REPEAT_MODE_MONTHLY or ALARM_REPEAT_MODE_ANNUALLY.
582 * @param [in] repeat_value the ALARM_REPEAT_MODE_REPEAT mode : interval between subsequent repeats of the alarm.
583 * the ALARM_REPEAT_MODE_WEEKLY mode : days of a week
584 * (ALARM_WDAY_SUNDAY, ALARM_WDAY_MONDAY, ALARM_WDAY_TUESDAY, ALARM_WDAY_WEDNESDAY,
585 * ALARM_WDAY_THURSDAY, ALARM_WDAY_FRIDAY, ALARM_WDAY_SATURDAY)
586 * the others : this parameter is ignored.
588 * @return This function returns ALARMMGR_RESULT_SUCCESS on success or a negative number on failure.
601 int ret_val = ALARMMGR_RESULT_SUCCESS;
602 alarm_entry_t* alarm;
603 alarm_repeat_mode_t repeat_mode =ALARM_REPEAT_MODE_WEEKLY;
604 int interval = ALARM_WDAY_MONDAY; //| ALARM_WDAY_TUESDAY|
605 ALARM_WDAY_WEDNESDAY| ALARM_WDAY_THURSDAY|ALARM_WDAY_FRIDAY ;
608 alarm = alarmmgr_create_alarm();
611 //alarmmgr_create_alarm () failed
615 ret_val = alarmmgr_set_repeat_mode
616 (alarm, repeat_mode,interval);
618 if(ret_val == ALARMMGR_RESULT_SUCCESS)
620 //alarmmgr_set_repeat_mode() is successful
624 //alarmmgr_set_repeat_mode() failed
626 alarmmgr_free_alarm( alarm) ;
632 int alarmmgr_set_repeat_mode(alarm_entry_t *alarm,
633 alarm_repeat_mode_t repeat_mode,
637 * This function gives an application an alarm mode
639 * @param [in] alarm alarm entry
640 * @param [out] repeat_mode one of ALARM_REPEAT_MODE_ONCE, ALARM_REPEAT_MODE_REPEAT,
641 * ALARM_REPEAT_MODE_WEEKLY, ALARM_REPEAT_MODE_MONTHLY or ALARM_REPEAT_MODE_ANNUALLY.
642 * @param [out] repeat_value the ALARM_REPEAT_MODE_REPEAT mode : interval between subsequent repeats of the alarm.
643 * the ALARM_REPEAT_MODE_WEEKLY mode : days of a week
644 * (ALARM_WDAY_SUNDAY, ALARM_WDAY_MONDAY, ALARM_WDAY_TUESDAY, ALARM_WDAY_WEDNESDAY,
645 * ALARM_WDAY_THURSDAY, ALARM_WDAY_FRIDAY, ALARM_WDAY_SATURDAY)
646 * the others : this parameter is ignored.
648 * @return This function returns ALARMMGR_RESULT_SUCCESS on success or a negative number on failure.
661 int ret_val = ALARMMGR_RESULT_SUCCESS;
662 alarm_entry_t* alarm;
663 alarm_repeat_mode_t repeat;
666 alarm = alarmmgr_create_alarm();
669 //alarmmgr_create_alarm () failed
672 ret_val =alarmmgr_get_repeat_mode
673 (alarm, &repeat, &interval) ;
674 if(ret_val == ALARMMGR_RESULT_SUCCESS
675 && repeat == ALARM_REPEAT_MODE_ONCE) {
676 //alarmmgr_get_repeat_mode() is successful
679 //alarmmgr_get_repeat_mode() failed
681 alarmmgr_free_alarm(alarm) ;
687 int alarmmgr_get_repeat_mode(const alarm_entry_t *alarm,
688 alarm_repeat_mode_t *repeat_mode,
692 * This function sets an alarm mode
694 * @param [in] alarm alarm entry
695 * @param [in] alarm_type one of ALARM_TYPE_DEFAULT : After the device reboot, the alarm still works.
696 * ALARM_TYPE_VOLATILE : After the device reboot, the alarm does not work.
698 * @return This function returns ALARMMGR_RESULT_SUCCESS on success or a negative number on failure.
711 int ret_val = ALARMMGR_RESULT_SUCCESS;
712 alarm_entry_t* alarm;
713 int alarm_type = ALARM_TYPE_VOLATILE;
715 alarm = alarmmgr_create_alarm();
718 //alarmmgr_create_alarm () failed
722 ret_val = alarmmgr_set_type(alarm, alarm_type);
723 if(ret_val == ALARMMGR_RESULT_SUCCESS)
725 //alarmmgr_set_type() is successful
729 //alarmmgr_set_type() failed
731 alarmmgr_free_alarm( alarm) ;
737 int alarmmgr_set_type(alarm_entry_t *alarm, int alarm_type);
740 * This function gives an application an alarm mode
742 * @param [in] alarm alarm entry
743 * @param [out] alarm_type one of ALARM_TYPE_DEFAULT, ALARM_TYPE_VOLATILE
745 * @return This function returns ALARMMGR_RESULT_SUCCESS on success or a negative number on failure.
758 int ret_val = ALARMMGR_RESULT_SUCCESS;
759 alarm_entry_t* alarm;
762 alarm = alarmmgr_create_alarm();
764 //alarmmgr_create_alarm () failed
767 ret_val = alarmmgr_get_type( alarm, &alarm_type);
768 if(ret_val == ALARMMGR_RESULT_SUCCESS && alarm_type
769 == ALARM_TYPE_DEFAULT ) {
770 //alarmmgr_get_type() is successful
773 //alarmmgr_get_type() failed
775 alarmmgr_free_alarm( alarm) ;
781 int alarmmgr_get_type(const alarm_entry_t *alarm, int *alarm_type);
784 * This function adds an alarm entry to the server.
785 * Server will remember this entry, and generate alarm events for it when necessary.
786 * Server will call app-svc interface to sent notification to destination application. Destination information
787 * should be available in the input bundle.
788 * Alarm entries registered with the server cannot be changed.
789 * Remove from server before changing.
790 * Before the application calls alarmmgr_add_alarm_appsvc_with_localtime(), the application have to call alarmmgr_set_time().
791 * The time set is localtime.
792 * If the application does not call alarmmgr_set_repeat_mode, the default repeat_mode is ALARM_REPEAT_MODE_ONCE.
793 * If the application does not call alarmmgr_set_type, the default alarm_type is ALARM_TYPE_DEFAULT.
794 * The id of the new alarm will be copied to alarm_id if the fuction successes to create an alarm.
796 * @param [in] alarm the entry of an alarm to be created.
797 * @param [in] bundle_data bundle which contains information about the destination.
798 * @param [out] alarm_id the id of the alarm added.
800 * @return This function returns ALARMMGR_RESULT_SUCCESS on success or a negative number on failure.
804 * @see alarmmgr_add_alarm
814 struct tm current_tm;
815 alarm_entry_t* alarm_info;
818 alarm_date_t test_time;
827 printf("Unable to create bundle!!!\n");
831 appsvc_set_operation(b,APPSVC_OPERATION_DEFAULT);
832 appsvc_set_pkgname(b,"org.tizen.alarm-test");
836 printf("current time: %s\n", ctime(¤t_time));
837 localtime_r(¤t_time, ¤t_tm);
839 alarm_info = alarmmgr_create_alarm();
841 test_time.year = current_tm.tm_year;
842 test_time.month = current_tm.tm_mon;
843 test_time.day = current_tm.tm_mday;
845 test_time.hour = current_tm.tm_hour;
846 test_time.min = current_tm.tm_min+1;
850 alarmmgr_set_time(alarm_info,test_time);
851 alarmmgr_set_repeat_mode(alarm_info,ALARM_REPEAT_MODE_WEEKLY,ALARM_WDAY_MONDAY| \
852 ALARM_WDAY_TUESDAY|ALARM_WDAY_WEDNESDAY| \
853 ALARM_WDAY_THURSDAY|ALARM_WDAY_FRIDAY );
855 alarmmgr_set_type(alarm_info, ALARM_TYPE_DEFAULT);
856 //alarmmgr_set_type(alarm_info,ALARM_TYPE_VOLATILE);
857 if ((result = alarmmgr_add_alarm_appsvc_with_localtime(alarm_info,(void *)b,&alarm_id)) < 0)
859 printf("Alarm creation failed!!! Alrmgr error code is %d\n",result);
863 printf("Alarm created succesfully with alarm id %d\n",alarm_id);
869 int alarmmgr_add_alarm_appsvc_with_localtime(alarm_entry_t *alarm,void *bundle_data, alarm_id_t *alarm_id);
872 * This function adds an alarm entry to the server.
873 * Server will remember this entry, and generate alarm events for it when necessary.
874 * Alarm entries registered with the server cannot be changed.
875 * Remove from server before changing.
876 * Before the application calls alarmmgr_add_alarm_with_localtime(), the application have to call alarmmgr_set_time().
877 * The time set is localtime.
878 * If the application does not call alarmmgr_set_repeat_mode, the default repeat_mode is ALARM_REPEAT_MODE_ONCE.
879 * If the application does not call alarmmgr_set_type, the default alarm_type is ALARM_TYPE_DEFAULT.
880 * The id of the new alarm will be copied to alarm_id if the fuction successes to create an alarm.
882 * @param [in] alarm the entry of an alarm to be created.
883 * @param [in] destination the packname of application that the alarm will be expired.
884 * @param [out] alarm_id the id of the alarm added.
886 * @return This function returns ALARMMGR_RESULT_SUCCESS on success or a negative number on failure.
890 * @see alarmmgr_add_alarm
899 int ret_val = ALARMMGR_RESULT_SUCCESS;
900 alarm_entry_t* alarm;
901 const char* destination = NULL;
905 struct tm current_tm;
906 alarm_date_t test_time;
908 const char* pkg_name = "org.tizen.test";
912 ret_val =alarmmgr_init(pkg_name) ;
913 if(ret_val != ALARMMGR_RESULT_SUCCESS) {
914 //alarmmgr_init () failed
920 printf("current time: %s\n", ctime(¤t_time));
921 localtime_r(¤t_time, ¤t_tm);
923 alarm = alarmmgr_create_alarm();
926 test_time.month = 0;test_time.day = 0;
928 test_time.hour = current_tm.tm_hour;
929 test_time.min = current_tm.tm_min+1;
933 alarmmgr_set_time(alarm,test_time);
934 alarmmgr_set_repeat_mode(alarm,ALARM_REPEAT_MODE_WEEKLY, \
936 alarmmgr_set_type(alarm,ALARM_TYPE_VOLATILE);
939 ret_val=alarmmgr_add_alarm_with_localtime(alarm,destination,&alarm_id);
941 if(ret_val == ALARMMGR_RESULT_SUCCESS)
943 //alarmmgr_add_alarm_with_localtime() is successful
947 //alarmmgr_add_alarm_with_localtime() failed
949 alarmmgr_free_alarm( alarm) ;
953 int alarmmgr_add_alarm_with_localtime(alarm_entry_t *alarm,
954 const char *destination,
955 alarm_id_t *alarm_id);
959 * This function adds an alarm entry to the server.
960 * Server will remember this entry, and generate alarm events for it when necessary.
961 * Server will call app-svc interface to sent notification to destination application. Destination information
962 * should be available in the input bundle.
963 * Alarm entries registered with the server cannot be changed.
964 * Remove from server before changing.
965 * After the trigger_at_time seconds from now, the alarm will be expired.
966 * If the interval is zero, the repeat_mode is ALARM_REPEAT_MODE_ONCE.
967 * If the interval is >0, the repeat_mode is ALARM_REPEAT_MODE_REPEAT.
968 * The id of the new alarm will be copied to alarm_id if the fuction successes to create an alarm.
970 * @param [in] alarm_type one of ALARM_TYPE_DEFAULT, ALARM_TYPE_VOLATILE
971 * @param [in] trigger_at_time time interval to be triggered from now(sec). an alarm also will be expired at triggering time.
972 * @param [in] interval Interval between subsequent repeats of the alarm
973 * @param [in] bundle_data bundle which contains information about the destination.
974 * @param [out] alarm_id the id of the alarm added.
976 * @return This function returns ALARMMGR_RESULT_SUCCESS on success or a negative number on failure.
980 * @see alarmmgr_add_alarm_with_localtime alarmmgr_remove_alarm
998 printf("Unable to create bundle!!!\n");
1002 appsvc_set_pkgname(b,"org.tizen.alarm-test");
1003 //appsvc_set_operation(b,APPSVC_OPERATION_SEND_TEXT);
1004 appsvc_set_operation(b,APPSVC_OPERATION_DEFAULT);
1006 if ((result = alarmmgr_add_alarm_appsvc(ALARM_TYPE_DEFAULT, 10, 0, (void *)b ,&alarm_id)))
1007 printf("Unable to add alarm. Alarmmgr alarm no is %d\n", result);
1009 printf("Alarm added successfully. Alarm Id is %d\n", alarm_id);
1016 int alarmmgr_add_alarm_appsvc(int alarm_type, time_t trigger_at_time,
1017 time_t interval, void *bundle_data,
1018 alarm_id_t *alarm_id);
1022 * This function adds an alarm entry to the server.
1023 * Server will remember this entry, and generate alarm events for it when necessary.
1024 * Alarm entries registered with the server cannot be changed.
1025 * Remove from server before changing.
1026 * After the trigger_at_time seconds from now, the alarm will be expired.
1027 * If the interval is zero, the repeat_mode is ALARM_REPEAT_MODE_ONCE.
1028 * If the interval is >0, the repeat_mode is ALARM_REPEAT_MODE_REPEAT.
1029 * The id of the new alarm will be copied to alarm_id if the fuction successes to create an alarm.
1031 * @param [in] alarm_type one of ALARM_TYPE_DEFAULT, ALARM_TYPE_VOLATILE
1032 * @param [in] trigger_at_time time interval to be triggered from now(sec). an alarm also will be expired at triggering time.
1033 * @param [in] interval Interval between subsequent repeats of the alarm
1034 * @param [in] destination the packname of application that the alarm will be expired.
1035 * @param [out] alarm_id the id of the alarm added.
1037 * @return This function returns ALARMMGR_RESULT_SUCCESS on success or a negative number on failure.
1041 * @see alarmmgr_add_alarm_with_localtime alarmmgr_remove_alarm
1050 int ret_val = ALARMMGR_RESULT_SUCCESS;
1052 int alarm_type = ALARM_TYPE_VOLATILE;
1053 time_t trigger_at_time = 10;
1054 time_t interval = 10;
1055 const char* destination = NULL;
1056 alarm_id_t alarm_id;
1058 const char* pkg_name = "org.tizen.test";
1062 ret_val =alarmmgr_init(pkg_name) ;
1063 if(ret_val != ALARMMGR_RESULT_SUCCESS)
1065 //alarmmgr_init () failed
1069 ret_val = alarmmgr_add_alarm( alarm_type, trigger_at_time, interval,
1070 destination, &alarm_id);
1071 if(ret_val == ALARMMGR_RESULT_SUCCESS)
1073 //alarmmgr_add_alarm() is successful
1077 //alarmmgr_add_alarm() failed
1079 alarmmgr_remove_alarm( alarm_id) ;
1084 int alarmmgr_add_alarm(int alarm_type, time_t trigger_at_time,
1085 time_t interval, const char *destination,
1086 alarm_id_t *alarm_id);
1089 * This function deletes the alarm associated with the given alarm_id.
1091 * @param [in] alarm_id Specifies the ID of the alarm to be deleted.
1093 * @return This function returns ALARMMGR_RESULT_SUCCESS on success or a negative number on failure.
1097 * @see alarmmgr_add_alarm_with_localtime alarmmgr_add_alarm
1106 int ret_val = ALARMMGR_RESULT_SUCCESS;
1107 int alarm_type = ALARM_TYPE_VOLATILE;
1108 time_t trigger_at_time = 10;
1109 time_t interval = 10;
1110 const char* destination = NULL;
1111 alarm_id_t alarm_id;
1113 const char* pkg_name = "org.tizen.test";
1117 ret_val =alarmmgr_init(pkg_name) ;
1118 if(ret_val != ALARMMGR_RESULT_SUCCESS) {
1119 //alarmmgr_init () failed
1123 alarmmgr_add_alarm( alarm_type, trigger_at_time, interval,
1124 destination, &alarm_id);
1126 ret_val =alarmmgr_remove_alarm( alarm_id) ;
1127 if(ret_val == ALARMMGR_RESULT_SUCCESS) {
1128 /alarmmgr_remove_alarm() is successful
1131 //alarmmgr_remove_alarm() failed
1137 int alarmmgr_remove_alarm(alarm_id_t alarm_id);
1140 * This function deletes all registered alarms
1142 * @return This function returns ALARMMGR_RESULT_SUCCESS on success or a negative number on failure.
1144 int alarmmgr_remove_all(void);
1147 * This function gives a list of alarm ids that the application adds to the server.
1149 * @param [in] fn a user callback function
1150 * @param [in] user_param user parameter
1152 * @return This function returns ALARMMGR_RESULT_SUCCESS on success or a negative number on failure.
1156 * @see alarm_get_info
1163 int callback_2(alarm_id_t id, void* user_param)
1165 int* n = (int*)user_param;
1166 printf("[%d]alarm id : %d\n",*n,id);
1173 int ret_val = ALARMMGR_RESULT_SUCCESS;
1176 const char* pkg_name = "org.tizen.test";
1180 ret_val =alarmmgr_init(pkg_name) ;
1181 if(ret_val != ALARMMGR_RESULT_SUCCESS)
1183 //alarmmgr_init() failed
1187 ret_val = alarmmgr_enum_alarm_ids( callback_2, (void*)&n) ;
1188 if(ret_val == ALARMMGR_RESULT_SUCCESS)
1190 //alarmmgr_enum_alarm_ids() is successful
1194 //alarmmgr_enum_alarm_ids() failed
1200 int alarmmgr_enum_alarm_ids(alarm_enum_fn_t fn, void *user_param);
1204 * This function gets the information of the alarm assosiated with alarm_id to alarm_info. The application
1205 * must allocate alarm_info before calling this function.
1207 * @param [in] alarm_id the id of the alarm
1208 * @param [out] alarm the buffer alarm informaiton will be copied to
1210 * @return This function returns ALARMMGR_RESULT_SUCCESS on success or a negative number on failure.
1214 * @see alarmmgr_enum_alarm_ids
1223 int ret_val = ALARMMGR_RESULT_SUCCESS;
1224 int alarm_type = ALARM_TYPE_VOLATILE;
1225 time_t trigger_at_time = 10;
1226 time_t interval = ALARM_WDAY_SUNDAY;
1227 const char* destination = NULL;
1228 alarm_id_t alarm_id;
1230 alarm_entry_t *alarm;
1232 const char* pkg_name = "org.tizen.test_get_info1";
1236 ret_val =alarmmgr_init(pkg_name) ;
1237 if(ret_val != ALARMMGR_RESULT_SUCCESS) {
1238 //alarmmgr_init() failed
1241 ret_val = alarmmgr_add_alarm( alarm_type,trigger_at_time,interval,
1242 destination, &alarm_id);
1244 if(ret_val != ALARMMGR_RESULT_SUCCESS) {
1245 //alarmmgr_add_alarm() failed
1248 ret_val = alarmmgr_get_info(alarm_id, alarm);
1249 if(ret_val == ALARMMGR_RESULT_SUCCESS) {
1250 //alarmmgr_get_info() is successful
1253 //alarmmgr_get_info() failed
1255 alarmmgr_remove_alarm( alarm_id) ;
1259 int alarmmgr_get_info(alarm_id_t alarm_id, alarm_entry_t *alarm);
1263 * This function retrieves bundle associated with alarm.
1264 * Server will remember this entry, and pass the bundle information upon alarm expiry.
1265 * Server will call app-svc interface to sent notification to destination application. Destination information
1266 * should be available in the input bundle.
1267 * @param [in] alarm_id alarm id
1268 * @param [out] ALARMMGR_RESULT_SUCCESS on success or negative number on failure.
1270 * @return This function returns bundle on success or NULL on failure.
1283 alarm_id_t alarm_id;
1292 printf("Unable to create bundle!!!\n");
1296 appsvc_set_pkgname(b,"org.tizen.alarm-test");
1297 appsvc_set_operation(b,APPSVC_OPERATION_DEFAULT);
1299 if ((result = alarmmgr_add_alarm_appsvc(ALARM_TYPE_DEFAULT, 10, 0, (void *)b ,&alarm_id)))
1300 printf("Unable to add alarm. Alarmmgr alarm no is %d\n", result);
1302 printf("Alarm added successfully. Alarm Id is %d\n", alarm_id);
1304 int main(int argc,char **argv {
1307 int return_code = 0;
1309 b = alarmmgr_get_alarm_appsvc_info(alarm_id, &return_code);
1311 const char *pkgname = appsvc_get_pkgname(b);
1313 printf("Package name is %s\n",pkgname);
1322 void *alarmmgr_get_alarm_appsvc_info(alarm_id_t alarm_id, int *return_code);
1325 * This function gets the scheduled time of the alarm assosiated with alarm_id.
1327 * @param [in] alarm_id the id of the alarm
1328 * @param [out] duetime the scheduled time of the alarm
1330 * @return This function returns ALARMMGR_RESULT_SUCCESS on success or a negative number on failure.
1337 int alarmmgr_get_next_duetime(alarm_id_t alarm_id, time_t* duetime);
1340 * This function sets power RTC (which can power on the system).
1341 * @param [in] alarm_date_t time
1343 * @return This function returns the result. On success, ALARMMGR_RESULT_SUCCESS will be returned
1344 * else, appropriate error no will be returned.
1356 alarm_date_t alarm_date={2012,04,05,10,10,00};
1358 int main(int argc,char **argv {
1359 int return_code = 0;
1360 return_code = alarmmgr_set_rtc_time(&alarm_date);
1361 if (return_code != ALARMMGR_RESULT_SUCCESS){
1362 printf("Error returned is %d\n",return_code);
1369 int alarmmgr_set_rtc_time(alarm_date_t *time);
1372 * This function changes the system time which tranferred by other module
1373 * @param [in] new_time epoch time to be set
1375 * @return @c ALARMMGR_RESULT_SUCCESS on success,
1376 * otherwise a negative error value
1377 * @retval #ALARMMGR_RESULT_SUCCESS Successful
1378 * @retval #ERR_ALARM_SYSTEM_FAIL System failure
1380 int alarmmgr_set_systime(int new_time);
1383 * This function changes the system time and compensates the time using propagation delay.
1384 * @param [in] new_time system time to be set (seconds, nanoseconds)
1385 * @param [in] req_time time to request to change the system time (seconds, nanoseconds)
1387 * @return @c ALARMMGR_RESULT_SUCCESS on success,
1388 * otherwise a negative error value
1389 * @retval #ALARMMGR_RESULT_SUCCESS Successful
1390 * @retval #ERR_ALARM_SYSTEM_FAIL System failure
1391 * @retval #ERR_ALARM_INVALID_PARAM invalid parameter
1393 int alarmmgr_set_systime_with_propagation_delay(struct timespec new_time, struct timespec req_time);
1396 * This function changes the timezone which tranferred by other module
1397 * @param [in] tzpath_str the path to timezone definition file
1399 * @return @c ALARMMGR_RESULT_SUCCESS on success,
1400 * otherwise a negative error value
1401 * @retval #ALARMMGR_RESULT_SUCCESS Successful
1402 * @retval #ERR_ALARM_INVALID_PARAM Invalid parameter
1403 * @retval #ERR_ALARM_SYSTEM_FAIL System failure
1405 int alarmmgr_set_timezone(char *tzpath_str);
1408 int alarmmgr_add_alarm_withcb(int alarm_type, time_t trigger_at_time,
1409 time_t interval, alarm_cb_t handler, void *user_param, alarm_id_t *alarm_id);
1411 int alarmmgr_add_periodic_alarm_withcb(int interval, periodic_method_e method, alarm_cb_t handler,
1412 void *user_param, alarm_id_t *alarm_id);
1414 int alarmmgr_add_reference_periodic_alarm_withcb(int interval, alarm_cb_t handler,
1415 void *user_param, alarm_id_t *alarm_id);
1423 #endif/* ALARM_LIB_H*/