From 336798d599917ba965ff5978700fdc628ec2b125 Mon Sep 17 00:00:00 2001 From: Ji-hoon Lee Date: Wed, 20 Mar 2019 13:55:03 +0900 Subject: [PATCH] Extract setting management feature into CWakeupSettings Change-Id: Ic0bc22f9245304d84cc079f407368eab5ed11bef --- plugins/wakeup-manager/CMakeLists.txt | 1 + plugins/wakeup-manager/inc/wakeup_settings.h | 74 ++++++++++ plugins/wakeup-manager/src/wakeup_manager.cpp | 119 +++------------- .../wakeup-manager/src/wakeup_settings.cpp | 130 ++++++++++++++++++ 4 files changed, 224 insertions(+), 100 deletions(-) create mode 100644 plugins/wakeup-manager/inc/wakeup_settings.h create mode 100644 plugins/wakeup-manager/src/wakeup_settings.cpp diff --git a/plugins/wakeup-manager/CMakeLists.txt b/plugins/wakeup-manager/CMakeLists.txt index 5c0602f..1041038 100644 --- a/plugins/wakeup-manager/CMakeLists.txt +++ b/plugins/wakeup-manager/CMakeLists.txt @@ -46,6 +46,7 @@ ADD_DEFINITIONS("-DPACKAGE=\"${PACKAGE}\"") SET(SRCS src/wakeup_manager.cpp + src/wakeup_settings.cpp src/wakeup_policy.cpp src/wakeup_policy_default.cpp src/wakeup_audio_manager.cpp diff --git a/plugins/wakeup-manager/inc/wakeup_settings.h b/plugins/wakeup-manager/inc/wakeup_settings.h new file mode 100644 index 0000000..c24d170 --- /dev/null +++ b/plugins/wakeup-manager/inc/wakeup_settings.h @@ -0,0 +1,74 @@ +/* + * 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_SETTINGS_H_ +#define _WAKEUP_SETTINGS_H_ + +#include +#include + +namespace multiassistant +{ +namespace wakeup +{ + +#define DEFAULT_ASSISTANT_APPID "com.samsung.bixby-voice" + +#define WAKEUP_SETTINGS_KEY_DEFAULT_ASSISTANT_APPID "db/multi-assistant/default_assistant_appid" +#define WAKEUP_SETTINGS_KEY_UI_PANEL_ENABLED "db/multi-assistant/ui_panel_enabled" +#define WAKEUP_SETTINGS_KEY_CONVERSATION_TIMEOUT "db/multi-assistant/conversation_timeout" +#define WAKEUP_SETTINGS_KEY_MULTIPLE_MODE "db/multi-assistant/multiple_mode" +#define WAKEUP_SETTINGS_KEY_ENABLED_ASSISTANTS "db/multi-assistant/enabled_assistants" +#define WAKEUP_SETTINGS_KEY_WAKEUP_POLICY_DELAY "db/multi-assistant/wakeup_policy_delay" +#define WAKEUP_SETTINGS_KEY_WAKEUP_POLICY_PRIORITY "db/multi-assistant/wakeup_policy_priority" +#define WAKEUP_SETTINGS_KEY_STREAMING_DURATION_MAX "db/multi-assistant/streaming_duration_max" + +class CWakeupSettings +{ +public: + CWakeupSettings(); + virtual ~CWakeupSettings(); + + CWakeupSettings(const CWakeupSettings&) = delete; + CWakeupSettings& operator=(const CWakeupSettings&) = delete; + + void initialize(); + void deinitialize(); + + std::string get_default_assistant_appid(); + bool get_ui_panel_enabled(); + float get_conversation_timeout(); + bool get_multiple_mode(); + std::vector get_enabled_assistants(); + float get_wakeup_policy_delay(); + std::vector get_wakeup_policy_priority(); + float get_streaming_duration_max(); + +private: + std::string mDefaultAssistantAppid{DEFAULT_ASSISTANT_APPID}; + bool mUiPanelEnabled{true}; + float mConversationTimeout{5.0}; + bool mMultipleMode{true}; + std::vector mEnabledAssistants{DEFAULT_ASSISTANT_APPID}; + float mWakeupPolicyDelay{0.1}; + std::vector mWakeupPolicyPriority; // No priority by default + float mStreamingDurationMax{10.0}; +}; + +} // wakeup +} // multiassistant + +#endif /* _WAKEUP_SETTINGS_H_ */ diff --git a/plugins/wakeup-manager/src/wakeup_manager.cpp b/plugins/wakeup-manager/src/wakeup_manager.cpp index fd2b196..2aa267a 100644 --- a/plugins/wakeup-manager/src/wakeup_manager.cpp +++ b/plugins/wakeup-manager/src/wakeup_manager.cpp @@ -17,17 +17,15 @@ #include #include -#include #include #include #include #include #include -#include - #include "wakeup_manager_main.h" #include "wakeup_manager.h" +#include "wakeup_settings.h" #include "wakeup_audio_manager.h" #include "wakeup_policy_default.h" @@ -44,6 +42,8 @@ Ecore_Event_Handler* _key_up_handler = NULL; #endif +using namespace multiassistant::wakeup; + static bool g_audio_data_required = false; bool g_voice_key_pressed = false; @@ -90,29 +90,7 @@ static wakeup_manager_state_e g_wakeup_manager_state; static wakeup_event_info g_last_wakeup_event_info; -#define DEFAULT_ASSISTANT_APPID "com.samsung.bixby-voice" - -#define WAKEUP_SETTINGS_KEY_DEFAULT_ASSISTANT_APPID "db/multi-assistant/default_assistant_appid" -#define WAKEUP_SETTINGS_KEY_UI_PANEL_ENABLED "db/multi-assistant/ui_panel_enabled" -#define WAKEUP_SETTINGS_KEY_CONVERSATION_TIMEOUT "db/multi-assistant/conversation_timeout" -#define WAKEUP_SETTINGS_KEY_MULTIPLE_MODE "db/multi-assistant/multiple_mode" -#define WAKEUP_SETTINGS_KEY_ENABLED_ASSISTANTS "db/multi-assistant/enabled_assistants" -#define WAKEUP_SETTINGS_KEY_WAKEUP_POLICY_DELAY "db/multi-assistant/wakeup_policy_delay" -#define WAKEUP_SETTINGS_KEY_WAKEUP_POLICY_PRIORITY "db/multi-assistant/wakeup_policy_priority" -#define WAKEUP_SETTINGS_KEY_STREAMING_DURATION_MAX "db/multi-assistant/streaming_duration_max" - -typedef struct { - std::string default_assistant_appid{DEFAULT_ASSISTANT_APPID}; - bool ui_panel_enabled{true}; - float conversation_timeout{5.0}; - bool multiple_mode{true}; - std::vector enabled_assistants{DEFAULT_ASSISTANT_APPID}; - float wakeup_policy_delay{0.1}; - std::vector wakeup_policy_priority; // No priority by default - float streaming_duration_max{10.0}; -} wakeup_settings; - -static wakeup_settings g_wakeup_settings; +static CWakeupSettings g_wakeup_settings; enum STREAMING_MODE { STREAMING_MODE_NONE, @@ -124,22 +102,22 @@ enum STREAMING_MODE { static STREAMING_MODE g_streaming_mode{STREAMING_MODE_NONE}; static Ecore_Timer* g_streaming_duration_timer; -class CWakeupEventObserver : public multiassistant::wakeup::IWakeupEventObserver +class CWakeupEventObserver : public IWakeupEventObserver { public: void on_wakeup(wakeup_event_info info) override; }; -static std::unique_ptr g_wakeup_policy; +static std::unique_ptr g_wakeup_policy; static CWakeupEventObserver g_wakeup_event_observer; -class CAudioDataObserver : public multiassistant::wakeup::IAudioDataObserver +class CAudioDataObserver : public IAudioDataObserver { 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; }; -static multiassistant::wakeup::CAudioManager g_audio_manager; +static CAudioManager g_audio_manager; static CAudioDataObserver g_audio_data_observer; #ifdef TV_PRODUCT @@ -486,20 +464,20 @@ void CWakeupEventObserver::on_wakeup(wakeup_event_info info) void wakeup_policy_initialize(void) { - g_wakeup_policy.reset(new multiassistant::wakeup::CWakeupPolicyDefault); + g_wakeup_policy.reset(new CWakeupPolicyDefault); if (g_wakeup_policy) { g_wakeup_policy->subscribe(&g_wakeup_event_observer); } /* Default Policy specific initialization */ - multiassistant::wakeup::CWakeupPolicyDefault *default_policy = - dynamic_cast(g_wakeup_policy.get()); + CWakeupPolicyDefault *default_policy = + dynamic_cast(g_wakeup_policy.get()); if (default_policy) { int priority = 0; - default_policy->set_delay(g_wakeup_settings.wakeup_policy_delay); - MWR_LOGD("Setting Delay : %f", g_wakeup_settings.wakeup_policy_delay); - for (const auto& assistant : g_wakeup_settings.wakeup_policy_priority) { + 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); MWR_LOGD("Setting Priority : %d %s", priority, assistant.c_str()); } @@ -527,68 +505,7 @@ int wakeup_manager_initialize(void) g_engine_count = 0; - int vconf_ret; - char *vconf_str; - int vconf_bool; - double vconf_double; - - vconf_str = vconf_get_str(WAKEUP_SETTINGS_KEY_DEFAULT_ASSISTANT_APPID); - if (vconf_str) { - g_wakeup_settings.default_assistant_appid = vconf_str; - MWR_LOGD("default_assistant_appid : %s", g_wakeup_settings.default_assistant_appid.c_str()); - free(vconf_str); - vconf_str = nullptr; - } - vconf_ret = vconf_get_bool(WAKEUP_SETTINGS_KEY_UI_PANEL_ENABLED, &vconf_bool); - if (0 == vconf_ret) { - g_wakeup_settings.ui_panel_enabled = vconf_bool; - MWR_LOGD("ui_panel_enabled : %s", (g_wakeup_settings.ui_panel_enabled ? "true" : "false")); - } - vconf_ret = vconf_get_dbl(WAKEUP_SETTINGS_KEY_CONVERSATION_TIMEOUT, &vconf_double); - if (0 == vconf_ret) { - g_wakeup_settings.conversation_timeout = vconf_double; - MWR_LOGD("conversation_timeout : %f", g_wakeup_settings.conversation_timeout); - } - vconf_ret = vconf_get_bool(WAKEUP_SETTINGS_KEY_MULTIPLE_MODE, &vconf_bool); - if (0 == vconf_ret) { - g_wakeup_settings.multiple_mode = vconf_bool; - MWR_LOGD("multiple_mode : %s", (g_wakeup_settings.multiple_mode ? "true" : "false")); - } - vconf_str = vconf_get_str(WAKEUP_SETTINGS_KEY_ENABLED_ASSISTANTS); - if (vconf_str) { - std::string token; - std::istringstream iss(vconf_str); - g_wakeup_settings.enabled_assistants.clear(); - while (std::getline(iss, token, ';')) { - g_wakeup_settings.enabled_assistants.push_back(token); - MWR_LOGD("enabled_assistants : %s", token.c_str()); - } - free(vconf_str); - vconf_str = nullptr; - } - vconf_ret = vconf_get_dbl(WAKEUP_SETTINGS_KEY_WAKEUP_POLICY_DELAY, &vconf_double); - if (0 == vconf_ret) { - g_wakeup_settings.wakeup_policy_delay = vconf_double; - MWR_LOGD("conversation_timeout : %f", g_wakeup_settings.wakeup_policy_delay); - } - vconf_str = vconf_get_str(WAKEUP_SETTINGS_KEY_WAKEUP_POLICY_PRIORITY); - if (vconf_str) { - std::string token; - std::istringstream iss(vconf_str); - g_wakeup_settings.wakeup_policy_priority.clear(); - while (std::getline(iss, token, ';')) { - g_wakeup_settings.wakeup_policy_priority.push_back(token); - MWR_LOGD("wakeup_policy_priority : %s", token.c_str()); - } - free(vconf_str); - vconf_str = nullptr; - } - vconf_ret = vconf_get_dbl(WAKEUP_SETTINGS_KEY_STREAMING_DURATION_MAX, &vconf_double); - if (0 == vconf_ret) { - g_wakeup_settings.streaming_duration_max = vconf_double; - MWR_LOGD("streaming_duration_max : %f", g_wakeup_settings.streaming_duration_max); - } - + g_wakeup_settings.initialize(); wakeup_policy_initialize(); g_audio_manager.initialize(); @@ -614,6 +531,8 @@ int wakeup_manager_deinitialize(void) _ungrab_voice_key(); #endif + g_wakeup_settings.deinitialize(); + g_audio_manager.unsubscribe(&g_audio_data_observer); g_audio_manager.deinitialize(); @@ -878,7 +797,7 @@ int wakeup_manager_process_event(int event, void* data, int len) /* TODO: apply conversation timeout for selecting assistant here */ wakeup_event_info event; event.wakeup_word = nullptr; - event.wakeup_appid = g_wakeup_settings.default_assistant_appid.c_str(); + event.wakeup_appid = g_wakeup_settings.get_default_assistant_appid().c_str(); if (NULL != g_wakeup_event_cb) { g_wakeup_event_cb(event, g_wakeup_event_user_data); } @@ -1045,7 +964,7 @@ int wakeup_manager_start_streaming_utterance_data(void) if (g_streaming_duration_timer) { ecore_timer_del(g_streaming_duration_timer); } - g_streaming_duration_timer = ecore_timer_add(g_wakeup_settings.streaming_duration_max, + g_streaming_duration_timer = ecore_timer_add(g_wakeup_settings.get_streaming_duration_max(), streaming_duration_expired, nullptr); ecore_thread_main_loop_end(); diff --git a/plugins/wakeup-manager/src/wakeup_settings.cpp b/plugins/wakeup-manager/src/wakeup_settings.cpp new file mode 100644 index 0000000..794352c --- /dev/null +++ b/plugins/wakeup-manager/src/wakeup_settings.cpp @@ -0,0 +1,130 @@ +#include "wakeup_settings.h" +#include "wakeup_manager_main.h" + +#include +#include + +namespace multiassistant +{ +namespace wakeup +{ + +CWakeupSettings::CWakeupSettings() +{ +} + +CWakeupSettings::~CWakeupSettings() +{ +} + +void CWakeupSettings::initialize() +{ + int vconf_ret; + char *vconf_str; + int vconf_bool; + double vconf_double; + + vconf_str = vconf_get_str(WAKEUP_SETTINGS_KEY_DEFAULT_ASSISTANT_APPID); + if (vconf_str) { + mDefaultAssistantAppid = vconf_str; + MWR_LOGD("default_assistant_appid : %s", mDefaultAssistantAppid.c_str()); + free(vconf_str); + vconf_str = nullptr; + } + vconf_ret = vconf_get_bool(WAKEUP_SETTINGS_KEY_UI_PANEL_ENABLED, &vconf_bool); + if (0 == vconf_ret) { + mUiPanelEnabled = vconf_bool; + MWR_LOGD("ui_panel_enabled : %s", (mUiPanelEnabled ? "true" : "false")); + } + vconf_ret = vconf_get_dbl(WAKEUP_SETTINGS_KEY_CONVERSATION_TIMEOUT, &vconf_double); + if (0 == vconf_ret) { + mConversationTimeout = vconf_double; + MWR_LOGD("conversation_timeout : %f", mConversationTimeout); + } + vconf_ret = vconf_get_bool(WAKEUP_SETTINGS_KEY_MULTIPLE_MODE, &vconf_bool); + if (0 == vconf_ret) { + mMultipleMode = vconf_bool; + MWR_LOGD("multiple_mode : %s", (mMultipleMode ? "true" : "false")); + } + vconf_str = vconf_get_str(WAKEUP_SETTINGS_KEY_ENABLED_ASSISTANTS); + if (vconf_str) { + std::string token; + std::istringstream iss(vconf_str); + mEnabledAssistants.clear(); + while (std::getline(iss, token, ';')) { + mEnabledAssistants.push_back(token); + MWR_LOGD("enabled_assistants : %s", token.c_str()); + } + free(vconf_str); + vconf_str = nullptr; + } + vconf_ret = vconf_get_dbl(WAKEUP_SETTINGS_KEY_WAKEUP_POLICY_DELAY, &vconf_double); + if (0 == vconf_ret) { + mWakeupPolicyDelay = vconf_double; + MWR_LOGD("conversation_timeout : %f", mWakeupPolicyDelay); + } + vconf_str = vconf_get_str(WAKEUP_SETTINGS_KEY_WAKEUP_POLICY_PRIORITY); + if (vconf_str) { + std::string token; + std::istringstream iss(vconf_str); + mWakeupPolicyPriority.clear(); + while (std::getline(iss, token, ';')) { + mWakeupPolicyPriority.push_back(token); + MWR_LOGD("wakeup_policy_priority : %s", token.c_str()); + } + free(vconf_str); + vconf_str = nullptr; + } + vconf_ret = vconf_get_dbl(WAKEUP_SETTINGS_KEY_STREAMING_DURATION_MAX, &vconf_double); + if (0 == vconf_ret) { + mStreamingDurationMax = vconf_double; + MWR_LOGD("streaming_duration_max : %f", mStreamingDurationMax); + } +} + +void CWakeupSettings::deinitialize() +{ +} + +std::string CWakeupSettings::get_default_assistant_appid() +{ + return mDefaultAssistantAppid; +} + +bool CWakeupSettings::get_ui_panel_enabled() +{ + return mUiPanelEnabled; +} + +float CWakeupSettings::get_conversation_timeout() +{ + return mConversationTimeout; +} + +bool CWakeupSettings::get_multiple_mode() +{ + return mMultipleMode; +} + +std::vector CWakeupSettings::get_enabled_assistants() +{ + return mEnabledAssistants; +} + +float CWakeupSettings::get_wakeup_policy_delay() +{ + return mWakeupPolicyDelay; +} + +std::vector CWakeupSettings::get_wakeup_policy_priority() +{ + return mWakeupPolicyPriority; +} + +float CWakeupSettings::get_streaming_duration_max() +{ + return mStreamingDurationMax; +} + +} // wakeup +} // multiassistant -- 2.34.1