Create data structure for saving tidl proxy information 10/260010/4
authorSuyeon Hwang <stom.hwang@samsung.com>
Wed, 12 May 2021 07:07:57 +0000 (16:07 +0900)
committerSuyeon Hwang <stom.hwang@samsung.com>
Mon, 28 Jun 2021 01:34:54 +0000 (10:34 +0900)
Change-Id: I00a4583cd8b62527e3da5eddfd62951b72d5cad1
Signed-off-by: Suyeon Hwang <stom.hwang@samsung.com>
server/ttsd_data.cpp
server/ttsd_data.h
server/ttsd_tidl.c

index c61cf45dea03b52ebd5bf204f84b4343f3183655..6ba43497ee4631a00478996ae44c121b98512d0f 100644 (file)
@@ -18,7 +18,6 @@
 
 #include "ttsd_main.h"
 #include "ttsd_data.h"
-#include "ttsd_stub.h"
 
 using namespace std;
 
@@ -39,7 +38,6 @@ typedef struct
        std::list<sound_data_s*> m_wav_data;
 
        std::list<used_voice_s> m_used_voice;
-       rpc_port_tts_notify_cb_h notify_cb_h;
        tts_ipc_method_e ipc_method;
 } app_data_s;
 
@@ -166,7 +164,6 @@ int ttsd_data_new_client(int pid, int uid)
        app.uid = uid;
        app.utt_id_stopped = 0;
        app.state = APP_STATE_READY;
-       app.notify_cb_h = NULL;
        app.ipc_method = TTS_IPC_METHOD_UNDEFINED;
 
        g_app_list.insert(g_app_list.end(), app);
@@ -270,48 +267,6 @@ tts_ipc_method_e ttsd_data_get_ipc_method(int uid)
        return g_app_list[index].ipc_method;
 }
 
