Merge "Replace IPC between widget and server from dbus to tidl" into tizen
[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 #include <app_manager.h>
18 #include <aul.h>
19 #include <aul_window.h>
20
21 #include "vcd_client_data.h"
22 #include "vcd_config.h"
23 #include "vcd_main.h"
24
25 #include "voice_control_command_expand.h"
26
27 /* Client list */
28 static GSList* g_client_list = NULL;
29
30 static GSList* g_widget_list = NULL;
31
32 static manager_info_s g_manager;
33
34 /* Manager IPC info */
35 static manager_tidl_info_s* g_mgr_tidl_info = NULL;
36
37 /* Widget IPC info */
38 static GSList* g_widget_tidl_info_list = NULL;
39
40 /* Command list */
41 static current_commands_list_s g_cur_cmd_list;
42
43 /* Demandable client list */
44 static GSList* g_demandable_client = NULL;
45
46 /* Runtime info */
47 static bool g_silence_detection;
48 static vcd_recognition_mode_e g_recognition_mode;
49 static char* g_result_text = NULL;
50 static bool g_is_waiting_recording = false;
51 static int g_waiting_recording_pid = -1;
52
53 /* Function definitions */
54 widget_info_s* __widget_get_element(int pid);
55
56 vc_client_info_s* __client_get_element(int pid);
57
58
59 int vcd_client_manager_set(int pid)
60 {
61         // Get appid by pid using app control
62         char* appid = NULL;
63         int ret = app_manager_get_app_id(pid, &appid);
64         if (0 != ret || NULL == appid) {
65                 SLOG(LOG_ERROR, TAG_VCD, "[ERROR] fail to get app id, ret(%d), pid(%d)", ret, pid);
66                 return -1;
67         }
68
69         if (-1 != g_manager.pid && NULL != g_manager.appid && 0 == strncmp(g_manager.appid, appid, strlen(g_manager.appid))) {
70                 SLOG(LOG_WARN, TAG_VCD, "Same manager has already registered. It doesn't need to set manager again.");
71                 if (appid)
72                         free(appid);
73                 return 0;
74         }
75
76         g_manager.pid = pid;
77         g_manager.manager_cmd = false;
78         g_manager.exclusive_cmd_option = false;
79         g_manager.appid = NULL;
80
81         g_manager.appid = strdup(appid);
82
83         free(appid);
84         appid = NULL;
85         return 0;
86 }
87
88 int vcd_client_manager_unset()
89 {
90         g_manager.pid = -1;
91         g_manager.manager_cmd = false;
92         g_manager.exclusive_cmd_option = false;
93
94         return 0;
95 }
96
97 int vcd_client_manager_unset_appid()
98 {
99         if (NULL != g_manager.appid) {
100                 free(g_manager.appid);
101                 g_manager.appid = NULL;
102         }
103         return 0;
104 }
105
106 bool vcd_client_manager_is_valid(int pid)
107 {
108         if (-1 == g_manager.pid || pid == g_manager.pid) {
109                 return true;
110         }
111         return false;
112 }
113
114 int vcd_client_manager_set_command(int pid)
115 {
116         if (pid != g_manager.pid) {
117                 SLOG(LOG_ERROR, TAG_VCD, "[Client Data ERROR] pid(%d) is NOT valid", pid);
118                 return -1;
119         }
120         g_manager.manager_cmd = true;
121         return 0;
122 }
123
124 int vcd_client_manager_unset_command(int pid)
125 {
126         if (pid != g_manager.pid) {
127                 SLOG(LOG_ERROR, TAG_VCD, "[Client Data ERROR] pid(%d) is NOT valid", pid);
128                 return -1;
129         }
130         g_manager.manager_cmd = false;
131         return 0;
132 }
133
134 bool vcd_client_manager_is_system_command_valid(int pid)
135 {
136         if (pid != g_manager.pid) {
137                 SLOG(LOG_WARN, TAG_VCD, "[Client Data WARNING] pid(%d) is NOT valid", pid);
138                 return false;
139         }
140
141         if (true == g_manager.manager_cmd)
142                 return true;
143
144         return false;
145 }
146
147 int vcd_client_manager_set_demandable_client(int pid, GSList* client_list)
148 {
149         if (0 != g_slist_length(g_demandable_client)) {
150                 /* release data */
151                 GSList *iter = NULL;
152                 vc_demandable_client_s* temp_client;
153                 iter = g_slist_nth(g_demandable_client, 0);
154
155                 while (NULL != iter) {
156                         temp_client = iter->data;
157
158                         if (NULL != temp_client) {
159                                 if (NULL != temp_client->appid)         free(temp_client->appid);
160                                 free(temp_client);
161                         }
162
163                         iter = g_slist_next(iter);
164                 }
165                 g_demandable_client = NULL;
166         }
167
168         g_demandable_client = client_list;
169
170         return 0;
171 }
172
173 bool vcd_client_manager_check_demandable_client(int pid)
174 {
175         if (0 == g_slist_length(g_demandable_client)) {
176                 SLOG(LOG_INFO, TAG_VCD, "[Client Data] All client is available to request start");
177                 return true;
178         }
179
180         /* Check demandable appid */
181         char appid[1024] = {0, };
182         if (0 == aul_app_get_appid_bypid(pid, appid, sizeof(appid) - 1)) {
183                 SLOG(LOG_INFO, TAG_VCD, "[Client Data] %s(%d) requests start", appid, pid);
184         } else {
185                 SLOG(LOG_INFO, TAG_VCD, "[Client Data] daemon(%d) requests start", pid);
186         }
187
188         /* Compare appid */
189         GSList *iter = NULL;
190         vc_demandable_client_s* temp_client;
191         iter = g_slist_nth(g_demandable_client, 0);
192
193         while (NULL != iter) {
194                 temp_client = iter->data;
195
196                 if (NULL != temp_client) {
197
198                         SLOG(LOG_DEBUG, TAG_VCD, "[Client Data] demandable appid(%s)", temp_client->appid);
199
200                         if (NULL != temp_client->appid) {
201                                 if (0 == strcmp(temp_client->appid, appid)) {
202                                         SLOG(LOG_INFO, TAG_VCD, "[Client Data] pid(%d) is available", pid);
203                                         return true;
204                                 }
205                         } else {
206                                 if (0 == strlen(appid)) {
207                                         SLOG(LOG_INFO, TAG_VCD, "[Client Data] pid(%d) is available", pid);
208                                         return true;
209                                 }
210                         }
211                 }
212
213                 iter = g_slist_next(iter);
214         }
215
216         return false;
217 }
218
219 bool vcd_client_manager_get_exclusive()
220 {
221         return g_manager.exclusive_cmd_option;
222 }
223
224 int vcd_client_manager_set_exclusive(bool value)
225 {
226         g_manager.exclusive_cmd_option = value;
227         return 0;
228 }
229
230 int vcd_client_manager_get_pid()
231 {
232         return g_manager.pid;
233 }
234
235 int vcd_client_manager_get_appid(char** appid)
236 {
237         if (NULL != g_manager.appid)
238                 *appid = strdup(g_manager.appid);
239
240         return 0;
241 }
242
243 int vcd_client_manager_set_result_text(const char* result)
244 {
245         if (NULL != g_result_text) {
246                 free(g_result_text);
247                 g_result_text = NULL;
248         }
249
250         if (NULL != result) {
251                 g_result_text = strdup(result);
252         }
253
254         return 0;
255 }
256
257 char* vcd_client_manager_get_result_text()
258 {
259         return g_result_text;
260 }
261
262 int vcd_client_manager_create_tidl_info(int pid)
263 {
264         /*Check already created*/
265         if (NULL != g_mgr_tidl_info) {
266                 SLOG(LOG_WARN, TAG_VCD, "[Client Data] Manager tidl info pid is already registered");
267                 if (pid != g_mgr_tidl_info->pid) {
268                         SLOG(LOG_ERROR, TAG_VCD, "[ERROR] Manager pid is different");
269                         return VCD_ERROR_OPERATION_FAILED;
270                 }
271                 return VCD_ERROR_NONE;
272         }
273
274         SLOG(LOG_INFO, TAG_VCD, "[Client Data] There is no manager tidl info. Create new one.");
275         g_mgr_tidl_info = (manager_tidl_info_s*)calloc(1, sizeof(manager_tidl_info_s));
276         if (NULL == g_mgr_tidl_info) {
277                 SLOG(LOG_ERROR, TAG_VCD, "[ERROR] Fail to allocate memory");
278                 return VCD_ERROR_OUT_OF_MEMORY;
279         }
280
281         g_mgr_tidl_info->pid = pid;
282         g_mgr_tidl_info->notify_cb = NULL;
283         g_mgr_tidl_info->notify_cb_user_data = NULL;
284         g_mgr_tidl_info->send_buffer_cb = NULL;
285         g_mgr_tidl_info->send_buffer_cb_user_data = NULL;
286
287         g_mgr_tidl_info->connected = false;
288         g_mgr_tidl_info->connection_requesting = false;
289         g_mgr_tidl_info->rpc_h = NULL;
290
291         SLOG(LOG_INFO, TAG_VCD, "[Client Data SUCCESS] Add new manager tidl info. pid(%d)", pid);
292
293         return VCD_ERROR_NONE;
294 }
295
296 int vcd_client_manager_set_tidl_notify_cb(rpc_port_stub_vc_mgr_notify_cb_h callback, void* user_data)
297 {
298         if (NULL == g_mgr_tidl_info) {
299                 SLOG(LOG_ERROR, TAG_VCD, "[Client Data ERROR] There is no manager tidl info");
300                 return VCD_ERROR_INVALID_PARAMETER;
301         }
302
303         int ret = -1;
304         ret = rpc_port_stub_vc_mgr_notify_cb_clone(callback, &(g_mgr_tidl_info->notify_cb));
305         if (0 != ret) {
306                 SLOG(LOG_ERROR, TAG_VCD, "[Client Data ERROR] Fail to clone notify callback. ret(%d)", ret);
307         } else {
308                 SLOG(LOG_INFO, TAG_VCD, "[Client Data] Succeed to clone notify callback. ret(%d)", ret);
309         }
310         g_mgr_tidl_info->notify_cb_user_data = user_data;
311
312         return VCD_ERROR_NONE;
313 }
314
315 int vcd_client_manager_unset_tidl_notify_cb()
316 {
317         if (NULL == g_mgr_tidl_info) {
318                 SLOG(LOG_ERROR, TAG_VCD, "[Client Data ERROR] There is no manager tidl info");
319                 return VCD_ERROR_INVALID_PARAMETER;
320         }
321
322         int ret = -1;
323         ret = rpc_port_stub_vc_mgr_notify_cb_destroy(g_mgr_tidl_info->notify_cb);
324         if (0 != ret) {
325                 SLOG(LOG_ERROR, TAG_VCD, "[Client Data ERROR] Fail to destroy notify callback. ret(%d)", ret);
326         } else {
327                 SLOG(LOG_INFO, TAG_VCD, "[Client Data] Succeed to destroy notify callback. ret(%d)", ret);
328         }
329         g_mgr_tidl_info->notify_cb = NULL;
330         g_mgr_tidl_info->notify_cb_user_data = NULL;
331
332         return VCD_ERROR_NONE;
333 }
334
335 int vcd_client_manager_set_tidl_send_buffer_cb(rpc_port_stub_vc_mgr_send_buffer_cb_h callback, void* user_data)
336 {
337         if (NULL == g_mgr_tidl_info) {
338                 SLOG(LOG_ERROR, TAG_VCD, "[Client Data ERROR] There is no manager tidl info");
339                 return VCD_ERROR_INVALID_PARAMETER;
340         }
341
342         int ret = -1;
343         ret = rpc_port_stub_vc_mgr_send_buffer_cb_clone(callback, &(g_mgr_tidl_info->send_buffer_cb));
344         if (0 != ret) {
345                 SLOG(LOG_ERROR, TAG_VCD, "[Client Data ERROR] Fail to clone feedback callback. ret(%d)", ret);
346         } else {
347                 SLOG(LOG_INFO, TAG_VCD, "[Client Data] Succeed to clone feedback callback. ret(%d)", ret);
348         }
349         g_mgr_tidl_info->send_buffer_cb_user_data = user_data;
350
351         return VCD_ERROR_NONE;
352 }
353
354 int vcd_client_manager_unset_tidl_send_buffer_cb()
355 {
356         if (NULL == g_mgr_tidl_info) {
357                 SLOG(LOG_ERROR, TAG_VCD, "[Client Data ERROR] There is no manager tidl info");
358                 return VCD_ERROR_INVALID_PARAMETER;
359         }
360
361         int ret = -1;
362         ret = rpc_port_stub_vc_mgr_send_buffer_cb_destroy(g_mgr_tidl_info->send_buffer_cb);
363         if (0 != ret) {
364                 SLOG(LOG_ERROR, TAG_VCD, "[Client Data ERROR] Fail to destroy feedback callback. ret(%d)", ret);
365         } else {
366                 SLOG(LOG_INFO, TAG_VCD, "[Client Data] Succeed to destroy feedback callback. ret(%d)", ret);
367         }
368         g_mgr_tidl_info->send_buffer_cb = NULL;
369         g_mgr_tidl_info->send_buffer_cb_user_data = NULL;
370
371         return VCD_ERROR_NONE;
372 }
373
374 int vcd_client_manager_delete_tidl_info()
375 {
376         if (NULL == g_mgr_tidl_info) {
377                 SLOG(LOG_ERROR, TAG_VCD, "[Client Data ERROR] There is no manager tidl info");
378                 return VCD_ERROR_INVALID_PARAMETER;
379         }
380
381         if (0 != rpc_port_proxy_vcd_mgr_destroy(g_mgr_tidl_info->rpc_h)) {
382                 SLOG(LOG_ERROR, TAG_VCD, "[TIDL ERROR] Fail to destroy tidl handle");
383         }
384
385         g_mgr_tidl_info->rpc_h = NULL;
386         free(g_mgr_tidl_info);
387         g_mgr_tidl_info = NULL;
388
389         return 0;
390 }
391
392 manager_tidl_info_s* vcd_client_manager_get_tidl_info()
393 {
394         return g_mgr_tidl_info;
395 }
396
397 static void __vcd_client_release_each_commands(GSList** cmds)
398 {
399         GSList *iter = NULL;
400         vc_cmd_s* temp_cmd;
401
402         if (0 < g_slist_length(*cmds)) {
403                 iter = g_slist_nth(*cmds, 0);
404                 while (NULL != iter) {
405                         temp_cmd = iter->data;
406
407                         if (NULL != temp_cmd) {
408                                 if (NULL != temp_cmd->command) {
409                                         free(temp_cmd->command);
410                                         temp_cmd->command = NULL;
411                                 }
412                                 if (NULL != temp_cmd->appid) {
413                                         free(temp_cmd->appid);
414                                         temp_cmd->appid = NULL;
415                                 }
416                                 if (NULL != temp_cmd->parameter) {
417                                         free(temp_cmd->parameter);
418                                         temp_cmd->parameter = NULL;
419                                 }
420                                 if (NULL != temp_cmd->invocation_name) {
421                                         free(temp_cmd->invocation_name);
422                                         temp_cmd->invocation_name = NULL;
423                                 }
424                                 if (NULL != temp_cmd->fixed) {
425                                         free(temp_cmd->fixed);
426                                         temp_cmd->fixed = NULL;
427                                 }
428                                 free(temp_cmd);
429                                 temp_cmd = NULL;
430                         }
431                         *cmds = g_slist_remove_link(*cmds, iter);
432
433                         iter = g_slist_nth(*cmds, 0);
434                 }
435                 *cmds = NULL;
436         }
437 }
438
439 int __vcd_client_release_commands()
440 {
441         g_cur_cmd_list.total_cmd_count = 0;
442         g_cur_cmd_list.foreground = VC_NO_FOREGROUND_PID;
443
444         __vcd_client_release_each_commands(&(g_cur_cmd_list.widget_cmds));
445         __vcd_client_release_each_commands(&(g_cur_cmd_list.system_cmds));
446         __vcd_client_release_each_commands(&(g_cur_cmd_list.system_background_cmds));
447         __vcd_client_release_each_commands(&(g_cur_cmd_list.exclusive_system_cmds));
448         __vcd_client_release_each_commands(&(g_cur_cmd_list.foreground_cmds));
449         __vcd_client_release_each_commands(&(g_cur_cmd_list.background_cmds));
450
451         return 0;
452 }
453
454 int vcd_client_command_collect_command()
455 {
456         /* 1. Get foreground pid */
457         int fg_pid = 0;
458         int ret = -1;
459         if (0 != vcd_config_get_foreground(&fg_pid)) {
460                 SLOG(LOG_WARN, TAG_VCD, "[Server WARNING] Fail to get foreground pid");
461                 /* There is no foreground app for voice control */
462         }
463
464         SLOG(LOG_INFO, TAG_VCD, "[Client Data] Foreground pid(%d)", fg_pid);
465
466         /* 2. Clean up command list */
467         __vcd_client_release_commands();
468
469         /* Check exclusive system command */
470         if (true == g_manager.exclusive_cmd_option && 1 == vcd_config_get_command_type_enabled(VC_COMMAND_TYPE_EXCLUSIVE)) {
471                 SLOG(LOG_INFO, TAG_VCD, "[Client Data] Exclusive option of manager is ON");
472
473                 GSList* ex_sys_cmd_list = NULL;
474                 if (true == g_manager.manager_cmd) {
475                         ret = vc_cmd_parser_get_commands(g_manager.pid, VC_COMMAND_TYPE_EXCLUSIVE, &ex_sys_cmd_list);
476                         if (0 != ret) {
477                                 SLOG(LOG_ERROR, TAG_VCD, "[Client Data ERROR] Fail to get the system command list");
478                         } else {
479                                 g_cur_cmd_list.exclusive_system_cmds = ex_sys_cmd_list;
480                         }
481                 } else {
482                         SLOG(LOG_INFO, TAG_VCD, "[Client Data] No exclusive system commands");
483                 }
484
485                 return 0;
486         }
487
488         /* 3. Set system command */
489         GSList* sys_cmd_list = NULL;
490         if (true == g_manager.manager_cmd && 1 == vcd_config_get_command_type_enabled(VC_COMMAND_TYPE_SYSTEM)) {
491                 ret = vc_cmd_parser_get_commands(g_manager.pid, VC_COMMAND_TYPE_SYSTEM, &sys_cmd_list);
492                 if (0 != ret) {
493                         SLOG(LOG_ERROR, TAG_VCD, "[Client Data ERROR] Fail to get the system command list");
494                 } else {
495                         g_cur_cmd_list.system_cmds = sys_cmd_list;
496                 }
497         } else {
498                 SLOG(LOG_INFO, TAG_VCD, "[Client Data] No system commands");
499         }
500
501         GSList* sys_back_cmd_list = NULL;
502         if (true == g_manager.manager_cmd && 1 == vcd_config_get_command_type_enabled(VC_COMMAND_TYPE_SYSTEM_BACKGROUND)) {
503                 ret = vc_cmd_parser_get_commands(g_manager.pid, VC_COMMAND_TYPE_SYSTEM_BACKGROUND, &sys_back_cmd_list);
504                 if (0 != ret) {
505                         SLOG(LOG_ERROR, TAG_VCD, "[Client Data ERROR] Fail to get the system command list");
506                 } else {
507                         g_cur_cmd_list.system_background_cmds = sys_back_cmd_list;
508                 }
509         } else {
510                 SLOG(LOG_INFO, TAG_VCD, "[Client Data] No system background commands");
511         }
512
513         /* 4. Set foreground commands and widget */
514         GSList* fg_cmd_list = NULL;
515         if (VC_NO_FOREGROUND_PID != fg_pid) {
516                 GSList* widget_cmd_list = NULL;
517
518                 g_cur_cmd_list.foreground = fg_pid;
519
520                 /* 4-1. Set widget command */
521                 widget_info_s* widget_info = NULL;
522                 widget_info = __widget_get_element(fg_pid);
523                 if (NULL != widget_info && 1 == vcd_config_get_command_type_enabled(VC_COMMAND_TYPE_WIDGET)) {
524                         if (true == widget_info->widget_cmd) {
525                                 ret = vc_cmd_parser_get_commands(fg_pid, VC_COMMAND_TYPE_WIDGET, &widget_cmd_list);
526                                 if (0 != ret) {
527                                         SLOG(LOG_ERROR, TAG_VCD, "[Client Data ERROR] Fail to get the WIDGET command list");
528                                 } else {
529                                         g_cur_cmd_list.widget_cmds = widget_cmd_list;
530                                 }
531                         }
532                 } else {
533                         SLOG(LOG_INFO, TAG_VCD, "[Client Data] No widget commands");
534                 }
535
536                 /* 4-2. Set foreground command of foreground app */
537                 if (1 == vcd_config_get_command_type_enabled(VC_COMMAND_TYPE_FOREGROUND)) {
538                         ret = vc_cmd_parser_get_commands(fg_pid, VC_COMMAND_TYPE_FOREGROUND, &fg_cmd_list);
539                         if (0 != ret) {
540                                 SLOG(LOG_ERROR, TAG_VCD, "[Client Data ERROR] Fail to get the fg command list");
541                         } else {
542                                 g_cur_cmd_list.foreground_cmds = fg_cmd_list;
543                         }
544                 }
545         } else {
546                 SLOG(LOG_INFO, TAG_VCD, "[Client Data] No foreground app");
547         }
548         if (true == g_manager.manager_cmd && 1 == vcd_config_get_command_type_enabled(VC_COMMAND_TYPE_FOREGROUND)) {
549                 /* 4-3. Set foreground command by manager */
550                 ret = vc_cmd_parser_get_commands(g_manager.pid, VC_COMMAND_TYPE_FOREGROUND, &fg_cmd_list);
551                 if (0 != ret) {
552                         SLOG(LOG_INFO, TAG_VCD, "[Client Data] No foreground commands of manager app");
553                 } else {
554                         g_cur_cmd_list.foreground_cmds = fg_cmd_list;
555                 }
556         }
557
558         /* 5. Set background commands */
559         GSList* bg_cmd_list = NULL;
560         if (1 == vcd_config_get_command_type_enabled(VC_COMMAND_TYPE_BACKGROUND)) {
561                 ret = vc_cmd_parser_get_commands(fg_pid, VC_COMMAND_TYPE_BACKGROUND, &bg_cmd_list);
562                 if (0 != ret) {
563                         SLOG(LOG_ERROR, TAG_VCD, "[Client Data ERROR] Fail to get the bg command list");
564                 } else {
565                         /* Add item to global command list */
566                         g_cur_cmd_list.background_cmds = bg_cmd_list;
567                 }
568         }
569         return 0;
570 }
571
572 int vcd_client_get_length()
573 {
574         int command_count = 0;
575         command_count += g_slist_length(g_cur_cmd_list.widget_cmds);
576         command_count += g_slist_length(g_cur_cmd_list.system_cmds);
577         command_count += g_slist_length(g_cur_cmd_list.exclusive_system_cmds);
578         command_count += g_slist_length(g_cur_cmd_list.system_background_cmds);
579         command_count += g_slist_length(g_cur_cmd_list.foreground_cmds);
580         command_count += g_slist_length(g_cur_cmd_list.background_cmds);
581
582         g_cur_cmd_list.total_cmd_count = command_count;
583
584         SLOG(LOG_INFO, TAG_VCD, "[Client Data] Command count : %d ", g_cur_cmd_list.total_cmd_count);
585         return command_count;
586 }
587
588 int vcd_client_foreach_command(client_foreach_command_cb callback, void* user_data)
589 {
590         if (NULL == callback) {
591                 SLOG(LOG_ERROR, TAG_VCD, "[Client Data ERROR] input parameter is NULL");
592                 return VCD_ERROR_INVALID_PARAMETER;
593         }
594
595         if (0 != vcd_client_command_collect_command()) {
596                 SLOG(LOG_ERROR, TAG_VCD, "[Client Data ERROR] Fail to collect command");
597                 return VCD_ERROR_OPERATION_FAILED;
598         }
599
600         if (0 >= vcd_client_get_length()) {
601                 SLOG(LOG_ERROR, TAG_VCD, "[Client Data ERROR] No current command");
602                 return VCD_ERROR_OPERATION_FAILED;
603         }
604
605 //      int id_count = 1;
606         GSList *iter = NULL;
607         vc_cmd_s* temp_cmd;
608
609         if (0 < g_slist_length(g_cur_cmd_list.widget_cmds)) {
610                 iter = g_slist_nth(g_cur_cmd_list.widget_cmds, 0);
611                 while (NULL != iter) {
612                         temp_cmd = iter->data;
613
614                         SLOG(LOG_DEBUG, TAG_VCD, "[Client Data] Widget : id(%d) type(%d) format(%d) command(%s) domain(%d)"
615                                  , temp_cmd->id, temp_cmd->type, temp_cmd->format, temp_cmd->command, temp_cmd->domain);
616
617                         callback(temp_cmd->id, temp_cmd->type, temp_cmd->format, temp_cmd->command, temp_cmd->parameter, temp_cmd->domain, user_data);
618
619                         iter = g_slist_next(iter);
620                 }
621         } else {
622                 SLOG(LOG_INFO, TAG_VCD, "[Client Data] No widget commands");
623         }
624
625         if (0 < g_slist_length(g_cur_cmd_list.foreground_cmds)) {
626                 iter = g_slist_nth(g_cur_cmd_list.foreground_cmds, 0);
627                 while (NULL != iter) {
628                         temp_cmd = iter->data;
629
630                         SLOG(LOG_DEBUG, TAG_VCD, "[Client Data] Fore : id(%d) type(%d) format(%d) command(%s) param(%s) domain(%d) fixed(%s)"
631                                  , temp_cmd->id, temp_cmd->type, temp_cmd->format, temp_cmd->command, temp_cmd->parameter, temp_cmd->domain, temp_cmd->fixed);
632
633                         callback(temp_cmd->id, temp_cmd->type, temp_cmd->format, temp_cmd->command, temp_cmd->parameter, temp_cmd->domain, user_data);
634
635                         iter = g_slist_next(iter);
636                 }
637         } else {
638                 SLOG(LOG_INFO, TAG_VCD, "[Client Data] No foreground commands");
639         }
640
641         if (0 < g_slist_length(g_cur_cmd_list.system_cmds)) {
642                 iter = g_slist_nth(g_cur_cmd_list.system_cmds, 0);
643                 while (NULL != iter) {
644                         temp_cmd = iter->data;
645
646                         SLOG(LOG_DEBUG, TAG_VCD, "[Client Data] System : id(%d) type(%d) format(%d) command(%s) param(%s) domain(%d)"
647                                  , temp_cmd->id, temp_cmd->type, temp_cmd->format, temp_cmd->command, temp_cmd->parameter, temp_cmd->domain);
648
649                         callback(temp_cmd->id, temp_cmd->type, temp_cmd->format, temp_cmd->command, temp_cmd->parameter, temp_cmd->domain, user_data);
650
651                         iter = g_slist_next(iter);
652                 }
653         } else {
654                 SLOG(LOG_INFO, TAG_VCD, "[Client Data] No system commands");
655         }
656
657         if (0 < g_slist_length(g_cur_cmd_list.system_background_cmds)) {
658                 iter = g_slist_nth(g_cur_cmd_list.system_background_cmds, 0);
659                 while (NULL != iter) {
660                         temp_cmd = iter->data;
661
662                         SLOG(LOG_DEBUG, TAG_VCD, "[Client Data] System background : id(%d) type(%d) format(%d) command(%s) param(%s) domain(%d)"
663                                  , temp_cmd->id, temp_cmd->type, temp_cmd->format, temp_cmd->command, temp_cmd->parameter, temp_cmd->domain);
664
665                         callback(temp_cmd->id, temp_cmd->type, temp_cmd->format, temp_cmd->command, temp_cmd->parameter, temp_cmd->domain, user_data);
666
667                         iter = g_slist_next(iter);
668                 }
669         } else {
670                 SLOG(LOG_INFO, TAG_VCD, "[Client Data] No system background commands");
671         }
672
673         if (0 < g_slist_length(g_cur_cmd_list.exclusive_system_cmds)) {
674                 iter = g_slist_nth(g_cur_cmd_list.exclusive_system_cmds, 0);
675                 while (NULL != iter) {
676                         temp_cmd = iter->data;
677
678                         SLOG(LOG_DEBUG, TAG_VCD, "[Client Data] Exclusive system : id(%d) type(%d) format(%d) command(%s) param(%s) domain(%d)"
679                                  , temp_cmd->id, temp_cmd->type, temp_cmd->format, temp_cmd->command, temp_cmd->parameter, temp_cmd->domain);
680
681                         callback(temp_cmd->id, temp_cmd->type, temp_cmd->format, temp_cmd->command, temp_cmd->parameter, temp_cmd->domain, user_data);
682
683                         iter = g_slist_next(iter);
684                 }
685         } else {
686                 SLOG(LOG_INFO, TAG_VCD, "[Client Data] No exclusive system commands");
687         }
688
689         if (0 < g_slist_length(g_cur_cmd_list.background_cmds)) {
690                 iter = g_slist_nth(g_cur_cmd_list.background_cmds, 0);
691                 while (NULL != iter) {
692                         temp_cmd = iter->data;
693
694                         SLOG(LOG_DEBUG, TAG_VCD, "[Client Data] Back : id(%d) format(%d) type(%d) command(%s) param(%s) domain(%d) appid(%s) invocation(%s) fixed(%s)"
695                                  , temp_cmd->id, temp_cmd->type, temp_cmd->format, temp_cmd->command, temp_cmd->parameter, temp_cmd->domain, temp_cmd->appid, temp_cmd->invocation_name, temp_cmd->fixed);
696
697                         callback(temp_cmd->id, temp_cmd->type, temp_cmd->format, temp_cmd->command, temp_cmd->parameter, temp_cmd->domain, user_data);
698
699                         iter = g_slist_next(iter);
700                 }
701         } else {
702                 SLOG(LOG_INFO, TAG_VCD, "[Client Data] No background commands");
703         }
704         return 0;
705 }
706
707 static vc_cmd_s* __command_copy(vc_cmd_s* src_cmd)
708 {
709         if (NULL == src_cmd) {
710                 SLOG(LOG_WARN, TAG_VCD, "[Client Data] Input command is NULL");
711                 return NULL;
712         }
713
714         vc_cmd_s* temp_cmd = NULL;
715         temp_cmd = (vc_cmd_s*)calloc(sizeof(vc_cmd_s), 1);
716         if (NULL == temp_cmd) {
717                 SLOG(LOG_ERROR, TAG_VCD, "[ERROR] Fail to allocate memory");
718                 return NULL;
719         }
720
721         temp_cmd->id = src_cmd->id;
722         temp_cmd->pid = src_cmd->pid;
723         temp_cmd->index = src_cmd->index;
724         temp_cmd->type = src_cmd->type;
725         temp_cmd->format = src_cmd->format;
726         temp_cmd->domain = src_cmd->domain;
727
728         if (VC_COMMAND_TYPE_SYSTEM == temp_cmd->type)           temp_cmd->priority = VC_COMMAND_PRIORITY_SYSTEM;
729         else if (VC_COMMAND_TYPE_EXCLUSIVE == temp_cmd->type)   temp_cmd->priority = VC_COMMAND_PRIORITY_EXCLUSIVE;
730         else if (VC_COMMAND_TYPE_WIDGET == temp_cmd->type)      temp_cmd->priority = VC_COMMAND_PRIORITY_WIDGET;
731         else if (VC_COMMAND_TYPE_FOREGROUND == temp_cmd->type)  temp_cmd->priority = VC_COMMAND_PRIORITY_FOREGROUND;
732         else if (VC_COMMAND_TYPE_SYSTEM_BACKGROUND == temp_cmd->type)   temp_cmd->priority = VC_COMMAND_PRIORITY_SYSTEM_BACKGROUND;
733         else if (VC_COMMAND_TYPE_BACKGROUND == temp_cmd->type)  temp_cmd->priority = VC_COMMAND_PRIORITY_BACKGROUND;
734
735         if (NULL != src_cmd->command) {
736                 temp_cmd->command = strdup(src_cmd->command);
737         }
738
739         if (NULL != src_cmd->parameter) {
740                 temp_cmd->parameter = strdup(src_cmd->parameter);
741         }
742
743         if (NULL != src_cmd->appid) {
744                 temp_cmd->appid = strdup(src_cmd->appid);
745         }
746
747         if (NULL != src_cmd->invocation_name) {
748                 temp_cmd->invocation_name = strdup(src_cmd->invocation_name);
749         }
750
751         if (NULL != src_cmd->fixed) {
752                 temp_cmd->fixed = strdup(src_cmd->fixed);
753         }
754
755         temp_cmd->key = src_cmd->key;
756         temp_cmd->modifier = src_cmd->modifier;
757
758         return temp_cmd;
759 }
760
761 int vcd_client_get_cmd_from_result_id(int result_id, vc_cmd_s** result)
762 {
763         GSList *iter = NULL;
764         vc_cmd_s* temp_cmd;
765
766         SLOG(LOG_INFO, TAG_VCD, "[Client Data] Result id(%d)", result_id);
767
768         if (0 < g_slist_length(g_cur_cmd_list.widget_cmds)) {
769                 iter = g_slist_nth(g_cur_cmd_list.widget_cmds, 0);
770                 while (NULL != iter) {
771                         temp_cmd = iter->data;
772
773                         if (result_id == temp_cmd->id) {
774                                 /**pid = g_cur_cmd_list.foreground; */
775                                 /**cmd_type = VCD_CLIENT_COMMAND_GROUP_TYPE_UI_CONTROL; */
776                                 /*SLOG(LOG_DEBUG, TAG_VCD, "[Client Data] Find result pid(%d) type(%d)", *pid, *cmd_type); */
777
778                                 *result = __command_copy(temp_cmd);
779
780                                 return 0;
781                         }
782
783                         iter = g_slist_next(iter);
784                 }
785         } else {
786                 SLOG(LOG_INFO, TAG_VCD, "[Client Data] No widget commands");
787         }
788
789         if (0 < g_slist_length(g_cur_cmd_list.foreground_cmds)) {
790                 iter = g_slist_nth(g_cur_cmd_list.foreground_cmds, 0);
791
792                 while (NULL != iter) {
793                         temp_cmd = iter->data;
794
795                         SLOG(LOG_DEBUG, TAG_VCD, "[Client Data] command id (%d)", temp_cmd->id);
796
797                         if (result_id == temp_cmd->id) {
798                                 /**pid = g_cur_cmd_list.foreground; */
799                                 /**cmd_type = VCD_CLIENT_COMMAND_GROUP_TYPE_FOREGROUND; */
800                                 /*SLOG(LOG_DEBUG, TAG_VCD, "[Client Data] Find result pid(%d) type(%d)", *pid, *cmd_type); */
801
802                                 *result = __command_copy(temp_cmd);
803                                 return 0;
804                         }
805
806                         iter = g_slist_next(iter);
807                 }
808         } else {
809                 SLOG(LOG_INFO, TAG_VCD, "[Client Data] No foreground commands");
810         }
811
812         if (0 < g_slist_length(g_cur_cmd_list.system_cmds)) {
813                 iter = g_slist_nth(g_cur_cmd_list.system_cmds, 0);
814                 while (NULL != iter) {
815                         temp_cmd = iter->data;
816
817                         if (result_id == temp_cmd->id) {
818                                 /**pid = g_manager.pid; */
819                                 /**cmd_type = VCD_CLIENT_COMMAND_GROUP_TYPE_SYSTEM; */
820                                 /*SLOG(LOG_DEBUG, TAG_VCD, "[Client Data] Find result pid(%d) type(%d)", *pid, *cmd_type); */
821
822                                 *result = __command_copy(temp_cmd);
823                                 return 0;
824                         }
825
826                         iter = g_slist_next(iter);
827                 }
828         } else {
829                 SLOG(LOG_INFO, TAG_VCD, "[Client Data] No system commands");
830         }
831
832         if (0 < g_slist_length(g_cur_cmd_list.system_background_cmds)) {
833                 iter = g_slist_nth(g_cur_cmd_list.system_background_cmds, 0);
834                 while (NULL != iter) {
835                         temp_cmd = iter->data;
836
837                         if (result_id == temp_cmd->id) {
838                                 /**pid = g_manager.pid; */
839                                 /**cmd_type = VCD_CLIENT_COMMAND_GROUP_TYPE_SYSTEM_BACKGROUND; */
840                                 /*SLOG(LOG_DEBUG, TAG_VCD, "[Client Data] Find result pid(%d) type(%d)", *pid, *cmd_type); */
841
842                                 *result = __command_copy(temp_cmd);
843                                 return 0;
844                         }
845
846                         iter = g_slist_next(iter);
847                 }
848         } else {
849                 SLOG(LOG_INFO, TAG_VCD, "[Client Data] No system background commands");
850         }
851
852         if (0 < g_slist_length(g_cur_cmd_list.exclusive_system_cmds)) {
853                 iter = g_slist_nth(g_cur_cmd_list.exclusive_system_cmds, 0);
854                 while (NULL != iter) {
855                         temp_cmd = iter->data;
856
857                         if (result_id == temp_cmd->id) {
858                                 /**pid = g_manager.pid; */
859                                 /**cmd_type = VCD_CLIENT_COMMAND_GROUP_TYPE_SYSTEM_EXCLUSIVE; */
860                                 /*SLOG(LOG_DEBUG, TAG_VCD, "[Client Data] Find result pid(%d) type(%d)", *pid, *cmd_type); */
861
862                                 *result = __command_copy(temp_cmd);
863                                 return 0;
864                         }
865
866                         iter = g_slist_next(iter);
867                 }
868         } else {
869                 SLOG(LOG_INFO, TAG_VCD, "[Client Data] No exclusive system commands");
870         }
871
872         if (0 < g_slist_length(g_cur_cmd_list.background_cmds)) {
873                 iter = g_slist_nth(g_cur_cmd_list.background_cmds, 0);
874
875                 while (NULL != iter) {
876                         temp_cmd = iter->data;
877
878                         SLOG(LOG_DEBUG, TAG_VCD, "[Client Data] command id (%d)", temp_cmd->id);
879
880                         if (result_id == temp_cmd->id) {
881                                 *result = __command_copy(temp_cmd);
882                                 return 0;
883                         }
884
885                         iter = g_slist_next(iter);
886                 }
887         } else {
888                 SLOG(LOG_INFO, TAG_VCD, "[Client Data] No background commands");
889         }
890
891         SLOG(LOG_ERROR, TAG_VCD, "[Client Data ERROR] Not find matched result");
892         return -1;
893 }
894
895 int vcd_client_set_slience_detection(bool value)
896 {
897         g_silence_detection = value;
898         return 0;
899 }
900
901 bool vcd_client_get_slience_detection()
902 {
903         return g_silence_detection;
904 }
905
906 int vcd_client_set_recognition_mode(vcd_recognition_mode_e mode)
907 {
908         g_recognition_mode = mode;
909         return 0;
910 }
911
912 vcd_recognition_mode_e vcd_client_get_recognition_mode()
913 {
914         return g_recognition_mode;
915 }
916
917 int vcd_client_set_server_dialog(int pid, bool is_server_dialog)
918 {
919         vc_client_info_s* client_info = NULL;
920
921         client_info = __client_get_element(pid);
922         if (NULL == client_info) {
923                 SLOG(LOG_ERROR, TAG_VCD, "[Client Data ERROR] vcd_client_get_pid : pid(%d) is not found", pid);
924                 return VCD_ERROR_INVALID_PARAMETER;
925         }
926
927         client_info->server_dialog = is_server_dialog;
928
929         SLOG(LOG_INFO, TAG_VCD, "[Client Data] Set server dialog, client pid(%d), server_dialog(%d)", pid, client_info->server_dialog);
930         return 0;
931 }
932
933 int vcd_client_get_server_dialog(int pid, bool* is_server_dialog)
934 {
935         vc_client_info_s* client_info = NULL;
936
937         client_info = __client_get_element(pid);
938         if (NULL == client_info) {
939                 SLOG(LOG_ERROR, TAG_VCD, "[Client Data ERROR] vcd_client_get_pid : pid(%d) is not found", pid);
940                 return VCD_ERROR_INVALID_PARAMETER;
941         }
942
943         *is_server_dialog = client_info->server_dialog;
944
945         SLOG(LOG_INFO, TAG_VCD, "[Client Data] Get server dialog, client pid(%d), server_dialog(%d)", pid, *is_server_dialog);
946         return 0;
947 }
948
949 int vcd_client_append_cmd_from_type(int type, vc_cmd_list_h list)
950 {
951         GSList *item = NULL;
952
953         if (NULL == list) {
954                 SLOG(LOG_ERROR, TAG_VCD, "[ERROR] Invalid list parameter");
955                 return VCD_ERROR_INVALID_PARAMETER;
956         }
957
958         switch (type) {
959         case VC_COMMAND_TYPE_SYSTEM:
960                 item = g_cur_cmd_list.system_cmds;
961                 break;
962         case VC_COMMAND_TYPE_FOREGROUND:
963                 item = g_cur_cmd_list.foreground_cmds;
964                 break;
965         case VC_COMMAND_TYPE_WIDGET:
966                 item = g_cur_cmd_list.widget_cmds;
967                 break;
968         case VC_COMMAND_TYPE_SYSTEM_BACKGROUND:
969                 item = g_cur_cmd_list.system_background_cmds;
970                 break;
971         case VC_COMMAND_TYPE_BACKGROUND:
972                 item = g_cur_cmd_list.background_cmds;
973                 break;
974         case VC_COMMAND_TYPE_EXCLUSIVE:
975                 item = g_cur_cmd_list.exclusive_system_cmds;
976                 break;
977         default:
978                 SLOG(LOG_ERROR, TAG_VCD, "[ERROR] Invalid type parameter");
979                 return VCD_ERROR_INVALID_PARAMETER;
980         }
981
982         while (NULL != item) {
983                 vc_cmd_h temp_cmd = NULL;
984                 vc_cmd_h target_cmd = (vc_cmd_h)item->data;
985
986                 temp_cmd = (vc_cmd_h)__command_copy((vc_cmd_s*)target_cmd);
987
988                 if (NULL == temp_cmd) {
989                         SLOG(LOG_ERROR, TAG_VCD, "[ERROR] Fail to copy the command");
990                         return VCD_ERROR_OUT_OF_MEMORY;
991                 }
992
993                 if (0 != vc_cmd_list_add(list, temp_cmd)) {
994                         SLOG(LOG_ERROR, TAG_VCD, "[ERROR] Fail to add the command in the list");
995                         if (NULL != temp_cmd) {
996                                 vc_cmd_destroy(temp_cmd);
997                                 temp_cmd = NULL;
998                         }
999
1000                         return VCD_ERROR_OPERATION_FAILED;
1001                 }
1002
1003                 item = item->next;
1004         }
1005
1006         return 0;
1007 }
1008
1009 int __show_client_list()
1010 {
1011         GSList *iter = NULL;
1012         vc_client_info_s *data = NULL;
1013
1014         SLOG(LOG_DEBUG, TAG_VCD, "@@@ client list");
1015
1016         int count = g_slist_length(g_client_list);
1017         int i;
1018
1019         if (0 == count) {
1020                 SLOG(LOG_DEBUG, TAG_VCD, "No Client");
1021         } else {
1022                 iter = g_slist_nth(g_client_list, 0);
1023                 for (i = 0; i < count; i++) {
1024                         if (NULL == iter)
1025                                 break;
1026
1027                         data = iter->data;
1028
1029                         if (NULL != data) {
1030                                 SLOG(LOG_DEBUG, TAG_VCD, "[%dth] pid(%d)", i, data->pid);
1031                         }
1032                         iter = g_slist_next(iter);
1033                 }
1034         }
1035
1036         SLOG(LOG_DEBUG, TAG_VCD, "@@@");
1037
1038         SLOG(LOG_DEBUG, TAG_VCD, "@@@ widget list");
1039
1040         widget_info_s *widget_data = NULL;
1041
1042         count = g_slist_length(g_widget_list);
1043
1044         if (0 == count) {
1045                 SLOG(LOG_DEBUG, TAG_VCD, "No widget");
1046         } else {
1047                 iter = g_slist_nth(g_widget_list, 0);
1048                 for (i = 0; i < count; i++) {
1049                         if (NULL == iter)
1050                                 break;
1051
1052                         widget_data = iter->data;
1053
1054                         if (NULL != widget_data) {
1055                                 SLOG(LOG_DEBUG, TAG_VCD, "[%dth] pid(%d)", i, widget_data->pid);
1056                         }
1057                         iter = g_slist_next(iter);
1058                 }
1059         }
1060
1061         SLOG(LOG_DEBUG, TAG_VCD, "@@@");
1062
1063         return 0;
1064 }
1065
1066 int __show_command_list(GSList* cmd_group)
1067 {
1068         GSList *iter = NULL;
1069         vc_cmd_s *data = NULL;
1070
1071         SLOG(LOG_DEBUG, TAG_VCD, "@@@ command group");
1072
1073         int count = g_slist_length(cmd_group);
1074         int i;
1075
1076         if (0 == count) {
1077                 SLOG(LOG_DEBUG, TAG_VCD, "No command");
1078         } else {
1079                 iter = g_slist_nth(cmd_group, 0);
1080                 for (i = 0; i < count; i++) {
1081                         if (NULL == iter)
1082                                 break;
1083
1084                         data = iter->data;
1085                         if (NULL != data) {
1086                                 if (NULL != data->parameter) {
1087                                         SLOG(LOG_DEBUG, TAG_VCD, "[%dth] command(%s) parameter(%s) key(%d)", i, data->command, data->parameter, data->key);
1088                                 } else {
1089                                         SLOG(LOG_DEBUG, TAG_VCD, "[%dth] command(%s) key(%d)", i, data->command, data->key);
1090                                 }
1091                         }
1092                         iter = g_slist_next(iter);
1093                 }
1094         }
1095
1096         SLOG(LOG_DEBUG, TAG_VCD, "@@@");
1097
1098         return 0;
1099 }
1100
1101 GSList* __client_get_item(const int pid)
1102 {
1103         GSList *iter = NULL;
1104         vc_client_info_s *data = NULL;
1105
1106         int count = g_slist_length(g_client_list);
1107         int i;
1108
1109         if (0 < count) {
1110                 iter = g_slist_nth(g_client_list, 0);
1111                 for (i = 0; i < count; i++) {
1112                         if (NULL == iter)
1113                                 break;
1114
1115                         data = iter->data;
1116                         if (NULL != data) {
1117                                 if (pid == data->pid)
1118                                         return iter;
1119                         }
1120
1121                         iter = g_slist_next(iter);
1122                 }
1123         }
1124
1125         return NULL;
1126 }
1127
1128 vc_client_info_s* __client_get_element(int pid)
1129 {
1130         GSList *iter = NULL;
1131         vc_client_info_s *data = NULL;
1132
1133         int count = g_slist_length(g_client_list);
1134         int i;
1135
1136         if (0 < count) {
1137                 iter = g_slist_nth(g_client_list, 0);
1138                 for (i = 0; i < count; i++) {
1139                         if (NULL == iter)
1140                                 break;
1141
1142                         data = iter->data;
1143
1144                         if (NULL != data) {
1145                                 if (pid == data->pid)
1146                                         return data;
1147                         }
1148
1149                         iter = g_slist_next(iter);
1150                 }
1151         }
1152
1153         return NULL;
1154 }
1155
1156 int vcd_client_add(int pid)
1157 {
1158         /*Check pid is duplicated*/
1159         GSList *tmp = NULL;
1160         tmp = __client_get_item(pid);
1161
1162         if (NULL != tmp) {
1163                 SLOG(LOG_WARN, TAG_VCD, "[Client Data] Client pid is already registered");
1164                 return VCD_ERROR_INVALID_PARAMETER;
1165         }
1166
1167         vc_client_info_s *info = (vc_client_info_s*)calloc(1, sizeof(vc_client_info_s));
1168         if (NULL == info) {
1169                 SLOG(LOG_ERROR, TAG_VCD, "[ERROR] Fail to allocate memory");
1170                 return VCD_ERROR_OUT_OF_MEMORY;
1171         }
1172
1173         info->pid = pid;
1174
1175         info->fg_cmd = false;
1176         info->bg_cmd = false;
1177         info->exclusive_cmd = false;
1178         info->server_dialog = false;
1179
1180         /* Add item to global list */
1181         g_client_list = g_slist_append(g_client_list, info);
1182
1183         if (NULL == g_client_list) {
1184                 SLOG(LOG_ERROR, TAG_VCD, "[Client Data ERROR] Fail to add new client");
1185
1186                 free(info);
1187                 info = NULL;
1188
1189                 return -1;
1190         } else {
1191                 SLOG(LOG_INFO, TAG_VCD, "[Client Data SUCCESS] Add new client");
1192         }
1193
1194 #ifdef CLIENT_DATA_DEBUG
1195         __show_client_list();
1196 #endif
1197         return 0;
1198 }
1199
1200 int vcd_client_delete(int pid)
1201 {
1202         GSList *tmp = NULL;
1203         vc_client_info_s* client_info = NULL;
1204
1205         /*Get handle*/
1206         tmp = __client_get_item(pid);
1207         if (NULL == tmp) {
1208                 SLOG(LOG_ERROR, TAG_VCD, "[Client Data ERROR] pid(%d) is NOT valid", pid);
1209                 return VCD_ERROR_INVALID_PARAMETER;
1210         }
1211
1212         /*Free client structure*/
1213         client_info = tmp->data;
1214         if (NULL != client_info) {
1215                 free(client_info);
1216         }
1217
1218         /*Remove handle from list*/
1219         g_client_list = g_slist_remove_link(g_client_list, tmp);
1220
1221
1222 #ifdef CLIENT_DATA_DEBUG
1223         __show_client_list();
1224 #endif
1225
1226         return 0;
1227 }
1228
1229 bool vcd_client_is_available(int pid)
1230 {
1231         vc_client_info_s* client_info = NULL;
1232
1233         client_info = __client_get_element(pid);
1234         if (NULL == client_info) {
1235                 SLOG(LOG_WARN, TAG_VCD, "[Client Data] pid(%d) is NOT valid", pid);
1236                 return false;
1237         }
1238
1239         return true;
1240 }
1241
1242 int vcd_client_get_ref_count()
1243 {
1244         int count = 0;
1245
1246         count = g_slist_length(g_client_list) + g_slist_length(g_widget_list);
1247         if (0 < g_manager.pid) {
1248                 count++;
1249         }
1250
1251         SLOG(LOG_INFO, TAG_VCD, "[Client Data] client count : %d", count);
1252
1253         return count;
1254 }
1255
1256 int vcd_client_get_list(int** pids, int* pid_count)
1257 {
1258         if (NULL == pids || NULL == pid_count)
1259                 return -1;
1260
1261         int count = g_slist_length(g_client_list);
1262
1263         if (0 == count)
1264                 return -1;
1265
1266         int *tmp;
1267         tmp = (int*)calloc(count, sizeof(int));
1268         if (NULL == tmp) {
1269                 SLOG(LOG_ERROR, TAG_VCD, "[ERROR] Fail to allocate memory");
1270                 return VCD_ERROR_OUT_OF_MEMORY;
1271         }
1272
1273         GSList *iter = NULL;
1274         vc_client_info_s *data = NULL;
1275         int i = 0;
1276
1277         iter = g_slist_nth(g_client_list, 0);
1278
1279         while (NULL != iter) {
1280                 data = iter->data;
1281
1282                 if (NULL != data) {
1283                         tmp[i] = data->pid;
1284                 }
1285
1286                 iter = g_slist_next(iter);
1287                 i++;
1288         }
1289
1290         *pids = tmp;
1291         *pid_count = count;
1292
1293         return 0;
1294 }
1295
1296 int vcd_client_set_command_type(int pid, int type)
1297 {
1298         vc_client_info_s* client_info = NULL;
1299
1300         client_info = __client_get_element(pid);
1301         if (NULL == client_info) {
1302                 SLOG(LOG_ERROR, TAG_VCD, "[Client Data ERROR] vcd_client_get_pid : pid(%d) is not found", pid);
1303                 return VCD_ERROR_INVALID_PARAMETER;
1304         }
1305
1306         switch (type) {
1307         case VC_COMMAND_TYPE_FOREGROUND:
1308                 client_info->fg_cmd = true;
1309                 break;
1310         case VC_COMMAND_TYPE_BACKGROUND:
1311                 client_info->bg_cmd = true;
1312                 break;
1313         default:
1314                 SLOG(LOG_ERROR, TAG_VCD, "[Client Data ERROR] not supported command type(%d)", type);
1315                 return -1;
1316         }
1317
1318         return 0;
1319 }
1320
1321 int vcd_client_unset_command_type(int pid, int type)
1322 {
1323         vc_client_info_s* client_info = NULL;
1324
1325         client_info = __client_get_element(pid);
1326         if (NULL == client_info) {
1327                 SLOG(LOG_ERROR, TAG_VCD, "[Client Data ERROR] vcd_client_get_pid : pid(%d) is not found", pid);
1328                 return VCD_ERROR_INVALID_PARAMETER;
1329         }
1330
1331         switch (type) {
1332         case VC_COMMAND_TYPE_FOREGROUND:
1333                 client_info->fg_cmd = false;
1334                 break;
1335         case VC_COMMAND_TYPE_BACKGROUND:
1336                 client_info->bg_cmd = false;
1337                 break;
1338         default:
1339                 SLOG(LOG_ERROR, TAG_VCD, "[Client Data ERROR] not supported command type(%d)", type);
1340                 return -1;
1341         }
1342
1343         return 0;
1344 }
1345
1346 int vcd_client_set_exclusive_command(int pid)
1347 {
1348         vc_client_info_s* client_info = NULL;
1349
1350         client_info = __client_get_element(pid);
1351         if (NULL == client_info) {
1352                 SLOG(LOG_ERROR, TAG_VCD, "[Client Data ERROR] pid(%d) is not found", pid);
1353                 return VCD_ERROR_INVALID_PARAMETER;
1354         }
1355
1356         client_info->exclusive_cmd = true;
1357
1358         return 0;
1359 }
1360
1361 int vcd_client_unset_exclusive_command(int pid)
1362 {
1363         vc_client_info_s* client_info = NULL;
1364
1365         client_info = __client_get_element(pid);
1366         if (NULL == client_info) {
1367                 SLOG(LOG_ERROR, TAG_VCD, "[Client Data ERROR] pid(%d) is not found", pid);
1368                 return VCD_ERROR_INVALID_PARAMETER;
1369         }
1370
1371         client_info->exclusive_cmd = false;
1372
1373         return 0;
1374 }
1375
1376 int vcd_client_save_client_info()
1377 {
1378         if (0 != vc_info_parser_set_client_info(g_client_list)) {
1379                 SLOG(LOG_ERROR, TAG_VCD, "[ERROR] Fail to save client info");
1380                 return -1;
1381         }
1382
1383         return 0;
1384 }
1385
1386 /*
1387 * Functions for widget
1388 */
1389 GSList* __widget_get_item(int pid)
1390 {
1391         GSList *iter = NULL;
1392         widget_info_s *data = NULL;
1393
1394         int count = g_slist_length(g_widget_list);
1395         int i;
1396
1397         if (0 < count) {
1398                 iter = g_slist_nth(g_widget_list, 0);
1399                 for (i = 0; i < count; i++) {
1400                         if (NULL == iter)
1401                                 break;
1402
1403                         data = iter->data;
1404
1405                         if (NULL != data) {
1406                                 if (pid == data->pid)
1407                                         return iter;
1408                         }
1409
1410                         iter = g_slist_next(iter);
1411                 }
1412         }
1413
1414         return NULL;
1415 }
1416
1417 widget_info_s* __widget_get_element(int pid)
1418 {
1419         GSList *iter = NULL;
1420         widget_info_s *data = NULL;
1421
1422         int count = g_slist_length(g_widget_list);
1423         int i;
1424
1425         if (0 < count) {
1426                 iter = g_slist_nth(g_widget_list, 0);
1427                 i = 0;
1428
1429                 while (iter && i < count) {
1430                         data = iter->data;
1431
1432                         if (NULL != data) {
1433                                 if (pid == data->pid)
1434                                         return data;
1435                         }
1436
1437                         iter = g_slist_next(iter);
1438
1439                         i++;
1440                 }
1441         }
1442
1443         return NULL;
1444 }
1445
1446 int vcd_client_widget_get_list(int** pids, int* pid_count)
1447 {
1448         if (NULL == pids || NULL == pid_count)
1449                 return -1;
1450
1451         int count = g_slist_length(g_widget_list);
1452
1453         if (0 == count)
1454                 return -1;
1455
1456         int *tmp;
1457         tmp = (int*)calloc(count, sizeof(int));
1458         if (NULL == tmp) {
1459                 SLOG(LOG_ERROR, TAG_VCD, "[ERROR] Fail to allocate memory");
1460                 return VCD_ERROR_OUT_OF_MEMORY;
1461         }
1462
1463         GSList *iter = NULL;
1464         widget_info_s *data = NULL;
1465         int i = 0;
1466
1467         iter = g_slist_nth(g_widget_list, 0);
1468         while (NULL != iter) {
1469                 data = iter->data;
1470
1471                 if (NULL != data) {
1472                         tmp[i] = data->pid;
1473                 }
1474
1475                 iter = g_slist_next(iter);
1476                 i++;
1477         }
1478
1479         *pids = tmp;
1480         *pid_count = count;
1481
1482         return 0;
1483 }
1484
1485 int vcd_client_widget_add(int pid)
1486 {
1487         /*Check pid is duplicated*/
1488         GSList *tmp = NULL;
1489         tmp = __widget_get_item(pid);
1490
1491         if (NULL != tmp) {
1492                 SLOG(LOG_WARN, TAG_VCD, "[Client Data] widget pid is already registered");
1493                 return VCD_ERROR_INVALID_PARAMETER;
1494         }
1495
1496         widget_info_s *info = (widget_info_s*)calloc(1, sizeof(widget_info_s));
1497         if (NULL == info) {
1498                 SLOG(LOG_ERROR, TAG_VCD, "[ERROR] Fail to allocate memory");
1499                 return VCD_ERROR_OUT_OF_MEMORY;
1500         }
1501
1502         info->pid = pid;
1503         info->widget_cmd = false;
1504
1505         /* Add item to global list */
1506         g_widget_list = g_slist_append(g_widget_list, info);
1507
1508         if (NULL == g_widget_list) {
1509                 SLOG(LOG_ERROR, TAG_VCD, "[Client Data ERROR] Fail to add new widget");
1510
1511                 free(info);
1512                 info = NULL;
1513
1514                 return -1;
1515         } else {
1516                 SLOG(LOG_INFO, TAG_VCD, "[Client Data SUCCESS] Add new widget");
1517         }
1518
1519 #ifdef CLIENT_DATA_DEBUG
1520         __show_client_list();
1521 #endif
1522         return 0;
1523 }
1524
1525 int vcd_client_widget_delete(int pid)
1526 {
1527         GSList *tmp = NULL;
1528         widget_info_s* widget_info = NULL;
1529
1530         /*Get handle*/
1531         tmp = __widget_get_item(pid);
1532         if (NULL == tmp) {
1533                 SLOG(LOG_ERROR, TAG_VCD, "[Client Data ERROR] pid(%d) is NOT valid", pid);
1534                 return VCD_ERROR_INVALID_PARAMETER;
1535         }
1536
1537         /*Free client structure*/
1538         widget_info = tmp->data;
1539         if (NULL != widget_info) {
1540                 free(widget_info);
1541         }
1542
1543         /*Remove handle from list*/
1544         g_widget_list = g_slist_remove_link(g_widget_list, tmp);
1545
1546
1547 #ifdef CLIENT_DATA_DEBUG
1548         __show_client_list();
1549 #endif
1550
1551         return 0;
1552 }
1553
1554 int vcd_client_widget_get_foreground_pid()
1555 {
1556         /* 1. Get foreground pid */
1557         int fg_pid = 0;
1558         if (0 != vcd_config_get_foreground(&fg_pid)) {
1559                 SLOG(LOG_WARN, TAG_VCD, "[Server WARNING] Fail to get foreground pid");
1560                 /* There is no foreground app for voice control */
1561         }
1562
1563         widget_info_s* widget = NULL;
1564
1565         widget = __widget_get_element(fg_pid);
1566         if (NULL == widget) {
1567                 SLOG(LOG_WARN, TAG_VCD, "[Client Data] Not found foreground pid of widget");
1568                 return -1;
1569         }
1570
1571         return widget->pid;
1572 }
1573
1574
1575 bool vcd_client_widget_is_available(int pid)
1576 {
1577         widget_info_s* widget_info = NULL;
1578
1579         widget_info = __widget_get_element(pid);
1580         if (NULL == widget_info) {
1581                 SLOG(LOG_WARN, TAG_VCD, "[Client Data] pid(%d) is NOT valid", pid);
1582                 return false;
1583         }
1584
1585         return true;
1586 }
1587
1588 int vcd_client_widget_set_command(int pid)
1589 {
1590         widget_info_s *info = NULL;
1591         info = __widget_get_element(pid);
1592         if (NULL == info) {
1593                 SLOG(LOG_ERROR, TAG_VCD, "[Client Data ERROR] pid(%d) is NOT valid", pid);
1594                 return VCD_ERROR_INVALID_PARAMETER;
1595         }
1596
1597         info->widget_cmd = true;
1598
1599         return 0;
1600 }
1601
1602 int vcd_client_widget_unset_command(int pid)
1603 {
1604         widget_info_s *info = NULL;
1605         info = __widget_get_element(pid);
1606         if (NULL == info) {
1607                 SLOG(LOG_ERROR, TAG_VCD, "[Client Data ERROR] pid(%d) is NOT valid", pid);
1608                 return VCD_ERROR_INVALID_PARAMETER;
1609         }
1610
1611         info->widget_cmd = false;
1612
1613         return 0;
1614 }
1615
1616 int vcd_client_widget_set_asr_result_enabled(int pid, bool enable)
1617 {
1618         widget_info_s *info = NULL;
1619         info = __widget_get_element(pid);
1620         if (NULL == info) {
1621                 SLOG(LOG_ERROR, TAG_VCD, "[Client Data ERROR] pid(%d) is NOT valid", pid);
1622                 return VCD_ERROR_INVALID_PARAMETER;
1623         }
1624
1625         info->asr_result_enabled = enable;
1626
1627         return 0;
1628 }
1629
1630 int vcd_client_widget_get_asr_result_enabled(int pid, bool* enable)
1631 {
1632         widget_info_s *info = NULL;
1633         info = __widget_get_element(pid);
1634         if (NULL == info) {
1635                 SLOG(LOG_ERROR, TAG_VCD, "[Client Data ERROR] pid(%d) is NOT valid", pid);
1636                 return VCD_ERROR_INVALID_PARAMETER;
1637         }
1638
1639         *enable = info->asr_result_enabled;
1640
1641         return 0;
1642 }
1643
1644 int vcd_client_widget_set_waiting_for_recording(int pid, bool waiting)
1645 {
1646
1647         if (TRUE == waiting && pid != vcd_client_widget_get_foreground_pid()) {
1648                 SLOG(LOG_ERROR, TAG_VCD, "[Client Data ERROR] pid(%d) is NOT foreground pid", pid);
1649                 return -1;
1650         }
1651
1652         g_is_waiting_recording = waiting;
1653         g_waiting_recording_pid = pid;
1654         SLOG(LOG_ERROR, TAG_VCD, "[INFO] Success to set waiting for recording, pid(%d), waiting(%d)", pid, waiting);
1655         return 0;
1656 }
1657
1658 int vcd_client_widget_get_waiting_for_recording(int pid, bool* waiting)
1659 {
1660         if (pid != g_waiting_recording_pid) {
1661                 SLOG(LOG_ERROR, TAG_VCD, "[Client Data ERROR] pid(%d) is NOT waiting pid", pid);
1662                 return -1;
1663         }
1664
1665         *waiting = g_is_waiting_recording;
1666         SLOG(LOG_ERROR, TAG_VCD, "[INFO] Success to get waiting for recording, waiting(%d)", *waiting);
1667         return 0;
1668 }
1669
1670 GSList* __get_widget_tidl_info_item(const int pid)
1671 {
1672         GSList *iter = NULL;
1673         widget_tidl_info_s *data = NULL;
1674
1675         int count = g_slist_length(g_widget_tidl_info_list);
1676         int i;
1677
1678         if (0 < count) {
1679                 iter = g_slist_nth(g_widget_tidl_info_list, 0);
1680                 for (i = 0; i < count; i++) {
1681                         if (NULL == iter)
1682                                 break;
1683
1684                         data = iter->data;
1685                         if (NULL != data) {
1686                                 if (pid == data->pid)
1687                                         return iter;
1688                         }
1689
1690                         iter = g_slist_next(iter);
1691                 }
1692         }
1693
1694         return NULL;
1695 }
1696
1697 widget_tidl_info_s* __get_widget_tidl_info_element(int pid)
1698 {
1699         GSList *iter = NULL;
1700         widget_tidl_info_s *data = NULL;
1701
1702         int count = g_slist_length(g_widget_tidl_info_list);
1703         int i;
1704
1705         if (0 < count) {
1706                 iter = g_slist_nth(g_widget_tidl_info_list, 0);
1707                 for (i = 0; i < count; i++) {
1708                         if (NULL == iter)
1709                                 break;
1710
1711                         data = iter->data;
1712
1713                         if (NULL != data) {
1714                                 if (pid == data->pid)
1715                                         return data;
1716                         }
1717
1718                         iter = g_slist_next(iter);
1719                 }
1720         }
1721
1722         return NULL;
1723 }
1724
1725 int vcd_client_widget_add_tidl_info(int pid)
1726 {
1727         /*Check pid is duplicated*/
1728         widget_tidl_info_s* info = NULL;
1729         info = __get_widget_tidl_info_element(pid);
1730
1731         if (NULL != info) {
1732                 SLOG(LOG_WARN, TAG_VCD, "[Client Data] Widget tidl info pid is already registered");
1733                 return VCD_ERROR_NONE;
1734         }
1735
1736         SLOG(LOG_INFO, TAG_VCD, "[Client Data] There is no tidl info of pid(%d). Create new one.", pid);
1737         info = (widget_tidl_info_s*)calloc(1, sizeof(widget_tidl_info_s));
1738         if (NULL == info) {
1739                 SLOG(LOG_ERROR, TAG_VCD, "[ERROR] Fail to allocate memory");
1740                 return VCD_ERROR_OUT_OF_MEMORY;
1741         }
1742
1743         info->pid = pid;
1744         info->notify_cb = NULL;
1745         info->notify_cb_user_data = NULL;
1746
1747         info->connected = false;
1748         info->connection_requesting = false;
1749         info->rpc_h = NULL;
1750
1751         g_widget_tidl_info_list = g_slist_append(g_widget_tidl_info_list, info);
1752         if (NULL == g_widget_tidl_info_list) {
1753                 SLOG(LOG_ERROR, TAG_VCD, "[Client Data ERROR] Fail to add new widget tidl info");
1754
1755                 free(info);
1756                 info = NULL;
1757
1758                 return -1;
1759         } else {
1760                 SLOG(LOG_INFO, TAG_VCD, "[Client Data SUCCESS] Add new widget tidl info. pid(%d)", pid);
1761         }
1762
1763         return VCD_ERROR_NONE;
1764 }
1765
1766 int vcd_client_widget_set_tidl_notify_cb(int pid, rpc_port_stub_vc_widget_notify_cb_h callback, void* user_data)
1767 {
1768         /*Check pid*/
1769         widget_tidl_info_s* info = NULL;
1770         info = __get_widget_tidl_info_element(pid);
1771
1772         if (NULL == info) {
1773                 SLOG(LOG_ERROR, TAG_VCD, "[Client Data ERROR] There is no tidl info in the list. pid(%d)", pid);
1774                 return VCD_ERROR_INVALID_PARAMETER;
1775         }
1776
1777         int ret = -1;
1778         ret = rpc_port_stub_vc_widget_notify_cb_clone(callback, &(info->notify_cb));
1779         if (0 != ret) {
1780                 SLOG(LOG_ERROR, TAG_VCD, "[Client Data ERROR] Fail to clone notify callback. ret(%d)", ret);
1781         } else {
1782                 SLOG(LOG_INFO, TAG_VCD, "[Client Data] Succeed to clone notify callback. ret(%d)", ret);
1783         }
1784         info->notify_cb_user_data = user_data;
1785
1786         return VCD_ERROR_NONE;
1787 }
1788
1789 int vcd_client_widget_unset_tidl_notify_cb(int pid)
1790 {
1791         /*Check pid*/
1792         widget_tidl_info_s* info = NULL;
1793         info = __get_widget_tidl_info_element(pid);
1794
1795         if (NULL == info) {
1796                 SLOG(LOG_ERROR, TAG_VCD, "[Client Data ERROR] There is no tidl info in the list. pid(%d)", pid);
1797                 return VCD_ERROR_INVALID_PARAMETER;
1798         }
1799
1800         int ret = -1;
1801         ret = rpc_port_stub_vc_widget_notify_cb_destroy(info->notify_cb);
1802         if (0 != ret) {
1803                 SLOG(LOG_ERROR, TAG_VCD, "[Client Data ERROR] Fail to destroy notify callback. ret(%d)", ret);
1804         } else {
1805                 SLOG(LOG_INFO, TAG_VCD, "[Client Data] Succeed to destroy notify callback. ret(%d)", ret);
1806         }
1807         info->notify_cb = NULL;
1808         info->notify_cb_user_data = NULL;
1809
1810         return VCD_ERROR_NONE;
1811 }
1812
1813 int vcd_client_widget_delete_tidl_info(int pid)
1814 {
1815         GSList *tmp = NULL;
1816         widget_tidl_info_s* widget_tidl_info = NULL;
1817
1818         /*Get handle*/
1819         tmp = __get_widget_tidl_info_item(pid);
1820         if (NULL == tmp) {
1821                 SLOG(LOG_ERROR, TAG_VCD, "[Client Data ERROR] pid(%d) is NOT valid", pid);
1822                 return VCD_ERROR_INVALID_PARAMETER;
1823         }
1824
1825         /*Free widget structure*/
1826         widget_tidl_info = tmp->data;
1827         if (NULL != widget_tidl_info) {
1828                 free(widget_tidl_info);
1829         }
1830
1831         /*Remove handle from list*/
1832         g_widget_tidl_info_list = g_slist_remove_link(g_widget_tidl_info_list, tmp);
1833
1834         return 0;
1835 }
1836
1837 widget_tidl_info_s* vcd_client_widget_get_tidl_info(int pid)
1838 {
1839         return __get_widget_tidl_info_element(pid);
1840 }
1841
1842 GSList* vcd_client_widget_get_tidl_info_list()
1843 {
1844         return g_widget_tidl_info_list;
1845 }
1846
1847
1848 void vcd_client_update_foreground_pid()
1849 {
1850         int tmp_pid = VC_RUNTIME_INFO_NO_FOREGROUND;
1851         vcd_config_get_foreground(&tmp_pid);
1852
1853         int pid = VC_RUNTIME_INFO_NO_FOREGROUND;
1854         int ret = aul_window_get_focused_pid(&pid);
1855         if (0 != ret) {
1856                 SLOG(LOG_ERROR, TAG_VCD, "[Client Data ERROR] Fail to get focused pid, ret(%d)", ret);
1857         }
1858         SLOG(LOG_INFO, TAG_VCD, "[INFO] Foreground pid (%d), Focused pid (%d)", tmp_pid, pid);
1859
1860         GSList *iter = NULL;
1861         vc_client_info_s *data = NULL;
1862
1863         int count = g_slist_length(g_client_list);
1864         int i;
1865
1866         if (0 == count) {
1867                 SLOG(LOG_INFO, TAG_VCD, "No Client");
1868         } else {
1869                 iter = g_slist_nth(g_client_list, 0);
1870                 for (i = 0; i < count; i++) {
1871                         if (NULL == iter)
1872                                 break;
1873
1874                         data = iter->data;
1875
1876                         if (NULL != data) {
1877                                 SLOG(LOG_INFO, TAG_VCD, "[%dth] pid(%d)", i, data->pid);
1878                                 if (pid == data->pid) {
1879                                         SLOG(LOG_INFO, TAG_VCD, "[INFO] foreground pid (%d)", data->pid);
1880                                         vcd_config_set_foreground(data->pid, true);
1881                                         if (tmp_pid != data->pid) {
1882                                                 SLOG(LOG_INFO, TAG_VCD, "[INFO] foreground pid is different");
1883                                         }
1884                                         return;
1885                                 }
1886                         }
1887                         iter = g_slist_next(iter);
1888                 }
1889         }
1890
1891         widget_info_s *widget_data = NULL;
1892         count = g_slist_length(g_widget_list);
1893
1894         if (0 == count) {
1895                 SLOG(LOG_INFO, TAG_VCD, "No widget");
1896         } else {
1897                 iter = g_slist_nth(g_widget_list, 0);
1898                 for (i = 0; i < count; i++) {
1899                         if (NULL == iter)
1900                                 break;
1901
1902                         widget_data = iter->data;
1903
1904                         if (NULL != widget_data) {
1905                                 SLOG(LOG_INFO, TAG_VCD, "[%dth] pid(%d)", i, widget_data->pid);
1906                                 if (pid == widget_data->pid) {
1907                                         SLOG(LOG_INFO, TAG_VCD, "[INFO] foreground pid (%d)", widget_data->pid);
1908                                         vcd_config_set_foreground(widget_data->pid, true);
1909                                         if (tmp_pid != widget_data->pid) {
1910                                                 SLOG(LOG_INFO, TAG_VCD, "[INFO] foreground pid is changed");
1911                                         }
1912                                         return;
1913                                 }
1914                         }
1915                         iter = g_slist_next(iter);
1916                 }
1917         }
1918
1919         SLOG(LOG_INFO, TAG_VCD, "[INFO] No foreground");
1920         vcd_config_set_foreground(VC_RUNTIME_INFO_NO_FOREGROUND, true);
1921         return;
1922 }