Rearrange code to stop all client 94/271894/2
authorSuyeon Hwang <stom.hwang@samsung.com>
Thu, 20 Jan 2022 02:26:47 +0000 (11:26 +0900)
committerSuyeon Hwang <stom.hwang@samsung.com>
Tue, 15 Mar 2022 05:47:40 +0000 (14:47 +0900)
Change-Id: I1395e10b466b998a6b14d4d17ccb2cf6839b20e4
Signed-off-by: Suyeon Hwang <stom.hwang@samsung.com>
server/ttsd_player.cpp
server/ttsd_server.c
server/ttsd_server.h

index 2e59bc4edea1976ea47efc2a170020cf0cd1e912..5a520c941c38326a3c6a8bae04e11b3be710782b 100644 (file)
@@ -12,7 +12,6 @@
 */
 
 #include "ttsd_main.h"
-#include "ttsd_server.h"
 #include "ttsd_data.h"
 #include "ttsd_ipc.h"
 #include "ttsd_player.h"
@@ -546,11 +545,11 @@ int ttsd_player_all_stop()
                return TTSD_ERROR_OPERATION_FAILED;
        }
 
-       ttsd_data_foreach_clients(__stop_all_client_callback, nullptr);
        g_player_thread->requestStop();
+       ttsd_data_foreach_clients(__stop_all_client_callback, nullptr);
 
        SLOG(LOG_DEBUG, tts_tag(), "[Player SUCCESS] player all stop!!");
-       return 0;
+       return TTSD_ERROR_NONE;
 }
 
 int ttsd_player_get_background_volume_ratio(double* ratio)
index c310737f635d401e16efe794c605825718329f6c..a1611bfe19df03d15bd907ed9aadf27bf3a00652 100644 (file)
@@ -284,25 +284,40 @@ int ttsd_send_result(ttse_result_event_e event, const void* data, unsigned int d
        return TTSD_ERROR_NONE;
 }
 
-bool __get_client_cb(int pid, unsigned int uid, app_tts_state_e state, void* user_data)
+static bool __get_client_cb(int pid, unsigned int uid, app_tts_state_e state, void* user_data)
 {
+       if (0 > ttsd_data_is_client(uid)) {
+               SLOG(LOG_ERROR, tts_tag(), "[Server] Client(%d) is not valid.", uid);
+               ttsd_data_delete_client(uid);
+               return true;
+       }
+
        /* clear client data */
        ttsd_data_clear_data(uid);
 
        if (APP_STATE_READY != state) {
                ttsd_data_set_client_state(uid, APP_STATE_READY);
-
-               /* send message */
-               if (0 != ttsdc_ipc_send_set_state_message(pid, uid, APP_STATE_READY)) {
-                       /* remove client */
-                       ttsd_data_delete_client(uid);
-               }
+               ttsdc_ipc_send_set_state_message(pid, uid, APP_STATE_READY);
        }
 
        return true;
 }
 
-void __config_changed_cb(tts_config_type_e type, const char* str_param, int int_param, double double_param)
+static void __stop_all_client()
+{
+       SLOG(LOG_INFO, tts_tag(), "[Server] Send to stop all requests");
+
+       ttsd_engine_cancel_synthesis();
+       ttsd_set_synth_control(TTSD_SYNTHESIS_CONTROL_EXPIRED);
+
+       /* stop all player */
+       ttsd_player_all_stop();
+
+       /* send interrupt message to  all clients */
+       ttsd_data_foreach_clients(__get_client_cb, NULL);
+}
+
+static void __config_changed_cb(tts_config_type_e type, const char* str_param, int int_param, double double_param)
 {
        switch (type) {
        case TTS_CONFIG_TYPE_ENGINE:
@@ -328,14 +343,7 @@ void __config_changed_cb(tts_config_type_e type, const char* str_param, int int_
                        return;
                }
 
-               /* stop all player */
-               ttsd_player_all_stop();
-
-               /* send interrupt message to  all clients */
-               ttsd_data_foreach_clients(__get_client_cb, NULL);
-
-               ttsd_engine_cancel_synthesis();
-
+               __stop_all_client();
                break;
        }
 
@@ -454,19 +462,6 @@ void __screen_reader_changed_cb(bool value)
        return;
 }
 
-int ttsd_send_all_stop()
-{
-       SLOG(LOG_INFO, tts_tag(), "[Server] Send to stop all requests");
-
-       /* stop all player */
-       ttsd_player_all_stop();
-
-       /* send interrupt message to  all clients */
-       ttsd_data_foreach_clients(__get_client_cb, NULL);
-
-       return TTSD_ERROR_NONE;
-}
-
 /*
 * Server APIs
 */
index dea4c04199f8b4281a74e9e9b6e02de6907931c9..ee9c120a57258513bf571fed7e286d95e8852697 100644 (file)
@@ -40,7 +40,6 @@ Eina_Bool ttsd_get_daemon_exist();
 
 int ttsd_send_result(ttse_result_event_e event, const void* data, unsigned int data_size, ttse_audio_type_e audio_type, int rate, void* user_data);
 int ttsd_send_error(ttse_error_e error, const char* msg);
-int ttsd_send_all_stop();
 
 int ttsd_set_private_data_set_cb(ttse_private_data_set_cb callback);
 int ttsd_set_private_data_requested_cb(ttse_private_data_requested_cb callback);