Release version 0.12.34
[platform/core/appfw/alarm-manager.git] / tool / alarmmgr_add_periodic_alarm_withcb.c
1 /*
2  * Copyright (c) 2015 - 2019 Samsung Electronics Co., Ltd All Rights Reserved
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  * http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */
16 #include<stdio.h>
17 #include<stdlib.h>
18 #include<glib.h>
19
20 #include "alarm.h"
21
22 int callback(alarm_id_t alarm_id, void* user_param)
23 {
24         time_t current_time;
25         time(&current_time);
26
27         printf("Alarm[%d] has expired at %s\n", alarm_id, ctime(&current_time));
28         return 0;
29 }
30
31 void create_test()
32 {
33         int result = 0;
34         alarm_id_t alarm_id;
35
36         result = alarmmgr_add_periodic_alarm_withcb(5, QUANTUMIZE, callback, NULL, &alarm_id);
37         if (result < 0)
38                 printf("fail to alarmmgr_add_periodic_alarm_withcb : error_code : %d\n", result);
39
40         result = alarmmgr_add_periodic_alarm_withcb(5, CUT_OFF, callback, NULL, &alarm_id);
41         if (result < 0)
42                 printf("fail to alarmmgr_add_periodic_alarm_withcb : error_code : %d\n", result);
43
44 }
45
46 int main(int argc, char** argv)
47 {
48         GMainLoop *mainloop;
49         int result;
50
51         mainloop = g_main_loop_new(NULL, FALSE);
52         result = alarmmgr_init("org.tizen.alarmmgr.periodic");
53
54         if (result < 0)
55                 printf("fail to alarmmgr_init : error_code : %d\n", result);
56         else
57                 create_test();
58
59         g_main_loop_run(mainloop);
60
61         return 0;
62 }