Divide wakeup manager into a class and its wrapper
authorJi-hoon Lee <dalton.lee@samsung.com>
Mon, 1 Apr 2019 05:14:40 +0000 (14:14 +0900)
committerJi-hoon Lee <dalton.lee@samsung.com>
Mon, 1 Apr 2019 07:00:38 +0000 (16:00 +0900)
Change-Id: I094ab7c4061fcad48a23fb91e547ec4f3ec1cb81

16 files changed:
plugins/wakeup-manager/CMakeLists.txt
plugins/wakeup-manager/inc/wakeup_audio_manager.h
plugins/wakeup-manager/inc/wakeup_engine_manager.h
plugins/wakeup-manager/inc/wakeup_manager.h
plugins/wakeup-manager/inc/wakeup_manager_wrapper.h [new file with mode: 0644]
plugins/wakeup-manager/inc/wakeup_policy.h
plugins/wakeup-manager/inc/wakeup_policy_default.h
plugins/wakeup-manager/inc/wakeup_policy_impl.h
plugins/wakeup-manager/inc/wakeup_settings.h
plugins/wakeup-manager/src/wakeup_audio_manager.cpp
plugins/wakeup-manager/src/wakeup_engine_manager.cpp
plugins/wakeup-manager/src/wakeup_manager.cpp
plugins/wakeup-manager/src/wakeup_manager_wrapper.cpp [new file with mode: 0644]
plugins/wakeup-manager/src/wakeup_policy.cpp
plugins/wakeup-manager/src/wakeup_policy_default.cpp
plugins/wakeup-manager/src/wakeup_settings.cpp

index 91f0ed7..69e8f36 100644 (file)
@@ -52,6 +52,7 @@ SET(SRCS
        src/wakeup_policy_default.cpp
        src/wakeup_audio_manager.cpp
        src/wakeup_engine_manager.cpp
+       src/wakeup_manager_wrapper.cpp
 )
 
 FOREACH(flag ${wmpkgs_CFLAGS})
