89d4be0ba9e204085c49aa9bbbedab09c5c81e05
[platform/core/uifw/stt.git] / server / stte.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 #include <Ecore.h>
15
16 #include "stt_engine.h"
17 #include "stt_defs.h"
18 #include "stt_network.h"
19 #include "sttd_dbus.h"
20 #include "sttd_server.h"
21
22 #include "stte.h"
23
24
25 #define CLIENT_CLEAN_UP_TIME 500
26
27 static Ecore_Timer* g_check_client_timer = NULL;
28
29 int stte_main(int argc, char**argv, stte_request_callback_s *callback)
30 {
31         SLOG(LOG_DEBUG, TAG_STTD, "===== Start engine");
32
33         int ret = STTE_ERROR_NONE;
34
35         if (!ecore_init()) {
36                 SLOG(LOG_ERROR, TAG_STTD, "[ERROR] Fail to initialize Ecore");
37                 return STTE_ERROR_OPERATION_FAILED;
38         }
39
40         if (0 != sttd_dbus_open_connection()) {
41                 SLOG(LOG_ERROR, TAG_STTD, "[ERROR] Fail to open connection");
42                 ecore_shutdown();
43                 return STTE_ERROR_OPERATION_FAILED;
44         }
45
46         ret = sttd_initialize(callback);
47         if (0 != ret) {
48                 SLOG(LOG_ERROR, TAG_STTD, "[ERROR] Fail to initialize stt-service");
49                 sttd_dbus_close_connection();
50                 ecore_shutdown();
51                 return ret;
52         }
53
54         stt_network_initialize();
55
56         g_check_client_timer = ecore_timer_add(CLIENT_CLEAN_UP_TIME, sttd_cleanup_client, NULL);
57         if (NULL == g_check_client_timer) {
58                 SLOG(LOG_WARN, TAG_STTD, "[Main Warning] Fail to create timer of client check");
59         }
60
61         SLOG(LOG_DEBUG, TAG_STTD, "[Main] stt-service start...");
62
63         SLOG(LOG_DEBUG, TAG_STTD, "=====");
64         SLOG(LOG_DEBUG, TAG_STTD, "  ");
65         SLOG(LOG_DEBUG, TAG_STTD, "  ");
66
67         return STTE_ERROR_NONE;
68 }
69
70 int stte_send_result(stte_result_event_e event, const char* type, const char** result, int result_count,
71                                 const char* msg, void* time_info, void* user_data)
72 {
73         if (NULL == type || NULL == result) {
74                 SLOG(LOG_ERROR, TAG_STTD, "[Server ERROR] Invalid parameter");
75         }
76
77         int ret = STTE_ERROR_NONE;
78         ret = stt_engine_send_result(event, type, result, result_count, msg, time_info, user_data);
79         if (0 != ret) {
80                 SLOG(LOG_ERROR, TAG_STTD, "[Server ERROR] Fail to send result");
81         }
82         return ret;
83 }
84
85 int stte_send_error(stte_error_e error, const char* msg)
86 {
87         if (NULL == msg) {
88                 SLOG(LOG_ERROR, TAG_STTD, "[Server ERROR] Invalid parameter");
89         }
90
91         int ret = STTE_ERROR_NONE;
92         ret = stt_engine_send_error(error, msg);
93         if (0 != ret) {
94                 SLOG(LOG_ERROR, TAG_STTD, "[Server ERROR] Fail to send error info");
95         }
96         return ret;
97 }
98
99 int stte_send_speech_status(stte_speech_status_e status, void* user_data)
100 {
101         int ret = STTE_ERROR_NONE;
102         ret = stt_engine_send_speech_status(status, user_data);
103         if (0 != ret) {
104                 SLOG(LOG_ERROR, TAG_STTD, "[Server ERROR] Fail to send speech status");
105         }
106         return ret;
107 }
108
109 int stte_set_private_data_set_cb(stte_private_data_set_cb callback)
110 {
111         int ret = STTE_ERROR_NONE;
112         ret = stt_engine_set_private_data_set_cb(callback, NULL);
113         if (0 != ret) {
114                 SLOG(LOG_ERROR, TAG_STTD, "[Server ERROR] Fail to send speech status");
115         }
116         return ret;
117 }
118
119 int stte_set_private_data_requested_cb(stte_private_data_requested_cb callback)
120 {
121         int ret = STTE_ERROR_NONE;
122         ret = stt_engine_set_private_data_requested_cb(callback, NULL);
123         if (0 != ret) {
124                 SLOG(LOG_ERROR, TAG_STTD, "[Server ERROR] Fail to send speech status");
125         }
126         return ret;
127 }