Handle change_assistant request from panel 90/191090/5
authorJi-hoon Lee <dalton.lee@samsung.com>
Thu, 11 Oct 2018 08:01:07 +0000 (17:01 +0900)
committerJi-hoon Lee <dalton.lee@samsung.com>
Tue, 23 Oct 2018 07:06:20 +0000 (07:06 +0000)
Change-Id: Ib74a46c94828f8c008c9b261b0d41164415b08cc

inc/multi_assistant_service.h
src/multi_assistant_dbus_server.c
src/multi_assistant_service.c
src/multi_assistant_service_plugin.c

index d4ca45ee1901afbbdb35919d401057c261737599..93d50c11c33f3b8ac752edcf2f559f070fa2c68b 100644 (file)
@@ -43,16 +43,22 @@ int mas_ui_client_initialize(int pid);
 
 int mas_ui_client_deinitialize(int pid);
 
-int mas_ui_client_change_assistant(char* app_id);
+int mas_ui_client_change_assistant(const char* appid);
 
 int mas_get_current_client_pid();
 
 int mas_get_client_pid_by_wakeup_word(const char *wakeup_word);
 
+int mas_get_client_pid_by_appid(const char *appid);
+
 int mas_set_current_client_by_wakeup_word(const char *wakeup_word);
 
+int mas_set_current_client_by_appid(const char *appid);
+
 int mas_launch_client_by_wakeup_word(const char *wakeup_word);
 
+int mas_launch_client_by_appid(const char *appid);
+
 #ifdef __cplusplus
 }
 #endif
index 377c805e9d75512dc8920451594334ab4f6e67d2..e2eb69c839a283029e90e2a7824b79c0687f7f7d 100644 (file)
@@ -478,7 +478,7 @@ int ma_service_ui_dbus_change_assistant(DBusConnection* conn, DBusMessage* msg)
                DBUS_TYPE_STRING, &app_id,
                DBUS_TYPE_INVALID);
 
-       MAS_LOGD("[DEBUG] MAS UI CHANGE ASSISTANT");
+       MAS_LOGD("[DEBUG] MAS UI CHANGE ASSISTANT : %s", (app_id ? app_id : "NULL"));
 
        if (dbus_error_is_set(&err)) {
                MAS_LOGE("[IN ERROR] mas ui change assisant : Get arguments error (%s)", err.message);
index d923b43c6b8a41ab670891bf8a1ec8f4dd5bf7ff..fa8ecc35fba705adfbabbd740ddd93c3a472b3e3 100644 (file)
@@ -150,10 +150,15 @@ Eina_Bool __request_speech_data_timer(void *data)
        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';
-               if (0 == strncmp(g_launching_maclient_appid, appid, MAX_APPID_LEN)) {
+               if (g_launching_maclient_appid && strncmp(g_launching_maclient_appid, appid, MAX_APPID_LEN) == 0) {
                        g_launching_maclient_appid = NULL;
                        mas_client_request_speech_data(pid);
+               } else {
+                       MAS_LOGE("[ERROR] g_launching_maclient_appid and appid differ : %s %s",
+                               (g_launching_maclient_appid ? g_launching_maclient_appid : "NULL"), appid);
                }
+       } else {
+               MAS_LOGE("[ERROR] failed retrieving appid from pid %d", pid);
        }
 
        MAS_LOGD("END");
@@ -315,9 +320,32 @@ int mas_ui_client_deinitialize(int pid)
        return 0;
 }
 