index 1315314..1ba4b77 100644 (file)
@@ -33,10 +33,12 @@ namespace multiassistant
 namespace wakeup
 {
 
+using namespace std;
+
 class IAudioEventObserver
 {
 public:
-       virtual ~IAudioEventObserver() {}
+       virtual ~IAudioEventObserver() = default;
        virtual bool on_recording_audio_data(long time, void* data, int len) = 0;
        virtual bool on_streaming_audio_data(
                wakeup_speech_streaming_event_e event, void* buffer, unsigned int len) = 0;
@@ -46,6 +48,7 @@ class CAudioManager
 {
 public:
        CAudioManager();
+       CAudioManager(IAudioEventObserver *observer);
        ~CAudioManager();
 
        CAudioManager(const CAudioManager&) = delete;
@@ -80,27 +83,25 @@ private:
        void streaming_speech_data_thread_func();
        void streaming_background_data_thread_func(long start_time);
 
-       long get_current_milliseconds_after_epoch();
-
-       std::vector<IAudioEventObserver*> mObservers;
+       vector<IAudioEventObserver*> mObservers;
 
        audio_in_h mAudioIn{nullptr};
        sound_stream_info_h mStreamInfo{nullptr};
 
-       std::thread mRecorderThread;
-       std::atomic_bool mStopRecorderThread{false};
+       thread mRecorderThread;
+       atomic_bool mStopRecorderThread{false};
 
-       std::thread mStreamingThread;
-       std::atomic_bool mStopStreamingThread{false};
+       thread mStreamingThread;
+       atomic_bool mStopStreamingThread{false};
 
        static constexpr long mBackgroundRecordingDurationMilliseconds = 10 * 1000;
        typedef struct {
                long time;
                wakeup_speech_data data;
        } wakeup_speech_data_with_time;
-       std::vector<wakeup_speech_data_with_time> mSpeechData;
-       std::vector<wakeup_speech_data_with_time> mPreviousSpeechData;
-       std::list<wakeup_speech_data_with_time> mBackgroundData;
+       vector<wakeup_speech_data_with_time> mSpeechData;
+       vector<wakeup_speech_data_with_time> mPreviousSpeechData;
+       list<wakeup_speech_data_with_time> mBackgroundData;
        bool mVoiceKeyPressed{false};
 };
 
index bcfd9b8..e64faf7 100644 (file)
@@ -17,7 +17,7 @@
 #ifndef _WAKEUP_ENGINE_MANAGER_H_
 #define _WAKEUP_ENGINE_MANAGER_H_
 
-#include "wakeup_manager.h"
+#include "wakeup_manager_wrapper.h"
 
 #include <atomic>
 #include <string>
@@ -99,7 +99,7 @@ typedef struct {
 class IEngineEventObserver
 {
 public:
-       virtual ~IEngineEventObserver() {}
+       virtual ~IEngineEventObserver() = default;
        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 bool on_error(string engine_name, int error_code, string error_message) = 0;
@@ -113,6 +113,7 @@ class CWakeupEngineManager
 {
 public:
        CWakeupEngineManager();
+       CWakeupEngineManager(IEngineEventObserver *observer);
        virtual ~CWakeupEngineManager();
 
        CWakeupEngineManager(const CWakeupEngineManager&) = delete;
@@ -132,9 +133,9 @@ public:
 
        void update_manager_state(wakeup_manager_state_e state);
 
-       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_set_assistant_specific_command(string appid, string command);
        void engine_feed_audio_data(long time, void* data, int len);
 
        bool on_wakeup_event(string engine_name, wakeup_event_info info);
@@ -153,8 +154,8 @@ private:
                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;
 
index 7886b9e..c04d3a0 100644 (file)
 #ifndef _WAKEUP_MANAGER_H_
 #define _WAKEUP_MANAGER_H_
 
-#include <dlog.h>
-#include <stdbool.h>
-#include <tzplatform_config.h>
-
-#include "wakeup_interfaces.h"
-
-#ifdef __cplusplus
-extern "C" {
-#endif
-
-#ifndef EXPORT_API
-       #if defined _WIN32 || defined __CYGWIN__
-       #ifdef BUILDING_DLL
-               #ifdef __GNUC__
-               #define EXPORT_API __attribute__ ((dllexport))
-               #else
-               #define EXPORT_API __declspec(dllexport) // Note: actually gcc seems to also supports this syntax.
-               #endif
-       #else
-               #ifdef __GNUC__
-               #define EXPORT_API __attribute__ ((dllimport))
-               #else
-               #define EXPORT_API __declspec(dllimport) // Note: actually gcc seems to also supports this syntax.
-               #endif
-       #endif
-       #define DLL_LOCAL
-       #else
-       #if __GNUC__ >= 4
-               #define EXPORT_API __attribute__ ((visibility ("default")))
-               #define DLL_LOCAL  __attribute__ ((visibility ("hidden")))
-       #else
-               #define EXPORT_API
-               #define DLL_LOCAL
-       #endif
-       #endif
-#endif
-
-typedef enum {
-       WAKEUP_SPEECH_STATUS_NONE = -1,                                         /**< None */
-       WAKEUP_SPEECH_STATUS_BEGINNING_POINT_DETECTED = 1,      /**< Beginning point of speech is detected */
-       WAKEUP_SPEECH_STATUS_END_POINT_DETECTED = 2             /**< End point of speech is detected */
-} wakeup_service_speech_status_e;
-
-typedef enum {
-       WAKEUP_MANAGER_STATE_INACTIVE = 0,
-       WAKEUP_MANAGER_STATE_LISTENING = 1,
-       WAKEUP_MANAGER_STATE_UTTERANCE = 2,
-       WAKEUP_MANAGER_STATE_PROCESSING = 3,
-       WAKEUP_MANAGER_STATE_VOICE_FEEDBACK = 4
-} wakeup_manager_state_e;
-
-typedef void (*wakeup_service_wakeup_event_cb)(wakeup_event_info info, void* user_data);
-
-typedef void (*wakeup_service_speech_streaming_cb)(wakeup_speech_streaming_event_e event, void* buffer, int len, void *user_data);
-
-typedef void (*wakeup_service_speech_status_cb)(wakeup_service_speech_status_e status, void *user_data);
-
-typedef void (*wakeup_service_error_cb)(int error, const char* err_msg, void* user_data);
-
-typedef void (*wakeup_service_audio_data_require_status_cb)(bool require, void* user_data);
-
-EXPORT_API int wakeup_manager_initialize(void);
-
-EXPORT_API int wakeup_manager_deinitialize(void);
-
-EXPORT_API int wakeup_manager_add_assistant_wakeup_word(const char* appid, const char* wakeup_word, const char* language);
-
-EXPORT_API int wakeup_manager_add_assistant_language(const char* appid, const char* language);
-
-EXPORT_API int wakeup_manager_set_assistant_wakeup_engine(const char* appid, const char *engine);
-
-EXPORT_API int wakeup_manager_set_assistant_enabled(const char* appid, int enabled);
-
-EXPORT_API int wakeup_manager_set_language(const char* language);
-
-EXPORT_API int wakeup_manager_activate(void);
-
-EXPORT_API int wakeup_manager_deactivate(void);
-
-EXPORT_API int wakeup_manager_update_voice_feedback_state(const char *appid, int state);
-
-EXPORT_API int wakeup_manager_send_assistant_specific_command(const char* appid, const char* command);
-
-EXPORT_API int wakeup_manager_update_result_state(const char *appid, int state);
-
-EXPORT_API int wakeup_manager_process_event(int event, void* data, int len);
-
-EXPORT_API int wakeup_manager_start_streaming_utterance_data(void);
-
-EXPORT_API int wakeup_manager_stop_streaming_utterance_data(void);
-
-EXPORT_API int wakeup_manager_start_streaming_previous_utterance_data(void);
-
-EXPORT_API int wakeup_manager_stop_streaming_previous_utterance_data(void);
-
-EXPORT_API int wakeup_manager_start_streaming_follow_up_data(void);
-
-EXPORT_API int wakeup_manager_stop_streaming_follow_up_data(void);
-
-EXPORT_API int wakeup_manager_get_audio_format(int *rate, int *channel, int *audio_type);
-
-EXPORT_API int wakeup_manager_set_wakeup_event_callback(wakeup_service_wakeup_event_cb callback, void* user_data);
-
-EXPORT_API int wakeup_manager_set_utterance_streaming_callback(wakeup_service_speech_streaming_cb callback, void* user_data);
-
-EXPORT_API int wakeup_manager_set_previous_utterance_streaming_callback(wakeup_service_speech_streaming_cb callback, void* user_data);
-
-EXPORT_API int wakeup_manager_set_follow_up_streaming_callback(wakeup_service_speech_streaming_cb callback, void* user_data);
-
-EXPORT_API int wakeup_manager_set_speech_status_callback(wakeup_service_speech_status_cb callback, void* user_data);
-
-EXPORT_API int wakeup_manager_set_error_callback(wakeup_service_error_cb callback, void* user_data);
-
-typedef enum {
-       MA_PLUGIN_EVENT_VOICE_KEY_PRESSED = 0,
-       MA_PLUGIN_EVENT_VOICE_KEY_RELEASED,
-} ma_plugin_event_e;
-
-#ifdef __cplusplus
-}
-#endif
+#include "wakeup_manager_wrapper.h"
+#include "wakeup_settings.h"
+#include "wakeup_engine_manager.h"
+#include "wakeup_audio_manager.h"
+#include "wakeup_policy_default.h"
+
+#include <memory>
+
+namespace multiassistant
+{
+namespace wakeup
+{
+
+using namespace std;
+
+enum class STREAMING_MODE {
+       NONE,
+       UTTERANCE,
+       PREVIOUS_UTTERANCE,
+       FOLLOW_UP,
+};
+
+class IWakeupEventObserver {
+       public:
+               virtual ~IWakeupEventObserver() = default;
+               virtual void on_wakeup(wakeup_event_info info) = 0;
+               virtual void on_streaming_audio_data(
+                       wakeup_speech_streaming_event_e event, void* buffer, unsigned int len) = 0;
+       };
+
+class CWakeupManager
+{
+public:
+       CWakeupManager(IWakeupEventObserver *observer);
+       virtual ~CWakeupManager();
+
+       CWakeupManager(const CWakeupManager&) = delete;
+       CWakeupManager& operator=(const CWakeupManager&) = delete;
+
+       bool initialize();
+       bool deinitialize();
+
+       void subscribe(IWakeupEventObserver *observer);
+       void unsubscribe(IWakeupEventObserver *observer);
+
+       bool activate();
+       bool deactivate();
+
+       bool add_assistant_language(string appid, string language);
+       bool add_assistant_wakeup_word(string appid, string wakeup_word, string language);
+       bool set_assistant_wakeup_engine(string appid, string engine);
+       bool set_assistant_enabled(string appid, bool enabled);
+
+       bool update_voice_feedback_state(string appid, bool state);
+       bool send_assistant_specific_command(string appid, string command);
+       bool update_result_state(string appid, int state);
+       bool process_event(ma_plugin_event_e event, void* data, int len);
+       bool get_audio_format(int* rate, int* channel, int* audio_type);
+       bool set_language(string language);
+       bool get_voice_key_pressed();
+
+       STREAMING_MODE get_streaming_mode();
+       bool set_streaming_mode(STREAMING_MODE mode);
+
+       bool start_streaming_utterance_data();
+       bool stop_streaming_utterance_data();
+       bool start_streaming_follow_up_data();
+       bool stop_streaming_follow_up_data();
+       bool start_streaming_previous_utterance_data();
+       bool stop_streaming_previous_utterance_data();
+
+       CWakeupPolicy* get_wakeup_policy();
+       CWakeupEngineManager* get_engine_manager();
+       CAudioManager* get_audio_manager();
+
+       vector<IWakeupEventObserver*> get_observers();
+       void set_last_wakeup_event_info(wakeup_event_info info);
+
+       bool change_manager_state(wakeup_manager_state_e state);
+private:
+       class CEngineEventObserver : public IEngineEventObserver
+       {
+       public:
+               bool on_wakeup_event(string engine_name, wakeup_event_info info) override;
+               bool on_speech_status(string engine_name, wakeup_service_speech_status_e status) override;
+               bool on_error(string engine_name, int error_code, string error_message) override;
+               bool on_audio_data_require_status(string engine_name, bool require) override;
+
+               bool on_streaming_audio_data(
+                       wakeup_speech_streaming_event_e event, void* buffer, unsigned int len) override;
+
+               void set_wakeup_manager(CWakeupManager *manager) { mWakeupManager = manager; }
+       private:
+               CWakeupManager *mWakeupManager{nullptr};
+       };
+
+       class CPolicyEventObserver : public IPolicyEventObserver
+       {
+       public:
+               void on_wakeup(wakeup_event_info info) override;
+
+               void set_wakeup_manager(CWakeupManager *manager) { mWakeupManager = manager; }
+       private:
+               CWakeupManager *mWakeupManager{nullptr};
+       };
+
+       class CAudioEventObserver : public IAudioEventObserver
+       {
+       public:
+               bool on_recording_audio_data(long time, void* data, int len) override;
+               bool on_streaming_audio_data(
+                       wakeup_speech_streaming_event_e event, void* buffer, unsigned int len) override;
+
+               void set_wakeup_manager(CWakeupManager *manager) { mWakeupManager = manager; }
+               void set_wakeup_engine_manager(CWakeupEngineManager *manager) { mEngineManager = manager; }
+       private:
+               CWakeupManager *mWakeupManager{nullptr};
+               CWakeupEngineManager *mEngineManager{nullptr};
+       };
+
+       void initialize_wakeup_policy();
+
+       vector<IWakeupEventObserver*> mObservers;
+
+       unique_ptr<CWakeupPolicy> mWakeupPolicy;
+
+       CAudioManager mAudioManager;
+       CWakeupEngineManager mWakeupEngineManager;
+       CWakeupSettings mWakeupSettings;
+
+       CAudioEventObserver mAudioEventObserver;
+       CEngineEventObserver mEngineEventObserver;
+       CPolicyEventObserver mPolicyEventObserver;
+
+       thread mEngineDataThread;
+       atomic_bool mStopEngineDataThread{false};
+
+       bool mVoiceKeyPressed{false};
+       string mCurrentLanguage;
+
+       STREAMING_MODE mStreamingMode{STREAMING_MODE::NONE};
+       Ecore_Timer* mStreamingDurationTimer{nullptr};
+
+       wakeup_manager_state_e mWakeupManagerState{WAKEUP_MANAGER_STATE_INACTIVE};
+       wakeup_event_info mLastWakeupEventInfo;
+};
+
+} // wakeup
+} // multiassistant
 
 #endif /* _WAKEUP_MANAGER_H_ */
diff --git a/plugins/wakeup-manager/inc/wakeup_manager_wrapper.h b/plugins/wakeup-manager/inc/wakeup_manager_wrapper.h
new file mode 100644 (file)
index 0000000..8ecf262
--- /dev/null
@@ -0,0 +1,143 @@
+/*
+ * Copyright 2018  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.
+ * You may obtain a copy of the License at
+ *
+ * http://floralicense.org/license/
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an AS IS BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+
+#ifndef _WAKEUP_MANAGER_WRAPPER_H_
+#define _WAKEUP_MANAGER_WRAPPER_H_
+
+#include <dlog.h>
+#include <stdbool.h>
+#include <tzplatform_config.h>
+
+#include "wakeup_interfaces.h"
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+#ifndef EXPORT_API
+       #if defined _WIN32 || defined __CYGWIN__
+       #ifdef BUILDING_DLL
+               #ifdef __GNUC__
+               #define EXPORT_API __attribute__ ((dllexport))
+               #else
+               #define EXPORT_API __declspec(dllexport) // Note: actually gcc seems to also supports this syntax.
+               #endif
+       #else
+               #ifdef __GNUC__
+               #define EXPORT_API __attribute__ ((dllimport))
+               #else
+               #define EXPORT_API __declspec(dllimport) // Note: actually gcc seems to also supports this syntax.
+               #endif
+       #endif
+       #define DLL_LOCAL
+       #else
+       #if __GNUC__ >= 4
+               #define EXPORT_API __attribute__ ((visibility ("default")))
+               #define DLL_LOCAL  __attribute__ ((visibility ("hidden")))
+       #else
+               #define EXPORT_API
+               #define DLL_LOCAL
+       #endif
+       #endif
+#endif
+
+typedef enum {
+       WAKEUP_SPEECH_STATUS_NONE = -1,                                         /**< None */
+       WAKEUP_SPEECH_STATUS_BEGINNING_POINT_DETECTED = 1,      /**< Beginning point of speech is detected */
+       WAKEUP_SPEECH_STATUS_END_POINT_DETECTED = 2             /**< End point of speech is detected */
+} wakeup_service_speech_status_e;
+
+typedef enum {
+       WAKEUP_MANAGER_STATE_INACTIVE = 0,
+       WAKEUP_MANAGER_STATE_LISTENING = 1,
+       WAKEUP_MANAGER_STATE_UTTERANCE = 2,
+       WAKEUP_MANAGER_STATE_PROCESSING = 3,
+       WAKEUP_MANAGER_STATE_VOICE_FEEDBACK = 4
+} wakeup_manager_state_e;
+
+typedef void (*wakeup_service_wakeup_event_cb)(wakeup_event_info info, void* user_data);
+
+typedef void (*wakeup_service_speech_streaming_cb)(wakeup_speech_streaming_event_e event, void* buffer, int len, void *user_data);
+
+typedef void (*wakeup_service_speech_status_cb)(wakeup_service_speech_status_e status, void *user_data);
+
+typedef void (*wakeup_service_error_cb)(int error, const char* err_msg, void* user_data);
+
+typedef void (*wakeup_service_audio_data_require_status_cb)(bool require, void* user_data);
+
+typedef enum {
+       MA_PLUGIN_EVENT_VOICE_KEY_PRESSED = 0,
+       MA_PLUGIN_EVENT_VOICE_KEY_RELEASED,
+} ma_plugin_event_e;
+
+EXPORT_API int wakeup_manager_initialize(void);
+
+EXPORT_API int wakeup_manager_deinitialize(void);
+
+EXPORT_API int wakeup_manager_add_assistant_wakeup_word(const char* appid, const char* wakeup_word, const char* language);
+
+EXPORT_API int wakeup_manager_add_assistant_language(const char* appid, const char* language);
+
+EXPORT_API int wakeup_manager_set_assistant_wakeup_engine(const char* appid, const char *engine);
+
+EXPORT_API int wakeup_manager_set_assistant_enabled(const char* appid, int enabled);
+
+EXPORT_API int wakeup_manager_set_language(const char* language);
+
+EXPORT_API int wakeup_manager_activate(void);
+
+EXPORT_API int wakeup_manager_deactivate(void);
+
+EXPORT_API int wakeup_manager_update_voice_feedback_state(const char *appid, int state);
+
+EXPORT_API int wakeup_manager_send_assistant_specific_command(const char* appid, const char* command);
+
+EXPORT_API int wakeup_manager_update_result_state(const char *appid, int state);
+
+EXPORT_API int wakeup_manager_process_event(int event, void* data, int len);
+
+EXPORT_API int wakeup_manager_start_streaming_utterance_data(void);
+
+EXPORT_API int wakeup_manager_stop_streaming_utterance_data(void);
+
+EXPORT_API int wakeup_manager_start_streaming_previous_utterance_data(void);
+
+EXPORT_API int wakeup_manager_stop_streaming_previous_utterance_data(void);
+
+EXPORT_API int wakeup_manager_start_streaming_follow_up_data(void);
+
+EXPORT_API int wakeup_manager_stop_streaming_follow_up_data(void);
+
+EXPORT_API int wakeup_manager_get_audio_format(int *rate, int *channel, int *audio_type);
+
+EXPORT_API int wakeup_manager_set_wakeup_event_callback(wakeup_service_wakeup_event_cb callback, void* user_data);
+
+EXPORT_API int wakeup_manager_set_utterance_streaming_callback(wakeup_service_speech_streaming_cb callback, void* user_data);
+
+EXPORT_API int wakeup_manager_set_previous_utterance_streaming_callback(wakeup_service_speech_streaming_cb callback, void* user_data);
+
+EXPORT_API int wakeup_manager_set_follow_up_streaming_callback(wakeup_service_speech_streaming_cb callback, void* user_data);
+
+EXPORT_API int wakeup_manager_set_speech_status_callback(wakeup_service_speech_status_cb callback, void* user_data);
+
+EXPORT_API int wakeup_manager_set_error_callback(wakeup_service_error_cb callback, void* user_data);
+
+#ifdef __cplusplus
+}
+#endif
+
+#endif /* _WAKEUP_MANAGER_WRAPPER_H_ */
index be35679..71ed0a1 100644 (file)
@@ -27,10 +27,12 @@ namespace multiassistant
 namespace wakeup
 {
 
-class IWakeupEventObserver
+using namespace std;
+
+class IPolicyEventObserver
 {
 public:
-       virtual ~IWakeupEventObserver() {}
+       virtual ~IPolicyEventObserver() = default;
        virtual void on_wakeup(wakeup_event_info info) = 0;
 };
 
@@ -40,17 +42,18 @@ class CWakeupPolicy
 {
 public:
        CWakeupPolicy();
+       CWakeupPolicy(IPolicyEventObserver *observer);
        virtual ~CWakeupPolicy();
 
        CWakeupPolicy(const CWakeupPolicy&) = delete;
        CWakeupPolicy& operator=(const CWakeupPolicy&) = delete;
 
-       void subscribe(IWakeupEventObserver *observer);
-       void unsubscribe(IWakeupEventObserver *observer);
+       void subscribe(IPolicyEventObserver *observer);
+       void unsubscribe(IPolicyEventObserver *observer);
 
        virtual void wakeup_candidate(wakeup_event_info info) = 0;
 protected:
-       std::unique_ptr<CWakeupPolicyImpl> mImpl;
+       unique_ptr<CWakeupPolicyImpl> mImpl;
 };
 
 } // wakeup
index 524aa6b..619d6b5 100644 (file)
@@ -29,26 +29,29 @@ namespace multiassistant
 namespace wakeup
 {
 
+using namespace std;
+
 class CWakeupPolicyDefault : public CWakeupPolicy
 {
 public:
        CWakeupPolicyDefault();
+       CWakeupPolicyDefault(IPolicyEventObserver *observer);
        ~CWakeupPolicyDefault();
 
-       void set_assistant_priority(std::string appid, int priority);
+       void set_assistant_priority(string appid, int priority);
        void set_delay(float seconds);
 
        void wakeup_candidate(wakeup_event_info info);
        void timer_expired();
 private:
        typedef struct {
-               std::string appid;
+               string appid;
                int priority{0};
        } PRIORITY_INFO;
 
        float mDelaySeconds{0.0f};
-       std::vector<PRIORITY_INFO> mPriorityInfos;
-       std::vector<wakeup_event_info> mWakeupInfos;
+       vector<PRIORITY_INFO> mPriorityInfos;
+       vector<wakeup_event_info> mWakeupInfos;
 
        Ecore_Timer *mTimer{nullptr};
 };
index bec11fd..a072250 100644 (file)
@@ -32,12 +32,12 @@ public:
        CWakeupPolicyImpl() {}
        ~CWakeupPolicyImpl() {}
 
-       void subscribe(IWakeupEventObserver *observer);
-       void unsubscribe(IWakeupEventObserver *observer);
+       void subscribe(IPolicyEventObserver *observer);
+       void unsubscribe(IPolicyEventObserver *observer);
 
        void wakeup(wakeup_event_info info);
 private:
-       std::vector<IWakeupEventObserver*> mObservers;
+       vector<IPolicyEventObserver*> mObservers;
 };
 
 } // wakeup
index d4743f2..95a49ad 100644 (file)
@@ -25,6 +25,8 @@ namespace multiassistant
 namespace wakeup
 {
 
+using namespace std;
+
 #define DEFAULT_ASSISTANT_APPID "org.tizen.voice-app"
 
 #define WAKEUP_SETTINGS_KEY_DEFAULT_ASSISTANT_APPID "db/multi-assistant/default_assistant_appid"
@@ -48,23 +50,23 @@ public:
        void initialize();
        void deinitialize();
 
-       std::string get_default_assistant_appid();
+       string get_default_assistant_appid();
        bool get_ui_panel_enabled();
        float get_conversation_timeout();
        bool get_multiple_mode();
-       std::vector<std::string> get_enabled_assistants();
+       vector<string> get_enabled_assistants();
        float get_wakeup_policy_delay();
-       std::vector<std::string> get_wakeup_policy_priority();
+       vector<string> get_wakeup_policy_priority();
        float get_streaming_duration_max();
 
 private:
-       std::string mDefaultAssistantAppid{DEFAULT_ASSISTANT_APPID};
+       string mDefaultAssistantAppid{DEFAULT_ASSISTANT_APPID};
        bool mUiPanelEnabled{true};
        float mConversationTimeout{5.0};
        bool mMultipleMode{true};
-       std::vector<std::string> mEnabledAssistants{DEFAULT_ASSISTANT_APPID};
+       vector<string> mEnabledAssistants{DEFAULT_ASSISTANT_APPID};
        float mWakeupPolicyDelay{0.1};
-       std::vector<std::string> mWakeupPolicyPriority; // No priority by default
+       vector<string> mWakeupPolicyPriority; // No priority by default
        float mStreamingDurationMax{10.0};
 };
 
index 77f69e8..c0c7b5c 100644 (file)
@@ -27,6 +27,11 @@ CAudioManager::~CAudioManager()
 {
 }
 
+CAudioManager::CAudioManager(IAudioEventObserver *observer) : CAudioManager()
+{
+       subscribe(observer);
+}
+
 #ifdef TV_PRODUCT
 static void _bt_cb_hid_state_changed(int result, bool connected, const char *remote_address, void *user_data)
 {
@@ -192,12 +197,22 @@ void CAudioManager::subscribe(IAudioEventObserver *observer)
 
 void CAudioManager::unsubscribe(IAudioEventObserver *observer)
 {
-       auto iter = std::find(mObservers.begin(), mObservers.end(), observer);
+       auto iter = find(mObservers.begin(), mObservers.end(), observer);
        if (iter != mObservers.end()) {
                mObservers.erase(iter);
        }
 }
 
+static long get_current_milliseconds_after_epoch()
+{
+       auto now = chrono::system_clock::now();
+       auto now_ms = chrono::time_point_cast<chrono::milliseconds>(now);
+       /* number of milliseconds since the epoch of system_clock */
+       auto value = now_ms.time_since_epoch();
+
+       return value.count();
+}
+
 #define FRAME_LENGTH 160
 #define BUFFER_LENGTH FRAME_LENGTH * 2
 
@@ -300,7 +315,7 @@ void CAudioManager::start_recording()
                                break;
                        } else if (BT_ERROR_NOW_IN_PROGRESS == ret) {
                                MWR_LOGE("[Recorder ERROR] Fail bt_hid_send_rc_command : %d", ret);
-                               std::this_thread::sleep_for(std::chrono::milliseconds(50));
+                               this_thread::sleep_for(chrono::milliseconds(50));
                                bt_retry++;
                        } else {
                                break;
@@ -317,7 +332,8 @@ void CAudioManager::start_recording()
 #endif
        {
                mStopRecorderThread.store(false);
-               mRecorderThread = std::thread(&CAudioManager::recorder_thread_func, this);
+               MWR_LOGD("Starting recorder thread");
+               mRecorderThread = thread(&CAudioManager::recorder_thread_func, this);
        }
 }
 
@@ -340,7 +356,7 @@ void CAudioManager::streaming_speech_data_thread_func()
 
                        /* waiting */
                        while (1) {
-                               std::this_thread::sleep_for(std::chrono::milliseconds(10));
+                               this_thread::sleep_for(chrono::milliseconds(10));
                                if (index < mSpeechData.size()) {
                                        MWR_LOGI("[INFO] Resume thread");
                                        break;
@@ -378,7 +394,7 @@ void CAudioManager::streaming_speech_data_thread_func()
                if (WAKEUP_SPEECH_STREAMING_EVENT_FINISH == speech_data.event) {
                        MWR_LOGI("[INFO] Finish to get and send speech data");
                        /* Now move all the speech data to previous speech data for later use */
-                       mPreviousSpeechData = std::move(mSpeechData);
+                       mPreviousSpeechData = move(mSpeechData);
                        break;
                }
 
@@ -394,7 +410,7 @@ void CAudioManager::streaming_background_data_thread_func(long start_time)
        auto iter = lead;
        while (lead != mBackgroundData.end() && lead->time < start_time) {
                iter = lead;
-               std::advance(lead, 1);
+               advance(lead, 1);
        }
 
        MWR_LOGD("data_count : %zu", mBackgroundData.size());
@@ -410,13 +426,13 @@ void CAudioManager::streaming_background_data_thread_func(long start_time)
 
                        /* waiting */
                        while (1) {
-                               std::this_thread::sleep_for(std::chrono::milliseconds(10));
+                               this_thread::sleep_for(chrono::milliseconds(10));
                                if (iter == mBackgroundData.end()) {
                                        iter = mBackgroundData.begin();
                                }
                                lead = iter;
                                if (lead != mBackgroundData.end()) {
-                                       std::advance(lead, 1);
+                                       advance(lead, 1);
                                }
                                if (lead != mBackgroundData.end()) {
                                        MWR_LOGI("[INFO] Resume thread");
@@ -459,11 +475,11 @@ void CAudioManager::streaming_background_data_thread_func(long start_time)
                if (WAKEUP_SPEECH_STREAMING_EVENT_FINISH == speech_data.event) {
                        MWR_LOGI("[INFO] Finish to get and send speech data");
                        /* Now move all the speech data to previous speech data for later use */
-                       mPreviousSpeechData = std::move(mSpeechData);
+                       mPreviousSpeechData = move(mSpeechData);
                        break;
                }
 
-               std::advance(lead, 1);
+               advance(lead, 1);
        }
 }
 
@@ -507,9 +523,9 @@ void CAudioManager::start_streaming_current_utterance_data(bool from_start_time,
        }
        if (from_start_time) {
                mSpeechData.clear();
-               mStreamingThread = std::thread(&CAudioManager::streaming_background_data_thread_func, this, start_time);
+               mStreamingThread = thread(&CAudioManager::streaming_background_data_thread_func, this, start_time);
        } else {
-               mStreamingThread = std::thread(&CAudioManager::streaming_speech_data_thread_func, this);
+               mStreamingThread = thread(&CAudioManager::streaming_speech_data_thread_func, this);
        }
 }
 
@@ -523,7 +539,7 @@ void CAudioManager::stop_streaming_current_utterance_data()
        mStopStreamingThread.store(false);
 
        /* Now move all the speech data to previous speech data for later use */
-       mPreviousSpeechData = std::move(mSpeechData);
+       mPreviousSpeechData = move(mSpeechData);
 }
 
 void CAudioManager::start_streaming_previous_utterance_data()
@@ -557,15 +573,5 @@ bool CAudioManager::voice_key_pressed_get()
        return mVoiceKeyPressed;
 }
 
-long CAudioManager::get_current_milliseconds_after_epoch()
-{
-       auto now = std::chrono::system_clock::now();
-       auto now_ms = std::chrono::time_point_cast<std::chrono::milliseconds>(now);
-       /* number of milliseconds since the epoch of system_clock */
-       auto value = now_ms.time_since_epoch();
-
-       return value.count();
-}
-
 } // wakeup
 } // multiassistant
