Keep assistants updated about service state changes 23/219623/3
authorJi-hoon Lee <dalton.lee@samsung.com>
Fri, 6 Dec 2019 10:00:44 +0000 (19:00 +0900)
committerJi-hoon Lee <dalton.lee@samsung.com>
Fri, 6 Dec 2019 10:08:48 +0000 (19:08 +0900)
Change-Id: Ie7e01bc84b61da61da959e03cbebec16bf14a9fa

12 files changed:
inc/multi_assistant_main.h
inc/multi_assistant_service_client.h
inc/multi_assistant_service_plugin.h
inc/multi_wakeup_recognizer.h
plugins/wakeup-manager/inc/wakeup_manager.h
plugins/wakeup-manager/inc/wakeup_manager_wrapper.h
plugins/wakeup-manager/src/wakeup_manager.cpp
plugins/wakeup-manager/src/wakeup_manager_wrapper.cpp
src/multi_assistant_dbus.c
src/multi_assistant_dbus.h
src/multi_assistant_service.c
src/multi_assistant_service_plugin.c

index 3e2b2c1..8adc1c0 100644 (file)
@@ -82,6 +82,7 @@
 #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"
index b3eebf1..110d0d1 100644 (file)
@@ -83,6 +83,10 @@ int mas_launch_client_by_wakeup_word(const char *wakeup_word);
 
 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,
index 7115f95..cae0038 100644 (file)
@@ -173,6 +173,8 @@ typedef int (*wakeup_manager_set_error_callback)(wakeup_service_error_cb callbac
 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;
@@ -210,6 +212,7 @@ typedef struct {
        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
index 6e1b26a..cdd8140 100644 (file)
@@ -22,6 +22,7 @@
 
 #include <multi_assistant_common.h>
 #include <multi_assistant_service.h>
+#include <multi_assistant_internal.h>
 
 #ifdef __cplusplus
 extern "C" {
@@ -41,6 +42,8 @@ typedef void (*wakeup_service_streaming_section_changed_cb)(ma_audio_streaming_d
 
 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
index 8d36921..85ce732 100644 (file)
@@ -50,6 +50,7 @@ public:
        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 {
index 92858fb..54fd533 100644 (file)
@@ -24,6 +24,7 @@
 #include <tzplatform_config.h>
 
 #include <multi_assistant_service.h>
+#include <multi_assistant_internal.h>
 
 #ifdef __cplusplus
 extern "C" {
@@ -55,6 +56,8 @@ typedef void (*wakeup_service_streaming_section_changed_cb)(ma_audio_streaming_d
 
 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;
@@ -130,6 +133,8 @@ EXPORT_API int wakeup_manager_set_streaming_section_changed_callback(wakeup_serv
 
 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);
index 352ebbe..7119251 100644 (file)
@@ -379,6 +379,9 @@ bool CWakeupManager::change_manager_state(wakeup_manager_state_e state)
 {
        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;
 }
 
index 2325bcb..5fe6469 100644 (file)
@@ -48,6 +48,9 @@ static void* g_streaming_section_changed_user_data;
 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;
@@ -56,6 +59,7 @@ class CWakeupEventObserver : public IWakeupEventObserver
        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
@@ -110,6 +114,9 @@ int wakeup_manager_initialize(void)
        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]");
@@ -644,6 +651,22 @@ int wakeup_manager_set_wakeup_engine_command_callback(wakeup_service_engine_comm
        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;
@@ -706,6 +729,13 @@ void CWakeupEventObserver::on_wakeup_engine_command(
        }
 }
 
+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) {
index 1fb2ed4..664a111 100644 (file)
@@ -512,6 +512,57 @@ int masc_dbus_send_wakeup_engine_command(int pid, const char* command)
        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()) {
index 9a8790c..4c38cd2 100644 (file)
@@ -35,6 +35,14 @@ int masc_dbus_active_state_change(int pid, int state);
 
 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);
index 0361e22..7faabf5 100644 (file)
@@ -75,6 +75,7 @@ static const char *g_wakeup_maclient_appid = NULL;
 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;
@@ -259,6 +260,8 @@ int mas_client_initialize(int pid)
                } 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");
        }
@@ -1129,7 +1132,6 @@ int mas_prelaunch_default_assistant()
        return 0;
 }
 
-
 ma_preprocessing_allow_mode_e get_preprocessing_allow_mode(const char* appid)
 {
        for (int loop = 0; loop < MAX_MACLIENT_INFO_NUM; loop++) {
@@ -1253,6 +1255,34 @@ int mas_process_preprocessing_state_event(PREPROCESSING_STATE_EVENT event)
        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;
index aca5001..a486a84 100644 (file)
@@ -367,6 +367,13 @@ static void __wakeup_engine_command_cb(mas_wakeup_engine_command_target_e target
        }
 }
 
+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]");
@@ -488,6 +495,9 @@ int multi_assistant_service_plugin_initialize(void)
        _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) {
@@ -1068,6 +1078,12 @@ int multi_assistant_service_plugin_set_callbacks(void)
                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;
 }
 
@@ -1230,4 +1246,22 @@ int multi_assistant_service_plugin_set_wakeup_engine_command_callback(wakeup_ser
                }
        }
        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;
+}
+