Postpone restart operation when streaming audio data
[platform/core/uifw/multi-assistant-service.git] / src / service_plugin.cpp
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;