add alarmmgr_get_next_duetime api
[framework/appfw/alarm-manager.git] / include / alarm.h
1 /*
2  *  alarm-manager
3  *
4  * Copyright (c) 2000 - 2011 Samsung Electronics Co., Ltd. All rights reserved.
5  *
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>
8  *
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
12  *
13  * http://www.apache.org/licenses/LICENSE-2.0
14  *
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.
20  *
21  */
22
23
24
25
26 #ifndef ALARM_LIB_H
27 #define ALARM_LIB_H
28
29 /**
30  * @open
31  * @addtogroup APPLICATION_FRAMEWORK
32  * @{
33  *
34  * @defgroup Alarm Alarm
35  * @version 0.4.2
36  *
37  *
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:
41  *
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  *
58  *
59  * 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.
60  *
61  *
62  * @code
63 #include<stdio.h>
64 #include<stdlib.h>
65 #include<glib.h>
66
67 #include "alarm.h"
68
69 int callback(alarm_id_t alarm_id, void *user_param)
70 {
71         int error;
72         time_t current_time;
73         time(&current_time);
74
75         printf("Alarm[%d] has expired at %s\n", alarm_id, ctime(&current_time));
76         return 0;
77 }
78
79 void create_test()
80 {
81         time_t current_time;
82         struct tm current_tm;
83         alarm_entry_t* alarm_info;
84         alarm_id_t alarm_id;
85         int result;
86         alarm_date_t test_time;
87
88         time(&current_time);
89
90         printf("current time: %s\n", ctime(&current_time));
91         localtime_r(&current_time, &current_tm);
92
93         alarm_info = alarmmgr_create_alarm();
94
95         test_time.year = current_tm.tm_year+1900;
96         test_time.month = current_tm.tm_mon+1;
97         test_time.day = current_tm.tm_mday;
98         test_time.hour = current_tm.tm_hour;
99         test_time.min = current_tm.tm_min+1;
100         test_time.sec = 0;
101
102         alarmmgr_set_time(alarm_info,test_time);
103         alarmmgr_set_repeat_mode(alarm_info,ALARM_REPEAT_MODE_WEEKLY,
104         ALARM_WDAY_MONDAY| \
105         ALARM_WDAY_TUESDAY|ALARM_WDAY_WEDNESDAY| \
106         ALARM_WDAY_THURSDAY|ALARM_WDAY_FRIDAY );
107
108         alarmmgr_set_type(alarm_info,ALARM_TYPE_VOLATILE);
109         alarmmgr_add_alarm_with_localtime(alarm_info,NULL,&alarm_id);
110
111         if(result != ALARMMGR_RESULT_SUCCESS)
112                 printf("fail to alarmmgr_create : error_code : %d\n",result);
113
114 }
115
116 int main(int argc, char** argv)
117 {
118         int error_code;
119         GMainLoop *mainloop;
120         int result;
121         g_type_init();
122
123         mainloop = g_main_loop_new(NULL, FALSE);
124         result = alarmmgr_init("org.tizen.test");
125
126         if(result != ALARMMGR_RESULT_SUCCESS) {
127                 printf("fail to alarmmgr_init : error_code : %d\n",result);
128         }
129         else {
130                 result = alarmmgr_set_cb(callback,NULL);
131                 if(result != ALARMMGR_RESULT_SUCCESS) {
132                         printf("fail to alarmmgr_set_cb : error_code :
133                                                         %d\n",result);
134                 }
135                 else {
136                         create_test();
137                 }
138         }
139         g_main_loop_run(mainloop);
140 }
141
142 * @endcode
143 *
144 */
145
146 /**
147  * @addtogroup Alarm
148  * @{
149  */
150
151 #include<sys/types.h>
152 #include<stdbool.h>
153
154 #ifdef __cplusplus
155 extern "C" {
156 #endif
157
158 /**
159 * Type of an alarm id
160 */
161 typedef int alarm_id_t;
162 /**
163 * The prototype of alarm handler.
164 * param [in]    alarm_id the id of expired alarm
165 */
166 typedef int (*alarm_cb_t) (alarm_id_t alarm_id, void *user_param);
167
168 typedef int (*alarm_enum_fn_t) (alarm_id_t alarm_id, void *user_param);
169
170 /**
171 * This enumeration has day of a week of alarm
172 */
173 typedef enum {
174         ALARM_WDAY_SUNDAY = 0x01, /**< enalbe alarm on Sunday*/
175         ALARM_WDAY_MONDAY = 0x02, /**< enalbe alarm on Monday*/
176         ALARM_WDAY_TUESDAY = 0x04, /**< enable alarm on Tuesday*/
177         ALARM_WDAY_WEDNESDAY = 0x08, /**< enalbe alarm on Wednesday*/
178         ALARM_WDAY_THURSDAY = 0x10, /**< enable alarm on Thursday*/
179         ALARM_WDAY_FRIDAY = 0x20,  /**< enable alarm on Friday*/
180         ALARM_WDAY_SATURDAY = 0x40,/**< enable alarm on Saturday*/
181 } alarm_day_of_week_t;
182
183 /**
184 * This enumeration has error codes of alarm
185 */
186         typedef enum {
187                 ERR_ALARM_INVALID_PARAM = -10,
188                                      /**<Invalid parameter*/
189                 ERR_ALARM_INVALID_ID,   /**<Invalid id*/
190                 ERR_ALARM_INVALID_REPEAT,
191                                         /**<Invalid repeat mode*/
192                 ERR_ALARM_INVALID_TIME, /**<Invalid time. */
193                 ERR_ALARM_INVALID_DATE, /**<Invalid date. */
194                 ERR_ALARM_NO_SERVICE_NAME,
195                                     /**<there is no alarm service
196                                         for this applicaation. */
197                 ERR_ALARM_INVALID_TYPE,  /*Invalid type*/
198                 ERR_ALARM_NO_PERMISSION, /*No permission*/
199                 ERR_ALARM_SYSTEM_FAIL = -1,
200                 ALARMMGR_RESULT_SUCCESS = 0,
201         } alarm_error_t;
202
203 /**
204 *  This enumeration has repeat mode of alarm
205 */
206 typedef enum {
207         ALARM_REPEAT_MODE_ONCE = 0,     /**<once : the alarm will be expired
208                                         only one time. */
209         ALARM_REPEAT_MODE_REPEAT,       /**<repeat : the alarm will be expired
210                                         repeatly*/
211         ALARM_REPEAT_MODE_WEEKLY,       /**<weekly*/
212         ALARM_REPEAT_MODE_MONTHLY,      /**< monthly*/
213         ALARM_REPEAT_MODE_ANNUALLY,     /**< annually*/
214         ALARM_REPEAT_MODE_MAX,
215 } alarm_repeat_mode_t;
216
217
218 #define ALARM_TYPE_DEFAULT      0x0     /*< non volatile */
219 #define ALARM_TYPE_VOLATILE     0x02    /*< volatile */
220 #define ALARM_TYPE_NOLAUNCH 0x04        /*<without launch */
221
222
223 /**
224 * This struct has date information
225 */
226 typedef struct {
227         int year;               /**< specifies the year */
228         int month;              /**< specifies the month */
229         int day;                /**< specifies the day */
230         int hour;               /**< specifies the hour */
231         int min;                /**< specifies the minute*/
232         int sec;                /**< specifies the second*/
233 } alarm_date_t;
234
235
236 typedef struct alarm_info_t alarm_entry_t;
237
238
239 /**
240  *
241  * This function initializes alarm library. It connects to system bus and registers the application's service name.
242  *
243  * @param       [in]    pkg_name        a package of application
244  *
245  * @return On success, ALARMMGR_RESULT_SUCCESS is returned. On error, a negative number is returned
246  *
247  * @pre None.
248  * @post None.
249  * @see None.
250  * @remark An application must call this function before using other alarm APIs.
251  * @par Sample code:
252  * @code
253 #include <alarm.h>
254
255 ...
256 {
257         int ret_val = ALARMMGR_RESULT_SUCCESS;
258         const char* pkg_name = "org.tizen.test";
259
260         g_type_init();
261
262         ret_val =alarmmgr_init(pkg_name) ;
263         if(ret_val == ALARMMGR_RESULT_SUCCESS)
264         {
265                  //alarmmgr_init() is successful
266         }
267         else
268         {
269                  //alarmmgr_init () failed
270         }
271 }
272  * @endcode
273  * @limo
274  */
275 int alarmmgr_init(const char *appid);
276
277 /**
278  *
279  * This function de-initializes alarm library. It un-registers the application's service name and dis-connects from system bus.
280  *
281  * @param       None
282  *
283  * @return      None
284  *
285  * @pre         Alarm manager is initialized
286  * @post        Alarm manager is de-initialized
287  * @remark An application must call this function once it is done with alarmmanger usage
288  * @par Sample code:
289  * @code
290 #include <alarm.h>
291
292 ...
293 {
294         // Initialize alarmmanager
295         // Set alarm
296
297         alarmmgr_fini() ;
298 }
299  * @endcode
300  */
301
302 void alarmmgr_fini();
303
304
305 /**
306  * This function registers handler which handles an alarm event. An application should register the alarm handler
307  * before it enters mainloop.
308  *
309  * @param       [in]    handler Callback function
310  * @param       [in]    user_param      User Parameter
311  *
312  * @return      This function returns ALARMMGR_RESULT_SUCCESS on success or a negative number on failure.
313  *
314  * @pre alarmmgr_init().
315  * @post None.
316  * @see None.
317  * @remark      An application can have only one alarm handler. If an application
318  *          calls this function more than one times, the handler regitered during  the
319  *          last call of this funiction will be called when an alarm event has occured.
320  * @par Sample code:
321  * @code
322 #include <alarm.h>
323 ...
324
325 // Call back function
326 int callback(alarm_id_t alarm_id,void* user_param)
327 {
328         time_t current_time;
329         time(&current_time);
330
331         printf("Alarm[%d] has expired at %s\n", alarm_id, ctime(&current_time));
332
333         return 0;
334
335 }
336
337 ...
338 {
339         int ret_val = ALARMMGR_RESULT_SUCCESS;
340         void *user_param = NULL;
341
342         ret_val = alarmmgr_set_cb( callback, user_param);
343         if(ret_val == ALARMMGR_RESULT_SUCCESS)
344         {
345                 //alarmmgr_set_cb() is successful
346         }
347         else
348         {
349                  //alarmmgr_set_cb () failed
350         }
351 }
352
353  * @endcode
354  * @limo
355  */
356 int alarmmgr_set_cb(alarm_cb_t handler, void *user_param);
357
358
359 /**
360  * This function creates a new alarm entry, will not be known to the server until alarmmgr_add_alarm is called.
361  *
362  * @return      This function returns the pointer of alarm_entry_t
363  *
364  * @pre None.
365  * @post None.
366  * @see None.
367  * @remark      After an application use this object, an application free this pointer through alarmmgr_free_alarm
368  *
369  * @par Sample code:
370  * @code
371 #include <alarm.h>
372
373 ...
374 {
375         alarm_entry_t* alarm;
376
377         alarm = alarmmgr_create_alarm() ;
378         if(alarm != NULL)
379         {
380                  //alarmmgr_create_alarm() is successful
381         }
382         else
383         {
384                  //alarmmgr_create_alarm () failed
385         }
386 }
387
388
389  * @endcode
390  * @limo
391  */
392 alarm_entry_t *alarmmgr_create_alarm(void);
393
394
395 /**
396  * This function frees an alarm entry.
397  *
398  * @param       [in]    alarm   alarm entry
399  *
400  * @return      This function returns ALARMMGR_RESULT_SUCCESS on success or a negative number on failure.
401  *
402  * @pre None.
403  * @post None.
404  * @see None.
405  * @remark      None.
406  *
407  * @par Sample code:
408  * @code
409 #include <alarm.h>
410
411 ...
412  {
413          int ret_val = ALARMMGR_RESULT_SUCCESS;
414          alarm_entry_t* alarm;
415
416          alarm = alarmmgr_create_alarm() ;
417          if(alarm == NULL)
418          {
419                   //alarmmgr_create_alarm () failed
420          }
421          else
422                  {
423
424                          ret_val = alarmmgr_free_alarm( alarm) ;
425                          if(ret_val == ALARMMGR_RESULT_SUCCESS)
426                          {
427                                   //alarmmgr_free_alarm() is successful
428                          }
429                          else
430                          {
431                                  //alarmmgr_free_alarm() failed
432                          }
433                  }
434  }
435
436  * @endcode
437  * @limo
438  */
439 int alarmmgr_free_alarm(alarm_entry_t *alarm);
440
441
442 /**
443  * This function sets time that alarm should be expried.
444  *
445  * @param       [in]    alarm   alarm entry
446  * @param       [in]    time            time the alarm should first go off
447  *
448  * @return      This function returns ALARMMGR_RESULT_SUCCESS on success or a negative number on failure.
449  *
450  * @pre None.
451  * @post None.
452  * @see None.
453  * @remark  None.
454  *
455  * @par Sample code:
456  * @code
457 #include <alarm.h>
458
459  ...
460   {
461           int ret_val = ALARMMGR_RESULT_SUCCESS;
462           alarm_entry_t* alarm;
463           time_t current_time;
464           struct tm current_tm;
465           alarm_date_t test_time;
466
467
468          time(&current_time);
469          localtime_r(&current_time, &current_tm);
470
471          alarm = alarmmgr_create_alarm();
472           if(alarm == NULL)
473           {
474                    //alarmmgr_create_alarm () failed
475           }
476           else {
477                 test_time.year = current_tm.tm_year;
478                 test_time.month = current_tm.tm_mon;
479                 test_time.day = current_tm.tm_mday;
480
481                 test_time.hour = current_tm.tm_hour;
482                 test_time.min = current_tm.tm_min+1;
483                 test_time.sec = 0;
484
485                 ret_val=alarmmgr_set_time(alarm,test_time);
486                 if(ret_val == ALARMMGR_RESULT_SUCCESS)
487                 {
488                         //alarmmgr_set_time() is successful
489                 }
490                 else
491                 {
492                         //alarmmgr_set_time() failed
493                 }
494                           alarmmgr_free_alarm( alarm) ;
495           }
496  }
497
498  * @endcode
499  * @limo
500  */
501 int alarmmgr_set_time(alarm_entry_t *alarm, alarm_date_t time);
502
503 /**
504  * This function gives an application time that alarm should be expried.
505  *
506  * @param       [in]            alarm   alarm entry
507  * @param       [out]   time            time the alarm should first go off
508  *
509  * @return      This function returns ALARMMGR_RESULT_SUCCESS on success or a negative number on failure.
510  *
511  * @pre None.
512  * @post None.
513  * @see None.
514  * @remark      But an application does not need to specify year, month, and day field of alarm_info. If an application sets
515  *                      those fields with zero, the function sets them with proper values.
516  *
517  * @par Sample code:
518  * @code
519 #include <alarm.h>
520
521  ...
522  {
523          int ret_val = ALARMMGR_RESULT_SUCCESS;
524          alarm_entry_t* alarm;
525
526          time_t current_time;
527                 struct tm current_tm;
528          alarm_date_t test_time;
529          alarm_date_t new_time;
530
531
532                 time(&current_time);
533                 localtime_r(&current_time, &current_tm);
534
535                 alarm = alarmmgr_create_alarm();
536          if(alarm == NULL) {
537                   //alarmmgr_create_alarm () failed
538          }
539          else {
540                 test_time.year = current_tm.tm_year;
541                 test_time.month = current_tm.tm_mon;
542                 test_time.day = current_tm.tm_mday;
543
544                 test_time.hour = current_tm.tm_hour;
545                 test_time.min = current_tm.tm_min+1;
546                 test_time.sec = 0;
547
548                 ret_val = alarmmgr_set_time(alarm,test_time);
549                 if(ret_val == ALARMMGR_RESULT_SUCCESS) {
550                         //alarmmgr_set_time() is successful
551                 }
552                 else {
553                         //alarmmgr_set_time() failed
554                 }
555
556                 ret_val = alarmmgr_get_time(alarm, &new_time);
557                 if(ret_val == ALARMMGR_RESULT_SUCCESS) {
558                         //alarmmgr_get_time() is successful
559                 }
560                 else {
561                         //alarmmgr_get_time() failed
562                 }
563                 alarmmgr_free_alarm( alarm) ;
564         }
565  }
566
567  * @endcode
568  * @limo
569  */
570 int alarmmgr_get_time(const alarm_entry_t *alarm, alarm_date_t *time);
571
572 /**
573  * This function sets an alarm repeat mode
574  *
575  * @param       [in]    alarm   alarm entry
576  * @param       [in]    repeat_mode     one of ALARM_REPEAT_MODE_ONCE, ALARM_REPEAT_MODE_REPEAT,
577  *                                                              ALARM_REPEAT_MODE_WEEKLY, ALARM_REPEAT_MODE_MONTHLY or ALARM_REPEAT_MODE_ANNUALLY.
578  * @param       [in]    repeat_value    the ALARM_REPEAT_MODE_REPEAT mode : interval between subsequent repeats of the alarm.
579  *                                                              the ALARM_REPEAT_MODE_WEEKLY mode : days of a week
580  *                                                              (ALARM_WDAY_SUNDAY, ALARM_WDAY_MONDAY, ALARM_WDAY_TUESDAY,      ALARM_WDAY_WEDNESDAY,
581  *                                                              ALARM_WDAY_THURSDAY,    ALARM_WDAY_FRIDAY, ALARM_WDAY_SATURDAY)
582  *                                                              the others : this parameter is ignored.
583  *
584  * @return      This function returns ALARMMGR_RESULT_SUCCESS on success or a negative number on failure.
585  *
586  * @pre None.
587  * @post None.
588  * @see None.
589  * @remark  None.
590  *
591  * @par Sample code:
592  * @code
593 #include <alarm.h>
594
595   ...
596  {
597          int ret_val = ALARMMGR_RESULT_SUCCESS;
598          alarm_entry_t* alarm;
599          alarm_repeat_mode_t repeat_mode =ALARM_REPEAT_MODE_WEEKLY;
600          int interval = ALARM_WDAY_MONDAY; //| ALARM_WDAY_TUESDAY|
601                 ALARM_WDAY_WEDNESDAY| ALARM_WDAY_THURSDAY|ALARM_WDAY_FRIDAY ;
602
603
604          alarm = alarmmgr_create_alarm();
605          if(alarm == NULL)
606          {
607                   //alarmmgr_create_alarm () failed
608          }
609          else
610                  {
611                            ret_val = alarmmgr_set_repeat_mode
612                                         (alarm, repeat_mode,interval);
613
614                          if(ret_val == ALARMMGR_RESULT_SUCCESS)
615                          {
616                                   //alarmmgr_set_repeat_mode() is successful
617                          }
618                          else
619                          {
620                                  //alarmmgr_set_repeat_mode() failed
621                          }
622                          alarmmgr_free_alarm( alarm) ;
623                  }
624  }
625
626  * @endcode
627  * @limo
628  */
629 int alarmmgr_set_repeat_mode(alarm_entry_t *alarm,
630                                      alarm_repeat_mode_t repeat_mode,
631                                      int repeat_value);
632
633 /**
634  * This function gives an application an alarm mode
635  *
636  * @param       [in]            alarm   alarm entry
637  * @param       [out]   repeat_mode     one of ALARM_REPEAT_MODE_ONCE, ALARM_REPEAT_MODE_REPEAT,
638  *                                                                      ALARM_REPEAT_MODE_WEEKLY, ALARM_REPEAT_MODE_MONTHLY or ALARM_REPEAT_MODE_ANNUALLY.
639  * @param       [out]   repeat_value    the ALARM_REPEAT_MODE_REPEAT mode : interval between subsequent repeats of the alarm.
640  *                                                                      the ALARM_REPEAT_MODE_WEEKLY mode : days of a week
641  *                                                                      (ALARM_WDAY_SUNDAY, ALARM_WDAY_MONDAY, ALARM_WDAY_TUESDAY,      ALARM_WDAY_WEDNESDAY,
642  *                                                                      ALARM_WDAY_THURSDAY,    ALARM_WDAY_FRIDAY, ALARM_WDAY_SATURDAY)
643  *                                                                      the others : this parameter is ignored.
644  *
645  * @return      This function returns ALARMMGR_RESULT_SUCCESS on success or a negative number on failure.
646  *
647  * @pre None.
648  * @post None.
649  * @see None.
650  * @remark  None.
651  *
652  * @par Sample code:
653  * @code
654 #include <alarm.h>
655
656    ...
657  {
658          int ret_val = ALARMMGR_RESULT_SUCCESS;
659          alarm_entry_t* alarm;
660          alarm_repeat_mode_t repeat;
661          int interval;
662
663          alarm = alarmmgr_create_alarm();
664          if(alarm == NULL)
665          {
666                  //alarmmgr_create_alarm () failed
667          }
668          else {
669                 ret_val =alarmmgr_get_repeat_mode
670                                         (alarm, &repeat, &interval) ;
671                          if(ret_val == ALARMMGR_RESULT_SUCCESS
672                         && repeat == ALARM_REPEAT_MODE_ONCE) {
673                                 //alarmmgr_get_repeat_mode() is successful
674                         }
675                         else {
676                                 //alarmmgr_get_repeat_mode() failed
677                         }
678                         alarmmgr_free_alarm(alarm) ;
679         }
680  }
681
682  * @endcode
683  * @limo
684  */
685 int alarmmgr_get_repeat_mode(const alarm_entry_t *alarm,
686                                      alarm_repeat_mode_t *repeat_mode,
687                                      int *repeat_value);
688
689 /**
690  * This function sets an alarm mode
691  *
692  * @param       [in]    alarm   alarm entry
693  * @param       [in]    alarm_type      one of ALARM_TYPE_DEFAULT : After the device reboot, the alarm still works.
694  *                                                      ALARM_TYPE_VOLATILE : After the device reboot, the alarm does not work.
695  *
696  * @return      This function returns ALARMMGR_RESULT_SUCCESS on success or a negative number on failure.
697  *
698  * @pre None.
699  * @post None.
700  * @see None.
701  * @remark  None.
702  *
703  * @par Sample code:
704  * @code
705 #include <alarm.h>
706
707    ...
708  {
709          int ret_val = ALARMMGR_RESULT_SUCCESS;
710          alarm_entry_t* alarm;
711          int alarm_type = ALARM_TYPE_VOLATILE;
712
713          alarm = alarmmgr_create_alarm();
714          if(alarm == NULL)
715          {
716                   //alarmmgr_create_alarm () failed
717          }
718          else
719                  {
720                          ret_val = alarmmgr_set_type(alarm,  alarm_type);
721                          if(ret_val == ALARMMGR_RESULT_SUCCESS)
722                          {
723                                   //alarmmgr_set_type() is successful
724                          }
725                          else
726                          {
727                                   //alarmmgr_set_type() failed
728                          }
729                          alarmmgr_free_alarm( alarm) ;
730                  }
731  }
732
733  * @endcode
734  * @limo
735  */
736 int alarmmgr_set_type(alarm_entry_t *alarm, int alarm_type);
737
738 /**
739  * This function gives an application an alarm mode
740  *
741  * @param       [in]            alarm   alarm entry
742  * @param       [out]   alarm_type      one of ALARM_TYPE_DEFAULT, ALARM_TYPE_VOLATILE
743  *
744  * @return      This function returns ALARMMGR_RESULT_SUCCESS on success or a negative number on failure.
745  *
746  * @pre None.
747  * @post None.
748  * @see None.
749  * @remark  None.
750  *
751  * @par Sample code:
752  * @code
753 #include <alarm.h>
754
755    ...
756  {
757         int ret_val = ALARMMGR_RESULT_SUCCESS;
758         alarm_entry_t* alarm;
759         int alarm_type;
760
761         alarm = alarmmgr_create_alarm();
762         if(alarm == NULL) {
763                 //alarmmgr_create_alarm () failed
764         }
765         else {
766                 ret_val = alarmmgr_get_type(  alarm, &alarm_type);
767                 if(ret_val == ALARMMGR_RESULT_SUCCESS && alarm_type
768                                                 == ALARM_TYPE_DEFAULT ) {
769                         //alarmmgr_get_type() is successful
770                 }
771                 else {
772                         //alarmmgr_get_type() failed
773                 }
774                 alarmmgr_free_alarm( alarm) ;
775         }
776  }
777
778  * @endcode
779  * @limo
780  */
781 int alarmmgr_get_type(const alarm_entry_t *alarm, int *alarm_type);
782
783 /**
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.
795  *
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.
799  *
800  * @return      This function returns ALARMMGR_RESULT_SUCCESS on success or a negative number on failure.
801  *
802  * @pre None.
803  * @post None.
804  * @see alarmmgr_add_alarm
805  * @remark  None.
806  *
807  * @par Sample code:
808  * @code
809 #include <alarm.h>
810
811    ...
812 {
813     time_t current_time;
814     struct tm current_tm;
815     alarm_entry_t* alarm_info;
816     alarm_id_t alarm_id;
817     int result;
818     alarm_date_t test_time;
819
820
821         bundle *b=NULL;
822
823         b=bundle_create();
824
825         if (NULL == b)
826         {
827                 printf("Unable to create bundle!!!\n");
828                 return;
829         }
830
831         appsvc_set_operation(b,APPSVC_OPERATION_DEFAULT);
832         appsvc_set_pkgname(b,"org.tizen.alarm-test");
833
834     time(&current_time);
835
836     printf("current time: %s\n", ctime(&current_time));
837     localtime_r(&current_time, &current_tm);
838
839     alarm_info = alarmmgr_create_alarm();
840
841     test_time.year = current_tm.tm_year;
842                         test_time.month = current_tm.tm_mon;
843                         test_time.day = current_tm.tm_mday;
844
845                         test_time.hour = current_tm.tm_hour;
846                         test_time.min = current_tm.tm_min+1;
847                         test_time.sec = 5;
848
849
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 );
854
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)
858         {
859                 printf("Alarm creation failed!!! Alrmgr error code is %d\n",result);
860         }
861         else
862         {
863                 printf("Alarm created succesfully with alarm id %d\n",alarm_id);
864         }
865
866 }
867  * @endcode
868  * @limo
869  */
870 int alarmmgr_add_alarm_appsvc_with_localtime(alarm_entry_t *alarm,void *bundle_data, alarm_id_t *alarm_id);
871
872 /**
873  * This function adds an alarm entry to the server.
874  * Server will remember this entry, and generate alarm events for it when necessary.
875  * Alarm entries registered with the server cannot be changed.
876  * Remove from server before changing.
877  * Before the application calls alarmmgr_add_alarm_with_localtime(), the application have to call alarmmgr_set_time().
878  * The time set is localtime.
879  * If the application does not call alarmmgr_set_repeat_mode, the default repeat_mode is ALARM_REPEAT_MODE_ONCE.
880  * If the application does not call alarmmgr_set_type, the default alarm_type is ALARM_TYPE_DEFAULT.
881  * The id of the new alarm will be copied to  alarm_id if the fuction successes to create an alarm.
882  *
883  * @param       [in]            alarm           the entry of an alarm to be created.
884  * @param       [in]            destination     the packname of application that the alarm will be expired.
885  * @param       [out]   alarm_id                the id of the alarm added.
886  *
887  * @return      This function returns ALARMMGR_RESULT_SUCCESS on success or a negative number on failure.
888  *
889  * @pre None.
890  * @post None.
891  * @see alarmmgr_add_alarm
892  * @remark  None.
893  *
894  * @par Sample code:
895  * @code
896 #include <alarm.h>
897
898    ...
899 {
900         int ret_val = ALARMMGR_RESULT_SUCCESS;
901         alarm_entry_t* alarm;
902         const char* destination = NULL;
903         alarm_id_t alarm_id;
904
905         time_t current_time;
906         struct tm current_tm;
907         alarm_date_t test_time;
908
909         const char* pkg_name = "org.tizen.test";
910
911         g_type_init();
912
913         ret_val =alarmmgr_init(pkg_name) ;
914         if(ret_val != ALARMMGR_RESULT_SUCCESS) {
915                 //alarmmgr_init () failed
916                 return;
917         }
918
919         time(&current_time);
920
921         printf("current time: %s\n", ctime(&current_time));
922         localtime_r(&current_time, &current_tm);
923
924         alarm = alarmmgr_create_alarm();
925
926         test_time.year = 0;
927         test_time.month = 0;test_time.day = 0;
928
929         test_time.hour = current_tm.tm_hour;
930         test_time.min = current_tm.tm_min+1;
931         test_time.sec = 0;
932
933
934          alarmmgr_set_time(alarm,test_time);
935          alarmmgr_set_repeat_mode(alarm,ALARM_REPEAT_MODE_WEEKLY, \
936                                         ALARM_WDAY_MONDAY);
937          alarmmgr_set_type(alarm,ALARM_TYPE_VOLATILE);
938
939
940         ret_val=alarmmgr_add_alarm_with_localtime(alarm,destination,&alarm_id);
941
942          if(ret_val == ALARMMGR_RESULT_SUCCESS)
943          {
944                   //alarmmgr_add_alarm_with_localtime() is successful
945          }
946          else
947          {
948                   //alarmmgr_add_alarm_with_localtime() failed
949          }
950          alarmmgr_free_alarm( alarm) ;
951  }
952  * @endcode
953  * @limo
954  */
955 int alarmmgr_add_alarm_with_localtime(alarm_entry_t *alarm,
956                                               const char *destination,
957                                               alarm_id_t *alarm_id);
958
959
960 /**
961  * This function adds an alarm entry to the server.
962  * Server will remember this entry, and generate alarm events for it when necessary.
963  * Server will call app-svc interface to sent notification to destination application. Destination information
964  * should be available in the input bundle.
965  * Alarm entries registered with the server cannot be changed.
966  * Remove from server before changing.
967  * After the trigger_at_time seconds from now, the alarm will be expired.
968  * If the interval is zero, the repeat_mode is ALARM_REPEAT_MODE_ONCE.
969  * If the interval is >0, the repeat_mode is ALARM_REPEAT_MODE_REPEAT.
970  * The id of the new alarm will be copied to  alarm_id if the fuction successes to create an alarm.
971  *
972  * @param       [in]            alarm_type              one of ALARM_TYPE_DEFAULT, ALARM_TYPE_VOLATILE
973  * @param       [in]            trigger_at_time time interval to be triggered from now(sec). an alarm also will be expired at triggering time.
974  * @param       [in]            interval                Interval between subsequent repeats of the alarm
975  * @param       [in]            bundle_data             bundle which contains information about the destination.
976  * @param       [out]   alarm_id                        the id of the alarm added.
977  *
978  * @return      This function returns ALARMMGR_RESULT_SUCCESS on success or a negative number on failure.
979  *
980  * @pre None.
981  * @post None.
982  * @see alarmmgr_add_alarm_with_localtime alarmmgr_remove_alarm
983  * @remark  None.
984  *
985  * @par Sample code:
986  * @code
987 #include <alarm.h>
988
989  ...
990  {
991                 int result;
992                 alarm_id_t alarm_id;
993
994                 bundle *b=NULL;
995
996                 b=bundle_create();
997
998                 if (NULL == b)
999                 {
1000                         printf("Unable to create bundle!!!\n");
1001                         return;
1002                 }
1003
1004                 appsvc_set_pkgname(b,"org.tizen.alarm-test");
1005                 //appsvc_set_operation(b,APPSVC_OPERATION_SEND_TEXT);
1006                 appsvc_set_operation(b,APPSVC_OPERATION_DEFAULT);
1007
1008                 if ((result = alarmmgr_add_alarm_appsvc(ALARM_TYPE_DEFAULT, 10, 0, (void *)b ,&alarm_id)))
1009                         printf("Unable to add alarm. Alarmmgr alarm no is %d\n", result);
1010                 else
1011                         printf("Alarm added successfully. Alarm Id is %d\n", alarm_id);
1012                 return;
1013
1014  }
1015
1016  * @endcode
1017  * @limo
1018  */
1019 int alarmmgr_add_alarm_appsvc(int alarm_type, time_t trigger_at_time,
1020                                time_t interval, void *bundle_data,
1021                                alarm_id_t *alarm_id);
1022
1023
1024 /**
1025  * This function adds an alarm entry to the server.
1026  * Server will remember this entry, and generate alarm events for it when necessary.
1027  * Alarm entries registered with the server cannot be changed.
1028  * Remove from server before changing.
1029  * After the trigger_at_time seconds from now, the alarm will be expired.
1030  * If the interval is zero, the repeat_mode is ALARM_REPEAT_MODE_ONCE.
1031  * If the interval is >0, the repeat_mode is ALARM_REPEAT_MODE_REPEAT.
1032  * The id of the new alarm will be copied to  alarm_id if the fuction successes to create an alarm.
1033  *
1034  * @param       [in]            alarm_type              one of ALARM_TYPE_DEFAULT, ALARM_TYPE_VOLATILE
1035  * @param       [in]            trigger_at_time time interval to be triggered from now(sec). an alarm also will be expired at triggering time.
1036  * @param       [in]            interval                        Interval between subsequent repeats of the alarm
1037  * @param       [in]            destination             the packname of application that the alarm will be expired.
1038  * @param       [out]   alarm_id                        the id of the alarm added.
1039  *
1040  * @return      This function returns ALARMMGR_RESULT_SUCCESS on success or a negative number on failure.
1041  *
1042  * @pre None.
1043  * @post None.
1044  * @see alarmmgr_add_alarm_with_localtime alarmmgr_remove_alarm
1045  * @remark  None.
1046  *
1047  * @par Sample code:
1048  * @code
1049 #include <alarm.h>
1050
1051  ...
1052  {
1053          int ret_val = ALARMMGR_RESULT_SUCCESS;
1054
1055          int alarm_type = ALARM_TYPE_VOLATILE;
1056          time_t trigger_at_time = 10;
1057          time_t interval = 10;
1058          const char* destination = NULL;
1059          alarm_id_t alarm_id;
1060
1061          const char* pkg_name = "org.tizen.test";
1062
1063          g_type_init();
1064
1065          ret_val =alarmmgr_init(pkg_name) ;
1066          if(ret_val != ALARMMGR_RESULT_SUCCESS)
1067          {
1068                   //alarmmgr_init () failed
1069                   return;
1070          }
1071
1072          ret_val = alarmmgr_add_alarm( alarm_type, trigger_at_time, interval,
1073                                         destination, &alarm_id);
1074          if(ret_val == ALARMMGR_RESULT_SUCCESS)
1075          {
1076                   //alarmmgr_add_alarm() is successful
1077          }
1078          else
1079          {
1080                    //alarmmgr_add_alarm() failed
1081          }
1082          alarmmgr_remove_alarm( alarm_id) ;
1083  }
1084
1085  * @endcode
1086  * @limo
1087  */
1088 int alarmmgr_add_alarm(int alarm_type, time_t trigger_at_time,
1089                                time_t interval, const char *destination,
1090                                alarm_id_t *alarm_id);
1091
1092 /**
1093  * This function deletes the alarm associated with the given alarm_id.
1094  *
1095  * @param       [in]    alarm_id        Specifies the ID of the alarm to be deleted.
1096  *
1097  * @return      This function returns ALARMMGR_RESULT_SUCCESS on success or a negative number on failure.
1098  *
1099  * @pre None.
1100  * @post None.
1101  * @see alarmmgr_add_alarm_with_localtime alarmmgr_add_alarm
1102  * @remark  None.
1103  *
1104  * @par Sample code:
1105  * @code
1106 #include <alarm.h>
1107
1108  ...
1109  {
1110         int ret_val = ALARMMGR_RESULT_SUCCESS;
1111         int alarm_type = ALARM_TYPE_VOLATILE;
1112         time_t trigger_at_time = 10;
1113         time_t interval = 10;
1114         const char* destination = NULL;
1115         alarm_id_t alarm_id;
1116
1117         const char* pkg_name = "org.tizen.test";
1118
1119         g_type_init();
1120
1121         ret_val =alarmmgr_init(pkg_name) ;
1122         if(ret_val != ALARMMGR_RESULT_SUCCESS) {
1123                 //alarmmgr_init () failed
1124                 return;
1125         }
1126
1127         alarmmgr_add_alarm( alarm_type,  trigger_at_time, interval,
1128                                                 destination, &alarm_id);
1129
1130         ret_val =alarmmgr_remove_alarm( alarm_id) ;
1131         if(ret_val == ALARMMGR_RESULT_SUCCESS) {
1132                 /alarmmgr_remove_alarm() is successful
1133         }
1134         else {
1135                 //alarmmgr_remove_alarm() failed
1136         }
1137  }
1138
1139  * @endcode
1140  * @limo
1141  */
1142 int alarmmgr_remove_alarm(alarm_id_t alarm_id);
1143
1144 /**
1145  * This function gives a list of alarm ids that the application adds to the server.
1146  *
1147  * @param       [in]    fn                      a user callback function
1148  * @param       [in]    user_param      user parameter
1149  *
1150  * @return                      This function returns ALARMMGR_RESULT_SUCCESS on success or a negative number on failure.
1151  *
1152  * @pre None.
1153  * @post None.
1154  * @see alarm_get_info
1155  * @remark  None.
1156  *
1157  * @par Sample code:
1158  * @code
1159 #include <alarm.h>
1160
1161  int callback_2(alarm_id_t id, void* user_param)
1162  {
1163          int* n = (int*)user_param;
1164          printf("[%d]alarm id : %d\n",*n,id);
1165          (*n)++;
1166          return 0;
1167  }
1168
1169 ...
1170  {
1171          int ret_val = ALARMMGR_RESULT_SUCCESS;
1172          int n = 1;
1173
1174          const char* pkg_name = "org.tizen.test";
1175
1176          g_type_init();
1177
1178          ret_val =alarmmgr_init(pkg_name) ;
1179          if(ret_val != ALARMMGR_RESULT_SUCCESS)
1180          {
1181                   //alarmmgr_init() failed
1182                   return;
1183          }
1184
1185          ret_val = alarmmgr_enum_alarm_ids( callback_2, (void*)&n) ;
1186          if(ret_val == ALARMMGR_RESULT_SUCCESS)
1187          {
1188                    //alarmmgr_enum_alarm_ids() is successful
1189          }
1190          else
1191          {
1192                  //alarmmgr_enum_alarm_ids() failed
1193          }
1194  }
1195
1196  * @endcode
1197  * @limo
1198  */
1199 int alarmmgr_enum_alarm_ids(alarm_enum_fn_t fn, void *user_param);
1200
1201
1202 /**
1203  * This function gets the information of the alarm assosiated with alarm_id to alarm_info. The application
1204  * must allocate alarm_info before calling this function.
1205  *
1206  * @param       [in]    alarm_id                the id of the alarm
1207  * @param       [out]   alarm   the buffer alarm informaiton will be copied to
1208  *
1209  * @return                      This function returns ALARMMGR_RESULT_SUCCESS on success or a negative number on failure.
1210  *
1211  * @pre None.
1212  * @post None.
1213  * @see alarmmgr_enum_alarm_ids
1214  * @remark  None.
1215  *
1216  * @par Sample code:
1217  * @code
1218 #include <alarm.h>
1219
1220 ...
1221  {
1222         int ret_val = ALARMMGR_RESULT_SUCCESS;
1223         int alarm_type = ALARM_TYPE_VOLATILE;
1224         time_t trigger_at_time = 10;
1225         time_t interval = ALARM_WDAY_SUNDAY;
1226         const char* destination = NULL;
1227         alarm_id_t alarm_id;
1228
1229         alarm_entry_t *alarm;
1230
1231         const char* pkg_name = "org.tizen.test_get_info1";
1232
1233         g_type_init();
1234
1235         ret_val =alarmmgr_init(pkg_name) ;
1236         if(ret_val != ALARMMGR_RESULT_SUCCESS) {
1237                 //alarmmgr_init() failed
1238                 return;
1239         }
1240         ret_val = alarmmgr_add_alarm( alarm_type,trigger_at_time,interval,
1241                         destination, &alarm_id);
1242
1243         if(ret_val != ALARMMGR_RESULT_SUCCESS) {
1244                 //alarmmgr_add_alarm() failed
1245                 return;
1246         }
1247         ret_val = alarmmgr_get_info(alarm_id, alarm);
1248         if(ret_val == ALARMMGR_RESULT_SUCCESS) {
1249                 //alarmmgr_get_info() is successful
1250         }
1251         else {
1252                 //alarmmgr_get_info() failed
1253         }
1254         alarmmgr_remove_alarm( alarm_id) ;
1255  }
1256  * @endcode
1257  * @limo
1258  */
1259 int alarmmgr_get_info(alarm_id_t alarm_id, alarm_entry_t *alarm);
1260
1261
1262 /**
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.
1269  *
1270  * @return      This function returns bundle on success or NULL on failure.
1271  *
1272  * @pre None.
1273  * @post None.
1274  * @see None
1275  * @remark  None.
1276  *
1277  * @par Sample code:
1278  * @code
1279 #include <alarm.h>
1280
1281  ...
1282
1283 alarm_id_t alarm_id;
1284
1285 register_alarm(){
1286         int result;
1287         bundle *b=NULL;
1288         b=bundle_create();
1289
1290         if (NULL == b)
1291         {
1292                 printf("Unable to create bundle!!!\n");
1293                 return;
1294         }
1295
1296         appsvc_set_pkgname(b,"org.tizen.alarm-test");
1297         appsvc_set_operation(b,APPSVC_OPERATION_DEFAULT);
1298
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);
1301         else
1302                 printf("Alarm added successfully. Alarm Id is %d\n", alarm_id);
1303 }
1304 int main(int argc,char **argv {
1305         register_alarm();
1306
1307         int return_code = 0;
1308         bundle *b = NULL;
1309         b = alarmmgr_get_alarm_appsvc_info(alarm_id, &return_code);
1310         if (b){
1311                 const char *pkgname = appsvc_get_pkgname(b);
1312                 if (pkgname){
1313                         printf("Package name is %s\n",pkgname);
1314                 }
1315         }
1316
1317         return 0;
1318
1319  }
1320  * @endcode
1321  * @limo
1322  */
1323 void *alarmmgr_get_alarm_appsvc_info(alarm_id_t alarm_id, int *return_code);
1324
1325 /**
1326  * This function gets the scheduled time of the alarm assosiated with alarm_id.
1327  *
1328  * @param       [in]    alarm_id                the id of the alarm
1329  * @param       [out]   duetime the scheduled time of the alarm
1330  *
1331  * @return                      This function returns ALARMMGR_RESULT_SUCCESS on success or a negative number on failure.
1332  *
1333  * @pre None.
1334  * @post None.
1335  * @see None
1336  * @remark  None.
1337  */
1338  int alarmmgr_get_next_duetime(alarm_id_t alarm_id, time_t* duetime);
1339
1340 /**
1341  * This function sets power RTC (which can power on the system).
1342  * @param       [in]            alarm_date_t            time
1343  *
1344  * @return      This function returns the result. On success, ALARMMGR_RESULT_SUCCESS will be returned
1345  *              else, appropriate error no will be returned.
1346  * @pre None.
1347  * @post None.
1348  * @see None
1349  * @remark  None.
1350  *
1351  * @par Sample code:
1352  * @code
1353 #include <alarm.h>
1354
1355  ...
1356
1357 alarm_date_t alarm_date={2012,04,05,10,10,00};
1358
1359 int main(int argc,char **argv {
1360         int return_code = 0;
1361         return_code = alarmmgr_set_rtc_time(&alarm_date);
1362         if (return_code != ALARMMGR_RESULT_SUCCESS){
1363                 printf("Error returned is %d\n",return_code);
1364         }
1365         return 0;
1366
1367  }
1368  * @endcode
1369  * @limo
1370  */
1371 int alarmmgr_set_rtc_time(alarm_date_t *time);
1372
1373 int alarmmgr_add_alarm_withcb(int alarm_type, time_t trigger_at_time,
1374                                   time_t interval, alarm_cb_t handler, void *user_param, alarm_id_t *alarm_id);
1375
1376 /**
1377  * @}
1378  */
1379
1380
1381 /**
1382  * @}
1383  */
1384
1385
1386 int alarmmgr_power_on(bool on_off);
1387
1388 #ifdef __cplusplus
1389 }
1390 #endif
1391
1392
1393 #endif/* ALARM_LIB_H*/