Update UID of instant reprepare client 77/288377/4
authorSuyeon Hwang <stom.hwang@samsung.com>
Thu, 2 Feb 2023 08:10:38 +0000 (17:10 +0900)
committerSuyeon Hwang <stom.hwang@samsung.com>
Tue, 21 Feb 2023 03:02:38 +0000 (12:02 +0900)
- Requirement:
In order to start engine quickly, one of the clients needs to reprepare
instantly.

- Contents:
To make one of the clients reprepare instantly, this patch adds new
logic into the engine library. Through this patch, the engine library
will update the UID of the clieant which needs to reprepare instantly.
This UID update will occur when the connection of the service is changed.

Change-Id: I465c4e3444fbd177feb3bdabdb20338bbab5daf1
Signed-off-by: Suyeon Hwang <stom.hwang@samsung.com>
common/tts_config_mgr.c
common/tts_config_mgr.h
common/tts_defs.h
server/ttsd_config.c
server/ttsd_config.h
server/ttsd_data.cpp
server/ttsd_data.h
server/ttsd_dbus_server.c
server/ttsd_server.c
server/ttsd_server.h
server/ttsd_tidl.c

index 8cbe6abd59767617009cc71156de515b9dcd3fdb..cd862075765465b59674730d4182433c08dc7a25 100644 (file)
@@ -2139,3 +2139,87 @@ int tts_config_mgr_get_max_text_size(unsigned int* size)
 
        return TTS_CONFIG_ERROR_NONE;
 }
+
+int tts_config_mgr_get_instant_reprepare_client(unsigned int *uid)
+{
+       struct buxton_client *bux_cli = NULL;
+       int ret = buxton_open(&bux_cli, NULL, NULL);
+       if (0 != ret) {
+               SLOG(LOG_ERROR, TAG_TTSCONFIG, "[BUXTON2] buxton_open failed!! (%d)", ret);
+               return TTS_CONFIG_ERROR_OPERATION_FAILED;
+       }
+
+       struct buxton_layer *bux_layer = buxton_create_layer("system");
+       if (NULL == bux_layer) {
+               SLOG(LOG_ERROR, TAG_TTSCONFIG, "[BUXTON2] buxton_create_layer FAIL");
+               buxton_close(bux_cli);
+               return TTS_CONFIG_ERROR_OPERATION_FAILED;
+       }
+
+       struct buxton_value *bux_val = NULL;
+       ret = buxton_get_value_sync(bux_cli, bux_layer, TTS_VCONF_INSTANT_REPREPARE_CLIENT, &bux_val);
+       if (0 != ret || NULL == bux_val) {
+               SLOG(LOG_ERROR, TAG_TTSCONFIG, "[BUXTON2] buxton_get_value_sync failed!! (%d)", ret);
+               buxton_free_layer(bux_layer);
+               buxton_close(bux_cli);
+               return TTS_CONFIG_ERROR_OPERATION_FAILED;
+       }
+
+       unsigned int specified_uid = TTS_INVALID_UID;
+       ret = buxton_value_get_uint32(bux_val, &specified_uid);
+       if (0 != ret) {
+               SLOG(LOG_ERROR, TAG_TTSCONFIG, "[BUXTON2] buxton_value_get_uint32 failed!! (%d)", ret);
+               ret = TTS_CONFIG_ERROR_OPERATION_FAILED;
+       } else {
+               SLOG(LOG_DEBUG, TAG_TTSCONFIG, "[BUXTON2] buxton_value_get_uint32: ret(%d), key(%s), uid(%u)", ret, TTS_VCONF_INSTANT_REPREPARE_CLIENT, specified_uid);
+               *uid = specified_uid;
+               ret = TTS_CONFIG_ERROR_NONE;
+       }
+
+       buxton_value_free(bux_val);
+       buxton_free_layer(bux_layer);
+       buxton_close(bux_cli);
+
+       return ret;
+}
+
+int tts_config_mgr_set_instant_reprepare_client(const unsigned int uid)
+{
+       struct buxton_client *bux_cli = NULL;
+       int ret = buxton_open(&bux_cli, NULL, NULL);
+       if (0 != ret) {
+               SLOG(LOG_ERROR, TAG_TTSCONFIG, "[BUXTON2] buxton_open failed!! (%d)", ret);
+               return TTS_CONFIG_ERROR_OPERATION_FAILED;
+       }
+
+       struct buxton_layer *bux_layer = buxton_create_layer("system");
+       if (NULL == bux_layer) {
+               SLOG(LOG_ERROR, TAG_TTSCONFIG, "[BUXTON2] buxton_create_layer FAIL");
+               buxton_close(bux_cli);
+               return TTS_CONFIG_ERROR_OPERATION_FAILED;
+       }
+
+       struct buxton_value *bux_val = buxton_value_create_uint32(uid);
+       if (NULL == bux_val) {
+               SLOG(LOG_ERROR, TAG_TTSCONFIG, "[BUXTON2] buxton_value_create_uint32 FAIL");
+               buxton_free_layer(bux_layer);
+               buxton_close(bux_cli);
+               return TTS_CONFIG_ERROR_OPERATION_FAILED;
+       }
+
+       SLOG(LOG_DEBUG, TAG_TTSCONFIG, "[BUXTON2] layer: %s", buxton_layer_get_name(bux_layer));
+       ret = buxton_set_value_sync(bux_cli, bux_layer, TTS_VCONF_INSTANT_REPREPARE_CLIENT, bux_val);
+       if (0 != ret) {
+               SLOG(LOG_ERROR, TAG_TTSCONFIG, "[BUXTON2] buxton_set_value_sync failed!! (%d)", ret);
+               ret = TTS_CONFIG_ERROR_OPERATION_FAILED;
+       } else {
+               SLOG(LOG_DEBUG, TAG_TTSCONFIG, "[BUXTON2] buxton_set_value_sync: ret(%d), key(%s), uid(%u)", ret, TTS_VCONF_INSTANT_REPREPARE_CLIENT, uid);
+               ret = TTS_CONFIG_ERROR_NONE;
+       }
+
+       buxton_value_free(bux_val);
+       buxton_free_layer(bux_layer);
+       buxton_close(bux_cli);
+
+       return ret;
+}
index 2f9537ac9d24db8b094faf8301a4d1e64001489f..220045772bbe5c3bc88f9cf3ec70b02911cf1429 100644 (file)
@@ -125,10 +125,12 @@ bool tts_config_check_default_engine_is_valid(const char* engine);
 
 bool tts_config_check_default_voice_is_valid(const char* language, int type);
 
