From 5516f0e1c967793756af7d6a49c7743ab74c4758 Mon Sep 17 00:00:00 2001 From: Ji-hoon Lee Date: Wed, 11 Sep 2019 18:51:30 +0900 Subject: [PATCH] Send preprocessing information when activating assistants Change-Id: If9a4080f58fafad4732d2d5a2dfbfc56221eba84 --- inc/multi_assistant_main.h | 1 + src/multi_assistant_dbus.c | 65 ++++++++++++++++++++++++++++++++++++ src/multi_assistant_dbus.h | 2 ++ src/multi_assistant_service.c | 46 ++++++++++++++++++------- src/multi_assistant_service_plugin.c | 1 + 5 files changed, 103 insertions(+), 12 deletions(-) diff --git a/inc/multi_assistant_main.h b/inc/multi_assistant_main.h index 6a40549..4ca15c0 100644 --- a/inc/multi_assistant_main.h +++ b/inc/multi_assistant_main.h @@ -74,6 +74,7 @@ #define MAS_METHOD_STREAMING_AUDIO_DATA "mas_method_streaming_audio_data" #define MAS_METHOD_WAKEUP_ENGINE_COMMAND "mas_method_wakeup_engine_command" #define MAS_METHOD_ERROR "mas_method_error" +#define MAS_METHOD_SEND_PREPROCESSING_INFORMATION "mas_method_send_preprocessing_information" #define MAS_UI_METHOD_SEND_ASR_RESULT "mas_ui_method_send_asr_result" #define MAS_UI_METHOD_SEND_RESULT "mas_ui_method_send_result" diff --git a/src/multi_assistant_dbus.c b/src/multi_assistant_dbus.c index 4da5cef..0ca4dec 100644 --- a/src/multi_assistant_dbus.c +++ b/src/multi_assistant_dbus.c @@ -276,6 +276,71 @@ int masc_dbus_active_state_change(int pid, int state) return 0; } +int masc_dbus_send_preprocessing_information(int pid, const char* app_id) +{ + if (0 != __dbus_check()) { + return -1; //MAS_ERROR_OPERATION_FAILED; + } + + DBusMessage* msg; + + DBusError err; + dbus_error_init(&err); + + char service_name[64]; + memset(service_name, '\0', 64); + snprintf(service_name, 64, "%s_%d", MA_CLIENT_SERVICE_NAME, pid); + + msg = dbus_message_new_method_call( + service_name, + MA_CLIENT_SERVICE_OBJECT_PATH, + MA_CLIENT_SERVICE_INTERFACE, + MAS_METHOD_SEND_PREPROCESSING_INFORMATION); + + static int count = 0; + if (NULL == msg) { + MAS_LOGE(">>>> Request mas send preprocessing assistant information : Fail to make message"); + return -1; // MAS_ERROR_OPERATION_FAILED; + } else { + MAS_LOGD(">>>> Request mas send preprocessing assistant information : %s", service_name); + } + + char* temp_app_id = NULL; + if (!app_id) + temp_app_id = strdup("#NULL"); + else + temp_app_id = strdup(app_id); + + if (true != dbus_message_append_args(msg, + DBUS_TYPE_STRING, &temp_app_id, + DBUS_TYPE_INVALID)) { + dbus_message_unref(msg); + MAS_LOGE("[ERROR] Fail to append args"); + if (temp_app_id) + free(temp_app_id); + return -1; + } + + dbus_message_set_no_reply(msg, TRUE); + + if (1 != dbus_connection_send(g_conn_sender, msg, NULL)) { + MAS_LOGE("[Dbus ERROR] Fail to Send"); + if (temp_app_id) + free(temp_app_id); + return -1; // MAS_ERROR_OPERATION_FAILED; + } else { + MAS_LOGD("[Dbus DEBUG] Success to Send preprocessing assistant information : %s", app_id); + dbus_connection_flush(g_conn_sender); + } + + dbus_message_unref(msg); + + if (temp_app_id) + free(temp_app_id); + + return 0; +} + int masc_ui_dbus_send_hello(void) { if (0 != __dbus_check()) { diff --git a/src/multi_assistant_dbus.h b/src/multi_assistant_dbus.h index d28c716..47091bf 100644 --- a/src/multi_assistant_dbus.h +++ b/src/multi_assistant_dbus.h @@ -33,6 +33,8 @@ int masc_dbus_send_streaming_audio_data(int pid, int event, unsigned char* data, int masc_dbus_active_state_change(int pid, int state); +int masc_dbus_send_preprocessing_information(int pid, const char* app_id); + int masc_ui_dbus_send_hello(void); int masc_ui_dbus_send_asr_result(int pid, int event, char* asr_result); diff --git a/src/multi_assistant_service.c b/src/multi_assistant_service.c index 49c784b..e2f4db0 100644 --- a/src/multi_assistant_service.c +++ b/src/multi_assistant_service.c @@ -39,6 +39,7 @@ static const char *g_current_lang = "en_US"; #define MULTI_ASSISTANT_SETTINGS_ACTIVATED "db/multi-assistant/activated" #define WAKEUP_SETTINGS_KEY_DEFAULT_ASSISTANT_APPID "db/multi-assistant/default_assistant_appid" +#define WAKEUP_SETTINGS_KEY_PREPROCESSING_ASSISTANT_APPID "db/multi-assistant/preprocessing_assistant_appid" #define WAKEUP_SETTINGS_KEY_PRELAUNCH_MODE "db/multi-assistant/prelaunch_mode" #define MAX_MACLIENT_INFO_NUM 16 @@ -196,6 +197,7 @@ int mas_client_initialize(int pid) if (g_wakeup_maclient_appid && strncmp(g_wakeup_maclient_appid, appid, MAX_APPID_LEN) == 0) { g_wakeup_maclient_appid = NULL; + mas_client_send_preprocessing_information(pid); mas_client_activate(pid); } else { MAS_LOGE("[ERROR] g_wakeup_maclient_appid and appid differ : %s %s", @@ -246,11 +248,9 @@ int mas_client_get_audio_source_type(int pid, char** type) return ret; } -int mas_client_activate(int pid) +bool check_pid_is_current_maclient(int pid) { - int ret = -1; - MAS_LOGD("[Enter] pid(%d)", pid); - + bool ret = false; char appid[MAX_APPID_LEN] = {'\0',}; if (AUL_R_OK == aul_app_get_appid_bypid(pid, appid, sizeof(appid))) { appid[MAX_APPID_LEN - 1] = '\0'; @@ -260,18 +260,39 @@ int mas_client_activate(int pid) } if (current_maclient_appid && 0 == strncmp(current_maclient_appid, appid, MAX_APPID_LEN)) { - MAS_LOGD("appid %s matches with current MA Client, activating", appid); - /* - ret = multi_assistant_service_plugin_start_streaming_utterance_data(); - if (0 != ret) { - MAS_LOGE("[ERROR] Fail to request speech data(%d)", ret); - } - */ - masc_dbus_active_state_change(pid, MA_ACTIVE_STATE_ACTIVE); + ret = true; } else { MAS_LOGE("appid %s does not match with current MA Client", appid); } } + return ret; +} + +int mas_client_send_preprocessing_information(int pid) +{ + int ret = -1; + MAS_LOGD("[Enter] pid(%d)", pid); + + if (check_pid_is_current_maclient(pid)) { + char* vconf_str = vconf_get_str(WAKEUP_SETTINGS_KEY_PREPROCESSING_ASSISTANT_APPID); + MAS_LOGD("preprocessing_assistant_appid : %s", vconf_str); + ret = masc_dbus_send_preprocessing_information(pid, vconf_str); + free(vconf_str); + vconf_str = NULL; + } + + return ret; +} + +int mas_client_activate(int pid) +{ + int ret = -1; + MAS_LOGD("[Enter] pid(%d)", pid); + + if (check_pid_is_current_maclient(pid)) { + MAS_LOGD("pid %d matches with current MA Client, activating", pid); + ret = masc_dbus_active_state_change(pid, MA_ACTIVE_STATE_ACTIVE); + } return ret; } @@ -404,6 +425,7 @@ int mas_ui_client_change_assistant(const char* appid) if (pid != -1) { /* Bring MA client to foreground - is there a better way instead of launching? */ mas_launch_client_by_appid(appid, CLIENT_LAUNCH_MODE_ACTIVATION); + mas_client_send_preprocessing_information(pid); masc_dbus_active_state_change(pid, MA_ACTIVE_STATE_ACTIVE); MAS_LOGD("MA Client with appid %s exists, requesting speech data", (appid ? appid : "NULL")); /* diff --git a/src/multi_assistant_service_plugin.c b/src/multi_assistant_service_plugin.c index 6689b10..4017c97 100644 --- a/src/multi_assistant_service_plugin.c +++ b/src/multi_assistant_service_plugin.c @@ -108,6 +108,7 @@ Eina_Bool __launch_assistant_by_wakeup_appid_timer(char* appid) mas_set_current_client_by_appid(appid); if (ui_panel_enabled) masc_ui_dbus_change_assistant(appid); if ((pid = mas_get_client_pid_by_appid(appid)) != -1) { + mas_client_send_preprocessing_information(pid); masc_dbus_active_state_change(pid, MA_ACTIVE_STATE_ACTIVE); /* Bring MA client to foreground - is there a better way instead of launching? */ mas_launch_client_by_appid(appid, CLIENT_LAUNCH_MODE_ACTIVATION); -- 2.7.4