index 94c0263..ae1b05c 100644 (file)
@@ -18,6 +18,11 @@ CWakeupEngineManager::~CWakeupEngineManager()
 {
 }
 
+CWakeupEngineManager::CWakeupEngineManager(IEngineEventObserver *observer) : CWakeupEngineManager()
+{
+       subscribe(observer);
+}
+
 void CWakeupEngineManager::initialize()
 {
        DIR* dp = opendir(MA_WAKEUP_ENGINE_PATH);
@@ -219,7 +224,7 @@ void CWakeupEngineManager::update_manager_state(wakeup_manager_state_e state)
        }
 }
 
-void CWakeupEngineManager::engine_add_target_assistant(const string engine_name, const string appid)
+void CWakeupEngineManager::engine_add_target_assistant(string engine_name, string appid)
 {
        const auto& iter = find_if(mEngineInfo.begin(), mEngineInfo.end(),
                [engine_name](const EngineInfo& info) {
@@ -255,7 +260,7 @@ void CWakeupEngineManager::engine_add_target_assistant(const string engine_name,
        }
 }
 
-void CWakeupEngineManager::engine_add_wakeup_word(const string appid, const string wakeup_word, const string language)
+void CWakeupEngineManager::engine_add_wakeup_word(string appid, string wakeup_word, string language)
 {
        for (const auto& info : mEngineInfo) {
                auto iter = find(
@@ -270,7 +275,7 @@ void CWakeupEngineManager::engine_add_wakeup_word(const string appid, const stri
        }
 }
 
-void CWakeupEngineManager::engine_set_assistant_specific_command(const string appid, const string command)
+void CWakeupEngineManager::engine_set_assistant_specific_command(string appid, string command)
 {
        for (const auto& info : mEngineInfo) {
                auto iter = find(
@@ -379,7 +384,7 @@ bool CWakeupEngineManager::on_audio_data_require_status(string engine_name, bool
        return true;
 }
 
-void CWakeupEngineManager::add_engine(const string name, const string path)
+void CWakeupEngineManager::add_engine(string name, string path)
 {
        sleep(10);
        MWR_LOGD("Name (%s), Filepath(%s)", name.c_str(), path.c_str());
@@ -501,7 +506,7 @@ void CWakeupEngineManager::add_engine(const string name, const string path)
        }
 }
 
-void CWakeupEngineManager::add_engine_directory(const string name, const string path)
+void CWakeupEngineManager::add_engine_directory(string name, string path)
 {
        if (0 == path.size()) return;
 
index c46f8d2..10d052f 100644 (file)
  * See the License for the specific language governing permissions and
  * limitations under the License.
  */
-#include <Ecore.h>
-#include <dirent.h>
 
-#include <thread>
-#include <atomic>
-#include <vector>
-#include <memory>
-#include <algorithm>
-
-#include "wakeup_manager_main.h"
 #include "wakeup_manager.h"
-#include "wakeup_settings.h"
-#include "wakeup_engine_manager.h"
-#include "wakeup_audio_manager.h"
+#include "wakeup_manager_main.h"
 #include "wakeup_policy_default.h"
 
-#ifdef TV_PRODUCT
-#include <Ecore_Input.h>
+#include <algorithm>
 
+namespace multiassistant
+{
+namespace wakeup
+{
+
+#ifdef TV_PRODUCT
 #define EFL_BETA_API_SUPPORT
 
+#include <Ecore_Input.h>
 #include <Ecore_Wl2.h>
 #include <Key_Mode.h>
 
-Ecore_Event_Handler* _key_down_handler = NULL;
-Ecore_Event_Handler* _key_up_handler = NULL;
-
-#endif
-
-using namespace multiassistant::wakeup;
-
-bool g_voice_key_pressed = false;
-
-static std::thread g_engine_data_thread;
-static std::atomic_bool g_engine_data_thread_should_stop;
-
-static wakeup_service_wakeup_event_cb g_wakeup_event_cb;
-static void* g_wakeup_event_user_data;
-
-static wakeup_service_speech_streaming_cb g_utterance_streaming_cb;
-static void* g_utterance_streaming_user_data;
-
-static wakeup_service_speech_streaming_cb g_previous_utterance_streaming_cb;
-static void* g_previous_utterance_streaming_user_data;
-
-static wakeup_service_speech_streaming_cb g_follow_up_streaming_cb;
-static void* g_follow_up_streaming_user_data;
-
-static wakeup_service_speech_status_cb g_speech_status_cb;
-static void* g_speech_status_user_data;
-
-static wakeup_service_error_cb g_error_cb;
-static void* g_error_user_data;
-
-static char* g_current_language = NULL;
-static wakeup_manager_state_e g_wakeup_manager_state;
-
-static wakeup_event_info g_last_wakeup_event_info;
+static Ecore_Event_Handler* _key_down_handler = NULL;
+static Ecore_Event_Handler* _key_up_handler = NULL;
 
-static CWakeupSettings g_wakeup_settings;
-
-class CEngineEventObserver : public IEngineEventObserver
-{
-public:
-       bool on_wakeup_event(string engine_name, wakeup_event_info info) override;
-       bool on_speech_status(string engine_name, wakeup_service_speech_status_e status) override;
-       bool on_error(string engine_name, int error_code, string error_message) override;
-       bool on_audio_data_require_status(string engine_name, bool require) override;
-
-       bool on_streaming_audio_data(
-               wakeup_speech_streaming_event_e event, void* buffer, unsigned int len) override;
-};
-static CWakeupEngineManager g_wakeup_engine_manager;
-static CEngineEventObserver g_engine_event_observer;
-
-enum STREAMING_MODE {
-       STREAMING_MODE_NONE,
-       STREAMING_MODE_UTTERANCE,
-       STREAMING_MODE_PREVIOUS_UTTERANCE,
-       STREAMING_MODE_FOLLOW_UP,
-};
-
-static STREAMING_MODE g_streaming_mode{STREAMING_MODE_NONE};
-static Ecore_Timer* g_streaming_duration_timer;
-
-class CWakeupEventObserver : public IWakeupEventObserver
-{
-public:
-       void on_wakeup(wakeup_event_info info) override;
-};
-static std::unique_ptr<CWakeupPolicy> g_wakeup_policy;
-static CWakeupEventObserver g_wakeup_event_observer;
-
-class CAudioEventObserver : public IAudioEventObserver
-{
-public:
-       CAudioEventObserver(CWakeupEngineManager *manager) : mEngineManager{manager}
-       {
-       }
-       bool on_recording_audio_data(long time, void* data, int len) override;
-    bool on_streaming_audio_data(
-        wakeup_speech_streaming_event_e event, void* buffer, unsigned int len) override;
-private:
-       CWakeupEngineManager *mEngineManager{nullptr};
-};
-static CAudioManager g_audio_manager;
-static CAudioEventObserver g_audio_event_observer{&g_wakeup_engine_manager};
-
-#ifdef TV_PRODUCT
 Eina_Bool _key_down_cb(void* data, int type, void* event)
 {
        Ecore_Event_Key *ev = (Ecore_Event_Key *) event;
@@ -208,56 +121,84 @@ bool _delete_key_cb(void)
 }
 #endif
 
-void wakeup_policy_initialize(void)
+static bool check_language_valid(string language)
+{
+       return true;
+}
+
+static bool initialize_wakeup_event_info(wakeup_event_info* info)
+{
+       bool ret = false;
+       if (info) {
+               ret = true;
+
+               info->wakeup_appid = nullptr;
+               info->wakeup_word = nullptr;
+               info->wakeup_language = nullptr;
+               info->wakeup_voice_id = nullptr;
+               info->wakeup_confidence_score = 0.0f;
+
+               info->wakeup_start_time = 0;
+               info->wakeup_end_time = 0L;
+               info->wakeup_time_valid = false;
+
+               info->extra_data = nullptr;
+               info->extra_data_length = 0;
+               info->extra_data_description = nullptr;
+       }
+       return ret;
+}
+
+CWakeupManager::CWakeupManager(IWakeupEventObserver *observer)
 {
-       g_wakeup_policy.reset(new CWakeupPolicyDefault);
-       if (g_wakeup_policy) {
-               g_wakeup_policy->subscribe(&g_wakeup_event_observer);
+       initialize_wakeup_event_info(&mLastWakeupEventInfo);
+
+       if (observer) {
+               subscribe(observer);
        }
+}
+
+CWakeupManager::~CWakeupManager()
+{
+}
+
+void CWakeupManager::initialize_wakeup_policy()
+{
+       mWakeupPolicy.reset(new CWakeupPolicyDefault{&mPolicyEventObserver});
 
        /* Default Policy specific initialization */
-       CWakeupPolicyDefault *default_policy =
-               dynamic_cast<CWakeupPolicyDefault*>(g_wakeup_policy.get());
-       if (default_policy) {
+       CWakeupPolicyDefault *policy =
+               dynamic_cast<CWakeupPolicyDefault*>(mWakeupPolicy.get());
+       if (policy) {
                int priority = 0;
 
-               default_policy->set_delay(g_wakeup_settings.get_wakeup_policy_delay());
-               MWR_LOGD("Setting Delay : %f", g_wakeup_settings.get_wakeup_policy_delay());
-               for (const auto& assistant : g_wakeup_settings.get_wakeup_policy_priority()) {
-                       default_policy->set_assistant_priority(assistant, ++priority);
+               policy->set_delay(mWakeupSettings.get_wakeup_policy_delay());
+               MWR_LOGD("Setting Delay : %f", mWakeupSettings.get_wakeup_policy_delay());
+               for (const auto& assistant : mWakeupSettings.get_wakeup_policy_priority()) {
+                       policy->set_assistant_priority(assistant, ++priority);
                        MWR_LOGD("Setting Priority : %d %s", priority, assistant.c_str());
                }
        }
 }
 
-int wakeup_manager_initialize(void)
+bool CWakeupManager::initialize()
 {
        MWR_LOGD("[ENTER]");
 
-       g_wakeup_event_cb = NULL;
-       g_wakeup_event_user_data = NULL;
+       mPolicyEventObserver.set_wakeup_manager(this);
+       mEngineEventObserver.set_wakeup_manager(this);
+       mAudioEventObserver.set_wakeup_manager(this);
 
-       g_utterance_streaming_cb = NULL;
-       g_utterance_streaming_user_data = NULL;
+       mWakeupSettings.initialize();
 
-       g_follow_up_streaming_cb = NULL;
-       g_follow_up_streaming_user_data = NULL;
+       mAudioEventObserver.set_wakeup_engine_manager(&mWakeupEngineManager);
+       mAudioManager.subscribe(&mAudioEventObserver);
+       mAudioManager.initialize();
 
-       g_speech_status_cb = NULL;
-       g_speech_status_user_data = NULL;
+       initialize_wakeup_policy();
 
-       g_error_cb = NULL;
-       g_error_user_data = NULL;
-
-       wakeup_policy_initialize();
-
-       g_wakeup_settings.initialize();
-
-       g_audio_manager.subscribe(&g_audio_event_observer);
-       g_audio_manager.initialize();
-
-       g_wakeup_engine_manager.subscribe(&g_engine_event_observer);
-       g_wakeup_engine_manager.initialize();
+       mWakeupEngineManager.subscribe(&mEngineEventObserver);
+       mWakeupEngineManager.initialize();
 
 #ifdef TV_PRODUCT
        Ecore_Wl2_Display *_ecore_wl2_display = NULL;
@@ -273,10 +214,10 @@ int wakeup_manager_initialize(void)
 #endif
 
        MWR_LOGD("[END]");
-       return 0;
+       return true;
 }
 
-int wakeup_manager_deinitialize(void)
+bool CWakeupManager::deinitialize()
 {
        MWR_LOGD("[ENTER]");
 
@@ -285,407 +226,373 @@ int wakeup_manager_deinitialize(void)
        _ungrab_voice_key();
 #endif
 
-       g_wakeup_engine_manager.unsubscribe(&g_engine_event_observer);
-       g_wakeup_engine_manager.deinitialize();
+       mWakeupEngineManager.unsubscribe(&mEngineEventObserver);
+       mWakeupEngineManager.deinitialize();
 
-       g_audio_manager.unsubscribe(&g_audio_event_observer);
-       g_audio_manager.deinitialize();
+       mAudioManager.unsubscribe(&mAudioEventObserver);
+       mAudioManager.deinitialize();
 
-       g_wakeup_settings.deinitialize();
-
-       if (g_current_language) {
-               free(g_current_language);
-               g_current_language = NULL;
-       }
+       mWakeupSettings.deinitialize();
 
        MWR_LOGD("[END]");
-       return 0;
+       return true;
+}
+
+void CWakeupManager::subscribe(IWakeupEventObserver *observer)
+{
+       mObservers.push_back(observer);
 }
 
-static int _is_valid_language(const char* language, bool* is_valid)
+void CWakeupManager::unsubscribe(IWakeupEventObserver *observer)
 {
-       if (language && is_valid) {
-               *is_valid = true;
+       auto iter = find(mObservers.begin(), mObservers.end(), observer);
+       if (iter != mObservers.end()) {
+               mObservers.erase(iter);
        }
-       return 0;
 }
 
-int wakeup_manager_add_assistant_wakeup_word(const char* appid, const char* wakeup_word, const char* language)
+bool CWakeupManager::activate(void)
 {
        MWR_LOGD("[ENTER]");
 
-       if (NULL == appid || NULL == wakeup_word) {
-               MWR_LOGD("[ERROR] Parameter is invalid, appid(%s), wakeup_word(%s), language(%s)", appid, wakeup_word, language);
-               return -1;
-       }
-       MWR_LOGD("[DEBUG] appid(%s), wakeup word(%s),language(%s)", appid, wakeup_word, language);
-       g_wakeup_engine_manager.engine_add_wakeup_word(appid, wakeup_word, language);
+       change_manager_state(WAKEUP_MANAGER_STATE_LISTENING);
 
        MWR_LOGD("[END]");
-       return 0;
+       return true;
 }
 
-int wakeup_manager_add_assistant_language(const char* appid, const char* language)
+bool CWakeupManager::deactivate(void)
 {
        MWR_LOGD("[ENTER]");
 
-       if (NULL == appid || NULL == language) {
-               MWR_LOGD("[ERROR] Parameter is invalid, appid(%s), language(%s)", appid, language);
-               return -1;
-       }
+       change_manager_state(WAKEUP_MANAGER_STATE_INACTIVE);
 
-       bool is_valid = false;
-       int ret = _is_valid_language(language, &is_valid);
-       if (0 != ret) {
-               MWR_LOGE("[ERROR] Fail to do wakeup_service_is_valid_language function (%d)", ret);
-               return ret;
-       }
-       if (is_valid == false) {
-               MWR_LOGE("[ERROR] Not supported language (%s)", language);
-               return -1;
-       }
+       MWR_LOGD("[END]");
+       return true;
+}
 
-       MWR_LOGD("[DEBUG] language(%s)", language);
+bool CWakeupManager::add_assistant_language(string appid, string language)
+{
+       MWR_LOGD("[ENTER]");
 
        MWR_LOGD("[END]");
-       return 0;
+       return true;
 }
 
-int wakeup_manager_set_assistant_wakeup_engine(const char* appid, const char* engine)
+bool CWakeupManager::add_assistant_wakeup_word(string appid, string wakeup_word, string language)
 {
        MWR_LOGD("[ENTER]");
 
-       if (NULL == appid || NULL == engine) {
-               MWR_LOGD("[ERROR] Parameter is invalid, appid(%s), wakeup engine(%s)", appid, engine);
-               return -1;
-       }
+       mWakeupEngineManager.engine_add_wakeup_word(appid, wakeup_word, language);
+
+       MWR_LOGD("[END]");
+       return true;
+}
+
+bool CWakeupManager::set_assistant_wakeup_engine(string appid, string engine)
+{
+       MWR_LOGD("[ENTER]");
 
-       MWR_LOGD("[DEBUG] appid(%s), wakeup engine(%s)", appid, engine);
-       g_wakeup_engine_manager.engine_add_target_assistant(engine, appid);
+       mWakeupEngineManager.engine_add_target_assistant(engine, appid);
 
        MWR_LOGD("[END]");
-       return 0;
+       return true;
 }
 
-int wakeup_manager_set_assistant_enabled(const char* appid, int enabbled)
+bool CWakeupManager::set_assistant_enabled(string appid, bool enabled)
 {
        MWR_LOGD("[ENTER]");
 
        MWR_LOGD("[END]");
 
-       return 0;
+       return true;
 }
 
-int wakeup_manager_set_language(const char* language)
+bool CWakeupManager::set_language(string language)
 {
+       bool ret = false;
        MWR_LOGD("[ENTER]");
 
-       int ret = 0;
-       bool is_valid = false;
-       ret = _is_valid_language(language, &is_valid);
-       if (0 != ret) {
-               MWR_LOGE("[ERROR] wakeup_service_is_valid_language fail (%d)", ret);
-               return ret;
-       }
-       if (is_valid == false) {
-               MWR_LOGE("[ERROR] Not supported language (%s)", language);
-               return -1;
+       if (check_language_valid(language)) {
+               mCurrentLanguage = language;
+               ret = true;
+       } else {
+               MWR_LOGE("[ERROR] Not supported language (%s)", language.c_str());
        }
 
-       g_current_language = strdup(language);
-
        MWR_LOGD("[END]");
-       return 0;
+       return ret;
 }
 
-int wakeup_manager_change_state(wakeup_manager_state_e state)
+bool CWakeupManager::get_voice_key_pressed()
 {
-       g_wakeup_engine_manager.update_manager_state(state);
-       return 0;
+       return mVoiceKeyPressed;
 }
 
-int wakeup_manager_activate(void)
+STREAMING_MODE CWakeupManager::get_streaming_mode()
 {
-       MWR_LOGD("[ENTER]");
-
-       wakeup_manager_change_state(WAKEUP_MANAGER_STATE_LISTENING);
-
-       MWR_LOGD("[END]");
-       return 0;
+       return mStreamingMode;
 }
 
-int wakeup_manager_deactivate(void)
+bool CWakeupManager::set_streaming_mode(STREAMING_MODE mode)
 {
-       MWR_LOGD("[ENTER]");
-
-       wakeup_manager_change_state(WAKEUP_MANAGER_STATE_INACTIVE);
+       mStreamingMode = mode;
+       return true;
+}
 
-       MWR_LOGD("[END]");
-       return 0;
+bool CWakeupManager::change_manager_state(wakeup_manager_state_e state)
+{
+       mWakeupEngineManager.update_manager_state(state);
+       return true;
 }
 
-int wakeup_manager_update_voice_feedback_state(const char* appid, int state)
+bool CWakeupManager::update_voice_feedback_state(string appid, bool state)
 {
        MWR_LOGD("[ENTER]");
 
-       if (NULL == appid) {
-               MWR_LOGD("[ERROR] Parameter is invalid, appid(%s)",
-                       (appid ? appid : "NULL"));
-               return -1;
-       }
-
        if (state) {
-               if (g_wakeup_manager_state == WAKEUP_MANAGER_STATE_LISTENING ||
-                       g_wakeup_manager_state == WAKEUP_MANAGER_STATE_PROCESSING) {
-                       wakeup_manager_change_state(WAKEUP_MANAGER_STATE_VOICE_FEEDBACK);
+               if (WAKEUP_MANAGER_STATE_LISTENING == mWakeupManagerState ||
+                       WAKEUP_MANAGER_STATE_PROCESSING == mWakeupManagerState) {
+                       change_manager_state(WAKEUP_MANAGER_STATE_VOICE_FEEDBACK);
                }
        } else {
-               if (g_wakeup_manager_state == WAKEUP_MANAGER_STATE_VOICE_FEEDBACK) {
-                       wakeup_manager_change_state(WAKEUP_MANAGER_STATE_LISTENING);
+               if (WAKEUP_MANAGER_STATE_VOICE_FEEDBACK == mWakeupManagerState) {
+                       change_manager_state(WAKEUP_MANAGER_STATE_LISTENING);
                }
        }
 
        MWR_LOGD("[END]");
-       return 0;
+       return true;
 }
 
-int wakeup_manager_send_assistant_specific_command(const char* appid, const char* command)
+bool CWakeupManager::send_assistant_specific_command(string appid, string command)
 {
        MWR_LOGD("[ENTER]");
 
-       if (NULL == appid || NULL == command) {
-               MWR_LOGD("[ERROR] Parameter is invalid, appid(%s), command(%s)",
-                       (appid ? appid : "NULL"), (command ? command : "NULL"));
-               return -1;
-       }
-
-       const char* voice_key_pressed = "voice_key_pressed";
-       const char* voice_key_released = "voice_key_released";
+       static const string voice_key_pressed{"voice_key_pressed"};
+       static const string voice_key_released{"voice_key_released"};
 
-       if (command) {
-               if (0 == strncmp(command, voice_key_pressed, strlen(voice_key_pressed))) {
-                       wakeup_manager_process_event(MA_PLUGIN_EVENT_VOICE_KEY_PRESSED, NULL, 0);
-               } else if (0 == strncmp(command, voice_key_released, strlen(voice_key_released))) {
-                       wakeup_manager_process_event(MA_PLUGIN_EVENT_VOICE_KEY_RELEASED, NULL, 0);
-               }
+       if (0 == command.compare(voice_key_pressed)) {
+               process_event(MA_PLUGIN_EVENT_VOICE_KEY_PRESSED, NULL, 0);
+       } else if (0 == command.compare(voice_key_released)) {
+               process_event(MA_PLUGIN_EVENT_VOICE_KEY_RELEASED, NULL, 0);
        }
 
-       g_wakeup_engine_manager.engine_set_assistant_specific_command(appid, command);
+       mWakeupEngineManager.engine_set_assistant_specific_command(appid, command);
 
        MWR_LOGD("[END]");
-       return 0;
+       return true;
 }
 
-int wakeup_manager_update_result_state(const char* appid, int state)
+bool CWakeupManager::update_result_state(string appid, int state)
 {
        MWR_LOGD("[ENTER]");
-       if (NULL == appid) {
-               MWR_LOGD("[ERROR] Parameter is invalid, appid(%s)",
-                       (appid ? appid : "NULL"));
-               return -1;
-       }
-       if (g_wakeup_manager_state == WAKEUP_MANAGER_STATE_PROCESSING) {
-               wakeup_manager_change_state(WAKEUP_MANAGER_STATE_LISTENING);
+       if (WAKEUP_MANAGER_STATE_PROCESSING == mWakeupManagerState) {
+               change_manager_state(WAKEUP_MANAGER_STATE_LISTENING);
        }
        MWR_LOGD("[END]");
-       return 0;
+       return true;
 }
 
-int wakeup_manager_process_event(int event, void* data, int len)
+bool CWakeupManager::process_event(ma_plugin_event_e event, void* data, int len)
 {
        MWR_LOGD("[ENTER]");
 
        // LOCK REQUIRED
-       if (event == MA_PLUGIN_EVENT_VOICE_KEY_PRESSED) {
-               if (g_voice_key_pressed != true) {
+       if (MA_PLUGIN_EVENT_VOICE_KEY_PRESSED == event) {
+               if (mVoiceKeyPressed != true) {
                        /* Clear all existing data */
-                       g_audio_manager.clear_speech_data();
+                       mAudioManager.clear_speech_data();
 
-                       g_voice_key_pressed = true;
-                       g_audio_manager.voice_key_pressed_set(g_voice_key_pressed);
+                       mVoiceKeyPressed = true;
+                       mAudioManager.voice_key_pressed_set(mVoiceKeyPressed);
                        /* (Re)Start recorder thread using bt hid */
-                       g_audio_manager.start_recording();
+                       mAudioManager.start_recording();
 
                        /* Wakeup default assistant */
                        /* TODO: apply conversation timeout for selecting assistant here */
                        wakeup_event_info event_info;
-                       std::string appid = g_wakeup_settings.get_default_assistant_appid();
+                       initialize_wakeup_event_info(&event_info);
+
+                       string appid = mWakeupSettings.get_default_assistant_appid();
                        event_info.wakeup_appid = appid.c_str();
-                       event_info.wakeup_word = nullptr;
-                       event_info.wakeup_language = nullptr;
-                       event_info.wakeup_voice_id = nullptr;
-                       event_info.wakeup_confidence_score = 0.0f;
-
-                       event_info.wakeup_start_time = 0L;
-                       event_info.wakeup_end_time = 0L;
-                       event_info.wakeup_time_valid = false;
-
-                       event_info.extra_data = nullptr;
-                       event_info.extra_data_length = 0;
-                       event_info.extra_data_description = nullptr;
-                       if (NULL != g_wakeup_event_cb) {
-                               g_wakeup_event_cb(event_info, g_wakeup_event_user_data);
+
+                       for (const auto& observer : mObservers) {
+                               observer->on_wakeup(event_info);
                        }
                }
-       } else if (event == MA_PLUGIN_EVENT_VOICE_KEY_RELEASED) {
-               if (g_voice_key_pressed != false) {
-                       g_voice_key_pressed = false;
-                       g_audio_manager.voice_key_pressed_set(g_voice_key_pressed);
-                       g_audio_manager.finalize_speech_data();
-                       if (g_wakeup_engine_manager.get_audio_data_required()) {
+       } else if (MA_PLUGIN_EVENT_VOICE_KEY_RELEASED == event) {
+               if (mVoiceKeyPressed != false) {
+                       mVoiceKeyPressed = false;
+                       mAudioManager.voice_key_pressed_set(mVoiceKeyPressed);
+                       mAudioManager.finalize_speech_data();
+                       if (mWakeupEngineManager.get_audio_data_required()) {
                                /* Restart recorder thread using standard mic */
-                               g_audio_manager.start_recording();
+                               mAudioManager.start_recording();
                        } else {
-                               g_audio_manager.stop_recording();
+                               mAudioManager.stop_recording();
                        }
                }
        }
        // UNLOCK REQUIRED
 
        MWR_LOGD("[END]");
-       return 0;
+       return true;
 }
 
-void __wakeup_service_streaming_cb(wakeup_speech_streaming_event_e event, void* buffer, unsigned int len)
+vector<IWakeupEventObserver*> CWakeupManager::get_observers()
 {
-       if (WAKEUP_SPEECH_STREAMING_EVENT_START == event) {
-               MWR_LOGD("streaming_cb START");
-       }
-       if (WAKEUP_SPEECH_STREAMING_EVENT_FINISH == event) {
-               MWR_LOGD("streaming_cb FINISH");
-       }
-       if (NULL != g_utterance_streaming_cb) {
-               g_utterance_streaming_cb(event, buffer, len, g_utterance_streaming_user_data);
-       } else {
-               MWR_LOGI("[INFO] No service streaming callback");
-       }
+       return mObservers;
+}
+
+void CWakeupManager::set_last_wakeup_event_info(wakeup_event_info info)
+{
+       mLastWakeupEventInfo = info;
 }
 
 static Eina_Bool streaming_duration_expired(void *data)
 {
        MWR_LOGD("[ENTER]");
-       switch(g_streaming_mode) {
-               case STREAMING_MODE_UTTERANCE:
-                       g_audio_manager.stop_streaming_current_utterance_data();
-                       g_wakeup_engine_manager.stop_streaming_current_utterance_data();
+       CWakeupManager *wakeup_manager = static_cast<CWakeupManager*>(data);
+       if (nullptr == wakeup_manager) return ECORE_CALLBACK_CANCEL;
+
+       CAudioManager *audio_manager = wakeup_manager->get_audio_manager();
+       CWakeupEngineManager *engine_manager = wakeup_manager->get_engine_manager();
+
+       if (nullptr == audio_manager) return ECORE_CALLBACK_CANCEL;
+       if (nullptr == engine_manager) return ECORE_CALLBACK_CANCEL;
+
+       switch(wakeup_manager->get_streaming_mode()) {
+               case STREAMING_MODE::UTTERANCE:
+                       audio_manager->stop_streaming_current_utterance_data();
+                       engine_manager->stop_streaming_current_utterance_data();
                break;
-               case STREAMING_MODE_PREVIOUS_UTTERANCE:
-                       g_audio_manager.stop_streaming_previous_utterance_data();
+               case STREAMING_MODE::PREVIOUS_UTTERANCE:
+                       audio_manager->stop_streaming_previous_utterance_data();
                break;
-               case STREAMING_MODE_FOLLOW_UP:
-                       g_audio_manager.stop_streaming_follow_up_data();
+               case STREAMING_MODE::FOLLOW_UP:
+                       audio_manager->stop_streaming_follow_up_data();
                break;
        }
 
        unsigned char final_buffer[2] = {'\0', };
-       __wakeup_service_streaming_cb(
-               WAKEUP_SPEECH_STREAMING_EVENT_FINISH, final_buffer, sizeof(final_buffer));
+       vector<IWakeupEventObserver*> observers = wakeup_manager->get_observers();
+       for (const auto& observer : observers) {
+               observer->on_streaming_audio_data(
+                       WAKEUP_SPEECH_STREAMING_EVENT_FINISH, final_buffer, sizeof(final_buffer));
+       }
+       wakeup_manager->set_streaming_mode(STREAMING_MODE::NONE);
 
-       g_streaming_mode = STREAMING_MODE_NONE;
        return ECORE_CALLBACK_CANCEL;
 }
 
-int wakeup_manager_start_streaming_utterance_data(void)
+bool CWakeupManager::start_streaming_utterance_data()
 {
        MWR_LOGD("[ENTER]");
 
-       g_streaming_mode = STREAMING_MODE_UTTERANCE;
+       mAudioManager.stop_streaming_current_utterance_data();
+       mWakeupEngineManager.stop_streaming_current_utterance_data();
 
-       g_audio_manager.stop_streaming_current_utterance_data();
-       g_wakeup_engine_manager.stop_streaming_current_utterance_data();
+       mStreamingMode = STREAMING_MODE::UTTERANCE;
 
        bool streaming_by_manager = true;
        /* What if the user pressed voice key but then again immediately releases? */
-       if (g_voice_key_pressed) {
-               g_audio_manager.start_streaming_current_utterance_data();
+       if (mVoiceKeyPressed) {
+               mAudioManager.start_streaming_current_utterance_data();
        } else {
-               if(g_last_wakeup_event_info.wakeup_time_valid) {
-                       g_audio_manager.start_streaming_current_utterance_data(true, g_last_wakeup_event_info.wakeup_end_time);
+               if(mLastWakeupEventInfo.wakeup_time_valid) {
+                       mAudioManager.start_streaming_current_utterance_data(true, mLastWakeupEventInfo.wakeup_end_time);
                } else {
+                       mWakeupEngineManager.start_streaming_current_utterance_data();
                        streaming_by_manager = false;
-                       g_wakeup_engine_manager.start_streaming_current_utterance_data();
                }
        }
 
        ecore_thread_main_loop_begin();
-       if (g_streaming_duration_timer) {
-               ecore_timer_del(g_streaming_duration_timer);
+       if (mStreamingDurationTimer) {
+               ecore_timer_del(mStreamingDurationTimer);
+               mStreamingDurationTimer = nullptr;
        }
        if (streaming_by_manager) {
-               g_streaming_duration_timer = ecore_timer_add(g_wakeup_settings.get_streaming_duration_max(),
-                       streaming_duration_expired, nullptr);
+               mStreamingDurationTimer = ecore_timer_add(
+                       mWakeupSettings.get_streaming_duration_max(),
+                       streaming_duration_expired, this);
        }
        ecore_thread_main_loop_end();
 
        MWR_LOGD("[END]");
-       return 0;
+       return true;
 }
 
-int wakeup_manager_stop_streaming_utterance_data(void)
+bool CWakeupManager::stop_streaming_utterance_data()
 {
        MWR_LOGD("[ENTER]");
-       if (g_streaming_duration_timer) {
+
+       if (mStreamingDurationTimer) {
                ecore_thread_main_loop_begin();
-               ecore_timer_del(g_streaming_duration_timer);
+               ecore_timer_del(mStreamingDurationTimer);
+               mStreamingDurationTimer = nullptr;
                ecore_thread_main_loop_end();
        }
-       if (g_wakeup_manager_state == WAKEUP_MANAGER_STATE_UTTERANCE) {
-               wakeup_manager_change_state(WAKEUP_MANAGER_STATE_PROCESSING);
+       if (WAKEUP_MANAGER_STATE_UTTERANCE == mWakeupManagerState) {
+               change_manager_state(WAKEUP_MANAGER_STATE_PROCESSING);
        }
-       g_audio_manager.stop_streaming_current_utterance_data();
-       g_wakeup_engine_manager.stop_streaming_current_utterance_data();
-       g_streaming_mode = STREAMING_MODE_NONE;
+       mAudioManager.stop_streaming_current_utterance_data();
+       mWakeupEngineManager.stop_streaming_current_utterance_data();
+
+       mStreamingMode = STREAMING_MODE::NONE;
+
        MWR_LOGD("[END]");
-       return 0;
+       return true;
 }
 
-int wakeup_manager_start_streaming_follow_up_data(void)
+bool CWakeupManager::start_streaming_follow_up_data()
 {
        MWR_LOGD("[ENTER]");
 
-       g_streaming_mode = STREAMING_MODE_FOLLOW_UP;
+       mStreamingMode = STREAMING_MODE::FOLLOW_UP;
 
        MWR_LOGD("[END]");
-       return 0;
+       return true;
 }
 
-int wakeup_manager_stop_streaming_follow_up_data(void)
+bool CWakeupManager::stop_streaming_follow_up_data()
 {
        MWR_LOGD("[ENTER]");
 
-       g_streaming_mode = STREAMING_MODE_NONE;
+       mStreamingMode = STREAMING_MODE::NONE;
 
        MWR_LOGD("[END]");
-       return 0;
+       return true;
 }
 
-int wakeup_manager_start_streaming_previous_utterance_data(void)
+bool CWakeupManager::start_streaming_previous_utterance_data()
 {
        MWR_LOGD("[ENTER]");
 
-       g_streaming_mode = STREAMING_MODE_PREVIOUS_UTTERANCE;
+       mStreamingMode = STREAMING_MODE::PREVIOUS_UTTERANCE;
 
        MWR_LOGD("[END]");
-       return 0;
+       return true;
 }
 
-int wakeup_manager_stop_streaming_previous_utterance_data(void)
+bool CWakeupManager::stop_streaming_previous_utterance_data()
 {
        MWR_LOGD("[ENTER]");
 
-       g_streaming_mode = STREAMING_MODE_NONE;
+       mStreamingMode = STREAMING_MODE::NONE;
 
        MWR_LOGD("[END]");
-       return 0;
+       return true;
 }
 
-int wakeup_manager_get_audio_format(int* rate, int* channel, int* audio_type)
+bool CWakeupManager::get_audio_format(int* rate, int* channel, int* audio_type)
 {
        MWR_LOGD("[ENTER]");
 
        if (!audio_type || !rate || !channel) {
                MWR_LOGE("[ERROR] Invalid parameter");
-               return -1;
+               return false;
        }
 
        *rate = 16000;
@@ -693,176 +600,134 @@ int wakeup_manager_get_audio_format(int* rate, int* channel, int* audio_type)
        *audio_type = 0;
 
        MWR_LOGD("[END] rate(%d), channel(%d), audio_type(%d)", *rate, *channel, *audio_type);
-       return 0;
+       return true;
 }
 
-int wakeup_manager_set_wakeup_event_callback(wakeup_service_wakeup_event_cb callback, void* user_data)
+CWakeupPolicy* CWakeupManager::get_wakeup_policy()
 {
-       MWR_LOGD("[ENTER]");
-
-       if (NULL == callback) {
-               MWR_LOGE("[ERROR] Input parameter is NULL");
-               return -1;
-       }
-
-       g_wakeup_event_cb = callback;
-       g_wakeup_event_user_data = user_data;
-
-       MWR_LOGD("[END]");
-       return 0;
+       return mWakeupPolicy.get();
 }
 
-int wakeup_manager_set_utterance_streaming_callback(wakeup_service_speech_streaming_cb callback, void* user_data)
+CWakeupEngineManager* CWakeupManager::get_engine_manager()
 {
-       MWR_LOGD("[ENTER]");
-
-       if (NULL == callback) {
-               MWR_LOGE("[ERROR] Input parameter is NULL");
-               return -1;
-       }
-
-       g_utterance_streaming_cb = callback;
-       g_utterance_streaming_user_data = user_data;
-
-       MWR_LOGD("[END]");
-       return 0;
+       return &mWakeupEngineManager;
 }
 
-int wakeup_manager_set_previous_utterance_streaming_callback(wakeup_service_speech_streaming_cb callback, void* user_data)
+CAudioManager* CWakeupManager::get_audio_manager()
 {
-       MWR_LOGD("[ENTER]");
-
-       if (NULL == callback) {
-               MWR_LOGE("[ERROR] Input parameter is NULL");
-               return -1;
-       }
-
-       g_previous_utterance_streaming_cb = callback;
-       g_previous_utterance_streaming_user_data = user_data;
-
-       MWR_LOGD("[END]");
-       return 0;
+       return &mAudioManager;
 }
 
-int wakeup_manager_set_follow_up_streaming_callback(wakeup_service_speech_streaming_cb callback, void* user_data)
+bool CWakeupManager::CEngineEventObserver::on_wakeup_event(string engine_name, wakeup_event_info info)
 {
        MWR_LOGD("[ENTER]");
+       if (nullptr == mWakeupManager) return false;
 
-       if (NULL == callback) {
-               MWR_LOGE("[ERROR] Input parameter is NULL");
-               return -1;
+       CWakeupPolicy* policy = mWakeupManager->get_wakeup_policy();
+       if (policy) {
+               policy->wakeup_candidate(info);
        }
-
-       g_follow_up_streaming_cb = callback;
-       g_follow_up_streaming_user_data = user_data;
-
-       MWR_LOGD("[END]");
-       return 0;
+       return true;
 }
 
-int wakeup_manager_set_speech_status_callback(wakeup_service_speech_status_cb callback, void* user_data)
+bool CWakeupManager::CEngineEventObserver::on_speech_status(string engine_name, wakeup_service_speech_status_e status)
 {
        MWR_LOGD("[ENTER]");
+       if (nullptr == mWakeupManager) return false;
 
-       if (NULL == callback) {
-               MWR_LOGE("[ERROR] Input parameter is NULL");
-               return -1;
-       }
-
-       g_speech_status_cb = callback;
-       g_speech_status_user_data = user_data;
-
-       MWR_LOGD("[END]");
-       return 0;
+       return true;
 }
 
-int wakeup_manager_set_error_callback(wakeup_service_error_cb callback, void* user_data)
+bool CWakeupManager::CEngineEventObserver::on_error(string engine_name, int error_code, string error_message)
 {
        MWR_LOGD("[ENTER]");
+       if (nullptr == mWakeupManager) return false;
 
-       if (NULL == callback) {
-               MWR_LOGE("[ERROR] Input parameter is NULL");
-               return -1;
-       }
-
-       g_error_cb = callback;
-       g_error_user_data = user_data;
-
-       MWR_LOGD("[END]");
-       return 0;
-}
-
-bool CEngineEventObserver::on_wakeup_event(string engine_name, wakeup_event_info info)
-{
-       MWR_LOGD("[ENTER]");
-       if (g_wakeup_policy) {
-               g_wakeup_policy->wakeup_candidate(info);
-       }
        return true;
 }
 
-bool CEngineEventObserver::on_speech_status(string engine_name, wakeup_service_speech_status_e status)
+bool CWakeupManager::CEngineEventObserver::on_audio_data_require_status(string engine_name, bool require)
 {
        MWR_LOGD("[ENTER]");
-       return true;
-}
+       if (nullptr == mWakeupManager) return false;
 
-bool CEngineEventObserver::on_error(string engine_name, int error_code, string error_message)
-{
-       MWR_LOGD("[ENTER]");
-       return true;
-}
+       CAudioManager *audio_manager = mWakeupManager->get_audio_manager();
+       CWakeupEngineManager *engine_manager = mWakeupManager->get_engine_manager();
 
-bool CEngineEventObserver::on_audio_data_require_status(string engine_name, bool require)
-{
-       MWR_LOGD("[ENTER]");
-       if (g_wakeup_engine_manager.get_audio_data_required()) {
-               if (g_voice_key_pressed != true) {
-                       g_audio_manager.start_recording();
-               }
-       } else {
-               if (g_voice_key_pressed != true) {
-                       g_audio_manager.stop_recording();
+       if (audio_manager && engine_manager) {
+               if (engine_manager->get_audio_data_required()) {
+                       if (mWakeupManager->get_voice_key_pressed() != true) {
+                               audio_manager->start_recording();
+                       }
+               } else {
+                       if (mWakeupManager->get_voice_key_pressed() != true) {
+                               audio_manager->stop_recording();
+                       }
                }
        }
        return true;
 }
 
-bool CEngineEventObserver::on_streaming_audio_data(
+bool CWakeupManager::CEngineEventObserver::on_streaming_audio_data(
        wakeup_speech_streaming_event_e event, void* buffer, unsigned int len)
 {
-       __wakeup_service_streaming_cb(event, buffer, len);
+       if (nullptr == mWakeupManager) return false;
+
+       vector<IWakeupEventObserver*> observers = mWakeupManager->get_observers();
+       for (const auto& observer : observers) {
+               observer->on_streaming_audio_data(event, buffer, len);
+       }
        if (WAKEUP_SPEECH_STREAMING_EVENT_FINISH == event) {
-               g_streaming_mode = STREAMING_MODE_NONE;
+               mWakeupManager->set_streaming_mode(STREAMING_MODE::NONE);
        }
+
        return true;
 }
 
-void CWakeupEventObserver::on_wakeup(wakeup_event_info info)
+void CWakeupManager::CPolicyEventObserver::on_wakeup(wakeup_event_info info)
 {
-       if (NULL != g_wakeup_event_cb) {
-               g_last_wakeup_event_info = info;
-               g_wakeup_engine_manager.set_selected_wakeup_info(info);
-               g_wakeup_event_cb(info, g_wakeup_event_user_data);
+       if (nullptr == mWakeupManager) return;
+       mWakeupManager->set_last_wakeup_event_info(info);
+
+       CWakeupEngineManager *engine_manager = mWakeupManager->get_engine_manager();
+       if (nullptr == engine_manager) return;
+
+       engine_manager->set_selected_wakeup_info(info);
+       vector<IWakeupEventObserver*> observers = mWakeupManager->get_observers();
+       for (const auto& observer : observers) {
+               observer->on_wakeup(info);
        }
 }
 
-bool CAudioEventObserver::on_recording_audio_data(long time, void* data, int len)
+bool CWakeupManager::CAudioEventObserver::on_recording_audio_data(long time, void* data, int len)
 {
+       if (nullptr == mWakeupManager) return false;
+
+       CWakeupEngineManager *engine_manager = mWakeupManager->get_engine_manager();
        if (nullptr == mEngineManager) return false;
-       if (false == mEngineManager->get_audio_data_required()) return false;
 
-       g_wakeup_engine_manager.engine_feed_audio_data(time, data, len);
+       if (false == engine_manager->get_audio_data_required()) return false;
+
+       engine_manager->engine_feed_audio_data(time, data, len);
 
        return true;
 }
 
-bool CAudioEventObserver::on_streaming_audio_data(
+bool CWakeupManager::CAudioEventObserver::on_streaming_audio_data(
        wakeup_speech_streaming_event_e event, void* buffer, unsigned int len)
 {
-       __wakeup_service_streaming_cb(event, buffer, len);
+       if (nullptr == mWakeupManager) return false;
+
+       vector<IWakeupEventObserver*> observers = mWakeupManager->get_observers();
+       for (const auto& observer : observers) {
+               observer->on_streaming_audio_data(event, buffer, len);
+       }
        if (WAKEUP_SPEECH_STREAMING_EVENT_FINISH == event) {
-               g_streaming_mode = STREAMING_MODE_NONE;
+               mWakeupManager->set_streaming_mode(STREAMING_MODE::NONE);
        }
+
        return true;
 }
+
+} // wakeup
+} // multiassistant
diff --git a/plugins/wakeup-manager/src/wakeup_manager_wrapper.cpp b/plugins/wakeup-manager/src/wakeup_manager_wrapper.cpp
new file mode 100644 (file)
index 0000000..29d3844
--- /dev/null
@@ -0,0 +1,436 @@
+/*
+ * Copyright 2018  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.
+ * You may obtain a copy of the License at
+ *
+ * http://floralicense.org/license/
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an AS IS BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+#include "wakeup_manager_wrapper.h"
+#include "wakeup_manager_main.h"
+#include "wakeup_manager.h"
+
+using namespace multiassistant::wakeup;
+
+static wakeup_service_wakeup_event_cb g_wakeup_event_cb;
+static void* g_wakeup_event_user_data;
+
+static wakeup_service_speech_streaming_cb g_utterance_streaming_cb;
+static void* g_utterance_streaming_user_data;
+
+static wakeup_service_speech_streaming_cb g_previous_utterance_streaming_cb;
+static void* g_previous_utterance_streaming_user_data;
+
+static wakeup_service_speech_streaming_cb g_follow_up_streaming_cb;
+static void* g_follow_up_streaming_user_data;
+
+static wakeup_service_speech_status_cb g_speech_status_cb;
+static void* g_speech_status_user_data;
+
+static wakeup_service_error_cb g_error_cb;
+static void* g_error_user_data;
+
+class CWakeupEventObserver : public IWakeupEventObserver
+{
+       void on_wakeup(wakeup_event_info info) override;
+       void on_streaming_audio_data(
+               wakeup_speech_streaming_event_e event, void* buffer, unsigned int len) override;
+};
+
+static CWakeupEventObserver g_wakeup_event_observer;
+static CWakeupManager g_wakeup_manager(&g_wakeup_event_observer);
+
+int wakeup_manager_initialize(void)
+{
+       MWR_LOGD("[ENTER]");
+
+       g_wakeup_event_cb = NULL;
+       g_wakeup_event_user_data = NULL;
+
+       g_utterance_streaming_cb = NULL;
+       g_utterance_streaming_user_data = NULL;
+
+       g_follow_up_streaming_cb = NULL;
+       g_follow_up_streaming_user_data = NULL;
+
+       g_speech_status_cb = NULL;
+       g_speech_status_user_data = NULL;
+
+       g_error_cb = NULL;
+       g_error_user_data = NULL;
+
+       g_wakeup_manager.initialize();
+
+       MWR_LOGD("[END]");
+       return 0;
+}
+
+int wakeup_manager_deinitialize(void)
+{
+       MWR_LOGD("[ENTER]");
+
+       g_wakeup_manager.deinitialize();
+
+       MWR_LOGD("[END]");
+       return 0;
+}
+
+int wakeup_manager_add_assistant_wakeup_word(const char* appid, const char* wakeup_word, const char* language)
+{
+       MWR_LOGD("[ENTER]");
+
+       if (NULL == appid || NULL == wakeup_word) {
+               MWR_LOGD("[ERROR] Parameter is invalid, appid(%s), wakeup_word(%s), language(%s)", appid, wakeup_word, language);
+               return -1;
+       }
+       g_wakeup_manager.add_assistant_wakeup_word(
+               string{appid}, string{wakeup_word}, (language ? string{language} : string{}));
+
+       MWR_LOGD("[END]");
+       return 0;
+}
+
+int wakeup_manager_add_assistant_language(const char* appid, const char* language)
+{
+       MWR_LOGD("[ENTER]");
+
+       if (NULL == appid || NULL == language) {
+               MWR_LOGD("[ERROR] Parameter is invalid, appid(%s), language(%s)", appid, language);
+               return -1;
+       }
+
+       g_wakeup_manager.add_assistant_language(string{appid}, string{language});
+
+       MWR_LOGD("[DEBUG] language(%s)", language);
+
+       MWR_LOGD("[END]");
+       return 0;
+}
+
+int wakeup_manager_set_assistant_wakeup_engine(const char* appid, const char* engine)
+{
+       MWR_LOGD("[ENTER]");
+
+       if (NULL == appid || NULL == engine) {
+               MWR_LOGD("[ERROR] Parameter is invalid, appid(%s), wakeup engine(%s)", appid, engine);
+               return -1;
+       }
+
+       MWR_LOGD("[DEBUG] appid(%s), wakeup engine(%s)", appid, engine);
+       g_wakeup_manager.set_assistant_wakeup_engine(string{appid}, string{engine});
+
+       MWR_LOGD("[END]");
+       return 0;
+}
+
+int wakeup_manager_set_assistant_enabled(const char* appid, int enabled)
+{
+       MWR_LOGD("[ENTER]");
+
+       if (NULL == appid) {
+               MWR_LOGD("[ERROR] Parameter is invalid, appid(%s)", appid);
+               return -1;
+       }
+
+       g_wakeup_manager.set_assistant_enabled(string{appid}, enabled);
+
+       MWR_LOGD("[END]");
+
+       return 0;
+}
+
+int wakeup_manager_set_language(const char* language)
+{
+       MWR_LOGD("[ENTER]");
+
+       if (NULL == language) {
+               MWR_LOGD("[ERROR] Parameter is invalid, language(%s)", language);
+               return -1;
+       }
+
+       g_wakeup_manager.set_language(string{language});
+
+       MWR_LOGD("[END]");
+       return 0;
+}
+
+int wakeup_manager_change_state(wakeup_manager_state_e state)
+{
+       g_wakeup_manager.change_manager_state(state);
+       return 0;
+}
+
+int wakeup_manager_activate(void)
+{
+       MWR_LOGD("[ENTER]");
+
+       g_wakeup_manager.activate();
+
+       MWR_LOGD("[END]");
+       return 0;
+}
+
+int wakeup_manager_deactivate(void)
+{
+       MWR_LOGD("[ENTER]");
+
+       g_wakeup_manager.deactivate();
+
+       MWR_LOGD("[END]");
+       return 0;
+}
+
+int wakeup_manager_update_voice_feedback_state(const char* appid, int state)
+{
+       MWR_LOGD("[ENTER]");
+
+       if (NULL == appid) {
+               MWR_LOGD("[ERROR] Parameter is invalid, appid(%s)", appid);
+               return -1;
+       }
+
+       g_wakeup_manager.update_voice_feedback_state(string{appid}, state);
+
+       MWR_LOGD("[END]");
+       return 0;
+}
+
+int wakeup_manager_send_assistant_specific_command(const char* appid, const char* command)
+{
+       MWR_LOGD("[ENTER]");
+
+       if (NULL == appid || NULL == command) {
+               MWR_LOGD("[ERROR] Parameter is invalid, appid(%s), command(%s)", appid, command);
+               return -1;
+       }
+
+       g_wakeup_manager.send_assistant_specific_command(string{appid}, string{command});
+
+       MWR_LOGD("[END]");
+       return 0;
+}
+
+int wakeup_manager_update_result_state(const char* appid, int state)
+{
+       MWR_LOGD("[ENTER]");
+
+       if (NULL == appid) {
+               MWR_LOGD("[ERROR] Parameter is invalid, appid(%s)", appid);
+               return -1;
+       }
+       g_wakeup_manager.update_result_state(string{appid}, state);
+
+       MWR_LOGD("[END]");
+       return 0;
+}
+
+int wakeup_manager_process_event(int event, void* data, int len)
+{
+       MWR_LOGD("[ENTER]");
+
+       g_wakeup_manager.process_event(static_cast<ma_plugin_event_e>(event), data, len);
+
+       MWR_LOGD("[END]");
+       return 0;
+}
+
+int wakeup_manager_start_streaming_utterance_data(void)
+{
+       MWR_LOGD("[ENTER]");
+
+       g_wakeup_manager.start_streaming_utterance_data();
+
+       MWR_LOGD("[END]");
+       return 0;
+}
+
+int wakeup_manager_stop_streaming_utterance_data(void)
+{
+       MWR_LOGD("[ENTER]");
+
+       g_wakeup_manager.stop_streaming_utterance_data();
+
+       MWR_LOGD("[END]");
+       return 0;
+}
+
+int wakeup_manager_start_streaming_follow_up_data(void)
+{
+       MWR_LOGD("[ENTER]");
+
+       g_wakeup_manager.start_streaming_follow_up_data();
+
+       MWR_LOGD("[END]");
+       return 0;
+}
+
+int wakeup_manager_stop_streaming_follow_up_data(void)
+{
+       MWR_LOGD("[ENTER]");
+
+       g_wakeup_manager.stop_streaming_follow_up_data();
+
+       MWR_LOGD("[END]");
+       return 0;
+}
+
+int wakeup_manager_start_streaming_previous_utterance_data(void)
+{
+       MWR_LOGD("[ENTER]");
+
+       g_wakeup_manager.start_streaming_previous_utterance_data();
+
+       MWR_LOGD("[END]");
+       return 0;
+}
+
+int wakeup_manager_stop_streaming_previous_utterance_data(void)
+{
+       MWR_LOGD("[ENTER]");
+
+       g_wakeup_manager.stop_streaming_previous_utterance_data();
+
+       MWR_LOGD("[END]");
+       return 0;
+}
+
+int wakeup_manager_get_audio_format(int* rate, int* channel, int* audio_type)
+{
+       MWR_LOGD("[ENTER]");
+
+       if (!audio_type || !rate || !channel) {
+               MWR_LOGE("[ERROR] Invalid parameter");
+               return -1;
+       }
+
+       g_wakeup_manager.get_audio_format(rate, channel, audio_type);
+
+       MWR_LOGD("[END] rate(%d), channel(%d), audio_type(%d)", *rate, *channel, *audio_type);
+       return 0;
+}
+
+int wakeup_manager_set_wakeup_event_callback(wakeup_service_wakeup_event_cb callback, void* user_data)
+{
+       MWR_LOGD("[ENTER]");
+
+       if (NULL == callback) {
+               MWR_LOGE("[ERROR] Input parameter is NULL");
+               return -1;
+       }
+
+       g_wakeup_event_cb = callback;
+       g_wakeup_event_user_data = user_data;
+
+       MWR_LOGD("[END]");
+       return 0;
+}
+
+int wakeup_manager_set_utterance_streaming_callback(wakeup_service_speech_streaming_cb callback, void* user_data)
+{
+       MWR_LOGD("[ENTER]");
+
+       if (NULL == callback) {
+               MWR_LOGE("[ERROR] Input parameter is NULL");
+               return -1;
+       }
+
+       g_utterance_streaming_cb = callback;
+       g_utterance_streaming_user_data = user_data;
+
+       MWR_LOGD("[END]");
+       return 0;
+}
+
+int wakeup_manager_set_previous_utterance_streaming_callback(wakeup_service_speech_streaming_cb callback, void* user_data)
+{
+       MWR_LOGD("[ENTER]");
+
+       if (NULL == callback) {
+               MWR_LOGE("[ERROR] Input parameter is NULL");
+               return -1;
+       }
+
+       g_previous_utterance_streaming_cb = callback;
+       g_previous_utterance_streaming_user_data = user_data;
+
+       MWR_LOGD("[END]");
+       return 0;
+}
+
+int wakeup_manager_set_follow_up_streaming_callback(wakeup_service_speech_streaming_cb callback, void* user_data)
+{
+       MWR_LOGD("[ENTER]");
+
+       if (NULL == callback) {
+               MWR_LOGE("[ERROR] Input parameter is NULL");
+               return -1;
+       }
+
+       g_follow_up_streaming_cb = callback;
+       g_follow_up_streaming_user_data = user_data;
+
+       MWR_LOGD("[END]");
+       return 0;
+}
+
+int wakeup_manager_set_speech_status_callback(wakeup_service_speech_status_cb callback, void* user_data)
+{
+       MWR_LOGD("[ENTER]");
+
+       if (NULL == callback) {
+               MWR_LOGE("[ERROR] Input parameter is NULL");
+               return -1;
+       }
+
+       g_speech_status_cb = callback;
+       g_speech_status_user_data = user_data;
+
+       MWR_LOGD("[END]");
+       return 0;
+}
+
+int wakeup_manager_set_error_callback(wakeup_service_error_cb callback, void* user_data)
+{
+       MWR_LOGD("[ENTER]");
+
+       if (NULL == callback) {
+               MWR_LOGE("[ERROR] Input parameter is NULL");
+               return -1;
+       }
+
+       g_error_cb = callback;
+       g_error_user_data = user_data;
+
+       MWR_LOGD("[END]");
+       return 0;
+}
+
+void CWakeupEventObserver::on_wakeup(wakeup_event_info info)
+{
+       if (NULL != g_wakeup_event_cb) {
+               g_wakeup_event_cb(info, g_wakeup_event_user_data);
+       }
+}
+
+void CWakeupEventObserver::on_streaming_audio_data(
+       wakeup_speech_streaming_event_e event, void* buffer, unsigned int len)
+{
+       if (WAKEUP_SPEECH_STREAMING_EVENT_START == event) {
+               MWR_LOGD("streaming_cb START");
+       }
+       if (WAKEUP_SPEECH_STREAMING_EVENT_FINISH == event) {
+               MWR_LOGD("streaming_cb FINISH");
+       }
+       if (NULL != g_utterance_streaming_cb) {
+               g_utterance_streaming_cb(event, buffer, len, g_utterance_streaming_user_data);
+       } else {
+               MWR_LOGI("[INFO] No service streaming callback");
+       }
+}
\ No newline at end of file
index 6d39cfc..eb01c7f 100644 (file)
@@ -9,14 +9,14 @@ namespace multiassistant
 namespace wakeup
 {
 
-void CWakeupPolicyImpl::subscribe(IWakeupEventObserver *observer)
+void CWakeupPolicyImpl::subscribe(IPolicyEventObserver *observer)
 {
        mObservers.push_back(observer);
 }
 
-void CWakeupPolicyImpl::unsubscribe(IWakeupEventObserver *observer)
+void CWakeupPolicyImpl::unsubscribe(IPolicyEventObserver *observer)
 {
-       auto iter = std::find(mObservers.begin(), mObservers.end(), observer);
+       auto iter = find(mObservers.begin(), mObservers.end(), observer);
        if (iter != mObservers.end()) {
                mObservers.erase(iter);
        }
@@ -40,12 +40,17 @@ CWakeupPolicy::~CWakeupPolicy()
 {
 }
 
-void CWakeupPolicy::subscribe(IWakeupEventObserver *observer)
+CWakeupPolicy::CWakeupPolicy(IPolicyEventObserver *observer) : CWakeupPolicy()
+{
+       subscribe(observer);
+}
+
+void CWakeupPolicy::subscribe(IPolicyEventObserver *observer)
 {
        if (mImpl) mImpl->subscribe(observer);
 }
 
-void CWakeupPolicy::unsubscribe(IWakeupEventObserver *observer)
+void CWakeupPolicy::unsubscribe(IPolicyEventObserver *observer)
 {
        if (mImpl) mImpl->unsubscribe(observer);
 }
index 3fafdfd..3175733 100644 (file)
@@ -19,6 +19,11 @@ CWakeupPolicyDefault::CWakeupPolicyDefault()
 {
 }
 
+CWakeupPolicyDefault::CWakeupPolicyDefault(IPolicyEventObserver *observer)
+       : CWakeupPolicy(observer)
+{
+}
+
 CWakeupPolicyDefault::~CWakeupPolicyDefault()
 {
        if (mTimer) {
@@ -27,7 +32,7 @@ CWakeupPolicyDefault::~CWakeupPolicyDefault()
        }
 }
 
-void CWakeupPolicyDefault::set_assistant_priority(std::string appid, int priority)
+void CWakeupPolicyDefault::set_assistant_priority(string appid, int priority)
 {
        PRIORITY_INFO info;
        info.appid = appid;
index 794352c..165b0df 100644 (file)
@@ -48,10 +48,10 @@ void CWakeupSettings::initialize()
        }
        vconf_str = vconf_get_str(WAKEUP_SETTINGS_KEY_ENABLED_ASSISTANTS);
        if (vconf_str) {
-               std::string token;
-               std::istringstream iss(vconf_str);
+               string token;
+               istringstream iss(vconf_str);
                mEnabledAssistants.clear();
-               while (std::getline(iss, token, ';')) {
+               while (getline(iss, token, ';')) {
                        mEnabledAssistants.push_back(token);
                        MWR_LOGD("enabled_assistants : %s", token.c_str());
                }
@@ -65,10 +65,10 @@ void CWakeupSettings::initialize()
        }
        vconf_str = vconf_get_str(WAKEUP_SETTINGS_KEY_WAKEUP_POLICY_PRIORITY);
        if (vconf_str) {
-               std::string token;
-               std::istringstream iss(vconf_str);
+               string token;
+               istringstream iss(vconf_str);
                mWakeupPolicyPriority.clear();
-               while (std::getline(iss, token, ';')) {
+               while (getline(iss, token, ';')) {
                        mWakeupPolicyPriority.push_back(token);
                        MWR_LOGD("wakeup_policy_priority : %s", token.c_str());
                }
@@ -86,7 +86,7 @@ void CWakeupSettings::deinitialize()
 {
 }
 
-std::string CWakeupSettings::get_default_assistant_appid()
+string CWakeupSettings::get_default_assistant_appid()
 {
        return mDefaultAssistantAppid;
 }
@@ -106,7 +106,7 @@ bool CWakeupSettings::get_multiple_mode()
        return mMultipleMode;
 }
 
-std::vector<std::string> CWakeupSettings::get_enabled_assistants()
+vector<string> CWakeupSettings::get_enabled_assistants()
 {
        return mEnabledAssistants;
 }
@@ -116,7 +116,7 @@ float CWakeupSettings::get_wakeup_policy_delay()
        return mWakeupPolicyDelay;
 }
 
-std::vector<std::string> CWakeupSettings::get_wakeup_policy_priority()
+vector<string> CWakeupSettings::get_wakeup_policy_priority()
 {
        return mWakeupPolicyPriority;
 }