Separate config setter and value change handler 67/275267/1
authorJi-hoon Lee <dalton.lee@samsung.com>
Thu, 19 May 2022 07:14:03 +0000 (16:14 +0900)
committerJi-hoon Lee <dalton.lee@samsung.com>
Thu, 19 May 2022 07:14:03 +0000 (16:14 +0900)
Change-Id: Ia659b1cc4a56eca2a4293493c6ce5c3e21b0e565

plugins/wakeup-manager/inc/wakeup_manager.h
plugins/wakeup-manager/src/wakeup_engine_manager.cpp
plugins/wakeup-manager/src/wakeup_manager.cpp
plugins/wakeup-manager/src/wakeup_manager_wrapper.cpp
plugins/wakeup-manager/src/wakeup_settings.cpp
src/client_manager.cpp
src/service_main.cpp

index 21f8ccd..b348b2e 100644 (file)
@@ -97,6 +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);
        string get_default_assistant();
 
        bool update_voice_feedback_state(string appid, bool state);
index 307ff3c..5fb0b0c 100644 (file)
@@ -246,6 +246,7 @@ void CWakeupEngineManager::set_assistant_activated(string appid, bool activated)
                                if (info.activated) {
                                        try {
                                                info.interface.activate();
+                                               MWR_LOGW("Activating wakeup engine : %s", info.engine_name.c_str());
                                        } catch (const std::exception& e) {
                                                MWR_LOGE("[ERROR] wakeup engine %s threw exception : %s",
                                                        info.engine_name.c_str(), e.what());
@@ -253,6 +254,7 @@ void CWakeupEngineManager::set_assistant_activated(string appid, bool activated)
                                } else {
                                        try {
                                                info.interface.deactivate();
+                                               MWR_LOGW("Deactivating wakeup engine : %s", info.engine_name.c_str());
                                        } catch (const std::exception& e) {
                                                MWR_LOGE("[ERROR] wakeup engine %s threw exception : %s",
                                                        info.engine_name.c_str(), e.what());
@@ -394,20 +396,20 @@ void CWakeupEngineManager::streaming_speech_data_thread_func()
 
                        if (0 != ret) {
                                /* empty queue */
-                               MWR_LOGD("[DEBUG] No feedback data. Waiting mode : %d", ret);
+                               MWR_LOGD("[DEBUG] No feedback data. Waiting mode : %d %d", ret, cnt);
 
                                /* waiting */
                                while (!(mStopStreamingThread.load())) {
                                        burst_count = 0;
                                        this_thread::sleep_for(chrono::milliseconds(10));
                                        if (index < interface->get_utterance_data_count()) {
-                                               MWR_LOGD("[INFO] Resume thread");
+                                               MWR_LOGD("[INFO] Resume thread, %d", cnt);
                                                break;
                                        }
                                        mStreamingHistory.last_count_fetched.store(get_current_milliseconds_after_epoch());
                                        if (g_speech_pcm_wait_count < cnt) {
                                                unsigned char final_buffer[2] = {'\0', };
-                                               MWR_LOGE("[ERROR] Wrong request, there's no pcm data");
+                                               MWR_LOGE("[ERROR] Wrong request, there's no pcm data : %d", cnt);
 #ifdef BUF_SAVE_MODE
                                                if (g_pFile) {
                                                        fwrite(final_buffer, 1, sizeof(final_buffer), g_pFile);
@@ -654,12 +656,20 @@ void CWakeupEngineManager::engine_set_assistant_specific_command(string appid, s
 
 void CWakeupEngineManager::engine_feed_audio_data(long time, void* data, int len)
 {
+       bool print = false;
+       const std::chrono::seconds interval(3);
+       static auto last = std::chrono::steady_clock::now();
+       auto now = std::chrono::steady_clock::now();
+       if (now - last > interval) {
+               print = true;
+               last = now;
+       }
        for (const auto& info : mEngineInfo) {
+               bool filtered_out = false;
                if (info.activated &&
                        info.audio_data_require_status &&
                        info.interface.feed_audio_data) {
                        try {
-                               bool filtered_out = false;
                                /* After a wakeup event, wakeup engines other than the selected one
                                   does not need to receive audio data. */
                                if (WAKEUP_MANAGER_STATE_UTTERANCE == mWakeupManagerState) {
@@ -669,8 +679,8 @@ void CWakeupEngineManager::engine_feed_audio_data(long time, void* data, int len
                                }
                                if (!filtered_out) {
                                        int ret = info.interface.feed_audio_data(time, data, len);
-                                       if (0 != ret) {
-                                               LOGE("[ERROR] Fail to feed speech data, ret(%d) : %s", ret, info.engine_name.c_str());
+                                       if (ret != 0 || print) {
+                                               LOGE("Feed speech data, ret(%d) : %s", ret, info.engine_name.c_str());
                                        }
                                }
                        } catch (const std::exception& e) {
@@ -678,6 +688,12 @@ void CWakeupEngineManager::engine_feed_audio_data(long time, void* data, int len
                                        info.engine_name.c_str(), e.what());
                        }
                }
+               if (print) {
+                       MWR_LOGE("Feeding audio data to %s : %d %d %p %d",
+                               info.engine_name.c_str(),
+                               info.activated, info.audio_data_require_status,
+                               info.interface.feed_audio_data, filtered_out);
+               }
        }
 }
 
index 90580cc..7b631af 100644 (file)
@@ -299,7 +299,7 @@ bool CWakeupManager::set_assistant_enabled(string appid, bool enabled)
        if (false == mAssistantSupportsCurrentLanguage[appid]) {
                activated = false;
        }
-       if (0 == appid.compare(mCurrentDefaultAssistant)) {
+       if (0 == appid.compare(mWakeupSettings.get_default_assistant_appid())) {
                activated = true;
        }
        mWakeupEngineManager.set_assistant_activated(appid, activated);
@@ -310,13 +310,27 @@ bool CWakeupManager::set_assistant_enabled(string appid, bool enabled)
 
 bool CWakeupManager::set_default_assistant(string appid)
 {
-       MWR_LOGE("[ENTER] %s", appid.c_str());
+       MWR_LOGE("[ENTER] %s %s", appid.c_str(), mCurrentDefaultAssistant.c_str());
+
+       process_default_assistant_changed(appid);
+
+       mWakeupSettings.set_default_assistant_appid(appid);
+
+       return true;
+}
+
+bool CWakeupManager::process_default_assistant_changed(string appid)
+{
+       MWR_LOGE("[ENTER] %s %s", appid.c_str(), mCurrentDefaultAssistant.c_str());
+
+       if (mCurrentDefaultAssistant.compare(appid) == 0) {
+               MWR_LOGE("Default assistant appid not changed, ignoring...");
+               return false;
+       }
 
        if (mWakeupManagerState == WAKEUP_MANAGER_STATE_UTTERANCE ||
                mWakeupManagerState == WAKEUP_MANAGER_STATE_PROCESSING) {
-               if (mCurrentDefaultAssistant.compare(appid) != 0) {
-                       update_recognition_result(mCurrentDefaultAssistant, MA_RECOGNITION_RESULT_EVENT_ERROR);
-               }
+               update_recognition_result(mCurrentDefaultAssistant, MA_RECOGNITION_RESULT_EVENT_ERROR);
        }
 
        /* Check if previous default assistant has to be deactivated */
@@ -331,6 +345,7 @@ bool CWakeupManager::set_default_assistant(string appid)
 
        /* New default assistant has to be activated no matter what */
        mWakeupEngineManager.set_assistant_activated(appid, true);
+
        mCurrentDefaultAssistant = appid;
 
        MWR_LOGD("[END]");
@@ -339,7 +354,7 @@ bool CWakeupManager::set_default_assistant(string appid)
 
 string CWakeupManager::get_default_assistant()
 {
-       return mCurrentDefaultAssistant;
+       return mWakeupSettings.get_default_assistant_appid();
 }
 
 bool CWakeupManager::get_assistant_enabled(string appid)
@@ -378,7 +393,7 @@ bool CWakeupManager::set_language(string language)
                if (false == mAssistantEnabled[info.appid]) {
                        disable = true;
                }
-               if (0 == info.appid.compare(mCurrentDefaultAssistant)) {
+               if (0 == info.appid.compare(mWakeupSettings.get_default_assistant_appid())) {
                        /* Default Assistant should be activated no matter what */
                        disable = false;
                }
@@ -575,7 +590,8 @@ bool CWakeupManager::process_plugin_event(mas_plugin_event_e event, void* data,
                wakeup_info.wakeup_end_time = get_current_milliseconds_after_epoch();
                wakeup_info.wakeup_engine = WAKEUP_ENGINE_VOICE_KEY;
 
-               wakeup_info.wakeup_appid = mCurrentDefaultAssistant.c_str();
+               std::string default_assistant_appid = mWakeupSettings.get_default_assistant_appid();
+               wakeup_info.wakeup_appid = default_assistant_appid.c_str();
                MWR_LOGD("wakeup_appid : %s", wakeup_info.wakeup_appid);
 
                set_last_wakeup_event_info(wakeup_info);
@@ -879,6 +895,7 @@ bool CWakeupManager::unset_voice_key_tap_duration()
 
 bool CWakeupManager::set_voice_key_support_mode(VOICE_KEY_SUPPORT_MODE mode)
 {
+       MWR_LOGI("Voice key support mode : %d", mode);
        mCurrentVoiceKeySupportMode = mode;
        return true;
 }
@@ -1077,7 +1094,7 @@ void CWakeupManager::CPolicyEventObserver::on_wakeup(mas_wakeup_event_info wakeu
        if (nullptr == audio_manager || nullptr == engine_manager || nullptr == settings) return;
 
        if (wakeup_info.wakeup_appid && strlen(wakeup_info.wakeup_appid) > 0) {
-               settings->set_default_assistant_appid(wakeup_info.wakeup_appid);
+               mWakeupManager->set_default_assistant(wakeup_info.wakeup_appid);
        }
 
        mWakeupManager->stop_streaming_utterance_data();
@@ -1157,7 +1174,7 @@ bool CWakeupManager::CSettingsEventObserver::on_default_assistant_appid_changed(
        const char* appid)
 {
        if (nullptr == mWakeupManager || nullptr == appid) return false;
-       mWakeupManager->set_default_assistant(std::string(appid));
+       mWakeupManager->process_default_assistant_changed(std::string(appid));
        vector<ISettingValueObserver*> observers = mWakeupManager->get_setting_observers();
        for (const auto& observer : observers) {
                observer->on_value_changed();
index eb22125..00c258f 100644 (file)
 
 #include <memory>
 
+#if 0
+#define BUF_SAVE_MODE
+#endif
+#if 0
+#define BUF_LOAD_MODE
+#endif
+
+#ifdef BUF_SAVE_MODE
+static char g_temp_file_name[128] = {'\0', };
+
+static FILE* g_pFile = NULL;
+
+static int g_count = 1;
+#endif
+
+#ifdef BUF_LOAD_MODE
+static FILE* g_pFile = NULL;
+#endif
+
 using namespace multiassistant::wakeup;
 
 static wakeup_service_wakeup_event_cb g_wakeup_event_cb;
@@ -75,6 +94,30 @@ static std::unique_ptr<CWakeupEventObserver> g_wakeup_event_observer;
 static std::unique_ptr<CSettingValueObserver> g_setting_value_observer;
 static std::unique_ptr<CWakeupManager> g_wakeup_manager;
 
+int wakeup_manager_feed_audio_data(mas_speech_streaming_event_e event, void* buffer, int len);
+
+#ifdef BUF_LOAD_MODE
+static Eina_Bool file_read_feed(void *data)
+{
+       if (g_pFile == NULL) {
+               g_pFile = fopen("/tmp/ma_feed_file", "rb");
+               if (g_pFile == NULL) return EINA_FALSE;
+       }
+
+       if (feof(g_pFile)) {
+               fclose(g_pFile);
+               return EINA_FALSE;
+       }
+
+       const size_t BUFFER_SIZE = 4096;
+       unsigned char buffer[BUFFER_SIZE];
+       size_t len = fread(buffer, sizeof(unsigned char), BUFFER_SIZE, g_pFile);
+       wakeup_manager_feed_audio_data(MAS_SPEECH_STREAMING_EVENT_CONTINUE, buffer, len);
+
+       return EINA_TRUE;
+}
+#endif
+
 int wakeup_manager_initialize(void)
 {
        MWR_LOGI("[ENTER]");
@@ -127,6 +170,45 @@ int wakeup_manager_initialize(void)
        g_wakeup_manager->initialize();
 
        MWR_LOGD("[END]");
+
+#ifdef BUF_SAVE_MODE
+       if (g_pFile) {
+               fclose(g_pFile);
+               g_pFile = NULL;
+       } else {
+               MWR_LOGD("[Recorder Info] File not found!");
+       }
+
+       while (1) {
+               snprintf(g_temp_file_name, sizeof(g_temp_file_name), "/tmp/wakeup_manager_%d_%d", getpid(), g_count);
+               int ret = access(g_temp_file_name, 0);
+
+               if (0 == ret) {
+                       MWR_LOGD("[Recorder ERROR] File is already exist");
+                       if (0 == remove(g_temp_file_name)) {
+                               MWR_LOGD("[Recorder] Remove file");
+                               break;
+                       } else {
+                               g_count++;
+                       }
+               } else {
+                       break;
+               }
+       }
+
+       MWR_LOGD("[Recorder] Temp file name=[%s]", g_temp_file_name);
+
+       /* open test file */
+       g_pFile = fopen(g_temp_file_name, "wb+x");
+       if (!g_pFile) {
+               MWR_LOGD("[Recorder ERROR] File not found!");
+       }
+       g_count++;
+#endif
+
+#ifdef BUF_LOAD_MODE
+       Ecore_Timer* timer = ecore_timer_add(0.01f, file_read_feed, NULL);
+#endif
        return 0;
 }
 
@@ -134,6 +216,14 @@ int wakeup_manager_deinitialize(void)
 {
        MWR_LOGI("[ENTER]");
 
+#ifdef BUF_SAVE_MODE
+       if (g_pFile) {
+               MWR_LOGE("[Recorder SUCCESS] File Close");
+               fclose(g_pFile);
+               g_pFile = NULL;
+       }
+#endif
+
        if (nullptr == g_wakeup_manager) return -1;
 
        try {
@@ -744,6 +834,13 @@ int wakeup_manager_feed_audio_data(mas_speech_streaming_event_e event, void* buf
 {
        if (nullptr == g_wakeup_manager) return -1;
 
+#ifdef BUF_SAVE_MODE
+       static int num = 0;
+       const int MAXIMUM_NUM = 1000;
+       if (g_pFile && num++ < MAXIMUM_NUM)
+               fwrite(buffer, 1, len, g_pFile);
+#endif
+
        g_wakeup_manager->feed_audio_data(event, buffer, len);
 
        return 0;
index 4022002..329d4c3 100644 (file)
@@ -263,10 +263,10 @@ string CWakeupSettings::get_default_assistant_appid()
 {
        char *vconf_str;
        vconf_str = vconf_get_str(WAKEUP_SETTINGS_KEY_DEFAULT_ASSISTANT_APPID);
-       MWR_LOGD("default_assistant_appid : %s", vconf_str);
+       MWR_LOGD("vconf default_assistant_appid : %s", vconf_str);
        if (vconf_str) {
                mDefaultAssistantAppid = vconf_str;
-               MWR_LOGD("default_assistant_appid : %s", mDefaultAssistantAppid.c_str());
+               MWR_LOGD("member default_assistant_appid : %s", mDefaultAssistantAppid.c_str());
                free(vconf_str);
                vconf_str = nullptr;
        }
@@ -276,6 +276,10 @@ string CWakeupSettings::get_default_assistant_appid()
 
 void CWakeupSettings::set_default_assistant_appid(std::string appid)
 {
+       if (appid.compare(get_default_assistant_appid()) == 0) {
+               MWR_LOGE("Default assistant appid not changed, ignoring...");
+               return;
+       }
        int ret = vconf_set_str(WAKEUP_SETTINGS_KEY_DEFAULT_ASSISTANT_APPID, appid.c_str());
        MWR_LOGD("default_assistant_appid : %s, %d", appid.c_str(), ret);
        mDefaultAssistantAppid = appid;
index e380782..458c384 100644 (file)
@@ -76,7 +76,6 @@ int CClientManager::destroy_client_by_appid(std::string appid)
 
 ma_client_s* CClientManager::find_client_by_appid(std::string appid)
 {
-       MAS_LOGD("Looking for client with appid : %s", appid.c_str());
        ma_client_s *data = NULL;
 
        int count = g_slist_length(mClientList);
@@ -87,13 +86,12 @@ ma_client_s* CClientManager::find_client_by_appid(std::string appid)
 
                if (NULL != data) {
                        if (0 == appid.compare(data->appid)) {
-                               MAS_LOGD("Found client : %s %d", data->appid.c_str(), data->pid);
                                return data;
                        }
                }
        }
 
-       MAS_LOGE("[ERROR] client Not found");
+       MAS_LOGE("[ERROR] client Not found : %s", appid.c_str());
 
        return NULL;
 }
@@ -142,7 +140,6 @@ pid_t CClientManager::find_client_pid_by_index(unsigned int index)
 
 pid_t CClientManager::find_client_pid_by_appid(std::string appid)
 {
-       MAS_LOGD("Checking PID of appid : %s", appid.c_str());
        pid_t pid = -1;
 
        if (nullptr == mApplicationManager) {
@@ -152,7 +149,6 @@ pid_t CClientManager::find_client_pid_by_appid(std::string appid)
 
        ma_client_s* client = find_client_by_appid(appid);
        if (client) {
-               MAS_LOGD("Found client : %s %d", client->appid.c_str(), client->pid);
                bool running = mApplicationManager->is_application_running(client->pid);
                if (false == running) {
                        MAS_LOGE("The PID for %s was %d, but it seems to be terminated",
index 635f895..96cba78 100644 (file)
@@ -945,6 +945,8 @@ const char* CServiceMain::get_client_appid_by_wakeup_word(const char *wakeup_wor
 
 int CServiceMain::set_current_client_by_wakeup_word(const char *wakeup_word)
 {
+       LOGI("[ENTER] %s", wakeup_word);
+
        int loop;
        int ret = -1;
        int prev_selection = mCurrentClientInfo;
@@ -1006,6 +1008,8 @@ int CServiceMain::set_current_client_by_wakeup_word(const char *wakeup_word)
 
 int CServiceMain::set_current_client_by_appid(const char *appid)
 {
+       LOGI("[ENTER] %s", appid);
+
        int ret = -1;
        int prev_selection = mCurrentClientInfo;
 
@@ -1039,6 +1043,7 @@ int CServiceMain::set_current_client_by_appid(const char *appid)
 
 int CServiceMain::launch_client_by_appid(const char *appid, CLIENT_LAUNCH_MODE launch_mode)
 {
+       LOGI("[ENTER] %s", appid);
        int result = 0;
 
        if (NULL == appid || 0 == strlen(appid)) {
@@ -1069,7 +1074,7 @@ int CServiceMain::launch_client_by_appid(const char *appid, CLIENT_LAUNCH_MODE l
                                }
                        }
                }
-               MAS_LOGD("mWakeupClientAppId : %s, %d", mWakeupClientAppId.c_str(), found);
+               MAS_LOGE("mWakeupClientAppId : %s, %d", mWakeupClientAppId.c_str(), found);
        }
 
        return result;
@@ -1077,6 +1082,7 @@ int CServiceMain::launch_client_by_appid(const char *appid, CLIENT_LAUNCH_MODE l
 
 int CServiceMain::bring_client_to_foreground(const char* appid)
 {
+       LOGI("[ENTER]");
        int ret = 0;
 
        if (NULL == appid || 0 == strlen(appid)) {
@@ -1099,6 +1105,7 @@ int CServiceMain::launch_client_by_wakeup_word(const char *wakeup_word)
 
 int CServiceMain::prelaunch_default_assistant()
 {
+       LOGI("[ENTER]");
        /* CHECK NEEDED : should the code segment below and activation logic above be moved to wakeup manger? */
        boost::optional<bool> prelaunch_mode =
                mPreferenceManager.get_bool(WAKEUP_SETTINGS_KEY_PRELAUNCH_MODE);
@@ -1117,6 +1124,7 @@ int CServiceMain::prelaunch_default_assistant()
 
 int CServiceMain::update_voice_key_support_mode()
 {
+       LOGI("[ENTER]");
        /* CHECK NEEDED : should the code segment below and activation logic above be moved to wakeup manger? */
        bool successful = false;
        const char *default_assistant = NULL;
@@ -1124,6 +1132,7 @@ int CServiceMain::update_voice_key_support_mode()
                for (int loop = 0; loop < MAX_MACLIENT_INFO_NUM; loop++) {
                        ClientInfoItems *items = mClientInfo.getItems();
                        if (items[loop].used) {
+                               LOGI("APPID : %s", items[loop].appid);
                                if (default_assistant &&
                                        strncmp(default_assistant, items[loop].appid, MAX_APPID_LEN) == 0) {
                                        float duration = items[loop].voice_key_tap_duration;
@@ -1141,6 +1150,7 @@ int CServiceMain::update_voice_key_support_mode()
        }
 
        if (!successful) {
+               LOGE("VOICE KEY SUPPORT MODE update not successful!!!");
                mServicePlugin.unset_voice_key_tap_duration();
                mServicePlugin.set_voice_key_support_mode(VOICE_KEY_SUPPORT_MODE_NONE);
        }