+int tts_set_server_tts(tts_h tts, const char* credential)
+{
+ if (0 != __tts_get_feature_enabled()) {
+ return TTS_ERROR_NOT_SUPPORTED;
+ }
+
+ if (NULL == tts || NULL == credential) {
+ SLOG(LOG_ERROR, TAG_TTSC, "[ERROR] Input parameter is null");
+ return TTS_ERROR_INVALID_PARAMETER;
+ }
+
+ tts_client_s* client = tts_client_get(tts);
+
+ if (NULL == client) {
+ SLOG(LOG_ERROR, TAG_TTSC, "[ERROR] Get state : A handle is not valid");
+ return TTS_ERROR_INVALID_PARAMETER;
+ }
+
+ if (TTS_STATE_CREATED != client->current_state && TTS_STATE_READY != client->current_state) {
+ SLOG(LOG_ERROR, TAG_TTSC, "[ERROR] The current state is invalid (%d).", client->current_state);
+ return TTS_ERROR_INVALID_STATE;
+ }
+
+ if (NULL != client->credential) {
+ free(client->credential);
+ client->credential = NULL;
+ }
+
+ client->credential = strdup(credential);
+ if (NULL == client->credential) {
+ SLOG(LOG_ERROR, TAG_TTSC, "[ERROR] Fail to allocate memory");
+ return TTS_ERROR_OUT_OF_MEMORY;
+ }
+
+ client->internal = true;
+
+ char* key = NULL;
+ if (NULL != credential)
+ key = strdup("EnableServerTTS");
+ else
+ key = strdup("DisableServerTTS");
+ if (NULL == key) {
+ SLOG(LOG_ERROR, TAG_TTSC, "[ERROR] Fail to allocate memory");
+ return TTS_ERROR_OUT_OF_MEMORY;
+ }
+
+ int pid = getpid();
+ char* appid = NULL;
+ int ret = app_manager_get_app_id(pid, &appid);
+ if (0 != ret) {
+ SLOG(LOG_ERROR, TAG_TTSC, "[ERROR] Fail to get appid, ret(%d), pid(%d), appid(%s)", ret, pid, appid);
+ free(key);
+ key = NULL;
+ return TTS_ERROR_OPERATION_FAILED;
+ }
+
+ ret = tts_set_private_data(tts, 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);
+ key = NULL;
+ return ret;
+ }
+
+ free(appid);
+ appid = NULL;
+ free(key);
+ key = NULL;
+
+ SLOG(LOG_DEBUG, TAG_TTSC, "=====");
+ SLOG(LOG_DEBUG, TAG_TTSC, " ");
+
+ return TTS_ERROR_NONE;
+}
+