-int mas_ui_client_change_assistant(char* app_id)
+int mas_ui_client_change_assistant(const char* appid)
 {
-       MAS_LOGD("[Enter] app_id(%s)", app_id);
+       MAS_LOGD("[Enter]");
+
+       mas_set_current_client_by_appid(appid);
+       if (mas_get_client_pid_by_appid(appid) != -1) {
+               MAS_LOGD("MA Client with appid %s exists, requesting speech data", (appid ? appid : "NULL"));
+               int ret = wakeup_service_request_speech_data();
+               if (0 != ret) {
+                       MAS_LOGE("[ERROR] Fail to request speech data(%d)", ret);
+               }
+       } else {
+               // Appropriate MA Client not available, trying to launch new one
+               MAS_LOGD("MA Client with appid %s does not exist, launching client", (appid ? appid : "NULL"));
+
+               /* The appid parameter might not exist after this function call, so we use appid string in our g_maclient_info */
+               for (int loop = 0; loop < MAX_MACLIENT_INFO_NUM; loop++) {
+                       if (g_maclient_info[loop].used &&
+                               strlen(g_maclient_info[loop].appid) > 0 &&
+                               strlen(g_maclient_info[loop].wakeup_word) > 0) {
+                               if (strncmp(appid, g_maclient_info[loop].appid, MAX_APPID_LEN) == 0) {
+                                       mas_launch_client_by_appid(g_maclient_info[loop].appid);
+                               }
+                       }
+               }
+       }
 
        return 0;
 }
@@ -476,11 +504,10 @@ int mas_get_current_client_pid()
        return ret;
 }
 
-int mas_get_client_pid_by_wakeup_word(const char *wakeup_word)
+int mas_get_client_pid_by_appid(const char *appid)
 {
        int ret = -1;
 
-       const char *appid = __get_client_appid_by_wakeup_word(wakeup_word);
        if (appid) {
                ma_client_s *client = NULL;
                client = ma_client_find_by_appid(appid);
@@ -492,6 +519,12 @@ int mas_get_client_pid_by_wakeup_word(const char *wakeup_word)
        return ret;
 }
 
+int mas_get_client_pid_by_wakeup_word(const char *wakeup_word)
+{
+       const char *appid = __get_client_appid_by_wakeup_word(wakeup_word);
+       return mas_get_client_pid_by_appid(appid);
+}
+
 int mas_set_current_client_by_wakeup_word(const char *wakeup_word)
 {
        int ret = -1;
@@ -508,14 +541,29 @@ int mas_set_current_client_by_wakeup_word(const char *wakeup_word)
        return ret;
 }
 
-int mas_launch_client_by_wakeup_word(const char *wakeup_word)
+int mas_set_current_client_by_appid(const char *appid)
+{
+       int ret = -1;
+
+       for (int loop = 0; loop < MAX_MACLIENT_INFO_NUM; loop++) {
+               if (g_maclient_info[loop].used &&
+                       strlen(g_maclient_info[loop].appid) > 0 &&
+                       strlen(g_maclient_info[loop].wakeup_word) > 0) {
+                       if (strncmp(appid, g_maclient_info[loop].appid, MAX_APPID_LEN) == 0) {
+                               g_current_maclient_info = loop;
+                       }
+               }
+       }
+       return ret;
+}
+
+int mas_launch_client_by_appid(const char *appid)
 {
        app_control_h app_control;
        int ret = 0;
 
-       const char *appid = __get_client_appid_by_wakeup_word(wakeup_word);
-       if (NULL == appid || 0 == strlen(appid)) {
-               MAS_LOGW("could not find appropriate appid with wakeup word %s", (wakeup_word ? wakeup_word : "NULL"));
+       if (NULL == appid || strlen(appid) == 0) {
+               MAS_LOGE("appid invalid, failed launching MA Client");
                return -1;
        }
 
@@ -560,6 +608,12 @@ int mas_launch_client_by_wakeup_word(const char *wakeup_word)
        return ret;
 }
 
+int mas_launch_client_by_wakeup_word(const char *wakeup_word)
+{
+       const char *appid = __get_client_appid_by_wakeup_word(wakeup_word);
+       return mas_launch_client_by_appid(appid);
+}
+
 bool service_app_create(void *data)
 {
        // Todo: add your code here.
index 8abfbe70a7e555c6c7aa9d98bf3ac5f4dc6b56dd..e1fc12f99158281cdf464a237591587be7a43df2 100644 (file)
@@ -223,8 +223,6 @@ static Eina_Bool __wakeup_start_recording(void* data)
 {
        MAS_LOGD( "[SUCCESS] __wakeup_start_recording is called.");
 
-       (void*)data;
-
        int ret;
 
        ret = wakeup_service_start_recording();