Implement tts_prepare_sync() on tidl method 07/260007/3
authorSuyeon Hwang <stom.hwang@samsung.com>
Wed, 21 Apr 2021 02:53:01 +0000 (11:53 +0900)
committerSuyeon Hwang <stom.hwang@samsung.com>
Fri, 25 Jun 2021 11:32:45 +0000 (20:32 +0900)
Change-Id: I583eab761d9af9083257dfdc77344c1595231187
Signed-off-by: Suyeon Hwang <stom.hwang@samsung.com>
client/tts_tidl.c
server/ttsd_tidl.c
tidl/tts.tidl

index 9754996..d8c407e 100644 (file)
@@ -24,6 +24,7 @@ typedef struct {
        int uid;
        bool connected;
        rpc_port_proxy_tts_h rpc_h;
+       rpc_port_tts_notify_cb_h notify_cb_h;
        int mode;
 } tts_tidl_info_s;
 
@@ -396,19 +397,53 @@ int tts_tidl_request_hello(int uid)
 
        SLOG(LOG_DEBUG, TAG_TTSC, ">>>>> TTS Hello");
        /* register callback - needed to create new client before adding callback */
-       rpc_port_tts_notify_cb_h cb = rpc_port_tts_notify_cb_create(__notify_cb, false, NULL);
-       if (0 != rpc_port_proxy_tts_invoke_register_cb(info->rpc_h, client->pid, uid, cb)) {
-               SLOG(LOG_ERROR, TAG_TTSC, "[ERROR] Failed to invoke register");
-               return TTS_ERROR_OPERATION_FAILED;
+       if (NULL != info->notify_cb_h) {
+               rpc_port_proxy_tts_notify_cb_dispose(info->rpc_h, info->notify_cb_h);
+               info->notify_cb_h = NULL;
        }
 
+       info->notify_cb_h = rpc_port_tts_notify_cb_create(__notify_cb, false, NULL);
+       rpc_port_proxy_tts_invoke_register_cb(info->rpc_h, client->pid, uid, info->notify_cb_h);
+
        SLOG(LOG_DEBUG, TAG_TTSC, "<<<<");
        return TTS_ERROR_NONE;
 }
 
 int tts_tidl_request_hello_sync(int uid)
 {
-       //TODO implement when adding sync api
+       SLOG(LOG_DEBUG, TAG_TTSC, "[TIDL] tts_tidl_request_hello");
+
+       tts_client_s* client = tts_client_get_by_uid(uid);
+       if (NULL == client) {
+               SLOG(LOG_ERROR, TAG_TTSC, "[ERROR] Fail to get client");
+               return TTS_ERROR_INVALID_PARAMETER;
+       }
+
+       tts_tidl_info_s* info = __get_tidl_info_s(uid);
+       if (NULL == info) {
+               SLOG(LOG_ERROR, TAG_TTSC, "[ERROR] Fail to get tidl info");
+               return TTS_ERROR_INVALID_PARAMETER;
+       }
+
+       if (!info->connected) {
+               SLOG(LOG_ERROR, TAG_TTSC, "[ERROR] Not Connected");
+               return TTS_ERROR_OPERATION_FAILED;
+       }
+
+       SLOG(LOG_DEBUG, TAG_TTSC, ">>>>> TTS Hello");
+       /* register callback - needed to create new client before adding callback */
+       if (NULL != info->notify_cb_h) {
+               rpc_port_proxy_tts_notify_cb_dispose(info->rpc_h, info->notify_cb_h);
+               info->notify_cb_h = NULL;
+       }
+
+       info->notify_cb_h = rpc_port_tts_notify_cb_create(__notify_cb, false, NULL);
+       if (0 != rpc_port_proxy_tts_invoke_register_cb_sync(info->rpc_h, client->pid, uid, info->notify_cb_h)) {
+               SLOG(LOG_ERROR, TAG_TTSC, "[ERROR] Failed to invoke register");
+               return TTS_ERROR_OPERATION_FAILED;
+       }
+
+       SLOG(LOG_DEBUG, TAG_TTSC, "<<<<");
        return TTS_ERROR_NONE;
 }
 
index 2693dbb..b9f7154 100644 (file)
@@ -61,19 +61,19 @@ static void __destroy_client_cb(rpc_port_stub_tts_context_h context, void *user_
        free(sender);
 }
 
-static int __register_cb(rpc_port_stub_tts_context_h context, int pid, int uid, rpc_port_tts_notify_cb_h callback, void* user_data)
+static void __register_cb(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 uid(%d)", uid);
 
        bool credential_needed = false;
        if (0 != ttsd_server_initialize(pid, uid, TTS_IPC_METHOD_TIDL, &credential_needed)) {
                SLOG(LOG_ERROR, tts_tag(), "[IN ERROR] ttsd Hello : server initialize");
-               return TTSE_ERROR_OPERATION_FAILED;
+               return;
        }
 
        if (0 != ttsd_data_set_notify_h(uid, callback, NULL)) {
                SLOG(LOG_ERROR, tts_tag(), "[Server ERROR] Fail to set notify callback");
-               return TTSD_ERROR_OPERATION_FAILED;
+               return;
        }
 
        SLOG(LOG_INFO, tts_tag(), "create player instance");
@@ -81,6 +81,19 @@ static int __register_cb(rpc_port_stub_tts_context_h context, int pid, int uid,
 
        SLOG(LOG_ERROR, tts_tag(), "<<<<<<<<<<<");
 
+       return;
+}
+
+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");
+               return TTSD_ERROR_OPERATION_FAILED;
+       }
+
+       SLOG(LOG_ERROR, tts_tag(), "<<<<<<<<<<<");
+
        return TTSE_ERROR_NONE;
 }
 
@@ -135,7 +148,7 @@ static int __initialize_cb(rpc_port_stub_tts_context_h context, int pid, int uid
        SECURE_SLOG(LOG_DEBUG, tts_tag(), "[IN] tts initialize : pid(%d), uid(%d)", pid , uid);
 
        if (0 != ttsd_server_initialize(pid, uid, TTS_IPC_METHOD_TIDL, credential_needed)) {
-               return -1;
+               return TTSD_ERROR_OPERATION_FAILED;
        }
        SLOG(LOG_DEBUG, tts_tag(), "[OUT] tts initialize credential_needed(%d)", *credential_needed);
 
@@ -281,6 +294,7 @@ int ttsd_tidl_open_connection()
        g_callback.terminate = __destroy_client_cb;
        g_callback.set_mode = __set_mode_cb;
        g_callback.register_cb = __register_cb;
+       g_callback.register_cb_sync = __register_cb_sync;
        g_callback.unregister_cb = __unregister_cb;
        g_callback.initialize = __initialize_cb;
        g_callback.finalize = __finalize_cb;
index 2ba57d7..0547c79 100644 (file)
@@ -1,6 +1,7 @@
 interface tts {
        void notify_cb(int pid, int uid, bundle msg) delegate;
-       int register_cb(int pid, int uid, notify_cb callback);
+       void register_cb(int pid, int uid, notify_cb callback) async;
+       int register_cb_sync(int pid, int uid, notify_cb callback);
        int unregister_cb(int uid);
 
        int set_mode(int mode);