2 * Copyright (c) 2011-2015 Samsung Electronics Co., Ltd All Rights Reserved
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
8 * http://www.apache.org/licenses/LICENSE-2.0
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.
17 #include <app_manager.h>
19 #include <aul_window.h>
21 #include "vcd_client_data.h"
22 #include "vcd_config.h"
25 #include "voice_control_command_expand.h"
28 static GSList* g_client_list = NULL;
30 static GSList* g_widget_list = NULL;
32 static manager_info_s g_manager;
34 /* Manager IPC info */
35 static manager_tidl_info_s* g_mgr_tidl_info = NULL;
38 static GSList* g_widget_tidl_info_list = NULL;
41 static current_commands_list_s g_cur_cmd_list;
43 /* Demandable client list */
44 static GSList* g_demandable_client = NULL;
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;
53 /* Function definitions */
54 widget_info_s* __widget_get_element(int pid);
56 vc_client_info_s* __client_get_element(int pid);
59 int vcd_client_manager_set(int pid)
61 // Get appid by pid using app control
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);
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.");
77 g_manager.manager_cmd = false;
78 g_manager.exclusive_cmd_option = false;
79 g_manager.appid = NULL;
81 g_manager.appid = strdup(appid);
88 int vcd_client_manager_unset()
91 g_manager.manager_cmd = false;
92 g_manager.exclusive_cmd_option = false;
97 int vcd_client_manager_unset_appid()
99 if (NULL != g_manager.appid) {
100 free(g_manager.appid);
101 g_manager.appid = NULL;
106 bool vcd_client_manager_is_valid(int pid)
108 if (-1 == g_manager.pid || pid == g_manager.pid) {
114 int vcd_client_manager_set_command(int pid)
116 if (pid != g_manager.pid) {
117 SLOG(LOG_ERROR, TAG_VCD, "[Client Data ERROR] pid(%d) is NOT valid", pid);
120 g_manager.manager_cmd = true;
124 int vcd_client_manager_unset_command(int pid)
126 if (pid != g_manager.pid) {
127 SLOG(LOG_ERROR, TAG_VCD, "[Client Data ERROR] pid(%d) is NOT valid", pid);
130 g_manager.manager_cmd = false;
134 bool vcd_client_manager_is_system_command_valid(int pid)
136 if (pid != g_manager.pid) {
137 SLOG(LOG_WARN, TAG_VCD, "[Client Data WARNING] pid(%d) is NOT valid", pid);
141 if (true == g_manager.manager_cmd)
147 int vcd_client_manager_set_demandable_client(int pid, GSList* client_list)
149 if (0 != g_slist_length(g_demandable_client)) {
152 vc_demandable_client_s* temp_client;
153 iter = g_slist_nth(g_demandable_client, 0);
155 while (NULL != iter) {
156 temp_client = iter->data;
158 if (NULL != temp_client) {
159 if (NULL != temp_client->appid) free(temp_client->appid);
163 iter = g_slist_next(iter);
165 g_demandable_client = NULL;
168 g_demandable_client = client_list;
173 bool vcd_client_manager_check_demandable_client(int pid)
175 if (0 == g_slist_length(g_demandable_client)) {
176 SLOG(LOG_INFO, TAG_VCD, "[Client Data] All client is available to request start");
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);
185 SLOG(LOG_INFO, TAG_VCD, "[Client Data] daemon(%d) requests start", pid);
190 vc_demandable_client_s* temp_client;
191 iter = g_slist_nth(g_demandable_client, 0);
193 while (NULL != iter) {
194 temp_client = iter->data;
196 if (NULL != temp_client) {
198 SLOG(LOG_DEBUG, TAG_VCD, "[Client Data] demandable appid(%s)", temp_client->appid);
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);
206 if (0 == strlen(appid)) {
207 SLOG(LOG_INFO, TAG_VCD, "[Client Data] pid(%d) is available", pid);
213 iter = g_slist_next(iter);
219 bool vcd_client_manager_get_exclusive()
221 return g_manager.exclusive_cmd_option;
224 int vcd_client_manager_set_exclusive(bool value)
226 g_manager.exclusive_cmd_option = value;
230 int vcd_client_manager_get_pid()
232 return g_manager.pid;
235 int vcd_client_manager_get_appid(char** appid)
237 if (NULL != g_manager.appid)
238 *appid = strdup(g_manager.appid);
243 int vcd_client_manager_set_result_text(const char* result)
245 if (NULL != g_result_text) {
247 g_result_text = NULL;
250 if (NULL != result) {
251 g_result_text = strdup(result);
257 char* vcd_client_manager_get_result_text()
259 return g_result_text;
262 int vcd_client_manager_create_tidl_info(int pid)
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;
271 return VCD_ERROR_NONE;
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;
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;
287 g_mgr_tidl_info->connected = false;
288 g_mgr_tidl_info->connection_requesting = false;
289 g_mgr_tidl_info->rpc_h = NULL;
291 SLOG(LOG_INFO, TAG_VCD, "[Client Data SUCCESS] Add new manager tidl info. pid(%d)", pid);
293 return VCD_ERROR_NONE;
296 int vcd_client_manager_set_tidl_notify_cb(rpc_port_stub_vc_mgr_notify_cb_h callback, void* user_data)
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;
304 ret = rpc_port_stub_vc_mgr_notify_cb_clone(callback, &(g_mgr_tidl_info->notify_cb));
306 SLOG(LOG_ERROR, TAG_VCD, "[Client Data ERROR] Fail to clone notify callback. ret(%d)", ret);
308 SLOG(LOG_INFO, TAG_VCD, "[Client Data] Succeed to clone notify callback. ret(%d)", ret);
310 g_mgr_tidl_info->notify_cb_user_data = user_data;
312 return VCD_ERROR_NONE;
315 int vcd_client_manager_unset_tidl_notify_cb()
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;
323 ret = rpc_port_stub_vc_mgr_notify_cb_destroy(g_mgr_tidl_info->notify_cb);
325 SLOG(LOG_ERROR, TAG_VCD, "[Client Data ERROR] Fail to destroy notify callback. ret(%d)", ret);
327 SLOG(LOG_INFO, TAG_VCD, "[Client Data] Succeed to destroy notify callback. ret(%d)", ret);
329 g_mgr_tidl_info->notify_cb = NULL;
330 g_mgr_tidl_info->notify_cb_user_data = NULL;
332 return VCD_ERROR_NONE;
335 int vcd_client_manager_set_tidl_send_buffer_cb(rpc_port_stub_vc_mgr_send_buffer_cb_h callback, void* user_data)
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;
343 ret = rpc_port_stub_vc_mgr_send_buffer_cb_clone(callback, &(g_mgr_tidl_info->send_buffer_cb));
345 SLOG(LOG_ERROR, TAG_VCD, "[Client Data ERROR] Fail to clone feedback callback. ret(%d)", ret);
347 SLOG(LOG_INFO, TAG_VCD, "[Client Data] Succeed to clone feedback callback. ret(%d)", ret);
349 g_mgr_tidl_info->send_buffer_cb_user_data = user_data;
351 return VCD_ERROR_NONE;
354 int vcd_client_manager_unset_tidl_send_buffer_cb()
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;
362 ret = rpc_port_stub_vc_mgr_send_buffer_cb_destroy(g_mgr_tidl_info->send_buffer_cb);
364 SLOG(LOG_ERROR, TAG_VCD, "[Client Data ERROR] Fail to destroy feedback callback. ret(%d)", ret);
366 SLOG(LOG_INFO, TAG_VCD, "[Client Data] Succeed to destroy feedback callback. ret(%d)", ret);
368 g_mgr_tidl_info->send_buffer_cb = NULL;
369 g_mgr_tidl_info->send_buffer_cb_user_data = NULL;
371 return VCD_ERROR_NONE;
374 int vcd_client_manager_delete_tidl_info()
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;
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");
385 g_mgr_tidl_info->rpc_h = NULL;
386 free(g_mgr_tidl_info);
387 g_mgr_tidl_info = NULL;
392 manager_tidl_info_s* vcd_client_manager_get_tidl_info()
394 return g_mgr_tidl_info;
397 static void __vcd_client_release_each_commands(GSList** cmds)
402 if (0 < g_slist_length(*cmds)) {
403 iter = g_slist_nth(*cmds, 0);
404 while (NULL != iter) {
405 temp_cmd = iter->data;
407 if (NULL != temp_cmd) {
408 if (NULL != temp_cmd->command) {
409 free(temp_cmd->command);
410 temp_cmd->command = NULL;
412 if (NULL != temp_cmd->appid) {
413 free(temp_cmd->appid);
414 temp_cmd->appid = NULL;
416 if (NULL != temp_cmd->parameter) {
417 free(temp_cmd->parameter);
418 temp_cmd->parameter = NULL;
420 if (NULL != temp_cmd->invocation_name) {
421 free(temp_cmd->invocation_name);
422 temp_cmd->invocation_name = NULL;
424 if (NULL != temp_cmd->fixed) {
425 free(temp_cmd->fixed);
426 temp_cmd->fixed = NULL;
431 *cmds = g_slist_remove_link(*cmds, iter);
433 iter = g_slist_nth(*cmds, 0);
439 int __vcd_client_release_commands()
441 g_cur_cmd_list.total_cmd_count = 0;
442 g_cur_cmd_list.foreground = VC_NO_FOREGROUND_PID;
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));
454 int vcd_client_command_collect_command()
456 /* 1. Get foreground pid */
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 */
464 SLOG(LOG_INFO, TAG_VCD, "[Client Data] Foreground pid(%d)", fg_pid);
466 /* 2. Clean up command list */
467 __vcd_client_release_commands();
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");
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);
477 SLOG(LOG_ERROR, TAG_VCD, "[Client Data ERROR] Fail to get the system command list");
479 g_cur_cmd_list.exclusive_system_cmds = ex_sys_cmd_list;
482 SLOG(LOG_INFO, TAG_VCD, "[Client Data] No exclusive system commands");
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);
493 SLOG(LOG_ERROR, TAG_VCD, "[Client Data ERROR] Fail to get the system command list");
495 g_cur_cmd_list.system_cmds = sys_cmd_list;
498 SLOG(LOG_INFO, TAG_VCD, "[Client Data] No system commands");
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);
505 SLOG(LOG_ERROR, TAG_VCD, "[Client Data ERROR] Fail to get the system command list");
507 g_cur_cmd_list.system_background_cmds = sys_back_cmd_list;
510 SLOG(LOG_INFO, TAG_VCD, "[Client Data] No system background commands");
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;
518 g_cur_cmd_list.foreground = fg_pid;
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);
527 SLOG(LOG_ERROR, TAG_VCD, "[Client Data ERROR] Fail to get the WIDGET command list");
529 g_cur_cmd_list.widget_cmds = widget_cmd_list;
533 SLOG(LOG_INFO, TAG_VCD, "[Client Data] No widget commands");
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);
540 SLOG(LOG_ERROR, TAG_VCD, "[Client Data ERROR] Fail to get the fg command list");
542 g_cur_cmd_list.foreground_cmds = fg_cmd_list;
546 SLOG(LOG_INFO, TAG_VCD, "[Client Data] No foreground app");
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);
552 SLOG(LOG_INFO, TAG_VCD, "[Client Data] No foreground commands of manager app");
554 g_cur_cmd_list.foreground_cmds = fg_cmd_list;
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);
563 SLOG(LOG_ERROR, TAG_VCD, "[Client Data ERROR] Fail to get the bg command list");
565 /* Add item to global command list */
566 g_cur_cmd_list.background_cmds = bg_cmd_list;
572 int vcd_client_get_length()
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);
582 g_cur_cmd_list.total_cmd_count = command_count;
584 SLOG(LOG_INFO, TAG_VCD, "[Client Data] Command count : %d ", g_cur_cmd_list.total_cmd_count);
585 return command_count;
588 int vcd_client_foreach_command(client_foreach_command_cb callback, void* user_data)
590 if (NULL == callback) {
591 SLOG(LOG_ERROR, TAG_VCD, "[Client Data ERROR] input parameter is NULL");
592 return VCD_ERROR_INVALID_PARAMETER;
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;
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;
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;
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);
617 callback(temp_cmd->id, temp_cmd->type, temp_cmd->format, temp_cmd->command, temp_cmd->parameter, temp_cmd->domain, user_data);
619 iter = g_slist_next(iter);
622 SLOG(LOG_INFO, TAG_VCD, "[Client Data] No widget commands");
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;
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);
633 callback(temp_cmd->id, temp_cmd->type, temp_cmd->format, temp_cmd->command, temp_cmd->parameter, temp_cmd->domain, user_data);
635 iter = g_slist_next(iter);
638 SLOG(LOG_INFO, TAG_VCD, "[Client Data] No foreground commands");
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;
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);
649 callback(temp_cmd->id, temp_cmd->type, temp_cmd->format, temp_cmd->command, temp_cmd->parameter, temp_cmd->domain, user_data);
651 iter = g_slist_next(iter);
654 SLOG(LOG_INFO, TAG_VCD, "[Client Data] No system commands");
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;
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);
665 callback(temp_cmd->id, temp_cmd->type, temp_cmd->format, temp_cmd->command, temp_cmd->parameter, temp_cmd->domain, user_data);
667 iter = g_slist_next(iter);
670 SLOG(LOG_INFO, TAG_VCD, "[Client Data] No system background commands");
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;
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);
681 callback(temp_cmd->id, temp_cmd->type, temp_cmd->format, temp_cmd->command, temp_cmd->parameter, temp_cmd->domain, user_data);
683 iter = g_slist_next(iter);
686 SLOG(LOG_INFO, TAG_VCD, "[Client Data] No exclusive system commands");
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;
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);
697 callback(temp_cmd->id, temp_cmd->type, temp_cmd->format, temp_cmd->command, temp_cmd->parameter, temp_cmd->domain, user_data);
699 iter = g_slist_next(iter);
702 SLOG(LOG_INFO, TAG_VCD, "[Client Data] No background commands");
707 static vc_cmd_s* __command_copy(vc_cmd_s* src_cmd)
709 if (NULL == src_cmd) {
710 SLOG(LOG_WARN, TAG_VCD, "[Client Data] Input command is NULL");
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");
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;
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;
735 if (NULL != src_cmd->command) {
736 temp_cmd->command = strdup(src_cmd->command);
739 if (NULL != src_cmd->parameter) {
740 temp_cmd->parameter = strdup(src_cmd->parameter);
743 if (NULL != src_cmd->appid) {
744 temp_cmd->appid = strdup(src_cmd->appid);
747 if (NULL != src_cmd->invocation_name) {
748 temp_cmd->invocation_name = strdup(src_cmd->invocation_name);
751 if (NULL != src_cmd->fixed) {
752 temp_cmd->fixed = strdup(src_cmd->fixed);
755 temp_cmd->key = src_cmd->key;
756 temp_cmd->modifier = src_cmd->modifier;
761 int vcd_client_get_cmd_from_result_id(int result_id, vc_cmd_s** result)
766 SLOG(LOG_INFO, TAG_VCD, "[Client Data] Result id(%d)", result_id);
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;
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); */
778 *result = __command_copy(temp_cmd);
783 iter = g_slist_next(iter);
786 SLOG(LOG_INFO, TAG_VCD, "[Client Data] No widget commands");
789 if (0 < g_slist_length(g_cur_cmd_list.foreground_cmds)) {
790 iter = g_slist_nth(g_cur_cmd_list.foreground_cmds, 0);
792 while (NULL != iter) {
793 temp_cmd = iter->data;
795 SLOG(LOG_DEBUG, TAG_VCD, "[Client Data] command id (%d)", temp_cmd->id);
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); */
802 *result = __command_copy(temp_cmd);
806 iter = g_slist_next(iter);
809 SLOG(LOG_INFO, TAG_VCD, "[Client Data] No foreground commands");
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;
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); */
822 *result = __command_copy(temp_cmd);
826 iter = g_slist_next(iter);
829 SLOG(LOG_INFO, TAG_VCD, "[Client Data] No system commands");
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;
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); */
842 *result = __command_copy(temp_cmd);
846 iter = g_slist_next(iter);
849 SLOG(LOG_INFO, TAG_VCD, "[Client Data] No system background commands");
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;
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); */
862 *result = __command_copy(temp_cmd);
866 iter = g_slist_next(iter);
869 SLOG(LOG_INFO, TAG_VCD, "[Client Data] No exclusive system commands");
872 if (0 < g_slist_length(g_cur_cmd_list.background_cmds)) {
873 iter = g_slist_nth(g_cur_cmd_list.background_cmds, 0);
875 while (NULL != iter) {
876 temp_cmd = iter->data;
878 SLOG(LOG_DEBUG, TAG_VCD, "[Client Data] command id (%d)", temp_cmd->id);
880 if (result_id == temp_cmd->id) {
881 *result = __command_copy(temp_cmd);
885 iter = g_slist_next(iter);
888 SLOG(LOG_INFO, TAG_VCD, "[Client Data] No background commands");
891 SLOG(LOG_ERROR, TAG_VCD, "[Client Data ERROR] Not find matched result");
895 int vcd_client_set_slience_detection(bool value)
897 g_silence_detection = value;
901 bool vcd_client_get_slience_detection()
903 return g_silence_detection;
906 int vcd_client_set_recognition_mode(vcd_recognition_mode_e mode)
908 g_recognition_mode = mode;
912 vcd_recognition_mode_e vcd_client_get_recognition_mode()
914 return g_recognition_mode;
917 int vcd_client_set_server_dialog(int pid, bool is_server_dialog)
919 vc_client_info_s* client_info = NULL;
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;
927 client_info->server_dialog = is_server_dialog;
929 SLOG(LOG_INFO, TAG_VCD, "[Client Data] Set server dialog, client pid(%d), server_dialog(%d)", pid, client_info->server_dialog);
933 int vcd_client_get_server_dialog(int pid, bool* is_server_dialog)
935 vc_client_info_s* client_info = NULL;
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;
943 *is_server_dialog = client_info->server_dialog;
945 SLOG(LOG_INFO, TAG_VCD, "[Client Data] Get server dialog, client pid(%d), server_dialog(%d)", pid, *is_server_dialog);
949 int vcd_client_append_cmd_from_type(int type, vc_cmd_list_h list)
954 SLOG(LOG_ERROR, TAG_VCD, "[ERROR] Invalid list parameter");
955 return VCD_ERROR_INVALID_PARAMETER;
959 case VC_COMMAND_TYPE_SYSTEM:
960 item = g_cur_cmd_list.system_cmds;
962 case VC_COMMAND_TYPE_FOREGROUND:
963 item = g_cur_cmd_list.foreground_cmds;
965 case VC_COMMAND_TYPE_WIDGET:
966 item = g_cur_cmd_list.widget_cmds;
968 case VC_COMMAND_TYPE_SYSTEM_BACKGROUND:
969 item = g_cur_cmd_list.system_background_cmds;
971 case VC_COMMAND_TYPE_BACKGROUND:
972 item = g_cur_cmd_list.background_cmds;
974 case VC_COMMAND_TYPE_EXCLUSIVE:
975 item = g_cur_cmd_list.exclusive_system_cmds;
978 SLOG(LOG_ERROR, TAG_VCD, "[ERROR] Invalid type parameter");
979 return VCD_ERROR_INVALID_PARAMETER;
982 while (NULL != item) {
983 vc_cmd_h temp_cmd = NULL;
984 vc_cmd_h target_cmd = (vc_cmd_h)item->data;
986 temp_cmd = (vc_cmd_h)__command_copy((vc_cmd_s*)target_cmd);
988 if (NULL == temp_cmd) {
989 SLOG(LOG_ERROR, TAG_VCD, "[ERROR] Fail to copy the command");
990 return VCD_ERROR_OUT_OF_MEMORY;
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);
1000 return VCD_ERROR_OPERATION_FAILED;
1009 int __show_client_list()
1011 GSList *iter = NULL;
1012 vc_client_info_s *data = NULL;
1014 SLOG(LOG_DEBUG, TAG_VCD, "@@@ client list");
1016 int count = g_slist_length(g_client_list);
1020 SLOG(LOG_DEBUG, TAG_VCD, "No Client");
1022 iter = g_slist_nth(g_client_list, 0);
1023 for (i = 0; i < count; i++) {
1030 SLOG(LOG_DEBUG, TAG_VCD, "[%dth] pid(%d)", i, data->pid);
1032 iter = g_slist_next(iter);
1036 SLOG(LOG_DEBUG, TAG_VCD, "@@@");
1038 SLOG(LOG_DEBUG, TAG_VCD, "@@@ widget list");
1040 widget_info_s *widget_data = NULL;
1042 count = g_slist_length(g_widget_list);
1045 SLOG(LOG_DEBUG, TAG_VCD, "No widget");
1047 iter = g_slist_nth(g_widget_list, 0);
1048 for (i = 0; i < count; i++) {
1052 widget_data = iter->data;
1054 if (NULL != widget_data) {
1055 SLOG(LOG_DEBUG, TAG_VCD, "[%dth] pid(%d)", i, widget_data->pid);
1057 iter = g_slist_next(iter);
1061 SLOG(LOG_DEBUG, TAG_VCD, "@@@");
1066 int __show_command_list(GSList* cmd_group)
1068 GSList *iter = NULL;
1069 vc_cmd_s *data = NULL;
1071 SLOG(LOG_DEBUG, TAG_VCD, "@@@ command group");
1073 int count = g_slist_length(cmd_group);
1077 SLOG(LOG_DEBUG, TAG_VCD, "No command");
1079 iter = g_slist_nth(cmd_group, 0);
1080 for (i = 0; i < count; i++) {
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);
1089 SLOG(LOG_DEBUG, TAG_VCD, "[%dth] command(%s) key(%d)", i, data->command, data->key);
1092 iter = g_slist_next(iter);
1096 SLOG(LOG_DEBUG, TAG_VCD, "@@@");
1101 GSList* __client_get_item(const int pid)
1103 GSList *iter = NULL;
1104 vc_client_info_s *data = NULL;
1106 int count = g_slist_length(g_client_list);
1110 iter = g_slist_nth(g_client_list, 0);
1111 for (i = 0; i < count; i++) {
1117 if (pid == data->pid)
1121 iter = g_slist_next(iter);
1128 vc_client_info_s* __client_get_element(int pid)
1130 GSList *iter = NULL;
1131 vc_client_info_s *data = NULL;
1133 int count = g_slist_length(g_client_list);
1137 iter = g_slist_nth(g_client_list, 0);
1138 for (i = 0; i < count; i++) {
1145 if (pid == data->pid)
1149 iter = g_slist_next(iter);
1156 int vcd_client_add(int pid)
1158 /*Check pid is duplicated*/
1160 tmp = __client_get_item(pid);
1163 SLOG(LOG_WARN, TAG_VCD, "[Client Data] Client pid is already registered");
1164 return VCD_ERROR_INVALID_PARAMETER;
1167 vc_client_info_s *info = (vc_client_info_s*)calloc(1, sizeof(vc_client_info_s));
1169 SLOG(LOG_ERROR, TAG_VCD, "[ERROR] Fail to allocate memory");
1170 return VCD_ERROR_OUT_OF_MEMORY;
1175 info->fg_cmd = false;
1176 info->bg_cmd = false;
1177 info->exclusive_cmd = false;
1178 info->server_dialog = false;
1180 /* Add item to global list */
1181 g_client_list = g_slist_append(g_client_list, info);
1183 if (NULL == g_client_list) {
1184 SLOG(LOG_ERROR, TAG_VCD, "[Client Data ERROR] Fail to add new client");
1191 SLOG(LOG_INFO, TAG_VCD, "[Client Data SUCCESS] Add new client");
1194 #ifdef CLIENT_DATA_DEBUG
1195 __show_client_list();
1200 int vcd_client_delete(int pid)
1203 vc_client_info_s* client_info = NULL;
1206 tmp = __client_get_item(pid);
1208 SLOG(LOG_ERROR, TAG_VCD, "[Client Data ERROR] pid(%d) is NOT valid", pid);
1209 return VCD_ERROR_INVALID_PARAMETER;
1212 /*Free client structure*/
1213 client_info = tmp->data;
1214 if (NULL != client_info) {
1218 /*Remove handle from list*/
1219 g_client_list = g_slist_remove_link(g_client_list, tmp);
1222 #ifdef CLIENT_DATA_DEBUG
1223 __show_client_list();
1229 bool vcd_client_is_available(int pid)
1231 vc_client_info_s* client_info = NULL;
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);
1242 int vcd_client_get_ref_count()
1246 count = g_slist_length(g_client_list) + g_slist_length(g_widget_list);
1247 if (0 < g_manager.pid) {
1251 SLOG(LOG_INFO, TAG_VCD, "[Client Data] client count : %d", count);
1256 int vcd_client_get_list(int** pids, int* pid_count)
1258 if (NULL == pids || NULL == pid_count)
1261 int count = g_slist_length(g_client_list);
1267 tmp = (int*)calloc(count, sizeof(int));
1269 SLOG(LOG_ERROR, TAG_VCD, "[ERROR] Fail to allocate memory");
1270 return VCD_ERROR_OUT_OF_MEMORY;
1273 GSList *iter = NULL;
1274 vc_client_info_s *data = NULL;
1277 iter = g_slist_nth(g_client_list, 0);
1279 while (NULL != iter) {
1286 iter = g_slist_next(iter);
1296 int vcd_client_set_command_type(int pid, int type)
1298 vc_client_info_s* client_info = NULL;
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;
1307 case VC_COMMAND_TYPE_FOREGROUND:
1308 client_info->fg_cmd = true;
1310 case VC_COMMAND_TYPE_BACKGROUND:
1311 client_info->bg_cmd = true;
1314 SLOG(LOG_ERROR, TAG_VCD, "[Client Data ERROR] not supported command type(%d)", type);
1321 int vcd_client_unset_command_type(int pid, int type)
1323 vc_client_info_s* client_info = NULL;
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;
1332 case VC_COMMAND_TYPE_FOREGROUND:
1333 client_info->fg_cmd = false;
1335 case VC_COMMAND_TYPE_BACKGROUND:
1336 client_info->bg_cmd = false;
1339 SLOG(LOG_ERROR, TAG_VCD, "[Client Data ERROR] not supported command type(%d)", type);
1346 int vcd_client_set_exclusive_command(int pid)
1348 vc_client_info_s* client_info = NULL;
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;
1356 client_info->exclusive_cmd = true;
1361 int vcd_client_unset_exclusive_command(int pid)
1363 vc_client_info_s* client_info = NULL;
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;
1371 client_info->exclusive_cmd = false;
1376 int vcd_client_save_client_info()
1378 if (0 != vc_info_parser_set_client_info(g_client_list)) {
1379 SLOG(LOG_ERROR, TAG_VCD, "[ERROR] Fail to save client info");
1387 * Functions for widget
1389 GSList* __widget_get_item(int pid)
1391 GSList *iter = NULL;
1392 widget_info_s *data = NULL;
1394 int count = g_slist_length(g_widget_list);
1398 iter = g_slist_nth(g_widget_list, 0);
1399 for (i = 0; i < count; i++) {
1406 if (pid == data->pid)
1410 iter = g_slist_next(iter);
1417 widget_info_s* __widget_get_element(int pid)
1419 GSList *iter = NULL;
1420 widget_info_s *data = NULL;
1422 int count = g_slist_length(g_widget_list);
1426 iter = g_slist_nth(g_widget_list, 0);
1429 while (iter && i < count) {
1433 if (pid == data->pid)
1437 iter = g_slist_next(iter);
1446 int vcd_client_widget_get_list(int** pids, int* pid_count)
1448 if (NULL == pids || NULL == pid_count)
1451 int count = g_slist_length(g_widget_list);
1457 tmp = (int*)calloc(count, sizeof(int));
1459 SLOG(LOG_ERROR, TAG_VCD, "[ERROR] Fail to allocate memory");
1460 return VCD_ERROR_OUT_OF_MEMORY;
1463 GSList *iter = NULL;
1464 widget_info_s *data = NULL;
1467 iter = g_slist_nth(g_widget_list, 0);
1468 while (NULL != iter) {
1475 iter = g_slist_next(iter);
1485 int vcd_client_widget_add(int pid)
1487 /*Check pid is duplicated*/
1489 tmp = __widget_get_item(pid);
1492 SLOG(LOG_WARN, TAG_VCD, "[Client Data] widget pid is already registered");
1493 return VCD_ERROR_INVALID_PARAMETER;
1496 widget_info_s *info = (widget_info_s*)calloc(1, sizeof(widget_info_s));
1498 SLOG(LOG_ERROR, TAG_VCD, "[ERROR] Fail to allocate memory");
1499 return VCD_ERROR_OUT_OF_MEMORY;
1503 info->widget_cmd = false;
1505 /* Add item to global list */
1506 g_widget_list = g_slist_append(g_widget_list, info);
1508 if (NULL == g_widget_list) {
1509 SLOG(LOG_ERROR, TAG_VCD, "[Client Data ERROR] Fail to add new widget");
1516 SLOG(LOG_INFO, TAG_VCD, "[Client Data SUCCESS] Add new widget");
1519 #ifdef CLIENT_DATA_DEBUG
1520 __show_client_list();
1525 int vcd_client_widget_delete(int pid)
1528 widget_info_s* widget_info = NULL;
1531 tmp = __widget_get_item(pid);
1533 SLOG(LOG_ERROR, TAG_VCD, "[Client Data ERROR] pid(%d) is NOT valid", pid);
1534 return VCD_ERROR_INVALID_PARAMETER;
1537 /*Free client structure*/
1538 widget_info = tmp->data;
1539 if (NULL != widget_info) {
1543 /*Remove handle from list*/
1544 g_widget_list = g_slist_remove_link(g_widget_list, tmp);
1547 #ifdef CLIENT_DATA_DEBUG
1548 __show_client_list();
1554 int vcd_client_widget_get_foreground_pid()
1556 /* 1. Get foreground pid */
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 */
1563 widget_info_s* widget = NULL;
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");
1575 bool vcd_client_widget_is_available(int pid)
1577 widget_info_s* widget_info = NULL;
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);
1588 int vcd_client_widget_set_command(int pid)
1590 widget_info_s *info = NULL;
1591 info = __widget_get_element(pid);
1593 SLOG(LOG_ERROR, TAG_VCD, "[Client Data ERROR] pid(%d) is NOT valid", pid);
1594 return VCD_ERROR_INVALID_PARAMETER;
1597 info->widget_cmd = true;
1602 int vcd_client_widget_unset_command(int pid)
1604 widget_info_s *info = NULL;
1605 info = __widget_get_element(pid);
1607 SLOG(LOG_ERROR, TAG_VCD, "[Client Data ERROR] pid(%d) is NOT valid", pid);
1608 return VCD_ERROR_INVALID_PARAMETER;
1611 info->widget_cmd = false;
1616 int vcd_client_widget_set_asr_result_enabled(int pid, bool enable)
1618 widget_info_s *info = NULL;
1619 info = __widget_get_element(pid);
1621 SLOG(LOG_ERROR, TAG_VCD, "[Client Data ERROR] pid(%d) is NOT valid", pid);
1622 return VCD_ERROR_INVALID_PARAMETER;
1625 info->asr_result_enabled = enable;
1630 int vcd_client_widget_get_asr_result_enabled(int pid, bool* enable)
1632 widget_info_s *info = NULL;
1633 info = __widget_get_element(pid);
1635 SLOG(LOG_ERROR, TAG_VCD, "[Client Data ERROR] pid(%d) is NOT valid", pid);
1636 return VCD_ERROR_INVALID_PARAMETER;
1639 *enable = info->asr_result_enabled;
1644 int vcd_client_widget_set_waiting_for_recording(int pid, bool waiting)
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);
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);
1658 int vcd_client_widget_get_waiting_for_recording(int pid, bool* waiting)
1660 if (pid != g_waiting_recording_pid) {
1661 SLOG(LOG_ERROR, TAG_VCD, "[Client Data ERROR] pid(%d) is NOT waiting pid", pid);
1665 *waiting = g_is_waiting_recording;
1666 SLOG(LOG_ERROR, TAG_VCD, "[INFO] Success to get waiting for recording, waiting(%d)", *waiting);
1670 GSList* __get_widget_tidl_info_item(const int pid)
1672 GSList *iter = NULL;
1673 widget_tidl_info_s *data = NULL;
1675 int count = g_slist_length(g_widget_tidl_info_list);
1679 iter = g_slist_nth(g_widget_tidl_info_list, 0);
1680 for (i = 0; i < count; i++) {
1686 if (pid == data->pid)
1690 iter = g_slist_next(iter);
1697 widget_tidl_info_s* __get_widget_tidl_info_element(int pid)
1699 GSList *iter = NULL;
1700 widget_tidl_info_s *data = NULL;
1702 int count = g_slist_length(g_widget_tidl_info_list);
1706 iter = g_slist_nth(g_widget_tidl_info_list, 0);
1707 for (i = 0; i < count; i++) {
1714 if (pid == data->pid)
1718 iter = g_slist_next(iter);
1725 int vcd_client_widget_add_tidl_info(int pid)
1727 /*Check pid is duplicated*/
1728 widget_tidl_info_s* info = NULL;
1729 info = __get_widget_tidl_info_element(pid);
1732 SLOG(LOG_WARN, TAG_VCD, "[Client Data] Widget tidl info pid is already registered");
1733 return VCD_ERROR_NONE;
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));
1739 SLOG(LOG_ERROR, TAG_VCD, "[ERROR] Fail to allocate memory");
1740 return VCD_ERROR_OUT_OF_MEMORY;
1744 info->notify_cb = NULL;
1745 info->notify_cb_user_data = NULL;
1747 info->connected = false;
1748 info->connection_requesting = false;
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");
1760 SLOG(LOG_INFO, TAG_VCD, "[Client Data SUCCESS] Add new widget tidl info. pid(%d)", pid);
1763 return VCD_ERROR_NONE;
1766 int vcd_client_widget_set_tidl_notify_cb(int pid, rpc_port_stub_vc_widget_notify_cb_h callback, void* user_data)
1769 widget_tidl_info_s* info = NULL;
1770 info = __get_widget_tidl_info_element(pid);
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;
1778 ret = rpc_port_stub_vc_widget_notify_cb_clone(callback, &(info->notify_cb));
1780 SLOG(LOG_ERROR, TAG_VCD, "[Client Data ERROR] Fail to clone notify callback. ret(%d)", ret);
1782 SLOG(LOG_INFO, TAG_VCD, "[Client Data] Succeed to clone notify callback. ret(%d)", ret);
1784 info->notify_cb_user_data = user_data;
1786 return VCD_ERROR_NONE;
1789 int vcd_client_widget_unset_tidl_notify_cb(int pid)
1792 widget_tidl_info_s* info = NULL;
1793 info = __get_widget_tidl_info_element(pid);
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;
1801 ret = rpc_port_stub_vc_widget_notify_cb_destroy(info->notify_cb);
1803 SLOG(LOG_ERROR, TAG_VCD, "[Client Data ERROR] Fail to destroy notify callback. ret(%d)", ret);
1805 SLOG(LOG_INFO, TAG_VCD, "[Client Data] Succeed to destroy notify callback. ret(%d)", ret);
1807 info->notify_cb = NULL;
1808 info->notify_cb_user_data = NULL;
1810 return VCD_ERROR_NONE;
1813 int vcd_client_widget_delete_tidl_info(int pid)
1816 widget_tidl_info_s* widget_tidl_info = NULL;
1819 tmp = __get_widget_tidl_info_item(pid);
1821 SLOG(LOG_ERROR, TAG_VCD, "[Client Data ERROR] pid(%d) is NOT valid", pid);
1822 return VCD_ERROR_INVALID_PARAMETER;
1825 /*Free widget structure*/
1826 widget_tidl_info = tmp->data;
1827 if (NULL != widget_tidl_info) {
1828 free(widget_tidl_info);
1831 /*Remove handle from list*/
1832 g_widget_tidl_info_list = g_slist_remove_link(g_widget_tidl_info_list, tmp);
1837 widget_tidl_info_s* vcd_client_widget_get_tidl_info(int pid)
1839 return __get_widget_tidl_info_element(pid);
1842 GSList* vcd_client_widget_get_tidl_info_list()
1844 return g_widget_tidl_info_list;
1848 void vcd_client_update_foreground_pid()
1850 int tmp_pid = VC_RUNTIME_INFO_NO_FOREGROUND;
1851 vcd_config_get_foreground(&tmp_pid);
1853 int pid = VC_RUNTIME_INFO_NO_FOREGROUND;
1854 int ret = aul_window_get_focused_pid(&pid);
1856 SLOG(LOG_ERROR, TAG_VCD, "[Client Data ERROR] Fail to get focused pid, ret(%d)", ret);
1858 SLOG(LOG_INFO, TAG_VCD, "[INFO] Foreground pid (%d), Focused pid (%d)", tmp_pid, pid);
1860 GSList *iter = NULL;
1861 vc_client_info_s *data = NULL;
1863 int count = g_slist_length(g_client_list);
1867 SLOG(LOG_INFO, TAG_VCD, "No Client");
1869 iter = g_slist_nth(g_client_list, 0);
1870 for (i = 0; i < count; i++) {
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");
1887 iter = g_slist_next(iter);
1891 widget_info_s *widget_data = NULL;
1892 count = g_slist_length(g_widget_list);
1895 SLOG(LOG_INFO, TAG_VCD, "No widget");
1897 iter = g_slist_nth(g_widget_list, 0);
1898 for (i = 0; i < count; i++) {
1902 widget_data = iter->data;
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");
1915 iter = g_slist_next(iter);
1919 SLOG(LOG_INFO, TAG_VCD, "[INFO] No foreground");
1920 vcd_config_set_foreground(VC_RUNTIME_INFO_NO_FOREGROUND, true);