Enable sending wakeup engine commands to the dependency module 38/218438/2
authorJi-hoon Lee <dalton.lee@samsung.com>
Fri, 22 Nov 2019 05:18:09 +0000 (14:18 +0900)
committerJi-hoon Lee <dalton.lee@samsung.com>
Fri, 22 Nov 2019 07:48:58 +0000 (16:48 +0900)
Change-Id: I27db2e1cc1da263428d800dc3b02dab6d5770df3

12 files changed:
inc/multi_wakeup_recognizer.h
plugins/wakeup-manager/dependency-default/inc/dependency_default.h
plugins/wakeup-manager/dependency-default/src/dependency_default.cpp
plugins/wakeup-manager/inc/dependency_resolver.h
plugins/wakeup-manager/inc/wakeup_engine_manager.h
plugins/wakeup-manager/inc/wakeup_manager.h
plugins/wakeup-manager/inc/wakeup_manager_wrapper.h
plugins/wakeup-manager/src/dependency_resolver.cpp
plugins/wakeup-manager/src/wakeup_engine_manager.cpp
plugins/wakeup-manager/src/wakeup_manager.cpp
plugins/wakeup-manager/src/wakeup_manager_wrapper.cpp
src/multi_assistant_service_plugin.c

index f928720..03e6685 100644 (file)
@@ -91,6 +91,12 @@ typedef enum {
        MA_AUDIO_STREAMING_DATA_SECTION_WAKE_WORD,              /**< Wake word section started */
 } ma_audio_streaming_data_section_e;
 
+typedef enum {
+       WAKEUP_ENGINE_COMMAND_TARGET_ALL_ASSISTANTS = 0,        /**< All assistants - name not required */
+       WAKEUP_ENGINE_COMMAND_TARGET_SPECIFIC_ASSISTANTS,       /**< Specific assistant - name required */
+       WAKEUP_ENGINE_COMMAND_TARGET_DEPENDENCY_MODULE,         /**< Dependency module - name not required */
+} wakeup_engine_command_target_e;
+
 typedef void (*ma_audio_streaming_data_section_changed_cb)(ma_audio_streaming_data_section_e section, void* user_data);
 
 typedef void (*wakeup_service_wakeup_event_cb)(wakeup_event_info wakeup_info, const char* wakeup_word, void* user_data);
@@ -105,7 +111,7 @@ typedef void (*wakeup_service_error_cb)(int error, const char* err_msg, void* us
 
 typedef void (*wakeup_service_streaming_section_changed_cb)(ma_audio_streaming_data_section_e section, void* user_data);
 
-typedef void (*wakeup_service_wakeup_engine_command_cb)(const char* assistant_name, const char* command, void* user_data);
+typedef void (*wakeup_service_wakeup_engine_command_cb)(wakeup_engine_command_target_e target, const char* assistant_name, const char* command, void* user_data);
 
 #ifdef __cplusplus
 }
index 2598200..f0e3c29 100644 (file)
@@ -68,6 +68,7 @@ EXPORT_API int mas_dependency_set_recording_session(unsigned int session);
 EXPORT_API int mas_dependency_set_background_volume(double ratio);
 EXPORT_API int mas_dependency_get_audio_format(int* rate, int* channel, int* audio_type);
 EXPORT_API int mas_dependency_get_audio_source_type(char** type);
+EXPORT_API int mas_dependency_process_wakeup_engine_command(const char* engine_name, const char* command);
 
 #ifdef __cplusplus
 }
index edff076..e3d859d 100644 (file)
@@ -88,3 +88,9 @@ int mas_dependency_get_audio_source_type(char** type)
        dependency_default_audio_get_audio_source_type(type);
        return 0;
 }
+
+int mas_dependency_process_wakeup_engine_command(const char* engine_name, const char* command)
+{
+       LOGD("Wakeup Engine %s has sent a command : %s", engine_name, command);
+       return 0;
+}
\ No newline at end of file
index b1ed068..2f7271a 100644 (file)
@@ -43,6 +43,7 @@ int dependency_resolver_set_recording_session(unsigned int);
 int dependency_resolver_set_background_volume(double ratio);
 int dependency_resolver_get_audio_format(int* rate, int* channel, int* audio_type);
 int dependency_resolver_get_audio_source_type(char** type);
