From 8ef3a6e9de6368b5909acefde1ece56421684138 Mon Sep 17 00:00:00 2001 From: Wonnam Jang Date: Mon, 26 Sep 2016 21:36:15 +0900 Subject: [PATCH] Update dialog and api Change-Id: Iae4c6190c631a78e5ea75aaa8c3d546155b99476 Signed-off-by: Wonnam Jang --- client/vc.c | 6 ++-- client/vc_mgr.c | 2 +- common/vc_cmd_db.c | 29 ++++++++++++---- common/vc_cmd_db.h | 6 ++++ common/vc_json_parser.c | 54 +++++++++++++++++++++++++++-- include/voice_control.h | 2 +- include/voice_control_command.h | 14 -------- include/voice_control_command_expand.h | 16 +++++++++ server/vcd_client_data.c | 34 +++++++++++++++++-- server/vcd_client_data.h | 5 +++ server/vcd_server.c | 62 ++++++++++++++++++++++++++++++++-- 11 files changed, 199 insertions(+), 31 deletions(-) diff --git a/client/vc.c b/client/vc.c index 327db61..e6b4de9 100644 --- a/client/vc.c +++ b/client/vc.c @@ -2035,7 +2035,7 @@ int vc_set_invocation_name(const char* name) return ret; } -int vc_dialog(const char* disp_text, const char* utt_text, bool continuous) +int vc_dialog(const char* disp_text, const char* utt_text, bool auto_start) { vc_state_e state; @@ -2072,8 +2072,8 @@ int vc_dialog(const char* disp_text, const char* utt_text, bool continuous) return VC_ERROR_INVALID_STATE; } - SLOG(LOG_DEBUG, TAG_VCC, "Request dialog : pid(%d) disp_text(%s), utt_text(%s), continuous(%d)", getpid(), disp_text, utt_text, continuous); - int ret = vc_dbus_request_dialog(getpid(), disp_text, utt_text, continuous); + SLOG(LOG_DEBUG, TAG_VCC, "Request dialog : pid(%d) disp_text(%s), utt_text(%s), auto_start(%d)", getpid(), disp_text, utt_text, auto_start); + int ret = vc_dbus_request_dialog(getpid(), disp_text, utt_text, auto_start); if (0 != ret) { SLOG(LOG_ERROR, TAG_VCC, "[ERROR] Fail to set foreground (true) : %d", ret); return VC_ERROR_OPERATION_FAILED; diff --git a/client/vc_mgr.c b/client/vc_mgr.c index f7aed98..603e112 100644 --- a/client/vc_mgr.c +++ b/client/vc_mgr.c @@ -2508,7 +2508,7 @@ int __vc_mgr_cb_dialog(int pid, const char* disp_text, const char* utt_text, boo vc_mgr_client_use_callback(g_vc_m); callback(pid, disp_text, utt_text, continuous, user_data); vc_mgr_client_not_use_callback(g_vc_m); - SLOG(LOG_DEBUG, TAG_VCM, "Error callback is called"); + SLOG(LOG_DEBUG, TAG_VCM, "Dialog callback is called"); } else { SLOG(LOG_WARN, TAG_VCM, "[WARNING] Error callback is null"); } diff --git a/common/vc_cmd_db.c b/common/vc_cmd_db.c index 3b627df..0168129 100644 --- a/common/vc_cmd_db.c +++ b/common/vc_cmd_db.c @@ -1167,6 +1167,24 @@ int vc_db_delete_table(const char* table) return VC_DB_ERROR_NONE; } +int vc_db_begin_transaction(void) +{ + int ret = __vc_db_begin_transaction(); + return ret; +} + +int vc_db_rollback_transaction(void) +{ + int ret = __vc_db_rollback_transaction(); + return ret; +} + +int vc_db_commit_transaction(void) +{ + int ret = __vc_db_commit_transaction(); + return ret; +} + static void __vc_db_remove_space(char** string) { if (NULL == string || NULL == *string) @@ -1310,8 +1328,6 @@ int vc_db_insert_command(int pid, vc_cmd_type_e type, vc_cmd_s* cmd) return ret; } - __vc_db_begin_transaction(); - if (0 != g_slist_length(cmd_list)) { GSList *iter = NULL; char* temp_command = NULL; @@ -1333,7 +1349,6 @@ int vc_db_insert_command(int pid, vc_cmd_type_e type, vc_cmd_s* cmd) int ret = __vc_db_insert_commands(pid, type, cmd); if (ret != VC_DB_ERROR_NONE) { - __vc_db_rollback_transaction(); if (NULL != fixed_cmd) { free(fixed_cmd); fixed_cmd = NULL; @@ -1351,7 +1366,6 @@ int vc_db_insert_command(int pid, vc_cmd_type_e type, vc_cmd_s* cmd) ret = __vc_db_insert_commands(pid, type, cmd); if (ret != VC_DB_ERROR_NONE) { - __vc_db_rollback_transaction(); if (NULL != fixed_cmd) { free(fixed_cmd); fixed_cmd = NULL; @@ -1370,8 +1384,6 @@ int vc_db_insert_command(int pid, vc_cmd_type_e type, vc_cmd_s* cmd) cmd_list = NULL; } - __vc_db_commit_transaction(); - if (NULL != fixed_cmd) { free(fixed_cmd); fixed_cmd = NULL; @@ -1390,6 +1402,8 @@ int vc_db_insert_commands_list(int pid, vc_cmd_type_e type, GSList* cmd_list, ch SLOG(LOG_DEBUG, vc_db_tag(), "list count : %d", count); + __vc_db_begin_transaction(); + for (i = 0; i < count; i++) { if (NULL == iter) break; @@ -1408,6 +1422,7 @@ int vc_db_insert_commands_list(int pid, vc_cmd_type_e type, GSList* cmd_list, ch int ret = vc_db_insert_command(pid, type, temp_cmd); if (ret != VC_DB_ERROR_NONE) { SLOG(LOG_ERROR, vc_db_tag(), "Fail to insert command, ret(%d)", ret); + __vc_db_rollback_transaction(); return ret; } } else { @@ -1416,6 +1431,8 @@ int vc_db_insert_commands_list(int pid, vc_cmd_type_e type, GSList* cmd_list, ch iter = g_slist_next(iter); } + __vc_db_commit_transaction(); + return VC_DB_ERROR_NONE; } diff --git a/common/vc_cmd_db.h b/common/vc_cmd_db.h index c8133e7..c0028b6 100644 --- a/common/vc_cmd_db.h +++ b/common/vc_cmd_db.h @@ -55,6 +55,12 @@ int vc_db_create_table(void); int vc_db_delete_table(const char* table); +int vc_db_begin_transaction(void); + +int vc_db_rollback_transaction(void); + +int vc_db_commit_transaction(void); + int vc_db_insert_command(int pid, vc_cmd_type_e type, vc_cmd_s* cmd); int vc_db_insert_commands_list(int pid, vc_cmd_type_e type, GSList* cmd_list, char* invocation_name); diff --git a/common/vc_json_parser.c b/common/vc_json_parser.c index f49d6d6..6d50d51 100644 --- a/common/vc_json_parser.c +++ b/common/vc_json_parser.c @@ -128,6 +128,12 @@ static int __vc_json_set_commands(JsonObject *root_obj, int type, char* invocati } } + ret = vc_db_begin_transaction(); + if (0 != ret) { + SLOG(LOG_ERROR, vc_json_tag(), "[ERROR] Fail to begin transaction for db"); + return ret; + } + for (i = 0; i < array_size; i++) { int temp = 0; const char* temp_text = NULL; @@ -139,6 +145,11 @@ static int __vc_json_set_commands(JsonObject *root_obj, int type, char* invocati free(prev_appid); temp_type = NULL; prev_appid = NULL; + ret = vc_db_rollback_transaction(); + if (0 != ret) { + SLOG(LOG_ERROR, vc_json_tag(), "[ERROR] Fail to begin transaction for db"); + return ret; + } return VC_ERROR_OUT_OF_MEMORY; } @@ -152,6 +163,11 @@ static int __vc_json_set_commands(JsonObject *root_obj, int type, char* invocati temp_type = NULL; prev_appid = NULL; cmd = NULL; + ret = vc_db_rollback_transaction(); + if (0 != ret) { + SLOG(LOG_ERROR, vc_json_tag(), "[ERROR] Fail to begin transaction for db"); + return ret; + } return VC_ERROR_OPERATION_FAILED; } @@ -173,6 +189,11 @@ static int __vc_json_set_commands(JsonObject *root_obj, int type, char* invocati temp_type = NULL; prev_appid = NULL; cmd = NULL; + ret = vc_db_rollback_transaction(); + if (0 != ret) { + SLOG(LOG_ERROR, vc_json_tag(), "[ERROR] Fail to begin transaction for db"); + return ret; + } return VC_ERROR_OUT_OF_MEMORY; } @@ -206,7 +227,11 @@ static int __vc_json_set_commands(JsonObject *root_obj, int type, char* invocati prev_appid = NULL; free(cmd); cmd = NULL; - + ret = vc_db_rollback_transaction(); + if (0 != ret) { + SLOG(LOG_ERROR, vc_json_tag(), "[ERROR] Fail to begin transaction for db"); + return ret; + } return VC_ERROR_OUT_OF_MEMORY; } } else { @@ -239,6 +264,11 @@ static int __vc_json_set_commands(JsonObject *root_obj, int type, char* invocati free(cmd); cmd = NULL; + ret = vc_db_rollback_transaction(); + if (0 != ret) { + SLOG(LOG_ERROR, vc_json_tag(), "[ERROR] Fail to begin transaction for db"); + return ret; + } return VC_ERROR_OUT_OF_MEMORY; } @@ -260,6 +290,11 @@ static int __vc_json_set_commands(JsonObject *root_obj, int type, char* invocati free(cmd); cmd = NULL; + ret = vc_db_rollback_transaction(); + if (0 != ret) { + SLOG(LOG_ERROR, vc_json_tag(), "[ERROR] Fail to begin transaction for db"); + return ret; + } return ret; } @@ -279,7 +314,11 @@ static int __vc_json_set_commands(JsonObject *root_obj, int type, char* invocati free(cmd); cmd = NULL; - + ret = vc_db_rollback_transaction(); + if (0 != ret) { + SLOG(LOG_ERROR, vc_json_tag(), "[ERROR] Fail to begin transaction for db"); + return ret; + } return VC_ERROR_OUT_OF_MEMORY; } } @@ -300,6 +339,11 @@ static int __vc_json_set_commands(JsonObject *root_obj, int type, char* invocati prev_appid = NULL; free(cmd); cmd = NULL; + ret = vc_db_rollback_transaction(); + if (0 != ret) { + SLOG(LOG_ERROR, vc_json_tag(), "[ERROR] Fail to begin transaction for db"); + return ret; + } return ret; } SLOG(LOG_WARN, vc_json_tag(), "[INFO] pid(%d), type(%d), format(%d), domain(%d), cmd(%s), appid(%s)", cmd->pid, type, cmd->format, cmd->domain, cmd->command, cmd->appid); @@ -319,6 +363,12 @@ static int __vc_json_set_commands(JsonObject *root_obj, int type, char* invocati cmd = NULL; } + ret = vc_db_commit_transaction(); + if (0 != ret) { + SLOG(LOG_ERROR, vc_json_tag(), "[ERROR] Fail to commit transaction for db"); + return ret; + } + free(temp_type); free(prev_appid); temp_type = NULL; diff --git a/include/voice_control.h b/include/voice_control.h index ef6cf50..205a39a 100644 --- a/include/voice_control.h +++ b/include/voice_control.h @@ -312,7 +312,7 @@ int vc_set_invocation_name(const char* name); * * @pre The service state should be #VC_SERVICE_STATE_READY. */ -int vc_dialog(const char* disp_text, const char* utt_text, bool continuous); +int vc_dialog(const char* disp_text, const char* utt_text, bool auto_start); /** * @brief Sets command list. diff --git a/include/voice_control_command.h b/include/voice_control_command.h index 188675d..f913caa 100644 --- a/include/voice_control_command.h +++ b/include/voice_control_command.h @@ -459,20 +459,6 @@ int vc_cmd_set_format(vc_cmd_h vc_command, vc_cmd_format_e format); */ int vc_cmd_get_format(vc_cmd_h vc_command, vc_cmd_format_e* format); -/** -* @brief Gets nlu json data. -* @since_tizen 3.0 -* -* @param[in] vc_command The command handle -* @param[out] json The nlu json data -* -* @return 0 on success, otherwise a negative error value -* @retval #VC_ERROR_NONE Successful -* @retval #VC_ERROR_INVALID_PARAMETER Invalid parameter -* @retval #VC_ERROR_NOT_SUPPORTED Not supported feature -* -*/ -int vc_cmd_get_nlu_json(vc_cmd_h vc_cmd, char** json); #ifdef __cplusplus } diff --git a/include/voice_control_command_expand.h b/include/voice_control_command_expand.h index 1e9b1b1..8bd196c 100644 --- a/include/voice_control_command_expand.h +++ b/include/voice_control_command_expand.h @@ -183,6 +183,22 @@ int vc_cmd_get_pid(vc_cmd_h vc_command, int* pid); */ int vc_cmd_set_unfixed_command(vc_cmd_h vc_command, const char* command); +/** +* @brief Gets nlu json data. +* @since_tizen 3.0 +* +* @param[in] vc_command The command handle +* @param[out] json The nlu json data +* +* @return 0 on success, otherwise a negative error value +* @retval #VC_ERROR_NONE Successful +* @retval #VC_ERROR_INVALID_PARAMETER Invalid parameter +* @retval #VC_ERROR_NOT_SUPPORTED Not supported feature +* +*/ +int vc_cmd_get_nlu_json(vc_cmd_h vc_cmd, char** json); + + #ifdef __cplusplus } #endif diff --git a/server/vcd_client_data.c b/server/vcd_client_data.c index d307a13..70f3749 100644 --- a/server/vcd_client_data.c +++ b/server/vcd_client_data.c @@ -14,8 +14,9 @@ * limitations under the License. */ - +#include #include + #include "vcd_client_data.h" #include "vcd_config.h" #include "vcd_main.h" @@ -46,14 +47,26 @@ vc_client_info_s* __client_get_element(int pid); int vcd_client_manager_set(int pid) { - if (-1 != g_manager.pid) { + if (-1 != g_manager.pid && NULL != g_manager.appid) { SLOG(LOG_DEBUG, TAG_VCD, "Manager has already registered"); return -1; } g_manager.pid = pid; g_manager.manager_cmd = false; g_manager.exclusive_cmd_option = false; + g_manager.appid = NULL; + + // Get appid by pid using app control + char* appid = NULL; + int ret = app_manager_get_app_id(pid, &appid); + if (0 != ret || NULL == appid) { + SLOG(LOG_ERROR, TAG_VCD, "[ERROR] fail to get app id, ret(%d), pid(%d)", ret, pid); + return -1; + } + g_manager.appid = strdup(appid); + free(appid); + appid = NULL; return 0; } @@ -66,6 +79,15 @@ int vcd_client_manager_unset() return 0; } +int vcd_client_manager_unset_appid() +{ + if (NULL != g_manager.appid) { + free(g_manager.appid); + g_manager.appid = NULL; + } + return 0; +} + bool vcd_client_manager_is_valid(int pid) { if (-1 == g_manager.pid || pid == g_manager.pid) { @@ -197,6 +219,14 @@ int vcd_client_manager_get_pid() return g_manager.pid; } +int vcd_client_manager_get_appid(char** appid) +{ + if (NULL != g_manager.appid) + *appid = strdup(g_manager.appid); + + return 0; +} + int vcd_client_manager_set_result_text(const char* result) { if (NULL != g_result_text) { diff --git a/server/vcd_client_data.h b/server/vcd_client_data.h index 6985a1f..62f3120 100644 --- a/server/vcd_client_data.h +++ b/server/vcd_client_data.h @@ -54,6 +54,7 @@ typedef struct { typedef struct { int pid; + char* appid; bool manager_cmd; bool exclusive_cmd_option; } manager_info_s; @@ -101,6 +102,8 @@ int vcd_client_manager_set(int pid); int vcd_client_manager_unset(); +int vcd_client_manager_unset_appid(); + bool vcd_client_manager_is_valid(int pid); int vcd_client_manager_set_command(int pid); @@ -117,6 +120,8 @@ int vcd_client_manager_set_exclusive(bool value); int vcd_client_manager_get_pid(); +int vcd_client_manager_get_appid(char** appid); + int vcd_client_manager_set_result_text(const char* result); char* vcd_client_manager_get_result_text(); diff --git a/server/vcd_server.c b/server/vcd_server.c index 95b81f1..843b587 100644 --- a/server/vcd_server.c +++ b/server/vcd_server.c @@ -1036,6 +1036,8 @@ void vcd_finalize() SLOG(LOG_DEBUG, TAG_VCD, "[Server] release engine"); } + vcd_client_manager_unset_appid(); + vcd_config_set_service_state(VCD_STATE_NONE); vcdc_send_service_state(VCD_STATE_NONE); @@ -1854,6 +1856,55 @@ int vcd_server_set_foreground(int pid, bool value) return 0; } +static int __vcd_server_launch_manager_app() +{ + int ret = -1; + bool running = false; + char* appid = NULL; + + ret = vcd_client_manager_get_appid(&appid); + if (0 != ret || NULL == appid) { + SLOG(LOG_ERROR, TAG_VCD, "[ERROR] Fail to get manager appid"); + return VCD_ERROR_OPERATION_FAILED; + } + ret = app_manager_is_running(appid, &running); + if (0 != ret) { + SLOG(LOG_ERROR, TAG_VCD, "[ERROR] Fail to check running with appid(%s)", appid); + free(appid); + appid = NULL; + return VCD_ERROR_OPERATION_FAILED; + } + if (false == running) { + int tmp_ret = __vcd_is_package_installed(appid); + if (false == tmp_ret) { + SLOG(LOG_ERROR, TAG_VCD, "[ERROR] manager app is not installed, appid(%s)", appid); + } else { + ret = __vcd_activate_app_by_appcontrol(appid); + if (0 != ret) { + SLOG(LOG_ERROR, TAG_VCD, "[ERROR] Fail to activate app"); + free(appid); + appid = NULL; + return ret; + } + SLOG(LOG_ERROR, TAG_VCD, "Launch vc manager app: appid(%s)", appid); + } + } else { + ret = __vcd_resume_app(appid); + if (0 != ret) { + SLOG(LOG_ERROR, TAG_VCD, "[ERROR] Fail to resume app"); + free(appid); + appid = NULL; + return ret; + } + SLOG(LOG_ERROR, TAG_VCD, "Resume vc manager app: appid(%s)", appid); + } + + free(appid); + appid = NULL; + + return VCD_ERROR_NONE; +} + int vcd_server_dialog(int pid, const char* disp_text, const char* utt_text, int continuous) { /* check if pid is valid */ @@ -1862,9 +1913,16 @@ int vcd_server_dialog(int pid, const char* disp_text, const char* utt_text, int return VCD_ERROR_INVALID_PARAMETER; } - if (0 != vcdc_send_dialog(vcd_client_manager_get_pid(), pid, disp_text, utt_text, continuous)) { + int ret = __vcd_server_launch_manager_app(); + if (0 != ret){ SLOG(LOG_ERROR, TAG_VCD, "[Server ERROR] Fail to send dialog : mgr_pid(%d), pid(%d), disp_text(%s), utt_text(%s), continue(%d)", vcd_client_manager_get_pid(), pid, disp_text, utt_text, continuous); - return VCD_ERROR_OPERATION_FAILED; + return ret; + } + + ret = vcdc_send_dialog(vcd_client_manager_get_pid(), pid, disp_text, utt_text, continuous); + if (0 != ret) { + SLOG(LOG_ERROR, TAG_VCD, "[Server ERROR] Fail to send dialog : mgr_pid(%d), pid(%d), disp_text(%s), utt_text(%s), continue(%d)", vcd_client_manager_get_pid(), pid, disp_text, utt_text, continuous); + return ret; } return 0; -- 2.7.4