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");
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;
}
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);
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;
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;
}
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.