#ifndef __SERVICE_IPC_DBUS_H__
#define __SERVICE_IPC_DBUS_H__
+#include <string>
+
#include <dbus/dbus.h>
#include <Ecore.h>
int close_connection();
int send_hello(pid_t pid);
int send_error_message(int reason, const char* err_msg);
- int send_streaming_audio_data(pid_t pid, int event, void* data, unsigned int data_size);
+ int send_streaming_audio_data(std::string appid, int event, void* data, unsigned int data_size);
int change_active_state(pid_t pid, int state, const char* wakeup_word,
const unsigned char* wakeup_extra_data, size_t wakeup_extra_data_length,
const char* wakeup_extra_data_desc);
int client_set_assistant_language(pid_t pid, const char* language);
int client_add_wake_word(pid_t pid, const char* wake_word, const char* language);
int client_remove_wake_word(pid_t pid, const char* wake_word, const char* language);
+
int ui_client_initialize(pid_t pid);
int ui_client_deinitialize(pid_t pid);
int ui_client_change_assistant(const char* appid);
+
pid_t get_current_client_pid();
pid_t get_current_preprocessing_client_pid();
pid_t get_current_audio_processing_pid();
+
+ boost::optional<std::string> get_current_client_appid();
+ boost::optional<std::string> get_current_preprocessing_client_appid();
+ boost::optional<std::string> get_current_audio_processing_appid();
+
int get_client_pid_by_wakeup_word(const char *wakeup_word);
+ const char* get_client_appid_by_wakeup_word(const char *wakeup_word);
+
int get_client_pid_by_appid(const char *appid);
std::string get_client_appid_by_pid(pid_t pid);
+
bool get_client_custom_ui_option_by_appid(const char *appid);
- const char* get_client_appid_by_wakeup_word(const char *wakeup_word);
+
int set_current_client_by_wakeup_word(const char *wakeup_word);
int set_current_client_by_appid(const char *appid);
+
int launch_client_by_wakeup_word(const char *wakeup_word,
const unsigned char* extra_data, size_t extra_data_length, const char *extra_data_desc);
+ int launch_client_by_appid(const char *appid, const char *word,
+ const unsigned char *extra_data, size_t extra_data_length, const char *extra_data_desc,
+ CLIENT_LAUNCH_MODE launch_mode);
+
int prelaunch_default_assistant();
int set_current_service_state(ma_service_state_e state);
int bring_client_to_foreground(const char* appid);
ma_service_state_e get_current_service_state();
- int launch_client_by_appid(const char *appid, const char *word,
- const unsigned char *extra_data, size_t extra_data_length, const char *extra_data_desc,
- CLIENT_LAUNCH_MODE launch_mode);
int process_preprocessing_state_event(PREPROCESSING_STATE_EVENT event);
int update_voice_key_support_mode();
+
int get_current_wakeup_word(char** wakeup_word);
int set_current_wakeup_word(const char *wakeup_word);
return value.count();
}
-int CServiceIpcDbus::send_streaming_audio_data(pid_t pid, int event, void* data, unsigned int data_size)
+int CServiceIpcDbus::send_streaming_audio_data(std::string appid, int event, void* data, unsigned int data_size)
{
if (nullptr == mClientManager) {
MAS_LOGE("mClientManager variable is NULL");
auto checkpoint_2 = std::chrono::steady_clock::now();
auto checkpoint_2_1 = checkpoint_2;
auto checkpoint_2_2 = checkpoint_2;
- auto checkpoint_2_3 = checkpoint_2;
- auto checkpoint_2_4 = checkpoint_2;
#endif
if (pending_buffer_size + total_size > STREAMING_BUFFER_SIZE ||
#ifdef PRINT_DETAILED_TIMEINFO
checkpoint_2_1 = std::chrono::steady_clock::now();
#endif
- boost::optional<std::string> appid = mApplicationManager->get_appid_by_pid(pid);
-#ifdef PRINT_DETAILED_TIMEINFO
- checkpoint_2_2 = std::chrono::steady_clock::now();
-#endif
-
- if (appid) {
-#ifdef PRINT_DETAILED_TIMEINFO
- checkpoint_2_3 = std::chrono::steady_clock::now();
-#endif
#if USE_TRUSTED_MESSAGE_PORT
- int ret = message_port_send_trusted_message((*appid).c_str(), message_port, b);
+ int ret = message_port_send_trusted_message(appid.c_str(), message_port, b);
#else
- int ret = message_port_send_message((*appid).c_str(), message_port, b);
+ int ret = message_port_send_message(appid.c_str(), message_port, b);
#endif
#ifdef PRINT_DETAILED_TIMEINFO
- checkpoint_2_4 = std::chrono::steady_clock::now();
+ checkpoint_2_2 = std::chrono::steady_clock::now();
#endif
- if (MESSAGE_PORT_ERROR_NONE != ret)
- masc_message_port_error(ret);
- } else {
- MAS_LOGE("AppID for PID %d not found!!!", pid);
- }
+ if (MESSAGE_PORT_ERROR_NONE != ret)
+ masc_message_port_error(ret);
pending_buffer_size = 0;
bundle_free(b);
bundle *b = bundle_create();
if (b) {
bundle_add_byte(b, "content", buffer, total_size);
- boost::optional<std::string> appid = mApplicationManager->get_appid_by_pid(pid);
- if (appid) {
#if USE_TRUSTED_MESSAGE_PORT
- int ret = message_port_send_trusted_message((*appid).c_str(), message_port, b);
+ int ret = message_port_send_trusted_message(appid.c_str(), message_port, b);
#else
- int ret = message_port_send_message((*appid).c_str(), message_port, b);
+ int ret = message_port_send_message(appid.c_str(), message_port, b);
#endif
- if (MESSAGE_PORT_ERROR_NONE != ret)
- masc_message_port_error(ret);
- } else {
- MAS_LOGE("AppID for PID %d not found!!!", pid);
- }
+ if (MESSAGE_PORT_ERROR_NONE != ret)
+ masc_message_port_error(ret);
bundle_free(b);
} else {
long long int count2_1 = get_time_interval_count(checkpoint_2, checkpoint_2_1);
long long int count2_2 = get_time_interval_count(checkpoint_2_1, checkpoint_2_2);
- long long int count2_3 = get_time_interval_count(checkpoint_2_2, checkpoint_2_3);
- long long int count2_4 = get_time_interval_count(checkpoint_2_3, checkpoint_2_4);
- long long int count2_5 = get_time_interval_count(checkpoint_2_4, checkpoint_3);
+ long long int count2_3 = get_time_interval_count(checkpoint_2_2, checkpoint_3);
- MAS_LOGE("Spent %lld for sending a single message %d [%lld %lld %lld %lld] (%lld %lld %lld %lld %lld)",
- count, flushed, count1, count2, count3, count4, count2_1, count2_2, count2_3, count2_4, count2_5);
+ MAS_LOGE("Spent %lld for sending a single message %d [%lld %lld %lld %lld] (%lld %lld %lld)",
+ count, flushed, count1, count2, count3, count4, count2_1, count2_2, count2_3);
}
#endif
int CServiceMain::get_current_client_pid()
{
int ret = -1;
+ boost::optional<std::string> appid = get_current_client_appid();
+ if (appid) {
+ ret = mClientManager.find_client_pid_by_appid(*appid);
+ }
+ return ret;
+}
+
+pid_t CServiceMain::get_current_preprocessing_client_pid()
+{
+ pid_t ret = -1;
+ boost::optional<std::string> preprocessing_appid = get_current_preprocessing_client_appid();
+ if (preprocessing_appid) {
+ ret = mClientManager.find_client_pid_by_appid(*preprocessing_appid);
+ }
+ return ret;
+}
+
+pid_t CServiceMain::get_current_audio_processing_pid()
+{
+ pid_t ret = -1;
+ boost::optional<std::string> audio_processing_appid = get_current_audio_processing_appid();
+ if (audio_processing_appid) {
+ boost::optional<pid_t> audio_processing_pid =
+ mApplicationManager.get_pid_by_appid(*audio_processing_appid);
+ if (audio_processing_pid) {
+ ret = *audio_processing_pid;
+ }
+ }
+ return ret;
+}
+
+boost::optional<std::string> CServiceMain::get_current_client_appid()
+{
+ boost::optional<std::string> ret;
if (mCurrentClientInfo >= 0 && mCurrentClientInfo < MAX_MACLIENT_INFO_NUM) {
ClientInfoItems *items = mClientInfo.getItems();
const char *appid = items[mCurrentClientInfo].appid;
if (appid) {
- ret = mClientManager.find_client_pid_by_appid(std::string{appid});
+ ret = std::string{appid};
}
}
return ret;
}
-pid_t CServiceMain::get_current_preprocessing_client_pid()
+boost::optional<std::string> CServiceMain::get_current_preprocessing_client_appid()
{
- pid_t ret = -1;
+ boost::optional<std::string> ret;
if (mCurrentPreprocessingClientInfo >= 0 && mCurrentPreprocessingClientInfo < MAX_MACLIENT_INFO_NUM) {
ClientInfoItems *items = mClientInfo.getItems();
const char *appid = items[mCurrentPreprocessingClientInfo].appid;
if (appid) {
- ret = mClientManager.find_client_pid_by_appid(std::string{appid});
+ ret = std::string{appid};
}
}
return ret;
}
-pid_t CServiceMain::get_current_audio_processing_pid()
+boost::optional<std::string> CServiceMain::get_current_audio_processing_appid()
{
- pid_t ret = -1;
+ boost::optional<std::string> ret;
if (mCurrentClientInfo >= 0 && mCurrentClientInfo < MAX_MACLIENT_INFO_NUM) {
ClientInfoItems *items = mClientInfo.getItems();
- boost::optional<std::string> audio_processing_appid =
- items[mCurrentClientInfo].audio_processing_appid;
- if (audio_processing_appid) {
- boost::optional<pid_t> audio_processing_pid;
- audio_processing_pid = mApplicationManager.get_pid_by_appid((*audio_processing_appid).c_str());
- if (audio_processing_pid) {
- ret = *audio_processing_pid;
- }
- }
+ ret = items[mCurrentClientInfo].audio_processing_appid;
}
return ret;
}
}
}
-static bool __validate_streaming_event_order(pid_t pid, mas_speech_streaming_event_e *event)
+static bool __validate_streaming_event_order(std::string appid, mas_speech_streaming_event_e *event)
{
bool ret = false;
- static int previous_pid = -1;
+ static std::string previous_appid;
static mas_speech_streaming_event_e previous_event = MAS_SPEECH_STREAMING_EVENT_FINISH;
if (NULL == event) return false;
{MAS_SPEECH_STREAMING_EVENT_FINISH, MAS_SPEECH_STREAMING_EVENT_FINISH},
};
- if (pid != previous_pid) {
+ if (appid != previous_appid) {
/* When sending streaming event to a new client, it always sends START message first */
previous_event = MAS_SPEECH_STREAMING_EVENT_FINISH;
}
*event = MAS_SPEECH_STREAMING_EVENT_START;
ret = true;
- MAS_LOGD("[WARNING] forcibly changed CONTINUE to START : %d -> %d (PID %d -> %d)",
- previous_event, *event, previous_pid, pid);
+ MAS_LOGD("[WARNING] forcibly changed CONTINUE to START : %d -> %d (PID %s -> %s)",
+ previous_event, *event, previous_appid.c_str(), appid.c_str());
}
}
if (ret) {
- previous_pid = pid;
+ previous_appid = appid;
previous_event = *event;
} else {
- MAS_LOGE("[ERROR] State sequence validation failed : %d -> %d (PID %d -> %d)",
- previous_event, *event, previous_pid, pid);
+ MAS_LOGE("[ERROR] State sequence validation failed : %d -> %d (APPID %s -> %s)",
+ previous_event, *event, previous_appid.c_str(), appid.c_str());
}
return ret;
}
if (service_ipc && service_main) {
/* First check if we have dedicated audio processing app for current client */
- pid_t pid = service_main->get_current_audio_processing_pid();
+ boost::optional<std::string> appid =
+ service_main->get_current_audio_processing_appid();
+
/* If not, send audio data to the main client */
- if (-1 == pid) pid = service_main->get_current_client_pid();
+ if (!appid) appid = service_main->get_current_client_appid();
+
+ boost::optional<std::string> preprocessing_appid =
+ service_main->get_current_preprocessing_client_appid();
- int preprocessing_pid = service_main->get_current_preprocessing_client_pid();
- if (pid == -1) {
- MAS_LOGE("[ERROR] Fail to retrieve pid of current MA client");
+ if (!appid) {
+ MAS_LOGE("[ERROR] Fail to retrieve target appid of current MA client");
} else {
- if (__validate_streaming_event_order(pid, &event)) {
+ if (__validate_streaming_event_order(*appid, &event)) {
#ifdef PRINT_DETAILED_TIMEINFO
checkpoint_2 = std::chrono::steady_clock::now();
#endif
-
- int ret = service_ipc->send_streaming_audio_data(pid,
+ int ret = service_ipc->send_streaming_audio_data(*appid,
event, buffer, len);
if (0 != ret) {
MAS_LOGE("[ERROR] Fail to send speech data, ret(%d)", ret);
}
- if (pid != preprocessing_pid && -1 != preprocessing_pid) {
- int ret = service_ipc->send_streaming_audio_data(preprocessing_pid,
+ if (preprocessing_appid && (*appid).compare(*preprocessing_appid) != 0) {
+ int ret = service_ipc->send_streaming_audio_data(*preprocessing_appid,
event, buffer, len);
if (0 != ret) {
MAS_LOGE("[ERROR] Fail to send speech data to preprocessing client, ret(%d)", ret);