Merge branch 'tizen_5.5' into tizen
[platform/core/uifw/multi-assistant-service.git] / plugins / wakeup-manager / inc / wakeup_engine_manager.h
index bcfd9b8..68993cf 100644 (file)
@@ -1,5 +1,5 @@
 /*
- * Copyright 2018  Samsung Electronics Co., Ltd
+ * Copyright 2018-2019 Samsung Electronics Co., Ltd
  *
  * Licensed under the Flora License, Version 1.1 (the License);
  * you may not use this file except in compliance with the License.
 #ifndef _WAKEUP_ENGINE_MANAGER_H_
 #define _WAKEUP_ENGINE_MANAGER_H_
 
-#include "wakeup_manager.h"
+#include "wakeup_manager_wrapper.h"
 
 #include <atomic>
 #include <string>
 #include <thread>
 #include <vector>
+#include <set>
 
 namespace multiassistant
 {
@@ -38,6 +39,7 @@ using namespace std;
 /* Need to check whether this dedicated engine path also needs to be configurable */
 #define MA_WAKEUP_DEDICATED_ENGINE_PATH                        "shared/lib/libwakeup-engine.so"
 
+/* Interfaces without version information */
 #define MA_WAKEUP_ENGINE_FUNC_INITIALIZE "wakeup_engine_initialize"
 typedef int (*wakeup_engine_initialize)(void);
 #define MA_WAKEUP_ENGINE_FUNC_DEINITIALIZE "wakeup_engine_deinitialize"
@@ -48,12 +50,16 @@ typedef int (*wakeup_engine_activate)(void);
 typedef int (*wakeup_engine_deactivate)(void);
 #define MA_WAKEUP_ENGINE_FUNC_ADD_WAKEUP_WORD "wakeup_engine_add_wakeup_word"
 typedef int (*wakeup_engine_add_wakeup_word)(const char* appid, const char* wakeup_word, const char* language);
+#define MA_WAKEUP_ENGINE_FUNC_REMOVE_WAKEUP_WORD "wakeup_engine_remove_wakeup_word"
+typedef int (*wakeup_engine_remove_wakeup_word)(const char* appid, const char* wakeup_word, const char* language);
 #define MA_WAKEUP_ENGINE_FUNC_ADD_LANGUAGE "wakeup_engine_add_language"
 typedef int (*wakeup_engine_add_language)(const char* appid, const char* language);
 #define MA_WAKEUP_ENGINE_FUNC_SET_LANGUAGE "wakeup_engine_set_language"
 typedef int (*wakeup_engine_set_language)(const char* language);
 #define MA_WAKEUP_ENGINE_FUNC_UPDATE_MANAGER_STATE "wakeup_engine_update_manager_state"
 typedef int (*wakeup_engine_update_manager_state)(wakeup_manager_state_e state);
+#define MA_WAKEUP_ENGINE_FUNC_UPDATE_RECOGNITION_RESULT "wakeup_engine_update_recognition_result"
+typedef int (*wakeup_engine_update_recognition_result)(const char* appid, int result);
 #define MA_WAKEUP_ENGINE_FUNC_SET_AUDIO_FORMAT "wakeup_engine_set_audio_format"
 typedef int (*wakeup_engine_set_audio_format)(int rate, int channel, int audio_type);
 #define MA_WAKEUP_ENGINE_FUNC_GET_AUDIO_FORMAT "wakeup_engine_get_audio_format"
@@ -63,9 +69,15 @@ typedef int (*wakeup_engine_feed_audio_data)(long time, void* data, int len);
 #define MA_WAKEUP_ENGINE_FUNC_GET_UTTERANCE_DATA_COUNT "wakeup_engine_get_utterance_data_count"
 typedef int (*wakeup_engine_get_utterance_data_count)(void);
 #define MA_WAKEUP_ENGINE_FUNC_GET_UTTERANCE_DATA "wakeup_engine_get_utterance_data"