+int dependency_resolver_process_wakeup_engine_command(const char* engine, const char* command);
 
 /**************************************************************************************
  *** Definitions for dependencies
@@ -73,6 +74,8 @@ typedef int (*mas_dependency_set_background_volume)(double ratio);
 typedef int (*mas_dependency_get_audio_format)(int* rate, int* channel, int* audio_type);
 #define MAS_DEPENDENCY_FUNC_GET_AUDIO_SOURCE_TYPE "mas_dependency_get_audio_source_type"
 typedef int (*mas_dependency_get_audio_source_type)(char** type);
+#define MAS_DEPENDENCY_FUNC_PROCESS_WAKEUP_ENGINE_COMMAND "mas_dependency_process_wakeup_engine_command"
+typedef int (*mas_dependency_process_wakeup_engine_command)(const char* engine_name, const char* command);
 
 typedef struct {
        mas_dependency_initialize                                                               initialize;
@@ -84,6 +87,7 @@ typedef struct {
        mas_dependency_set_background_volume                                    set_background_volume;
        mas_dependency_get_audio_format                                                 get_audio_format;
        mas_dependency_get_audio_source_type                                    get_audio_source_type;
+       mas_dependency_process_wakeup_engine_command                    process_wakeup_engine_command;
 } mas_dependency;
 
 #ifdef __cplusplus
index 8789ee8..cdf6f69 100644 (file)
@@ -130,7 +130,8 @@ public:
        virtual bool on_streaming_audio_data(
                wakeup_speech_streaming_event_e event, void* buffer, unsigned int len) = 0;
        virtual bool on_audio_streaming_data_section(ma_audio_streaming_data_section_e section) = 0;
-       virtual bool on_wakeup_engine_command(string assistant_name, string command) = 0;
+       virtual bool on_wakeup_engine_command(
+               wakeup_engine_command_target_e target, string engine_name, string assistant_name, string command) = 0;
 };
 
 class CWakeupEngineManager
@@ -173,7 +174,8 @@ public:
        bool on_speech_status(string engine_name, wakeup_service_speech_status_e status);
        bool on_error(string engine_name, int error_code, string error_message);
        bool on_audio_data_require_status(string engine_name, bool require);
-       bool on_wakeup_engine_command(string engine_name, string assistant_name, string command);
+       bool on_wakeup_engine_command(string engine_name,
+               wakeup_engine_command_target_e target, string assistant_name, string command);
 private:
        typedef struct {
                int version;
index ef2574d..3c7ba95 100644 (file)
@@ -48,7 +48,8 @@ public:
        virtual void on_streaming_audio_data(
                wakeup_speech_streaming_event_e event, void* buffer, unsigned int len) = 0;
        virtual void on_audio_streaming_data_section(ma_audio_streaming_data_section_e section) = 0;
-       virtual void on_wakeup_engine_command(const char* assistant_name, const char* command) = 0;
+       virtual void on_wakeup_engine_command(
+               wakeup_engine_command_target_e target, const char* name, const char* command) = 0;
 };
 
 class ISettingValueObserver {
@@ -139,7 +140,8 @@ private:
                bool on_streaming_audio_data(
                        wakeup_speech_streaming_event_e event, void* buffer, unsigned int len) override;
                bool on_audio_streaming_data_section(ma_audio_streaming_data_section_e section) override;
-               bool on_wakeup_engine_command(string assistant_name, string command) override;
+               bool on_wakeup_engine_command(
+                       wakeup_engine_command_target_e target, string engine, string name, string command) override;
 
                void set_wakeup_manager(CWakeupManager *manager) { mWakeupManager = manager; }
        private:
index 561d855..1e975b9 100644 (file)
@@ -55,6 +55,12 @@ typedef enum {
        MA_AUDIO_STREAMING_DATA_SECTION_WAKE_WORD,              /**< Wake word section started */
 } ma_audio_streaming_data_section_e;
 
+typedef enum {
+       WAKEUP_ENGINE_COMMAND_TARGET_ALL_ASSISTANTS = 0,        /**< All assistants - name not required */
+       WAKEUP_ENGINE_COMMAND_TARGET_SPECIFIC_ASSISTANT,        /**< Specific assistant - name required */
+       WAKEUP_ENGINE_COMMAND_TARGET_DEPENDENCY_MODULE,         /**< Dependency module - name not required */
+} wakeup_engine_command_target_e;
+
 typedef void (*ma_audio_streaming_data_section_changed_cb)(ma_audio_streaming_data_section_e section, void* user_data);
 
 typedef void (*wakeup_service_wakeup_event_cb)(wakeup_event_info wakeup_info, void* user_data);
