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