Add support for delivering preprocessing info and result 71/215971/1
authorJi-hoon Lee <dalton.lee@samsung.com>
Wed, 2 Oct 2019 11:46:25 +0000 (20:46 +0900)
committerJi-hoon Lee <dalton.lee@samsung.com>
Fri, 18 Oct 2019 04:34:55 +0000 (13:34 +0900)
Change-Id: Iab6dc1d92a23379d5697092fb295edba4f21376a

inc/multi_assistant_main.h
inc/multi_assistant_service.h
src/multi_assistant_dbus.c
src/multi_assistant_service.c
src/multi_assistant_service_plugin.c

index 42c4e2f..6c04aa6 100644 (file)
@@ -79,6 +79,7 @@
 #define MAS_METHOD_ERROR                                                       "mas_method_error"
 #define MAS_METHOD_SEND_PREPROCESSING_INFORMATION      "mas_method_send_preprocessing_information"
 #define MAS_METHOD_AUDIO_STREAMING_DATA_SECTION                "mas_method_audio_streaming_data_section"
+#define MAS_METHOD_SEND_PREPROCESSING_RESULT           "mas_method_send_preprocessing_result"
 
 #define MAS_UI_METHOD_SEND_ASR_RESULT                          "mas_ui_method_send_asr_result"
 #define MAS_UI_METHOD_SEND_RESULT                                      "mas_ui_method_send_result"
index 9ca7460..0a79b99 100644 (file)
@@ -65,6 +65,8 @@ int mas_ui_client_change_assistant(const char* appid);
 
 int mas_get_current_client_pid();
 
+int mas_get_current_preprocessing_client_pid();
+
 int mas_get_client_pid_by_wakeup_word(const char *wakeup_word);
 
 int mas_get_client_pid_by_appid(const char *appid);
index bbf0cbf..ac92dba 100644 (file)
@@ -393,6 +393,60 @@ int masc_dbus_send_streaming_section_changed(int pid, int section)
        return 0;
 }
 
+int masc_dbus_send_preprocessing_result(int pid, bool result)
+{
+       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_RESULT);
+
+       static int count = 0;
+       if (NULL == msg) {
+               MAS_LOGE(">>>> Request mas send preprocessing result : Fail to make message");
+               return -1; // MAS_ERROR_OPERATION_FAILED;
+       } else {
+               MAS_LOGD(">>>> Request mas send preprocessing result : %s", service_name);
+       }
+
+       int temp_result = result;
+
+       if (true != dbus_message_append_args(msg,
+               DBUS_TYPE_INT32, &temp_result,
+               DBUS_TYPE_INVALID)) {
+               dbus_message_unref(msg);
+               MAS_LOGE("[ERROR] Fail to append args");
+               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");
+               return -1; // MAS_ERROR_OPERATION_FAILED;
+       } else {
+               MAS_LOGD("[Dbus DEBUG] Success to Send preprocessing result : %d", temp_result);
+               dbus_connection_flush(g_conn_sender);
+       }
+
+       dbus_message_unref(msg);
+
+       return 0;
+}
+
 int masc_ui_dbus_send_hello(void)
 {
        if (0 != __dbus_check()) {
index 073967b..2c5d692 100644 (file)
@@ -68,6 +68,7 @@ typedef struct {
 } ma_client_s;
 
 static int g_current_maclient_info = 0;
+static int g_current_preprocessing_maclient_info = -1;
 static const char *g_wakeup_maclient_appid = NULL;
 
 static PREPROCESSING_STATE g_current_preprocessing_state = PREPROCESSING_STATE_NONE;
@@ -170,7 +171,10 @@ bool check_preprocessing_assistant_exists()
                for (int loop = 0; loop < MAX_MACLIENT_INFO_NUM; loop++) {
                        if (g_maclient_info[loop].used) {
                                if (strncmp(vconf_str, g_maclient_info[loop].appid, MAX_APPID_LEN) == 0) {
-                                       ret = true;
+                                       ma_client_s* client = ma_client_find_by_appid(vconf_str);
+                                       if (client && client->pid > 0) {
+                                               ret = true;
+                                       }
                                }
                        }
                }
@@ -178,6 +182,8 @@ bool check_preprocessing_assistant_exists()
                vconf_str = NULL;
        }
 
+       MAS_LOGD("result : %d", ret);
+
        return ret;
 }
 
@@ -235,12 +241,12 @@ int mas_client_initialize(int pid)
                        current_maclient_appid = g_maclient_info[g_current_maclient_info].appid;
                }
 
+               mas_client_send_preprocessing_information(pid);
                if (current_maclient_appid && 0 == strncmp(current_maclient_appid, appid, MAX_APPID_LEN)) {
                        MAS_LOGD("MA client with current maclient appid connected!");
 
                        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);
                                mas_process_preprocessing_state_event(PREPROCESSING_STATE_EVENT_ACTIVE_ASSISTANT_LAUNCHED);
                        } else {
@@ -292,38 +298,16 @@ int mas_client_get_audio_source_type(int pid, char** type)
        return ret;
 }
 
