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.
16 #include "tts_proxy.h"
17 #include "tts_internal.h"
18 #include "tts_client.h"
23 #define MAX_CONNECT_CHECK 100
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;
35 static GList* g_tidl_infos = NULL;
38 static tts_tidl_info_s* __get_tidl_info_s(unsigned int uid)
41 tts_tidl_info_s* info = NULL;
43 if (g_list_length(g_tidl_infos) > 0) {
44 /* Get a first item */
45 iter = g_list_first(g_tidl_infos);
47 while (NULL != iter) {
50 if (info->uid == uid) {
55 iter = g_list_next(iter);
62 static void __notify_cb(void *user_data, int pid, int uid, bundle *msg)
66 tts_client_s* client = tts_client_get_by_uid(uid);
67 RETM_IF(NULL == client, "[ERROR] Fail to get client");
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);
72 bundle_get_str(msg, TTS_BUNDLE_METHOD, &method);
74 if (0 == strncmp(TTSD_METHOD_HELLO, method, strlen(TTSD_METHOD_HELLO))) {
75 char* credential_needed = NULL;
77 bundle_get_str(msg, TTS_BUNDLE_CREDENTIAL_NEEDED, &credential_needed);
78 bundle_get_str(msg, TTS_BUNDLE_REASON, &ret);
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));
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;
88 SLOG(LOG_ERROR, TAG_TTSC, "[ERROR] Fail to get message(TTSD_METHOD_HELLO). pid(%d) uid(%u)", pid, u_uid);
90 } else if (0 == strncmp(TTSD_METHOD_UTTERANCE_STARTED, method, strlen(TTSD_METHOD_UTTERANCE_STARTED))) {
91 bundle_get_str(msg, TTS_BUNDLE_MESSAGE, &val);
93 tts_core_notify_utt_started(client, atoi(val));
95 } else if (0 == strncmp(TTSD_METHOD_UTTERANCE_COMPLETED, method, strlen(TTSD_METHOD_UTTERANCE_COMPLETED))) {
96 bundle_get_str(msg, TTS_BUNDLE_MESSAGE, &val);
98 tts_core_notify_utt_completeted(client, atoi(val));
100 } else if (0 == strncmp(TTSD_METHOD_SET_STATE, method, strlen(TTSD_METHOD_SET_STATE))) {
101 bundle_get_str(msg, TTS_BUNDLE_MESSAGE, &val);
103 tts_core_notify_state_changed(client, (tts_state_e)atoi(val));
105 } else if (0 == strncmp(TTSD_METHOD_ERROR, method, strlen(TTSD_METHOD_ERROR))) {
108 char *err_msg = NULL;
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);
117 SLOG(LOG_ERROR, TAG_TTSC, "[ERROR] Invalid msg");
121 static void __on_connected(rpc_port_proxy_tts_h h, void *user_data)
123 unsigned int uid = (uintptr_t)user_data;
125 tts_client_s* client = tts_client_get_by_uid(uid);
126 RETM_IF(NULL == client, "[ERROR] Fail to get client");
128 tts_tidl_info_s* info = __get_tidl_info_s(uid);
129 RETM_IF(NULL == info, "[ERROR] Fail to get tidl info");
131 info->connected = true;
132 info->connection_requesting = false;
133 info->register_callback_invoked = false;
135 SLOG(LOG_DEBUG, TAG_TTSC, "Connected to server");
138 static void __on_disconnected(rpc_port_proxy_tts_h h, void *user_data)
140 unsigned int uid = (uintptr_t)user_data;
142 tts_client_s* client = tts_client_get_by_uid(uid);
143 RETM_IF(NULL == client, "[ERROR] Fail to get client");
145 tts_tidl_info_s* info = __get_tidl_info_s(uid);
146 RETM_IF(NULL == info, "[ERROR] Fail to get tidl info");
148 info->connected = false;
149 info->connection_requesting = false;
150 info->register_callback_invoked = false;
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();
160 static void __on_rejected(rpc_port_proxy_tts_h h, void *user_data)
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");
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;
171 SLOG(LOG_ERROR, TAG_TTSC, "[ERROR] Rejected from server(%d)", uid);
175 static void __get_engine_app_id(int size, char* app_id)
177 RETM_IF(NULL == app_id, "app_id is NULL");
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);
185 snprintf(app_id, size, "%s", engine_name);
188 SLOG(LOG_INFO, TAG_TTSC, "engine app id : %s", app_id);
191 static rpc_port_proxy_tts_h __create_rpc_port(unsigned int uid, const char* engine_app_id)
193 rpc_port_proxy_tts_callback_s rpc_callback = {
194 .connected = __on_connected,
195 .disconnected = __on_disconnected,
196 .rejected = __on_rejected
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");
209 int tts_tidl_open_connection(unsigned int uid)
211 SLOG(LOG_DEBUG, TAG_TTSC, "[TIDL] tts_tidl_open_connection");
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");
216 tts_tidl_info_s* info = (tts_tidl_info_s*)calloc(1, sizeof(tts_tidl_info_s));
218 SLOG(LOG_ERROR, TAG_TTSC, "[TIDL ERROR] Fail to create tidl_info_s");
219 return TTS_ERROR_OUT_OF_MEMORY;
222 char engine_app_id[TTS_ENGINE_APPID_LEN] = {0, };
223 __get_engine_app_id(TTS_ENGINE_APPID_LEN, engine_app_id);
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");
229 return TTS_ERROR_OPERATION_FAILED;
232 info->engine_app_id = strdup(engine_app_id);
234 g_tidl_infos = g_list_append(g_tidl_infos, info);
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;
240 int tts_tidl_close_connection(unsigned int uid)
242 SLOG(LOG_DEBUG, TAG_TTSC, "[TIDL] tts_tidl_close_connection");
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");
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");
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;
256 info->notify_cb_h = NULL;
258 free(info->engine_app_id);
259 info->engine_app_id = NULL;
261 g_tidl_infos = g_list_remove(g_tidl_infos, info);
264 return TTS_ERROR_NONE;
267 int tts_tidl_stop_listening(unsigned int uid)
269 RETVM_IF(false == tts_client_is_valid_uid(uid), TTS_ERROR_INVALID_PARAMETER, "[ERROR] uid is not valid");
271 tts_client_set_start_listening(uid, false);
273 return TTS_ERROR_NONE;
276 static void __request_tidl_connect(tts_tidl_info_s* info)
278 if (info->connection_requesting) {
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);
288 SLOG(LOG_INFO, TAG_TTSC, "[INFO] Request connection to stub. ret(%d)", ret);
290 info->connection_requesting = true;
293 static int __create_notify_callback_handle(tts_tidl_info_s* info)
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;
300 if (RPC_PORT_ERROR_NONE != rpc_port_proxy_tts_notify_cb_create(&info->notify_cb_h)) {
301 return TTS_ERROR_OUT_OF_MEMORY;
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);
307 return TTS_ERROR_NONE;
310 static int __invoke_register_callback(int pid, tts_mode_e mode, tts_tidl_info_s* info)
312 if (info->register_callback_invoked) {
313 SLOG(LOG_ERROR, TAG_TTSC, "[INFO] Already register callback is invoked");
314 return TTS_ERROR_NONE;
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);
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;
328 int tts_tidl_request_hello(unsigned int uid, tts_mode_e mode)
330 SLOG(LOG_DEBUG, TAG_TTSC, "[TIDL] tts_tidl_request_hello");
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");
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");
338 char engine_app_id[TTS_ENGINE_APPID_LEN] = {0, };
339 __get_engine_app_id(TTS_ENGINE_APPID_LEN, engine_app_id);
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;
347 info->notify_cb_h = NULL;
348 info->register_callback_invoked = false;
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;
355 free(info->engine_app_id);
356 info->engine_app_id = strdup(engine_app_id);
357 info->connection_requesting = false;
360 if (!info->connected) {
361 SLOG(LOG_ERROR, TAG_TTSC, "[ERROR] Not Connected");
362 __request_tidl_connect(info);
363 return TTS_ERROR_OPERATION_FAILED;
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;
372 SLOG(LOG_DEBUG, TAG_TTSC, "<<<<");
373 return TTS_ERROR_NONE;
376 static int __request_tidl_connect_sync(tts_tidl_info_s* info)
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;
384 return TTS_ERROR_OPERATION_FAILED;
387 static int __convert_unhandled_error(int ret)
389 if (RPC_PORT_ERROR_IO_ERROR == ret || RPC_PORT_ERROR_OUT_OF_MEMORY == ret) {
390 return TTS_ERROR_OPERATION_FAILED;
396 static int __invoke_register_callback_sync(int pid, tts_tidl_info_s* info)
398 if (info->register_callback_invoked) {
399 SLOG(LOG_ERROR, TAG_TTSC, "[INFO] Already register callback is invoked");
400 return TTS_ERROR_NONE;
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));
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);
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));
421 info->register_callback_invoked = true;
422 return TTS_ERROR_NONE;
425 int tts_tidl_request_hello_sync(unsigned int uid)
427 SLOG(LOG_DEBUG, TAG_TTSC, "[TIDL] tts_tidl_request_hello");
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");
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");
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;
443 SLOG(LOG_INFO, TAG_TTSC, "[TIDL] Stub is Connected");
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;
452 SLOG(LOG_DEBUG, TAG_TTSC, "<<<<");
453 return TTS_ERROR_NONE;
456 int tts_tidl_request_initialize(unsigned int uid, tts_mode_e mode, bool* credential_needed)
458 SLOG(LOG_DEBUG, TAG_TTSC, "[TIDL] tts_tidl_request_initialize");
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");
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");
466 RETVM_IF(!info->connected, TTS_ERROR_OPERATION_FAILED, "[ERROR] Not Connected");
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);
475 if (TTS_ERROR_NONE != ret) {
476 SLOG(LOG_ERROR, TAG_TTSC, ">>>> Request tts initialize : Fail to invoke message");
480 *credential_needed = temp;
482 SLOG(LOG_DEBUG, TAG_TTSC, "<<<< tts initialize : credential_needed(%d)", *credential_needed);
484 return TTS_ERROR_NONE;
487 int tts_tidl_request_finalize(unsigned int uid)
489 SLOG(LOG_DEBUG, TAG_TTSC, "[TIDL] tts_tidl_request_finalize");
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");
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");
497 RETVM_IF(!info->connected, TTS_ERROR_OPERATION_FAILED, "[ERROR] Not Connected");
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);
506 if (TTS_ERROR_NONE != ret) {
507 SLOG(LOG_ERROR, TAG_TTSC, ">>>> Request tts initialize : Fail to invoke message");
511 tts_client_set_start_listening(uid, false);
512 return TTS_ERROR_NONE;
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)
517 SLOG(LOG_DEBUG, TAG_TTSC, "[TIDL] tts_tidl_request_add_text");
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");
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");
525 RETVM_IF(NULL == text || NULL == lang, TTS_ERROR_INVALID_PARAMETER, "Input parameter is NULL");
527 RETVM_IF(!info->connected, TTS_ERROR_OPERATION_FAILED, "[ERROR] Not Connected");
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);
537 if (TTS_ERROR_NONE != ret) {
538 SLOG(LOG_ERROR, TAG_TTSC, ">>>> Request add text : Fail to invoke message");
542 return TTS_ERROR_NONE;
545 int tts_tidl_request_set_private_data(unsigned int uid, const char* key, const char* data)
547 SLOG(LOG_DEBUG, TAG_TTSC, "[TIDL] tts_tidl_request_set_private_data");
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");
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");
555 RETVM_IF(NULL == key || NULL == data, TTS_ERROR_INVALID_PARAMETER, "Input parameter is NULL");
557 RETVM_IF(!info->connected, TTS_ERROR_OPERATION_FAILED, "[ERROR] Not Connected");
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);
566 if (TTS_ERROR_NONE != ret) {
567 SLOG(LOG_ERROR, TAG_TTSC, ">>>> Request set private data : Fail to invoke message");
571 return TTS_ERROR_NONE;
574 int tts_tidl_request_get_private_data(unsigned int uid, const char* key, char** data)
576 SLOG(LOG_DEBUG, TAG_TTSC, "[TIDL] tts_tidl_request_get_private_data");
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");
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");
584 RETVM_IF(NULL == key || NULL == data, TTS_ERROR_INVALID_PARAMETER, "Input parameter is NULL");
586 RETVM_IF(!info->connected, TTS_ERROR_OPERATION_FAILED, "[ERROR] Not Connected");
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);
595 if (TTS_ERROR_NONE != ret) {
596 SLOG(LOG_ERROR, TAG_TTSC, ">>>> Request get private data : Fail to invoke message");
602 SLOG(LOG_DEBUG, TAG_TTSC, "<<<<");
604 return TTS_ERROR_NONE;
607 int tts_tidl_request_play(unsigned int uid, const char* credential)
609 SLOG(LOG_DEBUG, TAG_TTSC, "[TIDL] tts_tidl_request_play");
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");
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");
617 RETVM_IF(!info->connected, TTS_ERROR_OPERATION_FAILED, "[ERROR] Not Connected");
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);
626 if (TTS_ERROR_NONE != ret) {
627 SLOG(LOG_ERROR, TAG_TTSC, ">>>> Request play : Fail to invoke message");
631 SLOG(LOG_DEBUG, TAG_TTSC, "<<<<");
633 return TTS_ERROR_NONE;
636 int tts_tidl_request_stop(unsigned int uid)
638 SLOG(LOG_DEBUG, TAG_TTSC, "[TIDL] tts_tidl_request_stop");
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");
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");
646 RETVM_IF(!info->connected, TTS_ERROR_OPERATION_FAILED, "[ERROR] Not Connected");
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);
654 if (TTS_ERROR_NONE != ret) {
655 SLOG(LOG_ERROR, TAG_TTSC, ">>>> Request stop : Fail to invoke message");
658 SLOG(LOG_DEBUG, TAG_TTSC, "<<<<");
660 return TTS_ERROR_NONE;
663 int tts_tidl_request_pause(unsigned int uid)
665 SLOG(LOG_DEBUG, TAG_TTSC, "[TIDL] tts_tidl_request_pause");
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");
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");
673 RETVM_IF(!info->connected, TTS_ERROR_OPERATION_FAILED, "[ERROR] Not Connected");
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);
681 if (TTS_ERROR_NONE != ret) {
682 SLOG(LOG_ERROR, TAG_TTSC, ">>>> Request pause : Fail to invoke message(%d)", ret);
686 SLOG(LOG_DEBUG, TAG_TTSC, "<<<<");
688 return TTS_ERROR_NONE;
691 int tts_tidl_request_play_pcm(unsigned int uid)
693 SLOG(LOG_DEBUG, TAG_TTSC, "[TIDL] tts_tidl_request_play_pcm");
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");
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");
701 RETVM_IF(!info->connected, TTS_ERROR_OPERATION_FAILED, "[ERROR] Not Connected");
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);
709 if (TTS_ERROR_NONE != ret) {
710 SLOG(LOG_ERROR, TAG_TTSC, ">>>> Request play pcm : Fail to invoke message(%d)", ret);
714 SLOG(LOG_DEBUG, TAG_TTSC, "<<<<");
716 return TTS_ERROR_NONE;
719 int tts_tidl_request_stop_pcm(unsigned int uid)
721 SLOG(LOG_DEBUG, TAG_TTSC, "[TIDL] tts_tidl_request_stop_pcm");
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");
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");
729 RETVM_IF(!info->connected, TTS_ERROR_OPERATION_FAILED, "[ERROR] Not Connected");
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);
737 if (TTS_ERROR_NONE != ret) {
738 SLOG(LOG_ERROR, TAG_TTSC, ">>>> Request pause pcm : Fail to invoke message(%d)", ret);
742 SLOG(LOG_DEBUG, TAG_TTSC, "<<<<");
744 return TTS_ERROR_NONE;
747 int tts_tidl_request_add_pcm(unsigned int uid, int event, const char* data, int data_size, int audio_type, int rate)
749 SLOG(LOG_DEBUG, TAG_TTSC, "[TIDL] tts_tidl_request_add_pcm");
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");
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");
757 RETVM_IF(!info->connected, TTS_ERROR_OPERATION_FAILED, "[ERROR] Not Connected");
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;
766 if (NULL != data && 0 < data_size) {
767 rpc_port_proxy_array_char_set(pcm_data, (char*)data, data_size);
769 SLOG(LOG_INFO, TAG_TTSC, "[TIDL] data is empty");
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);
779 if (TTS_ERROR_NONE != ret) {
780 SLOG(LOG_ERROR, TAG_TTSC, ">>>> Request pause pcm : Fail to invoke message(%d)", ret);
784 SLOG(LOG_DEBUG, TAG_TTSC, "<<<<");
786 return TTS_ERROR_NONE;