update for beta universally
[framework/appfw/alarm-manager.git] / test / alarm_get_info.c
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 #include<stdio.h>
24 #include<stdlib.h>
25 #include<glib.h>
26
27 #include "alarm.h"
28
29 int call2(alarm_id_t id, void* user_param)
30 {
31         int* n = (int*)user_param;
32         printf("[%d]alarm id : %d\n",*n,id);
33         (*n)++;
34 }
35
36 int callback(alarm_id_t alarm_id,void* user_param)
37 {
38         int error;
39         time_t current_time;
40         time(&current_time);
41
42         printf("Alarm[%d] has expired at %s\n", alarm_id, ctime(&current_time));
43
44         return 0;
45
46 }
47
48 void create_test()
49 {
50         time_t current_time;
51         struct tm current_tm;
52         alarm_entry_t* alarm_info;
53         alarm_id_t alarm_id;
54         int result;
55         alarm_date_t test_time;
56
57         time(&current_time);
58
59         printf("current time: %s\n", ctime(&current_time));
60         localtime_r(&current_time, &current_tm);
61         
62         alarm_info = alarmmgr_create_alarm();
63         
64         test_time.year = 0;                 
65                                 test_time.month = 0;                
66                                 test_time.day = 0;                  
67                                                  
68                                 test_time.hour = current_tm.tm_hour;
69                                 test_time.min = current_tm.tm_min+1;
70                                 test_time.sec = 0;
71
72         
73         alarmmgr_set_time(alarm_info,test_time);
74         alarmmgr_set_repeat_mode(alarm_info,ALARM_REPEAT_MODE_WEEKLY,ALARM_WDAY_MONDAY| \
75                                                                                                                                                         ALARM_WDAY_TUESDAY|ALARM_WDAY_WEDNESDAY| \
76                                             ALARM_WDAY_THURSDAY|ALARM_WDAY_FRIDAY );
77
78         alarmmgr_set_type(alarm_info,ALARM_TYPE_VOLATILE);
79         alarmmgr_add_alarm_with_localtime(alarm_info,NULL,&alarm_id);
80         alarmmgr_add_alarm_with_localtime(alarm_info,NULL,&alarm_id);
81
82         int n=1;
83                 alarmmgr_enum_alarm_ids(call2,(void*)&n);
84                 if(result < 0)
85                         printf("fail to alarmmgr_create : error_code : %d\n",result);
86         
87 }
88
89 int main(int argc, char** argv)
90 {       
91         int error_code;
92         GMainLoop *mainloop;
93                 int result;
94         
95         g_type_init();
96         
97         mainloop = g_main_loop_new(NULL, FALSE);
98                 
99         result = alarmmgr_init("org.tizen.test");
100
101                 if(result<0)
102                 {
103                         printf("fail to alarmmgr_init : error_code : %d\n",result);
104                 }
105                 else{
106                         
107            result = alarmmgr_set_cb(callback,NULL);
108
109                    if(result<0)
110                         {
111                                 printf("fail to alarmmgr_set_cb : error_code : %d\n",result);
112                         }
113                         else{
114                                 create_test();
115                         }
116                 }
117
118         g_main_loop_run(mainloop);
119 }
120
121