8caf70a33e46a293e081f0c8c9204b47af7b5753
[framework/appfw/alarm-manager.git] / test / appsvc-test / alarmmgr_add_alarm_appsvc_with_localtime.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 #include<glib-object.h>
27 #include <dlog/dlog.h>
28 #include <alarm.h>
29 #include <bundle.h>
30 #include <appsvc.h>
31
32 void create_test()
33 {
34         time_t current_time;
35         struct tm current_tm;
36         alarm_entry_t *alarm_info = NULL;
37         alarm_id_t alarm_id;
38         int result;
39         alarm_date_t test_time;
40
41         bundle *b = NULL;
42
43         b = bundle_create();
44
45         if (NULL == b) {
46                 printf("Unable to create bundle!!!\n");
47                 return;
48         }
49
50         appsvc_set_operation(b, APPSVC_OPERATION_DEFAULT);
51         appsvc_set_pkgname(b, "org.tizen.alarm-test");
52
53         time(&current_time);
54
55         printf("current time: %s\n", ctime(&current_time));
56         localtime_r(&current_time, &current_tm);
57
58         alarm_info = alarmmgr_create_alarm();
59         if (NULL == alarm_info) {
60                 printf("alarmmgr_create_alarm failed!!!\n");
61                 return;
62         }
63
64         test_time.year = current_tm.tm_year;
65         test_time.month = current_tm.tm_mon;
66         test_time.day = current_tm.tm_mday;
67
68         test_time.hour = current_tm.tm_hour;
69         test_time.min = current_tm.tm_min + 1;
70         test_time.sec = 5;
71
72         alarmmgr_set_time(alarm_info, test_time);
73         alarmmgr_set_repeat_mode(alarm_info, ALARM_REPEAT_MODE_WEEKLY,
74                                  ALARM_WDAY_MONDAY | ALARM_WDAY_TUESDAY |
75                                  ALARM_WDAY_WEDNESDAY | ALARM_WDAY_THURSDAY |
76                                  ALARM_WDAY_FRIDAY);
77
78         alarmmgr_set_type(alarm_info, ALARM_TYPE_DEFAULT);
79         //alarmmgr_set_type(alarm_info,ALARM_TYPE_VOLATILE);
80         if ((result =
81              alarmmgr_add_alarm_appsvc_with_localtime(alarm_info, (void *)b,
82                                                       &alarm_id)) < 0) {
83                 printf("Alarm creation failed!!! Alrmgr error code is %d\n",
84                        result);
85         } else {
86                 printf("Alarm created succesfully with alarm id %d\n",
87                        alarm_id);
88         }
89
90 }
91
92 int main(int argc, char **argv)
93 {
94         GMainLoop *mainloop;
95
96         g_type_init();
97
98         mainloop = g_main_loop_new(NULL, FALSE);
99
100         create_test();
101
102         g_main_loop_run(mainloop);
103
104         return 0;
105 }