Add new flag variable for checking state
[platform/core/uifw/tts.git] / client / tts_tidl.c
1 /* *  Copyright (c) 2021 Samsung Electronics Co., Ltd All Rights Reserved
2 *  Licensed under the Apache License, Version 2.0 (the "License");
3 *  you may not use this file except in compliance with the License.
4 *  You may obtain a copy of the License at
5 *  http://www.apache.org/licenses/LICENSE-2.0
6 *  Unless required by applicable law or agreed to in writing, software
7 *  distributed under the License is distributed on an "AS IS" BASIS,
8 *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
9 *  See the License for the specific language governing permissions and
10 *  limitations under the License.
11 */
12
13 #include <rpc-port.h>
14 #include "tts_main.h"
15 #include "tts_tidl.h"
16 #include "tts_proxy.h"
17 #include "tts_internal.h"
18 #include "tts_client.h"
19 #include "tts_core.h"
20 #include "tts_dlog.h"
21
22 #define MAXSLEEP 128
23 #define MAX_CONNECT_CHECK 100
24
25 typedef struct {
26         unsigned int uid;
27         bool connected;
28         bool connection_requesting;
29         bool register_callback_invoked;
30         rpc_port_proxy_tts_h rpc_h;
31         rpc_port_proxy_tts_notify_cb_h notify_cb_h;
32         char* engine_app_id;
33 } tts_tidl_info_s;
34
35 static GList* g_tidl_infos = NULL;
36
37
38 static tts_tidl_info_s* __get_tidl_info_s(unsigned int uid)
39 {
40         GList* iter = NULL;
41         tts_tidl_info_s* info = NULL;
42
43         if (g_list_length(g_tidl_infos) > 0) {
44                 /* Get a first item */
45                 iter = g_list_first(g_tidl_infos);
46
47                 while (NULL != iter) {
48                         info = iter->data;
49
50                         if (info->uid == uid) {
51                                 return info;
52                         }
53
54                         /* Next item */
55                         iter = g_list_next(iter);
56                 }
57         }
58
59         return NULL;
60 }
61
62 static void __notify_cb(void *user_data, int pid, int uid, bundle *msg)
63 {
64         char *method = NULL;
65         char *val = NULL;
66         tts_client_s* client = tts_client_get_by_uid(uid);
67         RETM_IF(NULL == client, "[ERROR] Fail to get client");
68
69         unsigned int u_uid = (unsigned int)uid;
70         SLOG(LOG_DEBUG, TAG_TTSC, "__notify_cb is invoked pid(%d) uid(%u)", pid, u_uid);
71
72         bundle_get_str(msg, TTS_BUNDLE_METHOD, &method);
73
74         if (0 == strncmp(TTSD_METHOD_HELLO, method, strlen(TTSD_METHOD_HELLO))) {
75                 char* credential_needed = NULL;
76                 char* ret = NULL;
77                 bundle_get_str(msg, TTS_BUNDLE_CREDENTIAL_NEEDED, &credential_needed);
78                 bundle_get_str(msg, TTS_BUNDLE_REASON, &ret);
79
80                 if (NULL != credential_needed && NULL != ret) {
81                         tts_client_set_start_listening(u_uid, true);
82                         tts_core_receive_hello(u_uid, atoi(ret), atoi(credential_needed));
83
84                         tts_tidl_info_s* info = __get_tidl_info_s(u_uid);
85                         RETM_IF(NULL == info, "[ERROR] Fail to get tidl info");
86                         info->register_callback_invoked = false;
87                 } else {
88                         SLOG(LOG_ERROR, TAG_TTSC, "[ERROR] Fail to get message(TTSD_METHOD_HELLO). pid(%d) uid(%u)", pid, u_uid);
89                 }
90         } else if (0 == strncmp(TTSD_METHOD_UTTERANCE_STARTED, method, strlen(TTSD_METHOD_UTTERANCE_STARTED))) {
91                 bundle_get_str(msg, TTS_BUNDLE_MESSAGE, &val);
92                 if (val) {
93                         tts_core_notify_utt_started(client, atoi(val));
94                 }
95         } else if (0 == strncmp(TTSD_METHOD_UTTERANCE_COMPLETED, method, strlen(TTSD_METHOD_UTTERANCE_COMPLETED))) {
96                 bundle_get_str(msg, TTS_BUNDLE_MESSAGE, &val);
97                 if (val) {
98                         tts_core_notify_utt_completeted(client, atoi(val));
99                 }
100         } else if (0 == strncmp(TTSD_METHOD_SET_STATE, method, strlen(TTSD_METHOD_SET_STATE))) {
101                 bundle_get_str(msg, TTS_BUNDLE_MESSAGE, &val);
102                 if (val) {
103                         tts_core_notify_state_changed(client, (tts_state_e)atoi(val));
104                 }
105         } else if (0 == strncmp(TTSD_METHOD_ERROR, method, strlen(TTSD_METHOD_ERROR))) {
106                 char *uttid = NULL;
107                 char *reason = NULL;
108                 char *err_msg = NULL;
109
110                 bundle_get_str(msg, TTS_BUNDLE_REASON, &reason);
111                 bundle_get_str(msg, TTS_BUNDLE_UTTID, &uttid);
112                 bundle_get_str(msg, TTS_BUNDLE_ERR_MSG, &err_msg);
113                 if (reason && uttid) {
114                         tts_core_notify_error_async(client, atoi(reason), atoi(uttid), err_msg);
115                 }
116         } else {
117                 SLOG(LOG_ERROR, TAG_TTSC, "[ERROR] Invalid msg");
118         }
119 }
120
121 static void __on_connected(rpc_port_proxy_tts_h h, void *user_data)
122 {
123         unsigned int uid = (uintptr_t)user_data;
124
125         tts_client_s* client = tts_client_get_by_uid(uid);
126         RETM_IF(NULL == client, "[ERROR] Fail to get client");
127
128         tts_tidl_info_s* info = __get_tidl_info_s(uid);
129         RETM_IF(NULL == info, "[ERROR] Fail to get tidl info");
130
131         info->connected = true;
132         info->connection_requesting = false;
133         info->register_callback_invoked = false;
134
135         SLOG(LOG_DEBUG, TAG_TTSC, "Connected to server");
136 }
137
138 static void __on_disconnected(rpc_port_proxy_tts_h h, void *user_data)
139 {
140         unsigned int uid = (uintptr_t)user_data;
141
142         tts_client_s* client = tts_client_get_by_uid(uid);
143         RETM_IF(NULL == client, "[ERROR] Fail to get client");
144
145         tts_tidl_info_s* info = __get_tidl_info_s(uid);
146         RETM_IF(NULL == info, "[ERROR] Fail to get tidl info");
147
148         info->connected = false;
149         info->connection_requesting = false;
150         info->register_callback_invoked = false;
151
152         SLOG(LOG_DEBUG, TAG_TTSC, "Disconnected from server");
153         if (tts_client_is_listening_started(uid)) {
154                 SLOG(LOG_DEBUG, TAG_TTSC, "Try to reconnect to server");
155                 tts_core_handle_service_reset();
156         }
157 }
158
159 //LCOV_EXCL_START
160 static void __on_rejected(rpc_port_proxy_tts_h h, void *user_data)
161 {
162         unsigned int uid = (uintptr_t)user_data;
163         tts_client_s *client = tts_client_get_by_uid(uid);
164         RETM_IF(NULL == client, "[ERROR] Fail to get client");
165
166         tts_tidl_info_s* info = __get_tidl_info_s(uid);
167         RETM_IF(NULL == info, "[ERROR] Fail to get tidl info");
168         info->connection_requesting = false;
169         info->register_callback_invoked = false;
170
171         SLOG(LOG_ERROR, TAG_TTSC, "[ERROR] Rejected from server(%d)", uid);
172 }
173 //LCOV_EXCL_STOP
174
175 static void __get_engine_app_id(int size, char* app_id)
176 {
177         RETM_IF(NULL == app_id, "app_id is NULL");
178
179         char* engine_name = vconf_get_str(TTS_ENGINE_DB_DEFAULT);
180         if (NULL == engine_name) {
181                 SLOG(LOG_ERROR, TAG_TTSC, "[ERROR] Fail to get engine name");
182                 engine_name = strdup(TTS_SERVER_ENGINE_DEFAULT);
183         }
184
185         snprintf(app_id, size, "%s", engine_name);
186         free(engine_name);
187
188         SLOG(LOG_INFO, TAG_TTSC, "engine app id : %s", app_id);
189 }
190
191 static rpc_port_proxy_tts_h __create_rpc_port(unsigned int uid, const char* engine_app_id)
192 {
193         rpc_port_proxy_tts_callback_s rpc_callback = {
194                 .connected = __on_connected,
195                 .disconnected = __on_disconnected,
196                 .rejected = __on_rejected
197         };
198
199         rpc_port_proxy_tts_h handle = NULL;
200         uintptr_t ptr_uid = uid;
201         if (RPC_PORT_ERROR_NONE != rpc_port_proxy_tts_create(engine_app_id, &rpc_callback, (void*)ptr_uid, &handle)) {
202                 SLOG(LOG_ERROR, TAG_TTSC, "[ERROR] Fail to create proxy");
203                 return NULL;
204         }
205
206         return handle;
207 }
208
209 int tts_tidl_open_connection(unsigned int uid)
210 {
211         SLOG(LOG_DEBUG, TAG_TTSC, "[TIDL] tts_tidl_open_connection");
212
213         tts_client_s* client = tts_client_get_by_uid(uid);
214         RETVM_IF(NULL == client, TTS_ERROR_INVALID_PARAMETER, "[ERROR] Fail to get client");
215
216         tts_tidl_info_s* info = (tts_tidl_info_s*)calloc(1, sizeof(tts_tidl_info_s));
217         if (NULL == info) {
218                 SLOG(LOG_ERROR, TAG_TTSC, "[TIDL ERROR] Fail to create tidl_info_s");
219                 return TTS_ERROR_OUT_OF_MEMORY;
220         }
221
222         char engine_app_id[TTS_ENGINE_APPID_LEN] = {0, };
223         __get_engine_app_id(TTS_ENGINE_APPID_LEN, engine_app_id);
224
225         info->rpc_h = __create_rpc_port(uid, engine_app_id);
226         if (NULL == info->rpc_h) {
227                 SLOG(LOG_ERROR, TAG_TTSC, "[TIDL ERROR] Fail to create proxy");
228                 free(info);
229                 return TTS_ERROR_OPERATION_FAILED;
230         }
231
232         info->engine_app_id = strdup(engine_app_id);
233         info->uid = uid;
234         g_tidl_infos = g_list_append(g_tidl_infos, info);
235
236         SLOG(LOG_ERROR, TAG_TTSC, "[TIDL] uid(%u) rpc_h(%p), engine_app_id(%s)", uid, info->rpc_h, info->engine_app_id);
237         return TTS_ERROR_NONE;
238 }
239
240 int tts_tidl_close_connection(unsigned int uid)
241 {
242         SLOG(LOG_DEBUG, TAG_TTSC, "[TIDL] tts_tidl_close_connection");
243
244         tts_client_s* client = tts_client_get_by_uid(uid);
245         RETVM_IF(NULL == client, TTS_ERROR_INVALID_PARAMETER, "[ERROR] Fail to get client");
246
247         tts_tidl_info_s* info = __get_tidl_info_s(uid);
248         RETVM_IF(NULL == info, TTS_ERROR_INVALID_PARAMETER, "[ERROR] Fail to get tidl info");
249
250         if (RPC_PORT_ERROR_NONE != rpc_port_proxy_tts_destroy(info->rpc_h)) {
251                 SLOG(LOG_ERROR, TAG_TTSC, "[ERROR] Fail to disconnect");
252                 return TTS_ERROR_OPERATION_FAILED;
253         }
254
255         info->rpc_h = NULL;
256         info->notify_cb_h = NULL;
257
258         free(info->engine_app_id);
259         info->engine_app_id = NULL;
260
261         g_tidl_infos = g_list_remove(g_tidl_infos, info);
262         free(info);
263
264         return TTS_ERROR_NONE;
265 }
266
267 int tts_tidl_stop_listening(unsigned int uid)
268 {
269         RETVM_IF(false == tts_client_is_valid_uid(uid), TTS_ERROR_INVALID_PARAMETER, "[ERROR] uid is not valid");
270
271         tts_client_set_start_listening(uid, false);
272
273         return TTS_ERROR_NONE;
274 }
275
276 static void __request_tidl_connect(tts_tidl_info_s* info)
277 {
278         if (info->connection_requesting) {
279                 return;
280         }
281
282         int ret = rpc_port_proxy_tts_connect(info->rpc_h);
283         if (RPC_PORT_ERROR_NONE != ret) {
284                 SLOG(LOG_INFO, TAG_TTSC, "[INFO] Fail to request connection to stub. ret(%d)", ret);
285                 return;
286         }
287
288         SLOG(LOG_INFO, TAG_TTSC, "[INFO] Request connection to stub. ret(%d)", ret);
289
290         info->connection_requesting = true;
291 }
292
293 static int __create_notify_callback_handle(tts_tidl_info_s* info)
294 {
295         if (NULL != info->notify_cb_h) {
296                 rpc_port_proxy_tts_notify_cb_dispose(info->rpc_h, info->notify_cb_h);
297                 info->notify_cb_h = NULL;
298         }
299
300         if (RPC_PORT_ERROR_NONE != rpc_port_proxy_tts_notify_cb_create(&info->notify_cb_h)) {
301                 return TTS_ERROR_OUT_OF_MEMORY;
302         }
303
304         rpc_port_proxy_tts_notify_cb_set_callback(info->notify_cb_h, __notify_cb, NULL);
305         rpc_port_proxy_tts_notify_cb_set_once(info->notify_cb_h, false);
306
307         return TTS_ERROR_NONE;
308 }
309
310 static int __invoke_register_callback(int pid, tts_mode_e mode, tts_tidl_info_s* info)
311 {
312         if (info->register_callback_invoked) {
313                 SLOG(LOG_ERROR, TAG_TTSC, "[INFO] Already register callback is invoked");
314                 return TTS_ERROR_NONE;
315         }
316
317         int ret = __create_notify_callback_handle(info);
318         if (TTS_ERROR_NONE != ret) {
319                 SLOG(LOG_ERROR, TAG_TTSC, "[ERROR] Fail to create callback handle. ret(%d)", ret);
320                 return ret;
321         }
322
323         rpc_port_proxy_tts_invoke_register_cb(info->rpc_h, pid, info->uid, (int)mode, info->notify_cb_h);
324         info->register_callback_invoked = true;
325         return TTS_ERROR_NONE;
326 }
327
328 int tts_tidl_request_hello(unsigned int uid, tts_mode_e mode)
329 {
330         SLOG(LOG_DEBUG, TAG_TTSC, "[TIDL] tts_tidl_request_hello");
331
332         tts_client_s* client = tts_client_get_by_uid(uid);
333         RETVM_IF(NULL == client, TTS_ERROR_INVALID_PARAMETER, "[ERROR] Fail to get client");
334
335         tts_tidl_info_s* info = __get_tidl_info_s(uid);
336         RETVM_IF(NULL == info, TTS_ERROR_INVALID_PARAMETER, "[ERROR] Fail to get tidl info");
337
338         char engine_app_id[TTS_ENGINE_APPID_LEN] = {0, };
339         __get_engine_app_id(TTS_ENGINE_APPID_LEN, engine_app_id);
340
341         if (NULL == info->engine_app_id || 0 != strncmp(info->engine_app_id, engine_app_id, TTS_ENGINE_APPID_LEN)) {
342                 SLOG(LOG_ERROR, TAG_TTSC, "[TIDL] tts engine is changed from (%s) to (%s)", info->engine_app_id, engine_app_id);
343                 if (RPC_PORT_ERROR_NONE != rpc_port_proxy_tts_destroy(info->rpc_h)) {
344                         SLOG(LOG_ERROR, TAG_TTSC, "[ERROR] Fail to destroy old rpc_port");
345                         return TTS_ERROR_OPERATION_FAILED;
346                 }
347                 info->notify_cb_h = NULL;
348                 info->register_callback_invoked = false;
349
350                 info->rpc_h = __create_rpc_port(uid, engine_app_id);
351                 if (NULL == info->rpc_h) {
352                         SLOG(LOG_ERROR, TAG_TTSC, "[ERROR] Fail to create proxy");
353                         return TTS_ERROR_OPERATION_FAILED;
354                 }
355                 free(info->engine_app_id);
356                 info->engine_app_id = strdup(engine_app_id);
357                 info->connection_requesting = false;
358         }
359
360         if (!info->connected) {
361                 SLOG(LOG_ERROR, TAG_TTSC, "[ERROR] Not Connected");
362                 __request_tidl_connect(info);
363                 return TTS_ERROR_OPERATION_FAILED;
364         }
365
366         SLOG(LOG_DEBUG, TAG_TTSC, ">>>>> TTS Hello");
367         if (TTS_ERROR_NONE != __invoke_register_callback(client->pid, mode, info)) {
368                 SLOG(LOG_ERROR, TAG_TTSC, "[ERROR] Fail to invoke register callback");
369                 return TTS_ERROR_OPERATION_FAILED;
370         }
371
372         SLOG(LOG_DEBUG, TAG_TTSC, "<<<<");
373         return TTS_ERROR_NONE;
374 }
375
376 static int __request_tidl_connect_sync(tts_tidl_info_s* info)
377 {
378         int ret = rpc_port_proxy_tts_connect_sync(info->rpc_h);
379         SLOG(LOG_INFO, TAG_TTSC, "[INFO] Request connection to stub. ret(%d)", ret);
380         if (RPC_PORT_ERROR_NONE == ret) {
381                 return TTS_ERROR_NONE;
382         }
383
384         return TTS_ERROR_OPERATION_FAILED;
385 }
386
387 static int __convert_unhandled_error(int ret)
388 {
389         if (RPC_PORT_ERROR_IO_ERROR == ret || RPC_PORT_ERROR_OUT_OF_MEMORY == ret) {
390                 return TTS_ERROR_OPERATION_FAILED;
391         }
392
393         return ret;
394 }
395
396 static int __invoke_register_callback_sync(int pid, tts_tidl_info_s* info)
397 {
398         if (info->register_callback_invoked) {
399                 SLOG(LOG_ERROR, TAG_TTSC, "[INFO] Already register callback is invoked");
400                 return TTS_ERROR_NONE;
401         }
402
403         int ret = TTS_ERROR_NONE;
404         ret = __create_notify_callback_handle(info);
405         if (TTS_ERROR_NONE != ret) {
406                 SLOG(LOG_ERROR, TAG_TTSC, "[ERROR] Fail to create callback handle. ret(%d/%s)", ret, get_error_message(ret));
407                 return ret;
408         }
409
410         ret = rpc_port_proxy_tts_invoke_register_cb_sync(info->rpc_h, pid, info->uid, info->notify_cb_h);
411         int exception = get_last_result();
412         if (RPC_PORT_ERROR_NONE != exception) {
413                 ret = __convert_unhandled_error(exception);
414         }
415
416         if (TTS_ERROR_NONE != ret) {
417                 SLOG(LOG_ERROR, TAG_TTSC, "[ERROR] Fail to register callback. ret(%d/%s)", ret, get_error_message(ret));
418                 return ret;
419         }
420
421         info->register_callback_invoked = true;
422         return TTS_ERROR_NONE;
423 }
424
425 int tts_tidl_request_hello_sync(unsigned int uid)
426 {
427         SLOG(LOG_DEBUG, TAG_TTSC, "[TIDL] tts_tidl_request_hello");
428
429         tts_client_s* client = tts_client_get_by_uid(uid);
430         RETVM_IF(NULL == client, TTS_ERROR_INVALID_PARAMETER, "[ERROR] Fail to get client");
431
432         tts_tidl_info_s* info = __get_tidl_info_s(uid);
433         RETVM_IF(NULL == info, TTS_ERROR_INVALID_PARAMETER, "[ERROR] Fail to get tidl info");
434
435         if (!info->connected) {
436                 SLOG(LOG_WARN, TAG_TTSC, "[WARNNING] Stub is not Connected. Try to connect..");
437                 int ret = __request_tidl_connect_sync(info);
438                 if (TTS_ERROR_NONE != ret) {
439                         SLOG(LOG_ERROR, TAG_TTSC, "[ERROR] Fail to connect. ret(%d)", ret);
440                         return TTS_ERROR_OPERATION_FAILED;
441                 }
442
443                 SLOG(LOG_INFO, TAG_TTSC, "[TIDL] Stub is Connected");
444         }
445
446         SLOG(LOG_DEBUG, TAG_TTSC, ">>>>> TTS Hello");
447         if (TTS_ERROR_NONE != __invoke_register_callback_sync(client->pid, info)) {
448                 SLOG(LOG_ERROR, TAG_TTSC, "[ERROR] Fail to invoke register callback");
449                 return TTS_ERROR_OPERATION_FAILED;
450         }
451
452         SLOG(LOG_DEBUG, TAG_TTSC, "<<<<");
453         return TTS_ERROR_NONE;
454 }
455
456 int tts_tidl_request_initialize(unsigned int uid, tts_mode_e mode, bool* credential_needed)
457 {
458         SLOG(LOG_DEBUG, TAG_TTSC, "[TIDL] tts_tidl_request_initialize");
459
460         tts_client_s* client = tts_client_get_by_uid(uid);
461         RETVM_IF(NULL == client, TTS_ERROR_INVALID_PARAMETER, "[ERROR] Fail to get client");
462
463         tts_tidl_info_s* info = __get_tidl_info_s(uid);
464         RETVM_IF(NULL == info, TTS_ERROR_INVALID_PARAMETER, "[ERROR] Fail to get tidl info");
465
466         RETVM_IF(!info->connected, TTS_ERROR_OPERATION_FAILED, "[ERROR] Not Connected");
467
468         bool temp;
469         int ret = rpc_port_proxy_tts_invoke_initialize(info->rpc_h, client->pid, uid, (int)mode, &temp);
470         int exception = get_last_result();
471         if (RPC_PORT_ERROR_NONE != exception) {
472                 ret = __convert_unhandled_error(exception);
473         }
474
475         if (TTS_ERROR_NONE != ret) {
476                 SLOG(LOG_ERROR, TAG_TTSC, ">>>> Request tts initialize : Fail to invoke message");
477                 return ret;
478         }
479
480         *credential_needed = temp;
481
482         SLOG(LOG_DEBUG, TAG_TTSC, "<<<< tts initialize : credential_needed(%d)", *credential_needed);
483
484         return TTS_ERROR_NONE;
485 }
486
487 int tts_tidl_request_finalize(unsigned int uid)
488 {
489         SLOG(LOG_DEBUG, TAG_TTSC, "[TIDL] tts_tidl_request_finalize");
490
491         tts_client_s* client = tts_client_get_by_uid(uid);
492                 RETVM_IF(NULL == client, TTS_ERROR_INVALID_PARAMETER, "[ERROR] Fail to get client");
493
494         tts_tidl_info_s* info = __get_tidl_info_s(uid);
495         RETVM_IF(NULL == info, TTS_ERROR_INVALID_PARAMETER, "[ERROR] Fail to get tidl info");
496
497         RETVM_IF(!info->connected, TTS_ERROR_OPERATION_FAILED, "[ERROR] Not Connected");
498
499
500         int ret = rpc_port_proxy_tts_invoke_finalize(info->rpc_h, uid);
501         int exception = get_last_result();
502         if (RPC_PORT_ERROR_NONE != exception) {
503                 ret = __convert_unhandled_error(exception);
504         }
505
506         if (TTS_ERROR_NONE != ret) {
507                 SLOG(LOG_ERROR, TAG_TTSC, ">>>> Request tts initialize : Fail to invoke message");
508                 return ret;
509         }
510
511         tts_client_set_start_listening(uid, false);
512         return TTS_ERROR_NONE;
513 }
514
515 int tts_tidl_request_add_text(unsigned int uid, const char* text, const char* lang, int vctype, int speed, int uttid, const char* credential)
516 {
517         SLOG(LOG_DEBUG, TAG_TTSC, "[TIDL] tts_tidl_request_add_text");
518
519         tts_client_s* client = tts_client_get_by_uid(uid);
520         RETVM_IF(NULL == client, TTS_ERROR_INVALID_PARAMETER, "[ERROR] Fail to get client");
521
522         tts_tidl_info_s* info = __get_tidl_info_s(uid);
523         RETVM_IF(NULL == info, TTS_ERROR_INVALID_PARAMETER, "[ERROR] Fail to get tidl info");
524
525         RETVM_IF(NULL == text || NULL == lang, TTS_ERROR_INVALID_PARAMETER, "Input parameter is NULL");
526
527         RETVM_IF(!info->connected, TTS_ERROR_OPERATION_FAILED, "[ERROR] Not Connected");
528
529
530         const char *not_null_credential = NULL == credential ? "NULL" : credential;
531         int ret = rpc_port_proxy_tts_invoke_add_text(info->rpc_h, uid, text, lang, vctype, speed, uttid, not_null_credential);
532         int exception = get_last_result();
533         if (RPC_PORT_ERROR_NONE != exception) {
534                 ret = __convert_unhandled_error(exception);
535         }
536
537         if (TTS_ERROR_NONE != ret) {
538                 SLOG(LOG_ERROR, TAG_TTSC, ">>>> Request add text : Fail to invoke message");
539                 return ret;
540         }
541
542         return TTS_ERROR_NONE;
543 }
544
545 int tts_tidl_request_set_private_data(unsigned int uid, const char* key, const char* data)
546 {
547         SLOG(LOG_DEBUG, TAG_TTSC, "[TIDL] tts_tidl_request_set_private_data");
548
549         tts_client_s* client = tts_client_get_by_uid(uid);
550         RETVM_IF(NULL == client, TTS_ERROR_INVALID_PARAMETER, "[ERROR] Fail to get client");
551
552         tts_tidl_info_s* info = __get_tidl_info_s(uid);
553         RETVM_IF(NULL == info, TTS_ERROR_INVALID_PARAMETER, "[ERROR] Fail to get tidl info");
554
555         RETVM_IF(NULL == key || NULL == data, TTS_ERROR_INVALID_PARAMETER, "Input parameter is NULL");
556
557         RETVM_IF(!info->connected, TTS_ERROR_OPERATION_FAILED, "[ERROR] Not Connected");
558
559
560         int ret = rpc_port_proxy_tts_invoke_set_private(info->rpc_h, uid, key, data);
561         int exception = get_last_result();
562         if (RPC_PORT_ERROR_NONE != exception) {
563                 ret = __convert_unhandled_error(exception);
564         }
565
566         if (TTS_ERROR_NONE != ret) {
567                 SLOG(LOG_ERROR, TAG_TTSC, ">>>> Request set private data : Fail to invoke message");
568                 return ret;
569         }
570
571         return TTS_ERROR_NONE;
572 }
573
574 int tts_tidl_request_get_private_data(unsigned int uid, const char* key, char** data)
575 {
576         SLOG(LOG_DEBUG, TAG_TTSC, "[TIDL] tts_tidl_request_get_private_data");
577
578         tts_client_s* client = tts_client_get_by_uid(uid);
579         RETVM_IF(NULL == client, TTS_ERROR_INVALID_PARAMETER, "[ERROR] Fail to get client");
580
581         tts_tidl_info_s* info = __get_tidl_info_s(uid);
582         RETVM_IF(NULL == info, TTS_ERROR_INVALID_PARAMETER, "[ERROR] Fail to get tidl info");
583
584         RETVM_IF(NULL == key || NULL == data, TTS_ERROR_INVALID_PARAMETER, "Input parameter is NULL");
585
586         RETVM_IF(!info->connected, TTS_ERROR_OPERATION_FAILED, "[ERROR] Not Connected");
587
588         char *tmp = NULL;
589         int ret = rpc_port_proxy_tts_invoke_get_private(info->rpc_h, uid, key, &tmp);
590         int exception = get_last_result();
591         if (RPC_PORT_ERROR_NONE != exception) {
592                 ret = __convert_unhandled_error(exception);
593         }
594
595         if (TTS_ERROR_NONE != ret) {
596                 SLOG(LOG_ERROR, TAG_TTSC, ">>>> Request get private data : Fail to invoke message");
597                 free(tmp);
598                 return ret;
599         }
600
601         *data = tmp;
602         SLOG(LOG_DEBUG, TAG_TTSC, "<<<<");
603
604         return TTS_ERROR_NONE;
605 }
606
607 int tts_tidl_request_play(unsigned int uid, const char* credential)
608 {
609         SLOG(LOG_DEBUG, TAG_TTSC, "[TIDL] tts_tidl_request_play");
610
611         tts_client_s* client = tts_client_get_by_uid(uid);
612         RETVM_IF(NULL == client, TTS_ERROR_INVALID_PARAMETER, "[ERROR] Fail to get client");
613
614         tts_tidl_info_s* info = __get_tidl_info_s(uid);
615         RETVM_IF(NULL == info, TTS_ERROR_INVALID_PARAMETER, "[ERROR] Fail to get tidl info");
616
617         RETVM_IF(!info->connected, TTS_ERROR_OPERATION_FAILED, "[ERROR] Not Connected");
618
619         const char *not_null_credential = NULL == credential ? "NULL" : credential;
620         int ret = rpc_port_proxy_tts_invoke_play(info->rpc_h, uid, not_null_credential);
621         int exception = get_last_result();
622         if (RPC_PORT_ERROR_NONE != exception) {
623                 ret = __convert_unhandled_error(exception);
624         }
625
626         if (TTS_ERROR_NONE != ret) {
627                 SLOG(LOG_ERROR, TAG_TTSC, ">>>> Request play : Fail to invoke message");
628                 return ret;
629         }
630
631         SLOG(LOG_DEBUG, TAG_TTSC, "<<<<");
632
633         return TTS_ERROR_NONE;
634 }
635
636 int tts_tidl_request_stop(unsigned int uid)
637 {
638         SLOG(LOG_DEBUG, TAG_TTSC, "[TIDL] tts_tidl_request_stop");
639
640         tts_client_s* client = tts_client_get_by_uid(uid);
641         RETVM_IF(NULL == client, TTS_ERROR_INVALID_PARAMETER, "[ERROR] Fail to get client");
642
643         tts_tidl_info_s* info = __get_tidl_info_s(uid);
644         RETVM_IF(NULL == info, TTS_ERROR_INVALID_PARAMETER, "[ERROR] Fail to get tidl info");
645
646         RETVM_IF(!info->connected, TTS_ERROR_OPERATION_FAILED, "[ERROR] Not Connected");
647
648         int ret = rpc_port_proxy_tts_invoke_stop(info->rpc_h, uid);
649         int exception = get_last_result();
650         if (RPC_PORT_ERROR_NONE != exception) {
651                 ret = __convert_unhandled_error(exception);
652         }
653
654         if (TTS_ERROR_NONE != ret) {
655                 SLOG(LOG_ERROR, TAG_TTSC, ">>>> Request stop : Fail to invoke message");
656                 return ret;
657         }
658         SLOG(LOG_DEBUG, TAG_TTSC, "<<<<");
659
660         return TTS_ERROR_NONE;
661 }
662
663 int tts_tidl_request_pause(unsigned int uid)
664 {
665         SLOG(LOG_DEBUG, TAG_TTSC, "[TIDL] tts_tidl_request_pause");
666
667         tts_client_s* client = tts_client_get_by_uid(uid);
668         RETVM_IF(NULL == client, TTS_ERROR_INVALID_PARAMETER, "[ERROR] Fail to get client");
669
670         tts_tidl_info_s* info = __get_tidl_info_s(uid);
671         RETVM_IF(NULL == info, TTS_ERROR_INVALID_PARAMETER, "[ERROR] Fail to get tidl info");
672
673         RETVM_IF(!info->connected, TTS_ERROR_OPERATION_FAILED, "[ERROR] Not Connected");
674
675         int ret = rpc_port_proxy_tts_invoke_pause(info->rpc_h, uid);
676         int exception = get_last_result();
677         if (RPC_PORT_ERROR_NONE != exception) {
678                 ret = __convert_unhandled_error(exception);
679         }
680
681         if (TTS_ERROR_NONE != ret) {
682                 SLOG(LOG_ERROR, TAG_TTSC, ">>>> Request pause : Fail to invoke message(%d)", ret);
683                 return ret;
684         }
685
686         SLOG(LOG_DEBUG, TAG_TTSC, "<<<<");
687
688         return TTS_ERROR_NONE;
689 }
690
691 int tts_tidl_request_play_pcm(unsigned int uid)
692 {
693         SLOG(LOG_DEBUG, TAG_TTSC, "[TIDL] tts_tidl_request_play_pcm");
694
695         tts_client_s* client = tts_client_get_by_uid(uid);
696         RETVM_IF(NULL == client, TTS_ERROR_INVALID_PARAMETER, "[ERROR] Fail to get client");
697
698         tts_tidl_info_s* info = __get_tidl_info_s(uid);
699         RETVM_IF(NULL == info, TTS_ERROR_INVALID_PARAMETER, "[ERROR] Fail to get tidl info");
700
701         RETVM_IF(!info->connected, TTS_ERROR_OPERATION_FAILED, "[ERROR] Not Connected");
702
703         int ret = rpc_port_proxy_tts_invoke_play_pcm(info->rpc_h, uid);
704         int exception = get_last_result();
705         if (RPC_PORT_ERROR_NONE != exception) {
706                 ret = __convert_unhandled_error(exception);
707         }
708
709         if (TTS_ERROR_NONE != ret) {
710                 SLOG(LOG_ERROR, TAG_TTSC, ">>>> Request play pcm : Fail to invoke message(%d)", ret);
711                 return ret;
712         }
713
714         SLOG(LOG_DEBUG, TAG_TTSC, "<<<<");
715
716         return TTS_ERROR_NONE;
717 }
718
719 int tts_tidl_request_stop_pcm(unsigned int uid)
720 {
721         SLOG(LOG_DEBUG, TAG_TTSC, "[TIDL] tts_tidl_request_stop_pcm");
722
723         tts_client_s* client = tts_client_get_by_uid(uid);
724         RETVM_IF(NULL == client, TTS_ERROR_INVALID_PARAMETER, "[ERROR] Fail to get client");
725
726         tts_tidl_info_s* info = __get_tidl_info_s(uid);
727         RETVM_IF(NULL == info, TTS_ERROR_INVALID_PARAMETER, "[ERROR] Fail to get tidl info");
728
729         RETVM_IF(!info->connected, TTS_ERROR_OPERATION_FAILED, "[ERROR] Not Connected");
730
731         int ret = rpc_port_proxy_tts_invoke_stop_pcm(info->rpc_h, uid);
732         int exception = get_last_result();
733         if (RPC_PORT_ERROR_NONE != exception) {
734                 ret = __convert_unhandled_error(exception);
735         }
736
737         if (TTS_ERROR_NONE != ret) {
738                 SLOG(LOG_ERROR, TAG_TTSC, ">>>> Request pause pcm : Fail to invoke message(%d)", ret);
739                 return ret;
740         }
741
742         SLOG(LOG_DEBUG, TAG_TTSC, "<<<<");
743
744         return TTS_ERROR_NONE;
745 }
746
747 int tts_tidl_request_add_pcm(unsigned int uid, int event, const char* data, int data_size, int audio_type, int rate)
748 {
749         SLOG(LOG_DEBUG, TAG_TTSC, "[TIDL] tts_tidl_request_add_pcm");
750
751         tts_client_s* client = tts_client_get_by_uid(uid);
752         RETVM_IF(NULL == client, TTS_ERROR_INVALID_PARAMETER, "[ERROR] Fail to get client");
753
754         tts_tidl_info_s* info = __get_tidl_info_s(uid);
755         RETVM_IF(NULL == info, TTS_ERROR_INVALID_PARAMETER, "[ERROR] Fail to get tidl info");
756
757         RETVM_IF(!info->connected, TTS_ERROR_OPERATION_FAILED, "[ERROR] Not Connected");
758
759         rpc_port_proxy_array_char_h pcm_data = NULL;
760         rpc_port_proxy_array_char_create(&pcm_data);
761         if (NULL == pcm_data) {
762                 SLOG(LOG_ERROR, TAG_TTSC, "[ERROR] Fail to create data handle");
763                 return TTS_ERROR_OUT_OF_MEMORY;
764         }
765
766         if (NULL != data && 0 < data_size) {
767                 rpc_port_proxy_array_char_set(pcm_data, (char*)data, data_size);
768         } else {
769                 SLOG(LOG_INFO, TAG_TTSC, "[TIDL] data is empty");
770         }
771
772         int ret = rpc_port_proxy_tts_invoke_add_pcm(info->rpc_h, uid, event, pcm_data, data_size, audio_type, rate);
773         rpc_port_proxy_array_char_destroy(pcm_data);
774         int exception = get_last_result();
775         if (RPC_PORT_ERROR_NONE != exception) {
776                 ret = __convert_unhandled_error(exception);
777         }
778
779         if (TTS_ERROR_NONE != ret) {
780                 SLOG(LOG_ERROR, TAG_TTSC, ">>>> Request pause pcm : Fail to invoke message(%d)", ret);
781                 return ret;
782         }
783
784         SLOG(LOG_DEBUG, TAG_TTSC, "<<<<");
785
786         return TTS_ERROR_NONE;
787 }