Create new proxy handle when connection is rejected 28/265428/2
authorSuyeon Hwang <stom.hwang@samsung.com>
Tue, 19 Oct 2021 04:01:50 +0000 (13:01 +0900)
committerSuyeon Hwang <stom.hwang@samsung.com>
Wed, 20 Oct 2021 04:40:34 +0000 (13:40 +0900)
TIDL proxy does not need to try connect repeatedly. And also, if connection is failed by timeout,
app needs to create new proxy handle.

Thus, this patch makes flag variable to check whether connect function is called. Using this flag,
app calls connect function once. And also this patch creates new handle when on_rejected callback
is called to retry connection.

Change-Id: I8a7c26f825e95276e257e77451ffacc7a6722af5
Signed-off-by: Suyeon Hwang <stom.hwang@samsung.com>
client/tts_tidl.c

index 1f43d8a5499c3d894cdeb8f3fd8a951e672a81ff..5937899bda43cf599ac37ad24c1ac703a7496710 100644 (file)
@@ -24,6 +24,7 @@
 typedef struct {
        int uid;
        bool connected;
+       bool connection_requesting;
        rpc_port_proxy_tts_h rpc_h;
        rpc_port_proxy_tts_notify_cb_h notify_cb_h;
        char* engine_app_id;
@@ -31,6 +32,9 @@ typedef struct {
 
 static GList* g_tidl_infos = NULL;
 
+
+static rpc_port_proxy_tts_h __create_rpc_port(int uid, const char* engine_app_id);
+
 static tts_tidl_info_s* __get_tidl_info_s(int uid)
 {
        GList* iter = NULL;
@@ -149,6 +153,7 @@ static void __on_connected(rpc_port_proxy_tts_h h, void *user_data)
        }
 
        info->connected = true;
+       info->connection_requesting = false;
        if (0 != rpc_port_proxy_tts_invoke_set_mode(info->rpc_h, tts_client_get_mode(client))) {
                SLOG(LOG_ERROR, TAG_TTSC, "Failed to set mode");
                return;
@@ -174,6 +179,7 @@ static void __on_disconnected(rpc_port_proxy_tts_h h, void *user_data)
        }
 
        info->connected = false;
+       info->connection_requesting = false;
        if (tts_client_is_listening_started(uid)) {
                tts_core_handle_service_reset();
                SLOG(LOG_DEBUG, TAG_TTSC, "Disconnected from server");
@@ -187,8 +193,28 @@ static void __on_rejected(rpc_port_proxy_tts_h h, void *user_data)
 {
        int uid = (intptr_t)user_data;
        tts_client_s *client = tts_client_get_by_uid(uid);
-       if (!client)
+       if (NULL == client) {
+               SLOG(LOG_ERROR, TAG_TTSC, "[ERROR] Fail to get client");
                return;
+       }
+
+       tts_tidl_info_s* info = __get_tidl_info_s(uid);
+       if (NULL == info) {
+               SLOG(LOG_ERROR, TAG_TTSC, "[ERROR] Fail to get tidl info");
+               return;
+       }
+
+       if (0 != rpc_port_proxy_tts_destroy(info->rpc_h)) {
+               SLOG(LOG_ERROR, TAG_TTSC, "[ERROR] Fail to disconnect");
+               return;
+       }
+
+       info->rpc_h = __create_rpc_port(uid, info->engine_app_id);
+       if (NULL == info->rpc_h) {
+               SLOG(LOG_ERROR, TAG_TTSC, "[ERROR] Fail to create proxy");
+               return;
+       }
+       info->connection_requesting = false;
 
        tts_core_notify_error_async(client, TTS_ERROR_PERMISSION_DENIED, client->utt_id, "Rejected");
        SLOG(LOG_DEBUG, TAG_TTSC, "Rejected from server");
@@ -320,6 +346,17 @@ int tts_tidl_stop_listening(int uid)
        return TTS_ERROR_NONE;
 }
 
+static void __request_tidl_connect(tts_tidl_info_s* info) {
+       if (info->connection_requesting) {
+               return;
+       }
+
+       int ret = rpc_port_proxy_tts_connect(info->rpc_h);
+       SLOG(LOG_INFO, TAG_TTSC, "[INFO] Request connection to stub. ret(%d)", ret);
+
+       info->connection_requesting = true;
+}
+
 int tts_tidl_request_hello(int uid)
 {
        SLOG(LOG_DEBUG, TAG_TTSC, "[TIDL] tts_tidl_request_hello");
@@ -354,11 +391,12 @@ int tts_tidl_request_hello(int uid)
                }
                free(info->engine_app_id);
                info->engine_app_id = strdup(engine_app_id);
+               info->connection_requesting = false;
        }
 
        if (!info->connected) {
                SLOG(LOG_ERROR, TAG_TTSC, "[ERROR] Not Connected");
-               rpc_port_proxy_tts_connect(info->rpc_h);
+               __request_tidl_connect(info);
                return TTS_ERROR_OPERATION_FAILED;
        }