Add sample code for terminating host process 73/215973/1
authorJi-hoon Lee <dalton.lee@samsung.com>
Wed, 16 Oct 2019 07:38:12 +0000 (16:38 +0900)
committerJi-hoon Lee <dalton.lee@samsung.com>
Fri, 18 Oct 2019 04:34:55 +0000 (13:34 +0900)
Change-Id: I4106710af29912e58bd0c4d0123cc1348f8ecc69

plugins/wakeup-manager/dependency-default/src/dependency_default.cpp
plugins/wakeup-manager/dependency-default/src/dependency_default_audio.cpp

index be13250..edff076 100644 (file)
@@ -2,9 +2,16 @@
 #include "dependency_default_audio.h"
 #include "dependency_default_button.h"
 
+#include <dlog.h>
+#include <service_app_extension.h>
+
+#include <thread>
+
 static mas_proxy_interface g_proxy_interface;
 const int g_dependency_version = 1;
 
+static bool g_should_exit = false;
+
 int mas_dependency_initialize(mas_proxy_interface interface, int *dependency_version)
 {
        g_proxy_interface = interface;
@@ -16,6 +23,20 @@ int mas_dependency_initialize(mas_proxy_interface interface, int *dependency_ver
                *dependency_version = g_dependency_version;
        }
 
+       /* If the service process has to terminate in certain circumstances,
+               set g_should_exit variable to true as below. */
+       // g_should_exit = true;
+
+       if (g_should_exit) {
+               LOGE("g_should_exit value contains positive value, registering timer");
+               std::thread([]() {
+                       std::this_thread::sleep_for(std::chrono::milliseconds(1000));
+                       LOGE("Now trying to exit");
+                       mas_dependency_deinitialize();
+                       service_app_exit_without_restart();
+               }).detach();
+       }
+
        return 0;
 }
 
index 1bc67c5..e803739 100644 (file)
@@ -190,6 +190,8 @@ void dependency_default_audio_initialize(mas_proxy_interface interfaces)
 
 void dependency_default_audio_deinitialize()
 {
+       dependency_default_audio_stop_recording();
+
        int ret = 0;
        if (g_virtual_sound_stream) {
                sound_manager_stop_virtual_stream(g_virtual_sound_stream);
@@ -268,13 +270,15 @@ static void recorder_thread_func()
 
 void dependency_default_audio_start_recording()
 {
-       int ret = audio_in_resume(g_audio_in);
-       if (AUDIO_IO_ERROR_NONE != ret) {
-               LOGD("[Recorder ERROR] Fail to resume audio in : %d", ret);
+       if (g_audio_in) {
+               int ret = audio_in_resume(g_audio_in);
+               if (AUDIO_IO_ERROR_NONE != ret) {
+                       LOGD("[Recorder ERROR] Fail to resume audio in : %d", ret);
+               }
+               g_stop_recorder_thread.store(false);
+               LOGD("Starting recorder thread");
+               g_recorder_thread = thread(recorder_thread_func);
        }
-       g_stop_recorder_thread.store(false);
-       LOGD("Starting recorder thread");
-       g_recorder_thread = thread(recorder_thread_func);
 }
 
 void dependency_default_audio_stop_recording()
@@ -284,9 +288,11 @@ void dependency_default_audio_stop_recording()
                g_stop_recorder_thread.store(true);
                g_recorder_thread.join();
        }
-       int ret = audio_in_pause(g_audio_in);
-       if (AUDIO_IO_ERROR_NONE != ret) {
-               LOGD("[Recorder ERROR] Fail to pause audio in : %d", ret);
+       if (g_audio_in) {
+               int ret = audio_in_pause(g_audio_in);
+               if (AUDIO_IO_ERROR_NONE != ret) {
+                       LOGD("[Recorder ERROR] Fail to pause audio in : %d", ret);
+               }
        }
 }