Send new state to client synchornously 50/269250/3
authorSuyeon Hwang <stom.hwang@samsung.com>
Wed, 12 Jan 2022 04:30:41 +0000 (13:30 +0900)
committerSuyeon Hwang <stom.hwang@samsung.com>
Thu, 20 Jan 2022 08:38:17 +0000 (17:38 +0900)
Current code sends new state asynchornously using ecore timer in order to prohibit main loop
from being blocked. However, sending new state can be delayed by the event from
ecore_main_loop_thread_safe_call_async(). Callback registered by this function has higher priority
than the ecore timer callback. This may cause uninteded behavior on client side.

To prevent this situation, this patch sends new state synchornously. By this patch, client gets
new state immediately after stop player. Of course, IPC overhead can be added into
ttsd_server_play(), but the overhead is short enough.

Change-Id: Ia580edbd957d57a215d3d760fdcd8de54b73c49c
Signed-off-by: Suyeon Hwang <stom.hwang@samsung.com>
server/ttsd_server.c

index 382573bc2f276c1a4ba08478430dd9f34869e7ee..8820e746d08a4c8da0277d50d9081f65d13ed656 100644 (file)
@@ -985,13 +985,13 @@ int ttsd_server_add_queue(unsigned int uid, const char* text, const char* lang,
        return TTSD_ERROR_NONE;
 }
 
-Eina_Bool __send_interrupt_client(void *data)
+void __send_interrupt_client(unsigned int uid)
 {
-       unsigned int uid = (uintptr_t)data;
+       SLOG(LOG_INFO, tts_tag(), "[Server] Send new state by policy. uid(%u)", uid);
        int pid = ttsd_data_get_pid(uid);
        if (pid <= 0) {
                SLOG(LOG_ERROR, tts_tag(), "[Server ERROR] Fail to get pid. uid(%u), pid(%d)", uid, pid);
-               return EINA_FALSE;
+               return;
        }
 
        ttsd_mode_e mode = ttsd_data_get_mode(uid);
@@ -1002,7 +1002,8 @@ Eina_Bool __send_interrupt_client(void *data)
                ttsdc_ipc_send_set_state_message(pid, uid, APP_STATE_PAUSED);
        }
 
-       return EINA_FALSE;
+       SLOG(LOG_INFO, tts_tag(), "[Server] Finish to send new state by policy. uid(%u)", uid);
+       return;
 }
 
 int ttsd_server_play(unsigned int uid, const char* credential)
@@ -1046,8 +1047,7 @@ int ttsd_server_play(unsigned int uid, const char* credential)
                                SLOG(LOG_WARN, tts_tag(), "[Server ERROR] Fail to stop server and player : uid (%u)", current_uid);
                        }
 
-                       uintptr_t p_current_uid = (uintptr_t)current_uid;
-                       ecore_timer_add(0, __send_interrupt_client, (void*)p_current_uid);
+                       __send_interrupt_client(current_uid);
                } else {
                        /* Default mode policy of interrupt is "Pause" */
 
@@ -1062,8 +1062,7 @@ int ttsd_server_play(unsigned int uid, const char* credential)
                        /* change state */
                        ttsd_data_set_client_state(current_uid, APP_STATE_PAUSED);
 
-                       uintptr_t p_current_uid = (uintptr_t)current_uid;
-                       ecore_timer_add(0, __send_interrupt_client, (void*)p_current_uid);
+                       __send_interrupt_client(current_uid);
                }
        }
 
@@ -1315,8 +1314,7 @@ int ttsd_server_play_pcm(unsigned int uid)
                                SLOG(LOG_WARN, tts_tag(), "[Server ERROR] Fail to stop server and player : uid (%u)", current_uid);
                        }
 
-                       uintptr_t p_current_uid = (uintptr_t)current_uid;
-                       ecore_timer_add(0, __send_interrupt_client, (void*)p_current_uid);
+                       __send_interrupt_client(current_uid);
                } else {
                        /* Default mode policy of interrupt is "Pause" */
 
@@ -1331,8 +1329,7 @@ int ttsd_server_play_pcm(unsigned int uid)
                        /* change state */
                        ttsd_data_set_client_state(current_uid, APP_STATE_PAUSED);
 
-                       uintptr_t p_current_uid = (uintptr_t)current_uid;
-                       ecore_timer_add(0, __send_interrupt_client, (void*)p_current_uid);
+                       __send_interrupt_client(current_uid);
                }
        }