Fix ttsd_data_get_client_state() returns state value directly 76/271876/2
authorSuyeon Hwang <stom.hwang@samsung.com>
Thu, 20 May 2021 06:08:19 +0000 (15:08 +0900)
committerSuyeon Hwang <stom.hwang@samsung.com>
Thu, 3 Mar 2022 04:28:32 +0000 (13:28 +0900)
Change-Id: I4ae4bbe95e236e2f957fa40b855b6ecd92958664
Signed-off-by: Suyeon Hwang <stom.hwang@samsung.com>
server/ttsd_data.cpp
server/ttsd_data.h
server/ttsd_player.cpp
server/ttsd_server.c

index c779083..340a8cb 100644 (file)
@@ -723,18 +723,16 @@ int ttsd_data_clear_data(unsigned int uid)
        return TTSD_ERROR_NONE;
 }
 
-int ttsd_data_get_client_state(unsigned int uid, app_tts_state_e* state)
+app_tts_state_e ttsd_data_get_client_state(unsigned int uid)
 {
        lock_guard<mutex> lock(g_app_data_mutex);
        app_data_s* app_data = __get_client_app_data(uid);
        if (nullptr == app_data) {
                SECURE_SLOG(LOG_ERROR, tts_tag(), "[DATA ERROR] uid is not valid (%u)", uid);
-               return TTSD_ERROR_INVALID_PARAMETER;
+               return APP_STATE_NONE;
        }
 
-       *state = app_data->state;
-
-       return TTSD_ERROR_NONE;
+       return app_data->state;
 }
 
 static unsigned int __get_playing_app_uid()
