Remove unnecessary codes
[platform/core/uifw/voice-control.git] / server / vcd_client_data.c
1 /*
2 * Copyright (c) 2011-2015 Samsung Electronics Co., Ltd All Rights Reserved
3 *
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
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
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.
15 */
16
17
18 #include <aul.h>
19 #include "vcd_client_data.h"
20 #include "vcd_config.h"
21 #include "vcd_main.h"
22
23 /* Client list */
24 static GSList* g_client_list = NULL;
25
26 static GSList* g_widget_list = NULL;
27
28 static manager_info_s g_manager;
29
30 /* Command list */
31 static current_commands_list_s g_cur_cmd_list;
32
33 /* Demandable client list */
34 static GSList* g_demandable_client = NULL;
35
36 /* Runtime info */
37 static bool g_silence_detection;
38 static vcd_recognition_mode_e g_recognition_mode;
39
40
41 /* Function definitions */
42 widget_info_s* __widget_get_element(int pid);
43
44 vc_client_info_s* __client_get_element(int pid);
45
46
47 int vcd_client_manager_set(int pid)
48 {
49         if (-1 != g_manager.pid) {
50                 SLOG(LOG_DEBUG, TAG_VCD, "Manager has already registered");
51                 return -1;
52         }
53         g_manager.pid = pid;
54         g_manager.manager_cmd = false;
55         g_manager.exclusive_cmd_option = false;
56
57         return 0;
58 }
59
60 int vcd_client_manager_unset()
61 {
62         g_manager.pid = -1;
63         g_manager.manager_cmd = false;
64         g_manager.exclusive_cmd_option = false;
65
66         return 0;
67 }
68
69 bool vcd_client_manager_is_valid(int pid)
70 {
71         if (-1 == g_manager.pid || pid == g_manager.pid) {
72                 return true;
73         }
74         return false;
75 }
76
77 int vcd_client_manager_set_command(int pid)
78 {
79         if (pid != g_manager.pid) {
80                 SLOG(LOG_ERROR, TAG_VCD, "[Client Data ERROR] pid(%d) is NOT valid", pid);
81                 return -1;
82         }
83         g_manager.manager_cmd = true;
84         return 0;
85 }
86
87 int vcd_client_manager_unset_command(int pid)
88 {
89         if (pid != g_manager.pid) {
90                 SLOG(LOG_ERROR, TAG_VCD, "[Client Data ERROR] pid(%d) is NOT valid", pid);
91                 return -1;
92         }
93         g_manager.manager_cmd = false;
94         return 0;
95 }
96
97 int vcd_client_manager_set_demandable_client(int pid, GSList* client_list)
98 {
99         if (0 != g_slist_length(g_demandable_client)) {
100                 /* releaes data */
101                 GSList *iter = NULL;
102                 vc_demandable_client_s* temp_client;
103                 iter = g_slist_nth(g_demandable_client, 0);
104
105                 while (NULL != iter) {
106                         temp_client = iter->data;
107
108                         if (NULL != temp_client) {
109                                 if (NULL != temp_client->appid)         free(temp_client->appid);
110                                 free(temp_client);
111                         }
112
113                         iter = g_slist_next(iter);
114                 }
115                 g_demandable_client = NULL;
116         }
117
118         g_demandable_client = client_list;
119
120         return 0;
121 }
122
123 bool vcd_client_manager_check_demandable_client(int pid)
124 {
125         if (0 == g_slist_length(g_demandable_client)) {
126                 SLOG(LOG_DEBUG, TAG_VCD, "[Client Data] All client is available to request start");
127                 return true;
128         }
129
130         /* Check demandable appid */
131         char appid[128] = {0, };
132         aul_app_get_appid_bypid(pid, appid, sizeof(appid));
133
134         if (0 < strlen(appid)) {
135                 SLOG(LOG_DEBUG, TAG_VCD, "[Client Data] %s(%d) requests start", appid, pid);
136         } else {
137                 SLOG(LOG_DEBUG, TAG_VCD, "[Client Data] daemon(%d) requests start", pid);
138         }
139
140         /* Compare appid */
141         GSList *iter = NULL;
142         vc_demandable_client_s* temp_client;
143         iter = g_slist_nth(g_demandable_client, 0);
144
145         while (NULL != iter) {
146                 temp_client = iter->data;
147
148                 if (NULL != temp_client) {
149
150                         SLOG(LOG_DEBUG, TAG_VCD, "[Client Data] demandable appid(%s)", temp_client->appid);
151
152                         if (NULL != temp_client->appid) {
153                                 if (0 == strcmp(temp_client->appid, appid)) {
154                                         SLOG(LOG_DEBUG, TAG_VCD, "[Client Data] pid(%d) is available", pid);
155                                         return true;
156                                 }
157                         } else {
158                                 if (0 == strlen(appid)) {
159                                         SLOG(LOG_DEBUG, TAG_VCD, "[Client Data] pid(%d) is available", pid);
160                                         return true;
161                                 }
162                         }
163                 }
164
165                 iter = g_slist_next(iter);
166         }
167
168         return false;
169 }
170
171 bool vcd_client_manager_get_exclusive()
172 {
173         return g_manager.exclusive_cmd_option;
174 }
175
176 int vcd_client_manager_set_exclusive(bool value)
177 {
178         g_manager.exclusive_cmd_option = value;
179         return 0;
180 }
181
182 int vcd_client_manager_get_pid()
183 {
184         return g_manager.pid;
185 }
186
187 int __vcd_client_release_commands()
188 {
189         g_cur_cmd_list.total_cmd_count = 0;
190         g_cur_cmd_list.foreground = VC_NO_FOREGROUND_PID;
191
192         GSList *iter = NULL;
193         vc_cmd_s* temp_cmd;
194
195         if (0 < g_slist_length(g_cur_cmd_list.widget_cmds)) {
196                 iter = g_slist_nth(g_cur_cmd_list.widget_cmds, 0);
197                 while (NULL != iter) {
198                         temp_cmd = iter->data;
199
200                         if (NULL != temp_cmd) {
201                                 if (NULL != temp_cmd->command)          free(temp_cmd->command);
202                                 if (NULL != temp_cmd->parameter)        free(temp_cmd->parameter);
203                                 free(temp_cmd);
204                         }
205
206                         iter = g_slist_next(iter);
207                 }
208                 g_cur_cmd_list.widget_cmds = NULL;
209         }
210
211         if (0 < g_slist_length(g_cur_cmd_list.foreground_cmds)) {
212                 iter = g_slist_nth(g_cur_cmd_list.foreground_cmds, 0);
213                 while (NULL != iter) {
214                         temp_cmd = iter->data;
215
216                         if (NULL != temp_cmd) {
217                                 if (NULL != temp_cmd->command)          free(temp_cmd->command);
218                                 if (NULL != temp_cmd->parameter)        free(temp_cmd->parameter);
219                                 free(temp_cmd);
220                         }
221
222                         iter = g_slist_next(iter);
223                 }
224                 g_cur_cmd_list.foreground_cmds = NULL;
225         }
226
227         if (0 < g_slist_length(g_cur_cmd_list.system_cmds)) {
228                 iter = g_slist_nth(g_cur_cmd_list.system_cmds, 0);
229                 while (NULL != iter) {
230                         temp_cmd = iter->data;
231
232                         if (NULL != temp_cmd) {
233                                 if (NULL != temp_cmd->command)          free(temp_cmd->command);
234                                 if (NULL != temp_cmd->parameter)        free(temp_cmd->parameter);
235                                 free(temp_cmd);
236                         }
237
238                         iter = g_slist_next(iter);
239                 }
240                 g_cur_cmd_list.system_cmds = NULL;
241         }
242
243         if (0 < g_slist_length(g_cur_cmd_list.exclusive_system_cmds)) {
244                 iter = g_slist_nth(g_cur_cmd_list.exclusive_system_cmds, 0);
245                 while (NULL != iter) {
246                         temp_cmd = iter->data;
247
248                         if (NULL != temp_cmd) {
249                                 if (NULL != temp_cmd->command)          free(temp_cmd->command);
250                                 if (NULL != temp_cmd->parameter)        free(temp_cmd->parameter);
251                                 free(temp_cmd);
252                         }
253
254                         iter = g_slist_next(iter);
255                 }
256                 g_cur_cmd_list.exclusive_system_cmds = NULL;
257         }
258
259         if (0 < g_slist_length(g_cur_cmd_list.background_cmds)) {
260                 background_command_s* back_cmd_info;
261                 iter = g_slist_nth(g_cur_cmd_list.background_cmds, 0);
262
263                 GSList* back_iter = NULL;
264
265                 while (NULL != iter) {
266                         back_cmd_info = iter->data;
267
268                         if (NULL != back_cmd_info) {
269                                 back_iter = g_slist_nth(back_cmd_info->cmds, 0);
270
271                                 while (NULL != back_iter) {
272                                         temp_cmd = back_iter->data;
273
274                                         if (NULL != temp_cmd) {
275                                                 if (NULL != temp_cmd->command)          free(temp_cmd->command);
276                                                 if (NULL != temp_cmd->parameter)        free(temp_cmd->parameter);
277                                                 free(temp_cmd);
278                                         }
279
280                                         back_iter = g_slist_next(back_iter);
281                                 }
282
283                                 back_cmd_info->cmds = NULL;
284                         }
285
286                         iter = g_slist_next(iter);
287                 }
288
289                 g_cur_cmd_list.background_cmds = NULL;
290         }
291
292         g_cur_cmd_list.bg_cmd_count = 0;
293
294         return 0;
295 }
296
297 int vcd_client_command_collect_command()
298 {
299         /* 1. Get foreground pid */
300         int fg_pid = 0;
301         int ret = -1;
302         if (0 != vcd_config_get_foreground(&fg_pid)) {
303                 SLOG(LOG_WARN, TAG_VCD, "[Server WARNING] Fail to get foreground pid");
304                 /* There is no foreground app for voice control */
305         }
306
307         SLOG(LOG_DEBUG, TAG_VCD, "[Client Data] Foreground pid(%d)", fg_pid);
308
309         /* 2. Clean up command list */
310         __vcd_client_release_commands();
311
312         /* Check exclusive system command */
313         if (true == g_manager.exclusive_cmd_option) {
314                 SLOG(LOG_DEBUG, TAG_VCD, "[Client Data] Exclusive option of manager is ON");
315
316                 GSList* ex_sys_cmd_list = NULL;
317                 if (true == g_manager.manager_cmd) {
318                         ret = vc_cmd_parser_get_commands(g_manager.pid, VC_COMMAND_TYPE_EXCLUSIVE, &ex_sys_cmd_list);
319                         if (0 != ret) {
320                                 SLOG(LOG_ERROR, TAG_VCD, "[Client Data ERROR] Fail to get the system command list");
321                         } else {
322                                 g_cur_cmd_list.exclusive_system_cmds = ex_sys_cmd_list;
323                         }
324                 } else {
325                         SLOG(LOG_DEBUG, TAG_VCD, "[Client Data] No exclusive system commands");
326                 }
327
328                 return 0;
329         }
330
331         /* 3. Set system command */
332         GSList* sys_cmd_list = NULL;
333         if (true == g_manager.manager_cmd) {
334                 ret = vc_cmd_parser_get_commands(g_manager.pid, VC_COMMAND_TYPE_SYSTEM, &sys_cmd_list);
335                 if (0 != ret) {
336                         SLOG(LOG_ERROR, TAG_VCD, "[Client Data ERROR] Fail to get the system command list");
337                 } else {
338                         g_cur_cmd_list.system_cmds = sys_cmd_list;
339                 }
340         } else {
341                 SLOG(LOG_DEBUG, TAG_VCD, "[Client Data] No system commands");
342         }
343
344         vc_client_info_s* client_info = NULL;
345         GSList *iter = NULL;
346
347         /* 4. Set foreground commands and widget */
348         if (VC_NO_FOREGROUND_PID != fg_pid) {
349                 GSList* fg_cmd_list = NULL;
350                 GSList* widget_cmd_list = NULL;
351
352                 g_cur_cmd_list.foreground = fg_pid;
353
354                 /* 4-1. Set widget command */
355                 widget_info_s* widget_info = NULL;
356                 widget_info = __widget_get_element(fg_pid);
357                 if (NULL != widget_info) {
358                         if (true == widget_info->widget_cmd) {
359                                 ret = vc_cmd_parser_get_commands(fg_pid, VC_COMMAND_TYPE_WIDGET, &widget_cmd_list);
360                                 if (0 != ret) {
361                                         SLOG(LOG_ERROR, TAG_VCD, "[Client Data ERROR] Fail to get the WIDGET command list");
362                                 } else {
363                                         g_cur_cmd_list.widget_cmds = widget_cmd_list;
364                                 }
365                         }
366                 } else {
367                         SLOG(LOG_DEBUG, TAG_VCD, "[Client Data] No widget commands");
368                 }
369
370                 /* Get handle */
371                 client_info = __client_get_element(fg_pid);
372                 if (NULL != client_info) {
373                         SLOG(LOG_DEBUG, TAG_VCD, "[Client Data] fore cmd(%d)", client_info->fg_cmd);
374
375                         /* 4-2. Set foreground command */
376                         if (true == client_info->fg_cmd) {
377                                 ret = vc_cmd_parser_get_commands(fg_pid, VC_COMMAND_TYPE_FOREGROUND, &fg_cmd_list);
378                                 if (0 != ret) {
379                                         SLOG(LOG_ERROR, TAG_VCD, "[Client Data ERROR] Fail to get the fg command list");
380                                 } else {
381                                         g_cur_cmd_list.foreground_cmds = fg_cmd_list;
382                                 }
383                         } else {
384                                 SLOG(LOG_DEBUG, TAG_VCD, "[Client Data] No foreground commands");
385                         }
386
387                         /* 4-3. Check exclusive option */
388                         if (true == client_info->exclusive_cmd) {
389                                 SLOG(LOG_DEBUG, TAG_VCD, "[Client Data] Exclusive command is ON");
390
391                                 /* 4-4. Set background command for exclusive option */
392                                 if (true == client_info->bg_cmd) {
393                                         SLOG(LOG_DEBUG, TAG_VCD, "[Client Data] Set background command");
394                                         GSList* bg_cmd_list = NULL;
395                                         ret = vc_cmd_parser_get_commands(client_info->pid, VC_COMMAND_TYPE_BACKGROUND, &bg_cmd_list);
396                                         if (0 != ret) {
397                                                 SLOG(LOG_ERROR, TAG_VCD, "[Client Data ERROR] Fail to get the bg command list : pid(%d)", client_info->pid);
398                                         } else {
399                                                 background_command_s* bg_cmd = (background_command_s*)calloc(1, sizeof(background_command_s));
400                                                 if (NULL == bg_cmd) {
401                                                         SLOG(LOG_ERROR, TAG_VCD, "[ERROR] Fail to allocate memory");
402                                                         return VCD_ERROR_OUT_OF_MEMORY;
403                                                 }
404
405                                                 bg_cmd->pid = client_info->pid;
406                                                 bg_cmd->cmds = bg_cmd_list;
407                                                 bg_cmd->cmd_count = g_slist_length(bg_cmd_list);
408
409                                                 /* Add item to global command list */
410                                                 g_cur_cmd_list.background_cmds = g_slist_append(g_cur_cmd_list.background_cmds, bg_cmd);
411                                         }
412                                 }
413                                 return 0;
414                         }
415                 } else {
416                         SLOG(LOG_WARN, TAG_VCD, "[Client Data] No foreground client : pid(%d)", fg_pid);
417                 }
418         } else {
419                 SLOG(LOG_DEBUG, TAG_VCD, "[Client Data] No foreground app");
420         }
421
422         /* 5. Set background commands */
423         if (0 < g_slist_length(g_client_list)) {
424                 iter = g_slist_nth(g_client_list, 0);
425
426                 while (NULL != iter) {
427                         client_info = iter->data;
428                         GSList* bg_cmd_list = NULL;
429
430                         SLOG(LOG_DEBUG, TAG_VCD, "[Client Data] Pid(%d) Back cmd(%d)", client_info->pid, client_info->bg_cmd);
431
432                         if (true == client_info->bg_cmd) {
433                                 ret = vc_cmd_parser_get_commands(client_info->pid, VC_COMMAND_TYPE_BACKGROUND, &bg_cmd_list);
434                                 if (0 != ret) {
435                                         SLOG(LOG_ERROR, TAG_VCD, "[Client Data ERROR] Fail to get the bg command list : pid(%d)", client_info->pid);
436                                 } else {
437                                         background_command_s* bg_cmd = (background_command_s*)calloc(1, sizeof(background_command_s));
438                                         if (NULL == bg_cmd) {
439                                                 SLOG(LOG_ERROR, TAG_VCD, "[ERROR] Fail to allocate memory");
440                                                 return VCD_ERROR_OUT_OF_MEMORY;
441                                         }
442
443                                         bg_cmd->pid = client_info->pid;
444                                         bg_cmd->cmds = bg_cmd_list;
445                                         bg_cmd->cmd_count = g_slist_length(bg_cmd_list);
446
447                                         /* Add item to global command list */
448                                         g_cur_cmd_list.background_cmds = g_slist_append(g_cur_cmd_list.background_cmds, bg_cmd);
449                                 }
450                         }
451
452                         iter = g_slist_next(iter);
453                 }
454         } else {
455                 /* NO client */
456                 SLOG(LOG_DEBUG, TAG_VCD, "[Client Data] No background commands");
457         }
458
459         return 0;
460 }
461
462 int vcd_client_get_length()
463 {
464         int command_count = 0;
465         command_count += g_slist_length(g_cur_cmd_list.widget_cmds);
466         command_count += g_slist_length(g_cur_cmd_list.foreground_cmds);
467         command_count += g_slist_length(g_cur_cmd_list.system_cmds);
468         command_count += g_slist_length(g_cur_cmd_list.exclusive_system_cmds);
469
470         GSList *iter = NULL;
471         background_command_s* back_cmd_info;
472
473         if (0 < g_slist_length(g_cur_cmd_list.background_cmds)) {
474                 iter = g_slist_nth(g_cur_cmd_list.background_cmds, 0);
475
476                 while (NULL != iter) {
477                         back_cmd_info = iter->data;
478
479                         command_count += g_slist_length(back_cmd_info->cmds);
480
481                         SLOG(LOG_DEBUG, TAG_VCD, "[Client Data] background commands count : %d", g_slist_length(back_cmd_info->cmds));
482
483                         iter = g_slist_next(iter);
484                 }
485         } else {
486                 /* NO client */
487                 SLOG(LOG_DEBUG, TAG_VCD, "[Client Data] No background commands");
488         }
489
490         g_cur_cmd_list.total_cmd_count = command_count;
491
492         SLOG(LOG_DEBUG, TAG_VCD, "[Client Data] Command count : %d ", g_cur_cmd_list.total_cmd_count);
493
494         return command_count;
495 }
496
497 int vcd_client_foreach_command(client_foreach_command_cb callback, void* user_data)
498 {
499         if (NULL == callback) {
500                 SLOG(LOG_ERROR, TAG_VCD, "[Client Data ERROR] input parameter is NULL");
501                 return VCD_ERROR_INVALID_PARAMETER;
502         }
503
504         int id_count = 1;
505         GSList *iter = NULL;
506         vc_cmd_s* temp_cmd;
507
508         if (0 < g_slist_length(g_cur_cmd_list.widget_cmds)) {
509                 iter = g_slist_nth(g_cur_cmd_list.widget_cmds, 0);
510                 while (NULL != iter) {
511                         temp_cmd = iter->data;
512
513                         temp_cmd->id = id_count;
514                         id_count++;
515
516                         SLOG(LOG_DEBUG, TAG_VCD, "[Client Data] Widget : id(%d) index(%d) format(%d) command(%s) param(%s) domain(%d)"
517                                  , temp_cmd->id, temp_cmd->index, temp_cmd->format, temp_cmd->command, temp_cmd->parameter, temp_cmd->domain);
518
519                         callback(temp_cmd->id, temp_cmd->format, temp_cmd->command, temp_cmd->parameter, temp_cmd->domain, user_data);
520
521                         iter = g_slist_next(iter);
522                 }
523         } else {
524                 SLOG(LOG_DEBUG, TAG_VCD, "[Client Data] No widget commands");
525         }
526
527         if (0 < g_slist_length(g_cur_cmd_list.foreground_cmds)) {
528                 iter = g_slist_nth(g_cur_cmd_list.foreground_cmds, 0);
529                 while (NULL != iter) {
530                         temp_cmd = iter->data;
531
532                         temp_cmd->id = id_count;
533                         id_count++;
534
535                         SLOG(LOG_DEBUG, TAG_VCD, "[Client Data] Foreground : id(%d) index(%d) format(%d) command(%s) param(%s) domain(%d)"
536                                  , temp_cmd->id, temp_cmd->index, temp_cmd->format, temp_cmd->command, temp_cmd->parameter, temp_cmd->domain);
537
538                         callback(temp_cmd->id, temp_cmd->format, temp_cmd->command, temp_cmd->parameter, temp_cmd->domain, user_data);
539
540                         iter = g_slist_next(iter);
541                 }
542         } else {
543                 SLOG(LOG_DEBUG, TAG_VCD, "[Client Data] No foreground commands");
544         }
545
546         if (0 < g_slist_length(g_cur_cmd_list.system_cmds)) {
547                 iter = g_slist_nth(g_cur_cmd_list.system_cmds, 0);
548                 while (NULL != iter) {
549                         temp_cmd = iter->data;
550
551                         temp_cmd->id = id_count;
552                         id_count++;
553
554                         SLOG(LOG_DEBUG, TAG_VCD, "[Client Data] System : id(%d) index(%d) format(%d) domain(%d) command(%s) param(%s)"
555                                  , temp_cmd->id, temp_cmd->index, temp_cmd->format, temp_cmd->domain, temp_cmd->command, temp_cmd->parameter);
556
557                         callback(temp_cmd->id, temp_cmd->format, temp_cmd->command, temp_cmd->parameter, temp_cmd->domain, user_data);
558
559                         iter = g_slist_next(iter);
560                 }
561         } else {
562                 SLOG(LOG_DEBUG, TAG_VCD, "[Client Data] No system commands");
563         }
564
565         if (0 < g_slist_length(g_cur_cmd_list.exclusive_system_cmds)) {
566                 iter = g_slist_nth(g_cur_cmd_list.exclusive_system_cmds, 0);
567                 while (NULL != iter) {
568                         temp_cmd = iter->data;
569
570                         temp_cmd->id = id_count;
571                         id_count++;
572
573                         SLOG(LOG_DEBUG, TAG_VCD, "[Client Data] Exclusive system : id(%d) index(%d) format(%d) command(%s) param(%s) domain(%d)"
574                                  , temp_cmd->id, temp_cmd->index, temp_cmd->format, temp_cmd->command, temp_cmd->parameter, temp_cmd->domain);
575
576                         callback(temp_cmd->id, temp_cmd->type, temp_cmd->command, temp_cmd->parameter, temp_cmd->domain, user_data);
577
578                         iter = g_slist_next(iter);
579                 }
580         } else {
581                 SLOG(LOG_DEBUG, TAG_VCD, "[Client Data] No exclusive system commands");
582         }
583
584         if (0 < g_slist_length(g_cur_cmd_list.background_cmds)) {
585                 background_command_s* back_cmd_info;
586                 iter = g_slist_nth(g_cur_cmd_list.background_cmds, 0);
587
588                 while (NULL != iter) {
589                         back_cmd_info = iter->data;
590
591                         GSList* back_iter = NULL;
592                         back_iter = g_slist_nth(back_cmd_info->cmds, 0);
593
594                         SLOG(LOG_DEBUG, TAG_VCD, "[Client Data] pid(%d) command count(%d)", back_cmd_info->pid, back_cmd_info->cmd_count);
595
596                         while (NULL != back_iter) {
597                                 temp_cmd = back_iter->data;
598
599                                 temp_cmd->id = id_count;
600                                 id_count++;
601
602                                 SLOG(LOG_DEBUG, TAG_VCD, "[Client Data] Background : id(%d) index(%d) format(%d) command(%s) param(%s) domain(%d)"
603                                          , temp_cmd->id, temp_cmd->index, temp_cmd->format, temp_cmd->command, temp_cmd->parameter, temp_cmd->domain);
604
605                                 callback(temp_cmd->id, temp_cmd->format, temp_cmd->command, temp_cmd->parameter, temp_cmd->domain, user_data);
606
607                                 back_iter = g_slist_next(back_iter);
608                         }
609
610                         iter = g_slist_next(iter);
611                 }
612         } else {
613                 SLOG(LOG_DEBUG, TAG_VCD, "[Client Data] No background commands");
614         }
615
616         return 0;
617 }
618
619 static vc_cmd_s* __command_copy(vc_cmd_s* src_cmd)
620 {
621         if (NULL == src_cmd) {
622                 SLOG(LOG_WARN, TAG_VCD, "[Client Data] Input command is NULL");
623                 return NULL;
624         }
625
626         vc_cmd_s* temp_cmd = NULL;
627         temp_cmd = (vc_cmd_s*)calloc(sizeof(vc_cmd_s), 1);
628         if (NULL == temp_cmd) {
629                 SLOG(LOG_ERROR, TAG_VCD, "[ERROR] Fail to allocate memory");
630                 return NULL;
631         }
632
633         temp_cmd->id = src_cmd->id;
634         temp_cmd->pid = src_cmd->pid;
635         temp_cmd->index = src_cmd->index;
636         temp_cmd->type = src_cmd->type;
637         temp_cmd->format = src_cmd->format;
638         temp_cmd->domain = src_cmd->domain;
639
640         if (NULL != src_cmd->command) {
641                 temp_cmd->command = strdup(src_cmd->command);
642         }
643
644         if (NULL != src_cmd->parameter) {
645                 temp_cmd->parameter = strdup(src_cmd->parameter);
646         }
647
648         temp_cmd->key = src_cmd->key;
649         temp_cmd->modifier = src_cmd->modifier;
650
651         return temp_cmd;
652 }
653
654 int vcd_client_get_cmd_from_result_id(int result_id, vc_cmd_s** result)
655 {
656         GSList *iter = NULL;
657         vc_cmd_s* temp_cmd;
658
659         SLOG(LOG_DEBUG, TAG_VCD, "[Client Data] Result id(%d)", result_id);
660
661         if (0 < g_slist_length(g_cur_cmd_list.widget_cmds)) {
662                 iter = g_slist_nth(g_cur_cmd_list.widget_cmds, 0);
663                 while (NULL != iter) {
664                         temp_cmd = iter->data;
665
666                         if (result_id == temp_cmd->id) {
667                                 /**pid = g_cur_cmd_list.foreground; */
668                                 /**cmd_type = VCD_CLIENT_COMMAND_GROUP_TYPE_UI_CONTROL; */
669                                 /*SLOG(LOG_DEBUG, TAG_VCD, "[Client Data] Find result pid(%d) type(%d)", *pid, *cmd_type); */
670
671                                 *result = __command_copy(temp_cmd);
672
673                                 return 0;
674                         }
675
676                         iter = g_slist_next(iter);
677                 }
678         } else {
679                 SLOG(LOG_DEBUG, TAG_VCD, "[Client Data] No widget commands");
680         }
681
682         if (0 < g_slist_length(g_cur_cmd_list.foreground_cmds)) {
683                 iter = g_slist_nth(g_cur_cmd_list.foreground_cmds, 0);
684
685                 while (NULL != iter) {
686                         temp_cmd = iter->data;
687
688                         SLOG(LOG_DEBUG, TAG_VCD, "[Client Data] command id (%d)", temp_cmd->id);
689
690                         if (result_id == temp_cmd->id) {
691                                 /**pid = g_cur_cmd_list.foreground; */
692                                 /**cmd_type = VCD_CLIENT_COMMAND_GROUP_TYPE_FOREGROUND; */
693                                 /*SLOG(LOG_DEBUG, TAG_VCD, "[Client Data] Find result pid(%d) type(%d)", *pid, *cmd_type); */
694
695                                 *result = __command_copy(temp_cmd);
696                                 return 0;
697                         }
698
699                         iter = g_slist_next(iter);
700                 }
701         } else {
702                 SLOG(LOG_DEBUG, TAG_VCD, "[Client Data] No foreground commands");
703         }
704
705         if (0 < g_slist_length(g_cur_cmd_list.system_cmds)) {
706                 iter = g_slist_nth(g_cur_cmd_list.system_cmds, 0);
707                 while (NULL != iter) {
708                         temp_cmd = iter->data;
709
710                         if (result_id == temp_cmd->id) {
711                                 /**pid = g_manager.pid; */
712                                 /**cmd_type = VCD_CLIENT_COMMAND_GROUP_TYPE_SYSTEM; */
713                                 /*SLOG(LOG_DEBUG, TAG_VCD, "[Client Data] Find result pid(%d) type(%d)", *pid, *cmd_type); */
714
715                                 *result = __command_copy(temp_cmd);
716                                 return 0;
717                         }
718
719                         iter = g_slist_next(iter);
720                 }
721         } else {
722                 SLOG(LOG_DEBUG, TAG_VCD, "[Client Data] No system commands");
723         }
724
725         if (0 < g_slist_length(g_cur_cmd_list.exclusive_system_cmds)) {
726                 iter = g_slist_nth(g_cur_cmd_list.exclusive_system_cmds, 0);
727                 while (NULL != iter) {
728                         temp_cmd = iter->data;
729
730                         if (result_id == temp_cmd->id) {
731                                 /**pid = g_manager.pid; */
732                                 /**cmd_type = VCD_CLIENT_COMMAND_GROUP_TYPE_SYSTEM_EXCLUSIVE; */
733                                 /*SLOG(LOG_DEBUG, TAG_VCD, "[Client Data] Find result pid(%d) type(%d)", *pid, *cmd_type); */
734
735                                 *result = __command_copy(temp_cmd);
736                                 return 0;
737                         }
738
739                         iter = g_slist_next(iter);
740                 }
741         } else {
742                 SLOG(LOG_DEBUG, TAG_VCD, "[Client Data] No exclusive system commands");
743         }
744
745         if (0 < g_slist_length(g_cur_cmd_list.background_cmds)) {
746                 background_command_s* back_cmd_info;
747                 iter = g_slist_nth(g_cur_cmd_list.background_cmds, 0);
748
749                 while (NULL != iter) {
750                         back_cmd_info = iter->data;
751
752                         GSList* back_iter = NULL;
753                         back_iter = g_slist_nth(back_cmd_info->cmds, 0);
754
755                         SLOG(LOG_DEBUG, TAG_VCD, "[Client Data] pid(%d) command count(%d)", back_cmd_info->pid, back_cmd_info->cmd_count);
756
757                         while (NULL != back_iter) {
758                                 temp_cmd = back_iter->data;
759
760                                 if (result_id == temp_cmd->id) {
761                                         /**pid = back_cmd_info->pid; */
762                                         /**cmd_type = VCD_CLIENT_COMMAND_GROUP_TYPE_BACKGROUND; */
763
764                                         *result = __command_copy(temp_cmd);
765                                         return 0;
766                                 }
767                                 back_iter = g_slist_next(back_iter);
768                         }
769
770                         iter = g_slist_next(iter);
771                 }
772         } else {
773                 SLOG(LOG_DEBUG, TAG_VCD, "[Client Data] No background commands");
774         }
775
776         SLOG(LOG_ERROR, TAG_VCD, "[Client Data ERROR] Not find matched result");
777
778         return -1;
779 }
780
781 int vcd_client_set_slience_detection(bool value)
782 {
783         g_silence_detection = value;
784         return 0;
785 }
786
787 bool vcd_client_get_slience_detection()
788 {
789         return g_silence_detection;
790 }
791
792 int vcd_client_set_recognition_mode(vcd_recognition_mode_e mode)
793 {
794         g_recognition_mode = mode;
795         return 0;
796 }
797
798 vcd_recognition_mode_e vcd_client_get_recognition_mode()
799 {
800         return g_recognition_mode;
801 }
802
803 int __show_client_list()
804 {
805         GSList *iter = NULL;
806         vc_client_info_s *data = NULL;
807
808         SLOG(LOG_DEBUG, TAG_VCD, "----- client list");
809
810         int count = g_slist_length(g_client_list);
811         int i;
812
813         if (0 == count) {
814                 SLOG(LOG_DEBUG, TAG_VCD, "No Client");
815         } else {
816                 iter = g_slist_nth(g_client_list, 0);
817                 for (i = 0; i < count; i++) {
818                         data = iter->data;
819
820                         SLOG(LOG_DEBUG, TAG_VCD, "[%dth] pid(%d)", i, data->pid);
821                         iter = g_slist_next(iter);
822                 }
823         }
824
825         SLOG(LOG_DEBUG, TAG_VCD, "-----");
826
827         SLOG(LOG_DEBUG, TAG_VCD, "----- widget list");
828
829         widget_info_s *widget_data = NULL;
830
831         count = g_slist_length(g_widget_list);
832
833         if (0 == count) {
834                 SLOG(LOG_DEBUG, TAG_VCD, "No widget");
835         } else {
836                 iter = g_slist_nth(g_widget_list, 0);
837                 for (i = 0; i < count; i++) {
838                         widget_data = iter->data;
839
840                         SLOG(LOG_DEBUG, TAG_VCD, "[%dth] pid(%d)", i, widget_data->pid);
841                         iter = g_slist_next(iter);
842                 }
843         }
844
845         SLOG(LOG_DEBUG, TAG_VCD, "-----");
846
847         return 0;
848 }
849
850 int __show_command_list(GSList* cmd_group)
851 {
852         GSList *iter = NULL;
853         vc_cmd_s *data = NULL;
854
855         SLOG(LOG_DEBUG, TAG_VCD, "----- command group");
856
857         int count = g_slist_length(cmd_group);
858         int i;
859
860         if (0 == count) {
861                 SLOG(LOG_DEBUG, TAG_VCD, "No command");
862         } else {
863                 iter = g_slist_nth(cmd_group, 0);
864                 for (i = 0; i < count; i++) {
865                         data = iter->data;
866
867                         if (NULL != data->parameter) {
868                                 SLOG(LOG_DEBUG, TAG_VCD, "[%dth] command(%s) parameter(%s) key(%d)", i, data->command, data->parameter, data->key);
869                         } else {
870                                 SLOG(LOG_DEBUG, TAG_VCD, "[%dth] command(%s) key(%d)", i, data->command, data->key);
871                         }
872                         iter = g_slist_next(iter);
873                 }
874         }
875
876         SLOG(LOG_DEBUG, TAG_VCD, "-----");
877
878         return 0;
879 }
880
881 GSList* __client_get_item(const int pid)
882 {
883         GSList *iter = NULL;
884         vc_client_info_s *data = NULL;
885
886         int count = g_slist_length(g_client_list);
887         int i;
888
889         if (0 < count) {
890                 iter = g_slist_nth(g_client_list, 0);
891                 for (i = 0; i < count; i++) {
892                         data = iter->data;
893
894                         if (pid == data->pid)
895                                 return iter;
896
897                         iter = g_slist_next(iter);
898                 }
899         }
900
901         return NULL;
902 }
903
904 vc_client_info_s* __client_get_element(int pid)
905 {
906         GSList *iter = NULL;
907         vc_client_info_s *data = NULL;
908
909         int count = g_slist_length(g_client_list);
910         int i;
911
912         if (0 < count) {
913                 iter = g_slist_nth(g_client_list, 0);
914                 for (i = 0; i < count; i++) {
915                         data = iter->data;
916
917                         if (pid == data->pid)
918                                 return data;
919
920                         iter = g_slist_next(iter);
921                 }
922         }
923
924         return NULL;
925 }
926
927 int vcd_client_add(int pid)
928 {
929         /*Check pid is duplicated*/
930         GSList *tmp = NULL;
931         tmp = __client_get_item(pid);
932
933         if (NULL != tmp) {
934                 SLOG(LOG_WARN, TAG_VCD, "[Client Data] Client pid is already registered");
935                 return VCD_ERROR_INVALID_PARAMETER;
936         }
937
938         vc_client_info_s *info = (vc_client_info_s*)calloc(1, sizeof(vc_client_info_s));
939         if (NULL == info) {
940                 SLOG(LOG_ERROR, TAG_VCD, "[ERROR] Fail to allocate memory");
941                 return VCD_ERROR_OUT_OF_MEMORY;
942         }
943
944         info->pid = pid;
945
946         info->fg_cmd = false;
947         info->bg_cmd = false;
948         info->exclusive_cmd = false;
949
950         /* Add item to global list */
951         g_client_list = g_slist_append(g_client_list, info);
952
953         if (NULL == g_client_list) {
954                 SLOG(LOG_ERROR, TAG_VCD, "[Client Data ERROR] Fail to add new client");
955                 return -1;
956         } else {
957                 SLOG(LOG_DEBUG, TAG_VCD, "[Client Data SUCCESS] Add new client");
958         }
959
960 #ifdef CLIENT_DATA_DEBUG
961         __show_client_list();
962 #endif
963         return 0;
964 }
965
966 int vcd_client_delete(int pid)
967 {
968         GSList *tmp = NULL;
969         vc_client_info_s* client_info = NULL;
970
971         /*Get handle*/
972         tmp = __client_get_item(pid);
973         if (NULL == tmp) {
974                 SLOG(LOG_ERROR, TAG_VCD, "[Client Data ERROR] pid(%d) is NOT valid", pid);
975                 return VCD_ERROR_INVALID_PARAMETER;
976         }
977
978         /*Free client structure*/
979         client_info = tmp->data;
980         if (NULL != client_info) {
981                 free(client_info);
982         }
983
984         /*Remove handle from list*/
985         g_client_list = g_slist_remove_link(g_client_list, tmp);
986
987
988 #ifdef CLIENT_DATA_DEBUG
989         __show_client_list();
990 #endif
991
992         return 0;
993 }
994
995 bool vcd_client_is_available(int pid)
996 {
997         vc_client_info_s* client_info = NULL;
998
999         client_info = __client_get_element(pid);
1000         if (NULL == client_info) {
1001                 SLOG(LOG_WARN, TAG_VCD, "[Client Data] pid(%d) is NOT valid", pid);
1002                 return false;
1003         }
1004
1005         return true;
1006 }
1007
1008 int vcd_client_get_ref_count()
1009 {
1010         int count = 0;
1011
1012         count = g_slist_length(g_client_list) + g_slist_length(g_widget_list);
1013         if (0 < g_manager.pid) {
1014                 count++;
1015         }
1016
1017         SLOG(LOG_DEBUG, TAG_VCD, "[Client Data] client count : %d", count);
1018
1019         return count;
1020 }
1021
1022 int vcd_client_get_list(int** pids, int* pid_count)
1023 {
1024         if (NULL == pids || NULL == pid_count)
1025                 return -1;
1026
1027         int count = g_slist_length(g_client_list);
1028
1029         if (0 == count)
1030                 return -1;
1031
1032         int *tmp;
1033         tmp = (int*)calloc(count, sizeof(int));
1034         if (NULL == tmp) {
1035                 SLOG(LOG_ERROR, TAG_VCD, "[ERROR] Fail to allocate memory");
1036                 return VCD_ERROR_OUT_OF_MEMORY;
1037         }
1038
1039         GSList *iter = NULL;
1040         vc_client_info_s *data = NULL;
1041         int i = 0;
1042
1043         iter = g_slist_nth(g_client_list, 0);
1044
1045         while (NULL != iter) {
1046                 data = iter->data;
1047
1048                 if (NULL != data) {
1049                         tmp[i] = data->pid;
1050                 }
1051
1052                 iter = g_slist_next(iter);
1053                 i++;
1054         }
1055
1056         *pids = tmp;
1057         *pid_count = count;
1058
1059         return 0;
1060 }
1061
1062 int vcd_client_set_command_type(int pid, int type)
1063 {
1064         vc_client_info_s* client_info = NULL;
1065
1066         client_info = __client_get_element(pid);
1067         if (NULL == client_info) {
1068                 SLOG(LOG_ERROR, TAG_VCD, "[Client Data ERROR] vcd_client_get_pid : pid(%d) is not found", pid);
1069                 return VCD_ERROR_INVALID_PARAMETER;
1070         }
1071
1072         switch (type) {
1073         case VC_COMMAND_TYPE_FOREGROUND:
1074                 client_info->fg_cmd = true;
1075                 break;
1076         case VC_COMMAND_TYPE_BACKGROUND:
1077                 client_info->bg_cmd = true;
1078                 break;
1079         default:
1080                 SLOG(LOG_ERROR, TAG_VCD, "[Client Data ERROR] not supported command type(%d)", type);
1081                 return -1;
1082         }
1083
1084         return 0;
1085 }
1086
1087 int vcd_client_unset_command_type(int pid, int type)
1088 {
1089         vc_client_info_s* client_info = NULL;
1090
1091         client_info = __client_get_element(pid);
1092         if (NULL == client_info) {
1093                 SLOG(LOG_ERROR, TAG_VCD, "[Client Data ERROR] vcd_client_get_pid : pid(%d) is not found", pid);
1094                 return VCD_ERROR_INVALID_PARAMETER;
1095         }
1096
1097         switch (type) {
1098         case VC_COMMAND_TYPE_FOREGROUND:
1099                 client_info->fg_cmd = false;
1100                 break;
1101         case VC_COMMAND_TYPE_BACKGROUND:
1102                 client_info->bg_cmd = false;
1103                 break;
1104         default:
1105                 SLOG(LOG_ERROR, TAG_VCD, "[Client Data ERROR] not supported command type(%d)", type);
1106                 return -1;
1107         }
1108
1109         return 0;
1110 }
1111
1112 int vcd_client_set_exclusive_command(int pid)
1113 {
1114         vc_client_info_s* client_info = NULL;
1115
1116         client_info = __client_get_element(pid);
1117         if (NULL == client_info) {
1118                 SLOG(LOG_ERROR, TAG_VCD, "[Client Data ERROR] pid(%d) is not found", pid);
1119                 return VCD_ERROR_INVALID_PARAMETER;
1120         }
1121
1122         client_info->exclusive_cmd = true;
1123
1124         return 0;
1125 }
1126
1127 int vcd_client_unset_exclusive_command(int pid)
1128 {
1129         vc_client_info_s* client_info = NULL;
1130
1131         client_info = __client_get_element(pid);
1132         if (NULL == client_info) {
1133                 SLOG(LOG_ERROR, TAG_VCD, "[Client Data ERROR] pid(%d) is not found", pid);
1134                 return VCD_ERROR_INVALID_PARAMETER;
1135         }
1136
1137         client_info->exclusive_cmd = false;
1138
1139         return 0;
1140 }
1141
1142 int vcd_client_save_client_info()
1143 {
1144         if (0 != vc_info_parser_set_client_info(g_client_list)) {
1145                 SLOG(LOG_ERROR, TAG_VCD, "[ERROR] Fail to save client info");
1146                 return -1;
1147         }
1148
1149         return 0;
1150 }
1151
1152 /*
1153 * Functions for widget
1154 */
1155 GSList* __widget_get_item(int pid)
1156 {
1157         GSList *iter = NULL;
1158         widget_info_s *data = NULL;
1159
1160         int count = g_slist_length(g_widget_list);
1161         int i;
1162
1163         if (0 < count) {
1164                 iter = g_slist_nth(g_widget_list, 0);
1165                 for (i = 0; i < count; i++) {
1166                         data = iter->data;
1167
1168                         if (pid == data->pid)
1169                                 return iter;
1170
1171                         iter = g_slist_next(iter);
1172                 }
1173         }
1174
1175         return NULL;
1176 }
1177
1178 widget_info_s* __widget_get_element(int pid)
1179 {
1180         GSList *iter = NULL;
1181         widget_info_s *data = NULL;
1182
1183         int count = g_slist_length(g_widget_list);
1184         int i;
1185
1186         if (0 < count) {
1187                 iter = g_slist_nth(g_widget_list, 0);
1188                 for (i = 0; i < count; i++) {
1189                         data = iter->data;
1190
1191                         if (NULL != data) {
1192                                 if (pid == data->pid)
1193                                         return data;
1194                         }
1195
1196                         iter = g_slist_next(iter);
1197                 }
1198         }
1199
1200         return NULL;
1201 }
1202
1203 int vcd_client_widget_get_list(int** pids, int* pid_count)
1204 {
1205         if (NULL == pids || NULL == pid_count)
1206                 return -1;
1207
1208         int count = g_slist_length(g_widget_list);
1209
1210         if (0 == count)
1211                 return -1;
1212
1213         int *tmp;
1214         tmp = (int*)calloc(count, sizeof(int));
1215         if (NULL == tmp) {
1216                 SLOG(LOG_ERROR, TAG_VCD, "[ERROR] Fail to allocate memory");
1217                 return VCD_ERROR_OUT_OF_MEMORY;
1218         }
1219
1220         GSList *iter = NULL;
1221         widget_info_s *data = NULL;
1222         int i = 0;
1223
1224         iter = g_slist_nth(g_widget_list, 0);
1225         while (NULL != iter) {
1226                 data = iter->data;
1227
1228                 if (NULL != data) {
1229                         tmp[i] = data->pid;
1230                 }
1231
1232                 iter = g_slist_next(iter);
1233                 i++;
1234         }
1235
1236         *pids = tmp;
1237         *pid_count = count;
1238
1239         return 0;
1240 }
1241
1242 int vcd_client_widget_add(int pid)
1243 {
1244         /*Check pid is duplicated*/
1245         GSList *tmp = NULL;
1246         tmp = __widget_get_item(pid);
1247
1248         if (NULL != tmp) {
1249                 SLOG(LOG_WARN, TAG_VCD, "[Client Data] widget pid is already registered");
1250                 return VCD_ERROR_INVALID_PARAMETER;
1251         }
1252
1253         widget_info_s *info = (widget_info_s*)calloc(1, sizeof(widget_info_s));
1254         if (NULL == info) {
1255                 SLOG(LOG_ERROR, TAG_VCD, "[ERROR] Fail to allocate memory");
1256                 return VCD_ERROR_OUT_OF_MEMORY;
1257         }
1258
1259         info->pid = pid;
1260         info->widget_cmd = false;
1261
1262         /* Add item to global list */
1263         g_widget_list = g_slist_append(g_widget_list, info);
1264
1265         if (NULL == g_widget_list) {
1266                 SLOG(LOG_ERROR, TAG_VCD, "[Client Data ERROR] Fail to add new widget");
1267                 return -1;
1268         } else {
1269                 SLOG(LOG_DEBUG, TAG_VCD, "[Client Data SUCCESS] Add new widget");
1270         }
1271
1272 #ifdef CLIENT_DATA_DEBUG
1273         __show_client_list();
1274 #endif
1275         return 0;
1276 }
1277
1278 int vcd_client_widget_delete(int pid)
1279 {
1280         GSList *tmp = NULL;
1281         widget_info_s* widget_info = NULL;
1282
1283         /*Get handle*/
1284         tmp = __widget_get_item(pid);
1285         if (NULL == tmp) {
1286                 SLOG(LOG_ERROR, TAG_VCD, "[Client Data ERROR] pid(%d) is NOT valid", pid);
1287                 return VCD_ERROR_INVALID_PARAMETER;
1288         }
1289
1290         /*Free client structure*/
1291         widget_info = tmp->data;
1292         if (NULL != widget_info) {
1293                 free(widget_info);
1294         }
1295
1296         /*Remove handle from list*/
1297         g_widget_list = g_slist_remove_link(g_widget_list, tmp);
1298
1299
1300 #ifdef CLIENT_DATA_DEBUG
1301         __show_client_list();
1302 #endif
1303
1304         return 0;
1305 }
1306
1307 int vcd_client_widget_get_foreground_pid()
1308 {
1309         /* 1. Get foreground pid */
1310         int fg_pid = 0;
1311         if (0 != vcd_config_get_foreground(&fg_pid)) {
1312                 SLOG(LOG_WARN, TAG_VCD, "[Server WARNING] Fail to get foreground pid");
1313                 /* There is no foreground app for voice control */
1314         }
1315
1316         widget_info_s* widget = NULL;
1317
1318         widget = __widget_get_element(fg_pid);
1319         if (NULL == widget) {
1320                 SLOG(LOG_WARN, TAG_VCD, "[Client Data] Not found foreground pid of widget");
1321                 return -1;
1322         }
1323
1324         return widget->pid;
1325 }
1326
1327
1328 bool vcd_client_widget_is_available(int pid)
1329 {
1330         widget_info_s* widget_info = NULL;
1331
1332         widget_info = __widget_get_element(pid);
1333         if (NULL == widget_info) {
1334                 SLOG(LOG_WARN, TAG_VCD, "[Client Data] pid(%d) is NOT valid", pid);
1335                 return false;
1336         }
1337
1338         return true;
1339 }
1340
1341 int vcd_client_widget_set_command(int pid)
1342 {
1343         widget_info_s *info = NULL;
1344         info = __widget_get_element(pid);
1345         if (NULL == info) {
1346                 SLOG(LOG_ERROR, TAG_VCD, "[Client Data ERROR] pid(%d) is NOT valid", pid);
1347                 return VCD_ERROR_INVALID_PARAMETER;
1348         }
1349
1350         info->widget_cmd = true;
1351
1352         return 0;
1353 }
1354
1355 int vcd_client_widget_unset_command(int pid)
1356 {
1357         widget_info_s *info = NULL;
1358         info = __widget_get_element(pid);
1359         if (NULL == info) {
1360                 SLOG(LOG_ERROR, TAG_VCD, "[Client Data ERROR] pid(%d) is NOT valid", pid);
1361                 return VCD_ERROR_INVALID_PARAMETER;
1362         }
1363
1364         info->widget_cmd = false;
1365
1366         return 0;
1367 }