#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_METHOD_SEND_WAKEUP_ENGINE_COMMAND "mas_method_send_wakeup_engine_command"
+#define MAS_METHOD_SERVICE_STATE_CHANGE "mas_method_service_state_change"
#define MAS_UI_METHOD_SEND_ASR_RESULT "mas_ui_method_send_asr_result"
#define MAS_UI_METHOD_SEND_RESULT "mas_ui_method_send_result"
int mas_prelaunch_default_assistant();
+int mas_set_current_service_state(ma_service_state_e state);
+
+ma_service_state_e mas_get_current_service_state();
+
typedef enum {
CLIENT_LAUNCH_MODE_ACTIVATION,
CLIENT_LAUNCH_MODE_PRELAUNCH,
typedef int (*wakeup_manager_set_streaming_section_changed_callback)(wakeup_service_streaming_section_changed_cb callback, void* user_data);
#define MA_WAKEUP_MANAGER_FUNC_SET_WAKEUP_ENGINE_COMMAND_CALLBACK "wakeup_manager_set_wakeup_engine_command_callback"
typedef int (*wakeup_manager_set_wakeup_engine_command_callback)(wakeup_service_wakeup_engine_command_cb callback, void* user_data);
+#define MA_WAKEUP_MANAGER_FUNC_SET_WAKEUP_SERVICE_STATE_CHANGED_CALLBACK "wakeup_manager_set_wakeup_service_state_changed_callback"
+typedef int (*wakeup_manager_set_wakeup_service_state_changed_callback)(wakeup_service_wakeup_service_state_changed_cb callback, void* user_data);
typedef struct {
wakeup_manager_initialize initialize;
wakeup_manager_set_error_callback set_error_callback;
wakeup_manager_set_streaming_section_changed_callback set_streaming_section_changed_callback;
wakeup_manager_set_wakeup_engine_command_callback set_wakeup_engine_command_callback;
+ wakeup_manager_set_wakeup_service_state_changed_callback set_wakeup_service_state_changed_callback;
} wakeup_manager_interface;
#ifdef __cplusplus
#include <multi_assistant_common.h>
#include <multi_assistant_service.h>
+#include <multi_assistant_internal.h>
#ifdef __cplusplus
extern "C" {
typedef void (*wakeup_service_wakeup_engine_command_cb)(mas_wakeup_engine_command_target_e target, const char* assistant_name, const char* command, void* user_data);
+typedef void (*wakeup_service_wakeup_service_state_changed_cb)(ma_service_state_e state, void* user_data);
+
#ifdef __cplusplus
}
#endif
virtual void on_audio_streaming_data_section(ma_audio_streaming_data_section_e section) = 0;
virtual void on_wakeup_engine_command(
mas_wakeup_engine_command_target_e target, const char* name, const char* command) = 0;
+ virtual void on_wakeup_service_state_changed(ma_service_state_e state) = 0;
};
class ISettingValueObserver {
#include <tzplatform_config.h>
#include <multi_assistant_service.h>
+#include <multi_assistant_internal.h>
#ifdef __cplusplus
extern "C" {
typedef void (*wakeup_service_engine_command_cb)(mas_wakeup_engine_command_target_e target, const char* assistant_name, const char* command, void* user_data);
+typedef void (*wakeup_service_state_changed_cb)(ma_service_state_e state, void* user_data);
+
typedef struct {
int plugin_version;
bool ui_panel_enabled;
EXPORT_API int wakeup_manager_set_wakeup_engine_command_callback(wakeup_service_engine_command_cb callback, void* user_data);
+EXPORT_API int wakeup_manager_set_wakeup_service_state_changed_callback(wakeup_service_state_changed_cb callback, void* user_data);
+
/* Internal API declarations for dependency modules */
int wakeup_manager_feed_audio_data(mas_speech_streaming_event_e event, void* buffer, int len);
{
mWakeupManagerState = state;
mWakeupEngineManager.update_manager_state(state);
+ for (const auto& observer : mWakeupObservers) {
+ observer->on_wakeup_service_state_changed((ma_service_state_e)state);
+ }
return true;
}
static wakeup_service_engine_command_cb g_wakeup_engine_command_cb;
static void* g_wakeup_engine_command_user_data;
+static wakeup_service_state_changed_cb g_wakeup_service_state_changed_cb;
+static void *g_wakeup_service_state_changed_user_data;
+
class CWakeupEventObserver : public IWakeupEventObserver
{
void on_wakeup(mas_wakeup_event_info wakeup_info) override;
void on_audio_streaming_data_section(ma_audio_streaming_data_section_e section) override;
void on_wakeup_engine_command(
mas_wakeup_engine_command_target_e target, const char* assistant_name, const char* command) override;
+ void on_wakeup_service_state_changed(ma_service_state_e state) override;
};
class CSettingValueObserver : public ISettingValueObserver
g_wakeup_engine_command_cb = NULL;
g_wakeup_engine_command_user_data = NULL;
+ g_wakeup_service_state_changed_cb = NULL;
+ g_wakeup_service_state_changed_user_data = NULL;
+
g_wakeup_manager->initialize();
MWR_LOGD("[END]");
return 0;
}
+int wakeup_manager_set_wakeup_service_state_changed_callback(wakeup_service_state_changed_cb callback, void* user_data)
+{
+ MWR_LOGD("[ENTER]");
+
+ if (NULL == callback) {
+ MWR_LOGE("[ERROR] Input parameter is NULL");
+ return -1;
+ }
+
+ g_wakeup_service_state_changed_cb = callback;
+ g_wakeup_service_state_changed_user_data = user_data;
+
+ MWR_LOGD("[END]");
+ return 0;
+}
+
int wakeup_manager_feed_audio_data(mas_speech_streaming_event_e event, void* buffer, int len)
{
if (nullptr == g_wakeup_manager) return -1;
}
}
+void CWakeupEventObserver::on_wakeup_service_state_changed(ma_service_state_e state)
+{
+ if (g_wakeup_service_state_changed_cb) {
+ g_wakeup_service_state_changed_cb(state, g_wakeup_service_state_changed_user_data);
+ }
+}
+
void CSettingValueObserver::on_value_changed()
{
if (g_setting_changed_cb) {
return 0;
}
+int masc_dbus_service_state_change(int pid, int state)
+{
+ 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_SERVICE_STATE_CHANGE);
+
+ static int count = 0;
+ if (NULL == msg) {
+ MAS_LOGE(">>>> Request mas send service state message : Fail to make message");
+ return -1; // MAS_ERROR_OPERATION_FAILED;
+ } else {
+ MAS_LOGD(">>>> Request mas send service state message : %s", service_name);
+ }
+
+ if (true != dbus_message_append_args(msg,
+ DBUS_TYPE_INT32, &state,
+ 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 activate message : %d", state);
+ dbus_connection_flush(g_conn_sender);
+ }
+
+ dbus_message_unref(msg);
+ return 0;
+}
+
int masc_ui_dbus_send_hello(void)
{
if (0 != __dbus_check()) {
int masc_dbus_send_preprocessing_information(int pid, const char* app_id);
+int masc_dbus_send_streaming_section_changed(int pid, int section);
+
+int masc_dbus_send_preprocessing_result(int pid, bool result);
+
+int masc_dbus_send_wakeup_engine_command(int pid, const char* command);
+
+int masc_dbus_service_state_change(int pid, int state);
+
int masc_ui_dbus_send_hello(void);
int masc_ui_dbus_send_asr_result(int pid, int event, char* asr_result);
static package_manager_h g_pkgmgr = NULL;
static PREPROCESSING_STATE g_current_preprocessing_state = PREPROCESSING_STATE_NONE;
+static ma_service_state_e g_current_service_state = MA_SERVICE_STATE_INACTIVE;
/* client list */
static GSList* g_client_list = NULL;
} else {
MAS_LOGD("MA client connected, but its appid does not match with current maclient");
}
+
+ masc_dbus_service_state_change(pid, mas_get_current_service_state());
} else {
MAS_LOGE("[ERROR] Fail to retrieve appid");
}
return 0;
}
-
ma_preprocessing_allow_mode_e get_preprocessing_allow_mode(const char* appid)
{
for (int loop = 0; loop < MAX_MACLIENT_INFO_NUM; loop++) {
return 0;
}
+int mas_set_current_service_state(ma_service_state_e state)
+{
+ g_current_service_state = state;
+
+ ma_client_s *data = NULL;
+
+ int count = g_slist_length(g_client_list);
+ int i;
+
+ for (i = 0; i < count; i++) {
+ data = g_slist_nth_data(g_client_list, i);
+
+ if (NULL != data && -1 != data->pid) {
+ int ret = masc_dbus_service_state_change(data->pid, state);
+ if (0 != ret) {
+ MAS_LOGE("[ERROR] Fail to send wakeup service state change to %d, ret(%d)",
+ data->pid, ret);
+ }
+ }
+ }
+ return 0;
+}
+
+ma_service_state_e mas_get_current_service_state()
+{
+ return g_current_service_state;
+}
+
static int pkg_app_list_cb(const pkgmgrinfo_appinfo_h handle, void *user_data)
{
char *appid = NULL;
}
}
+static void __wakeup_service_state_changed_cb(ma_service_state_e state, void* user_data)
+{
+ MAS_LOGD( "[SUCCESS] __wakeup_service_state_changed_cb is called, state(%d)", state);
+
+ mas_set_current_service_state(state);
+}
+
int multi_assistant_service_plugin_initialize(void)
{
MAS_LOGD( "[Enter]");
_wakeup_manager_interface.set_wakeup_engine_command_callback =
(wakeup_manager_set_wakeup_engine_command_callback)dlsym(g_handle,
MA_WAKEUP_MANAGER_FUNC_SET_WAKEUP_ENGINE_COMMAND_CALLBACK);
+ _wakeup_manager_interface.set_wakeup_service_state_changed_callback =
+ (wakeup_manager_set_wakeup_service_state_changed_callback)dlsym(g_handle,
+ MA_WAKEUP_MANAGER_FUNC_SET_WAKEUP_SERVICE_STATE_CHANGED_CALLBACK);
int ret = -1;
if (NULL != g_handle) {
return ret;
}
+ ret = multi_assistant_service_plugin_set_wakeup_service_state_changed_callback(__wakeup_service_state_changed_cb, NULL);
+ if (0 != ret) {
+ MAS_LOGE("Fail to set wakeup engine command cb");
+ return ret;
+ }
+
return 0;
}
}
}
return ret;
-}
\ No newline at end of file
+}
+
+int multi_assistant_service_plugin_set_wakeup_service_state_changed_callback(wakeup_service_wakeup_service_state_changed_cb callback, void* user_data)
+{
+ int ret = -1;
+ if (NULL != g_handle) {
+ wakeup_manager_set_wakeup_service_state_changed_callback func = _wakeup_manager_interface.set_wakeup_service_state_changed_callback;
+ if (NULL == func) {
+ MAS_LOGE("[ERROR] symbol lookup failed : %s", MA_WAKEUP_MANAGER_FUNC_SET_WAKEUP_SERVICE_STATE_CHANGED_CALLBACK);
+ } else {
+ ret = func(callback, user_data);
+ if (0 != ret) {
+ MAS_LOGE("[ERROR] Fail to set error callback, ret(%d)", ret);
+ }
+ }
+ }
+ return ret;
+}
+