From 7c50b342d94f258c7c2331df7b9b7ff81c1d6e52 Mon Sep 17 00:00:00 2001 From: Jihoon Kim Date: Fri, 21 Feb 2020 20:49:19 +0900 Subject: [PATCH] Terminate sticker-receiver when disconnected from mobile device Change-Id: I463ed46ba612b7a2521e26a242386bb283e946d3 Signed-off-by: Jihoon Kim --- receiver/inc/ft.h | 1 + receiver/src/ft.cpp | 33 +++++++++++++++++++++++++++++++++ receiver/src/main.cpp | 1 + 3 files changed, 35 insertions(+) diff --git a/receiver/inc/ft.h b/receiver/inc/ft.h index b64fa8d..bf25d8e 100644 --- a/receiver/inc/ft.h +++ b/receiver/inc/ft.h @@ -27,6 +27,7 @@ void reject_file(void); void accept_file(void); gboolean initialize_sap(void); +void deinitialize_sap(void); void sap_file_transfer_get_receive_filepath(char **filepath); diff --git a/receiver/src/ft.cpp b/receiver/src/ft.cpp index a67c6d6..ac09cf5 100644 --- a/receiver/src/ft.cpp +++ b/receiver/src/ft.cpp @@ -17,6 +17,7 @@ #include #include #include +#include #include #include #include @@ -213,6 +214,7 @@ void conn_terminated(sap_peer_agent_h peer_agent, void *user_data) { LOGI("connection terminated"); + service_app_exit(); } void @@ -271,6 +273,13 @@ static void on_agent_initialized(sap_agent_h agent, } } +static void on_agent_deinitialized(sap_agent_h agent, + sap_agent_deinitialized_result_e result, + void *user_data) +{ + LOGD("result of deinitialize : %d", result); +} + static void _on_device_status_changed(sap_device_status_e status, sap_transport_type_e transport_type, void *user_data) @@ -346,3 +355,27 @@ gboolean initialize_sap(void) return TRUE; } + +void deinitialize_sap(void) +{ + if (priv_data.agent) { + int ret = sap_agent_deinitialize(priv_data.agent, on_agent_deinitialized, NULL); + switch (ret) { + case SAP_RESULT_FAILURE: + LOGW("Failed to deinitialize"); + break; + case SAP_RESULT_SUCCESS: + LOGD("Succeed to deinitialize"); + break; + case SAP_RESULT_PERMISSION_DENIED: + LOGW("permission denied: deinitialize "); + break; + default: + LOGD("deinitialize : %d", ret); + break; + } + + sap_agent_destroy(priv_data.agent); + priv_data.agent = NULL; + } +} diff --git a/receiver/src/main.cpp b/receiver/src/main.cpp index d99158b..6151d90 100644 --- a/receiver/src/main.cpp +++ b/receiver/src/main.cpp @@ -24,6 +24,7 @@ static void app_control(app_control_h app_control, void *data) static void app_terminate(void *data) { /* Release all resources. */ + deinitialize_sap(); } int main(int argc, char *argv[]) -- 2.7.4