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