Handle the pending dbus calls before termination
[platform/core/connectivity/bluetooth-frwk.git] / bt-service-adaptation / services / bt-request-handler.c
index 45cf633..752f5de 100644 (file)
@@ -23,6 +23,7 @@
 #include <gio/gunixfdlist.h>
 #include <cynara-client.h>
 #include <cynara-creds-gdbus.h>
+#include <systemd/sd-daemon.h>
 
 #include "bluetooth-api.h"
 #include "bluetooth-audio-api.h"
@@ -193,9 +194,7 @@ static void __bt_service_get_parameters(GVariant *in_param,
 static gboolean __bt_is_sync_function(int service_function)
 {
        /*TODO: Keep adding sync methods with expect replies from bluetooth service */
-       if (service_function == BT_ENABLE_ADAPTER
-                       || service_function == BT_DISABLE_ADAPTER
-                       || service_function == BT_GET_LOCAL_ADDRESS
+       if (service_function == BT_GET_LOCAL_ADDRESS
                        || service_function == BT_GET_LOCAL_NAME
                        || service_function == BT_GET_LOCAL_VERSION
                        || service_function == BT_GET_BONDED_DEVICES
@@ -256,7 +255,7 @@ void _bt_save_invocation_context(GDBusMethodInvocation *invocation, int result,
 
 static int __bt_bm_request_data(_bt_battery_data_t *latest)
 {
-        int ret = _bt_bm_read_data(latest);
+       int ret = _bt_bm_read_data(latest);
        if (ret == BLUETOOTH_ERROR_NONE) {
                BT_DBG("Received data from bluetooth battery monitor: %ld %ld %d %d",
                        latest->session_start_time, latest->session_end_time,
@@ -441,24 +440,10 @@ int __bt_bluez_request(int function_name,
        switch (function_name) {
        case BT_ENABLE_ADAPTER: {
                result = _bt_enable_adapter();
-               /* Save invocation */
-               if (result == BLUETOOTH_ERROR_NONE) {
-                       BT_DBG("_bt_enable_adapter scheduled successfully! save invocation context");
-                       sender = (char*)g_dbus_method_invocation_get_sender(context);
-                       _bt_save_invocation_context(context, result, sender,
-                                       function_name, NULL);
-               }
                break;
        }
        case BT_DISABLE_ADAPTER: {
                result = _bt_disable_adapter();
-               /* Save invocation */
-               if (result == BLUETOOTH_ERROR_NONE) {
-                       BT_DBG("_bt_disable_adapter scheduled successfully! save invocation context");
-                       sender = (char*)g_dbus_method_invocation_get_sender(context);
-                       _bt_save_invocation_context(context, result, sender,
-                                       function_name, NULL);
-               }
                break;
        }
        case BT_RECOVER_ADAPTER:
@@ -900,6 +885,31 @@ int __bt_bluez_request(int function_name,
                result = _bt_set_white_list(&address, address_type, is_add);
                break;
         }
+       case BT_UPDATE_LE_CONNECTION_MODE: {
+               char *sender = NULL;
+               bluetooth_device_address_t remote_address = { { 0 } };
+               bluetooth_le_connection_param_t parameters = { 0 };
+               bluetooth_le_connection_mode_t mode = BLUETOOTH_LE_CONNECTION_MODE_BALANCED;
+
+               __bt_service_get_parameters(in_param1, &remote_address,
+                               sizeof(bluetooth_device_address_t));
+               __bt_service_get_parameters(in_param2, &mode,
+                               sizeof(bluetooth_le_connection_mode_t));
+
+               result = _bt_get_le_connection_parameter(mode, &parameters);
+               if (result != BLUETOOTH_ERROR_NONE)
+                       break;
+
+               sender = (char *)g_dbus_method_invocation_get_sender(context);
+
+               result = _bt_le_connection_update(sender,
+                               remote_address.addr,
+                               parameters.interval_min,
+                               parameters.interval_max,
+                               parameters.latency,
+                               parameters.timeout);
+               break;
+       }
        case BT_SET_MANUFACTURER_DATA: {
                bluetooth_manufacturer_data_t m_data = { 0 };
                __bt_service_get_parameters(in_param1,
@@ -3147,29 +3157,6 @@ normal:
                g_array_append_vals(*out_param1, &is_coded_phy_supported, sizeof(gboolean));
                break;
        }
-       case BT_UNREGISTER_SCAN_FILTER:{
-               char *sender = NULL;
-               int slot_id;
-
-               sender = (char *)g_dbus_method_invocation_get_sender(context);
-               __bt_service_get_parameters(in_param1, &slot_id, sizeof(int));
-               BT_DBG("Remove scan filter [Slot ID : %d]", slot_id);
-
-               result = _bt_unregister_scan_filter(sender, slot_id);
-
-               break;
-       }
-       case BT_UNREGISTER_ALL_SCAN_FILTERS: {
-               char *sender = NULL;
-
-               sender = (char *)g_dbus_method_invocation_get_sender(context);
-
-               BT_DBG("Remove all scan filters [Sender : %s]", sender);
-
-               result = _bt_unregister_all_scan_filters(sender);
-
-               break;
-       }
        case BT_DISCONNECT_DEVICE: {
                bluetooth_device_address_t address = { {0} };
 
@@ -3181,7 +3168,6 @@ normal:
        }
        case BT_REGISTER_SCAN_FILTER: {
                bluetooth_le_scan_filter_t scan_filter;
-               int slot_id;
 
                sender = (char*)g_dbus_method_invocation_get_sender(context);
                __bt_service_get_parameters(in_param1, &scan_filter,
@@ -3190,9 +3176,8 @@ normal:
                BT_DBG("bluetooth_le_scan_filter_t [features : 0x%.2x]",
                                scan_filter.added_features);
 
-               result = _bt_register_scan_filter(sender, &scan_filter, &slot_id);
+               result = _bt_register_scan_filter(sender, &scan_filter);
 
-               g_array_append_vals(*out_param1, &slot_id, sizeof(int));
                break;
        }
        default:
@@ -4149,8 +4134,6 @@ gboolean __bt_service_check_privilege(int function_name,
        case BT_IS_LE_2M_PHY_SUPPORTED:
        case BT_IS_LE_CODED_PHY_SUPPORTED:
        case BT_REGISTER_SCAN_FILTER:
-       case BT_UNREGISTER_SCAN_FILTER:
-       case BT_UNREGISTER_ALL_SCAN_FILTERS:
        case BT_IS_SCAN_FILTER_SUPPORTED:
        case BT_GET_ATT_MTU:
 
@@ -4286,6 +4269,19 @@ gboolean _is_name_acquired(void)
        return name_acquired;
 }
 
+void _bt_service_unref_connection(void)
+{
+       BT_INFO("+");
+
+       if (bt_service_conn) {
+               g_dbus_connection_flush_sync(bt_service_conn, NULL, NULL);
+               g_object_unref(bt_service_conn);
+               bt_service_conn = NULL;
+       }
+
+       BT_INFO("-");
+}
+
 int _bt_service_register(void)
 {
        GDBusConnection *conn;
@@ -4327,21 +4323,20 @@ fail:
 void _bt_service_unregister(void)
 {
        if (bt_service_conn) {
+               sd_notify(0, "STOPPING=1");
+
                if (owner_sig_id > 0) {
                        g_dbus_connection_signal_unsubscribe(
                                        bt_service_conn, owner_sig_id);
                        owner_sig_id = 0;
                }
 
-               __bt_service_register_object(bt_service_conn, NULL, FALSE);
-               if (bt_service_conn) {
-                       g_object_unref(bt_service_conn);
-                       bt_service_conn = NULL;
-               }
                if (owner_id > 0) {
                        g_bus_unown_name(owner_id);
                        owner_id = 0;
                }
+
+               __bt_service_register_object(bt_service_conn, NULL, FALSE);
        }
 }