Fix init/shutdown process in wkb-ibus and wkb-ibus-test
[profile/ivi/weekeyboard.git] / src / wkb-ibus-test.c
1 /*
2  * Copyright © 2013 Intel Corporation
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
17 #include "wkb-ibus.h"
18 #include "wkb-log.h"
19
20 #define _GNU_SOURCE
21 #include <signal.h>
22
23 #include <Eina.h>
24 #include <Ecore.h>
25 #include <Eldbus.h>
26 #include <Efreet.h>
27
28 static void
29 _finish(int foo)
30 {
31    ERR("FINISH\n");
32    wkb_ibus_shutdown();
33 }
34
35 static Eina_Bool
36 _connect_timer(void *data)
37 {
38    return !wkb_ibus_connect();
39 }
40
41 int
42 main (int argc, char *argv[])
43 {
44    int ret = 1;
45
46    if (!wkb_log_init("ibus-test"))
47       return 1;
48
49    if (!ecore_init())
50      {
51         ERR("Error initializing ecore");
52         goto ecore_err;
53      }
54
55    if (!wkb_ibus_init())
56      {
57         ERR("Error initializing ibus");
58         goto end;
59      }
60
61    ecore_timer_add(1, _connect_timer, NULL);
62
63    signal(SIGTERM, _finish);
64    signal(SIGINT, _finish);
65
66    ecore_main_loop_begin();
67    ret = 0;
68
69 end:
70    ecore_shutdown();
71
72 ecore_err:
73    wkb_log_shutdown();
74
75    return ret;
76 }