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