Preserve wakeup manager state on proactive default assistant change 20/276320/1
authorJi-hoon Lee <dalton.lee@samsung.com>
Thu, 9 Jun 2022 09:05:22 +0000 (18:05 +0900)
committerJi-hoon Lee <dalton.lee@samsung.com>
Tue, 14 Jun 2022 12:29:51 +0000 (21:29 +0900)
Change-Id: I772c2000e4201a7798226faeb70279fd36aca92e

plugins/wakeup-manager/inc/wakeup_manager.h
plugins/wakeup-manager/src/wakeup_manager.cpp
src/service_main.cpp

index b348b2e..0eae063 100644 (file)
@@ -97,7 +97,7 @@ public:
        bool set_assistant_enabled(string appid, bool enabled);
        bool get_assistant_enabled(string appid);
        bool set_default_assistant(string appid);
-       bool process_default_assistant_changed(string appid);
+       bool process_default_assistant_changed(string appid, bool expected);
        string get_default_assistant();
 
        bool update_voice_feedback_state(string appid, bool state);
@@ -145,6 +145,10 @@ public:
 
        void set_streaming_duration_timer(Ecore_Timer* timer);
        Ecore_Timer* get_streaming_duration_timer();
+
+       void start_periodic_monitor_timer();
+       void stop_periodic_monitor_timer();
+
 private:
        bool change_voice_key_status(ma_voice_key_status_e status);
 
@@ -239,6 +243,7 @@ private:
 
        STREAMING_MODE mStreamingMode{STREAMING_MODE::NONE};
        Ecore_Timer* mStreamingDurationTimer{nullptr};
+       Ecore_Timer* mPeriodicMonitorTimer{nullptr};
 
        wakeup_manager_state_e mWakeupManagerState{WAKEUP_MANAGER_STATE_INACTIVE};
 
index 7b631af..82537ba 100644 (file)
@@ -21,6 +21,7 @@
 #include "dependency_resolver.h"
 
 #include <algorithm>
+#include <iostream>
 
 #include <boost/optional.hpp>
 
