tts_ipc layer is interface layer.
Thus, developer should not have no interest below the layer.
However, in current code, tts_ipc function is used as different way by the ipc method.
Calling interface as same way is better to read, and if there is difference, the difference should
be covered on implementation layer.
This patch unify the usages of functions in tts_ipc. To unify the usage, this patch also fix the
implementation of each method dbus and tidl.
Change-Id: I557fed82f11cace93f52eb13a9ba37bb9287a38d
Signed-off-by: Suyeon Hwang <stom.hwang@samsung.com>
int pid = getpid();
char* appid = NULL;
int ret = app_manager_get_app_id(pid, &appid);
- if (0 != ret) {
- SLOG(LOG_ERROR, TAG_TTSC, "[ERROR] Fail to get appid, ret(%d), pid(%d), appid(%s)", ret, pid, appid);
+ if (0 != ret || NULL == appid) {
+ SLOG(LOG_ERROR, TAG_TTSC, "[ERROR] Fail to get appid, ret(%d), pid(%d)", ret, pid);
tts_ipc_set_method(TTS_IPC_METHOD_DBUS);
} else {
- if(NULL == appid ) {
- SLOG(LOG_INFO, TAG_TTSC, "[INFO] tts_create : client appid(null) => This is daemon process");
- tts_ipc_set_method(TTS_IPC_METHOD_DBUS);
- } else {
- SLOG(LOG_INFO, TAG_TTSC, "[INFO] ]tts_create : client appid(%s)", appid);
- tts_ipc_set_method(TTS_IPC_METHOD_TIDL);
- }
+ SLOG(LOG_INFO, TAG_TTSC, "[INFO] tts_create : client appid(%s), pid(%d)", appid, pid);
+ tts_ipc_set_method(TTS_IPC_METHOD_TIDL);
}
+
if (NULL != appid) {
free(appid);
appid = NULL;
}
}
- if (tts->connected) {
- if (1 == tts_client_get_size()) {
- SLOG(LOG_ERROR, TAG_TTSC, "[INFO] all clients are destroied");
- if (0 != tts_ipc_close_connection(client->uid)) {
- SLOG(LOG_ERROR, TAG_TTSC, "[ERROR] Fail to close connection");
- return TTS_ERROR_OPERATION_FAILED;
- }
- }
- }
-
tts_client_set_current_state(client, TTS_STATE_CREATED);
case TTS_STATE_CREATED:
thread_count = ecore_thread_active_get();
}
+ if (0 != tts_ipc_close_connection(client->uid)) {
+ SLOG(LOG_ERROR, TAG_TTSC, "[ERROR] Fail to close connection");
+ return TTS_ERROR_OPERATION_FAILED;
+ }
+
/* Free resources */
tts_client_destroy(tts);
}
int num_of_client = tts_client_get_size();
- if (0 == num_of_client) {
- SLOG(LOG_ERROR, TAG_TTSC, "[INFO] all clients are destroied");
- if (0 != tts_ipc_close_connection(client->uid)) {
- SLOG(LOG_ERROR, TAG_TTSC, "[ERROR] Fail to close connection");
- }
+ SLOG(LOG_ERROR, TAG_TTSC, "[INFO] num_of_client(%d)", num_of_client);
+ if (0 == num_of_client) {
if (0 != tts_core_deinitialize()) {
SLOG(LOG_ERROR, TAG_TTSC, "[ERROR] Fail to deinitialize core");
}
- } else {
- SLOG(LOG_ERROR, TAG_TTSC, "[INFO] num_of_client(%d)", num_of_client);
}
if (NULL != g_language) {
static Ecore_Fd_Handler* g_dbus_fd_handler = NULL;
+static volatile int g_connected_client = 0;
static int __tts_cb_error(int uid, tts_error_e reason, int utt_id, char* err_msg)
{
}
}
-int tts_dbus_open_connection()
+static int __dbus_open_connection()
{
- if (NULL != g_conn_sender && NULL != g_conn_listener) {
- SLOG(LOG_WARN, TAG_TTSC, "already existed connection ");
- return 0;
- }
-
- DBusError err;
-
/* initialize the error value */
+ DBusError err;
dbus_error_init(&err);
/* connect to the DBUS system bus, and check for errors */
return TTS_ERROR_OPERATION_FAILED;
}
- return 0;
+ return TTS_ERROR_NONE;
}
-int tts_dbus_close_connection()
+int tts_dbus_open_connection(int uid)
{
- DBusError err;
- dbus_error_init(&err);
+ if (NULL != g_conn_sender && NULL != g_conn_listener) {
+ SLOG(LOG_WARN, TAG_TTSC, "already existed connection ");
+ g_connected_client++;
+
+ return TTS_ERROR_NONE;
+ }
+
+ int ret = __dbus_open_connection();
+ if (TTS_ERROR_NONE == ret) {
+ g_connected_client++;
+ }
+
+ return ret;
+}
+static int __dbus_close_connection()
+{
if (NULL != g_dbus_fd_handler) {
ecore_main_fd_handler_del(g_dbus_fd_handler);
g_dbus_fd_handler = NULL;
__tts_dbus_connection_free();
- return 0;
+ return TTS_ERROR_NONE;
+}
+
+int tts_dbus_close_connection(int uid)
+{
+ g_connected_client--;
+
+ if (0 == g_connected_client) {
+ return __dbus_close_connection();
+ }
+
+ return TTS_ERROR_NONE;
}
int tts_dbus_stop_listening(int uid)
int tts_dbus_reconnect()
{
if (!g_conn_sender || !g_conn_listener) {
- tts_dbus_close_connection();
+ __dbus_close_connection();
- if (0 != tts_dbus_open_connection()) {
+ if (0 != __dbus_open_connection()) {
SLOG(LOG_ERROR, TAG_TTSC, "[ERROR] Fail to reconnect");
return -1;
}
sender_connected ? "Connected" : "Not connected", listener_connected ? "Connected" : "Not connected");
if (false == sender_connected || false == listener_connected) {
- tts_dbus_close_connection();
+ __dbus_close_connection();
- if (0 != tts_dbus_open_connection()) {
+ if (0 != __dbus_open_connection()) {
SLOG(LOG_ERROR, TAG_TTSC, "[ERROR] Fail to reconnect");
return -1;
}
extern "C" {
#endif
-int tts_dbus_open_connection();
+int tts_dbus_open_connection(int uid);
-int tts_dbus_close_connection();
+int tts_dbus_close_connection(int uid);
int tts_dbus_stop_listening(int uid);
SLOG(LOG_ERROR, TAG_TTSC, "[ERROR] method is not valid");
return TTS_ERROR_INVALID_PARAMETER;
}
+
g_ipc_method = method;
+ /* choose ipc */
+ switch (g_ipc_method) {
+ case TTS_IPC_METHOD_DBUS:
+ g_vtable = ttsc_dbus_vtable;
+ break;
+ case TTS_IPC_METHOD_TIDL:
+ g_vtable = ttsc_tidl_vtable;
+ break;
+ default:
+ SLOG(LOG_ERROR, TAG_TTSC, "[ERROR] IPC method is not valid");
+ g_vtable = NULL;
+ }
+
return TTS_ERROR_NONE;
}
switch (g_ipc_method) {
case TTS_IPC_METHOD_DBUS:
g_vtable = ttsc_dbus_vtable;
- return g_vtable[OPEN_CONNECTION]();
+ break;
case TTS_IPC_METHOD_TIDL:
g_vtable = ttsc_tidl_vtable;
- return g_vtable[OPEN_CONNECTION](uid);
+ break;
default:
SLOG(LOG_ERROR, TAG_TTSC, "[ERROR] IPC method is not set");
return TTS_ERROR_OPERATION_FAILED;
}
+
+ return g_vtable[OPEN_CONNECTION](uid);
}
int tts_ipc_close_connection(int uid)
return TTS_ERROR_OPERATION_FAILED;
}
- switch (g_ipc_method) {
- case TTS_IPC_METHOD_DBUS:
- return g_vtable[CLOSE_CONNECTION]();
- case TTS_IPC_METHOD_TIDL:
- return g_vtable[CLOSE_CONNECTION](uid);
- default:
- SLOG(LOG_ERROR, TAG_TTSC, "[ERROR] IPC method is not set");
- return TTS_ERROR_OPERATION_FAILED;
- }
+ return g_vtable[CLOSE_CONNECTION](uid);
}
int tts_ipc_stop_listening(int uid)
return;
}
- tts->connected = TRUE;
+ tts->connected = true;
if (0 != rpc_port_proxy_tts_invoke_set_mode(tts->rpc_h, client->mode)) {
SLOG(LOG_ERROR, TAG_TTSC, "Failed to set mode");
return;
return;
}
- tts->connected = FALSE;
-
+ tts->connected = false;
if (tts_client_is_listening_started(uid)) {
__tts_cb_error(-1, TTS_ERROR_SERVICE_RESET, -1, "Daemon Reset");
SLOG(LOG_DEBUG, TAG_TTSC, "Disconnected from server");
}
tts->rpc_h = NULL;
+ tts->connected = false;
return TTS_ERROR_NONE;
}