a2930063d6339ec8264fdc7d5ed82f37da1213f0
[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 int stte_main(int argc, char**argv, stte_request_callback_s *callback)
26 {
27         SLOG(LOG_DEBUG, TAG_STTD, "===== Start engine");
28
29         int ret = STTE_ERROR_NONE;
30
31         if (!ecore_init()) {
32                 SLOG(LOG_ERROR, TAG_STTD, "[ERROR] Fail to initialize Ecore");
33                 return STTE_ERROR_OPERATION_FAILED;
34         }
35
36         if (0 != sttd_dbus_open_connection()) {
37                 SLOG(LOG_ERROR, TAG_STTD, "[ERROR] Fail to open connection");
38                 ecore_shutdown();
39                 return STTE_ERROR_OPERATION_FAILED;
40         }
41
42         ret = sttd_initialize(callback);
43         if (0 != ret) {
44                 SLOG(LOG_ERROR, TAG_STTD, "[ERROR] Fail to initialize stt-service");
45                 sttd_dbus_close_connection();
46                 ecore_shutdown();
47                 return ret;
48         }
49
50         stt_network_initialize();
51
52         SLOG(LOG_DEBUG, TAG_STTD, "[Main] stt-service start...");
53
54         SLOG(LOG_DEBUG, TAG_STTD, "=====");
55         SLOG(LOG_DEBUG, TAG_STTD, "  ");
56         SLOG(LOG_DEBUG, TAG_STTD, "  ");
57
58         return STTE_ERROR_NONE;
59 }
60
61 int stte_send_result(stte_result_event_e event, const char* type, const char** result, int result_count,
62                                 const char* msg, void* time_info, void* user_data)
63 {
64         if (NULL == type || NULL == result) {
65                 SLOG(LOG_ERROR, TAG_STTD, "[Server ERROR] Invalid parameter");
66         }
67
68         int ret = STTE_ERROR_NONE;
69         ret = stt_engine_send_result(event, type, result, result_count, msg, time_info, user_data);
70         if (0 != ret) {
71                 SLOG(LOG_ERROR, TAG_STTD, "[Server ERROR] Fail to send result");
72         }
73         return ret;
74 }
75
76 int stte_send_error(stte_error_e error, const char* msg)
77 {
78         int ret = STTE_ERROR_NONE;
79         ret = stt_engine_send_error(error, msg);
80         if (0 != ret) {
81                 SLOG(LOG_ERROR, TAG_STTD, "[Server ERROR] Fail to send error info");
82         }
83         return ret;
84 }
85
86 int stte_send_speech_status(stte_speech_status_e status, void* user_data)
87 {
88         int ret = STTE_ERROR_NONE;
89         ret = stt_engine_send_speech_status(status, user_data);
90         if (0 != ret) {
91                 SLOG(LOG_ERROR, TAG_STTD, "[Server ERROR] Fail to send speech status");
92         }
93         return ret;
94 }
95
96 int stte_set_private_data_set_cb(stte_private_data_set_cb callback)
97 {
98         int ret = STTE_ERROR_NONE;
99         ret = stt_engine_set_private_data_set_cb(callback, NULL);
100         if (0 != ret) {
101                 SLOG(LOG_ERROR, TAG_STTD, "[Server ERROR] Fail to send speech status");
102         }
103         return ret;
104 }
105
106 int stte_set_private_data_requested_cb(stte_private_data_requested_cb callback)
107 {
108         int ret = STTE_ERROR_NONE;
109         ret = stt_engine_set_private_data_requested_cb(callback, NULL);
110         if (0 != ret) {
111                 SLOG(LOG_ERROR, TAG_STTD, "[Server ERROR] Fail to send speech status");
112         }
113         return ret;
114 }