Fix bugs
[platform/core/uifw/tts.git] / server / ttsd_main.c
1 /*
2 *  Copyright (c) 2011-2016 Samsung Electronics Co., Ltd All Rights Reserved 
3 *  Licensed under the Apache License, Version 2.0 (the "License");
4 *  you may not use this file except in compliance with the License.
5 *  You may obtain a copy of the License at
6 *  http://www.apache.org/licenses/LICENSE-2.0
7 *  Unless required by applicable law or agreed to in writing, software
8 *  distributed under the License is distributed on an "AS IS" BASIS,
9 *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
10 *  See the License for the specific language governing permissions and
11 *  limitations under the License.
12 */
13
14
15 #include "ttsd_main.h"
16 #include "ttsd_server.h"
17 #include "ttsd_dbus.h"
18 #include "ttsd_network.h"
19
20 #include <Ecore.h>
21
22 #define CLIENT_CLEAN_UP_TIME 500
23
24 static Ecore_Timer* g_check_client_timer = NULL;
25
26 const char* get_tag()
27 {
28         return "ttsd";
29 }
30
31 const char* tts_tag()
32 {
33         return "ttsd";
34 }
35
36 ttsd_mode_e ttsd_get_mode()
37 {
38         return TTSD_MODE_DEFAULT;
39 }
40
41 /* Main of TTS Daemon */
42 int main()
43 {
44         SLOG(LOG_DEBUG, get_tag(), "  ");
45         SLOG(LOG_DEBUG, get_tag(), "  ");
46         SLOG(LOG_DEBUG, get_tag(), "===== TTS DAEMON DEFAULT INITIALIZE");
47
48         if (!ecore_init()) {
49                 SLOG(LOG_ERROR, get_tag(), "[Main ERROR] Fail ecore_init()");
50                 return -1;
51         }
52
53         if (0 != ttsd_dbus_open_connection()) {
54                 SLOG(LOG_ERROR, get_tag(), "[Main ERROR] Fail to open dbus connection");
55                 return EXIT_FAILURE;
56         }
57
58         if (0 != ttsd_initialize()) {
59                 SLOG(LOG_ERROR, get_tag(), "[Main ERROR] Fail to initialize tts-daemon"); 
60                 return EXIT_FAILURE;
61         }
62
63         if (0 != ttsd_network_initialize()) {
64                 SLOG(LOG_WARN, get_tag(), "[Main WARNING] Fail to initialize network");
65         }
66
67         g_check_client_timer = ecore_timer_add(CLIENT_CLEAN_UP_TIME, ttsd_cleanup_client, NULL);
68         if (NULL == g_check_client_timer) {
69                 SLOG(LOG_WARN, get_tag(), "[Main Warning] Fail to create timer of client check");
70         }
71
72         SLOG(LOG_DEBUG, get_tag(), "[Main] tts-daemon start..."); 
73         SLOG(LOG_DEBUG, get_tag(), "=====");
74         SLOG(LOG_DEBUG, get_tag(), "  ");
75         SLOG(LOG_DEBUG, get_tag(), "  ");
76         
77         ecore_main_loop_begin();
78
79         SLOG(LOG_DEBUG, get_tag(), "===== TTS DAEMON DEFAULT FINALIZE");
80
81         if (NULL != g_check_client_timer) {
82                 ecore_timer_del(g_check_client_timer);
83         }
84
85         ttsd_dbus_close_connection();
86
87         ttsd_network_finalize();
88
89         ttsd_finalize();
90
91         ecore_shutdown();
92
93         SLOG(LOG_DEBUG, get_tag(), "=====");
94         SLOG(LOG_DEBUG, get_tag(), "  ");
95         SLOG(LOG_DEBUG, get_tag(), "  ");
96
97         return 0;
98 }
99