2 * Copyright (c) 2011-2016 Samsung Electronics Co., Ltd All Rights Reserved
3 * Licensed under the Apache License, Version 2.0 (the "License");
4 * you may not use this file except in compliance with the License.
5 * You may obtain a copy of the License at
6 * http://www.apache.org/licenses/LICENSE-2.0
7 * Unless required by applicable law or agreed to in writing, software
8 * distributed under the License is distributed on an "AS IS" BASIS,
9 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
10 * See the License for the specific language governing permissions and
11 * limitations under the License.
15 #include "sttd_main.h"
17 #include "sttd_client_data.h"
20 static GSList *g_client_list = NULL;
22 static unsigned int g_cur_recog_uid = 0;
24 int client_show_list()
27 client_info_s *data = NULL;
29 SLOG(LOG_DEBUG, TAG_STTD, "----- client list");
31 if (g_slist_length(g_client_list) > 0) {
32 /* Get a first item */
33 iter = g_slist_nth(g_client_list, 0);
36 while (NULL != iter) {
37 /*Get handle data from list*/
40 SECURE_SLOG(LOG_DEBUG, TAG_STTD, "[%dth] uid(%u), state(%d)", i, data->uid, data->state);
43 iter = g_slist_next(iter);
47 SLOG(LOG_DEBUG, TAG_STTD, "No Client");
50 SLOG(LOG_DEBUG, TAG_STTD, "-----");
55 GSList* __client_get_item(unsigned int uid)
58 client_info_s *data = NULL;
60 if (0 < g_slist_length(g_client_list)) {
61 iter = g_slist_nth(g_client_list, 0);
63 while (NULL != iter) {
64 /* Get handle data from list */
70 iter = g_slist_next(iter);
77 int sttd_client_add(int pid, unsigned int uid)
79 /*Check uid is duplicated*/
81 tmp = __client_get_item(uid);
84 SLOG(LOG_WARN, TAG_STTD, "[Client Data] Client uid is already registered");
85 return STTD_ERROR_INVALID_PARAMETER;
88 client_info_s *info = (client_info_s*)calloc(1, sizeof(client_info_s));
90 SLOG(LOG_ERROR, TAG_STTD, "[Client Data ERROR] Fail to allocate memory");
91 return STTD_ERROR_OUT_OF_MEMORY;
96 info->start_beep = NULL;
97 info->stop_beep = NULL;
98 info->state = APP_STATE_READY;
100 info->app_agreed = false;
102 /* Add item to global list */
103 g_client_list = g_slist_append(g_client_list, info);
105 if (NULL == g_client_list) {
106 SLOG(LOG_ERROR, TAG_STTD, "[Client Data ERROR] Fail to add new client");
111 return STTD_ERROR_OPERATION_FAILED;
114 #ifdef CLIENT_DATA_DEBUG
120 int sttd_client_delete(unsigned int uid)
123 client_info_s* hnd = NULL;
126 tmp = __client_get_item(uid);
128 SECURE_SLOG(LOG_ERROR, TAG_STTD, "[Client Data ERROR] uid(%u) is NOT valid", uid);
129 return STTD_ERROR_INVALID_PARAMETER;
132 /*Free client structure*/
135 if (NULL != hnd->start_beep) free(hnd->start_beep);
136 if (NULL != hnd->stop_beep) free(hnd->stop_beep);
140 /*Remove handle from list*/
141 g_client_list = g_slist_remove_link(g_client_list, tmp);
143 #ifdef CLIENT_DATA_DEBUG
150 int sttd_client_get_start_sound(unsigned int uid, char** filename)
152 if (NULL == filename) {
153 SLOG(LOG_ERROR, TAG_STTD, "[Client Data ERROR] Filename is NULL");
154 return STTD_ERROR_INVALID_PARAMETER;
158 client_info_s* hnd = NULL;
160 tmp = __client_get_item(uid);
162 return STTD_ERROR_INVALID_PARAMETER;
166 if (NULL != hnd->start_beep) {
167 *filename = strdup(hnd->start_beep);
175 int sttd_client_set_start_sound(unsigned int uid, const char* filename)
178 client_info_s* hnd = NULL;
180 tmp = __client_get_item(uid);
182 SECURE_SLOG(LOG_ERROR, TAG_STTD, "[Client Data ERROR] uid(%u) is NOT valid", uid);
183 return STTD_ERROR_INVALID_PARAMETER;
187 if (NULL != hnd->start_beep) {
188 free(hnd->start_beep);
191 if (NULL != filename) {
192 hnd->start_beep = strdup(filename);
193 SLOG(LOG_DEBUG, TAG_STTD, "[Client Data] Start sound file : %s", hnd->start_beep);
195 hnd->start_beep = NULL;
201 int sttd_client_get_stop_sound(unsigned int uid, char** filename)
203 if (NULL == filename) {
204 SLOG(LOG_ERROR, TAG_STTD, "[Client Data ERROR] Filename is NULL");
205 return STTD_ERROR_INVALID_PARAMETER;
209 client_info_s* hnd = NULL;
211 tmp = __client_get_item(uid);
213 return STTD_ERROR_INVALID_PARAMETER;
217 if (NULL != hnd->stop_beep) {
218 *filename = strdup(hnd->stop_beep);
226 int sttd_client_set_stop_sound(unsigned int uid, const char* filename)
229 client_info_s* hnd = NULL;
231 tmp = __client_get_item(uid);
233 SECURE_SLOG(LOG_ERROR, TAG_STTD, "[Client Data ERROR] uid(%u) is NOT valid", uid);
234 return STTD_ERROR_INVALID_PARAMETER;
238 if (NULL != hnd->stop_beep) {
239 free(hnd->stop_beep);
242 if (NULL != filename) {
243 hnd->stop_beep = strdup(filename);
244 SLOG(LOG_DEBUG, TAG_STTD, "[Client Data] Stop sound file : %s", hnd->stop_beep);
246 hnd->stop_beep = NULL;
252 int sttd_client_get_state(unsigned int uid, app_state_e* state)
255 client_info_s* hnd = NULL;
257 tmp = __client_get_item(uid);
259 return STTD_ERROR_INVALID_PARAMETER;
268 int sttd_client_set_state(unsigned int uid, app_state_e state)
271 client_info_s* hnd = NULL;
273 tmp = __client_get_item(uid);
275 SECURE_SLOG(LOG_ERROR, TAG_STTD, "[Client Data ERROR] uid(%u) is NOT valid", uid);
276 return STTD_ERROR_INVALID_PARAMETER;
285 int sttd_client_get_ref_count()
287 int count = g_slist_length(g_client_list);
292 int sttd_client_get_pid(unsigned int uid)
295 client_info_s* hnd = NULL;
297 tmp = __client_get_item(uid);
299 SECURE_SLOG(LOG_ERROR, TAG_STTD, "[Client Data ERROR] sttd_client_get_pid : uid(%u) is not found", uid);
300 return STTD_ERROR_INVALID_PARAMETER;
309 int sttd_client_get_current_recording()
312 client_info_s *data = NULL;
314 if (0 < g_slist_length(g_client_list)) {
315 iter = g_slist_nth(g_client_list, 0);
317 while (NULL != iter) {
318 /* Get handle data from list */
321 if (APP_STATE_RECORDING == data->state)
324 iter = g_slist_next(iter);
331 int sttd_client_get_current_thinking()
334 client_info_s *data = NULL;
336 if (0 < g_slist_length(g_client_list)) {
337 iter = g_slist_nth(g_client_list, 0);
339 while (NULL != iter) {
340 /* Get handle data from list */
343 if (APP_STATE_PROCESSING == data->state)
346 iter = g_slist_next(iter);
353 int sttd_cliet_set_timer(unsigned int uid, Ecore_Timer* timer)
356 client_info_s* hnd = NULL;
358 tmp = __client_get_item(uid);
360 SECURE_SLOG(LOG_ERROR, TAG_STTD, "[Client Data ERROR] uid(%u) is NOT valid", uid);
361 return STTD_ERROR_INVALID_PARAMETER;
370 int sttd_cliet_get_timer(unsigned int uid, Ecore_Timer** timer)
373 client_info_s* hnd = NULL;
375 tmp = __client_get_item(uid);
377 SECURE_SLOG(LOG_ERROR, TAG_STTD, "[Client Data ERROR] uid(%u) is NOT valid", uid);
378 return STTD_ERROR_INVALID_PARAMETER;
388 int sttd_client_get_list(unsigned int** uids, int* uid_count)
390 if (NULL == uids || NULL == uid_count)
393 int count = g_slist_length(g_client_list);
398 unsigned int* tmp = (unsigned int*)calloc(count, sizeof(unsigned int));
400 SLOG(LOG_ERROR, TAG_STTD, "[Client Data ERROR] Fail to allocate memory");
401 return STTD_ERROR_OUT_OF_MEMORY;
405 client_info_s *data = NULL;
408 iter = g_slist_nth(g_client_list, 0);
409 while (NULL != iter) {
410 if (NULL == iter->data) {
412 iter = g_slist_next(iter);
418 iter = g_slist_next(iter);
429 int stt_client_set_current_recognition(unsigned int uid)
431 if (STT_INVALID_UID != g_cur_recog_uid) {
435 g_cur_recog_uid = uid;
440 unsigned int stt_client_get_current_recognition()
442 return g_cur_recog_uid;
445 int stt_client_unset_current_recognition()
447 g_cur_recog_uid = STT_INVALID_UID;
451 int stt_client_set_app_agreed(unsigned int uid)
454 client_info_s* hnd = NULL;
456 tmp = __client_get_item(uid);
458 SLOG(LOG_ERROR, TAG_STTD, "[Client Data ERROR] uid(%u) is NOT valid", uid);
459 return STTD_ERROR_INVALID_PARAMETER;
463 hnd->app_agreed = true;
468 bool stt_client_get_app_agreed(unsigned int uid)
471 client_info_s* hnd = NULL;
473 tmp = __client_get_item(uid);
475 SLOG(LOG_ERROR, TAG_STTD, "[Client Data ERROR] uid(%u) is NOT valid", uid);
476 return STTD_ERROR_INVALID_PARAMETER;
480 return hnd->app_agreed;