2 * Copyright (c) 2018 Samsung Electronics Co., Ltd All Rights Reserved
4 * Licensed under the Apache License, Version 2.0 (the License);
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
8 * http://www.apache.org/licenses/LICENSE-2.0
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an AS IS BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
28 std::list<vc_tts_data_s*> g_tts_data;
30 static pthread_mutex_t g_tts_data_mutex = PTHREAD_MUTEX_INITIALIZER;
32 int vc_data_add_tts_data(vc_tts_data_s* data)
35 SLOG(LOG_ERROR, TAG_VCC, "[DATA ERROR] tts data is NULL");
36 return VC_ERROR_INVALID_PARAMETER;
39 pthread_mutex_lock(&g_tts_data_mutex);
42 g_tts_data.push_back(data);
43 } catch (const std::bad_alloc&) {
44 SLOG(LOG_ERROR, TAG_VCC, "[DATA ERROR] Fail to insert tts data (bad alloc)");
45 pthread_mutex_unlock(&g_tts_data_mutex);
47 return VC_ERROR_OUT_OF_MEMORY;
50 pthread_mutex_unlock(&g_tts_data_mutex);
55 int vc_data_get_first_tts_data(vc_tts_data_s** data)
58 SLOG(LOG_ERROR, TAG_VCC, "[DATA ERROR] tts data is NULL");
59 return VC_ERROR_INVALID_PARAMETER;
62 SLOG(LOG_DEBUG, TAG_VCC, "[DATA] tts_data : %p", *data);
64 pthread_mutex_lock(&g_tts_data_mutex);
65 if (g_tts_data.empty()) {
66 SLOG(LOG_DEBUG, TAG_VCC, "[DATA] There is no tts data");
68 pthread_mutex_unlock(&g_tts_data_mutex);
69 return VC_ERROR_OPERATION_FAILED;
72 *data = g_tts_data.front();
73 g_tts_data.pop_front();
75 pthread_mutex_unlock(&g_tts_data_mutex);
80 int vc_data_get_tts_data_size()
84 pthread_mutex_lock(&g_tts_data_mutex);
85 data_size = g_tts_data.size();
87 pthread_mutex_unlock(&g_tts_data_mutex);
92 int vc_data_clear_tts_data(vc_tts_data_s** data)
94 SLOG(LOG_DEBUG, TAG_VCC, "[DATA] clear tts data");
97 SLOG(LOG_ERROR, TAG_VCC, "[DATA ERROR] tts data is NULL");
98 return VC_ERROR_INVALID_PARAMETER;
101 pthread_mutex_lock(&g_tts_data_mutex);
103 vc_tts_data_s *temp = *data;
104 SLOG(LOG_DEBUG, TAG_VCC, "[DEBUG] event(%d) data(%p) size(%d)", temp->event, temp->data, temp->data_size);
116 pthread_mutex_unlock(&g_tts_data_mutex);
118 return VC_ERROR_NONE;
121 int vc_data_clear_tts_data_by_uttid(int utt_id)
123 SLOG(LOG_DEBUG, TAG_VCC, "[DATA] clear tts data by utt_id(%d)", utt_id);
125 pthread_mutex_lock(&g_tts_data_mutex);
127 if (g_tts_data.empty()) {
128 SLOG(LOG_ERROR, TAG_VCC, "[DATA ERROR] There is no tts data");
129 pthread_mutex_unlock(&g_tts_data_mutex);
130 return VC_ERROR_EMPTY;
133 std::list<vc_tts_data_s*>::iterator iter;
134 iter = g_tts_data.begin();
135 while (iter != g_tts_data.end()) {
136 vc_tts_data_s *temp = nullptr;
138 if (nullptr != temp && utt_id == temp->utt_id) {
139 iter = g_tts_data.erase(iter);
143 temp->data = nullptr;
151 pthread_mutex_unlock(&g_tts_data_mutex);
153 return VC_ERROR_NONE;