From aa014acf126ef7d03091bcf513b7c838396bacad Mon Sep 17 00:00:00 2001 From: Suyeon Hwang Date: Tue, 6 Apr 2021 18:36:57 +0900 Subject: [PATCH] Use tts_ipc_method_e on server side To match the method handling of client and server, this patch change the code to use tts_ipc_method_e on server. Using tts_ipc_method_e, server can be expanded to use other ipc method. And also, server can clearly know which ipc method is used by client. Change-Id: I48c98fb567d00fcaff805715bb6c097cc3caddde Signed-off-by: Suyeon Hwang --- client/tts_ipc.h | 7 +-- common/tts_ipc_method.h | 31 ++++++++++ server/ttsd_data.cpp | 30 ++++++---- server/ttsd_data.h | 5 +- server/ttsd_dbus_server.c | 22 +++---- server/ttsd_ipc.c | 146 ++++++++++++++++++++++------------------------ server/ttsd_ipc.h | 3 - server/ttsd_server.c | 7 ++- server/ttsd_server.h | 5 +- server/ttsd_tidl.c | 4 +- 10 files changed, 147 insertions(+), 113 deletions(-) create mode 100644 common/tts_ipc_method.h diff --git a/client/tts_ipc.h b/client/tts_ipc.h index dad79ff..68b43a3 100644 --- a/client/tts_ipc.h +++ b/client/tts_ipc.h @@ -14,6 +14,7 @@ #define __TTS_IPC_H_ #include "tts_client.h" +#include "tts_ipc_method.h" #ifdef __cplusplus extern "C" { @@ -37,12 +38,6 @@ typedef enum { REQUEST_ADD_PCM } tts_ipc_vtable_e; -typedef enum { - TTS_IPC_METHOD_UNDEFINED = -1, - TTS_IPC_METHOD_DBUS, - TTS_IPC_METHOD_TIDL -} tts_ipc_method_e; - int tts_ipc_set_method(tts_ipc_method_e method); int tts_ipc_get_method(tts_ipc_method_e* method); diff --git a/common/tts_ipc_method.h b/common/tts_ipc_method.h new file mode 100644 index 0000000..f956473 --- /dev/null +++ b/common/tts_ipc_method.h @@ -0,0 +1,31 @@ +/* +* Copyright (c) 2021 Samsung Electronics Co., Ltd All Rights Reserved +* Licensed under the Apache License, Version 2.0 (the "License"); +* you may not use this file except in compliance with the License. +* You may obtain a copy of the License at +* http://www.apache.org/licenses/LICENSE-2.0 +* Unless required by applicable law or agreed to in writing, software +* distributed under the License is distributed on an "AS IS" BASIS, +* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +* See the License for the specific language governing permissions and +* limitations under the License. +*/ + +#ifndef __TTS_IPC_METHOD_H__ +#define __TTS_IPC_METHOD_H__ + +#ifdef __cplusplus +extern "C" { +#endif + +typedef enum { + TTS_IPC_METHOD_UNDEFINED = -1, + TTS_IPC_METHOD_DBUS, + TTS_IPC_METHOD_TIDL +} tts_ipc_method_e; + +#ifdef __cplusplus +} +#endif + +#endif \ No newline at end of file diff --git a/server/ttsd_data.cpp b/server/ttsd_data.cpp index 7d2b8d4..da73d6d 100644 --- a/server/ttsd_data.cpp +++ b/server/ttsd_data.cpp @@ -39,7 +39,7 @@ typedef struct std::list m_used_voice; rpc_port_tts_notify_cb_h notify_cb_h; - bool ipc_tidl; + tts_ipc_method_e ipc_method; } app_data_s; static vector g_app_list; @@ -167,7 +167,7 @@ int ttsd_data_new_client(int pid, int uid) app.utt_id_stopped = 0; app.state = APP_STATE_READY; app.notify_cb_h = NULL; - app.ipc_tidl = false; + app.ipc_method = TTS_IPC_METHOD_UNDEFINED; g_app_list.insert(g_app_list.end(), app); @@ -246,25 +246,35 @@ int ttsd_data_get_pid(int uid) return g_app_list[index].pid; } -bool ttsd_data_is_client_use_tidl(int uid) +int ttsd_data_set_ipc_method(int uid, tts_ipc_method_e method) { - int index; + int index = ttsd_data_is_client(uid); + if (index < 0) { + SECURE_SLOG(LOG_ERROR, tts_tag(), "[DATA ERROR] uid is not valid (%d)", uid); + return TTSD_ERROR_INVALID_PARAMETER; + } - index = ttsd_data_is_client(uid); + g_app_list[index].ipc_method = method; - if (index < 0) { + return TTSD_ERROR_NONE; +} + +tts_ipc_method_e ttsd_data_get_ipc_method(int uid) +{ + int index = ttsd_data_is_client(uid); + if (index < 0) { SECURE_SLOG(LOG_ERROR, tts_tag(), "[DATA ERROR] uid is not valid (%d)", uid); - return false; + return TTS_IPC_METHOD_UNDEFINED; } - return g_app_list[index].ipc_tidl; + return g_app_list[index].ipc_method; } int ttsd_data_set_notify_h(int uid, rpc_port_tts_notify_cb_h handle, void* user_data) { int index = ttsd_data_is_client(uid); - if (index < 0) { + if (index < 0) { SECURE_SLOG(LOG_ERROR, tts_tag(), "[DATA ERROR] uid is not valid (%d)", uid); return TTSD_ERROR_INVALID_PARAMETER; } @@ -273,8 +283,6 @@ int ttsd_data_set_notify_h(int uid, rpc_port_tts_notify_cb_h handle, void* user_ return TTSD_ERROR_OPERATION_FAILED; } - g_app_list[index].ipc_tidl = true; - return TTSD_ERROR_NONE; } diff --git a/server/ttsd_data.h b/server/ttsd_data.h index e500869..c127d84 100644 --- a/server/ttsd_data.h +++ b/server/ttsd_data.h @@ -17,6 +17,7 @@ #include "ttse.h" #include "ttsd_stub.h" +#include "tts_ipc_method.h" #ifdef __cplusplus extern "C" { @@ -71,7 +72,9 @@ int ttsd_data_get_client_count(); int ttsd_data_get_pid(int uid); -bool ttsd_data_is_client_use_tidl(int uid); +int ttsd_data_set_ipc_method(int uid, tts_ipc_method_e method); + +tts_ipc_method_e ttsd_data_get_ipc_method(int uid); int ttsd_data_set_notify_h(int uid, rpc_port_tts_notify_cb_h handle, void* user_data); diff --git a/server/ttsd_dbus_server.c b/server/ttsd_dbus_server.c index 1e096d7..c0adacf 100644 --- a/server/ttsd_dbus_server.c +++ b/server/ttsd_dbus_server.c @@ -45,7 +45,7 @@ int ttsd_dbus_server_hello(DBusConnection* conn, DBusMessage* msg) ttsd_server_is_already_initialized(pid, uid, &is_initialized); if (false == is_initialized) { - ret = ttsd_server_initialize(pid, uid, &is_credential_needed); + ret = ttsd_server_initialize(pid, uid, TTS_IPC_METHOD_DBUS, &is_credential_needed); if (0 != ret) { SLOG(LOG_ERROR, tts_tag(), "[IN ERROR] ttsd Hello : server initialize, ret(%d)", ret); } @@ -111,7 +111,7 @@ int ttsd_dbus_server_initialize(DBusConnection* conn, DBusMessage* msg) } else { SECURE_SLOG(LOG_DEBUG, tts_tag(), "[IN] tts initialize : pid(%d), uid(%d)", pid , uid); - ret = ttsd_server_initialize(pid, uid, &credential_needed); + ret = ttsd_server_initialize(pid, uid, TTS_IPC_METHOD_DBUS, &credential_needed); } DBusMessage* reply; @@ -354,7 +354,7 @@ int ttsd_dbus_server_add_text(DBusConnection* conn, DBusMessage* msg) dbus_error_free(&err); ret = TTSD_ERROR_OPERATION_FAILED; } else { - SECURE_SLOG(LOG_DEBUG, tts_tag(), "[IN] tts add text : uid(%d), text(%s), lang(%s), type(%d), speed(%d), uttid(%d), credential(%s)", + SECURE_SLOG(LOG_DEBUG, tts_tag(), "[IN] tts add text : uid(%d), text(%s), lang(%s), type(%d), speed(%d), uttid(%d), credential(%s)", uid, (NULL == text) ? "NULL" : text, (NULL == lang) ? "NULL" : lang, voicetype, speed, uttid, (NULL == credential) ? "NULL" : credential); ret = ttsd_server_add_queue(uid, text, lang, voicetype, speed, uttid, credential); } @@ -447,8 +447,8 @@ int ttsd_dbus_server_stop(DBusConnection* conn, DBusMessage* msg) int uid; int ret = 0; - dbus_message_get_args(msg, &err, - DBUS_TYPE_INT32, &uid, + dbus_message_get_args(msg, &err, + DBUS_TYPE_INT32, &uid, DBUS_TYPE_INVALID); SLOG(LOG_DEBUG, tts_tag(), ">>>>> TTS STOP"); @@ -466,8 +466,8 @@ int ttsd_dbus_server_stop(DBusConnection* conn, DBusMessage* msg) reply = dbus_message_new_method_return(msg); if (NULL != reply) { - dbus_message_append_args(reply, - DBUS_TYPE_INT32, &ret, + dbus_message_append_args(reply, + DBUS_TYPE_INT32, &ret, DBUS_TYPE_INVALID); if (0 == ret) { @@ -500,8 +500,8 @@ int ttsd_dbus_server_pause(DBusConnection* conn, DBusMessage* msg) int uid; int uttid; int ret = 0; - dbus_message_get_args(msg, &err, - DBUS_TYPE_INT32, &uid, + dbus_message_get_args(msg, &err, + DBUS_TYPE_INT32, &uid, DBUS_TYPE_INVALID); SLOG(LOG_DEBUG, tts_tag(), ">>>>> TTS PAUSE"); @@ -519,8 +519,8 @@ int ttsd_dbus_server_pause(DBusConnection* conn, DBusMessage* msg) reply = dbus_message_new_method_return(msg); if (NULL != reply) { - dbus_message_append_args(reply, - DBUS_TYPE_INT32, &ret, + dbus_message_append_args(reply, + DBUS_TYPE_INT32, &ret, DBUS_TYPE_INVALID); if (0 == ret) { diff --git a/server/ttsd_ipc.c b/server/ttsd_ipc.c index bfbb99e..c7bf675 100644 --- a/server/ttsd_ipc.c +++ b/server/ttsd_ipc.c @@ -26,14 +26,13 @@ int ttsd_ipc_open_connection() { SLOG(LOG_INFO, tts_tag(), "[IPC] ttsd_ipc_open_connection"); - g_tidl_vtable = ttsd_tidl_vtable; - g_dbus_vtable = ttsd_dbus_vtable; + int return_for_tidl = TTSD_ERROR_OPERATION_FAILED; + int return_for_dbus = TTSD_ERROR_OPERATION_FAILED; - int ret1, ret2; - ret1 = g_tidl_vtable[OPEN_CONNECTION](); - ret2 = g_dbus_vtable[OPEN_CONNECTION](); + return_for_tidl = ttsd_tidl_vtable[OPEN_CONNECTION](); + return_for_dbus = ttsd_dbus_vtable[OPEN_CONNECTION](); - if (ret1 != TTSE_ERROR_NONE || ret2 != TTSE_ERROR_NONE) { + if (return_for_tidl != TTSE_ERROR_NONE || return_for_dbus != TTSE_ERROR_NONE) { return TTSD_ERROR_OPERATION_FAILED; } @@ -44,18 +43,13 @@ int ttsd_ipc_close_connection() { SLOG(LOG_INFO, tts_tag(), "[IPC] ttsd_ipc_close_connection"); - int ret1 = TTSD_ERROR_OPERATION_FAILED; - int ret2 = TTSD_ERROR_OPERATION_FAILED; + int return_for_tidl = TTSD_ERROR_OPERATION_FAILED; + int return_for_dbus = TTSD_ERROR_OPERATION_FAILED; - if (NULL != g_tidl_vtable) { - ret1 = g_tidl_vtable[CLOSE_CONNECTION](); - } - - if (NULL != g_dbus_vtable) { - ret2 = g_dbus_vtable[CLOSE_CONNECTION](); - } + return_for_tidl = ttsd_tidl_vtable[CLOSE_CONNECTION](); + return_for_dbus = ttsd_dbus_vtable[CLOSE_CONNECTION](); - if (ret1 != TTSE_ERROR_NONE || ret2 != TTSE_ERROR_NONE) { + if (return_for_tidl != TTSE_ERROR_NONE || return_for_dbus != TTSE_ERROR_NONE) { return TTSD_ERROR_OPERATION_FAILED; } @@ -66,102 +60,102 @@ int ttsdc_ipc_send_utt_start_message(int pid, int uid, int uttid) { SLOG(LOG_INFO, tts_tag(), "[IPC] ttsdc_ipc_send_utt_start_message"); - int index = ttsd_data_is_client(uid); - - if (index < 0) { + if (0 > ttsd_data_is_client(uid)) { SLOG(LOG_ERROR, tts_tag(), "[ERROR] uid is not valid (%d)", uid); return TTSD_ERROR_INVALID_PARAMETER; } - if (ttsd_data_is_client_use_tidl(uid)) { - if (NULL == g_tidl_vtable) { - SLOG(LOG_ERROR, tts_tag(), "vtable is NULL"); - return TTSD_ERROR_OPERATION_FAILED; - } - return g_tidl_vtable[SEND_MESSAGE](pid, uid, uttid, TTSD_METHOD_UTTERANCE_STARTED); - } else { - if (NULL == g_dbus_vtable) { - SLOG(LOG_ERROR, tts_tag(), "vtable is NULL"); - return TTSD_ERROR_OPERATION_FAILED; - } - return g_dbus_vtable[SEND_MESSAGE](pid, uid, uttid, TTSD_METHOD_UTTERANCE_STARTED); + switch (ttsd_data_get_ipc_method(uid)) + { + case TTS_IPC_METHOD_DBUS: + SLOG(LOG_DEBUG, tts_tag(), "[IPC] ipc method : dbus"); + return ttsd_dbus_vtable[SEND_MESSAGE](pid, uid, uttid, TTSD_METHOD_UTTERANCE_STARTED); + + case TTS_IPC_METHOD_TIDL: + SLOG(LOG_DEBUG, tts_tag(), "[IPC] ipc method : tidl"); + return ttsd_tidl_vtable[SEND_MESSAGE](pid, uid, uttid, TTSD_METHOD_UTTERANCE_STARTED); + + default: + SLOG(LOG_ERROR, tts_tag(), "[ERROR] method is not valid"); } + + return TTSD_ERROR_OPERATION_FAILED; } int ttsdc_ipc_send_utt_finish_message(int pid, int uid, int uttid) { SLOG(LOG_INFO, tts_tag(), "[IPC] ttsdc_ipc_send_utt_finish_message"); - int index = ttsd_data_is_client(uid); - - if (index < 0) { + if (0 > ttsd_data_is_client(uid)) { SLOG(LOG_ERROR, tts_tag(), "[ERROR] uid is not valid (%d)", uid); return TTSD_ERROR_INVALID_PARAMETER; } - if (ttsd_data_is_client_use_tidl(uid)) { - if (NULL == g_tidl_vtable) { - SLOG(LOG_ERROR, tts_tag(), "vtable is NULL"); - return TTSD_ERROR_OPERATION_FAILED; - } - return g_tidl_vtable[SEND_MESSAGE](pid, uid, uttid, TTSD_METHOD_UTTERANCE_COMPLETED); - } else { - if (NULL == g_dbus_vtable) { - SLOG(LOG_ERROR, tts_tag(), "vtable is NULL"); - return TTSD_ERROR_OPERATION_FAILED; - } - return g_dbus_vtable[SEND_MESSAGE](pid, uid, uttid, TTSD_METHOD_UTTERANCE_COMPLETED); + switch (ttsd_data_get_ipc_method(uid)) + { + case TTS_IPC_METHOD_DBUS: + SLOG(LOG_DEBUG, tts_tag(), "[IPC] ipc method : dbus"); + return ttsd_dbus_vtable[SEND_MESSAGE](pid, uid, uttid, TTSD_METHOD_UTTERANCE_COMPLETED); + + case TTS_IPC_METHOD_TIDL: + SLOG(LOG_DEBUG, tts_tag(), "[IPC] ipc method : tidl"); + return ttsd_tidl_vtable[SEND_MESSAGE](pid, uid, uttid, TTSD_METHOD_UTTERANCE_COMPLETED); + + default: + SLOG(LOG_ERROR, tts_tag(), "[ERROR] method is not valid"); } + + return TTSD_ERROR_OPERATION_FAILED; } int ttsdc_ipc_send_set_state_message(int pid, int uid, int state) { SLOG(LOG_INFO, tts_tag(), "[IPC] ttsdc_ipc_send_set_state_message"); - int index = ttsd_data_is_client(uid); - - if (index < 0) { + if (0 > ttsd_data_is_client(uid)) { SLOG(LOG_ERROR, tts_tag(), "[ERROR] uid is not valid (%d)", uid); return TTSD_ERROR_INVALID_PARAMETER; } - if (ttsd_data_is_client_use_tidl(uid)) { - if (NULL == g_tidl_vtable) { - SLOG(LOG_ERROR, tts_tag(), "vtable is NULL"); - return TTSD_ERROR_OPERATION_FAILED; - } - return g_tidl_vtable[SEND_MESSAGE](pid, uid, state, TTSD_METHOD_SET_STATE); - } else { - if (NULL == g_dbus_vtable) { - SLOG(LOG_ERROR, tts_tag(), "vtable is NULL"); - return TTSD_ERROR_OPERATION_FAILED; - } - return g_dbus_vtable[SEND_MESSAGE](pid, uid, state, TTSD_METHOD_SET_STATE); + switch (ttsd_data_get_ipc_method(uid)) + { + case TTS_IPC_METHOD_DBUS: + SLOG(LOG_DEBUG, tts_tag(), "[IPC] ipc method : dbus"); + return ttsd_dbus_vtable[SEND_MESSAGE](pid, uid, state, TTSD_METHOD_SET_STATE); + + case TTS_IPC_METHOD_TIDL: + SLOG(LOG_DEBUG, tts_tag(), "[IPC] ipc method : tidl"); + return ttsd_tidl_vtable[SEND_MESSAGE] (pid, uid, state, TTSD_METHOD_SET_STATE); + + default: + SLOG(LOG_ERROR, tts_tag(), "[ERROR] method is not valid"); } + + return TTSD_ERROR_OPERATION_FAILED; } int ttsdc_ipc_send_error_message(int pid, int uid, int uttid, int reason, char* err_msg) { SLOG(LOG_INFO, tts_tag(), "[IPC] ttsdc_ipc_send_error_message"); - int index = ttsd_data_is_client(uid); - - if (index < 0) { + if (0 > ttsd_data_is_client(uid)) { SLOG(LOG_ERROR, tts_tag(), "[ERROR] uid is not valid (%d)", uid); return TTSD_ERROR_INVALID_PARAMETER; } - if (ttsd_data_is_client_use_tidl(uid)) { - if (NULL == g_tidl_vtable) { - SLOG(LOG_ERROR, tts_tag(), "vtable is NULL"); - return TTSD_ERROR_OPERATION_FAILED; - } - return g_tidl_vtable[SEND_ERROR](pid, uid, uttid, reason, err_msg); - } else { - if (NULL == g_dbus_vtable) { - SLOG(LOG_ERROR, tts_tag(), "vtable is NULL"); - return TTSD_ERROR_OPERATION_FAILED; - } - return g_dbus_vtable[SEND_ERROR](pid, uid, uttid, reason, err_msg); + switch (ttsd_data_get_ipc_method(uid)) + { + case TTS_IPC_METHOD_DBUS: + SLOG(LOG_DEBUG, tts_tag(), "[IPC] ipc method : dbus"); + return ttsd_dbus_vtable[SEND_ERROR](pid, uid, uttid, reason, err_msg); + + case TTS_IPC_METHOD_TIDL: + SLOG(LOG_DEBUG, tts_tag(), "[IPC] ipc method : tidl"); + return ttsd_tidl_vtable[SEND_ERROR](pid, uid, uttid, reason, err_msg); + + default: + SLOG(LOG_ERROR, tts_tag(), "[ERROR] method is not valid"); } + + return TTSD_ERROR_OPERATION_FAILED; } diff --git a/server/ttsd_ipc.h b/server/ttsd_ipc.h index ba8c3eb..af4afc1 100644 --- a/server/ttsd_ipc.h +++ b/server/ttsd_ipc.h @@ -28,9 +28,6 @@ typedef enum { SEND_ERROR } ttsd_ipc_vtable_e; -int (**g_tidl_vtable)(); -int (**g_dbus_vtable)(); - int ttsd_ipc_open_connection(); int ttsd_ipc_close_connection(); diff --git a/server/ttsd_server.c b/server/ttsd_server.c index 276b0fc..18bccfb 100644 --- a/server/ttsd_server.c +++ b/server/ttsd_server.c @@ -602,7 +602,7 @@ int ttsd_server_is_already_initialized(int pid, int uid, bool* is_initialized) return TTSD_ERROR_NONE; } -int ttsd_server_initialize(int pid, int uid, bool* credential_needed) +int ttsd_server_initialize(int pid, int uid, tts_ipc_method_e method, bool* credential_needed) { SLOG(LOG_INFO, tts_tag(), "[Server] Server initialize"); @@ -642,6 +642,11 @@ int ttsd_server_initialize(int pid, int uid, bool* credential_needed) return TTSD_ERROR_OPERATION_FAILED; } + if (0 != ttsd_data_set_ipc_method(uid, method)) { + SLOG(LOG_ERROR, tts_tag(), "[Server ERROR] Fail to set ipc method"); + return TTSD_ERROR_OPERATION_FAILED; + } + if (0 != ttsd_player_create_instance(uid)) { SLOG(LOG_ERROR, tts_tag(), "[Server ERROR] Fail to create player"); return TTSD_ERROR_OPERATION_FAILED; diff --git a/server/ttsd_server.h b/server/ttsd_server.h index 58ef698..4b3b771 100644 --- a/server/ttsd_server.h +++ b/server/ttsd_server.h @@ -1,5 +1,5 @@ /* -* Copyright (c) 2011-2016 Samsung Electronics Co., Ltd All Rights Reserved +* Copyright (c) 2011-2016 Samsung Electronics Co., Ltd All Rights Reserved * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at @@ -19,6 +19,7 @@ #include #include "ttse.h" +#include "tts_ipc_method.h" #ifdef __cplusplus extern "C" { @@ -50,7 +51,7 @@ int ttsd_set_private_data_requested_cb(ttse_private_data_requested_cb callback); int ttsd_server_is_already_initialized(int pid, int uid, bool* is_initialized); -int ttsd_server_initialize(int pid, int uid, bool* credential_needed); +int ttsd_server_initialize(int pid, int uid, tts_ipc_method_e method, bool* credential_needed); int ttsd_server_finalize(int uid); diff --git a/server/ttsd_tidl.c b/server/ttsd_tidl.c index 9378635..a841093 100644 --- a/server/ttsd_tidl.c +++ b/server/ttsd_tidl.c @@ -66,7 +66,7 @@ static int __register_cb(rpc_port_stub_tts_context_h context, int pid, int uid, SLOG(LOG_DEBUG, tts_tag(), ">>>>> TTS REGISTER CALLBACK uid(%d)", uid); bool credential_needed = false; - if (0 != ttsd_server_initialize(pid, uid, &credential_needed)) { + if (0 != ttsd_server_initialize(pid, uid, TTS_IPC_METHOD_TIDL, &credential_needed)) { SLOG(LOG_ERROR, tts_tag(), "[IN ERROR] ttsd Hello : server initialize"); return TTSE_ERROR_OPERATION_FAILED; } @@ -134,7 +134,7 @@ static int __initialize_cb(rpc_port_stub_tts_context_h context, int uid, int pid { SECURE_SLOG(LOG_DEBUG, tts_tag(), "[IN] tts initialize : pid(%d), uid(%d)", pid , uid); - if (0 != ttsd_server_initialize(pid, uid, credential_needed)) { + if (0 != ttsd_server_initialize(pid, uid, TTS_IPC_METHOD_TIDL, credential_needed)) { return -1; } SLOG(LOG_DEBUG, tts_tag(), "[OUT] tts initialize credential_needed(%d)", *credential_needed); -- 2.7.4