@@ -71,7 +77,7 @@ typedef void (*wakeup_service_audio_data_require_status_cb)(bool require, void*
 
 typedef void (*wakeup_service_streaming_section_changed_cb)(ma_audio_streaming_data_section_e section, void* user_data);
 
-typedef void (*wakeup_service_engine_command_cb)(const char* assistant_name, const char* command, void* user_data);
+typedef void (*wakeup_service_engine_command_cb)(wakeup_engine_command_target_e target, const char* assistant_name, const char* command, void* user_data);
 
 typedef enum {
        MA_PLUGIN_EVENT_VOICE_KEY_PRESSED = 0,
index 43b080d..b15eef8 100644 (file)
@@ -86,6 +86,9 @@ int dependency_resolver_initialize(mas_proxy_interface interface)
        g_mas_dependency.get_audio_source_type =
                (mas_dependency_get_audio_source_type)dlsym(g_handle,
                MAS_DEPENDENCY_FUNC_GET_AUDIO_SOURCE_TYPE);
+       g_mas_dependency.process_wakeup_engine_command =
+               (mas_dependency_process_wakeup_engine_command)dlsym(g_handle,
+               MAS_DEPENDENCY_FUNC_PROCESS_WAKEUP_ENGINE_COMMAND);
 
        int ret = -1;
        int dependency_version = 0;
@@ -316,3 +319,28 @@ int dependency_resolver_get_audio_source_type(char** type)
 
        return ret;
 }
+
+int dependency_resolver_process_wakeup_engine_command(const char* engine, const char* command)
+{
+       int ret = -1;
+       if (NULL != g_handle) {
+               mas_dependency_process_wakeup_engine_command func = g_mas_dependency.process_wakeup_engine_command;
+               if (NULL == func) {
+                       MAS_LOGE("[ERROR] symbol lookup failed : %s", MAS_DEPENDENCY_FUNC_PROCESS_WAKEUP_ENGINE_COMMAND);
+               } else {
+                       try {
+                               ret = func(engine, command);
+                       } catch (const std::exception& e) {
+                               MAS_LOGE("[ERROR] %s of dependency module threw exception : %s",
+                                       MAS_DEPENDENCY_FUNC_PROCESS_WAKEUP_ENGINE_COMMAND, e.what());
+                       }
+                       if (0 != ret) {
+                               MAS_LOGE("[ERROR] Fail to process wakeup engine command, ret(%d)", ret);
+                       }
+               }
+       } else {
+               MAS_LOGE("[ERROR] g_handle is not valid");
+       }
+
+       return ret;
+}
index d9f6d7e..f75f958 100644 (file)
@@ -590,21 +590,29 @@ bool CWakeupEngineManager::on_audio_data_require_status(string engine_name, bool
        return true;
 }
 
-bool CWakeupEngineManager::on_wakeup_engine_command(string engine_name, string assistant_name, string command)
+bool CWakeupEngineManager::on_wakeup_engine_command(string engine_name, wakeup_engine_command_target_e target, string assistant_name, string command)
 {
        MWR_LOGD("[ENTER]");
 
        for (const auto& observer : mObservers) {
                if (observer) {
-                       const auto& iter = find_if(mEngineInfo.begin(), mEngineInfo.end(),
-                               [engine_name](const EngineInfo& info) {
-                                       return (0 == info.engine_name.compare(engine_name));
-                               });
-                       if (mEngineInfo.end() != iter) {
-                               for (const auto& assistant : iter->assistant_list) {
-                                       if (0 == assistant_name.compare(assistant) || 0 == assistant_name.length())
-                                       if (!observer->on_wakeup_engine_command(assistant, command)) {
-                                               LOGE("[Recorder WARNING] One of the observer returned false");
+                       if (WAKEUP_ENGINE_COMMAND_TARGET_DEPENDENCY_MODULE == target) {
+                               if (!observer->on_wakeup_engine_command(target, engine_name, assistant_name, command)) {
+                                       LOGE("[Recorder WARNING] One of the observer returned false");
+                               }
+                       } else {
+                               const auto& iter = find_if(mEngineInfo.begin(), mEngineInfo.end(),
+                                       [engine_name](const EngineInfo& info) {
+                                               return (0 == info.engine_name.compare(engine_name));
+                                       });
+                               if (mEngineInfo.end() != iter) {
+                                       for (const auto& assistant : iter->assistant_list) {
+                                               if (0 == assistant_name.compare(assistant) ||
+                                                       WAKEUP_ENGINE_COMMAND_TARGET_ALL_ASSISTANTS == target) {
+                                                       if (!observer->on_wakeup_engine_command(target, engine_name, assistant, command)) {
+                                                               LOGE("[Recorder WARNING] One of the observer returned false");
+                                                       }
+                                               }
                                        }
                                }
                        }
@@ -754,13 +762,14 @@ void CWakeupEngineManager::add_engine(string name, string path)
 
                if (info.interface.set_wakeup_engine_command_callback) {
                        info.interface.set_wakeup_engine_command_callback(
-                               [](const char* assistant_name, const char* command, void* user_data) {
+                               [](wakeup_engine_command_target_e target,
+                                       const char* assistant_name, const char* command, void* user_data) {
                                        CallbackUserData* data = static_cast<CallbackUserData*>(user_data);
                                        if (nullptr == data) return;
                                        if (nullptr == data->manager) return;
                                        if (nullptr == command) return;
                                        data->manager->on_wakeup_engine_command(
-                                               data->engine_name, (assistant_name ? assistant_name : ""), command);
+                                               data->engine_name, target, (assistant_name ? assistant_name : ""), command);
                                }, &(callback_user_data.back()));
                }
 
index d0b0e05..d4e82fc 100644 (file)
@@ -910,13 +910,20 @@ bool CWakeupManager::CEngineEventObserver::on_audio_streaming_data_section(
 }
 
 bool CWakeupManager::CEngineEventObserver::on_wakeup_engine_command(
-       string assistant_name, string command)
+       wakeup_engine_command_target_e target, string engine_name, string assistant_name, string command)
 {
        if (nullptr == mWakeupManager) return false;
 
-       vector<IWakeupEventObserver*> observers = mWakeupManager->get_wakeup_observers();
-       for (const auto& observer : observers) {
-               observer->on_wakeup_engine_command(assistant_name.c_str(), command.c_str());
+       if (WAKEUP_ENGINE_COMMAND_TARGET_DEPENDENCY_MODULE == target) {
+               dependency_resolver_process_wakeup_engine_command(engine_name.c_str(), command.c_str());
+       }
+
+       if (WAKEUP_ENGINE_COMMAND_TARGET_ALL_ASSISTANTS == target ||
+               WAKEUP_ENGINE_COMMAND_TARGET_SPECIFIC_ASSISTANT == target) {
+               vector<IWakeupEventObserver*> observers = mWakeupManager->get_wakeup_observers();
+               for (const auto& observer : observers) {
+                       observer->on_wakeup_engine_command(target, assistant_name.c_str(), command.c_str());
+               }
        }
 
        return true;
index 5e041ee..1abfbdf 100644 (file)
@@ -54,7 +54,8 @@ class CWakeupEventObserver : public IWakeupEventObserver
        void on_streaming_audio_data(
                wakeup_speech_streaming_event_e event, void* buffer, unsigned int len) override;
        void on_audio_streaming_data_section(ma_audio_streaming_data_section_e section) override;
-       void on_wakeup_engine_command(const char* assistant_name, const char* command) override;
+       void on_wakeup_engine_command(
+               wakeup_engine_command_target_e target, const char* assistant_name, const char* command) override;
 };
 
 class CSettingValueObserver : public ISettingValueObserver
@@ -683,10 +684,10 @@ void CWakeupEventObserver::on_audio_streaming_data_section(
 }
 
 void CWakeupEventObserver::on_wakeup_engine_command(
-       const char* assistant_name, const char* command)
+       wakeup_engine_command_target_e target, const char* assistant_name, const char* command)
 {
        if (g_wakeup_engine_command_cb) {
-               g_wakeup_engine_command_cb(assistant_name, command, g_wakeup_engine_command_user_data);
+               g_wakeup_engine_command_cb(target, assistant_name, command, g_wakeup_engine_command_user_data);
        }
 }
 
index 3af09f0..892eed3 100644 (file)
@@ -354,7 +354,7 @@ static void __streaming_section_changed_cb(ma_audio_streaming_data_section_e sec
        }
 }
 
-static void __wakeup_engine_command_cb(const char* assistant_name, const char* command, void* user_data)
+static void __wakeup_engine_command_cb(wakeup_engine_command_target_e target, const char* assistant_name, const char* command, void* user_data)
 {
        MAS_LOGD( "[SUCCESS] __wakeup_engine_command_cb is called, command(%s)", command);