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");
110 return STTD_ERROR_OPERATION_FAILED;
113 #ifdef CLIENT_DATA_DEBUG
119 int sttd_client_delete(int uid)
122 client_info_s* hnd = NULL;
125 tmp = __client_get_item(uid);
127 SECURE_SLOG(LOG_ERROR, TAG_STTD, "[Client Data ERROR] uid(%d) is NOT valid", uid);
128 return STTD_ERROR_INVALID_PARAMETER;
131 /*Free client structure*/
134 if (NULL != hnd->start_beep) free(hnd->start_beep);
135 if (NULL != hnd->stop_beep) free(hnd->stop_beep);
139 /*Remove handle from list*/
140 g_client_list = g_slist_remove_link(g_client_list, tmp);
142 #ifdef CLIENT_DATA_DEBUG
149 int sttd_client_get_start_sound(int uid, char** filename)
151 if (NULL == filename) {
152 SLOG(LOG_ERROR, TAG_STTD, "[Client Data ERROR] Filename is NULL");
153 return STTD_ERROR_INVALID_PARAMETER;
157 client_info_s* hnd = NULL;
159 tmp = __client_get_item(uid);
161 return STTD_ERROR_INVALID_PARAMETER;
165 if (NULL != hnd->start_beep) {
166 *filename = strdup(hnd->start_beep);
174 int sttd_client_set_start_sound(int uid, const char* filename)
177 client_info_s* hnd = NULL;
179 tmp = __client_get_item(uid);
181 SECURE_SLOG(LOG_ERROR, TAG_STTD, "[Client Data ERROR] uid(%d) is NOT valid", uid);
182 return STTD_ERROR_INVALID_PARAMETER;
186 if (NULL != hnd->start_beep) {
187 free(hnd->start_beep);
190 if (NULL != filename) {
191 hnd->start_beep = strdup(filename);
192 SLOG(LOG_DEBUG, TAG_STTD, "[Client Data] Start sound file : %s", hnd->start_beep);
194 hnd->start_beep = NULL;
200 int sttd_client_get_stop_sound(int uid, char** filename)
202 if (NULL == filename) {
203 SLOG(LOG_ERROR, TAG_STTD, "[Client Data ERROR] Filename is NULL");
204 return STTD_ERROR_INVALID_PARAMETER;
208 client_info_s* hnd = NULL;
210 tmp = __client_get_item(uid);
212 return STTD_ERROR_INVALID_PARAMETER;
216 if (NULL != hnd->stop_beep) {
217 *filename = strdup(hnd->stop_beep);
225 int sttd_client_set_stop_sound(int uid, const char* filename)
228 client_info_s* hnd = NULL;
230 tmp = __client_get_item(uid);
232 SECURE_SLOG(LOG_ERROR, TAG_STTD, "[Client Data ERROR] uid(%d) is NOT valid", uid);
233 return STTD_ERROR_INVALID_PARAMETER;
237 if (NULL != hnd->stop_beep) {
238 free(hnd->stop_beep);
241 if (NULL != filename) {
242 hnd->stop_beep = strdup(filename);
243 SLOG(LOG_DEBUG, TAG_STTD, "[Client Data] Stop sound file : %s", hnd->stop_beep);
245 hnd->stop_beep = NULL;
251 int sttd_client_get_state(int uid, app_state_e* state)
254 client_info_s* hnd = NULL;
256 tmp = __client_get_item(uid);
258 return STTD_ERROR_INVALID_PARAMETER;
267 int sttd_client_set_state(int uid, app_state_e state)
270 client_info_s* hnd = NULL;
272 tmp = __client_get_item(uid);
274 SECURE_SLOG(LOG_ERROR, TAG_STTD, "[Client Data ERROR] uid(%d) is NOT valid", uid);
275 return STTD_ERROR_INVALID_PARAMETER;
284 int sttd_client_get_ref_count()
286 int count = g_slist_length(g_client_list);
291 int sttd_client_get_pid(int uid)
294 client_info_s* hnd = NULL;
296 tmp = __client_get_item(uid);
298 SECURE_SLOG(LOG_ERROR, TAG_STTD, "[Client Data ERROR] sttd_client_get_pid : uid(%d) is not found", uid);
299 return STTD_ERROR_INVALID_PARAMETER;
308 int sttd_client_get_current_recording()
311 client_info_s *data = NULL;
313 if (0 < g_slist_length(g_client_list)) {
314 iter = g_slist_nth(g_client_list, 0);
316 while (NULL != iter) {
317 /* Get handle data from list */
320 if (APP_STATE_RECORDING == data->state)
323 iter = g_slist_next(iter);
330 int sttd_client_get_current_thinking()
333 client_info_s *data = NULL;
335 if (0 < g_slist_length(g_client_list)) {
336 iter = g_slist_nth(g_client_list, 0);
338 while (NULL != iter) {
339 /* Get handle data from list */
342 if (APP_STATE_PROCESSING == data->state)
345 iter = g_slist_next(iter);
352 int sttd_cliet_set_timer(int uid, Ecore_Timer* timer)
355 client_info_s* hnd = NULL;
357 tmp = __client_get_item(uid);
359 SECURE_SLOG(LOG_ERROR, TAG_STTD, "[Client Data ERROR] uid(%d) is NOT valid", uid);
360 return STTD_ERROR_INVALID_PARAMETER;
369 int sttd_cliet_get_timer(int uid, Ecore_Timer** timer)
372 client_info_s* hnd = NULL;
374 tmp = __client_get_item(uid);
376 SECURE_SLOG(LOG_ERROR, TAG_STTD, "[Client Data ERROR] uid(%d) is NOT valid", uid);
377 return STTD_ERROR_INVALID_PARAMETER;
387 int sttd_client_get_list(int** uids, int* uid_count)
389 if (NULL == uids || NULL == uid_count)
392 int count = g_slist_length(g_client_list);
398 tmp = (int*)calloc(count, sizeof(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(int uid)
431 if (0 != g_cur_recog_uid) {
435 g_cur_recog_uid = uid;
440 int stt_client_get_current_recognition()
442 return g_cur_recog_uid;
445 int stt_client_unset_current_recognition()
451 int stt_client_set_app_agreed(int uid)
454 client_info_s* hnd = NULL;
456 tmp = __client_get_item(uid);
458 SLOG(LOG_ERROR, TAG_STTD, "[Client Data ERROR] uid(%d) is NOT valid", uid);
459 return STTD_ERROR_INVALID_PARAMETER;
463 hnd->app_agreed = true;
468 bool stt_client_get_app_agreed(int uid)
471 client_info_s* hnd = NULL;
473 tmp = __client_get_item(uid);
475 SLOG(LOG_ERROR, TAG_STTD, "[Client Data ERROR] uid(%d) is NOT valid", uid);
476 return STTD_ERROR_INVALID_PARAMETER;
480 return hnd->app_agreed;