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"
16 #include "sttd_client_data.h"
19 static GSList *g_client_list = NULL;
21 static int g_cur_recog_uid = 0;
23 int client_show_list()
26 client_info_s *data = NULL;
28 SLOG(LOG_DEBUG, TAG_STTD, "----- client list");
30 if (g_slist_length(g_client_list) > 0) {
31 /* Get a first item */
32 iter = g_slist_nth(g_client_list, 0);
35 while (NULL != iter) {
36 /*Get handle data from list*/
39 SECURE_SLOG(LOG_DEBUG, TAG_STTD, "[%dth] uid(%d), state(%d)", i, data->uid, data->state);
42 iter = g_slist_next(iter);
46 SLOG(LOG_DEBUG, TAG_STTD, "No Client");
49 SLOG(LOG_DEBUG, TAG_STTD, "-----");
54 GSList* __client_get_item(int uid)
57 client_info_s *data = NULL;
59 if (0 < g_slist_length(g_client_list)) {
60 iter = g_slist_nth(g_client_list, 0);
62 while (NULL != iter) {
63 /* Get handle data from list */
69 iter = g_slist_next(iter);
76 int sttd_client_add(int pid, int uid)
78 /*Check uid is duplicated*/
80 tmp = __client_get_item(uid);
83 SLOG(LOG_WARN, TAG_STTD, "[Client Data] Client uid is already registered");
84 return STTD_ERROR_INVALID_PARAMETER;
87 client_info_s *info = (client_info_s*)calloc(1, sizeof(client_info_s));
89 SLOG(LOG_ERROR, TAG_STTD, "[Client Data ERROR] Fail to allocate memory");
90 return STTD_ERROR_OUT_OF_MEMORY;
95 info->start_beep = NULL;
96 info->stop_beep = NULL;
97 info->state = APP_STATE_READY;
99 info->app_agreed = false;
101 /* Add item to global list */
102 g_client_list = g_slist_append(g_client_list, info);
104 if (NULL == g_client_list) {
105 SLOG(LOG_ERROR, TAG_STTD, "[Client Data ERROR] Fail to add new client");
106 return STTD_ERROR_OPERATION_FAILED;
109 #ifdef CLIENT_DATA_DEBUG
115 int sttd_client_delete(int uid)
118 client_info_s* hnd = NULL;
121 tmp = __client_get_item(uid);
123 SECURE_SLOG(LOG_ERROR, TAG_STTD, "[Client Data ERROR] uid(%d) is NOT valid", uid);
124 return STTD_ERROR_INVALID_PARAMETER;
127 /*Free client structure*/
130 if (NULL != hnd->start_beep) free(hnd->start_beep);
131 if (NULL != hnd->stop_beep) free(hnd->stop_beep);
135 /*Remove handle from list*/
136 g_client_list = g_slist_remove_link(g_client_list, tmp);
138 #ifdef CLIENT_DATA_DEBUG
145 int sttd_client_get_start_sound(int uid, char** filename)
147 if (NULL == filename) {
148 SLOG(LOG_ERROR, TAG_STTD, "[Client Data ERROR] Filename is NULL");
149 return STTD_ERROR_INVALID_PARAMETER;
153 client_info_s* hnd = NULL;
155 tmp = __client_get_item(uid);
157 return STTD_ERROR_INVALID_PARAMETER;
161 if (NULL != hnd->start_beep) {
162 *filename = strdup(hnd->start_beep);
170 int sttd_client_set_start_sound(int uid, const char* filename)
173 client_info_s* hnd = NULL;
175 tmp = __client_get_item(uid);
177 SECURE_SLOG(LOG_ERROR, TAG_STTD, "[Client Data ERROR] uid(%d) is NOT valid", uid);
178 return STTD_ERROR_INVALID_PARAMETER;
182 if (NULL != hnd->start_beep) {
183 free(hnd->start_beep);
186 if (NULL != filename) {
187 hnd->start_beep = strdup(filename);
188 SLOG(LOG_DEBUG, TAG_STTD, "[Client Data] Start sound file : %s", hnd->start_beep);
190 hnd->start_beep = NULL;
196 int sttd_client_get_stop_sound(int uid, char** filename)
198 if (NULL == filename) {
199 SLOG(LOG_ERROR, TAG_STTD, "[Client Data ERROR] Filename is NULL");
200 return STTD_ERROR_INVALID_PARAMETER;
204 client_info_s* hnd = NULL;
206 tmp = __client_get_item(uid);
208 return STTD_ERROR_INVALID_PARAMETER;
212 if (NULL != hnd->stop_beep) {
213 *filename = strdup(hnd->stop_beep);
221 int sttd_client_set_stop_sound(int uid, const char* filename)
224 client_info_s* hnd = NULL;
226 tmp = __client_get_item(uid);
228 SECURE_SLOG(LOG_ERROR, TAG_STTD, "[Client Data ERROR] uid(%d) is NOT valid", uid);
229 return STTD_ERROR_INVALID_PARAMETER;
233 if (NULL != hnd->stop_beep) {
234 free(hnd->stop_beep);
237 if (NULL != filename) {
238 hnd->stop_beep = strdup(filename);
239 SLOG(LOG_DEBUG, TAG_STTD, "[Client Data] Stop sound file : %s", hnd->stop_beep);
241 hnd->stop_beep = NULL;
247 int sttd_client_get_state(int uid, app_state_e* state)
250 client_info_s* hnd = NULL;
252 tmp = __client_get_item(uid);
254 return STTD_ERROR_INVALID_PARAMETER;
263 int sttd_client_set_state(int uid, app_state_e state)
266 client_info_s* hnd = NULL;
268 tmp = __client_get_item(uid);
270 SECURE_SLOG(LOG_ERROR, TAG_STTD, "[Client Data ERROR] uid(%d) is NOT valid", uid);
271 return STTD_ERROR_INVALID_PARAMETER;
280 int sttd_client_get_ref_count()
282 int count = g_slist_length(g_client_list);
287 int sttd_client_get_pid(int uid)
290 client_info_s* hnd = NULL;
292 tmp = __client_get_item(uid);
294 SECURE_SLOG(LOG_ERROR, TAG_STTD, "[Client Data ERROR] sttd_client_get_pid : uid(%d) is not found", uid);
295 return STTD_ERROR_INVALID_PARAMETER;
304 int sttd_client_get_current_recording()
307 client_info_s *data = NULL;
309 if (0 < g_slist_length(g_client_list)) {
310 iter = g_slist_nth(g_client_list, 0);
312 while (NULL != iter) {
313 /* Get handle data from list */
316 if (APP_STATE_RECORDING == data->state)
319 iter = g_slist_next(iter);
326 int sttd_client_get_current_thinking()
329 client_info_s *data = NULL;
331 if (0 < g_slist_length(g_client_list)) {
332 iter = g_slist_nth(g_client_list, 0);
334 while (NULL != iter) {
335 /* Get handle data from list */
338 if (APP_STATE_PROCESSING == data->state)
341 iter = g_slist_next(iter);
348 int sttd_cliet_set_timer(int uid, Ecore_Timer* timer)
351 client_info_s* hnd = NULL;
353 tmp = __client_get_item(uid);
355 SECURE_SLOG(LOG_ERROR, TAG_STTD, "[Client Data ERROR] uid(%d) is NOT valid", uid);
356 return STTD_ERROR_INVALID_PARAMETER;
365 int sttd_cliet_get_timer(int uid, Ecore_Timer** timer)
368 client_info_s* hnd = NULL;
370 tmp = __client_get_item(uid);
372 SECURE_SLOG(LOG_ERROR, TAG_STTD, "[Client Data ERROR] uid(%d) is NOT valid", uid);
373 return STTD_ERROR_INVALID_PARAMETER;
383 int sttd_client_get_list(int** uids, int* uid_count)
385 if (NULL == uids || NULL == uid_count)
388 int count = g_slist_length(g_client_list);
394 tmp = (int*)calloc(count, sizeof(int));
396 SLOG(LOG_ERROR, TAG_STTD, "[Client Data ERROR] Fail to allocate memory");
397 return STTD_ERROR_OUT_OF_MEMORY;
401 client_info_s *data = NULL;
404 iter = g_slist_nth(g_client_list, 0);
405 while (NULL != iter) {
406 if (NULL == iter->data) {
408 iter = g_slist_next(iter);
414 iter = g_slist_next(iter);
425 int stt_client_set_current_recognition(int uid)
427 if (0 != g_cur_recog_uid) {
431 g_cur_recog_uid = uid;
436 int stt_client_get_current_recognition()
438 return g_cur_recog_uid;
441 int stt_client_unset_current_recognition()
447 int stt_client_set_app_agreed(int uid)
450 client_info_s* hnd = NULL;
452 tmp = __client_get_item(uid);
454 SLOG(LOG_ERROR, TAG_STTD, "[Client Data ERROR] uid(%d) is NOT valid", uid);
455 return STTD_ERROR_INVALID_PARAMETER;
459 hnd->app_agreed = true;
464 bool stt_client_get_app_agreed(int uid)
467 client_info_s* hnd = NULL;
469 tmp = __client_get_item(uid);
471 SLOG(LOG_ERROR, TAG_STTD, "[Client Data ERROR] uid(%d) is NOT valid", uid);
472 return STTD_ERROR_INVALID_PARAMETER;
476 return hnd->app_agreed;