Fix tts_tidl and tts_dbus use same logic 31/255431/2
authorSuyeon Hwang <stom.hwang@samsung.com>
Thu, 18 Mar 2021 02:11:49 +0000 (11:11 +0900)
committerSuyeon Hwang <stom.hwang@samsung.com>
Thu, 18 Mar 2021 07:58:28 +0000 (16:58 +0900)
Change-Id: Ic70c9e0963aee17835beed6826c657c363784ff8
Signed-off-by: Suyeon Hwang <stom.hwang@samsung.com>
client/tts_tidl.c

index ea7be209104a2ef090d8268883b2fdc1c5e04c81..73e4e1b0b97baf892a08ee6155d42e77b29e6d9a 100644 (file)
 
 #define MAXSLEEP 128
 
-static const char* __tts_get_error_code(tts_error_e err)
-{
-       switch (err) {
-       case TTS_ERROR_NONE:                    return "TTS_ERROR_NONE";
-       case TTS_ERROR_OUT_OF_MEMORY:           return "TTS_ERROR_OUT_OF_MEMORY";
-       case TTS_ERROR_IO_ERROR:                return "TTS_ERROR_IO_ERROR";
-       case TTS_ERROR_INVALID_PARAMETER:       return "TTS_ERROR_INVALID_PARAMETER";
-       case TTS_ERROR_OUT_OF_NETWORK:          return "TTS_ERROR_OUT_OF_NETWORK";
-       case TTS_ERROR_TIMED_OUT:               return "TTS_ERROR_TIMED_OUT";
-       case TTS_ERROR_PERMISSION_DENIED:       return "TTS_ERROR_PERMISSION_DENIED";
-       case TTS_ERROR_NOT_SUPPORTED:           return "TTS_ERROR_NOT_SUPPORTED";
-       case TTS_ERROR_INVALID_STATE:           return "TTS_ERROR_INVALID_STATE";
-       case TTS_ERROR_INVALID_VOICE:           return "TTS_ERROR_INVALID_VOICE";
-       case TTS_ERROR_ENGINE_NOT_FOUND:        return "TTS_ERROR_ENGINE_NOT_FOUND";
-       case TTS_ERROR_OPERATION_FAILED:        return "TTS_ERROR_OPERATION_FAILED";
-       case TTS_ERROR_AUDIO_POLICY_BLOCKED:    return "TTS_ERROR_AUDIO_POLICY_BLOCKED";
-       case TTS_ERROR_NOT_SUPPORTED_FEATURE:   return "TTS_ERROR_NOT_SUPPORTED_FEATURE";
-       case TTS_ERROR_SERVICE_RESET:           return "TTS_ERROR_SERVICE_RESET";
-       default:
-               return "Invalid error code";
-       }
-       return NULL;
-}
-
-int __tts_cb_hello(int uid, int ret, int credential_needed)
-{
-       tts_client_s* client = tts_client_get_by_uid(uid);
-       if (NULL == client) {
-               SLOG(LOG_ERROR, TAG_TTSC, "Fail to get TTS client or ignore this uid(%d)", uid);
-               return TTS_ERROR_OPERATION_FAILED;
-       }
-
-       if (client->hello_timer) {
-               ecore_timer_del(client->hello_timer);
-               client->hello_timer = NULL;
-       }
-
-       if (TTS_STATE_READY == client->current_state) {
-               SLOG(LOG_INFO, TAG_TTSC, "[INFO] tts client is already READY");
-               return TTS_ERROR_NONE;
-       }
-
-       if (TTS_ERROR_ENGINE_NOT_FOUND == ret) {
-               SLOG(LOG_ERROR, TAG_TTSC, "[ERROR] Fail to initialize : %s", __tts_get_error_code(ret));
-
-               client->reason = TTS_ERROR_ENGINE_NOT_FOUND;
-               client->utt_id = -1;
-
-               tts_core_notify_error_async(client, client->utt_id, client->reason);
-
-               return TTS_ERROR_OPERATION_FAILED;
-
-       } else if (TTS_ERROR_PERMISSION_DENIED == ret) {
-               SLOG(LOG_ERROR, TAG_TTSC, "[ERROR] Fail to initialize : %s", __tts_get_error_code(ret));
-
-               client->reason = TTS_ERROR_PERMISSION_DENIED;
-               client->utt_id = -1;
-
-               tts_core_notify_error_async(client, client->utt_id, client->reason);
-
-               return TTS_ERROR_PERMISSION_DENIED;
-
-       } else if (TTS_ERROR_NONE != ret) {
-               SLOG(LOG_WARN, TAG_TTSC, "[WARNING] Fail to connection. Retry to connect : %s", __tts_get_error_code(ret));
-               return TTS_ERROR_OPERATION_FAILED;
-
-       } else {
-               /* success to connect tts-daemon */
-               if (TTS_CREDENTIAL_NEEDED_ALREADY_INITIALIZED != credential_needed) {
-                       client->credential_needed = credential_needed;
-                       SLOG(LOG_ERROR, TAG_TTSC, "Supported options : credential(%s)", credential_needed ? "need" : "no need");
-               }
-       }
-
-       client->before_state = client->current_state;
-       client->current_state = TTS_STATE_READY;
-
-       tts_core_notify_state_changed_async(client, client->before_state, client->current_state);
-
-       SLOG(LOG_DEBUG, TAG_TTSC, "@@@");
-       return TTS_ERROR_NONE;
-}
-
 static int __tts_cb_error(int uid, tts_error_e reason, int utt_id, char* err_msg)
 {
        if (-1 == uid) {
@@ -133,24 +50,19 @@ static int __tts_cb_error(int uid, tts_error_e reason, int utt_id, char* err_msg
                                /* call callback function */
                                tts_core_notify_error_async(data, utt_id, reason);
 
-                               if (TTS_ERROR_SERVICE_RESET == reason) {
-                                       SLOG(LOG_WARN, TAG_TTSC, "[WARNING] Service Reset");
-
-                                       tts_client_s* client = tts_client_get(data->tts);
-                                       if (NULL == client) {
-                                               SLOG(LOG_ERROR, TAG_TTSC, "[ERROR] A handle is not valid");
-                                               return TTS_ERROR_INVALID_PARAMETER;
-                                       }
-
-                                       tts_core_reprepare(data);
-                               }
-
                                /* Next item */
                                iter = g_list_next(iter);
                        }
                }
 
                g_list_free(client_list);
+
+               if (TTS_ERROR_SERVICE_RESET == reason) {
+                       SLOG(LOG_WARN, TAG_TTSC, "[WARNING] Service Reset");
+
+                       tts_core_reprepare();
+               }
+
        } else {
                tts_client_s* client = tts_client_get_by_uid(uid);
 
@@ -167,12 +79,6 @@ static int __tts_cb_error(int uid, tts_error_e reason, int utt_id, char* err_msg
                        client->err_msg = strdup(err_msg);
 
                tts_core_notify_error_async(client, utt_id, reason);
-
-               if (TTS_ERROR_SERVICE_RESET == reason) {
-                       SLOG(LOG_WARN, TAG_TTSC, "[WARNING] Service Reset");
-
-                       tts_core_reprepare(client);
-               }
        }
 
        return 0;
@@ -264,7 +170,7 @@ static void __notify_cb(void *user_data, int pid, int uid, bundle *msg)
        if (0 == strncmp(TTSD_METHOD_HELLO, method, strlen(TTSD_METHOD_HELLO))) {
                bundle_get_str(msg, TTS_BUNDLE_CREDENTIAL_NEEDED, &val);
                if (val) {
-                       __tts_cb_hello(uid, 0, atoi(val));
+                       tts_core_receive_hello(uid, 0, atoi(val));
                }
        } else if (0 == strncmp(TTSD_METHOD_UTTERANCE_STARTED, method, strlen(TTSD_METHOD_UTTERANCE_STARTED))) {
                bundle_get_str(msg, TTS_BUNDLE_UTTID, &val);
@@ -293,7 +199,6 @@ static void __notify_cb(void *user_data, int pid, int uid, bundle *msg)
                        __tts_cb_error(uid, atoi(reason), atoi(uttid), err_msg);
                }
        }
-       //TODO add NameOwnerChanged
        else {
                SLOG(LOG_ERROR, TAG_TTSC, "[ERROR] Invalid msg");
        }