Make string members of wakeup event struct to be deep copied 21/263621/2
authorJi-hoon Lee <dalton.lee@samsung.com>
Mon, 6 Sep 2021 12:00:04 +0000 (21:00 +0900)
committerJi-hoon Lee <dalton.lee@samsung.com>
Tue, 7 Sep 2021 07:37:47 +0000 (07:37 +0000)
This fixes the problem found when running the previously added test.

[ RUN      ] DefaultFixture.WakeupEventInfoPreservedForStringLiterals
[       OK ] DefaultFixture.WakeupEventInfoPreservedForStringLiterals (2 ms)
[ RUN      ] DefaultFixture.WakeupEventInfoPreservedForDynamicallyAllocatedStrings
[       OK ] DefaultFixture.WakeupEventInfoPreservedForDynamicallyAllocatedStrings (0 ms)
[----------] 2 tests from DefaultFixture (2 ms total)

Change-Id: I24fecd9a78767beda7fafce67f69fae6d53ebf1d

plugins/wakeup-manager/inc/wakeup_policy_default.h
plugins/wakeup-manager/src/wakeup_policy_default.cpp

index 914c539..c0c6efa 100644 (file)
@@ -29,6 +29,18 @@ namespace multiassistant
 namespace wakeup
 {
 
+typedef struct {
+       std::string wakeup_appid;
+       std::string wakeup_word;
+       std::string wakeup_language;
+       std::string wakeup_voice_id;
+       std::string wakeup_engine;
+
+       std::string extra_data_description;
+       mas_wakeup_event_info info;
+} mas_wakeup_event_info_wrapper;
+
+
 using namespace std;
 
 class CWakeupPolicyDefault : public CWakeupPolicy
@@ -60,7 +72,7 @@ private:
 
        float mDelaySeconds{0.0f};
        vector<PRIORITY_INFO> mPriorityInfos;
-       vector<mas_wakeup_event_info> mWakeupInfos;
+       vector<mas_wakeup_event_info_wrapper> mWakeupInfos;
 
        Ecore_Timer *mTimer{nullptr};
 };
index 1199b26..ef1bab5 100644 (file)
@@ -75,7 +75,18 @@ static Eina_Bool timer_func(void *data)
 void CWakeupPolicyDefault::wakeup_candidate(mas_wakeup_event_info wakeup_info)
 {
        MWR_LOGI("[ENTER]");
-       mWakeupInfos.push_back(wakeup_info);
+       mas_wakeup_event_info_wrapper wrapper;
+       if (wakeup_info.wakeup_appid) wrapper.wakeup_appid = wakeup_info.wakeup_appid;
+       if (wakeup_info.wakeup_word) wrapper.wakeup_word = wakeup_info.wakeup_word;
+       if (wakeup_info.wakeup_language) wrapper.wakeup_language = wakeup_info.wakeup_language;
+       if (wakeup_info.wakeup_voice_id) wrapper.wakeup_voice_id = wakeup_info.wakeup_voice_id;
+       if (wakeup_info.wakeup_engine) wrapper.wakeup_engine = wakeup_info.wakeup_engine;
+       if (wakeup_info.extra_data_description) wrapper.extra_data_description = wakeup_info.extra_data_description;
+
+       wrapper.info = wakeup_info;
+
+       LOGI("wake word : %s", wakeup_info.wakeup_word);
+       mWakeupInfos.push_back(wrapper);
        if (nullptr == mTimer) {
                ecore_main_loop_thread_safe_call_async([](void* data) {
                        CWakeupPolicyDefault* policy = static_cast<CWakeupPolicyDefault*>(data);
@@ -98,7 +109,8 @@ void CWakeupPolicyDefault::timer_expired()
        MWR_LOGD("[ENTER]");
        if (0 == mWakeupInfos.size()) return;
 
-       mas_wakeup_event_info selected = mWakeupInfos.front();
+       mas_wakeup_event_info_wrapper selected = mWakeupInfos.front();
+       LOGD("wake word : %s", selected.wakeup_word.c_str());
        int selected_priority = -1;
        for (const auto &wakeup : mWakeupInfos) {
                for (const auto &info : mPriorityInfos) {
@@ -112,7 +124,14 @@ void CWakeupPolicyDefault::timer_expired()
                        }
                }
        }
-       if (mImpl) mImpl->wakeup(selected);
+       selected.info.wakeup_appid = selected.wakeup_appid.c_str();
+       selected.info.wakeup_word = selected.wakeup_word.c_str();
+       selected.info.wakeup_language = selected.wakeup_language.c_str();
+       selected.info.wakeup_voice_id = selected.wakeup_voice_id.c_str();
+       selected.info.wakeup_engine = selected.wakeup_engine.c_str();
+       selected.info.extra_data_description = selected.extra_data_description.c_str();
+
+       if (mImpl) mImpl->wakeup(selected.info);
        mWakeupInfos.clear();
 
        if (mTimer) {