-char* tts_config_get_message_path(int mode, int pid);
-
 int tts_config_mgr_get_max_text_size(unsigned int* size);
 
+int tts_config_mgr_get_instant_reprepare_client(unsigned int *uid);
+
+int tts_config_mgr_set_instant_reprepare_client(const unsigned int uid);
+
 
 #ifdef __cplusplus
 }
index 300b6ba0b3416711fa7d7a920cfeebc269a98864..5a97078590300bc28b05fd2eea7d0ea46f2c2222 100644 (file)
@@ -141,6 +141,8 @@ extern "C" {
 
 #define TTS_PLAYING_STATUS_KEY "memory/tts/engine/voice-guide-playing"
 
+#define TTS_VCONF_INSTANT_REPREPARE_CLIENT "db/voice/tts/instant-reprepare-client"
+
 
 /******************************************************************************************
 * Defines for log tag
index e5bd49b599219a4040dff99f694af2f555d1c2ab..3743d531b752411307b37b640ce913f633a2266e 100644 (file)
@@ -235,3 +235,28 @@ int ttsd_config_save_error(unsigned int uid, int uttid, const char* lang, int vc
 
        return 0;
 }
+
+int ttsd_config_get_instant_reprepare_client(unsigned int *uid)
+{
+       if (NULL == uid)
+               return TTSD_ERROR_INVALID_PARAMETER;
+
+       int ret = tts_config_mgr_get_instant_reprepare_client(uid);
+       if (TTS_CONFIG_ERROR_NONE != ret) {
+               SLOG(LOG_ERROR, tts_tag(), "[Config ERROR] Fail to get uid of instatly reprepared client. ret(%d)", ret);
+               return TTSD_ERROR_OPERATION_FAILED;
+       }
+
+       return TTSD_ERROR_NONE;
+}
+
+int ttsd_config_set_instant_reprepare_client(const unsigned int uid)
+{
+       int ret = tts_config_mgr_set_instant_reprepare_client(uid);
+       if (TTS_CONFIG_ERROR_NONE != ret) {
+               SLOG(LOG_ERROR, tts_tag(), "[Config ERROR] Fail to set uid of instatly reprepared client. ret(%d)", ret);
+               return TTSD_ERROR_OPERATION_FAILED;
+       }
+
+       return TTSD_ERROR_NONE;
+}
index c4641d28f8be3b827cbd8b9b9cc3ce293bc95e40..b1a8bb665a90b27d8a91742a83ebf28f56494119 100644 (file)
@@ -54,6 +54,10 @@ int ttsd_config_get_bg_volume_ratio(double* ratio);
 int ttsd_config_save_error(unsigned int uid, int uttid, const char* lang, int vctype, const char* text,
                           const char* func, int line, const char* message);
 
+int ttsd_config_get_instant_reprepare_client(unsigned int *uid);
+
+int ttsd_config_set_instant_reprepare_client(const unsigned int uid);
+
 #ifdef __cplusplus
 }
 #endif
index c8c5503904f504edb133f1367e1ef71836a30b98..4808bc9168c38c57e32f08ad65fae32538335551 100644 (file)
@@ -889,6 +889,17 @@ int ttsd_data_foreach_clients(ttsd_data_get_client_cb callback, void* user_data)
        return 0;
 }
 
+unsigned int ttsd_data_get_first_client_uid()
+{
+       unique_lock<mutex> lock(g_app_data_mutex);
+       if (g_app_list.empty()) {
+               SLOG(LOG_ERROR, tts_tag(), "[DATA ERROR] There is no valid client");
+               return TTS_INVALID_UID;
+       }
+
+       return g_app_list[0].uid;
+}
+
 bool ttsd_data_is_uttid_valid(unsigned int uid, int uttid)
 {
        lock_guard<mutex> lock(g_app_data_mutex);
index 0b0d8ad137d1792b1a93640241a936e5815282d5..15bd856cca392e087572b7915a97872822b529d5 100644 (file)
@@ -143,6 +143,8 @@ typedef bool(*ttsd_data_get_client_cb)(int pid, unsigned int uid, app_tts_state_
 
 int ttsd_data_foreach_clients(ttsd_data_get_client_cb callback, void* user_data);
 
+unsigned int ttsd_data_get_first_client_uid();
+
 bool ttsd_data_is_uttid_valid(unsigned int uid, int uttid);
 
 int ttsd_data_get_same_pid_client_count(int pid);
index 037d8c8e4059178c1de12cd227eb6d8399f57078..d338d88cd727f356227a46ad42d094d59a8e80c4 100644 (file)
@@ -57,11 +57,9 @@ int ttsd_dbus_server_hello(DBusConnection* conn, DBusMessage* msg)
                        if (0 != ret) {
                                SLOG(LOG_ERROR, tts_tag(), "[IN ERROR] ttsd Hello : server initialize, ret(%d)", ret);
                        }
-                       if (false == is_credential_needed) {
-                               credential_needed = 0;
-                       } else {
-                               credential_needed = 1;
-                       }
+                       ttsd_server_update_instant_reprepare_client();
+
+                       credential_needed = is_credential_needed ? 1 : 0;
                } else {
                        SLOG(LOG_INFO, tts_tag(), "[IN] ttsd hello : already initialized. pid(%d), uid(%u)", pid, uid);
                        ret = TTS_ERROR_ALREADY_INITIALIZED;
@@ -127,6 +125,7 @@ int ttsd_dbus_server_initialize(DBusConnection* conn, DBusMessage* msg)
        } else {
                SECURE_SLOG(LOG_DEBUG, tts_tag(), "[IN] tts initialize : pid(%d), uid(%u), mode(%d)", pid, uid, mode);
                ret = ttsd_server_initialize(pid, uid, (ttsd_mode_e)mode, registered_event_mask, TTS_IPC_METHOD_DBUS, &service_state, &credential_needed);
+               ttsd_server_update_instant_reprepare_client();
        }
 
        DBusMessage* reply;
@@ -179,7 +178,8 @@ int ttsd_dbus_server_finalize(DBusConnection* conn, DBusMessage* msg)
                ret = TTSD_ERROR_OPERATION_FAILED;
        } else {
                SECURE_SLOG(LOG_DEBUG, tts_tag(), "[IN] tts finalize : uid(%u)", uid);
-               ret =  ttsd_server_finalize(uid);
+               ret = ttsd_server_finalize(uid);
+               ttsd_server_update_instant_reprepare_client();
        }
 
        DBusMessage* reply;
index 2f323b1a20dc332b50432624bfc4c84a9476e4c8..268283975d160a6384fb8ce7a5c86f4bd43ec968 100644 (file)
@@ -880,6 +880,28 @@ int ttsd_server_finalize(unsigned int uid)
        return TTSD_ERROR_NONE;
 }
 
+int ttsd_server_update_instant_reprepare_client()
+{
+       SLOG(LOG_INFO, tts_tag(), "[Server] Update instant reprepare client");
+       unsigned int instant_reprepare_uid = TTS_INVALID_UID;
+       ttsd_config_get_instant_reprepare_client(&instant_reprepare_uid);
+
+       if (0 <= ttsd_data_is_client(instant_reprepare_uid)) {
+               SLOG(LOG_INFO, tts_tag(), "[Server] Uid(%u) is valid. Still no need to changee the value", instant_reprepare_uid);
+               return TTSD_ERROR_NONE;
+       }
+
+       unsigned int new_instant_reprepare_uid = ttsd_data_get_first_client_uid();
+       int ret = ttsd_config_set_instant_reprepare_client(new_instant_reprepare_uid);
+       if (TTSD_ERROR_NONE != ret) {
+               SLOG(LOG_ERROR, tts_tag(), "[Server] Fail to set UID(%u) of instant reprepare client", instant_reprepare_uid);
+               return TTSD_ERROR_OPERATION_FAILED;
+       }
+       SLOG(LOG_INFO, tts_tag(), "[Server] Update UID(%u) of instant reprepare client", instant_reprepare_uid);
+
+       return TTSD_ERROR_NONE;
+}
+
 static bool __is_connected_to_network()
 {
        /* Check network */
index dde10bc88f96d32acf18e1245eae8ce8027c5c95..4576074e6a4e2767af8f325255d898fc85860b8a 100644 (file)
@@ -53,6 +53,8 @@ int ttsd_server_initialize(int pid, unsigned int uid, ttsd_mode_e mode, int regi
 
 int ttsd_server_finalize(unsigned int uid);
 
+int ttsd_server_update_instant_reprepare_client();
+
 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);
index 86baa2e5a31719ee49128b628f1f0b02f21b4222..0f15a441f71ec9ec89440a8151667928a84f9a33 100644 (file)
@@ -107,6 +107,7 @@ static void __destroy_client_cb(rpc_port_stub_tts_context_h context, void *user_
                if (0 != ttsd_server_finalize(uid)) {
                        return;
                }
+               ttsd_server_update_instant_reprepare_client();
 
                pthread_mutex_lock(&g_tidl_proxy_infos_mutex);
                tts_tidl_proxy_info_s* info = __get_tidl_proxy_info_s(uid);
@@ -155,6 +156,7 @@ static void __register_cb(rpc_port_stub_tts_context_h context, int pid, int uid,
                if (0 != ret) {
                        SLOG(LOG_ERROR, tts_tag(), "[IN ERROR] ttsd Hello : server initialize, ret(%d)", ret);
                }
+               ttsd_server_update_instant_reprepare_client();
 
                credential_needed = is_credential_needed ? 1 : 0;
        } else {
@@ -277,6 +279,7 @@ static int __initialize_cb(rpc_port_stub_tts_context_h context, int pid, int uid
        if (0 != ttsd_server_initialize(pid, u_uid, mode, registered_event_mask, TTS_IPC_METHOD_TIDL, &tmp_service_state, credential_needed)) {
                return TTSD_ERROR_OPERATION_FAILED;
        }
+       ttsd_server_update_instant_reprepare_client();
 
        *service_state = (int)tmp_service_state;
        SLOG(LOG_ERROR, tts_tag(), "[OUT] tts initialize service_state(%d), credential_needed(%d)", tmp_service_state, *credential_needed);
@@ -293,6 +296,7 @@ static int __finalize_cb(rpc_port_stub_tts_context_h context, int uid, void *use
                SLOG(LOG_ERROR, tts_tag(), "[ERROR] TTS FINALIZE (%u) fail (%d/%s) <<<<<", u_uid, ret, get_error_message(ret));
                return ret;
        }
+       ttsd_server_update_instant_reprepare_client();
 
        pthread_mutex_lock(&g_tidl_proxy_infos_mutex);
        tts_tidl_proxy_info_s* info = __get_tidl_proxy_info_s(u_uid);