Use shared connection instead of private connection
[platform/core/connectivity/bluetooth-frwk.git] / bt-api / bt-common.c
index a962652..e180960 100644 (file)
@@ -47,7 +47,7 @@
 
 static bt_user_info_t user_info[BT_MAX_USER_INFO];
 static GDBusConnection *system_shared_conn = NULL;
-static GDBusConnection *system_private_conn = NULL;
+static GDBusConnection *system_common_conn = NULL;
 
 static guint bus_id;
 
@@ -55,6 +55,7 @@ static gboolean bt_enabled = FALSE;
 
 #define DBUS_TIMEOUT 20 * 1000 /* 20 Seconds */
 
+#if 0 // Remain this code for private connection in later.
 static GDBusConnection *g_bus_get_private_conn(void)
 {
        GError *error = NULL;
@@ -87,15 +88,21 @@ static GDBusConnection *g_bus_get_private_conn(void)
 
        return private_gconn;
 }
+#endif
 
-GDBusConnection *_bt_get_system_private_conn(void)
+// TODO: Need to use _bt_get_system_shared_conn in later.
+GDBusConnection *_bt_get_system_common_conn(void)
 {
-       if (system_private_conn == NULL)
-               system_private_conn = g_bus_get_private_conn();
-       else if (g_dbus_connection_is_closed(system_private_conn))
-               system_private_conn = g_bus_get_private_conn();
-
-       return system_private_conn;
+       if (system_common_conn == NULL) {
+               GError *error = NULL;
+               system_common_conn = g_bus_get_sync(G_BUS_TYPE_SYSTEM, NULL, &error);
+               if (error) {
+                       BT_ERR("GDBus connection Error : %s \n", error->message);
+                       g_clear_error(&error);
+                       return NULL;
+               }
+       }
+       return system_common_conn;
 }
 
 GDBusConnection *_bt_get_system_shared_conn(void)
@@ -1010,7 +1017,7 @@ static GDBusProxy *__bt_gdbus_get_device_proxy(char *object_path)
        GError *err = NULL;
        GDBusProxy *device_gproxy;
 
-       gconn = _bt_get_system_private_conn();
+       gconn = _bt_get_system_common_conn();
        if (gconn == NULL)
                return NULL;
 
@@ -1103,7 +1110,7 @@ static GDBusProxy * __bt_gdbus_get_adapter_proxy()
        GVariant *result = NULL;
        char *adapter_path = NULL;
 
-       conn = _bt_get_system_private_conn();
+       conn = _bt_get_system_common_conn();
        retv_if(conn == NULL, NULL);
 
        manager_proxy =  g_dbus_proxy_new_sync(conn,
@@ -1620,7 +1627,7 @@ int _bt_discover_service_uuids(char *address, char *remote_uuid)
        int result = BLUETOOTH_ERROR_INTERNAL;
 
        retv_if(remote_uuid == NULL, BLUETOOTH_ERROR_INTERNAL);
-       gconn = _bt_get_system_private_conn();
+       gconn = _bt_get_system_common_conn();
        retv_if(gconn == NULL, BLUETOOTH_ERROR_INTERNAL);
        object_path = _bt_get_device_object_path(address);
        retv_if(object_path == NULL, BLUETOOTH_ERROR_INTERNAL);
@@ -1690,7 +1697,7 @@ int _bt_get_cod_by_address(char *address, bluetooth_device_class_t *dev_class)
        unsigned int  class = 0x00;
        int ret = BLUETOOTH_ERROR_NONE;
 
-       gconn = _bt_get_system_private_conn();
+       gconn = _bt_get_system_common_conn();
        retv_if(gconn == NULL, BLUETOOTH_ERROR_INTERNAL);
 
        object_path = _bt_get_device_object_path(address);
@@ -1964,7 +1971,7 @@ char *_bt_get_device_object_path(char *address)
        GDBusConnection *conn = NULL;
        char *object_path = NULL;
 
-       conn = _bt_get_system_private_conn();
+       conn = _bt_get_system_common_conn();
        retv_if(conn == NULL, NULL);
 
        proxy =  g_dbus_proxy_new_sync(conn,
@@ -2079,7 +2086,7 @@ GVariant *_bt_get_managed_objects(void)
 
        BT_DBG("+");
 
-       g_conn = _bt_get_system_private_conn();
+       g_conn = _bt_get_system_common_conn();
        retv_if(g_conn == NULL, NULL);
 
        manager_proxy = g_dbus_proxy_new_sync(g_conn,
@@ -2478,7 +2485,7 @@ BT_EXPORT_API int bluetooth_register_callback(bluetooth_cb_func_ptr callback_ptr
 {
        int ret;
 
-       _bt_get_system_private_conn();
+       _bt_get_system_common_conn();
 
        ret = _bt_init_event_handler();
        if (ret != BLUETOOTH_ERROR_NONE &&
@@ -2556,10 +2563,5 @@ BT_EXPORT_API int bluetooth_unregister_callback(void)
                profile_gproxy = NULL;
        }
 
-       if (system_private_conn) {
-               g_object_unref(system_private_conn);
-               system_private_conn = NULL;
-       }
-
        return BLUETOOTH_ERROR_NONE;
 }