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>
160 * Type of an alarm id
162 typedef int alarm_id_t;
164 * The prototype of alarm handler.
165 * param [in] alarm_id the id of expired alarm
167 typedef int (*alarm_cb_t) (alarm_id_t alarm_id, void *user_param);
169 typedef int (*alarm_enum_fn_t) (alarm_id_t alarm_id, void *user_param);
172 * This enumeration has day of a week of alarm
175 ALARM_WDAY_SUNDAY = 0x01, /**< enalbe alarm on Sunday*/
176 ALARM_WDAY_MONDAY = 0x02, /**< enalbe alarm on Monday*/
177 ALARM_WDAY_TUESDAY = 0x04, /**< enable alarm on Tuesday*/
178 ALARM_WDAY_WEDNESDAY = 0x08, /**< enalbe alarm on Wednesday*/
179 ALARM_WDAY_THURSDAY = 0x10, /**< enable alarm on Thursday*/
180 ALARM_WDAY_FRIDAY = 0x20, /**< enable alarm on Friday*/
181 ALARM_WDAY_SATURDAY = 0x40,/**< enable alarm on Saturday*/
182 } alarm_day_of_week_t;
185 * This enumeration has error codes of alarm
188 ERR_ALARM_INVALID_PARAM = -10,
189 /**<Invalid parameter*/
190 ERR_ALARM_INVALID_ID, /**<Invalid id*/
191 ERR_ALARM_INVALID_REPEAT,
192 /**<Invalid repeat mode*/
193 ERR_ALARM_INVALID_TIME, /**<Invalid time. */
194 ERR_ALARM_INVALID_DATE, /**<Invalid date. */
195 ERR_ALARM_NO_SERVICE_NAME,
196 /**<there is no alarm service
197 for this applicaation. */
198 ERR_ALARM_INVALID_TYPE, /*Invalid type*/
199 ERR_ALARM_NO_PERMISSION, /*No permission*/
200 ERR_ALARM_SYSTEM_FAIL = -1,
201 ALARMMGR_RESULT_SUCCESS = 0,
205 * This enumeration has repeat mode of alarm
208 ALARM_REPEAT_MODE_ONCE = 0, /**<once : the alarm will be expired
210 ALARM_REPEAT_MODE_REPEAT, /**<repeat : the alarm will be expired
212 ALARM_REPEAT_MODE_WEEKLY, /**<weekly*/
213 ALARM_REPEAT_MODE_MONTHLY, /**< monthly*/
214 ALARM_REPEAT_MODE_ANNUALLY, /**< annually*/
215 ALARM_REPEAT_MODE_MAX,
216 } alarm_repeat_mode_t;
225 #define ALARM_TYPE_DEFAULT 0x0 /*< non volatile */
226 #define ALARM_TYPE_VOLATILE 0x02 /*< volatile */
227 #define ALARM_TYPE_NOLAUNCH 0x04 /*<without launch */
231 * This struct has date information
234 int year; /**< specifies the year */
235 int month; /**< specifies the month */
236 int day; /**< specifies the day */
237 int hour; /**< specifies the hour */
238 int min; /**< specifies the minute*/
239 int sec; /**< specifies the second*/
243 typedef struct alarm_info_t alarm_entry_t;
248 * This function initializes alarm library. It connects to system bus and registers the application's service name.
250 * @param [in] pkg_name a package of application
252 * @return On success, ALARMMGR_RESULT_SUCCESS is returned. On error, a negative number is returned
257 * @remark An application must call this function before using other alarm APIs.
264 int ret_val = ALARMMGR_RESULT_SUCCESS;
265 const char* pkg_name = "org.tizen.test";
269 ret_val =alarmmgr_init(pkg_name) ;
270 if(ret_val == ALARMMGR_RESULT_SUCCESS)
272 //alarmmgr_init() is successful
276 //alarmmgr_init () failed
282 int alarmmgr_init(const char *appid);
286 * This function de-initializes alarm library. It un-registers the application's service name and dis-connects from system bus.
292 * @pre Alarm manager is initialized
293 * @post Alarm manager is de-initialized
294 * @remark An application must call this function once it is done with alarmmanger usage
301 // Initialize alarmmanager
309 void alarmmgr_fini();
313 * This function registers handler which handles an alarm event. An application should register the alarm handler
314 * before it enters mainloop.
316 * @param [in] handler Callback function
317 * @param [in] user_param User Parameter
319 * @return This function returns ALARMMGR_RESULT_SUCCESS on success or a negative number on failure.
321 * @pre alarmmgr_init().
324 * @remark An application can have only one alarm handler. If an application
325 * calls this function more than one times, the handler regitered during the
326 * last call of this funiction will be called when an alarm event has occured.
332 // Call back function
333 int callback(alarm_id_t alarm_id,void* user_param)
338 printf("Alarm[%d] has expired at %s\n", alarm_id, ctime(¤t_time));
346 int ret_val = ALARMMGR_RESULT_SUCCESS;
347 void *user_param = NULL;
349 ret_val = alarmmgr_set_cb( callback, user_param);
350 if(ret_val == ALARMMGR_RESULT_SUCCESS)
352 //alarmmgr_set_cb() is successful
356 //alarmmgr_set_cb () failed
363 int alarmmgr_set_cb(alarm_cb_t handler, void *user_param);
367 * This function creates a new alarm entry, will not be known to the server until alarmmgr_add_alarm is called.
369 * @return This function returns the pointer of alarm_entry_t
374 * @remark After an application use this object, an application free this pointer through alarmmgr_free_alarm
382 alarm_entry_t* alarm;
384 alarm = alarmmgr_create_alarm() ;
387 //alarmmgr_create_alarm() is successful
391 //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
446 int alarmmgr_free_alarm(alarm_entry_t *alarm);
450 * This function sets time that alarm should be expried.
452 * @param [in] alarm alarm entry
453 * @param [in] time time the alarm should first go off
455 * @return This function returns ALARMMGR_RESULT_SUCCESS on success or a negative number on failure.
468 int ret_val = ALARMMGR_RESULT_SUCCESS;
469 alarm_entry_t* alarm;
471 struct tm current_tm;
472 alarm_date_t test_time;
476 localtime_r(¤t_time, ¤t_tm);
478 alarm = alarmmgr_create_alarm();
481 //alarmmgr_create_alarm () failed
484 test_time.year = current_tm.tm_year;
485 test_time.month = current_tm.tm_mon;
486 test_time.day = current_tm.tm_mday;
488 test_time.hour = current_tm.tm_hour;
489 test_time.min = current_tm.tm_min+1;
492 ret_val=alarmmgr_set_time(alarm,test_time);
493 if(ret_val == ALARMMGR_RESULT_SUCCESS)
495 //alarmmgr_set_time() is successful
499 //alarmmgr_set_time() failed
501 alarmmgr_free_alarm( alarm) ;
508 int alarmmgr_set_time(alarm_entry_t *alarm, alarm_date_t time);
511 * This function gives an application time that alarm should be expried.
513 * @param [in] alarm alarm entry
514 * @param [out] time time the alarm should first go off
516 * @return This function returns ALARMMGR_RESULT_SUCCESS on success or a negative number on failure.
521 * @remark But an application does not need to specify year, month, and day field of alarm_info. If an application sets
522 * those fields with zero, the function sets them with proper values.
530 int ret_val = ALARMMGR_RESULT_SUCCESS;
531 alarm_entry_t* alarm;
534 struct tm current_tm;
535 alarm_date_t test_time;
536 alarm_date_t new_time;
540 localtime_r(¤t_time, ¤t_tm);
542 alarm = alarmmgr_create_alarm();
544 //alarmmgr_create_alarm () failed
547 test_time.year = current_tm.tm_year;
548 test_time.month = current_tm.tm_mon;
549 test_time.day = current_tm.tm_mday;
551 test_time.hour = current_tm.tm_hour;
552 test_time.min = current_tm.tm_min+1;
555 ret_val = alarmmgr_set_time(alarm,test_time);
556 if(ret_val == ALARMMGR_RESULT_SUCCESS) {
557 //alarmmgr_set_time() is successful
560 //alarmmgr_set_time() failed
563 ret_val = alarmmgr_get_time(alarm, &new_time);
564 if(ret_val == ALARMMGR_RESULT_SUCCESS) {
565 //alarmmgr_get_time() is successful
568 //alarmmgr_get_time() failed
570 alarmmgr_free_alarm( alarm) ;
577 int alarmmgr_get_time(const alarm_entry_t *alarm, alarm_date_t *time);
580 * This function sets an alarm repeat mode
582 * @param [in] alarm alarm entry
583 * @param [in] repeat_mode one of ALARM_REPEAT_MODE_ONCE, ALARM_REPEAT_MODE_REPEAT,
584 * ALARM_REPEAT_MODE_WEEKLY, ALARM_REPEAT_MODE_MONTHLY or ALARM_REPEAT_MODE_ANNUALLY.
585 * @param [in] repeat_value the ALARM_REPEAT_MODE_REPEAT mode : interval between subsequent repeats of the alarm.
586 * the ALARM_REPEAT_MODE_WEEKLY mode : days of a week
587 * (ALARM_WDAY_SUNDAY, ALARM_WDAY_MONDAY, ALARM_WDAY_TUESDAY, ALARM_WDAY_WEDNESDAY,
588 * ALARM_WDAY_THURSDAY, ALARM_WDAY_FRIDAY, ALARM_WDAY_SATURDAY)
589 * the others : this parameter is ignored.
591 * @return This function returns ALARMMGR_RESULT_SUCCESS on success or a negative number on failure.
604 int ret_val = ALARMMGR_RESULT_SUCCESS;
605 alarm_entry_t* alarm;
606 alarm_repeat_mode_t repeat_mode =ALARM_REPEAT_MODE_WEEKLY;
607 int interval = ALARM_WDAY_MONDAY; //| ALARM_WDAY_TUESDAY|
608 ALARM_WDAY_WEDNESDAY| ALARM_WDAY_THURSDAY|ALARM_WDAY_FRIDAY ;
611 alarm = alarmmgr_create_alarm();
614 //alarmmgr_create_alarm () failed
618 ret_val = alarmmgr_set_repeat_mode
619 (alarm, repeat_mode,interval);
621 if(ret_val == ALARMMGR_RESULT_SUCCESS)
623 //alarmmgr_set_repeat_mode() is successful
627 //alarmmgr_set_repeat_mode() failed
629 alarmmgr_free_alarm( alarm) ;
636 int alarmmgr_set_repeat_mode(alarm_entry_t *alarm,
637 alarm_repeat_mode_t repeat_mode,
641 * This function gives an application an alarm mode
643 * @param [in] alarm alarm entry
644 * @param [out] repeat_mode one of ALARM_REPEAT_MODE_ONCE, ALARM_REPEAT_MODE_REPEAT,
645 * ALARM_REPEAT_MODE_WEEKLY, ALARM_REPEAT_MODE_MONTHLY or ALARM_REPEAT_MODE_ANNUALLY.
646 * @param [out] repeat_value the ALARM_REPEAT_MODE_REPEAT mode : interval between subsequent repeats of the alarm.
647 * the ALARM_REPEAT_MODE_WEEKLY mode : days of a week
648 * (ALARM_WDAY_SUNDAY, ALARM_WDAY_MONDAY, ALARM_WDAY_TUESDAY, ALARM_WDAY_WEDNESDAY,
649 * ALARM_WDAY_THURSDAY, ALARM_WDAY_FRIDAY, ALARM_WDAY_SATURDAY)
650 * the others : this parameter is ignored.
652 * @return This function returns ALARMMGR_RESULT_SUCCESS on success or a negative number on failure.
665 int ret_val = ALARMMGR_RESULT_SUCCESS;
666 alarm_entry_t* alarm;
667 alarm_repeat_mode_t repeat;
670 alarm = alarmmgr_create_alarm();
673 //alarmmgr_create_alarm () failed
676 ret_val =alarmmgr_get_repeat_mode
677 (alarm, &repeat, &interval) ;
678 if(ret_val == ALARMMGR_RESULT_SUCCESS
679 && repeat == ALARM_REPEAT_MODE_ONCE) {
680 //alarmmgr_get_repeat_mode() is successful
683 //alarmmgr_get_repeat_mode() failed
685 alarmmgr_free_alarm(alarm) ;
692 int alarmmgr_get_repeat_mode(const alarm_entry_t *alarm,
693 alarm_repeat_mode_t *repeat_mode,
697 * This function sets an alarm mode
699 * @param [in] alarm alarm entry
700 * @param [in] alarm_type one of ALARM_TYPE_DEFAULT : After the device reboot, the alarm still works.
701 * ALARM_TYPE_VOLATILE : After the device reboot, the alarm does not work.
703 * @return This function returns ALARMMGR_RESULT_SUCCESS on success or a negative number on failure.
716 int ret_val = ALARMMGR_RESULT_SUCCESS;
717 alarm_entry_t* alarm;
718 int alarm_type = ALARM_TYPE_VOLATILE;
720 alarm = alarmmgr_create_alarm();
723 //alarmmgr_create_alarm () failed
727 ret_val = alarmmgr_set_type(alarm, alarm_type);
728 if(ret_val == ALARMMGR_RESULT_SUCCESS)
730 //alarmmgr_set_type() is successful
734 //alarmmgr_set_type() failed
736 alarmmgr_free_alarm( alarm) ;
743 int alarmmgr_set_type(alarm_entry_t *alarm, int alarm_type);
746 * This function gives an application an alarm mode
748 * @param [in] alarm alarm entry
749 * @param [out] alarm_type one of ALARM_TYPE_DEFAULT, ALARM_TYPE_VOLATILE
751 * @return This function returns ALARMMGR_RESULT_SUCCESS on success or a negative number on failure.
764 int ret_val = ALARMMGR_RESULT_SUCCESS;
765 alarm_entry_t* alarm;
768 alarm = alarmmgr_create_alarm();
770 //alarmmgr_create_alarm () failed
773 ret_val = alarmmgr_get_type( alarm, &alarm_type);
774 if(ret_val == ALARMMGR_RESULT_SUCCESS && alarm_type
775 == ALARM_TYPE_DEFAULT ) {
776 //alarmmgr_get_type() is successful
779 //alarmmgr_get_type() failed
781 alarmmgr_free_alarm( alarm) ;
788 int alarmmgr_get_type(const alarm_entry_t *alarm, int *alarm_type);
791 * This function adds an alarm entry to the server.
792 * Server will remember this entry, and generate alarm events for it when necessary.
793 * Server will call app-svc interface to sent notification to destination application. Destination information
794 * should be available in the input bundle.
795 * Alarm entries registered with the server cannot be changed.
796 * Remove from server before changing.
797 * Before the application calls alarmmgr_add_alarm_appsvc_with_localtime(), the application have to call alarmmgr_set_time().
798 * The time set is localtime.
799 * If the application does not call alarmmgr_set_repeat_mode, the default repeat_mode is ALARM_REPEAT_MODE_ONCE.
800 * If the application does not call alarmmgr_set_type, the default alarm_type is ALARM_TYPE_DEFAULT.
801 * The id of the new alarm will be copied to alarm_id if the fuction successes to create an alarm.
803 * @param [in] alarm the entry of an alarm to be created.
804 * @param [in] bundle_data bundle which contains information about the destination.
805 * @param [out] alarm_id the id of the alarm added.
807 * @return This function returns ALARMMGR_RESULT_SUCCESS on success or a negative number on failure.
811 * @see alarmmgr_add_alarm
821 struct tm current_tm;
822 alarm_entry_t* alarm_info;
825 alarm_date_t test_time;
834 printf("Unable to create bundle!!!\n");
838 appsvc_set_operation(b,APPSVC_OPERATION_DEFAULT);
839 appsvc_set_pkgname(b,"org.tizen.alarm-test");
843 printf("current time: %s\n", ctime(¤t_time));
844 localtime_r(¤t_time, ¤t_tm);
846 alarm_info = alarmmgr_create_alarm();
848 test_time.year = current_tm.tm_year;
849 test_time.month = current_tm.tm_mon;
850 test_time.day = current_tm.tm_mday;
852 test_time.hour = current_tm.tm_hour;
853 test_time.min = current_tm.tm_min+1;
857 alarmmgr_set_time(alarm_info,test_time);
858 alarmmgr_set_repeat_mode(alarm_info,ALARM_REPEAT_MODE_WEEKLY,ALARM_WDAY_MONDAY| \
859 ALARM_WDAY_TUESDAY|ALARM_WDAY_WEDNESDAY| \
860 ALARM_WDAY_THURSDAY|ALARM_WDAY_FRIDAY );
862 alarmmgr_set_type(alarm_info, ALARM_TYPE_DEFAULT);
863 //alarmmgr_set_type(alarm_info,ALARM_TYPE_VOLATILE);
864 if ((result = alarmmgr_add_alarm_appsvc_with_localtime(alarm_info,(void *)b,&alarm_id)) < 0)
866 printf("Alarm creation failed!!! Alrmgr error code is %d\n",result);
870 printf("Alarm created succesfully with alarm id %d\n",alarm_id);
877 int alarmmgr_add_alarm_appsvc_with_localtime(alarm_entry_t *alarm,void *bundle_data, alarm_id_t *alarm_id);
880 * This function adds an alarm entry to the server.
881 * Server will remember this entry, and generate alarm events for it when necessary.
882 * Alarm entries registered with the server cannot be changed.
883 * Remove from server before changing.
884 * Before the application calls alarmmgr_add_alarm_with_localtime(), the application have to call alarmmgr_set_time().
885 * The time set is localtime.
886 * If the application does not call alarmmgr_set_repeat_mode, the default repeat_mode is ALARM_REPEAT_MODE_ONCE.
887 * If the application does not call alarmmgr_set_type, the default alarm_type is ALARM_TYPE_DEFAULT.
888 * The id of the new alarm will be copied to alarm_id if the fuction successes to create an alarm.
890 * @param [in] alarm the entry of an alarm to be created.
891 * @param [in] destination the packname of application that the alarm will be expired.
892 * @param [out] alarm_id the id of the alarm added.
894 * @return This function returns ALARMMGR_RESULT_SUCCESS on success or a negative number on failure.
898 * @see alarmmgr_add_alarm
907 int ret_val = ALARMMGR_RESULT_SUCCESS;
908 alarm_entry_t* alarm;
909 const char* destination = NULL;
913 struct tm current_tm;
914 alarm_date_t test_time;
916 const char* pkg_name = "org.tizen.test";
920 ret_val =alarmmgr_init(pkg_name) ;
921 if(ret_val != ALARMMGR_RESULT_SUCCESS) {
922 //alarmmgr_init () failed
928 printf("current time: %s\n", ctime(¤t_time));
929 localtime_r(¤t_time, ¤t_tm);
931 alarm = alarmmgr_create_alarm();
934 test_time.month = 0;test_time.day = 0;
936 test_time.hour = current_tm.tm_hour;
937 test_time.min = current_tm.tm_min+1;
941 alarmmgr_set_time(alarm,test_time);
942 alarmmgr_set_repeat_mode(alarm,ALARM_REPEAT_MODE_WEEKLY, \
944 alarmmgr_set_type(alarm,ALARM_TYPE_VOLATILE);
947 ret_val=alarmmgr_add_alarm_with_localtime(alarm,destination,&alarm_id);
949 if(ret_val == ALARMMGR_RESULT_SUCCESS)
951 //alarmmgr_add_alarm_with_localtime() is successful
955 //alarmmgr_add_alarm_with_localtime() failed
957 alarmmgr_free_alarm( alarm) ;
962 int alarmmgr_add_alarm_with_localtime(alarm_entry_t *alarm,
963 const char *destination,
964 alarm_id_t *alarm_id);
968 * This function adds an alarm entry to the server.
969 * Server will remember this entry, and generate alarm events for it when necessary.
970 * Server will call app-svc interface to sent notification to destination application. Destination information
971 * should be available in the input bundle.
972 * Alarm entries registered with the server cannot be changed.
973 * Remove from server before changing.
974 * After the trigger_at_time seconds from now, the alarm will be expired.
975 * If the interval is zero, the repeat_mode is ALARM_REPEAT_MODE_ONCE.
976 * If the interval is >0, the repeat_mode is ALARM_REPEAT_MODE_REPEAT.
977 * The id of the new alarm will be copied to alarm_id if the fuction successes to create an alarm.
979 * @param [in] alarm_type one of ALARM_TYPE_DEFAULT, ALARM_TYPE_VOLATILE
980 * @param [in] trigger_at_time time interval to be triggered from now(sec). an alarm also will be expired at triggering time.
981 * @param [in] interval Interval between subsequent repeats of the alarm
982 * @param [in] bundle_data bundle which contains information about the destination.
983 * @param [out] alarm_id the id of the alarm added.
985 * @return This function returns ALARMMGR_RESULT_SUCCESS on success or a negative number on failure.
989 * @see alarmmgr_add_alarm_with_localtime alarmmgr_remove_alarm
1007 printf("Unable to create bundle!!!\n");
1011 appsvc_set_pkgname(b,"org.tizen.alarm-test");
1012 //appsvc_set_operation(b,APPSVC_OPERATION_SEND_TEXT);
1013 appsvc_set_operation(b,APPSVC_OPERATION_DEFAULT);
1015 if ((result = alarmmgr_add_alarm_appsvc(ALARM_TYPE_DEFAULT, 10, 0, (void *)b ,&alarm_id)))
1016 printf("Unable to add alarm. Alarmmgr alarm no is %d\n", result);
1018 printf("Alarm added successfully. Alarm Id is %d\n", alarm_id);
1026 int alarmmgr_add_alarm_appsvc(int alarm_type, time_t trigger_at_time,
1027 time_t interval, void *bundle_data,
1028 alarm_id_t *alarm_id);
1032 * This function adds an alarm entry to the server.
1033 * Server will remember this entry, and generate alarm events for it when necessary.
1034 * Alarm entries registered with the server cannot be changed.
1035 * Remove from server before changing.
1036 * After the trigger_at_time seconds from now, the alarm will be expired.
1037 * If the interval is zero, the repeat_mode is ALARM_REPEAT_MODE_ONCE.
1038 * If the interval is >0, the repeat_mode is ALARM_REPEAT_MODE_REPEAT.
1039 * The id of the new alarm will be copied to alarm_id if the fuction successes to create an alarm.
1041 * @param [in] alarm_type one of ALARM_TYPE_DEFAULT, ALARM_TYPE_VOLATILE
1042 * @param [in] trigger_at_time time interval to be triggered from now(sec). an alarm also will be expired at triggering time.
1043 * @param [in] interval Interval between subsequent repeats of the alarm
1044 * @param [in] destination the packname of application that the alarm will be expired.
1045 * @param [out] alarm_id the id of the alarm added.
1047 * @return This function returns ALARMMGR_RESULT_SUCCESS on success or a negative number on failure.
1051 * @see alarmmgr_add_alarm_with_localtime alarmmgr_remove_alarm
1060 int ret_val = ALARMMGR_RESULT_SUCCESS;
1062 int alarm_type = ALARM_TYPE_VOLATILE;
1063 time_t trigger_at_time = 10;
1064 time_t interval = 10;
1065 const char* destination = NULL;
1066 alarm_id_t alarm_id;
1068 const char* pkg_name = "org.tizen.test";
1072 ret_val =alarmmgr_init(pkg_name) ;
1073 if(ret_val != ALARMMGR_RESULT_SUCCESS)
1075 //alarmmgr_init () failed
1079 ret_val = alarmmgr_add_alarm( alarm_type, trigger_at_time, interval,
1080 destination, &alarm_id);
1081 if(ret_val == ALARMMGR_RESULT_SUCCESS)
1083 //alarmmgr_add_alarm() is successful
1087 //alarmmgr_add_alarm() failed
1089 alarmmgr_remove_alarm( alarm_id) ;
1095 int alarmmgr_add_alarm(int alarm_type, time_t trigger_at_time,
1096 time_t interval, const char *destination,
1097 alarm_id_t *alarm_id);
1100 * This function deletes the alarm associated with the given alarm_id.
1102 * @param [in] alarm_id Specifies the ID of the alarm to be deleted.
1104 * @return This function returns ALARMMGR_RESULT_SUCCESS on success or a negative number on failure.
1108 * @see alarmmgr_add_alarm_with_localtime alarmmgr_add_alarm
1117 int ret_val = ALARMMGR_RESULT_SUCCESS;
1118 int alarm_type = ALARM_TYPE_VOLATILE;
1119 time_t trigger_at_time = 10;
1120 time_t interval = 10;
1121 const char* destination = NULL;
1122 alarm_id_t alarm_id;
1124 const char* pkg_name = "org.tizen.test";
1128 ret_val =alarmmgr_init(pkg_name) ;
1129 if(ret_val != ALARMMGR_RESULT_SUCCESS) {
1130 //alarmmgr_init () failed
1134 alarmmgr_add_alarm( alarm_type, trigger_at_time, interval,
1135 destination, &alarm_id);
1137 ret_val =alarmmgr_remove_alarm( alarm_id) ;
1138 if(ret_val == ALARMMGR_RESULT_SUCCESS) {
1139 /alarmmgr_remove_alarm() is successful
1142 //alarmmgr_remove_alarm() failed
1149 int alarmmgr_remove_alarm(alarm_id_t alarm_id);
1152 * This function deletes all registered alarms
1154 * @return This function returns ALARMMGR_RESULT_SUCCESS on success or a negative number on failure.
1156 int alarmmgr_remove_all(void);
1159 * This function gives a list of alarm ids that the application adds to the server.
1161 * @param [in] fn a user callback function
1162 * @param [in] user_param user parameter
1164 * @return This function returns ALARMMGR_RESULT_SUCCESS on success or a negative number on failure.
1168 * @see alarm_get_info
1175 int callback_2(alarm_id_t id, void* user_param)
1177 int* n = (int*)user_param;
1178 printf("[%d]alarm id : %d\n",*n,id);
1185 int ret_val = ALARMMGR_RESULT_SUCCESS;
1188 const char* pkg_name = "org.tizen.test";
1192 ret_val =alarmmgr_init(pkg_name) ;
1193 if(ret_val != ALARMMGR_RESULT_SUCCESS)
1195 //alarmmgr_init() failed
1199 ret_val = alarmmgr_enum_alarm_ids( callback_2, (void*)&n) ;
1200 if(ret_val == ALARMMGR_RESULT_SUCCESS)
1202 //alarmmgr_enum_alarm_ids() is successful
1206 //alarmmgr_enum_alarm_ids() failed
1213 int alarmmgr_enum_alarm_ids(alarm_enum_fn_t fn, void *user_param);
1217 * This function gets the information of the alarm assosiated with alarm_id to alarm_info. The application
1218 * must allocate alarm_info before calling this function.
1220 * @param [in] alarm_id the id of the alarm
1221 * @param [out] alarm the buffer alarm informaiton will be copied to
1223 * @return This function returns ALARMMGR_RESULT_SUCCESS on success or a negative number on failure.
1227 * @see alarmmgr_enum_alarm_ids
1236 int ret_val = ALARMMGR_RESULT_SUCCESS;
1237 int alarm_type = ALARM_TYPE_VOLATILE;
1238 time_t trigger_at_time = 10;
1239 time_t interval = ALARM_WDAY_SUNDAY;
1240 const char* destination = NULL;
1241 alarm_id_t alarm_id;
1243 alarm_entry_t *alarm;
1245 const char* pkg_name = "org.tizen.test_get_info1";
1249 ret_val =alarmmgr_init(pkg_name) ;
1250 if(ret_val != ALARMMGR_RESULT_SUCCESS) {
1251 //alarmmgr_init() failed
1254 ret_val = alarmmgr_add_alarm( alarm_type,trigger_at_time,interval,
1255 destination, &alarm_id);
1257 if(ret_val != ALARMMGR_RESULT_SUCCESS) {
1258 //alarmmgr_add_alarm() failed
1261 ret_val = alarmmgr_get_info(alarm_id, alarm);
1262 if(ret_val == ALARMMGR_RESULT_SUCCESS) {
1263 //alarmmgr_get_info() is successful
1266 //alarmmgr_get_info() failed
1268 alarmmgr_remove_alarm( alarm_id) ;
1273 int alarmmgr_get_info(alarm_id_t alarm_id, alarm_entry_t *alarm);
1277 * This function retrieves bundle associated with alarm.
1278 * Server will remember this entry, and pass the bundle information upon alarm expiry.
1279 * Server will call app-svc interface to sent notification to destination application. Destination information
1280 * should be available in the input bundle.
1281 * @param [in] alarm_id alarm id
1282 * @param [out] ALARMMGR_RESULT_SUCCESS on success or negative number on failure.
1284 * @return This function returns bundle on success or NULL on failure.
1297 alarm_id_t alarm_id;
1306 printf("Unable to create bundle!!!\n");
1310 appsvc_set_pkgname(b,"org.tizen.alarm-test");
1311 appsvc_set_operation(b,APPSVC_OPERATION_DEFAULT);
1313 if ((result = alarmmgr_add_alarm_appsvc(ALARM_TYPE_DEFAULT, 10, 0, (void *)b ,&alarm_id)))
1314 printf("Unable to add alarm. Alarmmgr alarm no is %d\n", result);
1316 printf("Alarm added successfully. Alarm Id is %d\n", alarm_id);
1318 int main(int argc,char **argv {
1321 int return_code = 0;
1323 b = alarmmgr_get_alarm_appsvc_info(alarm_id, &return_code);
1325 const char *pkgname = appsvc_get_pkgname(b);
1327 printf("Package name is %s\n",pkgname);
1337 void *alarmmgr_get_alarm_appsvc_info(alarm_id_t alarm_id, int *return_code);
1340 * This function gets the scheduled time of the alarm assosiated with alarm_id.
1342 * @param [in] alarm_id the id of the alarm
1343 * @param [out] duetime the scheduled time of the alarm
1345 * @return This function returns ALARMMGR_RESULT_SUCCESS on success or a negative number on failure.
1352 int alarmmgr_get_next_duetime(alarm_id_t alarm_id, time_t* duetime);
1355 * This function sets power RTC (which can power on the system).
1356 * @param [in] alarm_date_t time
1358 * @return This function returns the result. On success, ALARMMGR_RESULT_SUCCESS will be returned
1359 * else, appropriate error no will be returned.
1371 alarm_date_t alarm_date={2012,04,05,10,10,00};
1373 int main(int argc,char **argv {
1374 int return_code = 0;
1375 return_code = alarmmgr_set_rtc_time(&alarm_date);
1376 if (return_code != ALARMMGR_RESULT_SUCCESS){
1377 printf("Error returned is %d\n",return_code);
1385 int alarmmgr_set_rtc_time(alarm_date_t *time);
1388 * This function changes the system time which tranferred by other module
1389 * @param [in] new_time epoch time to be set
1391 * @return @c ALARMMGR_RESULT_SUCCESS on success,
1392 * otherwise a negative error value
1393 * @retval #ALARMMGR_RESULT_SUCCESS Successful
1394 * @retval #ERR_ALARM_SYSTEM_FAIL System failure
1396 int alarmmgr_set_systime(int new_time);
1399 * This function changes the timezone which tranferred by other module
1400 * @param [in] tzpath_str the path to timezone definition file
1402 * @return @c ALARMMGR_RESULT_SUCCESS on success,
1403 * otherwise a negative error value
1404 * @retval #ALARMMGR_RESULT_SUCCESS Successful
1405 * @retval #ERR_ALARM_INVALID_PARAM Invalid parameter
1406 * @retval #ERR_ALARM_SYSTEM_FAIL System failure
1408 int alarmmgr_set_timezone(char *tzpath_str);
1411 int alarmmgr_add_alarm_withcb(int alarm_type, time_t trigger_at_time,
1412 time_t interval, alarm_cb_t handler, void *user_param, alarm_id_t *alarm_id);
1414 int alarmmgr_add_periodic_alarm_withcb(int interval, periodic_method_e method, alarm_cb_t handler,
1415 void *user_param, alarm_id_t *alarm_id);
1417 int alarmmgr_add_reference_periodic_alarm_withcb(int interval, alarm_cb_t handler,
1418 void *user_param, alarm_id_t *alarm_id);
1426 #endif/* ALARM_LIB_H*/