Add credential field into app data on server side 66/268966/1
authorSuyeon Hwang <stom.hwang@samsung.com>
Wed, 5 Jan 2022 09:32:14 +0000 (18:32 +0900)
committerSuyeon Hwang <stom.hwang@samsung.com>
Wed, 5 Jan 2022 09:32:14 +0000 (18:32 +0900)
Change-Id: I7e0ddb44b6053c4cd6002414f3157e4a32640567
Signed-off-by: Suyeon Hwang <stom.hwang@samsung.com>
server/ttsd_data.cpp
server/ttsd_data.h
server/ttsd_server.c

index e0b86949e3e76afaebe8c5b030ec08b51da7531e..b15346ae6f58fe0c994218c609f4c4718ac775cd 100644 (file)
@@ -40,6 +40,8 @@ typedef struct
 
        std::list<used_voice_s> m_used_voice;
        tts_ipc_method_e ipc_method;
+
+       char* credential;
 } app_data_s;
 
 static vector<app_data_s> g_app_list;
@@ -166,6 +168,7 @@ int ttsd_data_new_client(int pid, unsigned int uid)
        app.state = APP_STATE_READY;
        app.mode = TTSD_MODE_DEFAULT;
        app.ipc_method = TTS_IPC_METHOD_UNDEFINED;
+       app.credential = nullptr;
 
        g_app_list.push_back(app);
 
@@ -348,6 +351,41 @@ ttsd_mode_e ttsd_data_get_mode(unsigned int uid)
        return app_data->mode;
 }
 
+int ttsd_data_set_credential(unsigned int uid, const char* credential)
+{
+       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;
+       }
+
+       free(app_data->credential);
+       app_data->credential = nullptr;
+
+       if (credential) {
+               app_data->credential = strdup(credential);
+       }
+
+       return TTSD_ERROR_NONE;
+}
+
+char* ttsd_data_get_credential(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 nullptr;
+       }
+
+       if (nullptr == app_data->credential) {
+               return nullptr;
+       }
+
+       return strdup(app_data->credential);
+}
+
 int ttsd_data_get_speak_data_size(unsigned int uid)
 {
        lock_guard<mutex> lock(g_app_data_mutex);
index b4c7d86f64b2fba2578b36e25639d0604db4d2b9..d7e934dd53e955488ebce0fe486e780b20aff992 100644 (file)
@@ -81,6 +81,10 @@ int ttsd_data_set_mode(unsigned int uid, ttsd_mode_e mode);
 
 ttsd_mode_e ttsd_data_get_mode(unsigned int uid);
 
+int ttsd_data_set_credential(unsigned int uid, const char* credential);
+
+char* ttsd_data_get_credential(unsigned int uid);
+
 /* speak data */
 int ttsd_data_add_speak_data(unsigned int uid, speak_data_s* data);
 
index d6bd0ca154ab693c7476fc28621dff4c13c88748..382573bc2f276c1a4ba08478430dd9f34869e7ee 100644 (file)
@@ -63,12 +63,11 @@ static bool g_is_terminated = false;
 
 
 /* Function definitions */
-static int __synthesis(unsigned int uid, const char* credential);
+static int __synthesis(unsigned int uid);
 
 static Eina_Bool __wait_synthesis(void *data)
 {
        /* get current play */
-       char* credential = (char*)data;
        unsigned int uid = ttsd_data_get_current_playing();
 
        if (uid > 0) {
@@ -80,7 +79,7 @@ static Eina_Bool __wait_synthesis(void *data)
                        g_wait_timer = NULL;
                        if (TTSD_SYNTHESIS_CONTROL_DONE == synth_control) {
                                /* Start next synthesis */
-                               __synthesis(uid, credential);
+                               __synthesis(uid);
                        }
                }
        } else {
@@ -90,7 +89,7 @@ static Eina_Bool __wait_synthesis(void *data)
        return EINA_FALSE;
 }
 
-static int __synthesis(unsigned int uid, const char* credential)
+static int __synthesis(unsigned int uid)
 {
        SLOG(LOG_DEBUG, tts_tag(), "@@@ SYNTHESIS  START");
 
@@ -126,6 +125,8 @@ static int __synthesis(unsigned int uid, const char* credential)
                g_utt.uid = uid;
                g_utt.uttid = speak_data->utt_id;
 
+               char* credential = ttsd_data_get_credential(uid);
+
                SLOG(LOG_INFO, tts_tag(), "-----------------------------------------------------------");
                SLOG(LOG_INFO, tts_tag(), "ID : uid (%u), uttid(%d) ", g_utt.uid, g_utt.uttid);
                SLOG(LOG_INFO, tts_tag(), "Voice : langauge(%s), type(%d), speed(%d)", speak_data->lang, speak_data->vctype, speak_data->speed);
@@ -150,9 +151,11 @@ static int __synthesis(unsigned int uid, const char* credential)
                                ttsdc_ipc_send_set_state_message(pid, uid, APP_STATE_READY);
                        }
                } else {
-                       g_wait_timer = ecore_timer_add(0.05, __wait_synthesis, (void*)credential);
+                       g_wait_timer = ecore_timer_add(0.05, __wait_synthesis, NULL);
                }
 
+               free(credential);
+               credential = NULL;
                ttsd_data_clear_speak_data(&speak_data);
        } else {
                ttsd_data_clear_speak_data(&speak_data);
@@ -967,13 +970,15 @@ int ttsd_server_add_queue(unsigned int uid, const char* text, const char* lang,
                        }
                }
 
+               ttsd_data_set_credential(uid, credential);
+
                /* Check whether tts-engine is running or not */
                ttsd_synthesis_control_e synth_control = ttsd_get_synth_control();
                SLOG(LOG_INFO, tts_tag(), "[Server INFO] synth_control(%d)", synth_control);
                if (TTSD_SYNTHESIS_CONTROL_DOING == synth_control) {
                        SLOG(LOG_WARN, tts_tag(), "[Server WARNING] Engine has already been running.");
                } else {
-                       __synthesis(uid, credential);
+                       __synthesis(uid);
                }
        }
 
@@ -1089,6 +1094,8 @@ int ttsd_server_play(unsigned int uid, const char* credential)
                }
        }
 
+       ttsd_data_set_credential(uid, credential);
+
        /* Check whether tts-engine is running or not */
        clock_gettime(CLOCK_MONOTONIC_RAW, &g_request_playing);
        ttsd_synthesis_control_e synth_control = ttsd_get_synth_control();
@@ -1096,7 +1103,7 @@ int ttsd_server_play(unsigned int uid, const char* credential)
        if (TTSD_SYNTHESIS_CONTROL_DOING == synth_control) {
                SLOG(LOG_WARN, tts_tag(), "[Server WARNING] Engine has already been running.");
        } else {
-               __synthesis(uid, credential);
+               __synthesis(uid);
        }
 
        return TTSD_ERROR_NONE;