Apply tizen 3.0 based product patchsets
[platform/core/connectivity/bluetooth-frwk.git] / bt-service / bt-request-handler.c
index ba994ba..38ec417 100644 (file)
@@ -73,7 +73,7 @@ static const gchar bt_service_introspection_xml[] =
 "      </interface>"
 "</node>";
 
-GDBusNodeInfo *node_info = NULL;
+static gboolean name_acquired = FALSE;
 
 static char *current_sender_playing = NULL;
 
@@ -715,15 +715,19 @@ int __bt_bluez_request(int function_name,
                break;
        }
        case BT_LE_CONN_UPDATE: {
+               char *sender = NULL;
                bluetooth_device_address_t local_address = { {0} };
                bluetooth_le_connection_param_t parameters = {0};
 
+               sender = (char *)g_dbus_method_invocation_get_sender(context);
+
                __bt_service_get_parameters(in_param1, &local_address,
                                sizeof(bluetooth_device_address_t));
                __bt_service_get_parameters(in_param2, &parameters,
                                sizeof(bluetooth_le_connection_param_t));
 
-               result =  _bt_le_conn_update(local_address.addr,
+               result =  _bt_le_conn_update(sender,
+                                       local_address.addr,
                                        parameters.interval_min,
                                        parameters.interval_max,
                                        parameters.latency,
@@ -968,6 +972,7 @@ int __bt_bluez_request(int function_name,
                break;
        }
        case BT_UPDATE_LE_CONNECTION_MODE: {
+               char *sender = NULL;
                bluetooth_device_address_t remote_address = { { 0 } };
                bluetooth_le_connection_param_t param = { 0 };
                bluetooth_le_connection_mode_t mode = BLUETOOTH_LE_CONNECTION_MODE_BALANCED;
@@ -981,7 +986,10 @@ int __bt_bluez_request(int function_name,
                if (result != BLUETOOTH_ERROR_NONE)
                        break;
 
-               result = _bt_le_conn_update(remote_address.addr,
+               sender = (char *)g_dbus_method_invocation_get_sender(context);
+
+               result = _bt_le_conn_update(sender,
+                               remote_address.addr,
                                param.interval_min,
                                param.interval_max,
                                param.latency,
@@ -3446,39 +3454,64 @@ int __bt_service_register_object(GDBusConnection *conn,
        return 0;
 }
 
+static void __bt_service_bus_acquired_handler(GDBusConnection *connection,
+               const gchar *name, gpointer user_data)
+{
+       GDBusNodeInfo *node_info = NULL;
+
+       BT_INFO("bus acquired");
+
+       ret_if(connection == NULL);
+
+       node_info = __bt_service_create_method_node_info(
+                       bt_service_introspection_xml);
+       ret_if(node_info == NULL);
+
+       __bt_service_register_object(connection, node_info, TRUE);
+       g_dbus_node_info_unref(node_info);
+
+       bt_service_conn = connection;
+}
+
+static void __bt_service_name_acquired_handler(GDBusConnection *connection,
+               const gchar *name, gpointer user_data)
+{
+       BT_INFO("name acquired");
+       name_acquired = TRUE;
+}
+
+static void __bt_service_name_lost_handler(GDBusConnection *connection,
+               const gchar *name, gpointer user_data)
+{
+       BT_INFO("name lost");
+       name_acquired = FALSE;
+}
+
+gboolean _is_name_acquired(void)
+{
+       return name_acquired;
+}
+
 int _bt_service_register(void)
 {
        GDBusConnection *conn;
        GError *err = NULL;
-       int result;
 
        conn = g_bus_get_sync(G_BUS_TYPE_SYSTEM, NULL, &err);
        retv_if(conn == NULL, BLUETOOTH_ERROR_INTERNAL);
+       bt_service_conn = conn;
 
        owner_id = g_bus_own_name(G_BUS_TYPE_SYSTEM,
                                BT_SERVICE_NAME,
                                G_BUS_NAME_OWNER_FLAGS_NONE,
-                               NULL, NULL, NULL,
+                               __bt_service_bus_acquired_handler,
+                               __bt_service_name_acquired_handler,
+                               __bt_service_name_lost_handler,
                                NULL, NULL);
        BT_DBG("owner_id is [%d]", owner_id);
        if (owner_id == 0)
                goto fail;
 
-       node_info = __bt_service_create_method_node_info(
-                       bt_service_introspection_xml);
-
-       if (node_info == NULL)
-               goto fail;
-
-       result = __bt_service_register_object(conn, node_info, TRUE);
-       g_dbus_node_info_unref(node_info);
-       node_info = NULL;
-
-       if (result != BLUETOOTH_ERROR_NONE)
-               goto fail;
-
-       bt_service_conn = conn;
-
        return BLUETOOTH_ERROR_NONE;
 
 fail:
@@ -3498,10 +3531,6 @@ void _bt_service_unregister(void)
                        g_object_unref(bt_service_conn);
                        bt_service_conn = NULL;
                }
-               if (node_info) {
-                       g_dbus_node_info_unref(node_info);
-                       node_info = NULL;
-               }
                if (owner_id > 0) {
                        g_bus_unown_name(owner_id);
                        owner_id = 0;