2 * Copyright (c) 2011 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 GList *g_client_list = NULL;
21 int client_show_list()
24 client_info_s *data = NULL;
26 SLOG(LOG_DEBUG, TAG_STTD, "----- client list");
28 if (g_list_length(g_client_list) > 0) {
29 /* Get a first item */
30 iter = g_list_first(g_client_list);
33 while (NULL != iter) {
34 /*Get handle data from list*/
37 SLOG(LOG_DEBUG, TAG_STTD, "[%dth] uid(%d), state(%d)", i, data->uid, data->state);
40 iter = g_list_next(iter);
44 SLOG(LOG_DEBUG, TAG_STTD, "No Client");
47 SLOG(LOG_DEBUG, TAG_STTD, "-----");
52 GList* sttd_client_get_item(const int uid)
55 client_info_s *data = NULL;
57 if (0 < g_list_length(g_client_list)) {
58 iter = g_list_first(g_client_list);
60 while (NULL != iter) {
61 /* Get handle data from list */
67 iter = g_list_next(iter);
74 int sttd_client_add(const int pid, const int uid)
76 /*Check uid is duplicated*/
78 tmp = sttd_client_get_item(uid);
81 SLOG(LOG_WARN, TAG_STTD, "[Client Data] Client uid is already registered");
82 return STTD_ERROR_INVALID_PARAMETER;
85 client_info_s *info = (client_info_s*)g_malloc0(sizeof(client_info_s));
89 info->state = APP_STATE_READY;
91 /* Add item to global list */
92 g_client_list = g_list_append(g_client_list, info);
94 if (NULL == g_client_list) {
95 SLOG(LOG_ERROR, TAG_STTD, "[Client Data ERROR] Fail to add new client");
98 SLOG(LOG_ERROR, TAG_STTD, "[Client Data SUCCESS] Add new client");
101 #ifdef CLIENT_DATA_DEBUG
108 int sttd_client_delete(const int uid)
111 client_info_s* hnd = NULL;
114 tmp = sttd_client_get_item(uid);
116 SLOG(LOG_ERROR, TAG_STTD, "[Client Data ERROR] uid(%d) is NOT valid", uid);
117 return STTD_ERROR_INVALID_PARAMETER;
120 /*Free client structure*/
126 /*Remove handle from list*/
127 g_client_list = g_list_remove_link(g_client_list, tmp);
129 #ifdef CLIENT_DATA_DEBUG
136 int sttd_client_get_state(const int uid, app_state_e* state)
139 client_info_s* hnd = NULL;
141 tmp = sttd_client_get_item(uid);
143 return STTD_ERROR_INVALID_PARAMETER;
149 SLOG(LOG_DEBUG, TAG_STTD, "[Client Data] Get state : uid(%d), state(%d)", uid, *state);
154 int sttd_client_set_state(const int uid, const app_state_e state)
157 client_info_s* hnd = NULL;
159 tmp = sttd_client_get_item(uid);
161 SLOG(LOG_ERROR, TAG_STTD, "[Client Data ERROR] uid(%d) is NOT valid", uid);
162 return STTD_ERROR_INVALID_PARAMETER;
168 SLOG(LOG_DEBUG, TAG_STTD, "[Client Data SUCCESS] Set state : uid(%d), state(%d)", uid, state);
173 int sttd_client_get_ref_count()
175 return g_list_length(g_client_list);
178 int sttd_client_get_pid(const int uid)
181 client_info_s* hnd = NULL;
183 tmp = sttd_client_get_item(uid);
185 SLOG(LOG_ERROR, TAG_STTD, "[Client Data ERROR] sttd_client_get_pid : uid(%d) is not found", uid);
186 return STTD_ERROR_INVALID_PARAMETER;
194 int sttd_client_get_current_recording()
197 client_info_s *data = NULL;
199 if (0 < g_list_length(g_client_list)) {
200 iter = g_list_first(g_client_list);
202 while (NULL != iter) {
203 /* Get handle data from list */
206 if (APP_STATE_RECORDING == data->state)
209 iter = g_list_next(iter);
216 int sttd_client_get_current_thinking()
219 client_info_s *data = NULL;
221 if (0 < g_list_length(g_client_list)) {
222 iter = g_list_first(g_client_list);
224 while (NULL != iter) {
225 /* Get handle data from list */
228 if (APP_STATE_PROCESSING == data->state)
231 iter = g_list_next(iter);