-int ttsd_data_set_notify_h(int uid, rpc_port_tts_notify_cb_h handle, void* user_data)
-{
-       int index = ttsd_data_is_client(uid);
-
-       if (index < 0) {
-               SECURE_SLOG(LOG_ERROR, tts_tag(), "[DATA ERROR] uid is not valid (%d)", uid);
-               return TTSD_ERROR_INVALID_PARAMETER;
-       }
-
-       if (rpc_port_tts_notify_cb_clone(handle, &(g_app_list[index].notify_cb_h)) != 0) {
-               return TTSD_ERROR_OPERATION_FAILED;
-       }
-
-       return TTSD_ERROR_NONE;
-}
-
-rpc_port_tts_notify_cb_h ttsd_data_get_notify_handle(int uid)
-{
-       int index = ttsd_data_is_client(uid);
-       SLOG(LOG_DEBUG, tts_tag(), "ttsd_data_is_client : index(%d)", index);
-       if (index < 0)  {
-               SECURE_SLOG(LOG_ERROR, tts_tag(), "[DATA ERROR] uid is not valid (%d)", uid);
-               return NULL;
-       }
-       return g_app_list[index].notify_cb_h;
-}
-
-int ttsd_data_unset_notify_h(int uid)
-{
-       int index = ttsd_data_is_client(uid);
-
-       if (index < 0)  {
-               SECURE_SLOG(LOG_ERROR, tts_tag(), "[DATA ERROR] uid is not valid (%d)", uid);
-               return TTSD_ERROR_INVALID_PARAMETER;
-       }
-
-       g_app_list[index].notify_cb_h = NULL;
-       SLOG(LOG_DEBUG, tts_tag(), "[DATA] uid(%d) callback is unseted", g_app_list[index].uid);
-
-       return TTSD_ERROR_NONE;
-}
-
 int ttsd_data_get_speak_data_size(int uid)
 {
        int index = 0;
index c127d8401e2bcf102a540045fb65a5a37aec1fbd..f5899fff82524c1d85f9c04167ccfce419979761 100644 (file)
@@ -76,12 +76,6 @@ int ttsd_data_set_ipc_method(int uid, tts_ipc_method_e method);
 
 tts_ipc_method_e ttsd_data_get_ipc_method(int uid);
 
-int ttsd_data_set_notify_h(int uid, rpc_port_tts_notify_cb_h handle, void* user_data);
-
-int ttsd_data_unset_notify_h(int uid);
-
-rpc_port_tts_notify_cb_h ttsd_data_get_notify_handle(int uid);
-
 /* speak data */
 int ttsd_data_add_speak_data(int uid, speak_data_s* data);
 
index 6a787eef739caea487625dae9550aa976b16adf3..f368021032f25b97dfc32d4634718c563add0479 100644 (file)
 
 #include "ttsd_tidl.h"
 
+typedef struct {
+       int uid;
+       rpc_port_tts_notify_cb_h notify_cb_h;
+} tts_tidl_proxy_info_s;
+
+static GList* g_tidl_proxy_infos = NULL;
+
 rpc_port_stub_tts_callback_s g_callback;
 
+static tts_tidl_proxy_info_s* __get_tidl_proxy_info_s(int uid)
+{
+       GList* iter = NULL;
+       tts_tidl_proxy_info_s* info = NULL;
+
+       if (g_list_length(g_tidl_proxy_infos) > 0) {
+               /* Get a first item */
+               iter = g_list_first(g_tidl_proxy_infos);
+
+               while (NULL != iter) {
+                       info = iter->data;
+                       if (info->uid == uid) {
+                               return info;
+                       }
+
+                       /* Next item */
+                       iter = g_list_next(iter);
+               }
+       }
+
+       return NULL;
+}
+
 void __send_msg(int pid, int uid, bundle* msg)
 {
        SLOG(LOG_INFO, tts_tag(), "[TIDL] start : send msg : pid(%d), uid(%d)", pid, uid);
-       rpc_port_tts_notify_cb_h handle;
+       tts_tidl_proxy_info_s* info = __get_tidl_proxy_info_s(uid);
+       if (NULL == info) {
+               SLOG(LOG_ERROR, tts_tag(), "[TIDL] Uid is not valid. pid(%d), uid(%d)", pid, uid);
+               return;
+       }
 
-       handle = ttsd_data_get_notify_handle(uid);
-       if (!handle) {
-               SLOG(LOG_INFO, tts_tag(), "ttsd_data_get_notify_handle handle null");
+       rpc_port_tts_notify_cb_h handle = info->notify_cb_h;
+       if (NULL == handle) {
+               SLOG(LOG_INFO, tts_tag(), "notify callback handle null");
                return;
        }
 
@@ -83,11 +117,21 @@ static void __register_cb(rpc_port_stub_tts_context_h context, int pid, int uid,
                credential_needed = TTS_CREDENTIAL_NEEDED_ALREADY_INITIALIZED;
        }
 
-       if (0 != ttsd_data_set_notify_h(uid, callback, NULL)) {
-               SLOG(LOG_ERROR, tts_tag(), "[Server ERROR] Fail to set notify callback");
+       tts_tidl_proxy_info_s* info = (tts_tidl_proxy_info_s*)calloc(1, sizeof(tts_tidl_proxy_info_s));
+       if (NULL == info) {
+               SLOG(LOG_ERROR, tts_tag(), "[TIDL ERROR] Fail to allocate memory for tidl proxy");
                return;
        }
 
+       if (0 != rpc_port_tts_notify_cb_clone(callback, &info->notify_cb_h)) {
+               SLOG(LOG_ERROR, tts_tag(), "[TIDL ERROR] Fail to set notify callback");
+               free(info);
+               return;
+       }
+
+       info->uid = uid;
+       g_tidl_proxy_infos = g_list_append(g_tidl_proxy_infos, info);
+
        SLOG(LOG_INFO, tts_tag(), "create player instance");
        ttsdc_tidl_send_hello(pid, uid, ret, credential_needed);
 
@@ -99,11 +143,22 @@ static void __register_cb(rpc_port_stub_tts_context_h context, int pid, int uid,
 static int __register_cb_sync(rpc_port_stub_tts_context_h context, int pid, int uid, rpc_port_tts_notify_cb_h callback, void* user_data)
 {
        SLOG(LOG_DEBUG, tts_tag(), ">>>>> TTS REGISTER CALLBACK synchronously uid(%d)", uid);
-       if (0 != ttsd_data_set_notify_h(uid, callback, NULL)) {
-               SLOG(LOG_ERROR, tts_tag(), "[Server ERROR] Fail to set notify callback");
+
+       tts_tidl_proxy_info_s* info = (tts_tidl_proxy_info_s*)calloc(1, sizeof(tts_tidl_proxy_info_s));
+       if (NULL == info) {
+               SLOG(LOG_ERROR, tts_tag(), "[TIDL ERROR] Fail to allocate memory for tidl proxy");
+               return TTSD_ERROR_OPERATION_FAILED;
+       }
+
+       if (0 != rpc_port_tts_notify_cb_clone(callback, &info->notify_cb_h)) {
+               SLOG(LOG_ERROR, tts_tag(), "[TIDL ERROR] Fail to set notify callback");
+               free(info);
                return TTSD_ERROR_OPERATION_FAILED;
        }
 
+       info->uid = uid;
+       g_tidl_proxy_infos = g_list_append(g_tidl_proxy_infos, info);
+
        SLOG(LOG_ERROR, tts_tag(), "<<<<<<<<<<<");
 
        return TTSE_ERROR_NONE;
@@ -162,6 +217,19 @@ static int __finalize_cb(rpc_port_stub_tts_context_h context, int uid, void *use
        if (0 != ttsd_server_finalize(uid)) {
                return -1;
        }
+
+       tts_tidl_proxy_info_s* info = __get_tidl_proxy_info_s(uid);
+       if (NULL == info) {
+               SLOG(LOG_ERROR, tts_tag(), "[TIDL ERROR] Fail to set notify callback");
+               return TTSD_ERROR_INVALID_PARAMETER;
+       }
+
+       rpc_port_tts_notify_cb_destroy(info->notify_cb_h);
+       info->notify_cb_h = NULL;
+
+       g_tidl_proxy_infos = g_list_remove(g_tidl_proxy_infos, info);
+       free(info);
+
        SLOG(LOG_DEBUG, tts_tag(), "<<<<<");
 
        return TTSE_ERROR_NONE;