Postpone restart operation when streaming audio data 59/285659/1
authorJi-hoon Lee <dalton.lee@samsung.com>
Thu, 15 Dec 2022 03:59:39 +0000 (12:59 +0900)
committerJi-hoon Lee <dalton.lee@samsung.com>
Fri, 16 Dec 2022 05:45:59 +0000 (14:45 +0900)
Change-Id: I0189262b57d89885c4463a8443939cbc5f67660b

inc/service_plugin.h
src/service_plugin.cpp

index 69d081c..6a4691d 100644 (file)
@@ -81,8 +81,11 @@ public:
        void set_service_ipc(CServiceIpcDbus* ipc) { mServiceIpc = ipc; }
        CServiceIpcDbus* get_service_ipc() { return mServiceIpc; }
 
-    void set_service_main(CServiceMain* main) { mServiceMain = main; }
-    CServiceMain* get_service_main() { return mServiceMain; }
+       void set_service_main(CServiceMain* main) { mServiceMain = main; }
+       CServiceMain* get_service_main() { return mServiceMain; }
+
+       void start_app_restart_timer();
+       void stop_app_restart_timer();
 private:
 #ifdef BUF_SAVE_MODE
        char mDumpFilename[128]{'\0', };
@@ -96,7 +99,9 @@ private:
        ma_plugin_settings* mPluginSettings{NULL};
 
        CServiceIpcDbus* mServiceIpc{nullptr};
-    CServiceMain* mServiceMain{nullptr};
+       CServiceMain* mServiceMain{nullptr};
+
+       Ecore_Timer *mAppRestartTimer{nullptr};
 };
 
 #endif /* __SERVICE_PLUGIN_H__ */
index 3f3ba2a..2b8e8da 100644 (file)
@@ -643,6 +643,37 @@ static void __wakeup_service_voice_key_status_changed_cb(ma_voice_key_status_e s
        }
 }
 
+static Eina_Bool app_restart_timer_func(void *user_data)
+{
+       CServicePlugin *plugin = static_cast<CServicePlugin*>(user_data);
+       if (plugin) {
+               CServiceMain* service_main = plugin->get_service_main();
+               if (service_main) {
+                       ma_service_state_e service_state = service_main->get_current_service_state();
+                       if (service_state != MA_SERVICE_STATE_UTTERANCE) {
+                               MAS_LOGE("[SUCCESS] Restarting service");
+                               service_main->app_restart();
+                       }
+               }
+       }
+
+       return ECORE_CALLBACK_RENEW;
+}
+
+void CServicePlugin::stop_app_restart_timer()
+{
+       if (mAppRestartTimer) {
+               ecore_timer_del(mAppRestartTimer);
+               mAppRestartTimer = nullptr;
+       }
+}
+
+void CServicePlugin::start_app_restart_timer()
+{
+       stop_app_restart_timer();
+       mAppRestartTimer = ecore_timer_add(1.0f, app_restart_timer_func, this);
+}
+
 static void __loaded_engine_changed_cb(void* user_data)
 {
        MAS_LOGD("[SUCCESS] __loaded_engine_changed_cb is called");
@@ -654,12 +685,12 @@ static void __loaded_engine_changed_cb(void* user_data)
        if (service_main) {
                /* Make sure the app doesn't restart within a conversation session */
                ma_service_state_e service_state = service_main->get_current_service_state();
-               if (service_state == MA_SERVICE_STATE_INACTIVE ||
-                       service_state == MA_SERVICE_STATE_LISTENING) {
+               if (service_state != MA_SERVICE_STATE_UTTERANCE) {
                        MAS_LOGE("[SUCCESS] Restarting service");
                        service_main->app_restart();
                } else {
                        MAS_LOGE("Cannot restart service when service_state is %d", service_state);
+                       plugin->start_app_restart_timer();
                }
        }
 }
@@ -855,6 +886,11 @@ int CServicePlugin::deinitialize(void)
        }
 #endif
 
+       if (mAppRestartTimer) {
+               ecore_timer_del(mAppRestartTimer);
+               mAppRestartTimer = nullptr;
+       }
+
        int ret = -1;
        if (NULL != mPluginHandle) {
                wakeup_manager_deinitialize func = mWakeupManagerInterface.deinitialize;