@@ -104,6 +105,7 @@ void CWakeupManager::initialize_wakeup_policy()
 bool CWakeupManager::initialize()
 {
        MWR_LOGE("[ENTER]");
+       std::cerr << "WakeupManager Initialize" << std::endl;
 
        mPolicyEventObserver.set_wakeup_manager(this);
        mEngineEventObserver.set_wakeup_manager(this);
@@ -131,6 +133,7 @@ bool CWakeupManager::initialize()
        dependency_resolver_initialize(interface);
 
        initialize_wakeup_policy();
+       start_periodic_monitor_timer();
 
        MWR_LOGD("[END]");
        return true;
@@ -139,7 +142,9 @@ bool CWakeupManager::initialize()
 bool CWakeupManager::deinitialize()
 {
        MWR_LOGE("[ENTER]");
+       std::cerr << "WakeupManager Deinitialize" << std::endl;
 
+       stop_periodic_monitor_timer();
        stop_streaming_duration_timer();
 
        dependency_resolver_deinitialize();
@@ -312,14 +317,15 @@ bool CWakeupManager::set_default_assistant(string appid)
 {
        MWR_LOGE("[ENTER] %s %s", appid.c_str(), mCurrentDefaultAssistant.c_str());
 
-       process_default_assistant_changed(appid);
+       /* Passing 'expected' as true since MAS is changing the default assistant config */
+       process_default_assistant_changed(appid, true);
 
        mWakeupSettings.set_default_assistant_appid(appid);
 
        return true;
 }
 
-bool CWakeupManager::process_default_assistant_changed(string appid)
+bool CWakeupManager::process_default_assistant_changed(string appid, bool expected)
 {
        MWR_LOGE("[ENTER] %s %s", appid.c_str(), mCurrentDefaultAssistant.c_str());
 
@@ -330,7 +336,16 @@ bool CWakeupManager::process_default_assistant_changed(string appid)
 
        if (mWakeupManagerState == WAKEUP_MANAGER_STATE_UTTERANCE ||
                mWakeupManagerState == WAKEUP_MANAGER_STATE_PROCESSING) {
-               update_recognition_result(mCurrentDefaultAssistant, MA_RECOGNITION_RESULT_EVENT_ERROR);
+               if (expected) {
+                       stop_streaming_utterance_data();
+                       stop_streaming_previous_utterance_data();
+                       stop_streaming_follow_up_data();
+
+                       mWakeupEngineManager.update_recognition_result(appid, MA_RECOGNITION_RESULT_EVENT_ERROR);
+               } else {
+                       /* If this is an unexpected change, invalidate previous recognition process */
+                       update_recognition_result(mCurrentDefaultAssistant, MA_RECOGNITION_RESULT_EVENT_ERROR);
+               }
        }
 
        /* Check if previous default assistant has to be deactivated */
@@ -922,6 +937,14 @@ CWakeupSettings* CWakeupManager::get_wakeup_settings()
 
 void CWakeupManager::feed_audio_data(mas_speech_streaming_event_e event, void* buffer, int len)
 {
+       const std::chrono::seconds interval(5);
+       static auto last = std::chrono::steady_clock::now();
+       auto now = std::chrono::steady_clock::now();
+       if (now - last > interval) {
+               std::cerr << "Feeding Audio : " << len << std::endl;
+               last = now;
+       }
+
        mAudioManager.feed_audio_data(event, buffer, len);
 }
 
@@ -930,6 +953,28 @@ void CWakeupManager::set_dependency_module_command(string engine_name, string co
        mWakeupEngineManager.engine_set_dependency_module_command(engine_name, command);
 }
 
+static Eina_Bool periodic_monitor_func(void *data)
+{
+       std::cerr << "MAS PERIODIC HEALTH CHECK" << std::endl;
+       return ECORE_CALLBACK_RENEW;
+}
+
+void CWakeupManager::start_periodic_monitor_timer()
+{
+       MWR_LOGI("MONITOR_TIMER START");
+       mPeriodicMonitorTimer = ecore_timer_add(
+               30.0f,
+               periodic_monitor_func, nullptr);
+}
+
+void CWakeupManager::stop_periodic_monitor_timer()
+{
+       if (mPeriodicMonitorTimer) {
+               ecore_timer_del(mPeriodicMonitorTimer);
+               mPeriodicMonitorTimer = nullptr;
+       }
+}
+
 void CWakeupManager::start_streaming_duration_timer()
 {
        MWR_LOGI("DURATION_TIMER START");
@@ -1174,7 +1219,8 @@ bool CWakeupManager::CSettingsEventObserver::on_default_assistant_appid_changed(
        const char* appid)
 {
        if (nullptr == mWakeupManager || nullptr == appid) return false;
-       mWakeupManager->process_default_assistant_changed(std::string(appid));
+       /* Passing 'expected' as false since the change was occurred outside of MAS */
+       mWakeupManager->process_default_assistant_changed(std::string(appid), false);
        vector<ISettingValueObserver*> observers = mWakeupManager->get_setting_observers();
        for (const auto& observer : observers) {
                observer->on_value_changed();
index 78500f1..70a7b3e 100644 (file)
@@ -30,6 +30,7 @@
 #include <list>
 #include <sstream>
 #include <tuple>
+#include <vector>
 
 #include "service_common.h"
 #include "service_main.h"
@@ -778,6 +779,16 @@ int CServiceMain::deinitialize_service_plugin(void)
        if (0 != mServicePlugin.deinitialize()) {
                MAS_LOGE("Fail to deinitialize");
        }
+
+       std::vector<pid_t> clients;
+       int client_num = mClientManager.get_client_num();
+       for (int loop = 0;loop < client_num;loop++) {
+               clients.push_back(mClientManager.find_client_pid_by_index(loop));
+       }
+
+       for (auto pid : clients) {
+               on_deinitialize(pid, mClientManager.find_sender_info_by_pid(pid));
+       }
        MAS_LOGI("[END]");
        return 0;
 }