-typedef int (*wakeup_engine_get_utterance_data)(int index, wakeup_speech_data *data);
+typedef int (*wakeup_engine_get_utterance_data)(int index, mas_speech_data *data);
+#define MA_WAKEUP_ENGINE_FUNC_GET_WAKE_WORD_DATA_COUNT "wakeup_engine_get_wake_word_data_count"
+typedef int (*wakeup_engine_get_wake_word_data_count)(void);
+#define MA_WAKEUP_ENGINE_FUNC_GET_WAKE_WORD_DATA "wakeup_engine_get_wake_word_data"
+typedef int (*wakeup_engine_get_wake_word_data)(int index, mas_speech_data *data);
 #define MA_WAKEUP_ENGINE_FUNC_SET_ASSISTANT_SPECIFIC_COMMAND "wakeup_engine_set_assistant_specific_command"
 typedef int (*wakeup_engine_set_assistant_specific_command)(const char* appid, const char* command);
+#define MA_WAKEUP_ENGINE_FUNC_SET_WAKE_WORD_AUDIO_REQUIRE_FLAG "wakeup_engine_set_wake_word_audio_require_flag"
+typedef int (*wakeup_engine_set_wake_word_audio_require_flag)(bool require);
 #define MA_WAKEUP_ENGINE_FUNC_SET_WAKEUP_EVENT_CALLBACK "wakeup_engine_set_wakeup_event_callback"
 typedef int (*wakeup_engine_set_wakeup_event_callback)(wakeup_service_wakeup_event_cb callback, void* user_data);
 #define MA_WAKEUP_ENGINE_FUNC_SET_SPEECH_STATUS_CALLBACK "wakeup_engine_set_speech_status_callback"
