Extract function about private data from tts.c 11/257111/2
authorSuyeon Hwang <stom.hwang@samsung.com>
Mon, 21 Dec 2020 10:58:14 +0000 (19:58 +0900)
committerSuyeon Hwang <stom.hwang@samsung.com>
Thu, 27 May 2021 04:45:11 +0000 (13:45 +0900)
Change-Id: Ia9c623f4344896b8235c975e44770dc0d53e660a
Signed-off-by: Suyeon Hwang <stom.hwang@samsung.com>
client/tts.c
client/tts_core.c
client/tts_core.h

index 59bb04f4df881b1ce1755b42effcc2e433619df6..8907354568da73c0d616faa0dd287f7f188c27d0 100644 (file)
@@ -493,6 +493,7 @@ int tts_set_server_tts(tts_h tts, const char* credential)
                return TTS_ERROR_INVALID_PARAMETER;
        }
 
+       // TODO: fix state check, because set_private_data runs only ready state
        tts_state_e current_state = tts_client_get_current_state(client);
        if (TTS_STATE_CREATED != current_state && TTS_STATE_READY != current_state) {
                SLOG(LOG_ERROR, TAG_TTSC, "[ERROR] The current state is invalid");
@@ -543,7 +544,7 @@ int tts_set_server_tts(tts_h tts, const char* credential)
                return TTS_ERROR_OPERATION_FAILED;
        }
 
-       ret = tts_set_private_data(tts, key, appid);
+       ret = tts_core_set_private_data(client, key, appid);
        if (0 != ret) {
                SLOG(LOG_ERROR, TAG_TTSC, "[ERROR] Fail to set private data, ret(%d), pid(%d), appid(%s)", ret, pid, appid);
                free(key);
@@ -1211,35 +1212,10 @@ int tts_set_private_data(tts_h tts, const char* key, const char* data)
                return TTS_ERROR_INVALID_PARAMETER;
        }
 
-       // TODO: move into tts_core
-       int uid = tts_client_get_uid(client);
-       int ret = -1;
-       int count = 0;
-       bool is_prepared = false;
-       while (0 != ret) {
-               ret = tts_ipc_request_set_private_data(uid, key, data);
-               if (0 != ret) {
-                       //LCOV_EXCL_START
-                       if (TTS_ERROR_INVALID_PARAMETER == ret && false == is_prepared) {
-                               tts_client_set_current_state(client, TTS_STATE_CREATED);
-                               if (0 == tts_core_prepare_sync(client)) {
-                                       is_prepared = true;
-                                       SLOG(LOG_INFO, TAG_TTSC, "[INFO] Success tts_prepare_sync");
-                               }
-                       } else if (TTS_ERROR_TIMED_OUT != ret) {
-                               SLOG(LOG_ERROR, TAG_TTSC, "[ERROR] result : %s", __tts_get_error_code(ret));
-                               return ret;
-                       } else {
-                               SLOG(LOG_WARN, TAG_TTSC, "[WARNING] retry : %s", __tts_get_error_code(ret));
-                               usleep(10000);
-                               count++;
-                               if (TTS_RETRY_COUNT == count) {
-                                       SLOG(LOG_ERROR, TAG_TTSC, "[ERROR] Fail to request");
-                                       return ret;
-                               }
-                       }
-                       //LCOV_EXCL_STOP
-               }
+       int ret = tts_core_set_private_data(client, key, data);
+       if (TTS_ERROR_NONE != ret) {
+               SLOG(LOG_ERROR, TAG_TTSC, "[ERROR] Fail to request set private data. ret(%s)", __tts_get_error_code(ret));
+               return ret;
        }
 
        SLOG(LOG_DEBUG, TAG_TTSC, "@@@");
@@ -1271,49 +1247,16 @@ int tts_get_private_data(tts_h tts, const char* key, char** data)
                return TTS_ERROR_INVALID_STATE;
        }
 
-       // TODO: move into tts_core
-       int uid = tts_client_get_uid(client);
-       int ret = -1;
-       int count = 0;
-       bool is_prepared = false;
-       while (0 != ret) {
-               ret = tts_ipc_request_get_private_data(uid, key, data);
-               if (0 != ret) {
-                       //LCOV_EXCL_START
-                       if (TTS_ERROR_INVALID_PARAMETER == ret && false == is_prepared) {
-                               tts_client_set_current_state(client, TTS_STATE_CREATED);
-                               if (0 == tts_core_prepare_sync(client)) {
-                                       is_prepared = true;
-                                       SLOG(LOG_INFO, TAG_TTSC, "[INFO] Success tts_prepare_sync");
-                               }
-                       } else if (TTS_ERROR_TIMED_OUT != ret) {
-                               SLOG(LOG_ERROR, TAG_TTSC, "[ERROR] result : %s", __tts_get_error_code(ret));
-                               return ret;
-                       } else {
-                               SLOG(LOG_WARN, TAG_TTSC, "[WARNING] retry : %s", __tts_get_error_code(ret));
-                               usleep(10000);
-                               count++;
-                               if (TTS_RETRY_COUNT == count) {
-                                       SLOG(LOG_ERROR, TAG_TTSC, "[ERROR] Fail to request");
-                                       return ret;
-                               }
-                       }
-                       //LCOV_EXCL_STOP
-               }
-       }
-
-       if (0 == strncmp(*data, "NULL", strlen(*data))) {
-               free(*data);
-               *data = NULL;
+       int ret = tts_core_get_private_data(client, key, data);
+       if (TTS_ERROR_NONE != ret) {
+               SLOG(LOG_ERROR, TAG_TTSC, "[ERROR] Fail to request get private data. ret(%s)", __tts_get_error_code(ret));
+               return ret;
        }
 
        SLOG(LOG_DEBUG, TAG_TTSC, "@@@");
        return 0;
 }
 
