libgdbus: Move common gdbus interfaces to libsystem package
[platform/core/system/feedbackd.git] / src / core / main.c
1 /*
2  * feedbackd
3  *
4  * Copyright (c) 2016 - 2017 Samsung Electronics Co., Ltd.
5  *
6  * Licensed under the Apache License, Version 2.0 (the License);
7  * you may not use this file except in compliance with the License.
8  * You may obtain a copy of the License at
9  *
10  *     http://www.apache.org/licenses/LICENSE-2.0
11  *
12  * Unless required by applicable law or agreed to in writing, software
13  * distributed under the License is distributed on an "AS IS" BASIS,
14  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15  * See the License for the specific language governing permissions and
16  * limitations under the License.
17  */
18
19
20 #include <stdio.h>
21 #include <fcntl.h>
22 #include <sys/reboot.h>
23 #include <glib.h>
24 #include <libgdbus/dbus-system.h>
25
26 #include "core/log.h"
27 #include "core/common.h"
28 #include "haptic/haptic.h"
29
30 static GMainLoop *mainloop = NULL;
31
32 static void sig_quit(int signo)
33 {
34         _D("received SIGTERM signal %d", signo);
35 }
36
37 static void sig_usr1(int signo)
38 {
39         _D("received SIGUSR1 signal %d, feedbackd'll be finished!", signo);
40
41         if (mainloop) {
42                 if (g_main_loop_is_running(mainloop))
43                         g_main_loop_quit(mainloop);
44                 mainloop = NULL;
45         }
46 }
47
48 int main(int argc, char **argv)
49 {
50         int ret;
51
52         mainloop = g_main_loop_new(NULL, FALSE);
53
54         if (!dbus_handle_init(G_BUS_TYPE_SYSTEM, VIBRATOR_BUS_NAME, NULL, NULL)) {
55                 _E("failed to init dbus connection");
56         }
57
58         ret = haptic_probe();
59         if (ret != 0) {
60                 _E("[haptic] probe fail");
61                 return ret;
62         }
63         haptic_init();
64
65         signal(SIGTERM, sig_quit);
66         signal(SIGUSR1, sig_usr1);
67
68         /* g_main_loop */
69         g_main_loop_run(mainloop);
70
71         _D("[haptic] deinitialize");
72         haptic_exit();
73         g_main_loop_unref(mainloop);
74         mainloop = NULL;
75
76         return 0;
77 }