-bool check_pid_is_current_maclient(int 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';
-               const char *current_maclient_appid = NULL;
-               if (g_current_maclient_info >= 0 && g_current_maclient_info < MAX_MACLIENT_INFO_NUM) {
-                       current_maclient_appid = g_maclient_info[g_current_maclient_info].appid;
-               }
-
-               if (current_maclient_appid && 0 == strncmp(current_maclient_appid, appid, MAX_APPID_LEN)) {
-                       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;
-       }
+       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;
 }
@@ -510,11 +494,26 @@ int mas_client_send_preprocessing_result(int pid, bool result)
        }
        if (!is_current_preprocessing_assistant(pid_appid)) return -1;
 
+       const char *current_maclient_appid = NULL;
+       if (g_current_maclient_info >= 0 && g_current_maclient_info < MAX_MACLIENT_INFO_NUM) {
+               current_maclient_appid = g_maclient_info[g_current_maclient_info].appid;
+       }
+
        if (result) {
+               MAS_LOGD("Preprocessing succeeded, bring (%s) to foreground", pid_appid);
+               mas_bring_client_to_foreground(pid_appid);
                mas_process_preprocessing_state_event(PREPROCESSING_STATE_EVENT_PREPROCESSING_SUCCEEDED);
        } else {
+               MAS_LOGD("Preprocessing failed, bring (%s) to foreground", current_maclient_appid);
+               mas_bring_client_to_foreground(current_maclient_appid);
                mas_process_preprocessing_state_event(PREPROCESSING_STATE_EVENT_PREPROCESSING_FAILED);
        }
+
+       ma_client_s* client = ma_client_find_by_appid(current_maclient_appid);
+       if (client) {
+               masc_dbus_send_preprocessing_result(client->pid, result);
+       }
+
        return 0;
 }
 
@@ -616,6 +615,10 @@ int __mas_assistant_info_cb(const char* appid, const char* name, const char* ico
                strncpy(g_maclient_info[index].appid, appid, MAX_APPID_LEN);
                g_maclient_info[index].appid[MAX_APPID_LEN - 1] = '\0';
 
+               if (is_current_preprocessing_assistant(g_maclient_info[index].appid)) {
+                       g_current_preprocessing_maclient_info = index;
+               }
+
                for (loop = 0;loop < MAX_WAKEUP_WORDS_NUM;loop++) {
                        if (loop < cnt_wakeup && wakeup_list[loop]) {
                                MAS_LOGD("wakeup_list(%d)(%s)(%s)", loop, wakeup_list[loop], wakeup_language[loop]);
@@ -790,8 +793,21 @@ int mas_get_current_client_pid()
 {
        int ret = -1;
        if (g_current_maclient_info >= 0 && g_current_maclient_info < MAX_MACLIENT_INFO_NUM) {
-               const char *current_maclient_appid = g_maclient_info[g_current_maclient_info].appid;
-               ma_client_s* client = ma_client_find_by_appid(current_maclient_appid);
+               const char *appid = g_maclient_info[g_current_maclient_info].appid;
+               ma_client_s* client = ma_client_find_by_appid(appid);
+               if (client) {
+                       ret = client->pid;
+               }
+       }
+       return ret;
+}
+
+int mas_get_current_preprocessing_client_pid()
+{
+       int ret = -1;
+       if (g_current_preprocessing_maclient_info >= 0 && g_current_preprocessing_maclient_info < MAX_MACLIENT_INFO_NUM) {
+               const char *appid = g_maclient_info[g_current_preprocessing_maclient_info].appid;
+               ma_client_s* client = ma_client_find_by_appid(appid);
                if (client) {
                        ret = client->pid;
                }
index 79f7aa5..700b3f2 100644 (file)
@@ -286,6 +286,7 @@ static void __audio_streaming_cb(wakeup_speech_streaming_event_e event, unsigned
        ++count;
 
        int pid = mas_get_current_client_pid();
+       int preprocessing_pid = mas_get_current_preprocessing_client_pid();
        if (pid == -1) {
                MAS_LOGE("[ERROR] Fail to retrieve pid of current MA client");
        } else {
@@ -294,6 +295,12 @@ static void __audio_streaming_cb(wakeup_speech_streaming_event_e event, unsigned
                        if (0 != ret) {
                                MAS_LOGE("[ERROR] Fail to send speech data, ret(%d)", ret);
                        }
+                       if (pid != preprocessing_pid && -1 != preprocessing_pid) {
+                               int ret = masc_dbus_send_streaming_audio_data(preprocessing_pid, event, buffer, len);
+                               if (0 != ret) {
+                                       MAS_LOGE("[ERROR] Fail to send speech data to preprocessing client, ret(%d)", ret);
+                               }
+                       }
                }
        }