Wait TIDL connection when tts_prepare_sync() is called 11/260011/4
authorSuyeon Hwang <stom.hwang@samsung.com>
Wed, 12 May 2021 11:01:51 +0000 (20:01 +0900)
committerSuyeon Hwang <stom.hwang@samsung.com>
Mon, 28 Jun 2021 01:34:54 +0000 (10:34 +0900)
Change-Id: I97892140e896249c1cd90f86ba3c2810ce6e4473
Signed-off-by: Suyeon Hwang <stom.hwang@samsung.com>
client/tts_tidl.c

index 130f2d7..555f373 100644 (file)
@@ -19,6 +19,7 @@
 #include "tts_core.h"
 
 #define MAXSLEEP 128
+#define MAX_CONNECT_CHECK 100
 
 typedef struct {
        int uid;
@@ -270,7 +271,7 @@ static void __get_engine_app_id(int mode, int size, char* app_id)
        SLOG(LOG_INFO, TAG_TTSC, "engine app id : %s", app_id);
 }
 
-static rpc_port_proxy_tts_h __open_rpc_port(int uid, int mode)
+static rpc_port_proxy_tts_h __create_rpc_port(int uid, int mode)
 {
        char engine_app_id[256] = {0, };
        __get_engine_app_id(mode, 256, engine_app_id);
@@ -308,9 +309,9 @@ int tts_tidl_open_connection(int uid)
        }
 
        tts_mode_e mode = tts_client_get_mode(client);
-       info->rpc_h = __open_rpc_port(uid, mode);
+       info->rpc_h = __create_rpc_port(uid, mode);
        if (NULL == info->rpc_h) {
-               SLOG(LOG_ERROR, TAG_TTSC, "[ERROR] Fail to open proxy");
+               SLOG(LOG_ERROR, TAG_TTSC, "[ERROR] Fail to create proxy");
                free(info);
                return TTS_ERROR_OPERATION_FAILED;
        }
@@ -381,14 +382,14 @@ int tts_tidl_request_hello(int uid)
 
        if (info->mode != client->mode) {
                SLOG(LOG_INFO, TAG_TTSC, "[TIDL] tts mode is changed from (%d) to (%d)", info->mode, client->mode);
-               if (NULL != info->rpc_h && 0 != rpc_port_proxy_tts_destroy(info->rpc_h)) {
+               if (0 != rpc_port_proxy_tts_destroy(info->rpc_h)) {
                        SLOG(LOG_ERROR, TAG_TTSC, "[ERROR] Fail to destroy old rpc_port");
                        return TTS_ERROR_OPERATION_FAILED;
                }
 
-               info->rpc_h = __open_rpc_port(uid, client->mode);
+               info->rpc_h = __create_rpc_port(uid, client->mode);
                if (NULL == info->rpc_h) {
-                       SLOG(LOG_ERROR, TAG_TTSC, "[ERROR] Fail to open proxy");
+                       SLOG(LOG_ERROR, TAG_TTSC, "[ERROR] Fail to create proxy");
                        return TTS_ERROR_OPERATION_FAILED;
                }
                info->mode = client->mode;
@@ -414,6 +415,22 @@ int tts_tidl_request_hello(int uid)
        return TTS_ERROR_NONE;
 }
 
+static int __wait_tidl_connection(tts_tidl_info_s* info)
+{
+       int cnt = 0;
+       while (false == info->connected && MAX_CONNECT_CHECK > cnt) {
+               ecore_main_loop_iterate();
+               usleep(50000);
+               cnt++;
+       }
+
+       if (false == info->connected) {
+               return TTS_ERROR_OPERATION_FAILED;
+       }
+
+       return TTS_ERROR_NONE;
+}
+
 int tts_tidl_request_hello_sync(int uid)
 {
        SLOG(LOG_DEBUG, TAG_TTSC, "[TIDL] tts_tidl_request_hello");
@@ -431,8 +448,14 @@ int tts_tidl_request_hello_sync(int uid)
        }
 
        if (!info->connected) {
-               SLOG(LOG_ERROR, TAG_TTSC, "[ERROR] Not Connected");
-               return TTS_ERROR_OPERATION_FAILED;
+               SLOG(LOG_WARN, TAG_TTSC, "[WARNNING] Stub is not Connected. Try to connect..");
+               rpc_port_proxy_tts_connect(info->rpc_h);
+               if (TTS_ERROR_NONE != __wait_tidl_connection(info)) {
+                       SLOG(LOG_ERROR, TAG_TTSC, "[ERROR] Fail to connect");
+                       return TTS_ERROR_OPERATION_FAILED;
+               }
+
+               SLOG(LOG_INFO, TAG_TTSC, "[TIDL] Stub is Connected");
        }
 
        SLOG(LOG_DEBUG, TAG_TTSC, ">>>>> TTS Hello");