index 8c9a1b6..1cb42e3 100644 (file)
@@ -26,6 +26,7 @@ extern "C" {
 
 
 typedef enum {
+       APP_STATE_NONE = -1,
        APP_STATE_CREATED = 0,
        APP_STATE_READY,
        APP_STATE_PLAYING,
@@ -118,7 +119,7 @@ int ttsd_data_set_used_voice(unsigned int uid, const char* lang, int type);
 
 int ttsd_data_reset_used_voice(unsigned int uid, ttsd_used_voice_cb callback);
 
-int ttsd_data_get_client_state(unsigned int uid, app_tts_state_e* state);
+app_tts_state_e ttsd_data_get_client_state(unsigned int uid);
 
 int ttsd_data_set_client_state(unsigned int uid, app_tts_state_e state);
 
index cf84d6a..657a4ff 100644 (file)
@@ -1005,8 +1005,8 @@ int ttsd_player_all_stop()
                        /* Get handle data from list */
                        data = (player_s*)iter->data;
 
-                       app_tts_state_e state;
-                       if (0 > ttsd_data_get_client_state(data->uid, &state)) {
+                       app_tts_state_e state = ttsd_data_get_client_state(data->uid);
+                       if (APP_STATE_NONE == state) {
                                SLOG(LOG_ERROR, tts_tag(), "[player ERROR] uid(%u) is not valid", data->uid);
                                iter = g_list_next(iter);
 
index 715b9fe..7e42890 100644 (file)
@@ -222,8 +222,8 @@ int ttsd_send_result(ttse_result_event_e event, const void* data, unsigned int d
        }
 
        /* check the current state */
-       app_tts_state_e state;
-       if (0 > ttsd_data_get_client_state(uid, &state)) {
+       app_tts_state_e state = ttsd_data_get_client_state(uid);
+       if (APP_STATE_NONE == state) {
                ttsd_set_synth_control(TTSD_SYNTHESIS_CONTROL_DONE);
                SLOG(LOG_ERROR, tts_tag(), "[Server ERROR] uid is not valid");
                return TTSD_ERROR_INVALID_PARAMETER;
@@ -784,8 +784,7 @@ int ttsd_server_finalize(unsigned int uid)
        SLOG(LOG_INFO, tts_tag(), "[Server] Server finalize");
        SLOG(LOG_INFO, tts_tag(), "[Server] File num(%d), Avg Latency(%lf), Min(%lf), Max(%lf)", g_file_num, (g_avg_latency / (double)g_file_num), g_min_latency, g_max_latency);
 
-       app_tts_state_e state;
-       if (0 > ttsd_data_get_client_state(uid, &state)) {
+       if (0 > ttsd_data_is_client(uid)) {
                SLOG(LOG_ERROR, tts_tag(), "[Server ERROR] ttsd_server_finalize : uid is not valid");
        }
 
@@ -817,8 +816,8 @@ int ttsd_server_finalize(unsigned int uid)
 
 int ttsd_server_set_mode(unsigned int uid, ttsd_mode_e mode)
 {
-       app_tts_state_e state;
-       if (0 > ttsd_data_get_client_state(uid, &state)) {
+       app_tts_state_e state = ttsd_data_get_client_state(uid);
+       if (APP_STATE_NONE == state) {
                SLOG(LOG_ERROR, tts_tag(), "[Server ERROR] uid(%u) is NOT valid", uid);
                return TTSD_ERROR_INVALID_PARAMETER;
        }
@@ -860,8 +859,8 @@ static bool __is_connected_to_network()
 
 int ttsd_server_add_queue(unsigned int uid, const char* text, const char* lang, int voice_type, int speed, int utt_id, const char* credential)
 {
-       app_tts_state_e state;
-       if (0 > ttsd_data_get_client_state(uid, &state)) {
+       app_tts_state_e state = ttsd_data_get_client_state(uid);
+       if (APP_STATE_NONE == state) {
                SLOG(LOG_ERROR, tts_tag(), "[Server ERROR] ttsd_server_add_queue : uid is not valid");
                return TTSD_ERROR_INVALID_PARAMETER;
        }
@@ -975,9 +974,8 @@ void __send_interrupt_client(unsigned int uid)
                return;
        }
 
-       app_tts_state_e state = APP_STATE_CREATED;
-
-       if (0 != ttsd_data_get_client_state(uid, &state)) {
+       app_tts_state_e state = ttsd_data_get_client_state(uid);
+       if (APP_STATE_NONE == state) {
                SLOG(LOG_ERROR, tts_tag(), "[Server ERROR] Fail to get state. uid(%u), pid(%d)", uid, pid);
                return;
        }
@@ -989,8 +987,8 @@ void __send_interrupt_client(unsigned int uid)
 
 int ttsd_server_play(unsigned int uid, const char* credential)
 {
-       app_tts_state_e state;
-       if (0 > ttsd_data_get_client_state(uid, &state)) {
+       app_tts_state_e state = ttsd_data_get_client_state(uid);
+       if (APP_STATE_NONE == state) {
                SLOG(LOG_ERROR, tts_tag(), "[Server ERROR] uid(%u) is NOT valid", uid);
                return TTSD_ERROR_INVALID_PARAMETER;
        }
@@ -1085,8 +1083,8 @@ int ttsd_server_play(unsigned int uid, const char* credential)
 
 int ttsd_server_stop(unsigned int uid)
 {
-       app_tts_state_e state;
-       if (0 > ttsd_data_get_client_state(uid, &state)) {
+       app_tts_state_e state = ttsd_data_get_client_state(uid);
+       if (APP_STATE_NONE == state) {
                SLOG(LOG_ERROR, tts_tag(), "[Server ERROR] uid is not valid");
                return TTSD_ERROR_INVALID_PARAMETER;
        }
@@ -1121,8 +1119,8 @@ int ttsd_server_stop(unsigned int uid)
 
 int ttsd_server_pause(unsigned int uid, int* utt_id)
 {
-       app_tts_state_e state;
-       if (0 > ttsd_data_get_client_state(uid, &state)) {
+       app_tts_state_e state = ttsd_data_get_client_state(uid);
+       if (APP_STATE_NONE == state) {
                SLOG(LOG_ERROR, tts_tag(), "[Server ERROR] ttsd_server_pause : uid is not valid");
                return TTSD_ERROR_INVALID_PARAMETER;
        }
@@ -1148,8 +1146,7 @@ int ttsd_server_pause(unsigned int uid, int* utt_id)
 
 int ttsd_server_get_support_voices(unsigned int uid, GList** voice_list)
 {
-       app_tts_state_e state;
-       if (0 > ttsd_data_get_client_state(uid, &state)) {
+       if (0 > ttsd_data_is_client(uid)) {
                SLOG(LOG_ERROR, tts_tag(), "[Server ERROR] uid is not valid");
                return TTSD_ERROR_INVALID_PARAMETER;
        }
@@ -1168,8 +1165,7 @@ int ttsd_server_get_support_voices(unsigned int uid, GList** voice_list)
 
 int ttsd_server_get_current_voice(unsigned int uid, char** language, int* voice_type)
 {
-       app_tts_state_e state;
-       if (0 > ttsd_data_get_client_state(uid, &state)) {
+       if (0 > ttsd_data_is_client(uid)) {
                SLOG(LOG_ERROR, tts_tag(), "[Server ERROR] ttsd_server_get_current_voice : uid is not valid");
                return TTSD_ERROR_INVALID_PARAMETER;
        }
@@ -1188,8 +1184,8 @@ int ttsd_server_get_current_voice(unsigned int uid, char** language, int* voice_
 
 int ttsd_server_set_private_data(unsigned int uid, const char* key, const char* data)
 {
-       app_tts_state_e state;
-       if (0 > ttsd_data_get_client_state(uid, &state)) {
+       app_tts_state_e state = ttsd_data_get_client_state(uid);
+       if (APP_STATE_NONE == state) {
                SLOG(LOG_ERROR, tts_tag(), "[Server ERROR] uid(%u) is NOT valid", uid);
                return TTSD_ERROR_INVALID_PARAMETER;
        }
@@ -1211,8 +1207,8 @@ int ttsd_server_set_private_data(unsigned int uid, const char* key, const char*
 
 int ttsd_server_get_private_data(unsigned int uid, const char* key, char** data)
 {
-       app_tts_state_e state;
-       if (0 > ttsd_data_get_client_state(uid, &state)) {
+       app_tts_state_e state = ttsd_data_get_client_state(uid);
+       if (APP_STATE_NONE == state) {
                SLOG(LOG_ERROR, tts_tag(), "[Server ERROR] uid(%u) is NOT valid", uid);
                return TTSD_ERROR_INVALID_PARAMETER;
        }
@@ -1260,8 +1256,8 @@ int ttsd_set_private_data_requested_cb(ttse_private_data_requested_cb callback)
 
 int ttsd_server_play_pcm(unsigned int uid)
 {
-       app_tts_state_e state;
-       if (0 > ttsd_data_get_client_state(uid, &state)) {
+       app_tts_state_e state = ttsd_data_get_client_state(uid);
+       if (APP_STATE_NONE == state) {
                SLOG(LOG_ERROR, tts_tag(), "[Server ERROR] uid(%u) is NOT valid", uid);
                return TTSD_ERROR_INVALID_PARAMETER;
        }
@@ -1325,8 +1321,8 @@ int ttsd_server_play_pcm(unsigned int uid)
 
 int ttsd_server_stop_pcm(unsigned int uid)
 {
-       app_tts_state_e state;
-       if (0 > ttsd_data_get_client_state(uid, &state)) {
+       app_tts_state_e state = ttsd_data_get_client_state(uid);
+       if (APP_STATE_NONE == state) {
                SLOG(LOG_ERROR, tts_tag(), "[Server ERROR] uid is not valid");
                return TTSD_ERROR_INVALID_PARAMETER;
        }
@@ -1342,7 +1338,6 @@ int ttsd_server_stop_pcm(unsigned int uid)
 
        ttsd_player_stop(uid);
 
-
        return TTSD_ERROR_NONE;
 }