From 71abe980656febfaff9c916e670ad1395a973aff Mon Sep 17 00:00:00 2001 From: Wootak Jung Date: Wed, 9 Sep 2020 08:24:26 +0900 Subject: [PATCH] Use shared connection instead of private connection private connection is not recommended except specific usecase Change-Id: Iab62eb16860014fc99a99ea29416313ec89efef3 Signed-off-by: Wootak Jung --- bt-api/bt-adapter-le.c | 2 +- bt-api/bt-adapter.c | 2 +- bt-api/bt-audio.c | 2 +- bt-api/bt-common.c | 42 ++++++++++++++++++++++-------------------- bt-api/bt-event-handler.c | 12 ++++++------ bt-api/bt-gatt-client.c | 38 +++++++++++++++++++------------------- bt-api/bt-hid-device.c | 4 ++-- bt-api/bt-request-sender.c | 2 +- bt-api/bt-telephony.c | 6 +++--- bt-api/include/bt-common.h | 2 +- 10 files changed, 57 insertions(+), 55 deletions(-) diff --git a/bt-api/bt-adapter-le.c b/bt-api/bt-adapter-le.c index 86be586..e4f80cd 100644 --- a/bt-api/bt-adapter-le.c +++ b/bt-api/bt-adapter-le.c @@ -32,7 +32,7 @@ BT_EXPORT_API int bluetooth_check_adapter_le(void) int ret; int value; - ret = _bt_get_adapter_path(_bt_get_system_private_conn(), NULL); + ret = _bt_get_adapter_path(_bt_get_system_common_conn(), NULL); if (ret != BLUETOOTH_ERROR_NONE) return BLUETOOTH_ADAPTER_LE_DISABLED; diff --git a/bt-api/bt-adapter.c b/bt-api/bt-adapter.c index 64f4cfa..c760552 100644 --- a/bt-api/bt-adapter.c +++ b/bt-api/bt-adapter.c @@ -76,7 +76,7 @@ BT_EXPORT_API int bluetooth_check_adapter(void) int value = VCONFKEY_BT_STATUS_OFF; int ret; - ret = _bt_get_adapter_path(_bt_get_system_private_conn(), NULL); + ret = _bt_get_adapter_path(_bt_get_system_common_conn(), NULL); if (ret != BLUETOOTH_ERROR_NONE) return BLUETOOTH_ADAPTER_DISABLED; diff --git a/bt-api/bt-audio.c b/bt-api/bt-audio.c index bed8e2c..0bca5f2 100644 --- a/bt-api/bt-audio.c +++ b/bt-api/bt-audio.c @@ -568,7 +568,7 @@ static GVariant* __bt_hf_agent_dbus_send(const char *path, const char *interface GDBusProxy *proxy = NULL; GDBusConnection *conn = 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, G_DBUS_PROXY_FLAGS_DO_NOT_LOAD_PROPERTIES, diff --git a/bt-api/bt-common.c b/bt-api/bt-common.c index a962652..e180960 100644 --- a/bt-api/bt-common.c +++ b/bt-api/bt-common.c @@ -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; } diff --git a/bt-api/bt-event-handler.c b/bt-api/bt-event-handler.c index b5dcd89..64efcda 100644 --- a/bt-api/bt-event-handler.c +++ b/bt-api/bt-event-handler.c @@ -4499,7 +4499,7 @@ int _bt_register_event(int event_type, void *event_cb, void *user_data) return BLUETOOTH_ERROR_INTERNAL; } - connection_type = _bt_get_system_private_conn(); + connection_type = _bt_get_system_common_conn(); if (connection_type == NULL) return BLUETOOTH_ERROR_INTERNAL; @@ -4540,7 +4540,7 @@ int _bt_unregister_event(int event_type) return BLUETOOTH_ERROR_INTERNAL; } - connection_type = _bt_get_system_private_conn(); + connection_type = _bt_get_system_common_conn(); event_list = g_slist_remove(event_list, (void *)cb_data); @@ -4588,7 +4588,7 @@ void _bt_register_name_owner_changed(void) { GDBusConnection *connection_type; - connection_type = _bt_get_system_private_conn(); + connection_type = _bt_get_system_common_conn(); if (connection_type == NULL) { BT_ERR("Unable to get the bus"); return; @@ -4603,7 +4603,7 @@ void _bt_unregister_name_owner_changed(void) { GDBusConnection *connection_type; - connection_type = _bt_get_system_private_conn(); + connection_type = _bt_get_system_common_conn(); if (connection_type != NULL && owner_sig_id > 0) { g_dbus_connection_signal_unsubscribe(connection_type, owner_sig_id); @@ -4619,7 +4619,7 @@ static void __bt_gatt_get_uuid_from_path(char *path, char **service_uuid) GVariant *ret = NULL; GVariant *value = NULL; - g_conn = _bt_get_system_private_conn(); + g_conn = _bt_get_system_common_conn(); ret_if(g_conn == NULL); proxy = g_dbus_proxy_new_sync(g_conn, @@ -4741,7 +4741,7 @@ int _bt_register_manager_subscribe_signal(gboolean subscribe) static guint service_added_id = 0; static guint interface_removed_id = 0; - g_conn = _bt_get_system_private_conn(); + g_conn = _bt_get_system_common_conn(); if (g_conn == NULL) return BLUETOOTH_ERROR_INTERNAL; diff --git a/bt-api/bt-gatt-client.c b/bt-api/bt-gatt-client.c index 07daf0b..b51dbc5 100644 --- a/bt-api/bt-gatt-client.c +++ b/bt-api/bt-gatt-client.c @@ -190,7 +190,7 @@ BT_EXPORT_API int bluetooth_gatt_get_service_property(const char *service_handle BT_CHECK_PARAMETER(service, return); BT_CHECK_ENABLED(return); - g_conn = _bt_get_system_private_conn(); + g_conn = _bt_get_system_common_conn(); retv_if(g_conn == NULL, BLUETOOTH_ERROR_INTERNAL); properties_proxy = g_dbus_proxy_new_sync(g_conn, @@ -505,7 +505,7 @@ BT_EXPORT_API int bluetooth_gatt_discover_service_characteristics( BT_CHECK_PARAMETER(service_handle, return); BT_CHECK_ENABLED(return); - g_conn = _bt_get_system_private_conn(); + g_conn = _bt_get_system_common_conn(); retv_if(g_conn == NULL, BLUETOOTH_ERROR_INTERNAL); properties_proxy = g_dbus_proxy_new_sync(g_conn, @@ -629,7 +629,7 @@ BT_EXPORT_API int bluetooth_gatt_get_characteristics_property( BT_CHECK_ENABLED(return); - g_conn = _bt_get_system_private_conn(); + g_conn = _bt_get_system_common_conn(); retv_if(g_conn == NULL, BLUETOOTH_ERROR_INTERNAL); properties_proxy = g_dbus_proxy_new_sync(g_conn, @@ -794,7 +794,7 @@ BT_EXPORT_API int bluetooth_gatt_get_char_from_uuid(const char *service_handle, BT_CHECK_PARAMETER(char_uuid, return); BT_CHECK_ENABLED(return); - g_conn = _bt_get_system_private_conn(); + g_conn = _bt_get_system_common_conn(); retv_if(g_conn == NULL, BLUETOOTH_ERROR_INTERNAL); properties_proxy = g_dbus_proxy_new_sync(g_conn, @@ -840,7 +840,7 @@ BT_EXPORT_API int bluetooth_gatt_get_char_descriptor_property( BT_CHECK_ENABLED(return); - g_conn = _bt_get_system_private_conn(); + g_conn = _bt_get_system_common_conn(); retv_if(g_conn == NULL, BLUETOOTH_ERROR_INTERNAL); properties_proxy = g_dbus_proxy_new_sync(g_conn, @@ -970,7 +970,7 @@ static void __bluetooth_internal_read_cb(GObject *source_object, BT_DBG("+"); - system_gconn = _bt_get_system_private_conn(); + system_gconn = _bt_get_system_common_conn(); value = g_dbus_connection_call_finish(system_gconn, res, &error); user_info = _bt_get_user_data(BT_COMMON); @@ -1031,7 +1031,7 @@ BT_EXPORT_API int bluetooth_gatt_read_characteristic_value(const char *chr, BT_CHECK_PARAMETER(chr, return); BT_CHECK_ENABLED(return); - conn = _bt_get_system_private_conn(); + conn = _bt_get_system_common_conn(); retv_if(conn == NULL, BLUETOOTH_ERROR_INTERNAL); resp_data = g_malloc0(sizeof(bt_gatt_resp_data_t)); @@ -1068,7 +1068,7 @@ static void __bluetooth_internal_write_cb(GObject *source_object, int att_ecode = 0; bt_gatt_resp_data_t *resp_data = user_data; - system_gconn = _bt_get_system_private_conn(); + system_gconn = _bt_get_system_common_conn(); value = g_dbus_connection_call_finish(system_gconn, res, &error); user_info = _bt_get_user_data(BT_COMMON); @@ -1121,7 +1121,7 @@ BT_EXPORT_API int bluetooth_gatt_set_characteristics_value( retv_if(length == 0, BLUETOOTH_ERROR_INVALID_PARAM); BT_CHECK_ENABLED(return); - conn = _bt_get_system_private_conn(); + conn = _bt_get_system_common_conn(); retv_if(conn == NULL, BLUETOOTH_ERROR_INTERNAL); builder1 = g_variant_builder_new(G_VARIANT_TYPE("ay")); @@ -1186,7 +1186,7 @@ BT_EXPORT_API int bluetooth_gatt_set_characteristics_value_by_type( retv_if(length == 0, BLUETOOTH_ERROR_INVALID_PARAM); BT_CHECK_ENABLED_INTERNAL(return); - conn = _bt_get_system_private_conn(); + conn = _bt_get_system_common_conn(); retv_if(conn == NULL, BLUETOOTH_ERROR_INTERNAL); builder1 = g_variant_builder_new(G_VARIANT_TYPE("ay")); @@ -1241,7 +1241,7 @@ BT_EXPORT_API int bluetooth_gatt_set_characteristics_value_request( retv_if(length == 0, BLUETOOTH_ERROR_INVALID_PARAM); BT_CHECK_ENABLED(return); - conn = _bt_get_system_private_conn(); + conn = _bt_get_system_common_conn(); retv_if(conn == NULL, BLUETOOTH_ERROR_INTERNAL); builder1 = g_variant_builder_new(G_VARIANT_TYPE("ay")); @@ -1300,7 +1300,7 @@ static int __bluetooth_gatt_descriptor_iter(const char *char_handle, const gchar *key; char_descriptor_type_t desc_type = TYPE_NONE; - g_conn = _bt_get_system_private_conn(); + g_conn = _bt_get_system_common_conn(); retv_if(g_conn == NULL, BLUETOOTH_ERROR_INTERNAL); properties_proxy = g_dbus_proxy_new_sync(g_conn, @@ -1466,7 +1466,7 @@ BT_EXPORT_API int bltooth_gatt_discover_characteristic_descriptor( BT_CHECK_PARAMETER(characteristic_handle, return); BT_CHECK_ENABLED(return); - g_conn = _bt_get_system_private_conn(); + g_conn = _bt_get_system_common_conn(); retv_if(g_conn == NULL, BLUETOOTH_ERROR_INTERNAL); properties_proxy = g_dbus_proxy_new_sync(g_conn, @@ -1507,7 +1507,7 @@ static void __bluetooth_internal_read_desc_cb(GObject *source_object, BT_DBG("+"); - system_gconn = _bt_get_system_private_conn(); + system_gconn = _bt_get_system_common_conn(); value = g_dbus_connection_call_finish(system_gconn, res, &error); user_info = _bt_get_user_data(BT_COMMON); @@ -1571,7 +1571,7 @@ BT_EXPORT_API int bluetooth_gatt_read_descriptor_value(const char *desc, BT_CHECK_PARAMETER(desc, return); BT_CHECK_ENABLED(return); - conn = _bt_get_system_private_conn(); + conn = _bt_get_system_common_conn(); retv_if(conn == NULL, BLUETOOTH_ERROR_INTERNAL); resp_data = g_malloc0(sizeof(bt_gatt_resp_data_t)); @@ -1611,7 +1611,7 @@ static void __bluetooth_internal_write_desc_cb(GObject *source_object, BT_DBG("+"); - system_gconn = _bt_get_system_private_conn(); + system_gconn = _bt_get_system_common_conn(); value = g_dbus_connection_call_finish(system_gconn, res, &error); user_info = _bt_get_user_data(BT_COMMON); @@ -1665,7 +1665,7 @@ BT_EXPORT_API int bluetooth_gatt_write_descriptor_value(const char *desc, retv_if(length == 0, BLUETOOTH_ERROR_INVALID_PARAM); BT_CHECK_ENABLED(return); - conn = _bt_get_system_private_conn(); + conn = _bt_get_system_common_conn(); retv_if(conn == NULL, BLUETOOTH_ERROR_INTERNAL); builder1 = g_variant_builder_new(G_VARIANT_TYPE("ay")); @@ -1715,7 +1715,7 @@ BT_EXPORT_API int bluetooth_gatt_watch_characteristics(const char *char_handle, BT_INFO_C("### Enable CCCD : %s [%s]", char_handle + 15, svc_name); - conn = _bt_get_system_private_conn(); + conn = _bt_get_system_common_conn(); retv_if(conn == NULL, BLUETOOTH_ERROR_INTERNAL); g_dbus_connection_call_sync(conn, @@ -1765,7 +1765,7 @@ BT_EXPORT_API int bluetooth_gatt_unwatch_characteristics(const char *char_handle BT_INFO("Disable CCCD : %s", char_handle); - conn = _bt_get_system_private_conn(); + conn = _bt_get_system_common_conn(); retv_if(conn == NULL, BLUETOOTH_ERROR_INTERNAL); g_dbus_connection_call_sync(conn, diff --git a/bt-api/bt-hid-device.c b/bt-api/bt-hid-device.c index 806fc31..09710bc 100644 --- a/bt-api/bt-hid-device.c +++ b/bt-api/bt-hid-device.c @@ -97,7 +97,7 @@ static GVariant* __bt_hid_agent_dbus_send(const char *path, GDBusProxy *proxy = NULL; GDBusConnection *conn = 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, G_DBUS_PROXY_FLAGS_DO_NOT_LOAD_PROPERTIES, @@ -472,7 +472,7 @@ int _bt_hid_device_get_fd(const char *address, int *ctrl, int *intr) int index1 = 0; int index2 = 0; GUnixFDList *out_fd_list = NULL; - conn = _bt_get_system_private_conn(); + conn = _bt_get_system_common_conn(); retv_if(conn == NULL, BLUETOOTH_ERROR_INTERNAL); adapter_path = _bt_get_device_object_path((char *)address); diff --git a/bt-api/bt-request-sender.c b/bt-api/bt-request-sender.c index a8f1334..e34c1ea 100644 --- a/bt-api/bt-request-sender.c +++ b/bt-api/bt-request-sender.c @@ -42,7 +42,7 @@ static GDBusProxy *__bt_gdbus_init_service_proxy(void) GDBusProxy *proxy; GError *err = NULL; - service_gconn = _bt_get_system_private_conn(); + service_gconn = _bt_get_system_common_conn(); if (!service_gconn) return NULL; diff --git a/bt-api/bt-telephony.c b/bt-api/bt-telephony.c index 9274cd9..498a422 100644 --- a/bt-api/bt-telephony.c +++ b/bt-api/bt-telephony.c @@ -944,7 +944,7 @@ static int __bluetooth_telephony_get_connected_device(void) int ret = BLUETOOTH_TELEPHONY_ERROR_NONE; FN_START; - conn = _bt_get_system_private_conn(); + conn = _bt_get_system_common_conn(); retv_if(conn == NULL, BLUETOOTH_TELEPHONY_ERROR_INTERNAL); manager_proxy = g_dbus_proxy_new_sync( @@ -1705,7 +1705,7 @@ BT_EXPORT_API int bluetooth_telephony_audio_open(void) return BLUETOOTH_TELEPHONY_ERROR_PERMISSION_DENIED; } - conn = _bt_get_system_private_conn(); + conn = _bt_get_system_common_conn(); if (!conn) { BT_DBG("No System Bus found\n"); return BLUETOOTH_TELEPHONY_ERROR_INTERNAL; @@ -1778,7 +1778,7 @@ BT_EXPORT_API int bluetooth_telephony_audio_close(void) return BLUETOOTH_TELEPHONY_ERROR_PERMISSION_DENIED; } - conn = _bt_get_system_private_conn(); + conn = _bt_get_system_common_conn(); if (!conn) { BT_DBG("No System Bus found\n"); return BLUETOOTH_TELEPHONY_ERROR_INTERNAL; diff --git a/bt-api/include/bt-common.h b/bt-api/include/bt-common.h index 13b4b3c..20cf0ab 100644 --- a/bt-api/include/bt-common.h +++ b/bt-api/include/bt-common.h @@ -386,7 +386,7 @@ int _bt_unregister_osp_server_in_agent(int type, char *uuid); int _bt_check_privilege(int service_type, int service_function); GDBusConnection *_bt_get_system_shared_conn(void); -GDBusConnection *_bt_get_system_private_conn(void); +GDBusConnection *_bt_get_system_common_conn(void); GVariant *_bt_get_managed_objects(void); -- 2.7.4