-//LCOV_EXCL_START
-//LCOV_EXCL_STOP
-
 int tts_set_state_changed_cb(tts_h tts, tts_state_changed_cb callback, void* user_data)
 {
        if (0 != __tts_get_feature_enabled()) {
index 0a688fe4e1d5b80daf167a8784ca0bb8c0ad1bc9..97054d782f66caca4d824de339f464e41e6c0685 100644 (file)
@@ -1444,3 +1444,100 @@ int tts_core_stop_pcm(tts_client_s* client)
        SLOG(LOG_INFO, TAG_TTSC, "[INFO] Success tts_dbus_request_stop_pcm");
        return tts_core_set_current_state(client, TTS_STATE_READY);
 }
+
+int tts_core_set_private_data(tts_client_s* client, const char* key, const char* data)
+{
+       if (false == tts_client_is_valid_client(client)) {
+               SLOG(LOG_ERROR, TAG_TTSC, "[ERROR] Client is not valid.");
+               return TTS_ERROR_INVALID_PARAMETER;
+       }
+
+       int uid = tts_client_get_uid(client);
+       int ret = -1;
+       int count = 0;
+       bool is_prepared = false;
+       while (0 != ret) {
+               ret = tts_ipc_request_set_private_data(uid, key, data);
+               if (0 != ret) {
+                       //LCOV_EXCL_START
+                       if (TTS_ERROR_INVALID_PARAMETER == ret && false == is_prepared) {
+                               tts_client_set_current_state(client, TTS_STATE_CREATED);
+                               if (0 == tts_core_prepare_sync(client)) {
+                                       is_prepared = true;
+                                       SLOG(LOG_INFO, TAG_TTSC, "[INFO] Success tts_prepare_sync");
+                               }
+                       } else if (TTS_ERROR_TIMED_OUT != ret) {
+                               SLOG(LOG_ERROR, TAG_TTSC, "[ERROR] result : %s", __tts_get_error_code(ret));
+                               return ret;
+                       } else {
+                               SLOG(LOG_WARN, TAG_TTSC, "[WARNING] retry : %s", __tts_get_error_code(ret));
+                               usleep(10000);
+                               count++;
+                               if (TTS_RETRY_COUNT == count) {
+                                       SLOG(LOG_ERROR, TAG_TTSC, "[ERROR] Fail to request");
+                                       return ret;
+                               }
+                       }
+                       //LCOV_EXCL_STOP
+               }
+       }
+
+       if (TTS_ERROR_NONE != ret) {
+               SLOG(LOG_ERROR, TAG_TTSC, "[ERROR] Fail to request");
+               return ret;
+       }
+
+       SLOG(LOG_INFO, TAG_TTSC, "[INFO] Success tts_dbus_request_set_private_data");
+       return TTS_ERROR_NONE;
+}
+
+int tts_core_get_private_data(tts_client_s* client, const char* key, char** data)
+{
+       if (false == tts_client_is_valid_client(client)) {
+               SLOG(LOG_ERROR, TAG_TTSC, "[ERROR] Client is not valid.");
+               return TTS_ERROR_INVALID_PARAMETER;
+       }
+
+       int uid = tts_client_get_uid(client);
+       int ret = -1;
+       int count = 0;
+       bool is_prepared = false;
+       while (0 != ret) {
+               ret = tts_ipc_request_get_private_data(uid, key, data);
+               if (0 != ret) {
+                       //LCOV_EXCL_START
+                       if (TTS_ERROR_INVALID_PARAMETER == ret && false == is_prepared) {
+                               tts_client_set_current_state(client, TTS_STATE_CREATED);
+                               if (0 == tts_core_prepare_sync(client)) {
+                                       is_prepared = true;
+                                       SLOG(LOG_INFO, TAG_TTSC, "[INFO] Success tts_prepare_sync");
+                               }
+                       } else if (TTS_ERROR_TIMED_OUT != ret) {
+                               SLOG(LOG_ERROR, TAG_TTSC, "[ERROR] result : %s", __tts_get_error_code(ret));
+                               return ret;
+                       } else {
+                               SLOG(LOG_WARN, TAG_TTSC, "[WARNING] retry : %s", __tts_get_error_code(ret));
+                               usleep(10000);
+                               count++;
+                               if (TTS_RETRY_COUNT == count) {
+                                       SLOG(LOG_ERROR, TAG_TTSC, "[ERROR] Fail to request");
+                                       return ret;
+                               }
+                       }
+                       //LCOV_EXCL_STOP
+               }
+       }
+
+       if (TTS_ERROR_NONE != ret) {
+               SLOG(LOG_ERROR, TAG_TTSC, "[ERROR] Fail to request");
+               return ret;
+       }
+
+       if (0 == strncmp(*data, "NULL", strlen(*data))) {
+               free(*data);
+               *data = NULL;
+       }
+
+       SLOG(LOG_INFO, TAG_TTSC, "[INFO] Success tts_dbus_request_get_private_data");
+       return TTS_ERROR_NONE;
+}
index 64a278fd356c2e3ba994cc69b6fc4bfff5c966d6..81d099613422f67da7c0c17320c3e83c9c8d7d32 100644 (file)
@@ -59,6 +59,9 @@ int tts_core_add_pcm(tts_client_s* client, int event, const void* data, unsigned
 int tts_core_play_pcm(tts_client_s* client);
 int tts_core_stop_pcm(tts_client_s* client);
 
+int tts_core_set_private_data(tts_client_s* client, const char* key, const char* data);
+int tts_core_get_private_data(tts_client_s* client, const char* key, char** data);
+
 int tts_core_receive_hello(int uid, int ret, int credential_needed);
 int tts_core_handle_service_reset();