@@ -74,6 +86,14 @@ typedef int (*wakeup_engine_set_speech_status_callback)(wakeup_service_speech_st
 typedef int (*wakeup_engine_set_error_callback)(wakeup_service_error_cb callback, void* user_data);
 #define MA_WAKEUP_ENGINE_FUNC_SET_AUDIO_DATA_REQUIRE_STATUS_CALLBACK "wakeup_engine_set_audio_data_require_status_callback"
 typedef int (*wakeup_engine_set_audio_data_require_status_callback)(wakeup_service_audio_data_require_status_cb callback, void* user_data);
+#define MA_WAKEUP_ENGINE_FUNC_SET_WAKEUP_ENGINE_COMMAND_CALLBACK "wakeup_engine_set_wakeup_engine_command_callback"
+typedef int (*wakeup_engine_set_wakeup_engine_command_callback)(wakeup_service_engine_command_cb callback, void* user_data);
+
+/* Interfaces after version 1 */
+#define MA_WAKEUP_ENGINE_FUNC_GET_VERSION "wakeup_engine_get_version"
+typedef int (*wakeup_engine_get_version)(int* version);
+#define MA_WAKEUP_ENGINE_FUNC_SET_DEPENDENCY_MODULE_COMMAND "wakeup_engine_set_dependency_module_command"
+typedef int (*wakeup_engine_set_dependency_module_command)(const char* command);
 
 typedef struct {
        wakeup_engine_initialize                                                                initialize;
@@ -81,38 +101,50 @@ typedef struct {
        wakeup_engine_activate                                                                  activate;
        wakeup_engine_deactivate                                                                deactivate;
        wakeup_engine_add_wakeup_word                                                   add_wakeup_word;
+       wakeup_engine_remove_wakeup_word                                                remove_wakeup_word;
        wakeup_engine_add_language                                                              add_language;
        wakeup_engine_set_language                                                              set_language;
        wakeup_engine_update_manager_state                                              update_manager_state;
+       wakeup_engine_update_recognition_result                                 update_recognition_result;
        wakeup_engine_set_audio_format                                                  set_audio_format;
        wakeup_engine_get_audio_format                                                  get_audio_format;
        wakeup_engine_feed_audio_data                                                   feed_audio_data;
        wakeup_engine_get_utterance_data_count                                  get_utterance_data_count;
        wakeup_engine_get_utterance_data                                                get_utterance_data;
+       wakeup_engine_get_wake_word_data_count                                  get_wake_word_data_count;
+       wakeup_engine_get_wake_word_data                                                get_wake_word_data;
+       wakeup_engine_get_version                                                               get_version;
        wakeup_engine_set_assistant_specific_command                    set_assistant_specific_command;
+       wakeup_engine_set_wake_word_audio_require_flag                  set_wake_word_audio_require_flag;
+       wakeup_engine_set_dependency_module_command                             set_dependency_module_command;
        wakeup_engine_set_wakeup_event_callback                                 set_wakeup_event_callback;
        wakeup_engine_set_speech_status_callback                                set_speech_status_callback;
        wakeup_engine_set_error_callback                                                set_error_callback;
        wakeup_engine_set_audio_data_require_status_callback    set_audio_data_require_status_callback;
+       wakeup_engine_set_wakeup_engine_command_callback                set_wakeup_engine_command_callback;
 } wakeup_engine_interface;
 
 class IEngineEventObserver
 {
 public:
-       virtual ~IEngineEventObserver() {}
-       virtual bool on_wakeup_event(string engine_name, wakeup_event_info info) = 0;
-       virtual bool on_speech_status(string engine_name, wakeup_service_speech_status_e status) = 0;
+       virtual ~IEngineEventObserver() = default;
+       virtual bool on_wakeup_event(string engine_name, mas_wakeup_event_info wakeup_info) = 0;
+       virtual bool on_speech_status(string engine_name, mas_speech_status_e status) = 0;
        virtual bool on_error(string engine_name, int error_code, string error_message) = 0;
        virtual bool on_audio_data_require_status(string engine_name, bool require) = 0;
 
        virtual bool on_streaming_audio_data(
-               wakeup_speech_streaming_event_e event, void* buffer, unsigned int len) = 0;
+               mas_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(
+               mas_wakeup_engine_command_target_e target, string engine_name, string assistant_name, string command) = 0;
 };
 
 class CWakeupEngineManager
 {
 public:
        CWakeupEngineManager();
+       CWakeupEngineManager(IEngineEventObserver *observer);
        virtual ~CWakeupEngineManager();
 
        CWakeupEngineManager(const CWakeupEngineManager&) = delete;
@@ -125,36 +157,48 @@ public:
        void unsubscribe(IEngineEventObserver *observer);
 
        bool get_audio_data_required();
-       void set_selected_wakeup_info(wakeup_event_info info);
+       void set_selected_wakeup_info(mas_wakeup_event_info wakeup_info);
+
+       bool set_language(string language);
+       bool set_assistant_language(string appid, string language);
+       void set_assistant_activated(string appid, bool activated);
+       bool get_assistant_activated(string appid);
+       void set_wake_word_audio_require_flag(bool require);
 
        void start_streaming_current_utterance_data();
        void stop_streaming_current_utterance_data();
 
        void update_manager_state(wakeup_manager_state_e state);
+       void update_recognition_result(string appid, int result);
 
-       void engine_add_target_assistant(const string engine_name, const string appid);
-       void engine_add_wakeup_word(const string appid, const string wakeup_word, const string language);
-       void engine_set_assistant_specific_command(const string appid, const string command);
+       void engine_add_target_assistant(string engine_name, string appid);
+       void engine_add_wakeup_word(string appid, string wakeup_word, string language);
+       void engine_remove_wakeup_word(string appid, string wakeup_word, string language);
+       void engine_set_assistant_specific_command(string appid, string command);
+       void engine_set_dependency_module_command(string engine_name, string command);
        void engine_feed_audio_data(long time, void* data, int len);
 
-       bool on_wakeup_event(string engine_name, wakeup_event_info info);
-       bool on_speech_status(string engine_name, wakeup_service_speech_status_e status);
+       bool on_wakeup_event(string engine_name, mas_wakeup_event_info wakeup_info);
+       bool on_speech_status(string engine_name, mas_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,
+               mas_wakeup_engine_command_target_e target, string assistant_name, string command);
 private:
        typedef struct {
+               int version;
                string engine_name;
-               bool active{false};
-               bool enabled{false};
+               bool activated{false};
                bool audio_data_require_status{false};
                string engine_path;
                wakeup_engine_interface interface{nullptr, };
                vector<string> assistant_list;
+               set<string> activated_assistants;
                void *engine_handle{nullptr};
        } EngineInfo;
 
-       void add_engine_directory(const string name, const string path);
-       void add_engine(const string name, const string path);
+       void add_engine_directory(string name, string path);
+       void add_engine(string name, string path);
 
        vector<IEngineEventObserver*> mObservers;
 
@@ -166,6 +210,9 @@ private:
 
        thread mStreamingThread;
        atomic_bool mStopStreamingThread{false};
+       wakeup_manager_state_e mWakeupManagerState{WAKEUP_MANAGER_STATE_INACTIVE};
+
+       bool mWakeWordAudioRequired{false};
 };
 
 } // wakeup