Hi,
Here's series of patches which makes handling of DBusConnection object
across code simpler and more consistent.
Problem with current implementation is that different modules handles
reference to D-Bus in a different way, e.g. some use dbus_bus_get() and
just store it in static variable, others pass this around via multiple
calls to finally store it in per-{adapter,device,request} structure or
some just use get_dbus_connection() call to have it immediately.
This creates a lot of redundant code which only (un)refs DBusConnection
and pass it around for no particular reason, because you can use global
reference which is exactly the same object.
What following patches do is:
(1) prefix get_dbus_connection() with btd_ so it can be used by external
plugins
(2) make sure D-Bus is disconnected after all modules (agent, mamanger,
plugins etc.) are shutdown
(3) remove any redundant internal references and function parameters that
pass/store DBusConnection and just use btd_get_dbus_connection() where
need to pass valid DBusConnection object (no need to ref it, there's
one global ref and it's always valid as per #2)
This makes things with D-Bus really simple: you need to pass DBusConnection
object somewhere - call btd_get_dbus_connection() and you have it. No need
to store it, no need to ref it. Perhaps some downside of this approach is
that few files (hdp.c, telephony-maemo{5,6}.c) have quite a lot of such calls
but if this is something to avoid we can still add global static variable
and call btd_get_dbus_connection() once in *_init(), just like dbusoob plugin
does now.
Comments are welcome.
Andrzej Kaczmarek (17):
Rename get_dbus_connection to btd_get_dbus_connection
core: Make D-Bus connection valid for entire bluetoothd lifetime
dbus-common: Remove conn parameter from emit_property_changed
dbus-common: Remove conn parameter from emit_array_property_changed
manager: Simplify DBusConnection object handling
agent: Simplify DBusConnection object handling
device: Simplify DBusConnection object handling
adapter: Simplify DBusConnection object handling
attrib: Simplify DBusConnection object handling
audio: Simplify DBusConnection object handling
health: Simplify DBusConnection object handling
input: Simplify DBusConnection object handling
network: Simplify DBusConnection object handling
sap: Simplify DBusConnection object handling
thermometer: Simplify DBusConnection object handling
service: Simplify DBusConnection object handling
dbusoob: Simplify DBusConnection object handling
attrib/client.c | 41 +++----
attrib/client.h | 3 +-
audio/a2dp.c | 9 +-
audio/a2dp.h | 2 +-
audio/avrcp.c | 2 +-
audio/avrcp.h | 2 +-
audio/control.c | 17 +--
audio/device.c | 22 ++--
audio/device.h | 4 +-
audio/gateway.c | 26 ++---
audio/headset.c | 68 ++++++-----
audio/main.c | 15 +--
audio/manager.c | 23 +---
audio/manager.h | 3 +-
audio/media.c | 69 +++++-------
audio/media.h | 2 +-
audio/sink.c | 54 ++++-----
audio/source.c | 30 ++---
audio/telephony-dummy.c | 17 ++-
audio/telephony-maemo5.c | 51 ++++-----
audio/telephony-maemo6.c | 36 +++---
audio/telephony-ofono.c | 25 ++---
audio/transport.c | 51 ++++-----
audio/transport.h | 3 +-
plugins/dbusoob.c | 15 ++-
plugins/service.c | 74 +++++-------
profiles/health/hdp.c | 182 ++++++++++++++----------------
profiles/health/hdp.h | 6 +-
profiles/health/hdp_main.c | 16 +--
profiles/health/hdp_manager.c | 15 +--
profiles/health/hdp_manager.h | 2 +-
profiles/health/hdp_types.h | 2 -
profiles/health/hdp_util.c | 6 +-
profiles/input/device.c | 35 +++---
profiles/input/device.h | 6 +-
profiles/input/main.c | 12 +-
profiles/input/manager.c | 10 +-
profiles/input/manager.h | 2 +-
profiles/network/connection.c | 70 +++++-------
profiles/network/connection.h | 2 -
profiles/network/main.c | 15 +--
profiles/network/manager.c | 16 +--
profiles/network/manager.h | 2 +-
profiles/network/server.c | 13 +--
profiles/network/server.h | 2 +-
profiles/proximity/immalert.c | 2 +-
profiles/proximity/linkloss.c | 2 +-
profiles/proximity/monitor.c | 22 ++--
profiles/proximity/reporter.c | 4 +-
profiles/sap/main.c | 16 +--
profiles/sap/manager.c | 17 +--
profiles/sap/manager.h | 2 +-
profiles/sap/sap-dummy.c | 19 +---
profiles/sap/server.c | 29 ++---
profiles/sap/server.h | 2 -
profiles/thermometer/main.c | 17 +--
profiles/thermometer/manager.c | 11 +-
profiles/thermometer/manager.h | 2 +-
profiles/thermometer/thermometer.c | 30 +++--
profiles/thermometer/thermometer.h | 3 +-
src/adapter.c | 199 +++++++++++++++-----------------
src/adapter.h | 8 +-
src/agent.c | 44 +++-----
src/agent.h | 3 -
src/dbus-common.c | 12 +-
src/dbus-common.h | 8 +-
src/device.c | 225 +++++++++++++++++--------------------
src/device.h | 29 +++--
src/event.c | 17 +--
src/main.c | 20 ++--
src/manager.c | 41 ++++---
src/manager.h | 4 +-
72 files changed, 758 insertions(+), 1108 deletions(-)
--
1.7.11.3
Hi Andrzej,
On Wed, Sep 19, 2012, Andrzej Kaczmarek wrote:
> Here's series of patches which makes handling of DBusConnection object
> across code simpler and more consistent.
>
> Problem with current implementation is that different modules handles
> reference to D-Bus in a different way, e.g. some use dbus_bus_get() and
> just store it in static variable, others pass this around via multiple
> calls to finally store it in per-{adapter,device,request} structure or
> some just use get_dbus_connection() call to have it immediately.
>
> This creates a lot of redundant code which only (un)refs DBusConnection
> and pass it around for no particular reason, because you can use global
> reference which is exactly the same object.
>
> What following patches do is:
> (1) prefix get_dbus_connection() with btd_ so it can be used by external
> plugins
> (2) make sure D-Bus is disconnected after all modules (agent, mamanger,
> plugins etc.) are shutdown
> (3) remove any redundant internal references and function parameters that
> pass/store DBusConnection and just use btd_get_dbus_connection() where
> need to pass valid DBusConnection object (no need to ref it, there's
> one global ref and it's always valid as per #2)
>
> This makes things with D-Bus really simple: you need to pass DBusConnection
> object somewhere - call btd_get_dbus_connection() and you have it. No need
> to store it, no need to ref it. Perhaps some downside of this approach is
> that few files (hdp.c, telephony-maemo{5,6}.c) have quite a lot of such calls
> but if this is something to avoid we can still add global static variable
> and call btd_get_dbus_connection() once in *_init(), just like dbusoob plugin
> does now.
>
> Comments are welcome.
I didn't see any major issues with this set so all patches have now been
applied. Thanks.
Johan
This patch removes redundant references and function parameters for
DBusConnection object and uses btd_get_dbus_connection() call wherever
such object is needed instead.
Pointer returned by this call is guaranteed to be valid for entire
bluetoothd lifetime and thus do not need to be refcounted.
---
audio/a2dp.c | 9 +------
audio/a2dp.h | 2 +-
audio/avrcp.c | 2 +-
audio/avrcp.h | 2 +-
audio/control.c | 9 ++++---
audio/device.c | 20 ++++++--------
audio/device.h | 4 +--
audio/gateway.c | 20 +++++++-------
audio/headset.c | 50 +++++++++++++++++------------------
audio/main.c | 15 +----------
audio/manager.c | 21 ++++-----------
audio/manager.h | 3 +--
audio/media.c | 69 +++++++++++++++++++-----------------------------
audio/media.h | 2 +-
audio/sink.c | 44 +++++++++++++-----------------
audio/source.c | 28 ++++++++------------
audio/telephony-dummy.c | 17 +++++-------
audio/telephony-maemo5.c | 51 +++++++++++++++++------------------
audio/telephony-maemo6.c | 36 +++++++++++--------------
audio/telephony-ofono.c | 25 +++++++++---------
audio/transport.c | 43 +++++++++++++-----------------
audio/transport.h | 3 +--
22 files changed, 194 insertions(+), 281 deletions(-)
diff --git a/audio/a2dp.c b/audio/a2dp.c
index 64b37e7..fd1c494 100644
--- a/audio/a2dp.c
+++ b/audio/a2dp.c
@@ -102,8 +102,6 @@ struct a2dp_setup {
int ref;
};
-static DBusConnection *connection = NULL;
-
struct a2dp_server {
bdaddr_t src;
GSList *sinks;
@@ -1168,7 +1166,7 @@ static struct a2dp_server *find_server(GSList *list, const bdaddr_t *src)
return NULL;
}
-int a2dp_register(DBusConnection *conn, const bdaddr_t *src, GKeyFile *config)
+int a2dp_register(const bdaddr_t *src, GKeyFile *config)
{
gboolean source = TRUE, sink = FALSE;
gboolean delay_reporting = FALSE;
@@ -1206,8 +1204,6 @@ int a2dp_register(DBusConnection *conn, const bdaddr_t *src, GKeyFile *config)
}
proceed:
- if (!connection)
- connection = dbus_connection_ref(conn);
server = find_server(servers, src);
if (!server) {
@@ -1278,9 +1274,6 @@ void a2dp_unregister(const bdaddr_t *src)
if (servers)
return;
-
- dbus_connection_unref(connection);
- connection = NULL;
}
struct a2dp_sep *a2dp_add_sep(const bdaddr_t *src, uint8_t type,
diff --git a/audio/a2dp.h b/audio/a2dp.h
index deab3b8..736bc66 100644
--- a/audio/a2dp.h
+++ b/audio/a2dp.h
@@ -64,7 +64,7 @@ typedef void (*a2dp_stream_cb_t) (struct avdtp *session,
struct avdtp_error *err,
void *user_data);
-int a2dp_register(DBusConnection *conn, const bdaddr_t *src, GKeyFile *config);
+int a2dp_register(const bdaddr_t *src, GKeyFile *config);
void a2dp_unregister(const bdaddr_t *src);
struct a2dp_sep *a2dp_add_sep(const bdaddr_t *src, uint8_t type,
diff --git a/audio/avrcp.c b/audio/avrcp.c
index 27be7e8..7258e7a 100644
--- a/audio/avrcp.c
+++ b/audio/avrcp.c
@@ -1270,7 +1270,7 @@ void avrcp_disconnect(struct audio_device *dev)
avctp_disconnect(session);
}
-int avrcp_register(DBusConnection *conn, const bdaddr_t *src, GKeyFile *config)
+int avrcp_register(const bdaddr_t *src, GKeyFile *config)
{
sdp_record_t *record;
gboolean tmp, master = TRUE;
diff --git a/audio/avrcp.h b/audio/avrcp.h
index bf11a6c..d94a050 100644
--- a/audio/avrcp.h
+++ b/audio/avrcp.h
@@ -88,7 +88,7 @@ struct avrcp_player_cb {
void *user_data);
};
-int avrcp_register(DBusConnection *conn, const bdaddr_t *src, GKeyFile *config);
+int avrcp_register(const bdaddr_t *src, GKeyFile *config);
void avrcp_unregister(const bdaddr_t *src);
gboolean avrcp_connect(struct audio_device *dev);
diff --git a/audio/control.c b/audio/control.c
index 02aea33..896bc48 100644
--- a/audio/control.c
+++ b/audio/control.c
@@ -66,6 +66,7 @@ struct control {
static void state_changed(struct audio_device *dev, avctp_state_t old_state,
avctp_state_t new_state, void *user_data)
{
+ DBusConnection *conn = btd_get_dbus_connection();
struct control *control = dev->control;
gboolean value;
@@ -77,7 +78,7 @@ static void state_changed(struct audio_device *dev, avctp_state_t old_state,
break;
value = FALSE;
- g_dbus_emit_signal(dev->conn, dev->path,
+ g_dbus_emit_signal(conn, dev->path,
AUDIO_CONTROL_INTERFACE,
"Disconnected", DBUS_TYPE_INVALID);
emit_property_changed(dev->path,
@@ -94,7 +95,7 @@ static void state_changed(struct audio_device *dev, avctp_state_t old_state,
break;
case AVCTP_STATE_CONNECTED:
value = TRUE;
- g_dbus_emit_signal(dev->conn, dev->path,
+ g_dbus_emit_signal(conn, dev->path,
AUDIO_CONTROL_INTERFACE, "Connected",
DBUS_TYPE_INVALID);
emit_property_changed(dev->path,
@@ -233,7 +234,7 @@ static void path_unregister(void *data)
void control_unregister(struct audio_device *dev)
{
- g_dbus_unregister_interface(dev->conn, dev->path,
+ g_dbus_unregister_interface(btd_get_dbus_connection(), dev->path,
AUDIO_CONTROL_INTERFACE);
}
@@ -247,7 +248,7 @@ struct control *control_init(struct audio_device *dev, GSList *uuids)
{
struct control *control;
- if (!g_dbus_register_interface(dev->conn, dev->path,
+ if (!g_dbus_register_interface(btd_get_dbus_connection(), dev->path,
AUDIO_CONTROL_INTERFACE,
control_methods, control_signals, NULL,
dev, path_unregister))
diff --git a/audio/device.c b/audio/device.c
index b93a294..99d6512 100644
--- a/audio/device.c
+++ b/audio/device.c
@@ -106,9 +106,6 @@ static void device_free(struct audio_device *dev)
{
struct dev_priv *priv = dev->priv;
- if (dev->conn)
- dbus_connection_unref(dev->conn);
-
btd_device_unref(dev->btd_dev);
if (priv) {
@@ -230,6 +227,7 @@ static void disconnect_cb(struct btd_device *btd_dev, gboolean removal,
static void device_set_state(struct audio_device *dev, audio_state_t new_state)
{
+ DBusConnection *conn = btd_get_dbus_connection();
struct dev_priv *priv = dev->priv;
const char *state_str;
DBusMessage *reply = NULL;
@@ -263,7 +261,7 @@ static void device_set_state(struct audio_device *dev, audio_state_t new_state)
reply = dbus_message_new_method_return(priv->dc_req);
dbus_message_unref(priv->dc_req);
priv->dc_req = NULL;
- g_dbus_send_message(dev->conn, reply);
+ g_dbus_send_message(conn, reply);
}
priv->disconnecting = FALSE;
}
@@ -277,7 +275,7 @@ static void device_set_state(struct audio_device *dev, audio_state_t new_state)
dbus_message_unref(priv->conn_req);
priv->conn_req = NULL;
- g_dbus_send_message(dev->conn, reply);
+ g_dbus_send_message(conn, reply);
}
emit_property_changed(dev->path,
@@ -632,14 +630,13 @@ static const GDBusSignalTable dev_signals[] = {
{ }
};
-struct audio_device *audio_device_register(DBusConnection *conn,
- struct btd_device *device,
+struct audio_device *audio_device_register(struct btd_device *device,
const char *path, const bdaddr_t *src,
const bdaddr_t *dst)
{
struct audio_device *dev;
- if (!conn || !path)
+ if (!path)
return NULL;
dev = g_new0(struct audio_device, 1);
@@ -648,12 +645,11 @@ struct audio_device *audio_device_register(DBusConnection *conn,
dev->path = g_strdup(path);
bacpy(&dev->dst, dst);
bacpy(&dev->src, src);
- dev->conn = dbus_connection_ref(conn);
dev->priv = g_new0(struct dev_priv, 1);
dev->priv->state = AUDIO_STATE_DISCONNECTED;
- if (!g_dbus_register_interface(dev->conn, dev->path,
- AUDIO_INTERFACE,
+ if (!g_dbus_register_interface(btd_get_dbus_connection(),
+ dev->path, AUDIO_INTERFACE,
dev_methods, dev_signals, NULL,
dev, NULL)) {
error("Unable to register %s on %s", AUDIO_INTERFACE,
@@ -730,7 +726,7 @@ void audio_device_unregister(struct audio_device *device)
if (device->control)
control_unregister(device);
- g_dbus_unregister_interface(device->conn, device->path,
+ g_dbus_unregister_interface(btd_get_dbus_connection(), device->path,
AUDIO_INTERFACE);
device_free(device);
diff --git a/audio/device.h b/audio/device.h
index 75f1da9..f9b868f 100644
--- a/audio/device.h
+++ b/audio/device.h
@@ -33,7 +33,6 @@ struct dev_priv;
struct audio_device {
struct btd_device *btd_dev;
- DBusConnection *conn;
char *path;
bdaddr_t src;
bdaddr_t dst;
@@ -52,8 +51,7 @@ struct audio_device {
struct dev_priv *priv;
};
-struct audio_device *audio_device_register(DBusConnection *conn,
- struct btd_device *device,
+struct audio_device *audio_device_register(struct btd_device *device,
const char *path, const bdaddr_t *src,
const bdaddr_t *dst);
diff --git a/audio/gateway.c b/audio/gateway.c
index 0fe29d1..45b25a1 100644
--- a/audio/gateway.c
+++ b/audio/gateway.c
@@ -159,7 +159,7 @@ static void agent_disconnect(struct audio_device *dev, struct hf_agent *agent)
msg = dbus_message_new_method_call(agent->name, agent->path,
"org.bluez.HandsfreeAgent", "Release");
- g_dbus_send_message(dev->conn, msg);
+ g_dbus_send_message(btd_get_dbus_connection(), msg);
}
static gboolean agent_sendfd(struct hf_agent *agent, int fd,
@@ -177,7 +177,7 @@ static gboolean agent_sendfd(struct hf_agent *agent, int fd,
DBUS_TYPE_UINT16, &gw->version,
DBUS_TYPE_INVALID);
- if (dbus_connection_send_with_reply(dev->conn, msg,
+ if (dbus_connection_send_with_reply(btd_get_dbus_connection(), msg,
&call, -1) == FALSE) {
dbus_message_unref(msg);
return FALSE;
@@ -308,6 +308,7 @@ done:
static void rfcomm_connect_cb(GIOChannel *chan, GError *err,
gpointer user_data)
{
+ DBusConnection *conn = btd_get_dbus_connection();
struct audio_device *dev = user_data;
struct gateway *gw = dev->gateway;
DBusMessage *reply;
@@ -338,7 +339,7 @@ static void rfcomm_connect_cb(GIOChannel *chan, GError *err,
else
reply = btd_error_failed(gw->msg, "Can't pass file descriptor");
- g_dbus_send_message(dev->conn, reply);
+ g_dbus_send_message(conn, reply);
return;
@@ -346,7 +347,7 @@ fail:
if (gw->msg) {
DBusMessage *reply;
reply = btd_error_failed(gw->msg, "Connect failed");
- g_dbus_send_message(dev->conn, reply);
+ g_dbus_send_message(conn, reply);
}
gateway_close(dev);
@@ -514,7 +515,7 @@ fail:
if (gw->msg) {
DBusMessage *reply = btd_error_failed(gw->msg,
gerr ? gerr->message : strerror(-err));
- g_dbus_send_message(dev->conn, reply);
+ g_dbus_send_message(btd_get_dbus_connection(), reply);
}
gateway_close(dev);
@@ -597,9 +598,6 @@ static DBusMessage *ag_disconnect(DBusConnection *conn, DBusMessage *msg,
DBusMessage *reply = NULL;
char gw_addr[18];
- if (!device->conn)
- return NULL;
-
if (!gw->rfcomm)
return btd_error_not_connected(msg);
@@ -706,7 +704,7 @@ static DBusMessage *unregister_agent(DBusConnection *conn,
if (strcmp(gw->agent->path, path) != 0)
return btd_error_does_not_exist(msg);
- g_dbus_remove_watch(device->conn, gw->agent->watch);
+ g_dbus_remove_watch(conn, gw->agent->watch);
agent_free(gw->agent);
gw->agent = NULL;
@@ -752,13 +750,13 @@ void gateway_unregister(struct audio_device *dev)
if (dev->gateway->agent)
agent_disconnect(dev, dev->gateway->agent);
- g_dbus_unregister_interface(dev->conn, dev->path,
+ g_dbus_unregister_interface(btd_get_dbus_connection(), dev->path,
AUDIO_GATEWAY_INTERFACE);
}
struct gateway *gateway_init(struct audio_device *dev)
{
- if (!g_dbus_register_interface(dev->conn, dev->path,
+ if (!g_dbus_register_interface(btd_get_dbus_connection(), dev->path,
AUDIO_GATEWAY_INTERFACE,
gateway_methods, gateway_signals,
NULL, dev, path_unregister))
diff --git a/audio/headset.c b/audio/headset.c
index 3ded18e..c822e35 100644
--- a/audio/headset.c
+++ b/audio/headset.c
@@ -186,12 +186,11 @@ struct event {
static GSList *headset_callbacks = NULL;
-static void error_connect_failed(DBusConnection *conn, DBusMessage *msg,
- int err)
+static void error_connect_failed(DBusMessage *msg, int err)
{
DBusMessage *reply = btd_error_failed(msg,
err < 0 ? strerror(-err) : "Connect failed");
- g_dbus_send_message(conn, reply);
+ g_dbus_send_message(btd_get_dbus_connection(), reply);
}
static int rfcomm_connect(struct audio_device *device, headset_stream_cb_t cb,
@@ -571,7 +570,7 @@ static void sco_connect_cb(GIOChannel *chan, GError *err, gpointer user_data)
if (p != NULL) {
p->err = -errno;
if (p->msg)
- error_connect_failed(dev->conn, p->msg, p->err);
+ error_connect_failed(p->msg, p->err);
pending_connect_finalize(dev);
}
@@ -594,7 +593,7 @@ static void sco_connect_cb(GIOChannel *chan, GError *err, gpointer user_data)
if (p->msg) {
DBusMessage *reply;
reply = dbus_message_new_method_return(p->msg);
- g_dbus_send_message(dev->conn, reply);
+ g_dbus_send_message(btd_get_dbus_connection(), reply);
}
pending_connect_finalize(dev);
@@ -672,7 +671,7 @@ static void hfp_slc_complete(struct audio_device *dev)
if (p->target_state == HEADSET_STATE_CONNECTED) {
if (p->msg) {
DBusMessage *reply = dbus_message_new_method_return(p->msg);
- g_dbus_send_message(dev->conn, reply);
+ g_dbus_send_message(btd_get_dbus_connection(), reply);
}
pending_connect_finalize(dev);
return;
@@ -681,7 +680,7 @@ static void hfp_slc_complete(struct audio_device *dev)
p->err = sco_connect(dev, NULL, NULL, NULL);
if (p->err < 0) {
if (p->msg)
- error_connect_failed(dev->conn, p->msg, p->err);
+ error_connect_failed(p->msg, p->err);
pending_connect_finalize(dev);
}
}
@@ -803,7 +802,7 @@ static int key_press(struct audio_device *device, const char *buf)
if (strlen(buf) < 9)
return -EINVAL;
- g_dbus_emit_signal(device->conn, device->path,
+ g_dbus_emit_signal(btd_get_dbus_connection(), device->path,
AUDIO_HEADSET_INTERFACE, "AnswerRequested",
DBUS_TYPE_INVALID);
@@ -848,7 +847,7 @@ int telephony_terminate_call_rsp(void *telephony_device,
if (err != CME_ERROR_NONE)
return telephony_generic_rsp(telephony_device, err);
- g_dbus_emit_signal(device->conn, device->path,
+ g_dbus_emit_signal(btd_get_dbus_connection(), device->path,
AUDIO_HEADSET_INTERFACE, "CallTerminated",
DBUS_TYPE_INVALID);
@@ -983,7 +982,7 @@ static int headset_set_gain(struct audio_device *device, uint16_t gain, char typ
return -EINVAL;
}
- g_dbus_emit_signal(device->conn, device->path,
+ g_dbus_emit_signal(btd_get_dbus_connection(), device->path,
AUDIO_HEADSET_INTERFACE, name,
DBUS_TYPE_UINT16, &gain,
DBUS_TYPE_INVALID);
@@ -1424,7 +1423,7 @@ void headset_connect_cb(GIOChannel *chan, GError *err, gpointer user_data)
if (p && p->msg) {
DBusMessage *reply = dbus_message_new_method_return(p->msg);
- g_dbus_send_message(dev->conn, reply);
+ g_dbus_send_message(btd_get_dbus_connection(), reply);
}
pending_connect_finalize(dev);
@@ -1433,7 +1432,7 @@ void headset_connect_cb(GIOChannel *chan, GError *err, gpointer user_data)
failed:
if (p && p->msg)
- error_connect_failed(dev->conn, p->msg, p->err);
+ error_connect_failed(p->msg, p->err);
pending_connect_finalize(dev);
if (hs->rfcomm)
headset_set_state(dev, HEADSET_STATE_CONNECTED);
@@ -1493,7 +1492,7 @@ static void get_record_cb(sdp_list_t *recs, int err, gpointer user_data)
strerror(-err), -err);
p->err = -err;
if (p->msg)
- error_connect_failed(dev->conn, p->msg, p->err);
+ error_connect_failed(p->msg, p->err);
goto failed;
}
@@ -1542,7 +1541,7 @@ static void get_record_cb(sdp_list_t *recs, int err, gpointer user_data)
error("Unable to connect: %s (%d)", strerror(-err), -err);
p->err = -err;
if (p->msg != NULL)
- error_connect_failed(dev->conn, p->msg, p->err);
+ error_connect_failed(p->msg, p->err);
goto failed;
}
@@ -1554,7 +1553,7 @@ failed_not_supported:
return;
if (p->msg) {
DBusMessage *reply = btd_error_not_supported(p->msg);
- g_dbus_send_message(dev->conn, reply);
+ g_dbus_send_message(btd_get_dbus_connection(), reply);
}
failed:
p->svclass = 0;
@@ -1798,8 +1797,7 @@ static DBusMessage *hs_cancel_call(DBusConnection *conn,
return reply;
}
-static DBusMessage *hs_set_gain(DBusConnection *conn,
- DBusMessage *msg,
+static DBusMessage *hs_set_gain(DBusMessage *msg,
void *data, uint16_t gain,
char type)
{
@@ -1910,14 +1908,14 @@ static DBusMessage *hs_set_property(DBusConnection *conn,
return btd_error_invalid_args(msg);
dbus_message_iter_get_basic(&sub, &gain);
- return hs_set_gain(conn, msg, data, gain,
+ return hs_set_gain(msg, data, gain,
HEADSET_GAIN_SPEAKER);
} else if (g_str_equal("MicrophoneGain", property)) {
if (dbus_message_iter_get_arg_type(&sub) != DBUS_TYPE_UINT16)
return btd_error_invalid_args(msg);
dbus_message_iter_get_basic(&sub, &gain);
- return hs_set_gain(conn, msg, data, gain,
+ return hs_set_gain(msg, data, gain,
HEADSET_GAIN_MICROPHONE);
}
@@ -2033,7 +2031,7 @@ static void path_unregister(void *data)
void headset_unregister(struct audio_device *dev)
{
- g_dbus_unregister_interface(dev->conn, dev->path,
+ g_dbus_unregister_interface(btd_get_dbus_connection(), dev->path,
AUDIO_HEADSET_INTERFACE);
}
@@ -2048,7 +2046,7 @@ struct headset *headset_init(struct audio_device *dev, GSList *uuids,
headset_update(dev, hs, uuids);
- if (!g_dbus_register_interface(dev->conn, dev->path,
+ if (!g_dbus_register_interface(btd_get_dbus_connection(), dev->path,
AUDIO_HEADSET_INTERFACE,
headset_methods, headset_signals, NULL,
dev, path_unregister)) {
@@ -2346,7 +2344,7 @@ void headset_set_state(struct audio_device *dev, headset_state_t state)
emit_property_changed(dev->path,
AUDIO_HEADSET_INTERFACE, "State",
DBUS_TYPE_STRING, &state_str);
- g_dbus_emit_signal(dev->conn, dev->path,
+ g_dbus_emit_signal(btd_get_dbus_connection(), dev->path,
AUDIO_HEADSET_INTERFACE,
"Disconnected",
DBUS_TYPE_INVALID);
@@ -2374,7 +2372,7 @@ void headset_set_state(struct audio_device *dev, headset_state_t state)
slc->inband_ring = TRUE;
else
slc->inband_ring = FALSE;
- g_dbus_emit_signal(dev->conn, dev->path,
+ g_dbus_emit_signal(btd_get_dbus_connection(), dev->path,
AUDIO_HEADSET_INTERFACE,
"Connected",
DBUS_TYPE_INVALID);
@@ -2387,7 +2385,7 @@ void headset_set_state(struct audio_device *dev, headset_state_t state)
telephony_device_connected(dev);
} else if (hs->state == HEADSET_STATE_PLAYING) {
value = FALSE;
- g_dbus_emit_signal(dev->conn, dev->path,
+ g_dbus_emit_signal(btd_get_dbus_connection(), dev->path,
AUDIO_HEADSET_INTERFACE,
"Stopped",
DBUS_TYPE_INVALID);
@@ -2411,7 +2409,7 @@ void headset_set_state(struct audio_device *dev, headset_state_t state)
G_IO_ERR | G_IO_NVAL,
(GIOFunc) sco_cb, dev);
- g_dbus_emit_signal(dev->conn, dev->path,
+ g_dbus_emit_signal(btd_get_dbus_connection(), dev->path,
AUDIO_HEADSET_INTERFACE, "Playing",
DBUS_TYPE_INVALID);
emit_property_changed(dev->path,
@@ -2590,7 +2588,7 @@ void headset_shutdown(struct audio_device *dev)
struct pending_connect *p = dev->headset->pending;
if (p && p->msg)
- error_connect_failed(dev->conn, p->msg, ECANCELED);
+ error_connect_failed(p->msg, ECANCELED);
pending_connect_finalize(dev);
headset_set_state(dev, HEADSET_STATE_DISCONNECTED);
diff --git a/audio/main.c b/audio/main.c
index a88f163..f7bb32a 100644
--- a/audio/main.c
+++ b/audio/main.c
@@ -142,20 +142,14 @@ drop:
g_io_channel_shutdown(chan, TRUE, NULL);
}
-static DBusConnection *connection;
-
static int audio_init(void)
{
GKeyFile *config;
gboolean enable_sco;
- connection = dbus_bus_get(DBUS_BUS_SYSTEM, NULL);
- if (connection == NULL)
- return -EIO;
-
config = load_config_file(CONFIGDIR "/audio.conf");
- if (audio_manager_init(connection, config, &enable_sco) < 0)
+ if (audio_manager_init(config, &enable_sco) < 0)
goto failed;
if (!enable_sco)
@@ -174,11 +168,6 @@ static int audio_init(void)
failed:
audio_manager_exit();
- if (connection) {
- dbus_connection_unref(connection);
- connection = NULL;
- }
-
return -EIO;
}
@@ -191,8 +180,6 @@ static void audio_exit(void)
}
audio_manager_exit();
-
- dbus_connection_unref(connection);
}
BLUETOOTH_PLUGIN_DEFINE(audio, VERSION,
diff --git a/audio/manager.c b/audio/manager.c
index 3b105ed..fbfe00f 100644
--- a/audio/manager.c
+++ b/audio/manager.c
@@ -85,7 +85,6 @@ struct audio_adapter {
static gboolean auto_connect = TRUE;
static int max_connected_headsets = 1;
-static DBusConnection *connection = NULL;
static GKeyFile *config = NULL;
static GSList *adapters = NULL;
static GSList *devices = NULL;
@@ -964,7 +963,7 @@ static int a2dp_server_probe(struct btd_adapter *adapter)
adapter_get_address(adapter, &src);
- err = a2dp_register(connection, &src, config);
+ err = a2dp_register(&src, config);
if (err < 0)
audio_adapter_unref(adp);
@@ -1003,7 +1002,7 @@ static int avrcp_server_probe(struct btd_adapter *adapter)
adapter_get_address(adapter, &src);
- err = avrcp_register(connection, &src, config);
+ err = avrcp_register(&src, config);
if (err < 0)
audio_adapter_unref(adp);
@@ -1042,7 +1041,7 @@ static int media_server_probe(struct btd_adapter *adapter)
adapter_get_address(adapter, &src);
- err = media_register(connection, path, &src);
+ err = media_register(path, &src);
if (err < 0)
audio_adapter_unref(adp);
@@ -1114,16 +1113,13 @@ static struct btd_adapter_driver media_driver = {
.remove = media_server_remove,
};
-int audio_manager_init(DBusConnection *conn, GKeyFile *conf,
- gboolean *enable_sco)
+int audio_manager_init(GKeyFile *conf, gboolean *enable_sco)
{
char **list;
int i;
gboolean b;
GError *err = NULL;
- connection = dbus_connection_ref(conn);
-
if (!conf)
goto proceed;
@@ -1206,13 +1202,6 @@ proceed:
void audio_manager_exit(void)
{
- /* Bail out early if we haven't been initialized */
- if (connection == NULL)
- return;
-
- dbus_connection_unref(connection);
- connection = NULL;
-
if (config) {
g_key_file_free(config);
config = NULL;
@@ -1337,7 +1326,7 @@ struct audio_device *manager_get_device(const bdaddr_t *src,
path = device_get_path(device);
- dev = audio_device_register(connection, device, path, src, dst);
+ dev = audio_device_register(device, path, src, dst);
if (!dev)
return NULL;
diff --git a/audio/manager.h b/audio/manager.h
index 300142d..08d814f 100644
--- a/audio/manager.h
+++ b/audio/manager.h
@@ -32,8 +32,7 @@ struct enabled_interfaces {
gboolean media_player;
};
-int audio_manager_init(DBusConnection *conn, GKeyFile *config,
- gboolean *enable_sco);
+int audio_manager_init(GKeyFile *config, gboolean *enable_sco);
void audio_manager_exit(void);
struct audio_device *manager_find_device(const char *path,
diff --git a/audio/media.c b/audio/media.c
index e4a7684..c88afc0 100644
--- a/audio/media.c
+++ b/audio/media.c
@@ -59,7 +59,6 @@
struct media_adapter {
bdaddr_t src; /* Adapter address */
char *path; /* Adapter path */
- DBusConnection *conn; /* Adapter connection */
GSList *endpoints; /* Endpoints list */
GSList *players; /* Players list */
};
@@ -147,8 +146,6 @@ static void media_endpoint_cancel_all(struct media_endpoint *endpoint)
static void media_endpoint_destroy(struct media_endpoint *endpoint)
{
- struct media_adapter *adapter = endpoint->adapter;
-
DBG("sender=%s path=%s", endpoint->sender, endpoint->path);
if (endpoint->hs_watch)
@@ -162,7 +159,7 @@ static void media_endpoint_destroy(struct media_endpoint *endpoint)
g_slist_free_full(endpoint->transports,
(GDestroyNotify) media_transport_destroy);
- g_dbus_remove_watch(adapter->conn, endpoint->watch);
+ g_dbus_remove_watch(btd_get_dbus_connection(), endpoint->watch);
g_free(endpoint->capabilities);
g_free(endpoint->sender);
g_free(endpoint->path);
@@ -209,12 +206,9 @@ static void headset_setconf_cb(struct media_endpoint *endpoint, void *ret,
static void clear_configuration(struct media_endpoint *endpoint,
struct media_transport *transport)
{
- DBusConnection *conn;
DBusMessage *msg;
const char *path;
- conn = endpoint->adapter->conn;
-
msg = dbus_message_new_method_call(endpoint->sender, endpoint->path,
MEDIA_ENDPOINT_INTERFACE,
"ClearConfiguration");
@@ -226,7 +220,7 @@ static void clear_configuration(struct media_endpoint *endpoint,
path = media_transport_get_path(transport);
dbus_message_append_args(msg, DBUS_TYPE_OBJECT_PATH, &path,
DBUS_TYPE_INVALID);
- g_dbus_send_message(conn, msg);
+ g_dbus_send_message(btd_get_dbus_connection(), msg);
done:
endpoint->transports = g_slist_remove(endpoint->transports, transport);
media_transport_destroy(transport);
@@ -307,8 +301,7 @@ done:
endpoint_request_free(request);
}
-static gboolean media_endpoint_async_call(DBusConnection *conn,
- DBusMessage *msg,
+static gboolean media_endpoint_async_call(DBusMessage *msg,
struct media_endpoint *endpoint,
media_endpoint_cb_t cb,
void *user_data,
@@ -319,7 +312,8 @@ static gboolean media_endpoint_async_call(DBusConnection *conn,
request = g_new0(struct endpoint_request, 1);
/* Timeout should be less than avdtp request timeout (4 seconds) */
- if (dbus_connection_send_with_reply(conn, msg, &request->call,
+ if (dbus_connection_send_with_reply(btd_get_dbus_connection(),
+ msg, &request->call,
REQUEST_TIMEOUT) == FALSE) {
error("D-Bus send failed");
g_free(request);
@@ -351,11 +345,8 @@ static gboolean select_configuration(struct media_endpoint *endpoint,
void *user_data,
GDestroyNotify destroy)
{
- DBusConnection *conn;
DBusMessage *msg;
- conn = endpoint->adapter->conn;
-
msg = dbus_message_new_method_call(endpoint->sender, endpoint->path,
MEDIA_ENDPOINT_INTERFACE,
"SelectConfiguration");
@@ -368,8 +359,7 @@ static gboolean select_configuration(struct media_endpoint *endpoint,
&capabilities, length,
DBUS_TYPE_INVALID);
- return media_endpoint_async_call(conn, msg, endpoint, cb, user_data,
- destroy);
+ return media_endpoint_async_call(msg, endpoint, cb, user_data, destroy);
}
static gint transport_device_cmp(gconstpointer data, gconstpointer user_data)
@@ -404,7 +394,6 @@ static gboolean set_configuration(struct media_endpoint *endpoint,
void *user_data,
GDestroyNotify destroy)
{
- DBusConnection *conn;
DBusMessage *msg;
const char *path;
DBusMessageIter iter;
@@ -415,9 +404,7 @@ static gboolean set_configuration(struct media_endpoint *endpoint,
if (transport != NULL)
return FALSE;
- conn = endpoint->adapter->conn;
-
- transport = media_transport_create(conn, endpoint, device,
+ transport = media_transport_create(endpoint, device,
configuration, size);
if (transport == NULL)
return FALSE;
@@ -440,8 +427,7 @@ static gboolean set_configuration(struct media_endpoint *endpoint,
transport_get_properties(transport, &iter);
- return media_endpoint_async_call(conn, msg, endpoint, cb, user_data,
- destroy);
+ return media_endpoint_async_call(msg, endpoint, cb, user_data, destroy);
}
static void release_endpoint(struct media_endpoint *endpoint)
@@ -464,7 +450,7 @@ static void release_endpoint(struct media_endpoint *endpoint)
return;
}
- g_dbus_send_message(endpoint->adapter->conn, msg);
+ g_dbus_send_message(btd_get_dbus_connection(), msg);
done:
media_endpoint_remove(endpoint);
@@ -787,9 +773,9 @@ static struct media_endpoint *media_endpoint_create(struct media_adapter *adapte
return NULL;
}
- endpoint->watch = g_dbus_add_disconnect_watch(adapter->conn, sender,
- media_endpoint_exit, endpoint,
- NULL);
+ endpoint->watch = g_dbus_add_disconnect_watch(btd_get_dbus_connection(),
+ sender, media_endpoint_exit,
+ endpoint, NULL);
adapter->endpoints = g_slist_append(adapter->endpoints, endpoint);
info("Endpoint registered: sender=%s path=%s", sender, path);
@@ -975,11 +961,12 @@ static void release_player(struct media_player *mp)
return;
}
- g_dbus_send_message(mp->adapter->conn, msg);
+ g_dbus_send_message(btd_get_dbus_connection(), msg);
}
static void media_player_free(gpointer data)
{
+ DBusConnection *conn = btd_get_dbus_connection();
struct media_player *mp = data;
struct media_adapter *adapter = mp->adapter;
@@ -988,9 +975,9 @@ static void media_player_free(gpointer data)
release_player(mp);
}
- g_dbus_remove_watch(adapter->conn, mp->watch);
- g_dbus_remove_watch(adapter->conn, mp->property_watch);
- g_dbus_remove_watch(adapter->conn, mp->track_watch);
+ g_dbus_remove_watch(conn, mp->watch);
+ g_dbus_remove_watch(conn, mp->property_watch);
+ g_dbus_remove_watch(conn, mp->track_watch);
if (mp->track)
g_hash_table_unref(mp->track);
@@ -1233,7 +1220,6 @@ static int get_setting(uint8_t attr, void *user_data)
static int set_setting(uint8_t attr, uint8_t val, void *user_data)
{
struct media_player *mp = user_data;
- struct media_adapter *adapter = mp->adapter;
const char *property, *value;
guint attr_uint = attr;
DBusMessage *msg;
@@ -1267,7 +1253,7 @@ static int set_setting(uint8_t attr, uint8_t val, void *user_data)
dbus_message_iter_append_basic(&var, DBUS_TYPE_STRING, &value);
dbus_message_iter_close_container(&iter, &var);
- g_dbus_send_message(adapter->conn, msg);
+ g_dbus_send_message(btd_get_dbus_connection(), msg);
return 0;
}
@@ -1678,6 +1664,7 @@ static struct media_player *media_player_create(struct media_adapter *adapter,
const char *path,
int *err)
{
+ DBusConnection *conn = btd_get_dbus_connection();
struct media_player *mp;
mp = g_new0(struct media_player, 1);
@@ -1686,15 +1673,15 @@ static struct media_player *media_player_create(struct media_adapter *adapter,
mp->path = g_strdup(path);
mp->timer = g_timer_new();
- mp->watch = g_dbus_add_disconnect_watch(adapter->conn, sender,
+ mp->watch = g_dbus_add_disconnect_watch(conn, sender,
media_player_exit, mp,
NULL);
- mp->property_watch = g_dbus_add_signal_watch(adapter->conn, sender,
+ mp->property_watch = g_dbus_add_signal_watch(conn, sender,
path, MEDIA_PLAYER_INTERFACE,
"PropertyChanged",
property_changed,
mp, NULL);
- mp->track_watch = g_dbus_add_signal_watch(adapter->conn, sender,
+ mp->track_watch = g_dbus_add_signal_watch(conn, sender,
path, MEDIA_PLAYER_INTERFACE,
"TrackChanged",
track_changed,
@@ -1846,24 +1833,22 @@ static void path_free(void *data)
while (adapter->players)
media_player_destroy(adapter->players->data);
- dbus_connection_unref(adapter->conn);
-
adapters = g_slist_remove(adapters, adapter);
g_free(adapter->path);
g_free(adapter);
}
-int media_register(DBusConnection *conn, const char *path, const bdaddr_t *src)
+int media_register(const char *path, const bdaddr_t *src)
{
struct media_adapter *adapter;
adapter = g_new0(struct media_adapter, 1);
- adapter->conn = dbus_connection_ref(conn);
bacpy(&adapter->src, src);
adapter->path = g_strdup(path);
- if (!g_dbus_register_interface(conn, path, MEDIA_INTERFACE,
+ if (!g_dbus_register_interface(btd_get_dbus_connection(),
+ path, MEDIA_INTERFACE,
media_methods, NULL, NULL,
adapter, path_free)) {
error("D-Bus failed to register %s path", path);
@@ -1884,8 +1869,8 @@ void media_unregister(const char *path)
struct media_adapter *adapter = l->data;
if (g_strcmp0(path, adapter->path) == 0) {
- g_dbus_unregister_interface(adapter->conn, path,
- MEDIA_INTERFACE);
+ g_dbus_unregister_interface(btd_get_dbus_connection(),
+ path, MEDIA_INTERFACE);
return;
}
}
diff --git a/audio/media.h b/audio/media.h
index 84fc1bc..82b9694 100644
--- a/audio/media.h
+++ b/audio/media.h
@@ -27,7 +27,7 @@ struct media_endpoint;
typedef void (*media_endpoint_cb_t) (struct media_endpoint *endpoint,
void *ret, int size, void *user_data);
-int media_register(DBusConnection *conn, const char *path, const bdaddr_t *src);
+int media_register(const char *path, const bdaddr_t *src);
void media_unregister(const char *path);
struct a2dp_sep *media_endpoint_get_sep(struct media_endpoint *endpoint);
diff --git a/audio/sink.c b/audio/sink.c
index 6201d85..4eb2c61 100644
--- a/audio/sink.c
+++ b/audio/sink.c
@@ -52,7 +52,6 @@
#define STREAM_SETUP_RETRY_TIMER 2
struct pending_request {
- DBusConnection *conn;
DBusMessage *msg;
unsigned int id;
};
@@ -68,7 +67,6 @@ struct sink {
sink_state_t state;
struct pending_request *connect;
struct pending_request *disconnect;
- DBusConnection *conn;
};
struct sink_state_callback {
@@ -144,7 +142,7 @@ static void avdtp_state_callback(struct audio_device *dev,
case AVDTP_SESSION_STATE_DISCONNECTED:
if (sink->state != SINK_STATE_CONNECTING) {
gboolean value = FALSE;
- g_dbus_emit_signal(dev->conn, dev->path,
+ g_dbus_emit_signal(btd_get_dbus_connection(), dev->path,
AUDIO_SINK_INTERFACE, "Disconnected",
DBUS_TYPE_INVALID);
emit_property_changed(dev->path,
@@ -166,8 +164,6 @@ static void avdtp_state_callback(struct audio_device *dev,
static void pending_request_free(struct audio_device *dev,
struct pending_request *pending)
{
- if (pending->conn)
- dbus_connection_unref(pending->conn);
if (pending->msg)
dbus_message_unref(pending->msg);
if (pending->id)
@@ -182,6 +178,7 @@ static void stream_state_changed(struct avdtp_stream *stream,
struct avdtp_error *err,
void *user_data)
{
+ DBusConnection *conn = btd_get_dbus_connection();
struct audio_device *dev = user_data;
struct sink *sink = dev->sink;
gboolean value;
@@ -199,7 +196,7 @@ static void stream_state_changed(struct avdtp_stream *stream,
sink->disconnect = NULL;
reply = dbus_message_new_method_return(p->msg);
- g_dbus_send_message(p->conn, reply);
+ g_dbus_send_message(conn, reply);
pending_request_free(dev, p);
}
@@ -214,7 +211,7 @@ static void stream_state_changed(struct avdtp_stream *stream,
if (old_state == AVDTP_STATE_CONFIGURED &&
sink->state == SINK_STATE_CONNECTING) {
value = TRUE;
- g_dbus_emit_signal(dev->conn, dev->path,
+ g_dbus_emit_signal(conn, dev->path,
AUDIO_SINK_INTERFACE,
"Connected",
DBUS_TYPE_INVALID);
@@ -224,7 +221,7 @@ static void stream_state_changed(struct avdtp_stream *stream,
DBUS_TYPE_BOOLEAN, &value);
} else if (old_state == AVDTP_STATE_STREAMING) {
value = FALSE;
- g_dbus_emit_signal(dev->conn, dev->path,
+ g_dbus_emit_signal(conn, dev->path,
AUDIO_SINK_INTERFACE,
"Stopped",
DBUS_TYPE_INVALID);
@@ -237,8 +234,9 @@ static void stream_state_changed(struct avdtp_stream *stream,
break;
case AVDTP_STATE_STREAMING:
value = TRUE;
- g_dbus_emit_signal(dev->conn, dev->path, AUDIO_SINK_INTERFACE,
- "Playing", DBUS_TYPE_INVALID);
+ g_dbus_emit_signal(conn, dev->path,
+ AUDIO_SINK_INTERFACE, "Playing",
+ DBUS_TYPE_INVALID);
emit_property_changed(dev->path,
AUDIO_SINK_INTERFACE, "Playing",
DBUS_TYPE_BOOLEAN, &value);
@@ -254,11 +252,10 @@ static void stream_state_changed(struct avdtp_stream *stream,
sink->stream_state = new_state;
}
-static void error_failed(DBusConnection *conn, DBusMessage *msg,
- const char *desc)
+static void error_failed(DBusMessage *msg, const char *desc)
{
DBusMessage *reply = btd_error_failed(msg, desc);
- g_dbus_send_message(conn, reply);
+ g_dbus_send_message(btd_get_dbus_connection(), reply);
}
static gboolean stream_setup_retry(gpointer user_data)
@@ -273,12 +270,12 @@ static gboolean stream_setup_retry(gpointer user_data)
if (pending->msg) {
DBusMessage *reply;
reply = dbus_message_new_method_return(pending->msg);
- g_dbus_send_message(pending->conn, reply);
+ g_dbus_send_message(btd_get_dbus_connection(), reply);
}
} else {
DBG("Stream setup failed, after XCASE connect:connect");
if (pending->msg)
- error_failed(pending->conn, pending->msg, "Stream setup failed");
+ error_failed(pending->msg, "Stream setup failed");
}
sink->connect = NULL;
@@ -304,7 +301,7 @@ static void stream_setup_complete(struct avdtp *session, struct a2dp_sep *sep,
if (pending->msg) {
DBusMessage *reply;
reply = dbus_message_new_method_return(pending->msg);
- g_dbus_send_message(pending->conn, reply);
+ g_dbus_send_message(btd_get_dbus_connection(), reply);
}
sink->connect = NULL;
@@ -323,7 +320,7 @@ static void stream_setup_complete(struct avdtp *session, struct a2dp_sep *sep,
sink);
} else {
if (pending->msg)
- error_failed(pending->conn, pending->msg, "Stream setup failed");
+ error_failed(pending->msg, "Stream setup failed");
sink->connect = NULL;
pending_request_free(sink->dev, pending);
DBG("Stream setup failed : %s", avdtp_strerror(err));
@@ -349,7 +346,7 @@ static void select_complete(struct avdtp *session, struct a2dp_sep *sep,
failed:
if (pending->msg)
- error_failed(pending->conn, pending->msg, "Stream setup failed");
+ error_failed(pending->msg, "Stream setup failed");
pending_request_free(sink->dev, pending);
sink->connect = NULL;
avdtp_unref(sink->session);
@@ -398,7 +395,7 @@ static void discovery_complete(struct avdtp *session, GSList *seps, struct avdtp
failed:
if (pending->msg)
- error_failed(pending->conn, pending->msg, "Stream setup failed");
+ error_failed(pending->msg, "Stream setup failed");
pending_request_free(sink->dev, pending);
sink->connect = NULL;
avdtp_unref(sink->session);
@@ -450,7 +447,6 @@ static DBusMessage *sink_connect(DBusConnection *conn,
pending = sink->connect;
- pending->conn = dbus_connection_ref(conn);
pending->msg = dbus_message_ref(msg);
DBG("stream creation in progress");
@@ -486,7 +482,6 @@ static DBusMessage *sink_disconnect(DBusConnection *conn,
return btd_error_failed(msg, strerror(-err));
pending = g_new0(struct pending_request, 1);
- pending->conn = dbus_connection_ref(conn);
pending->msg = dbus_message_ref(msg);
sink->disconnect = pending;
@@ -588,7 +583,7 @@ static void path_unregister(void *data)
void sink_unregister(struct audio_device *dev)
{
- g_dbus_unregister_interface(dev->conn, dev->path,
+ g_dbus_unregister_interface(btd_get_dbus_connection(), dev->path,
AUDIO_SINK_INTERFACE);
}
@@ -596,7 +591,7 @@ struct sink *sink_init(struct audio_device *dev)
{
struct sink *sink;
- if (!g_dbus_register_interface(dev->conn, dev->path,
+ if (!g_dbus_register_interface(btd_get_dbus_connection(), dev->path,
AUDIO_SINK_INTERFACE,
sink_methods, sink_signals, NULL,
dev, path_unregister))
@@ -664,8 +659,7 @@ gboolean sink_shutdown(struct sink *sink)
struct pending_request *pending = sink->connect;
if (pending->msg)
- error_failed(pending->conn, pending->msg,
- "Stream setup failed");
+ error_failed(pending->msg, "Stream setup failed");
pending_request_free(sink->dev, pending);
sink->connect = NULL;
diff --git a/audio/source.c b/audio/source.c
index 8e01666..41aedd2 100644
--- a/audio/source.c
+++ b/audio/source.c
@@ -53,7 +53,6 @@
#define STREAM_SETUP_RETRY_TIMER 2
struct pending_request {
- DBusConnection *conn;
DBusMessage *msg;
unsigned int id;
};
@@ -69,7 +68,6 @@ struct source {
source_state_t state;
struct pending_request *connect;
struct pending_request *disconnect;
- DBusConnection *conn;
};
struct source_state_callback {
@@ -148,8 +146,6 @@ static void avdtp_state_callback(struct audio_device *dev,
static void pending_request_free(struct audio_device *dev,
struct pending_request *pending)
{
- if (pending->conn)
- dbus_connection_unref(pending->conn);
if (pending->msg)
dbus_message_unref(pending->msg);
if (pending->id)
@@ -180,7 +176,7 @@ static void stream_state_changed(struct avdtp_stream *stream,
source->disconnect = NULL;
reply = dbus_message_new_method_return(p->msg);
- g_dbus_send_message(p->conn, reply);
+ g_dbus_send_message(btd_get_dbus_connection(), reply);
pending_request_free(dev, p);
}
@@ -207,11 +203,11 @@ static void stream_state_changed(struct avdtp_stream *stream,
source->stream_state = new_state;
}
-static void error_failed(DBusConnection *conn, DBusMessage *msg,
+static void error_failed(DBusMessage *msg,
const char *desc)
{
DBusMessage *reply = btd_error_failed(msg, desc);
- g_dbus_send_message(conn, reply);
+ g_dbus_send_message(btd_get_dbus_connection(), reply);
}
static gboolean stream_setup_retry(gpointer user_data)
@@ -226,12 +222,12 @@ static gboolean stream_setup_retry(gpointer user_data)
if (pending->msg) {
DBusMessage *reply;
reply = dbus_message_new_method_return(pending->msg);
- g_dbus_send_message(pending->conn, reply);
+ g_dbus_send_message(btd_get_dbus_connection(), reply);
}
} else {
DBG("Stream setup failed, after XCASE connect:connect");
if (pending->msg)
- error_failed(pending->conn, pending->msg, "Stream setup failed");
+ error_failed(pending->msg, "Stream setup failed");
}
source->connect = NULL;
@@ -257,7 +253,7 @@ static void stream_setup_complete(struct avdtp *session, struct a2dp_sep *sep,
if (pending->msg) {
DBusMessage *reply;
reply = dbus_message_new_method_return(pending->msg);
- g_dbus_send_message(pending->conn, reply);
+ g_dbus_send_message(btd_get_dbus_connection(), reply);
}
source->connect = NULL;
@@ -276,7 +272,7 @@ static void stream_setup_complete(struct avdtp *session, struct a2dp_sep *sep,
source);
} else {
if (pending->msg)
- error_failed(pending->conn, pending->msg, "Stream setup failed");
+ error_failed(pending->msg, "Stream setup failed");
source->connect = NULL;
pending_request_free(source->dev, pending);
DBG("Stream setup failed : %s", avdtp_strerror(err));
@@ -306,7 +302,7 @@ static void select_complete(struct avdtp *session, struct a2dp_sep *sep,
failed:
if (pending->msg)
- error_failed(pending->conn, pending->msg, "Stream setup failed");
+ error_failed(pending->msg, "Stream setup failed");
pending_request_free(source->dev, pending);
source->connect = NULL;
avdtp_unref(source->session);
@@ -349,7 +345,7 @@ static void discovery_complete(struct avdtp *session, GSList *seps, struct avdtp
failed:
if (pending->msg)
- error_failed(pending->conn, pending->msg, "Stream setup failed");
+ error_failed(pending->msg, "Stream setup failed");
pending_request_free(source->dev, pending);
source->connect = NULL;
avdtp_unref(source->session);
@@ -401,7 +397,6 @@ static DBusMessage *source_connect(DBusConnection *conn,
pending = source->connect;
- pending->conn = dbus_connection_ref(conn);
pending->msg = dbus_message_ref(msg);
DBG("stream creation in progress");
@@ -437,7 +432,6 @@ static DBusMessage *source_disconnect(DBusConnection *conn,
return btd_error_failed(msg, strerror(-err));
pending = g_new0(struct pending_request, 1);
- pending->conn = dbus_connection_ref(conn);
pending->msg = dbus_message_ref(msg);
source->disconnect = pending;
@@ -526,7 +520,7 @@ static void path_unregister(void *data)
void source_unregister(struct audio_device *dev)
{
- g_dbus_unregister_interface(dev->conn, dev->path,
+ g_dbus_unregister_interface(btd_get_dbus_connection(), dev->path,
AUDIO_SOURCE_INTERFACE);
}
@@ -534,7 +528,7 @@ struct source *source_init(struct audio_device *dev)
{
struct source *source;
- if (!g_dbus_register_interface(dev->conn, dev->path,
+ if (!g_dbus_register_interface(btd_get_dbus_connection(), dev->path,
AUDIO_SOURCE_INTERFACE,
source_methods, source_signals, NULL,
dev, path_unregister))
diff --git a/audio/telephony-dummy.c b/audio/telephony-dummy.c
index 2f89139..d1bbfd5 100644
--- a/audio/telephony-dummy.c
+++ b/audio/telephony-dummy.c
@@ -33,6 +33,7 @@
#include <dbus/dbus.h>
#include <gdbus.h>
+#include "dbus-common.h"
#include "log.h"
#include "telephony.h"
#include "error.h"
@@ -40,8 +41,6 @@
#define TELEPHONY_DUMMY_IFACE "org.bluez.TelephonyTest"
#define TELEPHONY_DUMMY_PATH "/org/bluez/test"
-static DBusConnection *connection = NULL;
-
static const char *chld_str = "0,1,1x,2,2x,3,4";
static char *subscriber_number = NULL;
static char *active_call_number = NULL;
@@ -199,7 +198,7 @@ void telephony_voice_dial_req(void *telephony_device, gboolean enable)
DBG("telephony-dummy: got %s voice dial request",
enable ? "enable" : "disable");
- g_dbus_emit_signal(connection, TELEPHONY_DUMMY_PATH,
+ g_dbus_emit_signal(btd_get_dbus_connection(), TELEPHONY_DUMMY_PATH,
TELEPHONY_DUMMY_IFACE, "VoiceDial",
DBUS_TYPE_INVALID);
@@ -417,9 +416,8 @@ int telephony_init(void)
DBG("");
- connection = dbus_bus_get(DBUS_BUS_SYSTEM, NULL);
-
- if (g_dbus_register_interface(connection, TELEPHONY_DUMMY_PATH,
+ if (g_dbus_register_interface(btd_get_dbus_connection(),
+ TELEPHONY_DUMMY_PATH,
TELEPHONY_DUMMY_IFACE,
dummy_methods, dummy_signals,
NULL, NULL, NULL) == FALSE) {
@@ -438,10 +436,9 @@ void telephony_exit(void)
{
DBG("");
- g_dbus_unregister_interface(connection, TELEPHONY_DUMMY_PATH,
- TELEPHONY_DUMMY_IFACE);
- dbus_connection_unref(connection);
- connection = NULL;
+ g_dbus_unregister_interface(btd_get_dbus_connection(),
+ TELEPHONY_DUMMY_PATH,
+ TELEPHONY_DUMMY_IFACE);
telephony_deinit();
}
diff --git a/audio/telephony-maemo5.c b/audio/telephony-maemo5.c
index 8a00296..deb64e4 100644
--- a/audio/telephony-maemo5.c
+++ b/audio/telephony-maemo5.c
@@ -36,6 +36,7 @@
#include <dbus/dbus.h>
#include <gdbus.h>
+#include "dbus-common.h"
#include "log.h"
#include "telephony.h"
#include "error.h"
@@ -188,8 +189,6 @@ static struct {
.operator_name = NULL,
};
-static DBusConnection *connection = NULL;
-
static GSList *calls = NULL;
/* Reference count for determining the call indicator status */
@@ -322,7 +321,7 @@ static int release_conference(void)
return -ENOMEM;
}
- g_dbus_send_message(connection, msg);
+ g_dbus_send_message(btd_get_dbus_connection(), msg);
return 0;
}
@@ -340,7 +339,7 @@ static int release_call(struct csd_call *call)
return -ENOMEM;
}
- g_dbus_send_message(connection, msg);
+ g_dbus_send_message(btd_get_dbus_connection(), msg);
return 0;
}
@@ -358,7 +357,7 @@ static int answer_call(struct csd_call *call)
return -ENOMEM;
}
- g_dbus_send_message(connection, msg);
+ g_dbus_send_message(btd_get_dbus_connection(), msg);
return 0;
}
@@ -376,7 +375,7 @@ static int split_call(struct csd_call *call)
return -ENOMEM;
}
- g_dbus_send_message(connection, msg);
+ g_dbus_send_message(btd_get_dbus_connection(), msg);
return 0;
}
@@ -393,7 +392,7 @@ static int unhold_call(struct csd_call *call)
return -ENOMEM;
}
- g_dbus_send_message(connection, msg);
+ g_dbus_send_message(btd_get_dbus_connection(), msg);
return 0;
}
@@ -410,7 +409,7 @@ static int hold_call(struct csd_call *call)
return -ENOMEM;
}
- g_dbus_send_message(connection, msg);
+ g_dbus_send_message(btd_get_dbus_connection(), msg);
return 0;
}
@@ -427,7 +426,7 @@ static int swap_calls(void)
return -ENOMEM;
}
- g_dbus_send_message(connection, msg);
+ g_dbus_send_message(btd_get_dbus_connection(), msg);
return 0;
}
@@ -444,7 +443,7 @@ static int create_conference(void)
return -ENOMEM;
}
- g_dbus_send_message(connection, msg);
+ g_dbus_send_message(btd_get_dbus_connection(), msg);
return 0;
}
@@ -461,7 +460,7 @@ static int call_transfer(void)
return -ENOMEM;
}
- g_dbus_send_message(connection, msg);
+ g_dbus_send_message(btd_get_dbus_connection(), msg);
return 0;
}
@@ -585,6 +584,7 @@ static int send_method_call(const char *dest, const char *path,
DBusPendingCallNotifyFunction cb,
void *user_data, int type, ...)
{
+ DBusConnection *conn = btd_get_dbus_connection();
DBusMessage *msg;
DBusPendingCall *call;
va_list args;
@@ -606,11 +606,11 @@ static int send_method_call(const char *dest, const char *path,
va_end(args);
if (!cb) {
- g_dbus_send_message(connection, msg);
+ g_dbus_send_message(conn, msg);
return 0;
}
- if (!dbus_connection_send_with_reply(connection, msg, &call, -1)) {
+ if (!dbus_connection_send_with_reply(conn, msg, &call, -1)) {
error("Sending %s failed", method);
dbus_message_unref(msg);
return -EIO;
@@ -1759,7 +1759,7 @@ static void hal_find_device_reply(DBusPendingCall *call, void *user_data)
"path='%s',"
"interface='org.freedesktop.Hal.Device',"
"member='PropertyModified'", path);
- dbus_bus_add_match(connection, match_string, NULL);
+ dbus_bus_add_match(btd_get_dbus_connection(), match_string, NULL);
hal_get_integer(path, "battery.charge_level.last_full", &battchg_last);
hal_get_integer(path, "battery.charge_level.current", &battchg_cur);
@@ -2031,6 +2031,7 @@ static DBusHandlerResult signal_filter(DBusConnection *conn,
int telephony_init(void)
{
+ DBusConnection *conn = btd_get_dbus_connection();
const char *battery_cap = "battery";
uint32_t features = AG_FEATURE_EC_ANDOR_NR |
AG_FEATURE_INBAND_RINGTONE |
@@ -2040,21 +2041,19 @@ int telephony_init(void)
AG_FEATURE_EXTENDED_ERROR_RESULT_CODES |
AG_FEATURE_THREE_WAY_CALLING;
- connection = dbus_bus_get(DBUS_BUS_SYSTEM, NULL);
-
- if (!dbus_connection_add_filter(connection, signal_filter,
+ if (!dbus_connection_add_filter(conn, signal_filter,
NULL, NULL))
error("Can't add signal filter");
- dbus_bus_add_match(connection,
+ dbus_bus_add_match(conn,
"type=signal,interface=" CSD_CALL_INTERFACE, NULL);
- dbus_bus_add_match(connection,
+ dbus_bus_add_match(conn,
"type=signal,interface=" CSD_CALL_INSTANCE, NULL);
- dbus_bus_add_match(connection,
+ dbus_bus_add_match(conn,
"type=signal,interface=" CSD_CALL_CONFERENCE, NULL);
- dbus_bus_add_match(connection,
+ dbus_bus_add_match(conn,
"type=signal,interface=" NETWORK_INTERFACE, NULL);
- dbus_bus_add_match(connection,
+ dbus_bus_add_match(conn,
"type=signal,interface=" SSC_DBUS_IFACE
",member=modem_state_changed_ind", NULL);
@@ -2066,7 +2065,7 @@ int telephony_init(void)
generate_flag_file(NONE_FLAG_FILE);
callerid = callerid_from_file();
- if (!g_dbus_register_interface(connection, TELEPHONY_MAEMO_PATH,
+ if (!g_dbus_register_interface(conn, TELEPHONY_MAEMO_PATH,
TELEPHONY_MAEMO_INTERFACE, telephony_maemo_methods,
NULL, NULL, NULL, NULL)) {
error("telephony-maemo interface %s init failed on path %s",
@@ -2096,10 +2095,8 @@ void telephony_exit(void)
g_slist_free(calls);
calls = NULL;
- dbus_connection_remove_filter(connection, signal_filter, NULL);
-
- dbus_connection_unref(connection);
- connection = NULL;
+ dbus_connection_remove_filter(btd_get_dbus_connection(),
+ signal_filter, NULL);
telephony_deinit();
}
diff --git a/audio/telephony-maemo6.c b/audio/telephony-maemo6.c
index 0727ffe..d000a2a 100644
--- a/audio/telephony-maemo6.c
+++ b/audio/telephony-maemo6.c
@@ -38,6 +38,7 @@
#include <bluetooth/sdp.h>
+#include "dbus-common.h"
#include "log.h"
#include "telephony.h"
#include "error.h"
@@ -163,8 +164,6 @@ struct pending_req {
static int get_property(const char *iface, const char *prop);
-static DBusConnection *connection = NULL;
-
static GSList *calls = NULL;
static GSList *watches = NULL;
static GSList *pending = NULL;
@@ -233,6 +232,7 @@ static int send_method_call(const char *dest, const char *path,
DBusPendingCallNotifyFunction cb,
void *user_data, int type, ...)
{
+ DBusConnection *conn = btd_get_dbus_connection();
DBusMessage *msg;
DBusPendingCall *call;
va_list args;
@@ -255,11 +255,11 @@ static int send_method_call(const char *dest, const char *path,
va_end(args);
if (!cb) {
- g_dbus_send_message(connection, msg);
+ g_dbus_send_message(conn, msg);
return 0;
}
- if (!dbus_connection_send_with_reply(connection, msg, &call, -1)) {
+ if (!dbus_connection_send_with_reply(conn, msg, &call, -1)) {
error("Sending %s failed", method);
dbus_message_unref(msg);
return -EIO;
@@ -351,7 +351,7 @@ static int release_conference(void)
return -ENOMEM;
}
- g_dbus_send_message(connection, msg);
+ g_dbus_send_message(btd_get_dbus_connection(), msg);
return 0;
}
@@ -369,7 +369,7 @@ static int release_call(struct csd_call *call)
return -ENOMEM;
}
- g_dbus_send_message(connection, msg);
+ g_dbus_send_message(btd_get_dbus_connection(), msg);
return 0;
}
@@ -387,7 +387,7 @@ static int answer_call(struct csd_call *call)
return -ENOMEM;
}
- g_dbus_send_message(connection, msg);
+ g_dbus_send_message(btd_get_dbus_connection(), msg);
return 0;
}
@@ -460,7 +460,7 @@ static int split_call(struct csd_call *call)
return -ENOMEM;
}
- g_dbus_send_message(connection, msg);
+ g_dbus_send_message(btd_get_dbus_connection(), msg);
return 0;
}
@@ -477,7 +477,7 @@ static int unhold_call(struct csd_call *call)
return -ENOMEM;
}
- g_dbus_send_message(connection, msg);
+ g_dbus_send_message(btd_get_dbus_connection(), msg);
return 0;
}
@@ -494,7 +494,7 @@ static int hold_call(struct csd_call *call)
return -ENOMEM;
}
- g_dbus_send_message(connection, msg);
+ g_dbus_send_message(btd_get_dbus_connection(), msg);
return 0;
}
@@ -511,7 +511,7 @@ static int swap_calls(void)
return -ENOMEM;
}
- g_dbus_send_message(connection, msg);
+ g_dbus_send_message(btd_get_dbus_connection(), msg);
return 0;
}
@@ -528,7 +528,7 @@ static int create_conference(void)
return -ENOMEM;
}
- g_dbus_send_message(connection, msg);
+ g_dbus_send_message(btd_get_dbus_connection(), msg);
return 0;
}
@@ -545,7 +545,7 @@ static int call_transfer(void)
return -ENOMEM;
}
- g_dbus_send_message(connection, msg);
+ g_dbus_send_message(btd_get_dbus_connection(), msg);
return 0;
}
@@ -2059,7 +2059,8 @@ static void add_watch(const char *sender, const char *path,
{
guint watch;
- watch = g_dbus_add_signal_watch(connection, sender, path, interface,
+ watch = g_dbus_add_signal_watch(btd_get_dbus_connection(),
+ sender, path, interface,
member, signal_filter, NULL, NULL);
watches = g_slist_prepend(watches, GUINT_TO_POINTER(watch));
@@ -2129,8 +2130,6 @@ int telephony_init(void)
DBG("");
- connection = dbus_bus_get(DBUS_BUS_SYSTEM, NULL);
-
add_watch(NULL, NULL, CSD_CALL_INTERFACE, NULL);
add_watch(NULL, NULL, CSD_CALL_INSTANCE, NULL);
add_watch(NULL, NULL, CSD_CALL_CONFERENCE, NULL);
@@ -2168,7 +2167,7 @@ int telephony_init(void)
static void remove_watch(gpointer data)
{
- g_dbus_remove_watch(connection, GPOINTER_TO_UINT(data));
+ g_dbus_remove_watch(btd_get_dbus_connection(), GPOINTER_TO_UINT(data));
}
void telephony_exit(void)
@@ -2193,8 +2192,5 @@ void telephony_exit(void)
g_slist_free_full(watches, remove_watch);
watches = NULL;
- dbus_connection_unref(connection);
- connection = NULL;
-
telephony_deinit();
}
diff --git a/audio/telephony-ofono.c b/audio/telephony-ofono.c
index 961fedd..f962c7e 100644
--- a/audio/telephony-ofono.c
+++ b/audio/telephony-ofono.c
@@ -37,6 +37,7 @@
#include <bluetooth/sdp.h>
+#include "dbus-common.h"
#include "log.h"
#include "telephony.h"
@@ -55,7 +56,6 @@ struct voice_call {
guint watch;
};
-static DBusConnection *connection = NULL;
static char *modem_obj_path = NULL;
static char *last_dialed_number = NULL;
static GSList *calls = NULL;
@@ -207,6 +207,7 @@ static int send_method_call(const char *dest, const char *path,
DBusPendingCallNotifyFunction cb,
void *user_data, int type, ...)
{
+ DBusConnection *conn = btd_get_dbus_connection();
DBusMessage *msg;
DBusPendingCall *call;
va_list args;
@@ -228,11 +229,11 @@ static int send_method_call(const char *dest, const char *path,
va_end(args);
if (!cb) {
- g_dbus_send_message(connection, msg);
+ g_dbus_send_message(conn, msg);
return 0;
}
- if (!dbus_connection_send_with_reply(connection, msg, &call, -1)) {
+ if (!dbus_connection_send_with_reply(conn, msg, &call, -1)) {
error("Sending %s failed", method);
dbus_message_unref(msg);
return -EIO;
@@ -656,7 +657,7 @@ static void call_free(void *data)
if (vc->status == CALL_STATUS_INCOMING)
telephony_calling_stopped_ind();
- g_dbus_remove_watch(connection, vc->watch);
+ g_dbus_remove_watch(btd_get_dbus_connection(), vc->watch);
g_free(vc->obj_path);
g_free(vc->number);
g_free(vc);
@@ -742,7 +743,8 @@ static struct voice_call *call_new(const char *path, DBusMessageIter *properties
vc = g_new0(struct voice_call, 1);
vc->obj_path = g_strdup(path);
- vc->watch = g_dbus_add_signal_watch(connection, NULL, path,
+ vc->watch = g_dbus_add_signal_watch(btd_get_dbus_connection(),
+ NULL, path,
OFONO_VC_INTERFACE, "PropertyChanged",
handle_vc_property_changed, vc, NULL);
@@ -1470,7 +1472,8 @@ static void add_watch(const char *sender, const char *path,
{
guint watch;
- watch = g_dbus_add_signal_watch(connection, sender, path, interface,
+ watch = g_dbus_add_signal_watch(btd_get_dbus_connection(),
+ sender, path, interface,
member, function, NULL, NULL);
watches = g_slist_prepend(watches, GUINT_TO_POINTER(watch));
@@ -1557,8 +1560,6 @@ int telephony_init(void)
int ret;
guint watch;
- connection = dbus_bus_get(DBUS_BUS_SYSTEM, NULL);
-
add_watch(OFONO_BUS_NAME, NULL, OFONO_MODEM_INTERFACE,
"PropertyChanged", handle_modem_property_changed);
add_watch(OFONO_BUS_NAME, NULL, OFONO_NETWORKREG_INTERFACE,
@@ -1572,7 +1573,8 @@ int telephony_init(void)
add_watch(OFONO_BUS_NAME, NULL, OFONO_VCMANAGER_INTERFACE,
"CallRemoved", handle_vcmanager_call_removed);
- watch = g_dbus_add_service_watch(connection, OFONO_BUS_NAME,
+ watch = g_dbus_add_service_watch(btd_get_dbus_connection(),
+ OFONO_BUS_NAME,
handle_service_connect,
handle_service_disconnect,
NULL, NULL);
@@ -1601,7 +1603,7 @@ int telephony_init(void)
static void remove_watch(gpointer data)
{
- g_dbus_remove_watch(connection, GPOINTER_TO_UINT(data));
+ g_dbus_remove_watch(btd_get_dbus_connection(), GPOINTER_TO_UINT(data));
}
static void pending_free(void *data)
@@ -1630,8 +1632,5 @@ void telephony_exit(void)
g_slist_free_full(pending, pending_free);
pending = NULL;
- dbus_connection_unref(connection);
- connection = NULL;
-
telephony_deinit();
}
diff --git a/audio/transport.c b/audio/transport.c
index 6541fc1..aed9f9a 100644
--- a/audio/transport.c
+++ b/audio/transport.c
@@ -97,7 +97,6 @@ struct headset_transport {
};
struct media_transport {
- DBusConnection *conn;
char *path; /* Transport object path */
struct audio_device *device; /* Transport device */
struct media_endpoint *endpoint; /* Transport endpoint */
@@ -225,7 +224,7 @@ void media_transport_destroy(struct media_transport *transport)
source_remove_state_cb(transport->source_watch);
path = g_strdup(transport->path);
- g_dbus_unregister_interface(transport->conn, path,
+ g_dbus_unregister_interface(btd_get_dbus_connection(), path,
MEDIA_TRANSPORT_INTERFACE);
g_free(path);
@@ -245,8 +244,7 @@ static struct media_request *media_request_create(DBusMessage *msg, guint id)
return req;
}
-static void media_request_reply(struct media_request *req,
- DBusConnection *conn, int err)
+static void media_request_reply(struct media_request *req, int err)
{
DBusMessage *reply;
@@ -260,7 +258,7 @@ static void media_request_reply(struct media_request *req,
ERROR_INTERFACE ".Failed",
"%s", strerror(err));
- g_dbus_send_message(conn, reply);
+ g_dbus_send_message(btd_get_dbus_connection(), reply);
}
static gboolean media_transport_release(struct media_transport *transport,
@@ -317,12 +315,12 @@ static void media_transport_remove(struct media_transport *transport,
/* Reply if owner has a pending request */
if (owner->pending)
- media_request_reply(owner->pending, transport->conn, EIO);
+ media_request_reply(owner->pending, EIO);
transport->owners = g_slist_remove(transport->owners, owner);
if (owner->watch)
- g_dbus_remove_watch(transport->conn, owner->watch);
+ g_dbus_remove_watch(btd_get_dbus_connection(), owner->watch);
media_owner_free(owner);
@@ -379,7 +377,7 @@ static void a2dp_resume_complete(struct avdtp *session,
if ((owner->lock & TRANSPORT_LOCK_WRITE) == 0)
omtu = 0;
- ret = g_dbus_send_reply(transport->conn, req->msg,
+ ret = g_dbus_send_reply(btd_get_dbus_connection(), req->msg,
DBUS_TYPE_UNIX_FD, &fd,
DBUS_TYPE_UINT16, &imtu,
DBUS_TYPE_UINT16, &omtu,
@@ -435,7 +433,7 @@ static void a2dp_suspend_complete(struct avdtp *session,
/* Release always succeeds */
if (owner->pending) {
owner->pending->id = 0;
- media_request_reply(owner->pending, transport->conn, 0);
+ media_request_reply(owner->pending, 0);
media_owner_remove(owner);
}
@@ -499,7 +497,7 @@ static void headset_resume_complete(struct audio_device *dev, void *user_data)
if ((owner->lock & TRANSPORT_LOCK_WRITE) == 0)
omtu = 0;
- ret = g_dbus_send_reply(transport->conn, req->msg,
+ ret = g_dbus_send_reply(btd_get_dbus_connection(), req->msg,
DBUS_TYPE_UNIX_FD, &fd,
DBUS_TYPE_UINT16, &imtu,
DBUS_TYPE_UINT16, &omtu,
@@ -545,7 +543,7 @@ static void headset_suspend_complete(struct audio_device *dev, void *user_data)
/* Release always succeeds */
if (owner->pending) {
owner->pending->id = 0;
- media_request_reply(owner->pending, transport->conn, 0);
+ media_request_reply(owner->pending, 0);
media_owner_remove(owner);
}
@@ -615,7 +613,7 @@ static void gateway_resume_complete(struct audio_device *dev, GError *err,
if ((owner->lock & TRANSPORT_LOCK_WRITE) == 0)
omtu = 0;
- ret = g_dbus_send_reply(transport->conn, req->msg,
+ ret = g_dbus_send_reply(btd_get_dbus_connection(), req->msg,
DBUS_TYPE_UNIX_FD, &fd,
DBUS_TYPE_UINT16, &imtu,
DBUS_TYPE_UINT16, &omtu,
@@ -662,7 +660,7 @@ static gboolean gateway_suspend_complete(gpointer user_data)
/* Release always succeeds */
if (owner->pending) {
owner->pending->id = 0;
- media_request_reply(owner->pending, transport->conn, 0);
+ media_request_reply(owner->pending, 0);
media_owner_remove(owner);
}
@@ -736,13 +734,13 @@ static void media_transport_add(struct media_transport *transport,
DBG("Transport %s Owner %s", transport->path, owner->name);
transport->owners = g_slist_append(transport->owners, owner);
owner->transport = transport;
- owner->watch = g_dbus_add_disconnect_watch(transport->conn, owner->name,
+ owner->watch = g_dbus_add_disconnect_watch(btd_get_dbus_connection(),
+ owner->name,
media_owner_exit,
owner, NULL);
}
-static struct media_owner *media_owner_create(DBusConnection *conn,
- DBusMessage *msg,
+static struct media_owner *media_owner_create(DBusMessage *msg,
transport_lock_t lock)
{
struct media_owner *owner;
@@ -814,7 +812,7 @@ static DBusMessage *acquire(DBusConnection *conn, DBusMessage *msg,
if (media_transport_acquire(transport, lock) == FALSE)
return btd_error_not_authorized(msg);
- owner = media_owner_create(conn, msg, lock);
+ owner = media_owner_create(msg, lock);
id = transport->resume(transport, owner);
if (id == 0) {
media_transport_release(transport, lock);
@@ -1153,9 +1151,6 @@ static void media_transport_free(void *data)
if (transport->destroy != NULL)
transport->destroy(transport->data);
- if (transport->conn)
- dbus_connection_unref(transport->conn);
-
g_free(transport->configuration);
g_free(transport->path);
g_free(transport);
@@ -1259,8 +1254,7 @@ static void source_state_changed(struct audio_device *dev,
transport_update_playing(transport, FALSE);
}
-struct media_transport *media_transport_create(DBusConnection *conn,
- struct media_endpoint *endpoint,
+struct media_transport *media_transport_create(struct media_endpoint *endpoint,
struct audio_device *device,
uint8_t *configuration,
size_t size)
@@ -1270,7 +1264,6 @@ struct media_transport *media_transport_create(DBusConnection *conn,
static int fd = 0;
transport = g_new0(struct media_transport, 1);
- transport->conn = dbus_connection_ref(conn);
transport->device = device;
transport->endpoint = endpoint;
transport->configuration = g_new(uint8_t, size);
@@ -1336,8 +1329,8 @@ struct media_transport *media_transport_create(DBusConnection *conn,
} else
goto fail;
- if (g_dbus_register_interface(transport->conn, transport->path,
- MEDIA_TRANSPORT_INTERFACE,
+ if (g_dbus_register_interface(btd_get_dbus_connection(),
+ transport->path, MEDIA_TRANSPORT_INTERFACE,
transport_methods, transport_signals, NULL,
transport, media_transport_free) == FALSE) {
error("Could not register transport %s", transport->path);
diff --git a/audio/transport.h b/audio/transport.h
index d20c327..a6b71e5 100644
--- a/audio/transport.h
+++ b/audio/transport.h
@@ -24,8 +24,7 @@
struct media_transport;
-struct media_transport *media_transport_create(DBusConnection *conn,
- struct media_endpoint *endpoint,
+struct media_transport *media_transport_create(struct media_endpoint *endpoint,
struct audio_device *device,
uint8_t *configuration,
size_t size);
--
1.7.11.3
This patch removes redundant references and function parameters for
DBusConnection object and uses btd_get_dbus_connection() call wherever
such object is needed instead.
Pointer returned by this call is guaranteed to be valid for entire
bluetoothd lifetime and thus do not need to be refcounted.
---
plugins/service.c | 74 ++++++++++++++++++++++---------------------------------
1 file changed, 29 insertions(+), 45 deletions(-)
diff --git a/plugins/service.c b/plugins/service.c
index f16abe7..9bb8882 100644
--- a/plugins/service.c
+++ b/plugins/service.c
@@ -36,6 +36,7 @@
#include <gdbus.h>
+#include "dbus-common.h"
#include "sdpd.h"
#include "sdp-xml.h"
#include "plugin.h"
@@ -45,8 +46,6 @@
#define SERVICE_INTERFACE "org.bluez.Service"
-static DBusConnection *connection;
-
struct record_data {
uint32_t handle;
char *sender;
@@ -62,7 +61,6 @@ struct context_data {
};
struct pending_auth {
- DBusConnection *conn;
DBusMessage *msg;
char *sender;
bdaddr_t dst;
@@ -338,7 +336,7 @@ static void exit_callback(DBusConnection *conn, void *user_data)
g_free(user_record);
}
-static int add_xml_record(DBusConnection *conn, const char *sender,
+static int add_xml_record(const char *sender,
struct service_adapter *serv_adapter,
const char *record, dbus_uint32_t *handle)
{
@@ -367,7 +365,8 @@ static int add_xml_record(DBusConnection *conn, const char *sender,
user_record->handle = sdp_record->handle;
user_record->sender = g_strdup(sender);
user_record->serv_adapter = serv_adapter;
- user_record->listener_id = g_dbus_add_disconnect_watch(conn, sender,
+ user_record->listener_id =
+ g_dbus_add_disconnect_watch(btd_get_dbus_connection(), sender,
exit_callback, user_record, NULL);
serv_adapter->records = g_slist_append(serv_adapter->records,
@@ -380,9 +379,9 @@ static int add_xml_record(DBusConnection *conn, const char *sender,
return 0;
}
-static DBusMessage *update_record(DBusConnection *conn, DBusMessage *msg,
- struct service_adapter *serv_adapter,
- dbus_uint32_t handle, sdp_record_t *sdp_record)
+static DBusMessage *update_record(DBusMessage *msg,
+ struct service_adapter *serv_adapter,
+ dbus_uint32_t handle, sdp_record_t *sdp_record)
{
bdaddr_t src;
int err;
@@ -408,9 +407,8 @@ static DBusMessage *update_record(DBusConnection *conn, DBusMessage *msg,
return dbus_message_new_method_return(msg);
}
-static DBusMessage *update_xml_record(DBusConnection *conn,
- DBusMessage *msg,
- struct service_adapter *serv_adapter)
+static DBusMessage *update_xml_record(DBusMessage *msg,
+ struct service_adapter *serv_adapter)
{
struct record_data *user_record;
sdp_record_t *sdp_record;
@@ -440,13 +438,14 @@ static DBusMessage *update_xml_record(DBusConnection *conn,
"Parsing of XML service record failed");
}
- return update_record(conn, msg, serv_adapter, handle, sdp_record);
+ return update_record(msg, serv_adapter, handle, sdp_record);
}
-static int remove_record(DBusConnection *conn, const char *sender,
- struct service_adapter *serv_adapter,
- dbus_uint32_t handle)
+static int remove_record(const char *sender,
+ struct service_adapter *serv_adapter,
+ dbus_uint32_t handle)
{
+ DBusConnection *conn = btd_get_dbus_connection();
struct record_data *user_record;
DBG("remove record 0x%x", handle);
@@ -478,7 +477,7 @@ static DBusMessage *add_service_record(DBusConnection *conn,
return btd_error_invalid_args(msg);
sender = dbus_message_get_sender(msg);
- err = add_xml_record(conn, sender, serv_adapter, record, &handle);
+ err = add_xml_record(sender, serv_adapter, record, &handle);
if (err < 0)
return btd_error_failed(msg, strerror(-err));
@@ -497,7 +496,7 @@ static DBusMessage *update_service_record(DBusConnection *conn,
{
struct service_adapter *serv_adapter = data;
- return update_xml_record(conn, msg, serv_adapter);
+ return update_xml_record(msg, serv_adapter);
}
static DBusMessage *remove_service_record(DBusConnection *conn,
@@ -513,7 +512,7 @@ static DBusMessage *remove_service_record(DBusConnection *conn,
sender = dbus_message_get_sender(msg);
- if (remove_record(conn, sender, serv_adapter, handle) < 0)
+ if (remove_record(sender, serv_adapter, handle) < 0)
return btd_error_not_available(msg);
return dbus_message_new_method_return(msg);
@@ -521,6 +520,7 @@ static DBusMessage *remove_service_record(DBusConnection *conn,
static void auth_cb(DBusError *derr, void *user_data)
{
+ DBusConnection *conn = btd_get_dbus_connection();
struct service_adapter *serv_adapter = user_data;
DBusMessage *reply;
struct pending_auth *auth;
@@ -537,16 +537,14 @@ static void auth_cb(DBusError *derr, void *user_data)
reply = btd_error_not_authorized(auth->msg);
dbus_message_unref(auth->msg);
- g_dbus_send_message(auth->conn, reply);
+ g_dbus_send_message(conn, reply);
goto done;
}
- g_dbus_send_reply(auth->conn, auth->msg,
+ g_dbus_send_reply(conn, auth->msg,
DBUS_TYPE_INVALID);
done:
- dbus_connection_unref(auth->conn);
-
serv_adapter->pending_list = g_slist_remove(serv_adapter->pending_list,
auth);
g_free(auth);
@@ -620,7 +618,6 @@ static DBusMessage *request_authorization(DBusConnection *conn,
auth = g_new0(struct pending_auth, 1);
auth->msg = dbus_message_ref(msg);
- auth->conn = dbus_connection_ref(connection);
auth->sender = user_record->sender;
memcpy(auth->uuid, uuid_str, MAX_LEN_UUID_STR);
str2ba(address, &auth->dst);
@@ -672,9 +669,7 @@ static DBusMessage *cancel_authorization(DBusConnection *conn,
reply = btd_error_not_authorized(auth->msg);
dbus_message_unref(auth->msg);
- g_dbus_send_message(auth->conn, reply);
-
- dbus_connection_unref(auth->conn);
+ g_dbus_send_message(btd_get_dbus_connection(), reply);
serv_adapter->pending_list = g_slist_remove(serv_adapter->pending_list,
auth);
@@ -717,6 +712,7 @@ static const GDBusMethodTable service_methods[] = {
static void path_unregister(void *data)
{
+ DBusConnection *conn = btd_get_dbus_connection();
struct service_adapter *serv_adapter = data;
GSList *l, *next = NULL;
@@ -725,8 +721,8 @@ static void path_unregister(void *data)
next = l->next;
- g_dbus_remove_watch(connection, user_record->listener_id);
- exit_callback(connection, user_record);
+ g_dbus_remove_watch(conn, user_record->listener_id);
+ exit_callback(conn, user_record);
}
if (serv_adapter->adapter != NULL)
@@ -750,7 +746,8 @@ static int register_interface(const char *path, struct btd_adapter *adapter)
serv_adapter->pending_list = NULL;
- if (g_dbus_register_interface(connection, path, SERVICE_INTERFACE,
+ if (g_dbus_register_interface(btd_get_dbus_connection(),
+ path, SERVICE_INTERFACE,
service_methods, NULL, NULL, serv_adapter,
path_unregister) == FALSE) {
error("D-Bus failed to register %s interface",
@@ -771,7 +768,8 @@ static void unregister_interface(const char *path)
{
DBG("path %s", path);
- g_dbus_unregister_interface(connection, path, SERVICE_INTERFACE);
+ g_dbus_unregister_interface(btd_get_dbus_connection(),
+ path, SERVICE_INTERFACE);
}
static int service_probe(struct btd_adapter *adapter)
@@ -796,12 +794,6 @@ static const char *any_path;
static int service_init(void)
{
- int err;
-
- connection = dbus_bus_get(DBUS_BUS_SYSTEM, NULL);
- if (connection == NULL)
- return -EIO;
-
any_path = btd_adapter_any_request_path();
if (any_path != NULL) {
if (register_interface(any_path, NULL) < 0) {
@@ -810,13 +802,7 @@ static int service_init(void)
}
}
- err = btd_register_adapter_driver(&service_driver);
- if (err < 0) {
- dbus_connection_unref(connection);
- return err;
- }
-
- return 0;
+ return btd_register_adapter_driver(&service_driver);
}
static void service_exit(void)
@@ -829,8 +815,6 @@ static void service_exit(void)
btd_adapter_any_release_path();
any_path = NULL;
}
-
- dbus_connection_unref(connection);
}
BLUETOOTH_PLUGIN_DEFINE(service, VERSION,
--
1.7.11.3
This patch removes local reference to DBusConnection object and uses
btd_get_dbus_connection() call wherever such object is needed instead.
Pointer returned by this call is guaranteed to be valid for entire
bluetoothd lifetime and thus do not need to be refcounted.
---
plugins/dbusoob.c | 15 +++++++--------
1 file changed, 7 insertions(+), 8 deletions(-)
diff --git a/plugins/dbusoob.c b/plugins/dbusoob.c
index 11b2594..543b272 100644
--- a/plugins/dbusoob.c
+++ b/plugins/dbusoob.c
@@ -63,7 +63,6 @@ struct oob_data {
};
static GSList *oob_requests = NULL;
-static DBusConnection *connection = NULL;
static gint oob_request_cmp(gconstpointer a, gconstpointer b)
{
@@ -129,7 +128,7 @@ done:
return;
}
- if (!g_dbus_send_message(connection, reply))
+ if (!g_dbus_send_message(btd_get_dbus_connection(), reply))
error("D-Bus send failed");
}
@@ -331,8 +330,10 @@ static int oob_probe(struct btd_adapter *adapter)
{
const char *path = adapter_get_path(adapter);
- if (!g_dbus_register_interface(connection, path, OOB_INTERFACE,
- oob_methods, NULL, NULL, adapter, NULL)) {
+ if (!g_dbus_register_interface(btd_get_dbus_connection(),
+ path, OOB_INTERFACE,
+ oob_methods, NULL, NULL,
+ adapter, NULL)) {
error("OOB interface init failed on path %s", path);
return -EIO;
}
@@ -344,8 +345,8 @@ static void oob_remove(struct btd_adapter *adapter)
{
read_local_data_complete(adapter, NULL, NULL);
- g_dbus_unregister_interface(connection, adapter_get_path(adapter),
- OOB_INTERFACE);
+ g_dbus_unregister_interface(btd_get_dbus_connection(),
+ adapter_get_path(adapter), OOB_INTERFACE);
}
static struct btd_adapter_driver oob_driver = {
@@ -358,8 +359,6 @@ static int dbusoob_init(void)
{
DBG("Setup dbusoob plugin");
- connection = btd_get_dbus_connection();
-
oob_register_cb(read_local_data_complete);
return btd_register_adapter_driver(&oob_driver);
--
1.7.11.3
This patch removes redundant references and function parameters for
DBusConnection object and uses btd_get_dbus_connection() call wherever
such object is needed instead.
Pointer returned by this call is guaranteed to be valid for entire
bluetoothd lifetime and thus do not need to be refcounted.
---
profiles/network/connection.c | 64 +++++++++++++++++--------------------------
profiles/network/connection.h | 2 --
profiles/network/main.c | 15 +---------
profiles/network/manager.c | 16 ++---------
profiles/network/manager.h | 2 +-
profiles/network/server.c | 13 ++++-----
profiles/network/server.h | 2 +-
7 files changed, 35 insertions(+), 79 deletions(-)
diff --git a/profiles/network/connection.c b/profiles/network/connection.c
index 178f51f..9773b7b 100644
--- a/profiles/network/connection.c
+++ b/profiles/network/connection.c
@@ -84,7 +84,6 @@ struct __service_16 {
uint16_t src;
} __attribute__ ((packed));
-static DBusConnection *connection = NULL;
static GSList *peers = NULL;
static struct network_peer *find_peer(GSList *list, const char *path)
@@ -115,25 +114,23 @@ static gboolean bnep_watchdog_cb(GIOChannel *chan, GIOCondition cond,
gpointer data)
{
struct network_conn *nc = data;
+ gboolean connected = FALSE;
+ const char *property = "";
- if (connection != NULL) {
- gboolean connected = FALSE;
- const char *property = "";
- emit_property_changed(nc->peer->path,
- NETWORK_PEER_INTERFACE, "Connected",
- DBUS_TYPE_BOOLEAN, &connected);
- emit_property_changed(nc->peer->path,
- NETWORK_PEER_INTERFACE, "Interface",
- DBUS_TYPE_STRING, &property);
- emit_property_changed(nc->peer->path,
- NETWORK_PEER_INTERFACE, "UUID",
- DBUS_TYPE_STRING, &property);
- device_remove_disconnect_watch(nc->peer->device, nc->dc_id);
- nc->dc_id = 0;
- if (nc->watch) {
- g_dbus_remove_watch(connection, nc->watch);
- nc->watch = 0;
- }
+ emit_property_changed(nc->peer->path,
+ NETWORK_PEER_INTERFACE, "Connected",
+ DBUS_TYPE_BOOLEAN, &connected);
+ emit_property_changed(nc->peer->path,
+ NETWORK_PEER_INTERFACE, "Interface",
+ DBUS_TYPE_STRING, &property);
+ emit_property_changed(nc->peer->path,
+ NETWORK_PEER_INTERFACE, "UUID",
+ DBUS_TYPE_STRING, &property);
+ device_remove_disconnect_watch(nc->peer->device, nc->dc_id);
+ nc->dc_id = 0;
+ if (nc->watch) {
+ g_dbus_remove_watch(btd_get_dbus_connection(), nc->watch);
+ nc->watch = 0;
}
info("%s disconnected", nc->dev);
@@ -148,6 +145,7 @@ static gboolean bnep_watchdog_cb(GIOChannel *chan, GIOCondition cond,
static void cancel_connection(struct network_conn *nc, const char *err_msg)
{
+ DBusConnection *conn = btd_get_dbus_connection();
DBusMessage *reply;
if (nc->timeout_source > 0) {
@@ -156,13 +154,13 @@ static void cancel_connection(struct network_conn *nc, const char *err_msg)
}
if (nc->watch) {
- g_dbus_remove_watch(connection, nc->watch);
+ g_dbus_remove_watch(conn, nc->watch);
nc->watch = 0;
}
if (nc->msg && err_msg) {
reply = btd_error_failed(nc->msg, err_msg);
- g_dbus_send_message(connection, reply);
+ g_dbus_send_message(conn, reply);
}
g_io_channel_shutdown(nc->io, TRUE, NULL);
@@ -269,7 +267,7 @@ static gboolean bnep_setup_cb(GIOChannel *chan, GIOCondition cond,
pdev = nc->dev;
uuid = bnep_uuid(nc->id);
- g_dbus_send_reply(connection, nc->msg,
+ g_dbus_send_reply(btd_get_dbus_connection(), nc->msg,
DBUS_TYPE_STRING, &pdev,
DBUS_TYPE_INVALID);
@@ -450,7 +448,7 @@ static DBusMessage *connection_cancel(DBusConnection *conn,
if (!g_str_equal(owner, caller))
return btd_error_not_authorized(msg);
- connection_destroy(conn, nc);
+ connection_destroy(NULL, nc);
return g_dbus_create_reply(msg, DBUS_TYPE_INVALID);
}
@@ -530,7 +528,7 @@ static void connection_free(void *data)
if (nc->dc_id)
device_remove_disconnect_watch(nc->peer->device, nc->dc_id);
- connection_destroy(connection, nc);
+ connection_destroy(NULL, nc);
g_free(nc);
nc = NULL;
@@ -585,7 +583,8 @@ void connection_unregister(const char *path)
g_slist_free_full(peer->connections, connection_free);
peer->connections = NULL;
- g_dbus_unregister_interface(connection, path, NETWORK_PEER_INTERFACE);
+ g_dbus_unregister_interface(btd_get_dbus_connection(),
+ path, NETWORK_PEER_INTERFACE);
}
static struct network_peer *create_peer(struct btd_device *device,
@@ -600,7 +599,7 @@ static struct network_peer *create_peer(struct btd_device *device,
bacpy(&peer->src, src);
bacpy(&peer->dst, dst);
- if (g_dbus_register_interface(connection, path,
+ if (g_dbus_register_interface(btd_get_dbus_connection(), path,
NETWORK_PEER_INTERFACE,
connection_methods,
connection_signals, NULL,
@@ -649,16 +648,3 @@ int connection_register(struct btd_device *device, const char *path,
return 0;
}
-
-int connection_init(DBusConnection *conn)
-{
- connection = dbus_connection_ref(conn);
-
- return 0;
-}
-
-void connection_exit(void)
-{
- dbus_connection_unref(connection);
- connection = NULL;
-}
diff --git a/profiles/network/connection.h b/profiles/network/connection.h
index a5e0e61..2e33c55 100644
--- a/profiles/network/connection.h
+++ b/profiles/network/connection.h
@@ -21,8 +21,6 @@
*
*/
-int connection_init(DBusConnection *conn);
-void connection_exit(void);
int connection_register(struct btd_device *device, const char *path,
bdaddr_t *src, bdaddr_t *dst, uint16_t id);
void connection_unregister(const char *path);
diff --git a/profiles/network/main.c b/profiles/network/main.c
index 88e77ee..8ec1f3f 100644
--- a/profiles/network/main.c
+++ b/profiles/network/main.c
@@ -32,27 +32,14 @@
#include "plugin.h"
#include "manager.h"
-static DBusConnection *connection;
-
static int network_init(void)
{
- connection = dbus_bus_get(DBUS_BUS_SYSTEM, NULL);
- if (connection == NULL)
- return -EIO;
-
- if (network_manager_init(connection) < 0) {
- dbus_connection_unref(connection);
- return -EIO;
- }
-
- return 0;
+ return network_manager_init();
}
static void network_exit(void)
{
network_manager_exit();
-
- dbus_connection_unref(connection);
}
BLUETOOTH_PLUGIN_DEFINE(network, VERSION,
diff --git a/profiles/network/manager.c b/profiles/network/manager.c
index 9ab3a8b..a0506d3 100644
--- a/profiles/network/manager.c
+++ b/profiles/network/manager.c
@@ -45,8 +45,6 @@
#include "connection.h"
#include "server.h"
-static DBusConnection *connection = NULL;
-
static gboolean conf_security = TRUE;
static void read_config(const char *file)
@@ -133,7 +131,7 @@ static struct btd_profile network_profile = {
.adapter_remove = network_server_remove,
};
-int network_manager_init(DBusConnection *conn)
+int network_manager_init(void)
{
read_config(CONFIGDIR "/network.conf");
@@ -149,16 +147,11 @@ int network_manager_init(DBusConnection *conn)
* field that defines which service the source is connecting to.
*/
- if (server_init(conn, conf_security) < 0)
+ if (server_init(conf_security) < 0)
return -1;
btd_profile_register(&network_profile);
- if (connection_init(conn) < 0)
- return -1;
-
- connection = dbus_connection_ref(conn);
-
return 0;
}
@@ -166,12 +159,7 @@ void network_manager_exit(void)
{
server_exit();
- connection_exit();
-
btd_profile_unregister(&network_profile);
- dbus_connection_unref(connection);
- connection = NULL;
-
bnep_cleanup();
}
diff --git a/profiles/network/manager.h b/profiles/network/manager.h
index 27bc13f..5ba1f0e 100644
--- a/profiles/network/manager.h
+++ b/profiles/network/manager.h
@@ -21,5 +21,5 @@
*
*/
-int network_manager_init(DBusConnection *conn);
+int network_manager_init(void);
void network_manager_exit(void);
diff --git a/profiles/network/server.c b/profiles/network/server.c
index 88e108f..43ce9d9 100644
--- a/profiles/network/server.c
+++ b/profiles/network/server.c
@@ -82,7 +82,6 @@ struct network_server {
guint watch_id; /* Client service watch */
};
-static DBusConnection *connection = NULL;
static GSList *adapters = NULL;
static gboolean security = TRUE;
@@ -553,18 +552,15 @@ drop:
g_io_channel_shutdown(chan, TRUE, NULL);
}
-int server_init(DBusConnection *conn, gboolean secure)
+int server_init(gboolean secure)
{
security = secure;
- connection = dbus_connection_ref(conn);
return 0;
}
void server_exit(void)
{
- dbus_connection_unref(connection);
- connection = NULL;
}
static uint32_t register_server_record(struct network_server *ns)
@@ -798,7 +794,8 @@ int server_register(struct btd_adapter *adapter)
path = adapter_get_path(adapter);
- if (!g_dbus_register_interface(connection, path, ns->iface,
+ if (!g_dbus_register_interface(btd_get_dbus_connection(),
+ path, ns->iface,
server_methods, NULL, NULL,
ns, path_unregister)) {
error("D-Bus failed to register %s interface",
@@ -832,8 +829,8 @@ int server_unregister(struct btd_adapter *adapter)
if (!ns)
return -EINVAL;
- g_dbus_unregister_interface(connection, adapter_get_path(adapter),
- ns->iface);
+ g_dbus_unregister_interface(btd_get_dbus_connection(),
+ adapter_get_path(adapter), ns->iface);
return 0;
}
diff --git a/profiles/network/server.h b/profiles/network/server.h
index 6351f6d..4c3ab85 100644
--- a/profiles/network/server.h
+++ b/profiles/network/server.h
@@ -21,7 +21,7 @@
*
*/
-int server_init(DBusConnection *conn, gboolean secure);
+int server_init(gboolean secure);
void server_exit(void);
int server_register(struct btd_adapter *adapter);
int server_unregister(struct btd_adapter *adapter);
--
1.7.11.3
This patch removes redundant references and function parameters for
DBusConnection object and uses btd_get_dbus_connection() call wherever
such object is needed instead.
Pointer returned by this call is guaranteed to be valid for entire
bluetoothd lifetime and thus do not need to be refcounted.
---
profiles/thermometer/main.c | 17 +----------------
profiles/thermometer/manager.c | 11 ++---------
profiles/thermometer/manager.h | 2 +-
profiles/thermometer/thermometer.c | 22 +++++++++-------------
profiles/thermometer/thermometer.h | 3 +--
5 files changed, 14 insertions(+), 41 deletions(-)
diff --git a/profiles/thermometer/main.c b/profiles/thermometer/main.c
index 4447b52..fd4b8e2 100644
--- a/profiles/thermometer/main.c
+++ b/profiles/thermometer/main.c
@@ -27,15 +27,12 @@
#include <stdint.h>
#include <glib.h>
#include <errno.h>
-#include <gdbus.h>
#include "plugin.h"
#include "manager.h"
#include "hcid.h"
#include "log.h"
-static DBusConnection *connection = NULL;
-
static int thermometer_init(void)
{
if (!main_opts.gatt_enabled) {
@@ -43,16 +40,7 @@ static int thermometer_init(void)
return -ENOTSUP;
}
- connection = dbus_bus_get(DBUS_BUS_SYSTEM, NULL);
- if (connection == NULL)
- return -EIO;
-
- if (thermometer_manager_init(connection) < 0) {
- dbus_connection_unref(connection);
- return -EIO;
- }
-
- return 0;
+ return thermometer_manager_init();
}
static void thermometer_exit(void)
@@ -61,9 +49,6 @@ static void thermometer_exit(void)
return;
thermometer_manager_exit();
-
- dbus_connection_unref(connection);
- connection = NULL;
}
BLUETOOTH_PLUGIN_DEFINE(thermometer, VERSION, BLUETOOTH_PLUGIN_PRIORITY_DEFAULT,
diff --git a/profiles/thermometer/manager.c b/profiles/thermometer/manager.c
index 4a894cf..1b5173e 100644
--- a/profiles/thermometer/manager.c
+++ b/profiles/thermometer/manager.c
@@ -20,7 +20,6 @@
*
*/
-#include <gdbus.h>
#include <errno.h>
#include <stdbool.h>
#include <bluetooth/uuid.h>
@@ -34,8 +33,6 @@
#include "thermometer.h"
#include "manager.h"
-static DBusConnection *connection = NULL;
-
static gint primary_uuid_cmp(gconstpointer a, gconstpointer b)
{
const struct gatt_primary *prim = a;
@@ -58,7 +55,7 @@ static int thermometer_driver_probe(struct btd_device *device, GSList *uuids)
tattr = l->data;
- return thermometer_register(connection, device, tattr);
+ return thermometer_register(device, tattr);
}
static void thermometer_driver_remove(struct btd_device *device)
@@ -73,7 +70,7 @@ static struct btd_profile thermometer_profile = {
.device_remove = thermometer_driver_remove
};
-int thermometer_manager_init(DBusConnection *conn)
+int thermometer_manager_init(void)
{
int ret;
@@ -81,14 +78,10 @@ int thermometer_manager_init(DBusConnection *conn)
if (ret < 0)
return ret;
- connection = dbus_connection_ref(conn);
return 0;
}
void thermometer_manager_exit(void)
{
btd_profile_unregister(&thermometer_profile);
-
- dbus_connection_unref(connection);
- connection = NULL;
}
diff --git a/profiles/thermometer/manager.h b/profiles/thermometer/manager.h
index ed928ad..01e4f62 100644
--- a/profiles/thermometer/manager.h
+++ b/profiles/thermometer/manager.h
@@ -20,5 +20,5 @@
*
*/
-int thermometer_manager_init(DBusConnection *conn);
+int thermometer_manager_init(void);
void thermometer_manager_exit(void);
diff --git a/profiles/thermometer/thermometer.c b/profiles/thermometer/thermometer.c
index 44043e8..77dcb26 100644
--- a/profiles/thermometer/thermometer.c
+++ b/profiles/thermometer/thermometer.c
@@ -56,7 +56,6 @@
#define MEASUREMENT_INTERVAL_SIZE 2
struct thermometer {
- DBusConnection *conn; /* The connection to the bus */
struct btd_device *dev; /* Device reference */
GAttrib *attrib; /* GATT connection */
struct att_range *svc_range; /* Thermometer range */
@@ -146,7 +145,7 @@ static void remove_watcher(gpointer user_data)
{
struct watcher *watcher = user_data;
- g_dbus_remove_watch(watcher->t->conn, watcher->id);
+ g_dbus_remove_watch(btd_get_dbus_connection(), watcher->id);
}
static void destroy_char(gpointer user_data)
@@ -179,7 +178,6 @@ static void destroy_thermometer(gpointer user_data)
if (t->fwatchers != NULL)
g_slist_free_full(t->fwatchers, remove_watcher);
- dbus_connection_unref(t->conn);
btd_device_unref(t->dev);
g_free(t->svc_range);
g_free(t);
@@ -822,7 +820,7 @@ static void watcher_exit(DBusConnection *conn, void *user_data)
remove_int_watcher(t, watcher);
t->fwatchers = g_slist_remove(t->fwatchers, watcher);
- g_dbus_remove_watch(watcher->t->conn, watcher->id);
+ g_dbus_remove_watch(btd_get_dbus_connection(), watcher->id);
if (g_slist_length(t->fwatchers) == 0)
disable_final_measurement(t);
@@ -901,7 +899,7 @@ static DBusMessage *unregister_watcher(DBusConnection *conn, DBusMessage *msg,
remove_int_watcher(t, watcher);
t->fwatchers = g_slist_remove(t->fwatchers, watcher);
- g_dbus_remove_watch(watcher->t->conn, watcher->id);
+ g_dbus_remove_watch(btd_get_dbus_connection(), watcher->id);
if (g_slist_length(t->fwatchers) == 0)
disable_final_measurement(t);
@@ -996,7 +994,6 @@ static void update_watcher(gpointer data, gpointer user_data)
{
struct watcher *w = data;
struct measurement *m = user_data;
- DBusConnection *conn = w->t->conn;
DBusMessageIter iter;
DBusMessageIter dict;
DBusMessage *msg;
@@ -1027,7 +1024,7 @@ static void update_watcher(gpointer data, gpointer user_data)
dbus_message_iter_close_container(&iter, &dict);
dbus_message_set_no_reply(msg, TRUE);
- g_dbus_send_message(conn, msg);
+ g_dbus_send_message(btd_get_dbus_connection(), msg);
}
static void recv_measurement(struct thermometer *t, struct measurement *m)
@@ -1232,20 +1229,19 @@ static void attio_disconnected_cb(gpointer user_data)
t->attrib = NULL;
}
-int thermometer_register(DBusConnection *connection, struct btd_device *device,
- struct gatt_primary *tattr)
+int thermometer_register(struct btd_device *device, struct gatt_primary *tattr)
{
const gchar *path = device_get_path(device);
struct thermometer *t;
t = g_new0(struct thermometer, 1);
- t->conn = dbus_connection_ref(connection);
t->dev = btd_device_ref(device);
t->svc_range = g_new0(struct att_range, 1);
t->svc_range->start = tattr->range.start;
t->svc_range->end = tattr->range.end;
- if (!g_dbus_register_interface(t->conn, path, THERMOMETER_INTERFACE,
+ if (!g_dbus_register_interface(btd_get_dbus_connection(),
+ path, THERMOMETER_INTERFACE,
thermometer_methods, thermometer_signals,
NULL, t, destroy_thermometer)) {
error("D-Bus failed to register %s interface",
@@ -1272,6 +1268,6 @@ void thermometer_unregister(struct btd_device *device)
t = l->data;
thermometers = g_slist_remove(thermometers, t);
- g_dbus_unregister_interface(t->conn, device_get_path(t->dev),
- THERMOMETER_INTERFACE);
+ g_dbus_unregister_interface(btd_get_dbus_connection(),
+ device_get_path(t->dev), THERMOMETER_INTERFACE);
}
diff --git a/profiles/thermometer/thermometer.h b/profiles/thermometer/thermometer.h
index 330503c..2744ed6 100644
--- a/profiles/thermometer/thermometer.h
+++ b/profiles/thermometer/thermometer.h
@@ -20,6 +20,5 @@
*
*/
-int thermometer_register(DBusConnection *connection, struct btd_device *device,
- struct gatt_primary *tattr);
+int thermometer_register(struct btd_device *device, struct gatt_primary *tattr);
void thermometer_unregister(struct btd_device *device);
--
1.7.11.3
This patch removes redundant references and function parameters for
DBusConnection object and uses btd_get_dbus_connection() call wherever
such object is needed instead.
Pointer returned by this call is guaranteed to be valid for entire
bluetoothd lifetime and thus do not need to be refcounted.
---
profiles/sap/main.c | 16 +---------------
profiles/sap/manager.c | 17 +----------------
profiles/sap/manager.h | 2 +-
profiles/sap/sap-dummy.c | 19 ++++++-------------
profiles/sap/server.c | 21 ++++-----------------
profiles/sap/server.h | 2 --
6 files changed, 13 insertions(+), 64 deletions(-)
diff --git a/profiles/sap/main.c b/profiles/sap/main.c
index c9c90bd..4894f2e 100644
--- a/profiles/sap/main.c
+++ b/profiles/sap/main.c
@@ -27,28 +27,14 @@
#include "plugin.h"
#include "manager.h"
-static DBusConnection *connection;
-
static int sap_init(void)
{
- connection = dbus_bus_get(DBUS_BUS_SYSTEM, NULL);
-
- if (!connection)
- return -EIO;
-
- if (sap_manager_init(connection) < 0) {
- dbus_connection_unref(connection);
- return -EIO;
- }
-
- return 0;
+ return sap_manager_init();
}
static void sap_exit(void)
{
sap_manager_exit();
-
- dbus_connection_unref(connection);
}
BLUETOOTH_PLUGIN_DEFINE(sap, VERSION,
diff --git a/profiles/sap/manager.c b/profiles/sap/manager.c
index ecf672e..ebfe266 100644
--- a/profiles/sap/manager.c
+++ b/profiles/sap/manager.c
@@ -32,8 +32,6 @@
#include "manager.h"
#include "server.h"
-static DBusConnection *connection = NULL;
-
static int sap_server_probe(struct btd_adapter *adapter)
{
const char *path = adapter_get_path(adapter);
@@ -61,16 +59,8 @@ static struct btd_profile sap_profile = {
.adapter_remove = sap_server_remove,
};
-int sap_manager_init(DBusConnection *conn)
+int sap_manager_init(void)
{
- connection = dbus_connection_ref(conn);
-
- if (sap_server_init(connection) < 0) {
- error("Can't init SAP server");
- dbus_connection_unref(conn);
- return -1;
- }
-
btd_profile_register(&sap_profile);
return 0;
@@ -79,9 +69,4 @@ int sap_manager_init(DBusConnection *conn)
void sap_manager_exit(void)
{
btd_profile_unregister(&sap_profile);
-
- dbus_connection_unref(connection);
- connection = NULL;
-
- sap_server_exit();
}
diff --git a/profiles/sap/manager.h b/profiles/sap/manager.h
index e08c882..6601a03 100644
--- a/profiles/sap/manager.h
+++ b/profiles/sap/manager.h
@@ -18,5 +18,5 @@
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
*/
-int sap_manager_init(DBusConnection *conn);
+int sap_manager_init(void);
void sap_manager_exit(void);
diff --git a/profiles/sap/sap-dummy.c b/profiles/sap/sap-dummy.c
index dab5acc..36354b8 100644
--- a/profiles/sap/sap-dummy.c
+++ b/profiles/sap/sap-dummy.c
@@ -28,7 +28,9 @@
#include <glib.h>
#include <gdbus.h>
+#include <stdint.h>
+#include "dbus-common.h"
#include "log.h"
#include "sap.h"
@@ -42,7 +44,6 @@ enum {
SIM_MISSING = 0x03
};
-static DBusConnection *connection = NULL;
static unsigned int init_cnt = 0;
static int sim_card_conn_status = SIM_DISCONNECTED;
@@ -359,18 +360,13 @@ int sap_init(void)
if (init_cnt++)
return 0;
- connection = dbus_bus_get(DBUS_BUS_SYSTEM, NULL);
-
- if (g_dbus_register_interface(connection, SAP_DUMMY_PATH,
+ if (g_dbus_register_interface(btd_get_dbus_connection(), SAP_DUMMY_PATH,
SAP_DUMMY_IFACE, dummy_methods, NULL, NULL,
NULL, NULL) == FALSE) {
error("sap-dummy interface %s init failed on path %s",
SAP_DUMMY_IFACE, SAP_DUMMY_PATH);
- if (init_cnt--) {
- dbus_connection_unref(connection);
- connection = NULL;
- }
+ init_cnt--;
return -1;
}
@@ -382,9 +378,6 @@ void sap_exit(void)
if (--init_cnt)
return;
- g_dbus_unregister_interface(connection, SAP_DUMMY_PATH,
- SAP_DUMMY_IFACE);
-
- dbus_connection_unref(connection);
- connection = NULL;
+ g_dbus_unregister_interface(btd_get_dbus_connection(),
+ SAP_DUMMY_PATH, SAP_DUMMY_IFACE);
}
diff --git a/profiles/sap/server.c b/profiles/sap/server.c
index fc3d83c..6c5aa21 100644
--- a/profiles/sap/server.c
+++ b/profiles/sap/server.c
@@ -79,8 +79,6 @@ struct sap_server {
struct sap_connection *conn;
};
-static DBusConnection *connection;
-
static void start_guard_timer(struct sap_server *server, guint interval);
static void stop_guard_timer(struct sap_server *server);
static gboolean guard_timeout(gpointer data);
@@ -1410,8 +1408,8 @@ int sap_server_register(const char *path, bdaddr_t *src)
}
server->listen_io = io;
- if (!g_dbus_register_interface(connection, server->path,
- SAP_SERVER_INTERFACE,
+ if (!g_dbus_register_interface(btd_get_dbus_connection(),
+ server->path, SAP_SERVER_INTERFACE,
server_methods, server_signals, NULL,
server, destroy_sap_interface)) {
error("D-Bus failed to register %s interface",
@@ -1434,19 +1432,8 @@ sdp_err:
void sap_server_unregister(const char *path)
{
- g_dbus_unregister_interface(connection, path, SAP_SERVER_INTERFACE);
+ g_dbus_unregister_interface(btd_get_dbus_connection(),
+ path, SAP_SERVER_INTERFACE);
sap_exit();
}
-
-int sap_server_init(DBusConnection *conn)
-{
- connection = dbus_connection_ref(conn);
- return 0;
-}
-
-void sap_server_exit(void)
-{
- dbus_connection_unref(connection);
- connection = NULL;
-}
diff --git a/profiles/sap/server.h b/profiles/sap/server.h
index 6d2f5e9..9ea9a78 100644
--- a/profiles/sap/server.h
+++ b/profiles/sap/server.h
@@ -20,7 +20,5 @@
#include <gdbus.h>
-int sap_server_init(DBusConnection *conn);
-void sap_server_exit(void);
int sap_server_register(const char *path, bdaddr_t *src);
void sap_server_unregister(const char *path);
--
1.7.11.3
This patch removes redundant references and function parameters for
DBusConnection object and uses btd_get_dbus_connection() call wherever
such object is needed instead.
Pointer returned by this call is guaranteed to be valid for entire
bluetoothd lifetime and thus do not need to be refcounted.
---
profiles/input/device.c | 25 +++++++++++++------------
profiles/input/device.h | 6 +++---
profiles/input/main.c | 12 +-----------
profiles/input/manager.c | 10 ++--------
profiles/input/manager.h | 2 +-
5 files changed, 20 insertions(+), 35 deletions(-)
diff --git a/profiles/input/device.c b/profiles/input/device.c
index dc3da80..73204e0 100644
--- a/profiles/input/device.c
+++ b/profiles/input/device.c
@@ -103,7 +103,6 @@ static void input_device_free(struct input_device *idev)
if (idev->dc_id)
device_remove_disconnect_watch(idev->device, idev->dc_id);
- dbus_connection_unref(idev->conn);
btd_device_unref(idev->device);
g_free(idev->name);
g_free(idev->path);
@@ -506,6 +505,7 @@ static int input_device_connected(struct input_device *idev)
static void interrupt_connect_cb(GIOChannel *chan, GError *conn_err,
gpointer user_data)
{
+ DBusConnection *conn = btd_get_dbus_connection();
struct input_device *idev = user_data;
DBusMessage *reply;
int err;
@@ -523,7 +523,7 @@ static void interrupt_connect_cb(GIOChannel *chan, GError *conn_err,
}
/* Replying to the requestor */
- g_dbus_send_reply(idev->conn, idev->pending_connect, DBUS_TYPE_INVALID);
+ g_dbus_send_reply(conn, idev->pending_connect, DBUS_TYPE_INVALID);
dbus_message_unref(idev->pending_connect);
idev->pending_connect = NULL;
@@ -537,7 +537,7 @@ static void interrupt_connect_cb(GIOChannel *chan, GError *conn_err,
failed:
error("%s", err_msg);
reply = btd_error_failed(idev->pending_connect, err_msg);
- g_dbus_send_message(idev->conn, reply);
+ g_dbus_send_message(conn, reply);
dbus_message_unref(idev->pending_connect);
idev->pending_connect = NULL;
@@ -599,7 +599,7 @@ static void control_connect_cb(GIOChannel *chan, GError *conn_err,
failed:
g_io_channel_unref(idev->ctrl_io);
idev->ctrl_io = NULL;
- g_dbus_send_message(idev->conn, reply);
+ g_dbus_send_message(btd_get_dbus_connection(), reply);
dbus_message_unref(idev->pending_connect);
idev->pending_connect = NULL;
}
@@ -716,9 +716,9 @@ static const GDBusSignalTable device_signals[] = {
{ }
};
-static struct input_device *input_device_new(DBusConnection *conn,
- struct btd_device *device, const char *path,
- const uint32_t handle, gboolean disable_sdp)
+static struct input_device *input_device_new(struct btd_device *device,
+ const char *path, const uint32_t handle,
+ gboolean disable_sdp)
{
struct btd_adapter *adapter = device_get_adapter(device);
struct input_device *idev;
@@ -730,7 +730,6 @@ static struct input_device *input_device_new(DBusConnection *conn,
device_get_address(device, &idev->dst, &dst_type);
idev->device = btd_device_ref(device);
idev->path = g_strdup(path);
- idev->conn = dbus_connection_ref(conn);
idev->handle = handle;
idev->disable_sdp = disable_sdp;
@@ -740,7 +739,8 @@ static struct input_device *input_device_new(DBusConnection *conn,
if (read_device_name(src_addr, dst_addr, dst_type, name) == 0)
idev->name = g_strdup(name);
- if (g_dbus_register_interface(conn, idev->path, INPUT_DEVICE_INTERFACE,
+ if (g_dbus_register_interface(btd_get_dbus_connection(),
+ idev->path, INPUT_DEVICE_INTERFACE,
device_methods, device_signals, NULL,
idev, device_unregister) == FALSE) {
error("Failed to register interface %s on path %s",
@@ -764,7 +764,7 @@ static gboolean is_device_sdp_disable(const sdp_record_t *rec)
return data && data->val.uint8;
}
-int input_device_register(DBusConnection *conn, struct btd_device *device,
+int input_device_register(struct btd_device *device,
const char *path, const char *uuid,
const sdp_record_t *rec, int timeout)
{
@@ -774,7 +774,7 @@ int input_device_register(DBusConnection *conn, struct btd_device *device,
if (idev)
return -EEXIST;
- idev = input_device_new(conn, device, path, rec->handle,
+ idev = input_device_new(device, path, rec->handle,
is_device_sdp_disable(rec));
if (!idev)
return -EINVAL;
@@ -815,7 +815,8 @@ int input_device_unregister(const char *path, const char *uuid)
return -EBUSY;
}
- g_dbus_unregister_interface(idev->conn, path, INPUT_DEVICE_INTERFACE);
+ g_dbus_unregister_interface(btd_get_dbus_connection(),
+ path, INPUT_DEVICE_INTERFACE);
return 0;
}
diff --git a/profiles/input/device.h b/profiles/input/device.h
index 0632570..b26d617 100644
--- a/profiles/input/device.h
+++ b/profiles/input/device.h
@@ -27,9 +27,9 @@
struct input_device;
struct input_conn;
-int input_device_register(DBusConnection *conn, struct btd_device *device,
- const char *path, const char *uuid,
- const sdp_record_t *rec, int timeout);
+int input_device_register(struct btd_device *device, const char *path,
+ const char *uuid, const sdp_record_t *rec,
+ int timeout);
int input_device_unregister(const char *path, const char *uuid);
int input_device_set_channel(const bdaddr_t *src, const bdaddr_t *dst, int psm,
diff --git a/profiles/input/main.c b/profiles/input/main.c
index 05469a1..4ddc511 100644
--- a/profiles/input/main.c
+++ b/profiles/input/main.c
@@ -53,22 +53,14 @@ static GKeyFile *load_config_file(const char *file)
return keyfile;
}
-static DBusConnection *connection;
-
static int input_init(void)
{
GKeyFile *config;
- connection = dbus_bus_get(DBUS_BUS_SYSTEM, NULL);
- if (connection == NULL)
- return -EIO;
-
config = load_config_file(CONFIGDIR "/input.conf");
- if (input_manager_init(connection, config) < 0) {
- dbus_connection_unref(connection);
+ if (input_manager_init(config) < 0)
return -EIO;
- }
if (config)
g_key_file_free(config);
@@ -79,8 +71,6 @@ static int input_init(void)
static void input_exit(void)
{
input_manager_exit();
-
- dbus_connection_unref(connection);
}
BLUETOOTH_PLUGIN_DEFINE(input, VERSION, BLUETOOTH_PLUGIN_PRIORITY_DEFAULT,
diff --git a/profiles/input/manager.c b/profiles/input/manager.c
index 13096c7..c899b4e 100644
--- a/profiles/input/manager.c
+++ b/profiles/input/manager.c
@@ -45,7 +45,6 @@
static int idle_timeout = 0;
-static DBusConnection *connection = NULL;
static GSList *adapters = NULL;
static void input_remove(struct btd_device *device, const char *uuid)
@@ -67,7 +66,7 @@ static int hid_device_probe(struct btd_device *device, GSList *uuids)
if (!rec)
return -1;
- return input_device_register(connection, device, path, HID_UUID, rec,
+ return input_device_register(device, path, HID_UUID, rec,
idle_timeout * 60);
}
@@ -115,7 +114,7 @@ static struct btd_profile input_profile = {
.adapter_remove = hid_server_remove,
};
-int input_manager_init(DBusConnection *conn, GKeyFile *config)
+int input_manager_init(GKeyFile *config)
{
GError *err = NULL;
@@ -128,8 +127,6 @@ int input_manager_init(DBusConnection *conn, GKeyFile *config)
}
}
- connection = dbus_connection_ref(conn);
-
btd_profile_register(&input_profile);
return 0;
@@ -138,7 +135,4 @@ int input_manager_init(DBusConnection *conn, GKeyFile *config)
void input_manager_exit(void)
{
btd_profile_unregister(&input_profile);
-
- dbus_connection_unref(connection);
- connection = NULL;
}
diff --git a/profiles/input/manager.h b/profiles/input/manager.h
index 7b93c5b..3f73253 100644
--- a/profiles/input/manager.h
+++ b/profiles/input/manager.h
@@ -21,5 +21,5 @@
*
*/
-int input_manager_init(DBusConnection *conn, GKeyFile *config);
+int input_manager_init(GKeyFile *config);
void input_manager_exit(void);
--
1.7.11.3
This patch removes redundant references and function parameters for
DBusConnection object and uses btd_get_dbus_connection() call wherever
such object is needed instead.
Pointer returned by this call is guaranteed to be valid for entire
bluetoothd lifetime and thus do not need to be refcounted.
---
profiles/health/hdp.c | 167 ++++++++++++++++++++----------------------
profiles/health/hdp.h | 6 +-
profiles/health/hdp_main.c | 16 +---
profiles/health/hdp_manager.c | 15 +---
profiles/health/hdp_manager.h | 2 +-
profiles/health/hdp_types.h | 2 -
profiles/health/hdp_util.c | 6 +-
7 files changed, 91 insertions(+), 123 deletions(-)
diff --git a/profiles/health/hdp.c b/profiles/health/hdp.c
index 489e1eb..d262a2a 100644
--- a/profiles/health/hdp.c
+++ b/profiles/health/hdp.c
@@ -46,8 +46,6 @@
#define ECHO_TIMEOUT 1 /* second */
#define HDP_ECHO_LEN 15
-static DBusConnection *connection = NULL;
-
static GSList *applications = NULL;
static GSList *devices = NULL;
static uint8_t next_app_id = HDP_MDEP_INITIAL;
@@ -55,12 +53,10 @@ static uint8_t next_app_id = HDP_MDEP_INITIAL;
static GSList *adapters;
static gboolean update_adapter(struct hdp_adapter *adapter);
-static struct hdp_device *create_health_device(DBusConnection *conn,
- struct btd_device *device);
+static struct hdp_device *create_health_device(struct btd_device *device);
static void free_echo_data(struct hdp_echo_data *edata);
struct hdp_create_dc {
- DBusConnection *conn;
DBusMessage *msg;
struct hdp_application *app;
struct hdp_device *dev;
@@ -71,7 +67,6 @@ struct hdp_create_dc {
};
struct hdp_tmp_dc_data {
- DBusConnection *conn;
DBusMessage *msg;
struct hdp_channel *hdp_chann;
guint ref;
@@ -126,7 +121,6 @@ static void hdp_channel_unref(struct hdp_channel *chan)
static void free_hdp_create_dc(struct hdp_create_dc *dc_data)
{
dbus_message_unref(dc_data->msg);
- dbus_connection_unref(dc_data->conn);
hdp_application_unref(dc_data->app);
health_device_unref(dc_data->dev);
@@ -157,7 +151,6 @@ static void hdp_create_data_unref(struct hdp_create_dc *dc_data)
static void free_hdp_conn_dc(struct hdp_tmp_dc_data *data)
{
dbus_message_unref(data->msg);
- dbus_connection_unref(data->conn);
hdp_channel_unref(data->hdp_chann);
g_free(data);
@@ -305,11 +298,6 @@ static void device_unref_mcl(struct hdp_device *hdp_device)
static void free_health_device(struct hdp_device *device)
{
- if (device->conn != NULL) {
- dbus_connection_unref(device->conn);
- device->conn = NULL;
- }
-
if (device->dev != NULL) {
btd_device_unref(device->dev);
device->dev = NULL;
@@ -370,12 +358,12 @@ static DBusMessage *manager_create_application(DBusConnection *conn,
}
app->oname = g_strdup(name);
- app->conn = dbus_connection_ref(conn);
applications = g_slist_prepend(applications, app);
- app->dbus_watcher = g_dbus_add_disconnect_watch(conn, name,
- client_disconnected, app, NULL);
+ app->dbus_watcher =
+ g_dbus_add_disconnect_watch(btd_get_dbus_connection(),
+ name, client_disconnected, app, NULL);
g_slist_foreach(adapters, (GFunc) update_adapter, NULL);
DBG("Health application created with id %s", app->path);
@@ -487,6 +475,7 @@ static void abort_mdl_cb(GError *err, gpointer data)
static void hdp_mdl_reconn_cb(struct mcap_mdl *mdl, GError *err, gpointer data)
{
+ DBusConnection *conn = btd_get_dbus_connection();
struct hdp_tmp_dc_data *dc_data = data;
DBusMessage *reply;
int fd;
@@ -499,7 +488,7 @@ static void hdp_mdl_reconn_cb(struct mcap_mdl *mdl, GError *err, gpointer data)
reply = g_dbus_create_error(dc_data->msg,
ERROR_INTERFACE ".HealthError",
"Cannot reconnect: %s", err->message);
- g_dbus_send_message(dc_data->conn, reply);
+ g_dbus_send_message(conn, reply);
/* Send abort request because remote side */
/* is now in PENDING state */
@@ -516,16 +505,15 @@ static void hdp_mdl_reconn_cb(struct mcap_mdl *mdl, GError *err, gpointer data)
reply = g_dbus_create_error(dc_data->msg,
ERROR_INTERFACE ".HealthError",
"Cannot get file descriptor");
- g_dbus_send_message(dc_data->conn, reply);
+ g_dbus_send_message(conn, reply);
return;
}
reply = g_dbus_create_reply(dc_data->msg, DBUS_TYPE_UNIX_FD,
&fd, DBUS_TYPE_INVALID);
- g_dbus_send_message(dc_data->conn, reply);
+ g_dbus_send_message(conn, reply);
- g_dbus_emit_signal(dc_data->conn,
- device_get_path(dc_data->hdp_chann->dev->dev),
+ g_dbus_emit_signal(conn, device_get_path(dc_data->hdp_chann->dev->dev),
HEALTH_DEVICE, "ChannelConnected",
DBUS_TYPE_OBJECT_PATH, &dc_data->hdp_chann->path,
DBUS_TYPE_INVALID);
@@ -561,6 +549,7 @@ static void hdp_get_dcpsm_cb(uint16_t dcpsm, gpointer user_data, GError *err)
static void device_reconnect_mdl_cb(struct mcap_mdl *mdl, GError *err,
gpointer data)
{
+ DBusConnection *conn = btd_get_dbus_connection();
struct hdp_tmp_dc_data *dc_data = data;
GError *gerr = NULL;
DBusMessage *reply;
@@ -569,7 +558,7 @@ static void device_reconnect_mdl_cb(struct mcap_mdl *mdl, GError *err,
reply = g_dbus_create_error(dc_data->msg,
ERROR_INTERFACE ".HealthError",
"Cannot reconnect: %s", err->message);
- g_dbus_send_message(dc_data->conn, reply);
+ g_dbus_send_message(conn, reply);
return;
}
@@ -585,7 +574,7 @@ static void device_reconnect_mdl_cb(struct mcap_mdl *mdl, GError *err,
reply = g_dbus_create_error(dc_data->msg,
ERROR_INTERFACE ".HealthError",
"Cannot reconnect: %s", gerr->message);
- g_dbus_send_message(dc_data->conn, reply);
+ g_dbus_send_message(conn, reply);
hdp_tmp_dc_data_unref(dc_data);
g_error_free(gerr);
@@ -629,13 +618,12 @@ static DBusMessage *channel_acquire_continue(struct hdp_tmp_dc_data *data,
static void channel_acquire_cb(gpointer data, GError *err)
{
- struct hdp_tmp_dc_data *dc_data = data;
DBusMessage *reply;
reply = channel_acquire_continue(data, err);
if (reply != NULL)
- g_dbus_send_message(dc_data->conn, reply);
+ g_dbus_send_message(btd_get_dbus_connection(), reply);
}
static DBusMessage *channel_acquire(DBusConnection *conn,
@@ -647,7 +635,6 @@ static DBusMessage *channel_acquire(DBusConnection *conn,
DBusMessage *reply;
dc_data = g_new0(struct hdp_tmp_dc_data, 1);
- dc_data->conn = dbus_connection_ref(conn);
dc_data->msg = dbus_message_ref(msg);
dc_data->hdp_chann = hdp_channel_ref(chan);
@@ -719,7 +706,8 @@ static void health_channel_destroy(void *data)
dev->channels = g_slist_remove(dev->channels, hdp_chan);
if (hdp_chan->mdep != HDP_MDEP_ECHO)
- g_dbus_emit_signal(dev->conn, device_get_path(dev->dev),
+ g_dbus_emit_signal(btd_get_dbus_connection(),
+ device_get_path(dev->dev),
HEALTH_DEVICE, "ChannelDeleted",
DBUS_TYPE_OBJECT_PATH, &hdp_chan->path,
DBUS_TYPE_INVALID);
@@ -780,8 +768,8 @@ static struct hdp_channel *create_channel(struct hdp_device *dev,
if (hdp_chann->mdep == HDP_MDEP_ECHO)
return hdp_channel_ref(hdp_chann);
- if (!g_dbus_register_interface(dev->conn, hdp_chann->path,
- HEALTH_CHANNEL,
+ if (!g_dbus_register_interface(btd_get_dbus_connection(),
+ hdp_chann->path, HEALTH_CHANNEL,
health_channels_methods, NULL, NULL,
hdp_chann, health_channel_destroy)) {
g_set_error(err, HDP_ERROR, HDP_UNSPECIFIED_ERROR,
@@ -802,8 +790,8 @@ static void remove_channels(struct hdp_device *dev)
chan = dev->channels->data;
path = g_strdup(chan->path);
- if (!g_dbus_unregister_interface(dev->conn, path,
- HEALTH_CHANNEL))
+ if (!g_dbus_unregister_interface(btd_get_dbus_connection(),
+ path, HEALTH_CHANNEL))
health_channel_destroy(chan);
g_free(path);
}
@@ -827,7 +815,8 @@ static void close_device_con(struct hdp_device *dev, gboolean cache)
const char *path;
path = device_get_path(dev->dev);
- g_dbus_unregister_interface(dev->conn, path, HEALTH_DEVICE);
+ g_dbus_unregister_interface(btd_get_dbus_connection(),
+ path, HEALTH_DEVICE);
}
}
@@ -967,10 +956,10 @@ static void hdp_mcap_mdl_connected_cb(struct mcap_mdl *mdl, void *data)
goto end;
}
- g_dbus_emit_signal(dev->conn, device_get_path(dev->dev), HEALTH_DEVICE,
- "ChannelConnected",
- DBUS_TYPE_OBJECT_PATH, &chan->path,
- DBUS_TYPE_INVALID);
+ g_dbus_emit_signal(btd_get_dbus_connection(), device_get_path(dev->dev),
+ HEALTH_DEVICE, "ChannelConnected",
+ DBUS_TYPE_OBJECT_PATH, &chan->path,
+ DBUS_TYPE_INVALID);
if (dev->fr != NULL)
goto end;
@@ -1010,7 +999,8 @@ static void hdp_mcap_mdl_deleted_cb(struct mcap_mdl *mdl, void *data)
chan = l->data;
path = g_strdup(chan->path);
- if (!g_dbus_unregister_interface(dev->conn, path, HEALTH_CHANNEL))
+ if (!g_dbus_unregister_interface(btd_get_dbus_connection(),
+ path, HEALTH_CHANNEL))
health_channel_destroy(chan);
g_free(path);
}
@@ -1030,7 +1020,8 @@ static void hdp_mcap_mdl_aborted_cb(struct mcap_mdl *mdl, void *data)
hdp_channel_ref(dev->ndc));
if (dev->ndc->mdep != HDP_MDEP_ECHO)
- g_dbus_emit_signal(dev->conn, device_get_path(dev->dev),
+ g_dbus_emit_signal(btd_get_dbus_connection(),
+ device_get_path(dev->dev),
HEALTH_DEVICE, "ChannelConnected",
DBUS_TYPE_OBJECT_PATH, &dev->ndc->path,
DBUS_TYPE_INVALID);
@@ -1123,7 +1114,8 @@ static uint8_t hdp_mcap_mdl_conn_req_cb(struct mcap_mcl *mcl, uint8_t mdepid,
char *path;
path = g_strdup(chan->path);
- g_dbus_unregister_interface(dev->conn, path, HEALTH_CHANNEL);
+ g_dbus_unregister_interface(btd_get_dbus_connection(),
+ path, HEALTH_CHANNEL);
g_free(path);
}
@@ -1212,7 +1204,7 @@ static void mcl_connected(struct mcap_mcl *mcl, gpointer data)
device = adapter_get_device(hdp_adapter->btd_adapter, str);
if (!device)
return;
- hdp_device = create_health_device(connection, device);
+ hdp_device = create_health_device(device);
if (!hdp_device)
return;
devices = g_slist_append(devices, hdp_device);
@@ -1280,7 +1272,8 @@ static void mcl_uncached(struct mcap_mcl *mcl, gpointer data)
/* be removed. Then we have to remove the HealthDevice */
/* interface manually */
path = device_get_path(hdp_device->dev);
- g_dbus_unregister_interface(hdp_device->conn, path, HEALTH_DEVICE);
+ g_dbus_unregister_interface(btd_get_dbus_connection(),
+ path, HEALTH_DEVICE);
DBG("Mcl uncached %s", path);
}
@@ -1303,7 +1296,8 @@ static void check_devices_mcl(void)
const char *path;
path = device_get_path(dev->dev);
- g_dbus_unregister_interface(dev->conn, path, HEALTH_DEVICE);
+ g_dbus_unregister_interface(btd_get_dbus_connection(),
+ path, HEALTH_DEVICE);
}
g_slist_free(to_delete);
@@ -1371,7 +1365,7 @@ fail:
return FALSE;
}
-int hdp_adapter_register(DBusConnection *conn, struct btd_adapter *adapter)
+int hdp_adapter_register(struct btd_adapter *adapter)
{
struct hdp_adapter *hdp_adapter;
@@ -1511,7 +1505,7 @@ static gboolean check_echo(GIOChannel *io_chan, GIOCondition cond,
end:
reply = g_dbus_create_reply(hdp_conn->msg, DBUS_TYPE_BOOLEAN, &value,
DBUS_TYPE_INVALID);
- g_dbus_send_message(hdp_conn->conn, reply);
+ g_dbus_send_message(btd_get_dbus_connection(), reply);
g_source_remove(edata->tid);
edata->tid = 0;
g_free(edata->buf);
@@ -1548,6 +1542,7 @@ static gboolean echo_timeout(gpointer data)
static void hdp_echo_connect_cb(struct mcap_mdl *mdl, GError *err,
gpointer data)
{
+ DBusConnection *conn = btd_get_dbus_connection();
struct hdp_tmp_dc_data *hdp_conn = data;
struct hdp_echo_data *edata;
GError *gerr = NULL;
@@ -1559,7 +1554,7 @@ static void hdp_echo_connect_cb(struct mcap_mdl *mdl, GError *err,
reply = g_dbus_create_error(hdp_conn->msg,
ERROR_INTERFACE ".HealthError",
"%s", err->message);
- g_dbus_send_message(hdp_conn->conn, reply);
+ g_dbus_send_message(conn, reply);
/* Send abort request because remote */
/* side is now in PENDING state. */
@@ -1580,7 +1575,7 @@ static void hdp_echo_connect_cb(struct mcap_mdl *mdl, GError *err,
reply = g_dbus_create_error(hdp_conn->msg,
ERROR_INTERFACE ".HealthError",
"Can't write in echo channel");
- g_dbus_send_message(hdp_conn->conn, reply);
+ g_dbus_send_message(conn, reply);
delete_echo_channel(hdp_conn->hdp_chann);
return;
}
@@ -1638,16 +1633,16 @@ static void abort_mdl_connection_cb(GError *err, gpointer data)
/* Connection operation has failed but we have to */
/* notify the channel created at MCAP level */
if (hdp_chann->mdep != HDP_MDEP_ECHO)
- g_dbus_emit_signal(hdp_conn->conn,
+ g_dbus_emit_signal(btd_get_dbus_connection(),
device_get_path(hdp_chann->dev->dev),
- HEALTH_DEVICE,
- "ChannelConnected",
+ HEALTH_DEVICE, "ChannelConnected",
DBUS_TYPE_OBJECT_PATH, &hdp_chann->path,
DBUS_TYPE_INVALID);
}
static void hdp_mdl_conn_cb(struct mcap_mdl *mdl, GError *err, gpointer data)
{
+ DBusConnection *conn = btd_get_dbus_connection();
struct hdp_tmp_dc_data *hdp_conn = data;
struct hdp_channel *hdp_chann = hdp_conn->hdp_chann;
struct hdp_device *dev = hdp_chann->dev;
@@ -1659,7 +1654,7 @@ static void hdp_mdl_conn_cb(struct mcap_mdl *mdl, GError *err, gpointer data)
reply = g_dbus_create_reply(hdp_conn->msg,
DBUS_TYPE_OBJECT_PATH, &hdp_chann->path,
DBUS_TYPE_INVALID);
- g_dbus_send_message(hdp_conn->conn, reply);
+ g_dbus_send_message(conn, reply);
/* Send abort request because remote side */
/* is now in PENDING state */
@@ -1676,14 +1671,12 @@ static void hdp_mdl_conn_cb(struct mcap_mdl *mdl, GError *err, gpointer data)
reply = g_dbus_create_reply(hdp_conn->msg,
DBUS_TYPE_OBJECT_PATH, &hdp_chann->path,
DBUS_TYPE_INVALID);
- g_dbus_send_message(hdp_conn->conn, reply);
+ g_dbus_send_message(conn, reply);
- g_dbus_emit_signal(hdp_conn->conn,
- device_get_path(hdp_chann->dev->dev),
- HEALTH_DEVICE,
- "ChannelConnected",
- DBUS_TYPE_OBJECT_PATH, &hdp_chann->path,
- DBUS_TYPE_INVALID);
+ g_dbus_emit_signal(conn, device_get_path(hdp_chann->dev->dev),
+ HEALTH_DEVICE, "ChannelConnected",
+ DBUS_TYPE_OBJECT_PATH, &hdp_chann->path,
+ DBUS_TYPE_INVALID);
if (!check_channel_conf(hdp_chann)) {
close_mdl(hdp_chann);
@@ -1703,6 +1696,7 @@ static void hdp_mdl_conn_cb(struct mcap_mdl *mdl, GError *err, gpointer data)
static void device_create_mdl_cb(struct mcap_mdl *mdl, uint8_t conf,
GError *err, gpointer data)
{
+ DBusConnection *conn = btd_get_dbus_connection();
struct hdp_create_dc *user_data = data;
struct hdp_tmp_dc_data *hdp_conn;
struct hdp_channel *hdp_chan;
@@ -1713,7 +1707,7 @@ static void device_create_mdl_cb(struct mcap_mdl *mdl, uint8_t conf,
reply = g_dbus_create_error(user_data->msg,
ERROR_INTERFACE ".HealthError",
"%s", err->message);
- g_dbus_send_message(user_data->conn, reply);
+ g_dbus_send_message(conn, reply);
return;
}
@@ -1741,7 +1735,6 @@ static void device_create_mdl_cb(struct mcap_mdl *mdl, uint8_t conf,
hdp_conn = g_new0(struct hdp_tmp_dc_data, 1);
hdp_conn->msg = dbus_message_ref(user_data->msg);
- hdp_conn->conn = dbus_connection_ref(user_data->conn);
hdp_conn->hdp_chann = hdp_chan;
hdp_conn->cb = user_data->cb;
hdp_chan->mdep = user_data->mdep;
@@ -1757,7 +1750,7 @@ static void device_create_mdl_cb(struct mcap_mdl *mdl, uint8_t conf,
reply = g_dbus_create_reply(hdp_conn->msg,
DBUS_TYPE_OBJECT_PATH, &hdp_chan->path,
DBUS_TYPE_INVALID);
- g_dbus_send_message(hdp_conn->conn, reply);
+ g_dbus_send_message(conn, reply);
hdp_tmp_dc_data_unref(hdp_conn);
/* Send abort request because remote side is now in PENDING state */
@@ -1775,7 +1768,7 @@ fail:
reply = g_dbus_create_error(user_data->msg,
ERROR_INTERFACE ".HealthError",
"%s", gerr->message);
- g_dbus_send_message(user_data->conn, reply);
+ g_dbus_send_message(conn, reply);
g_error_free(gerr);
/* Send abort request because remote side is now in PENDING */
@@ -1791,6 +1784,7 @@ fail:
static void device_create_dc_cb(gpointer user_data, GError *err)
{
+ DBusConnection *conn = btd_get_dbus_connection();
struct hdp_create_dc *data = user_data;
DBusMessage *reply;
GError *gerr = NULL;
@@ -1799,7 +1793,7 @@ static void device_create_dc_cb(gpointer user_data, GError *err)
reply = g_dbus_create_error(data->msg,
ERROR_INTERFACE ".HealthError",
"%s", err->message);
- g_dbus_send_message(data->conn, reply);
+ g_dbus_send_message(conn, reply);
return;
}
@@ -1821,7 +1815,7 @@ fail:
reply = g_dbus_create_error(data->msg, ERROR_INTERFACE ".HealthError",
"%s", gerr->message);
g_error_free(gerr);
- g_dbus_send_message(data->conn, reply);
+ g_dbus_send_message(conn, reply);
}
static DBusMessage *device_echo(DBusConnection *conn,
@@ -1837,7 +1831,6 @@ static DBusMessage *device_echo(DBusConnection *conn,
data->mdep = HDP_MDEP_ECHO;
data->config = HDP_RELIABLE_DC;
data->msg = dbus_message_ref(msg);
- data->conn = dbus_connection_ref(conn);
data->cb = hdp_echo_connect_cb;
hdp_create_data_ref(data);
@@ -1863,6 +1856,7 @@ fail:
static void device_get_mdep_cb(uint8_t mdep, gpointer data, GError *err)
{
+ DBusConnection *conn = btd_get_dbus_connection();
struct hdp_create_dc *dc_data, *user_data = data;
DBusMessage *reply;
GError *gerr = NULL;
@@ -1871,7 +1865,7 @@ static void device_get_mdep_cb(uint8_t mdep, gpointer data, GError *err)
reply = g_dbus_create_error(user_data->msg,
ERROR_INTERFACE ".HealthError",
"%s", err->message);
- g_dbus_send_message(user_data->conn, reply);
+ g_dbus_send_message(conn, reply);
return;
}
@@ -1893,7 +1887,7 @@ static void device_get_mdep_cb(uint8_t mdep, gpointer data, GError *err)
"%s", gerr->message);
hdp_create_data_unref(dc_data);
g_error_free(gerr);
- g_dbus_send_message(user_data->conn, reply);
+ g_dbus_send_message(conn, reply);
}
static DBusMessage *device_create_channel(DBusConnection *conn,
@@ -1942,7 +1936,6 @@ static DBusMessage *device_create_channel(DBusConnection *conn,
data->config = config;
data->app = hdp_application_ref(app);
data->msg = dbus_message_ref(msg);
- data->conn = dbus_connection_ref(conn);
data->cb = hdp_mdl_conn_cb;
if (hdp_get_mdep(device, l->data, device_get_mdep_cb,
@@ -1959,6 +1952,7 @@ static DBusMessage *device_create_channel(DBusConnection *conn,
static void hdp_mdl_delete_cb(GError *err, gpointer data)
{
+ DBusConnection *conn = btd_get_dbus_connection();
struct hdp_tmp_dc_data *del_data = data;
DBusMessage *reply;
char *path;
@@ -1967,20 +1961,21 @@ static void hdp_mdl_delete_cb(GError *err, gpointer data)
reply = g_dbus_create_error(del_data->msg,
ERROR_INTERFACE ".HealthError",
"%s", err->message);
- g_dbus_send_message(del_data->conn, reply);
+ g_dbus_send_message(conn, reply);
return;
}
path = g_strdup(del_data->hdp_chann->path);
- g_dbus_unregister_interface(del_data->conn, path, HEALTH_CHANNEL);
+ g_dbus_unregister_interface(conn, path, HEALTH_CHANNEL);
g_free(path);
reply = g_dbus_create_reply(del_data->msg, DBUS_TYPE_INVALID);
- g_dbus_send_message(del_data->conn, reply);
+ g_dbus_send_message(conn, reply);
}
static void hdp_continue_del_cb(gpointer user_data, GError *err)
{
+ DBusConnection *conn = btd_get_dbus_connection();
struct hdp_tmp_dc_data *del_data = user_data;
GError *gerr = NULL;
DBusMessage *reply;
@@ -1989,7 +1984,7 @@ static void hdp_continue_del_cb(gpointer user_data, GError *err)
reply = g_dbus_create_error(del_data->msg,
ERROR_INTERFACE ".HealthError",
"%s", err->message);
- g_dbus_send_message(del_data->conn, reply);
+ g_dbus_send_message(conn, reply);
return;
}
@@ -2003,7 +1998,7 @@ static void hdp_continue_del_cb(gpointer user_data, GError *err)
"%s", gerr->message);
hdp_tmp_dc_data_unref(del_data);
g_error_free(gerr);
- g_dbus_send_message(del_data->conn, reply);
+ g_dbus_send_message(conn, reply);
}
static DBusMessage *device_destroy_channel(DBusConnection *conn,
@@ -2029,7 +2024,6 @@ static DBusMessage *device_destroy_channel(DBusConnection *conn,
hdp_chan = l->data;
del_data = g_new0(struct hdp_tmp_dc_data, 1);
del_data->msg = dbus_message_ref(msg);
- del_data->conn = dbus_connection_ref(conn);
del_data->hdp_chann = hdp_channel_ref(hdp_chan);
if (device->mcl_conn) {
@@ -2124,8 +2118,7 @@ static const GDBusSignalTable health_device_signals[] = {
{ }
};
-static struct hdp_device *create_health_device(DBusConnection *conn,
- struct btd_device *device)
+static struct hdp_device *create_health_device(struct btd_device *device)
{
struct btd_adapter *adapter = device_get_adapter(device);
const gchar *path = device_get_path(device);
@@ -2136,7 +2129,6 @@ static struct hdp_device *create_health_device(DBusConnection *conn,
return NULL;
dev = g_new0(struct hdp_device, 1);
- dev->conn = dbus_connection_ref(conn);
dev->dev = btd_device_ref(device);
health_device_ref(dev);
@@ -2146,8 +2138,8 @@ static struct hdp_device *create_health_device(DBusConnection *conn,
dev->hdp_adapter = l->data;
- if (!g_dbus_register_interface(conn, path,
- HEALTH_DEVICE,
+ if (!g_dbus_register_interface(btd_get_dbus_connection(),
+ path, HEALTH_DEVICE,
health_device_methods,
health_device_signals, NULL,
dev, health_device_destroy)) {
@@ -2163,7 +2155,7 @@ fail:
return NULL;
}
-int hdp_device_register(DBusConnection *conn, struct btd_device *device)
+int hdp_device_register(struct btd_device *device)
{
struct hdp_device *hdev;
GSList *l;
@@ -2175,7 +2167,7 @@ int hdp_device_register(DBusConnection *conn, struct btd_device *device)
return 0;
}
- hdev = create_health_device(conn, device);
+ hdev = create_health_device(device);
if (hdev == NULL)
return -1;
@@ -2197,31 +2189,30 @@ void hdp_device_unregister(struct btd_device *device)
hdp_dev = l->data;
path = device_get_path(hdp_dev->dev);
- g_dbus_unregister_interface(hdp_dev->conn, path, HEALTH_DEVICE);
+ g_dbus_unregister_interface(btd_get_dbus_connection(),
+ path, HEALTH_DEVICE);
}
-int hdp_manager_start(DBusConnection *conn)
+int hdp_manager_start(void)
{
DBG("Starting Health manager");
- if (!g_dbus_register_interface(conn, MANAGER_PATH,
- HEALTH_MANAGER,
+ if (!g_dbus_register_interface(btd_get_dbus_connection(),
+ MANAGER_PATH, HEALTH_MANAGER,
health_manager_methods, NULL, NULL,
NULL, manager_path_unregister)) {
error("D-Bus failed to register %s interface", HEALTH_MANAGER);
return -1;
}
- connection = dbus_connection_ref(conn);
-
return 0;
}
void hdp_manager_stop(void)
{
- g_dbus_unregister_interface(connection, MANAGER_PATH, HEALTH_MANAGER);
+ g_dbus_unregister_interface(btd_get_dbus_connection(),
+ MANAGER_PATH, HEALTH_MANAGER);
- dbus_connection_unref(connection);
DBG("Stopped Health manager");
}
diff --git a/profiles/health/hdp.h b/profiles/health/hdp.h
index 39f0441..6e78b09 100644
--- a/profiles/health/hdp.h
+++ b/profiles/health/hdp.h
@@ -20,13 +20,13 @@
*
*/
-int hdp_adapter_register(DBusConnection *conn, struct btd_adapter *btd_adapter);
+int hdp_adapter_register(struct btd_adapter *btd_adapter);
void hdp_adapter_unregister(struct btd_adapter *btd_adapter);
-int hdp_device_register(DBusConnection *conn, struct btd_device *device);
+int hdp_device_register(struct btd_device *device);
void hdp_device_unregister(struct btd_device *device);
-int hdp_manager_start(DBusConnection *conn);
+int hdp_manager_start(void);
void hdp_manager_stop(void);
gboolean hdp_set_mcl_cb(struct hdp_device *device, GError **err);
diff --git a/profiles/health/hdp_main.c b/profiles/health/hdp_main.c
index 9367e73..1d38bea 100644
--- a/profiles/health/hdp_main.c
+++ b/profiles/health/hdp_main.c
@@ -31,28 +31,14 @@
#include "plugin.h"
#include "hdp_manager.h"
-static DBusConnection *connection = NULL;
-
static int hdp_init(void)
{
- connection = dbus_bus_get(DBUS_BUS_SYSTEM, NULL);
- if (connection == NULL)
- return -EIO;
-
- if (hdp_manager_init(connection) < 0) {
- dbus_connection_unref(connection);
- return -EIO;
- }
-
- return 0;
+ return hdp_manager_init();
}
static void hdp_exit(void)
{
hdp_manager_exit();
-
- dbus_connection_unref(connection);
- connection = NULL;
}
BLUETOOTH_PLUGIN_DEFINE(health, VERSION,
diff --git a/profiles/health/hdp_manager.c b/profiles/health/hdp_manager.c
index 1f899dc..740fe3a 100644
--- a/profiles/health/hdp_manager.c
+++ b/profiles/health/hdp_manager.c
@@ -42,11 +42,9 @@
#include "hdp_manager.h"
#include "hdp.h"
-static DBusConnection *connection = NULL;
-
static int hdp_adapter_probe(struct btd_adapter *adapter)
{
- return hdp_adapter_register(connection, adapter);
+ return hdp_adapter_register(adapter);
}
static void hdp_adapter_remove(struct btd_adapter *adapter)
@@ -56,7 +54,7 @@ static void hdp_adapter_remove(struct btd_adapter *adapter)
static int hdp_driver_probe(struct btd_device *device, GSList *uuids)
{
- return hdp_device_register(connection, device);
+ return hdp_device_register(device);
}
static void hdp_driver_remove(struct btd_device *device)
@@ -75,13 +73,11 @@ static struct btd_profile hdp_profile = {
.adapter_remove = hdp_adapter_remove,
};
-int hdp_manager_init(DBusConnection *conn)
+int hdp_manager_init(void)
{
- if (hdp_manager_start(conn) < 0)
+ if (hdp_manager_start() < 0)
return -1;
- connection = dbus_connection_ref(conn);
-
btd_profile_register(&hdp_profile);
return 0;
@@ -92,7 +88,4 @@ void hdp_manager_exit(void)
btd_profile_unregister(&hdp_profile);
hdp_manager_stop();
-
- dbus_connection_unref(connection);
- connection = NULL;
}
diff --git a/profiles/health/hdp_manager.h b/profiles/health/hdp_manager.h
index d39f190..1cab4d0 100644
--- a/profiles/health/hdp_manager.h
+++ b/profiles/health/hdp_manager.h
@@ -20,5 +20,5 @@
*
*/
-int hdp_manager_init(DBusConnection *conn);
+int hdp_manager_init(void);
void hdp_manager_exit(void);
diff --git a/profiles/health/hdp_types.h b/profiles/health/hdp_types.h
index 7f8b015..7e4d00f 100644
--- a/profiles/health/hdp_types.h
+++ b/profiles/health/hdp_types.h
@@ -66,7 +66,6 @@ enum data_specs {
};
struct hdp_application {
- DBusConnection *conn; /* For dbus watcher */
char *path; /* The path of the application */
uint16_t data_type; /* Data type handled for this application */
gboolean data_type_set; /* Flag for dictionary parsing */
@@ -91,7 +90,6 @@ struct hdp_adapter {
};
struct hdp_device {
- DBusConnection *conn; /* For name listener handling */
struct btd_device *dev; /* Device reference */
struct hdp_adapter *hdp_adapter; /* hdp_adapater */
struct mcap_mcl *mcl; /* The mcap control channel */
diff --git a/profiles/health/hdp_util.c b/profiles/health/hdp_util.c
index 761e07d..3afd715 100644
--- a/profiles/health/hdp_util.c
+++ b/profiles/health/hdp_util.c
@@ -44,6 +44,7 @@
#include <log.h>
+#include "dbus-common.h"
#include "mcap.h"
#include "mcap_lib.h"
#include "hdp_types.h"
@@ -1183,10 +1184,9 @@ gboolean hdp_get_dcpsm(struct hdp_device *device, hdp_continue_dcpsm_f func,
static void hdp_free_application(struct hdp_application *app)
{
if (app->dbus_watcher > 0)
- g_dbus_remove_watch(app->conn, app->dbus_watcher);
+ g_dbus_remove_watch(btd_get_dbus_connection(),
+ app->dbus_watcher);
- if (app->conn != NULL)
- dbus_connection_unref(app->conn);
g_free(app->oname);
g_free(app->description);
g_free(app->path);
--
1.7.11.3
This patch removes redundant references and function parameters for
DBusConnection object and uses btd_get_dbus_connection() call wherever
such object is needed instead.
Pointer returned by this call is guaranteed to be valid for entire
bluetoothd lifetime and thus do not need to be refcounted.
---
attrib/client.c | 41 ++++++++++++++++++-----------------------
attrib/client.h | 3 +--
src/device.c | 4 +---
3 files changed, 20 insertions(+), 28 deletions(-)
diff --git a/attrib/client.c b/attrib/client.c
index d5d40a1..2423fad 100644
--- a/attrib/client.c
+++ b/attrib/client.c
@@ -68,7 +68,6 @@ struct query {
struct gatt_service {
struct btd_device *dev;
struct gatt_primary *prim;
- DBusConnection *conn;
GAttrib *attrib;
guint attioid;
int psm;
@@ -204,7 +203,6 @@ static void gatt_service_free(struct gatt_service *gatt)
g_slist_free(gatt->offline_chars);
g_free(gatt->path);
btd_device_unref(gatt->dev);
- dbus_connection_unref(gatt->conn);
g_free(gatt);
}
@@ -296,7 +294,7 @@ static void watcher_exit(DBusConnection *conn, void *user_data)
DBG("%s watcher %s exited", gatt->path, watcher->name);
gatt->watchers = g_slist_remove(gatt->watchers, watcher);
- g_dbus_remove_watch(gatt->conn, watcher->id);
+ g_dbus_remove_watch(btd_get_dbus_connection(), watcher->id);
remove_attio(gatt);
}
@@ -317,7 +315,6 @@ static void update_watchers(gpointer data, gpointer user_data)
{
struct watcher *w = data;
struct characteristic *chr = user_data;
- DBusConnection *conn = w->gatt->conn;
DBusMessage *msg;
msg = dbus_message_new_method_call(w->name, w->path,
@@ -330,7 +327,7 @@ static void update_watchers(gpointer data, gpointer user_data)
&chr->value, chr->vlen, DBUS_TYPE_INVALID);
dbus_message_set_no_reply(msg, TRUE);
- g_dbus_send_message(conn, msg);
+ g_dbus_send_message(btd_get_dbus_connection(), msg);
}
static void events_handler(const uint8_t *pdu, uint16_t len,
@@ -434,7 +431,7 @@ static void attio_disconnected(gpointer user_data)
reply = btd_error_failed(gatt->query->msg,
"ATT IO channel was disconnected");
- g_dbus_send_message(gatt->conn, reply);
+ g_dbus_send_message(btd_get_dbus_connection(), reply);
dbus_message_unref(gatt->query->msg);
}
@@ -465,7 +462,8 @@ static DBusMessage *register_watcher(DBusConnection *conn,
watcher->name = g_strdup(sender);
watcher->gatt = gatt;
watcher->path = g_strdup(path);
- watcher->id = g_dbus_add_disconnect_watch(conn, sender, watcher_exit,
+ watcher->id = g_dbus_add_disconnect_watch(btd_get_dbus_connection(),
+ sender, watcher_exit,
watcher, watcher_free);
if (gatt->attioid == 0)
@@ -502,13 +500,13 @@ static DBusMessage *unregister_watcher(DBusConnection *conn,
watcher = l->data;
gatt->watchers = g_slist_remove(gatt->watchers, watcher);
- g_dbus_remove_watch(conn, watcher->id);
+ g_dbus_remove_watch(btd_get_dbus_connection(), watcher->id);
remove_attio(gatt);
return dbus_message_new_method_return(msg);
}
-static DBusMessage *set_value(DBusConnection *conn, DBusMessage *msg,
+static DBusMessage *set_value(DBusMessage *msg,
DBusMessageIter *iter, struct characteristic *chr)
{
struct gatt_service *gatt = chr->gatt;
@@ -582,7 +580,7 @@ static DBusMessage *set_property(DBusConnection *conn,
dbus_message_iter_recurse(&iter, &sub);
if (g_str_equal("Value", property))
- return set_value(conn, msg, &sub, chr);
+ return set_value(msg, &sub, chr);
return btd_error_invalid_args(msg);
}
@@ -636,13 +634,13 @@ static void store_characteristics(const bdaddr_t *sba, const bdaddr_t *dba,
static void register_characteristic(gpointer data, gpointer user_data)
{
struct characteristic *chr = data;
- DBusConnection *conn = chr->gatt->conn;
const char *gatt_path = user_data;
chr->path = g_strdup_printf("%s/characteristic%04x", gatt_path,
chr->handle);
- g_dbus_register_interface(conn, chr->path, CHAR_INTERFACE,
+ g_dbus_register_interface(btd_get_dbus_connection(),
+ chr->path, CHAR_INTERFACE,
char_methods, NULL, NULL, chr, NULL);
DBG("Registered: %s", chr->path);
@@ -1022,7 +1020,7 @@ fail:
dbus_message_unref(gatt->query->msg);
gatt->query->msg = NULL;
- g_dbus_send_message(gatt->conn, reply);
+ g_dbus_send_message(btd_get_dbus_connection(), reply);
query_list_remove(gatt, current);
g_free(current);
}
@@ -1121,8 +1119,7 @@ static const GDBusMethodTable prim_methods[] = {
{ }
};
-static struct gatt_service *primary_register(DBusConnection *conn,
- struct btd_device *device,
+static struct gatt_service *primary_register(struct btd_device *device,
struct gatt_primary *prim,
int psm)
{
@@ -1135,11 +1132,10 @@ static struct gatt_service *primary_register(DBusConnection *conn,
gatt->dev = btd_device_ref(device);
gatt->prim = prim;
gatt->psm = psm;
- gatt->conn = dbus_connection_ref(conn);
gatt->path = g_strdup_printf("%s/service%04x", device_path,
prim->range.start);
- g_dbus_register_interface(gatt->conn, gatt->path,
+ g_dbus_register_interface(btd_get_dbus_connection(), gatt->path,
CHAR_INTERFACE, prim_methods,
NULL, NULL, gatt, NULL);
gatt->chars = load_characteristics(gatt, prim->range.start);
@@ -1148,8 +1144,7 @@ static struct gatt_service *primary_register(DBusConnection *conn,
return gatt;
}
-GSList *attrib_client_register(DBusConnection *connection,
- struct btd_device *device, int psm,
+GSList *attrib_client_register(struct btd_device *device, int psm,
GAttrib *attrib, GSList *primaries)
{
GSList *l, *services;
@@ -1158,7 +1153,7 @@ GSList *attrib_client_register(DBusConnection *connection,
struct gatt_primary *prim = l->data;
struct gatt_service *gatt;
- gatt = primary_register(connection, device, prim, psm);
+ gatt = primary_register(device, prim, psm);
DBG("Registered: %s", gatt->path);
@@ -1172,15 +1167,15 @@ GSList *attrib_client_register(DBusConnection *connection,
static void primary_unregister(struct gatt_service *gatt)
{
+ DBusConnection *conn = btd_get_dbus_connection();
GSList *l;
for (l = gatt->chars; l; l = l->next) {
struct characteristic *chr = l->data;
- g_dbus_unregister_interface(gatt->conn, chr->path,
- CHAR_INTERFACE);
+ g_dbus_unregister_interface(conn, chr->path, CHAR_INTERFACE);
}
- g_dbus_unregister_interface(gatt->conn, gatt->path, CHAR_INTERFACE);
+ g_dbus_unregister_interface(conn, gatt->path, CHAR_INTERFACE);
remove_attio(gatt);
}
diff --git a/attrib/client.h b/attrib/client.h
index 948f030..89f4f24 100644
--- a/attrib/client.h
+++ b/attrib/client.h
@@ -22,7 +22,6 @@
*
*/
-GSList *attrib_client_register(DBusConnection *connection,
- struct btd_device *device, int psm,
+GSList *attrib_client_register(struct btd_device *device, int psm,
GAttrib *attrib, GSList *primaries);
void attrib_client_unregister(GSList *services);
diff --git a/src/device.c b/src/device.c
index 1b2c741..a6e10a5 100644
--- a/src/device.c
+++ b/src/device.c
@@ -2949,9 +2949,7 @@ void device_register_services(struct btd_device *device,
GSList *prim_list, int psm)
{
device->primaries = g_slist_concat(device->primaries, prim_list);
- device->services = attrib_client_register(btd_get_dbus_connection(),
- device, psm, NULL,
- prim_list);
+ device->services = attrib_client_register(device, psm, NULL, prim_list);
}
GSList *btd_device_get_primaries(struct btd_device *device)
--
1.7.11.3
This patch removes redundant references and function parameters for
DBusConnection object and uses btd_get_dbus_connection() call wherever
such object is needed instead.
Pointer returned by this call is guaranteed to be valid for entire
bluetoothd lifetime and thus do not need to be refcounted.
---
src/adapter.c | 26 +++++-----
src/device.c | 149 +++++++++++++++++++++++++---------------------------------
src/device.h | 29 +++++-------
src/event.c | 8 +---
4 files changed, 93 insertions(+), 119 deletions(-)
diff --git a/src/adapter.c b/src/adapter.c
index fb6a2e5..33ac246 100644
--- a/src/adapter.c
+++ b/src/adapter.c
@@ -940,7 +940,7 @@ static struct btd_device *adapter_create_device(DBusConnection *conn,
DBG("%s", address);
- device = device_create(conn, adapter, address, bdaddr_type);
+ device = device_create(adapter, address, bdaddr_type);
if (!device)
return NULL;
@@ -1396,9 +1396,9 @@ static DBusMessage *create_device(DBusConnection *conn,
goto failed;
if (device_is_bredr(device))
- err = device_browse_sdp(device, conn, msg, NULL, FALSE);
+ err = device_browse_sdp(device, msg, NULL, FALSE);
else
- err = device_browse_primary(device, conn, msg, FALSE);
+ err = device_browse_primary(device, msg, FALSE);
if (err < 0) {
adapter_remove_device(conn, adapter, device, TRUE);
@@ -1479,7 +1479,7 @@ static DBusMessage *create_paired_device(DBusConnection *conn,
return btd_error_failed(msg, strerror(-err));
}
- return device_create_bonding(device, conn, msg, agent_path, cap);
+ return device_create_bonding(device, msg, agent_path, cap);
}
static gint device_path_cmp(struct btd_device *device, const gchar *path)
@@ -1692,7 +1692,7 @@ static void create_stored_device_from_profiles(char *key, char *value,
address, (GCompareFunc) device_address_cmp))
return;
- device = device_create(connection, adapter, address, bdaddr_type);
+ device = device_create(adapter, address, bdaddr_type);
if (!device)
return;
@@ -1701,7 +1701,7 @@ static void create_stored_device_from_profiles(char *key, char *value,
list = device_services_from_record(device, uuids);
if (list)
- device_register_services(connection, device, list, ATT_PSM);
+ device_register_services(device, list, ATT_PSM);
device_probe_profiles(device, uuids);
@@ -1816,7 +1816,7 @@ static void create_stored_device_from_linkkeys(char *key, char *value,
(GCompareFunc) device_address_cmp))
return;
- device = device_create(connection, adapter, address, bdaddr_type);
+ device = device_create(adapter, address, bdaddr_type);
if (device) {
device_set_temporary(device, FALSE);
adapter->devices = g_slist_append(adapter->devices, device);
@@ -1853,7 +1853,7 @@ static void create_stored_device_from_ltks(char *key, char *value,
if (g_strcmp0(srcaddr, address) == 0)
return;
- device = device_create(connection, adapter, address, bdaddr_type);
+ device = device_create(adapter, address, bdaddr_type);
if (device) {
device_set_temporary(device, FALSE);
adapter->devices = g_slist_append(adapter->devices, device);
@@ -1870,7 +1870,7 @@ static void create_stored_device_from_blocked(char *key, char *value,
key, (GCompareFunc) device_address_cmp))
return;
- device = device_create(connection, adapter, key, BDADDR_BREDR);
+ device = device_create(adapter, key, BDADDR_BREDR);
if (device) {
device_set_temporary(device, FALSE);
adapter->devices = g_slist_append(adapter->devices, device);
@@ -1928,7 +1928,7 @@ static void create_stored_device_from_primaries(char *key, char *value,
address, (GCompareFunc) device_address_cmp))
return;
- device = device_create(connection, adapter, address, bdaddr_type);
+ device = device_create(adapter, address, bdaddr_type);
if (!device)
return;
@@ -1944,7 +1944,7 @@ static void create_stored_device_from_primaries(char *key, char *value,
uuids = g_slist_append(uuids, prim->uuid);
}
- device_register_services(connection, device, services, -1);
+ device_register_services(device, services, -1);
device_probe_profiles(device, uuids);
@@ -3083,7 +3083,7 @@ void adapter_add_connection(struct btd_adapter *adapter,
return;
}
- device_add_connection(device, connection);
+ device_add_connection(device);
adapter->connections = g_slist_append(adapter->connections, device);
}
@@ -3098,7 +3098,7 @@ void adapter_remove_connection(struct btd_adapter *adapter,
return;
}
- device_remove_connection(device, connection);
+ device_remove_connection(device);
adapter->connections = g_slist_remove(adapter->connections, device);
diff --git a/src/device.c b/src/device.c
index 3e28608..1b2c741 100644
--- a/src/device.c
+++ b/src/device.c
@@ -79,7 +79,6 @@ struct btd_disconnect_data {
};
struct bonding_req {
- DBusConnection *conn;
DBusMessage *msg;
guint listener_id;
struct btd_device *device;
@@ -96,7 +95,6 @@ struct authentication_req {
};
struct browse_req {
- DBusConnection *conn;
DBusMessage *msg;
struct btd_device *device;
GSList *match_uuids;
@@ -182,11 +180,10 @@ static uint16_t uuid_list[] = {
static void browse_request_free(struct browse_req *req)
{
if (req->listener_id)
- g_dbus_remove_watch(req->conn, req->listener_id);
+ g_dbus_remove_watch(btd_get_dbus_connection(),
+ req->listener_id);
if (req->msg)
dbus_message_unref(req->msg);
- if (req->conn)
- dbus_connection_unref(req->conn);
if (req->device)
btd_device_unref(req->device);
g_slist_free_full(req->profiles_added, g_free);
@@ -436,8 +433,7 @@ static DBusMessage *get_properties(DBusConnection *conn,
return reply;
}
-static DBusMessage *set_alias(DBusConnection *conn, DBusMessage *msg,
- const char *alias, void *data)
+static DBusMessage *set_alias(DBusMessage *msg, const char *alias, void *data)
{
struct btd_device *device = data;
struct btd_adapter *adapter = device->adapter;
@@ -470,8 +466,7 @@ static DBusMessage *set_alias(DBusConnection *conn, DBusMessage *msg,
return dbus_message_new_method_return(msg);
}
-static DBusMessage *set_trust(DBusConnection *conn, DBusMessage *msg,
- gboolean value, void *data)
+static DBusMessage *set_trust(DBusMessage *msg, gboolean value, void *data)
{
struct btd_device *device = data;
struct btd_adapter *adapter = device->adapter;
@@ -519,8 +514,7 @@ static gboolean do_disconnect(gpointer user_data)
return FALSE;
}
-int device_block(DBusConnection *conn, struct btd_device *device,
- gboolean update_only)
+int device_block(struct btd_device *device, gboolean update_only)
{
int err = 0;
bdaddr_t src;
@@ -557,8 +551,8 @@ int device_block(DBusConnection *conn, struct btd_device *device,
return 0;
}
-int device_unblock(DBusConnection *conn, struct btd_device *device,
- gboolean silent, gboolean update_only)
+int device_unblock(struct btd_device *device, gboolean silent,
+ gboolean update_only)
{
int err = 0;
bdaddr_t src;
@@ -591,16 +585,15 @@ int device_unblock(DBusConnection *conn, struct btd_device *device,
return 0;
}
-static DBusMessage *set_blocked(DBusConnection *conn, DBusMessage *msg,
- gboolean value, void *data)
+static DBusMessage *set_blocked(DBusMessage *msg, gboolean value, void *data)
{
struct btd_device *device = data;
int err;
if (value)
- err = device_block(conn, device, FALSE);
+ err = device_block(device, FALSE);
else
- err = device_unblock(conn, device, FALSE, FALSE);
+ err = device_unblock(device, FALSE, FALSE);
switch (-err) {
case 0:
@@ -638,7 +631,7 @@ static DBusMessage *set_property(DBusConnection *conn,
return btd_error_invalid_args(msg);
dbus_message_iter_get_basic(&sub, &value);
- return set_trust(conn, msg, value, data);
+ return set_trust(msg, value, data);
} else if (g_str_equal("Alias", property)) {
const char *alias;
@@ -646,7 +639,7 @@ static DBusMessage *set_property(DBusConnection *conn,
return btd_error_invalid_args(msg);
dbus_message_iter_get_basic(&sub, &alias);
- return set_alias(conn, msg, alias, data);
+ return set_alias(msg, alias, data);
} else if (g_str_equal("Blocked", property)) {
dbus_bool_t value;
@@ -655,7 +648,7 @@ static DBusMessage *set_property(DBusConnection *conn,
dbus_message_iter_get_basic(&sub, &value);
- return set_blocked(conn, msg, value, data);
+ return set_blocked(msg, value, data);
}
return btd_error_invalid_args(msg);
@@ -685,7 +678,7 @@ static DBusMessage *discover_services(DBusConnection *conn,
return btd_error_invalid_args(msg);
if (strlen(pattern) == 0) {
- err = device_browse_sdp(device, conn, msg, NULL, FALSE);
+ err = device_browse_sdp(device, msg, NULL, FALSE);
if (err < 0)
goto fail;
} else {
@@ -696,7 +689,7 @@ static DBusMessage *discover_services(DBusConnection *conn,
sdp_uuid128_to_uuid(&uuid);
- err = device_browse_sdp(device, conn, msg, &uuid, FALSE);
+ err = device_browse_sdp(device, msg, &uuid, FALSE);
if (err < 0)
goto fail;
}
@@ -733,6 +726,7 @@ static void iter_append_record(DBusMessageIter *dict, uint32_t handle,
static void discover_services_reply(struct browse_req *req, int err,
sdp_list_t *recs)
{
+ DBusConnection *conn = btd_get_dbus_connection();
DBusMessage *reply;
DBusMessageIter iter, dict;
sdp_list_t *seq;
@@ -747,7 +741,7 @@ static void discover_services_reply(struct browse_req *req, int err,
reply = dbus_message_new_error(req->msg, err_if,
strerror(-err));
- g_dbus_send_message(req->conn, reply);
+ g_dbus_send_message(conn, reply);
return;
}
@@ -782,7 +776,7 @@ static void discover_services_reply(struct browse_req *req, int err,
dbus_message_iter_close_container(&iter, &dict);
- g_dbus_send_message(req->conn, reply);
+ g_dbus_send_message(conn, reply);
}
static DBusMessage *cancel_discover(DBusConnection *conn,
@@ -822,8 +816,6 @@ static void bonding_request_cancel(struct bonding_req *bonding)
void device_request_disconnect(struct btd_device *device, DBusMessage *msg)
{
- DBusConnection *conn = btd_get_dbus_connection();
-
if (device->bonding)
bonding_request_cancel(device->bonding);
@@ -858,9 +850,10 @@ void device_request_disconnect(struct btd_device *device, DBusMessage *msg)
device->disconn_timer = g_timeout_add_seconds(DISCONNECT_TIMER,
do_disconnect, device);
- g_dbus_emit_signal(conn, device->path,
- DEVICE_INTERFACE, "DisconnectRequested",
- DBUS_TYPE_INVALID);
+ g_dbus_emit_signal(btd_get_dbus_connection(),
+ device->path,
+ DEVICE_INTERFACE, "DisconnectRequested",
+ DBUS_TYPE_INVALID);
}
static DBusMessage *disconnect(DBusConnection *conn, DBusMessage *msg,
@@ -904,7 +897,7 @@ gboolean device_is_connected(struct btd_device *device)
return device->connected;
}
-void device_add_connection(struct btd_device *device, DBusConnection *conn)
+void device_add_connection(struct btd_device *device)
{
if (device->connected) {
char addr[18];
@@ -920,7 +913,7 @@ void device_add_connection(struct btd_device *device, DBusConnection *conn)
DBUS_TYPE_BOOLEAN, &device->connected);
}
-void device_remove_connection(struct btd_device *device, DBusConnection *conn)
+void device_remove_connection(struct btd_device *device)
{
if (!device->connected) {
char addr[18];
@@ -939,7 +932,8 @@ void device_remove_connection(struct btd_device *device, DBusConnection *conn)
while (device->disconnects) {
DBusMessage *msg = device->disconnects->data;
- g_dbus_send_reply(conn, msg, DBUS_TYPE_INVALID);
+ g_dbus_send_reply(btd_get_dbus_connection(),
+ msg, DBUS_TYPE_INVALID);
device->disconnects = g_slist_remove(device->disconnects, msg);
}
@@ -1035,8 +1029,7 @@ static void device_set_version(struct btd_device *device, uint16_t value)
DBUS_TYPE_UINT16, &value);
}
-struct btd_device *device_create(DBusConnection *conn,
- struct btd_adapter *adapter,
+struct btd_device *device_create(struct btd_adapter *adapter,
const gchar *address, uint8_t bdaddr_type)
{
gchar *address_up;
@@ -1057,9 +1050,10 @@ struct btd_device *device_create(DBusConnection *conn,
DBG("Creating device %s", device->path);
- if (g_dbus_register_interface(conn, device->path, DEVICE_INTERFACE,
- device_methods, device_signals, NULL,
- device, device_free) == FALSE) {
+ if (g_dbus_register_interface(btd_get_dbus_connection(),
+ device->path, DEVICE_INTERFACE,
+ device_methods, device_signals, NULL,
+ device, device_free) == FALSE) {
device_free(device);
return NULL;
}
@@ -1077,7 +1071,7 @@ struct btd_device *device_create(DBusConnection *conn,
device->trusted = read_trust(&src, address, device->bdaddr_type);
if (read_blocked(&src, &device->bdaddr, device->bdaddr_type))
- device_block(conn, device, FALSE);
+ device_block(device, FALSE);
if (read_link_key(&src, &device->bdaddr, device->bdaddr_type, NULL,
NULL) == 0) {
@@ -1149,7 +1143,6 @@ static void device_remove_stored(struct btd_device *device)
{
bdaddr_t src, dst;
uint8_t dst_type;
- DBusConnection *conn = btd_get_dbus_connection();
adapter_get_address(device->adapter, &src);
device_get_address(device, &dst, &dst_type);
@@ -1171,7 +1164,7 @@ static void device_remove_stored(struct btd_device *device)
delete_device_service(&src, &dst, dst_type);
if (device->blocked)
- device_unblock(conn, device, TRUE, FALSE);
+ device_unblock(device, TRUE, FALSE);
}
void device_remove(struct btd_device *device, gboolean remove_stored)
@@ -1568,7 +1561,7 @@ static void create_device_reply(struct btd_device *device, struct browse_req *re
dbus_message_append_args(reply, DBUS_TYPE_OBJECT_PATH, &device->path,
DBUS_TYPE_INVALID);
- g_dbus_send_message(req->conn, reply);
+ g_dbus_send_message(btd_get_dbus_connection(), reply);
}
GSList *device_services_from_record(struct btd_device *device, GSList *profiles)
@@ -1644,8 +1637,7 @@ static void search_cb(sdp_list_t *recs, int err, gpointer user_data)
list = device_services_from_record(device, req->profiles_added);
if (list)
- device_register_services(req->conn, device, list,
- ATT_PSM);
+ device_register_services(device, list, ATT_PSM);
device_probe_profiles(device, req->profiles_added);
}
@@ -1672,7 +1664,7 @@ send_reply:
if (err < 0) {
DBusMessage *reply;
reply = btd_error_failed(req->msg, strerror(-err));
- g_dbus_send_message(req->conn, reply);
+ g_dbus_send_message(btd_get_dbus_connection(), reply);
goto cleanup;
}
@@ -1853,7 +1845,7 @@ static void primary_cb(GSList *services, guint8 status, gpointer user_data)
DBusMessage *reply;
reply = btd_error_failed(req->msg,
att_ecode2str(status));
- g_dbus_send_message(req->conn, reply);
+ g_dbus_send_message(btd_get_dbus_connection(), reply);
}
goto done;
}
@@ -1867,7 +1859,7 @@ static void primary_cb(GSList *services, guint8 status, gpointer user_data)
g_slist_free_full(device->primaries, g_free);
device->primaries = NULL;
- device_register_services(req->conn, device, g_slist_copy(services), -1);
+ device_register_services(device, g_slist_copy(services), -1);
if (req->profiles_removed)
device_remove_profiles(device, req->profiles_removed);
@@ -2008,7 +2000,7 @@ static void att_browse_error_cb(const GError *gerr, gpointer user_data)
DBusMessage *reply;
reply = btd_error_failed(req->msg, gerr->message);
- g_dbus_send_message(req->conn, reply);
+ g_dbus_send_message(btd_get_dbus_connection(), reply);
}
device->browse = NULL;
@@ -2024,8 +2016,8 @@ static void att_browse_cb(gpointer user_data)
device->browse);
}
-int device_browse_primary(struct btd_device *device, DBusConnection *conn,
- DBusMessage *msg, gboolean secure)
+int device_browse_primary(struct btd_device *device, DBusMessage *msg,
+ gboolean secure)
{
struct btd_adapter *adapter = device->adapter;
struct att_callbacks *attcb;
@@ -2071,10 +2063,6 @@ int device_browse_primary(struct btd_device *device, DBusConnection *conn,
}
done:
- if (conn == NULL)
- conn = btd_get_dbus_connection();
-
- req->conn = dbus_connection_ref(conn);
if (msg) {
const char *sender = dbus_message_get_sender(msg);
@@ -2082,7 +2070,8 @@ done:
req->msg = dbus_message_ref(msg);
/* Track the request owner to cancel it
* automatically if the owner exits */
- req->listener_id = g_dbus_add_disconnect_watch(conn,
+ req->listener_id = g_dbus_add_disconnect_watch(
+ btd_get_dbus_connection(),
sender,
discover_services_req_exit,
req, NULL);
@@ -2091,8 +2080,8 @@ done:
return 0;
}
-int device_browse_sdp(struct btd_device *device, DBusConnection *conn,
- DBusMessage *msg, uuid_t *search, gboolean reverse)
+int device_browse_sdp(struct btd_device *device, DBusMessage *msg,
+ uuid_t *search, gboolean reverse)
{
struct btd_adapter *adapter = device->adapter;
struct browse_req *req;
@@ -2123,10 +2112,6 @@ int device_browse_sdp(struct btd_device *device, DBusConnection *conn,
return err;
}
- if (conn == NULL)
- conn = btd_get_dbus_connection();
-
- req->conn = dbus_connection_ref(conn);
device->browse = req;
if (msg) {
@@ -2135,7 +2120,8 @@ int device_browse_sdp(struct btd_device *device, DBusConnection *conn,
req->msg = dbus_message_ref(msg);
/* Track the request owner to cancel it
* automatically if the owner exits */
- req->listener_id = g_dbus_add_disconnect_watch(conn,
+ req->listener_id = g_dbus_add_disconnect_watch(
+ btd_get_dbus_connection(),
sender,
discover_services_req_exit,
req, NULL);
@@ -2264,9 +2250,9 @@ static gboolean start_discovery(gpointer user_data)
struct btd_device *device = user_data;
if (device_is_bredr(device))
- device_browse_sdp(device, NULL, NULL, NULL, TRUE);
+ device_browse_sdp(device, NULL, NULL, TRUE);
else
- device_browse_primary(device, NULL, NULL, FALSE);
+ device_browse_primary(device, NULL, FALSE);
device->discov_timer = 0;
@@ -2313,14 +2299,12 @@ static void bonding_request_free(struct bonding_req *bonding)
return;
if (bonding->listener_id)
- g_dbus_remove_watch(bonding->conn, bonding->listener_id);
+ g_dbus_remove_watch(btd_get_dbus_connection(),
+ bonding->listener_id);
if (bonding->msg)
dbus_message_unref(bonding->msg);
- if (bonding->conn)
- dbus_connection_unref(bonding->conn);
-
device = bonding->device;
g_free(bonding);
@@ -2363,8 +2347,7 @@ static void device_agent_removed(struct agent *agent, void *user_data)
device->authr->agent = NULL;
}
-static struct bonding_req *bonding_request_new(DBusConnection *conn,
- DBusMessage *msg,
+static struct bonding_req *bonding_request_new(DBusMessage *msg,
struct btd_device *device,
const char *agent_path,
uint8_t capability)
@@ -2390,7 +2373,6 @@ static struct bonding_req *bonding_request_new(DBusConnection *conn,
proceed:
bonding = g_new0(struct bonding_req, 1);
- bonding->conn = dbus_connection_ref(conn);
bonding->msg = dbus_message_ref(msg);
return bonding;
@@ -2414,7 +2396,6 @@ static void create_bond_req_exit(DBusConnection *conn, void *user_data)
}
DBusMessage *device_create_bonding(struct btd_device *device,
- DBusConnection *conn,
DBusMessage *msg,
const char *agent_path,
uint8_t capability)
@@ -2464,10 +2445,11 @@ DBusMessage *device_create_bonding(struct btd_device *device,
if (err < 0)
return btd_error_failed(msg, strerror(-err));
- bonding = bonding_request_new(conn, msg, device, agent_path,
+ bonding = bonding_request_new(msg, device, agent_path,
capability);
- bonding->listener_id = g_dbus_add_disconnect_watch(conn,
+ bonding->listener_id = g_dbus_add_disconnect_watch(
+ btd_get_dbus_connection(),
dbus_message_get_sender(msg),
create_bond_req_exit, device,
NULL);
@@ -2534,11 +2516,9 @@ void device_bonding_complete(struct btd_device *device, uint8_t status)
}
if (device_is_bredr(device))
- device_browse_sdp(device, bonding->conn, bonding->msg,
- NULL, FALSE);
+ device_browse_sdp(device, bonding->msg, NULL, FALSE);
else
- device_browse_primary(device, bonding->conn,
- bonding->msg, FALSE);
+ device_browse_primary(device, bonding->msg, FALSE);
bonding_request_free(bonding);
} else {
@@ -2608,7 +2588,7 @@ void device_cancel_bonding(struct btd_device *device, uint8_t status)
device_cancel_authentication(device, FALSE);
reply = new_authentication_return(bonding->msg, status);
- g_dbus_send_message(bonding->conn, reply);
+ g_dbus_send_message(btd_get_dbus_connection(), reply);
bonding_request_cancel(bonding);
bonding_request_free(bonding);
@@ -2965,12 +2945,13 @@ void device_set_authorizing(struct btd_device *device, gboolean auth)
device->authorizing = auth;
}
-void device_register_services(DBusConnection *conn, struct btd_device *device,
+void device_register_services(struct btd_device *device,
GSList *prim_list, int psm)
{
device->primaries = g_slist_concat(device->primaries, prim_list);
- device->services = attrib_client_register(conn, device, psm, NULL,
- prim_list);
+ device->services = attrib_client_register(btd_get_dbus_connection(),
+ device, psm, NULL,
+ prim_list);
}
GSList *btd_device_get_primaries(struct btd_device *device)
@@ -2990,7 +2971,7 @@ void btd_device_gatt_set_service_changed(struct btd_device *device,
prim->changed = TRUE;
}
- device_browse_primary(device, NULL, NULL, FALSE);
+ device_browse_primary(device, NULL, FALSE);
}
void btd_device_add_uuid(struct btd_device *device, const char *uuid)
@@ -3050,7 +3031,6 @@ struct btd_device *btd_device_ref(struct btd_device *device)
void btd_device_unref(struct btd_device *device)
{
- DBusConnection *conn = btd_get_dbus_connection();
gchar *path;
device->ref--;
@@ -3062,7 +3042,8 @@ void btd_device_unref(struct btd_device *device)
path = g_strdup(device->path);
- g_dbus_unregister_interface(conn, path, DEVICE_INTERFACE);
+ g_dbus_unregister_interface(btd_get_dbus_connection(),
+ path, DEVICE_INTERFACE);
g_free(path);
}
diff --git a/src/device.h b/src/device.h
index 9426ef8..44cb615 100644
--- a/src/device.h
+++ b/src/device.h
@@ -34,9 +34,8 @@ typedef enum {
AUTH_TYPE_NOTIFY_PINCODE,
} auth_type_t;
-struct btd_device *device_create(DBusConnection *conn,
- struct btd_adapter *adapter,
- const char *address, uint8_t bdaddr_type);
+struct btd_device *device_create(struct btd_adapter *adapter,
+ const char *address, uint8_t bdaddr_type);
void device_set_name(struct btd_device *device, const char *name);
void device_get_name(struct btd_device *device, char *name, size_t len);
@@ -47,17 +46,17 @@ uint16_t btd_device_get_version(struct btd_device *device);
void device_remove(struct btd_device *device, gboolean remove_stored);
gint device_address_cmp(struct btd_device *device, const gchar *address);
gint device_bdaddr_cmp(struct btd_device *device, bdaddr_t *bdaddr);
-int device_browse_primary(struct btd_device *device, DBusConnection *conn,
- DBusMessage *msg, gboolean secure);
-int device_browse_sdp(struct btd_device *device, DBusConnection *conn,
- DBusMessage *msg, uuid_t *search, gboolean reverse);
+int device_browse_primary(struct btd_device *device, DBusMessage *msg,
+ gboolean secure);
+int device_browse_sdp(struct btd_device *device, DBusMessage *msg,
+ uuid_t *search, gboolean reverse);
void device_probe_profiles(struct btd_device *device, GSList *profiles);
const sdp_record_t *btd_device_get_record(struct btd_device *device,
const char *uuid);
GSList *btd_device_get_primaries(struct btd_device *device);
void btd_device_gatt_set_service_changed(struct btd_device *device,
uint16_t start, uint16_t end);
-void device_register_services(DBusConnection *conn, struct btd_device *device,
+void device_register_services(struct btd_device *device,
GSList *prim_list, int psm);
GSList *device_services_from_record(struct btd_device *device,
GSList *profiles);
@@ -81,8 +80,7 @@ void device_set_temporary(struct btd_device *device, gboolean temporary);
void device_set_bonded(struct btd_device *device, gboolean bonded);
void device_set_auto_connect(struct btd_device *device, gboolean enable);
gboolean device_is_connected(struct btd_device *device);
-DBusMessage *device_create_bonding(struct btd_device *device,
- DBusConnection *conn, DBusMessage *msg,
+DBusMessage *device_create_bonding(struct btd_device *device, DBusMessage *msg,
const char *agent_path, uint8_t capability);
void device_bonding_complete(struct btd_device *device, uint8_t status);
void device_simple_pairing_complete(struct btd_device *device, uint8_t status);
@@ -102,8 +100,8 @@ void device_cancel_authentication(struct btd_device *device, gboolean aborted);
gboolean device_is_authenticating(struct btd_device *device);
gboolean device_is_authorizing(struct btd_device *device);
void device_set_authorizing(struct btd_device *device, gboolean auth);
-void device_add_connection(struct btd_device *device, DBusConnection *conn);
-void device_remove_connection(struct btd_device *device, DBusConnection *conn);
+void device_add_connection(struct btd_device *device);
+void device_remove_connection(struct btd_device *device);
void device_request_disconnect(struct btd_device *device, DBusMessage *msg);
typedef void (*disconnect_watch) (struct btd_device *device, gboolean removal,
@@ -120,10 +118,9 @@ void device_set_appearance(struct btd_device *device, uint16_t value);
struct btd_device *btd_device_ref(struct btd_device *device);
void btd_device_unref(struct btd_device *device);
-int device_block(DBusConnection *conn, struct btd_device *device,
- gboolean update_only);
-int device_unblock(DBusConnection *conn, struct btd_device *device,
- gboolean silent, gboolean update_only);
+int device_block(struct btd_device *device, gboolean update_only);
+int device_unblock(struct btd_device *device, gboolean silent,
+ gboolean update_only);
void device_set_pnpid(struct btd_device *device, uint8_t vendor_id_src,
uint16_t vendor_id, uint16_t product_id,
uint16_t product_ver);
diff --git a/src/event.c b/src/event.c
index e720b26..f1f5aaf 100644
--- a/src/event.c
+++ b/src/event.c
@@ -521,13 +521,11 @@ void btd_event_device_blocked(bdaddr_t *local, bdaddr_t *peer)
struct btd_adapter *adapter;
struct btd_device *device;
- DBusConnection *conn = btd_get_dbus_connection();
-
if (!get_adapter_and_device(local, peer, &adapter, &device, FALSE))
return;
if (device)
- device_block(conn, device, TRUE);
+ device_block(device, TRUE);
}
void btd_event_device_unblocked(bdaddr_t *local, bdaddr_t *peer)
@@ -535,13 +533,11 @@ void btd_event_device_unblocked(bdaddr_t *local, bdaddr_t *peer)
struct btd_adapter *adapter;
struct btd_device *device;
- DBusConnection *conn = btd_get_dbus_connection();
-
if (!get_adapter_and_device(local, peer, &adapter, &device, FALSE))
return;
if (device)
- device_unblock(conn, device, FALSE, TRUE);
+ device_unblock(device, FALSE, TRUE);
}
void btd_event_device_unpaired(bdaddr_t *local, bdaddr_t *peer)
--
1.7.11.3
This patch removes redundant references and function parameters for
DBusConnection object and uses btd_get_dbus_connection() call wherever
such object is needed instead.
Pointer returned by this call is guaranteed to be valid for entire
bluetoothd lifetime and thus do not need to be refcounted.
---
audio/manager.c | 2 +-
profiles/health/hdp.c | 3 +-
src/adapter.c | 132 ++++++++++++++++++++++----------------------------
src/adapter.h | 8 +--
src/event.c | 9 ++--
src/manager.c | 2 +-
6 files changed, 68 insertions(+), 88 deletions(-)
diff --git a/audio/manager.c b/audio/manager.c
index 99fcaf8..3b105ed 100644
--- a/audio/manager.c
+++ b/audio/manager.c
@@ -1329,7 +1329,7 @@ struct audio_device *manager_get_device(const bdaddr_t *src,
ba2str(dst, addr);
- device = adapter_get_device(connection, adapter, addr);
+ device = adapter_get_device(adapter, addr);
if (!device) {
error("Unable to get btd_device object for %s", addr);
return NULL;
diff --git a/profiles/health/hdp.c b/profiles/health/hdp.c
index 351fe1e..489e1eb 100644
--- a/profiles/health/hdp.c
+++ b/profiles/health/hdp.c
@@ -1209,8 +1209,7 @@ static void mcl_connected(struct mcap_mcl *mcl, gpointer data)
char str[18];
ba2str(&addr, str);
- device = adapter_get_device(connection,
- hdp_adapter->btd_adapter, str);
+ device = adapter_get_device(hdp_adapter->btd_adapter, str);
if (!device)
return;
hdp_device = create_health_device(connection, device);
diff --git a/src/adapter.c b/src/adapter.c
index 33ac246..d804472 100644
--- a/src/adapter.c
+++ b/src/adapter.c
@@ -84,12 +84,10 @@
#define OFF_TIMER 3
-static DBusConnection *connection = NULL;
static GSList *adapter_drivers = NULL;
struct session_req {
struct btd_adapter *adapter;
- DBusConnection *conn; /* Connection reference */
DBusMessage *msg; /* Unreplied message ref */
char *owner; /* Bus name of the owner */
guint id; /* Listener id */
@@ -218,15 +216,14 @@ static struct session_req *session_ref(struct session_req *req)
}
static struct session_req *create_session(struct btd_adapter *adapter,
- DBusConnection *conn, DBusMessage *msg,
- uint8_t mode, GDBusWatchFunction cb)
+ DBusMessage *msg, uint8_t mode,
+ GDBusWatchFunction cb)
{
const char *sender = dbus_message_get_sender(msg);
struct session_req *req;
req = g_new0(struct session_req, 1);
req->adapter = adapter;
- req->conn = dbus_connection_ref(conn);
req->msg = dbus_message_ref(msg);
req->mode = mode;
@@ -234,7 +231,8 @@ static struct session_req *create_session(struct btd_adapter *adapter,
return session_ref(req);
req->owner = g_strdup(sender);
- req->id = g_dbus_add_disconnect_watch(conn, sender, cb, req, NULL);
+ req->id = g_dbus_add_disconnect_watch(btd_get_dbus_connection(),
+ sender, cb, req, NULL);
info("%s session %p with %s activated",
req->mode ? "Mode" : "Discovery", req, sender);
@@ -317,8 +315,8 @@ done:
session_ref(req);
} else
/* Wait for mode change to reply */
- adapter->pending_mode = create_session(adapter,
- connection, msg, new_mode, NULL);
+ adapter->pending_mode = create_session(adapter, msg,
+ new_mode, NULL);
} else
/* Nothing to reply just write the new mode */
adapter->mode = new_mode;
@@ -326,8 +324,8 @@ done:
return 0;
}
-static DBusMessage *set_discoverable(DBusConnection *conn, DBusMessage *msg,
- gboolean discoverable, void *data)
+static DBusMessage *set_discoverable(DBusMessage *msg,
+ gboolean discoverable, void *data)
{
struct btd_adapter *adapter = data;
uint8_t mode;
@@ -347,8 +345,7 @@ static DBusMessage *set_discoverable(DBusConnection *conn, DBusMessage *msg,
return NULL;
}
-static DBusMessage *set_powered(DBusConnection *conn, DBusMessage *msg,
- gboolean powered, void *data)
+static DBusMessage *set_powered(DBusMessage *msg, gboolean powered, void *data)
{
struct btd_adapter *adapter = data;
uint8_t mode;
@@ -356,8 +353,7 @@ static DBusMessage *set_powered(DBusConnection *conn, DBusMessage *msg,
if (powered) {
mode = get_mode(&adapter->bdaddr, "on");
- return set_discoverable(conn, msg, mode == MODE_DISCOVERABLE,
- data);
+ return set_discoverable(msg, mode == MODE_DISCOVERABLE, data);
}
mode = MODE_OFF;
@@ -374,8 +370,8 @@ static DBusMessage *set_powered(DBusConnection *conn, DBusMessage *msg,
return NULL;
}
-static DBusMessage *set_pairable(DBusConnection *conn, DBusMessage *msg,
- gboolean pairable, void *data)
+static DBusMessage *set_pairable(DBusMessage *msg,
+ gboolean pairable, void *data)
{
struct btd_adapter *adapter = data;
int err;
@@ -402,7 +398,7 @@ done:
static gboolean pairable_timeout_handler(void *data)
{
- set_pairable(NULL, NULL, FALSE, data);
+ set_pairable(NULL, FALSE, data);
return FALSE;
}
@@ -557,7 +553,7 @@ static void session_free(void *data)
struct session_req *req = data;
if (req->id)
- g_dbus_remove_watch(req->conn, req->id);
+ g_dbus_remove_watch(btd_get_dbus_connection(), req->id);
if (req->msg) {
dbus_message_unref(req->msg);
@@ -565,8 +561,6 @@ static void session_free(void *data)
agent_cancel(req->adapter->agent);
}
- if (req->conn)
- dbus_connection_unref(req->conn);
g_free(req->owner);
g_free(req);
}
@@ -596,6 +590,7 @@ static void session_unref(struct session_req *req)
static void confirm_mode_cb(struct agent *agent, DBusError *derr, void *data)
{
+ DBusConnection *conn = btd_get_dbus_connection();
struct session_req *req = data;
int err;
DBusMessage *reply;
@@ -605,7 +600,7 @@ static void confirm_mode_cb(struct agent *agent, DBusError *derr, void *data)
if (derr && dbus_error_is_set(derr)) {
reply = dbus_message_new_error(req->msg, derr->name,
derr->message);
- g_dbus_send_message(req->conn, reply);
+ g_dbus_send_message(conn, reply);
session_unref(req);
return;
}
@@ -624,7 +619,7 @@ static void confirm_mode_cb(struct agent *agent, DBusError *derr, void *data)
* mode, or change is not needed. Otherwise, reply is sent in
* set_mode_complete.
*/
- g_dbus_send_message(req->conn, reply);
+ g_dbus_send_message(conn, reply);
dbus_message_unref(req->msg);
req->msg = NULL;
@@ -634,10 +629,8 @@ static void confirm_mode_cb(struct agent *agent, DBusError *derr, void *data)
session_unref(req);
}
-static DBusMessage *set_discoverable_timeout(DBusConnection *conn,
- DBusMessage *msg,
- uint32_t timeout,
- void *data)
+static DBusMessage *set_discoverable_timeout(DBusMessage *msg,
+ uint32_t timeout, void *data)
{
struct btd_adapter *adapter = data;
const char *path;
@@ -661,10 +654,8 @@ static DBusMessage *set_discoverable_timeout(DBusConnection *conn,
return dbus_message_new_method_return(msg);
}
-static DBusMessage *set_pairable_timeout(DBusConnection *conn,
- DBusMessage *msg,
- uint32_t timeout,
- void *data)
+static DBusMessage *set_pairable_timeout(DBusMessage *msg,
+ uint32_t timeout, void *data)
{
struct btd_adapter *adapter = data;
const char *path;
@@ -725,8 +716,8 @@ void adapter_name_changed(struct btd_adapter *adapter, const char *name)
adapter->name = g_strdup(name);
emit_property_changed(adapter->path,
- ADAPTER_INTERFACE, "Name",
- DBUS_TYPE_STRING, &name);
+ ADAPTER_INTERFACE, "Name",
+ DBUS_TYPE_STRING, &name);
if (main_opts.gatt_enabled)
attrib_gap_set(adapter, GATT_CHARAC_DEVICE_NAME,
@@ -761,8 +752,7 @@ int adapter_set_name(struct btd_adapter *adapter, const char *name)
return 0;
}
-static DBusMessage *set_name(DBusConnection *conn, DBusMessage *msg,
- const char *name, void *data)
+static DBusMessage *set_name(DBusMessage *msg, const char *name, void *data)
{
struct btd_adapter *adapter = data;
int ret;
@@ -930,8 +920,7 @@ void adapter_service_remove(struct btd_adapter *adapter, void *r)
adapter_emit_uuids_updated(adapter);
}
-static struct btd_device *adapter_create_device(DBusConnection *conn,
- struct btd_adapter *adapter,
+static struct btd_device *adapter_create_device(struct btd_adapter *adapter,
const char *address,
uint8_t bdaddr_type)
{
@@ -949,7 +938,7 @@ static struct btd_device *adapter_create_device(DBusConnection *conn,
adapter->devices = g_slist_append(adapter->devices, device);
path = device_get_path(device);
- g_dbus_emit_signal(conn, adapter->path,
+ g_dbus_emit_signal(btd_get_dbus_connection(), adapter->path,
ADAPTER_INTERFACE, "DeviceCreated",
DBUS_TYPE_OBJECT_PATH, &path,
DBUS_TYPE_INVALID);
@@ -959,7 +948,7 @@ static struct btd_device *adapter_create_device(DBusConnection *conn,
return device;
}
-void adapter_remove_device(DBusConnection *conn, struct btd_adapter *adapter,
+void adapter_remove_device(struct btd_adapter *adapter,
struct btd_device *device,
gboolean remove_storage)
{
@@ -971,7 +960,7 @@ void adapter_remove_device(DBusConnection *conn, struct btd_adapter *adapter,
adapter_update_devices(adapter);
- g_dbus_emit_signal(conn, adapter->path,
+ g_dbus_emit_signal(btd_get_dbus_connection(), adapter->path,
ADAPTER_INTERFACE, "DeviceRemoved",
DBUS_TYPE_OBJECT_PATH, &dev_path,
DBUS_TYPE_INVALID);
@@ -984,9 +973,8 @@ void adapter_remove_device(DBusConnection *conn, struct btd_adapter *adapter,
device_remove(device, remove_storage);
}
-struct btd_device *adapter_get_device(DBusConnection *conn,
- struct btd_adapter *adapter,
- const gchar *address)
+struct btd_device *adapter_get_device(struct btd_adapter *adapter,
+ const gchar *address)
{
struct btd_device *device;
@@ -999,8 +987,7 @@ struct btd_device *adapter_get_device(DBusConnection *conn,
if (device)
return device;
- return adapter_create_device(conn, adapter, address,
- BDADDR_BREDR);
+ return adapter_create_device(adapter, address, BDADDR_BREDR);
}
static gboolean discovery_cb(gpointer user_data)
@@ -1047,8 +1034,7 @@ static DBusMessage *adapter_start_discovery(DBusConnection *conn,
return btd_error_failed(msg, strerror(-err));
done:
- req = create_session(adapter, conn, msg, 0,
- session_owner_exit);
+ req = create_session(adapter, msg, 0, session_owner_exit);
adapter->disc_sessions = g_slist_append(adapter->disc_sessions, req);
@@ -1201,7 +1187,7 @@ static DBusMessage *set_property(DBusConnection *conn,
return btd_error_invalid_args(msg);
dbus_message_iter_get_basic(&sub, &name);
- return set_name(conn, msg, name, data);
+ return set_name(msg, name, data);
} else if (g_str_equal("Powered", property)) {
gboolean powered;
@@ -1210,7 +1196,7 @@ static DBusMessage *set_property(DBusConnection *conn,
dbus_message_iter_get_basic(&sub, &powered);
- return set_powered(conn, msg, powered, data);
+ return set_powered(msg, powered, data);
} else if (g_str_equal("Discoverable", property)) {
gboolean discoverable;
@@ -1219,7 +1205,7 @@ static DBusMessage *set_property(DBusConnection *conn,
dbus_message_iter_get_basic(&sub, &discoverable);
- return set_discoverable(conn, msg, discoverable, data);
+ return set_discoverable(msg, discoverable, data);
} else if (g_str_equal("DiscoverableTimeout", property)) {
uint32_t timeout;
@@ -1228,7 +1214,7 @@ static DBusMessage *set_property(DBusConnection *conn,
dbus_message_iter_get_basic(&sub, &timeout);
- return set_discoverable_timeout(conn, msg, timeout, data);
+ return set_discoverable_timeout(msg, timeout, data);
} else if (g_str_equal("Pairable", property)) {
gboolean pairable;
@@ -1237,7 +1223,7 @@ static DBusMessage *set_property(DBusConnection *conn,
dbus_message_iter_get_basic(&sub, &pairable);
- return set_pairable(conn, msg, pairable, data);
+ return set_pairable(msg, pairable, data);
} else if (g_str_equal("PairableTimeout", property)) {
uint32_t timeout;
@@ -1246,7 +1232,7 @@ static DBusMessage *set_property(DBusConnection *conn,
dbus_message_iter_get_basic(&sub, &timeout);
- return set_pairable_timeout(conn, msg, timeout, data);
+ return set_pairable_timeout(msg, timeout, data);
}
return btd_error_invalid_args(msg);
@@ -1274,8 +1260,8 @@ static DBusMessage *request_session(DBusConnection *conn,
session_ref(req);
return dbus_message_new_method_return(msg);
} else {
- req = create_session(adapter, conn, msg, new_mode,
- session_owner_exit);
+ req = create_session(adapter, msg, new_mode,
+ session_owner_exit);
adapter->mode_sessions = g_slist_append(adapter->mode_sessions,
req);
}
@@ -1338,13 +1324,12 @@ static DBusMessage *cancel_device_creation(DBusConnection *conn,
return NULL;
}
- adapter_remove_device(conn, adapter, device, TRUE);
+ adapter_remove_device(adapter, device, TRUE);
return dbus_message_new_method_return(msg);
}
-static struct btd_device *create_device_internal(DBusConnection *conn,
- struct btd_adapter *adapter,
+static struct btd_device *create_device_internal(struct btd_adapter *adapter,
const char *address, int *err)
{
struct remote_dev_info *dev;
@@ -1360,7 +1345,7 @@ static struct btd_device *create_device_internal(DBusConnection *conn,
else
bdaddr_type = BDADDR_BREDR;
- device = adapter_create_device(conn, adapter, address, bdaddr_type);
+ device = adapter_create_device(adapter, address, bdaddr_type);
if (!device && err)
*err = -ENOMEM;
@@ -1391,7 +1376,7 @@ static DBusMessage *create_device(DBusConnection *conn,
DBG("%s", address);
- device = create_device_internal(conn, adapter, address, &err);
+ device = create_device_internal(adapter, address, &err);
if (!device)
goto failed;
@@ -1401,7 +1386,7 @@ static DBusMessage *create_device(DBusConnection *conn,
err = device_browse_primary(device, msg, FALSE);
if (err < 0) {
- adapter_remove_device(conn, adapter, device, TRUE);
+ adapter_remove_device(adapter, device, TRUE);
return btd_error_failed(msg, strerror(-err));
}
@@ -1474,7 +1459,7 @@ static DBusMessage *create_paired_device(DBusConnection *conn,
device = adapter_find_device(adapter, address);
if (!device) {
- device = create_device_internal(conn, adapter, address, &err);
+ device = create_device_internal(adapter, address, &err);
if (!device)
return btd_error_failed(msg, strerror(-err));
}
@@ -1516,7 +1501,7 @@ static DBusMessage *remove_device(DBusConnection *conn, DBusMessage *msg,
device_set_temporary(device, TRUE);
if (!device_is_connected(device)) {
- adapter_remove_device(conn, adapter, device, TRUE);
+ adapter_remove_device(adapter, device, TRUE);
return dbus_message_new_method_return(msg);
}
@@ -2086,7 +2071,7 @@ static void load_connections(struct btd_adapter *adapter)
ba2str(bdaddr, address);
DBG("Adding existing connection to %s", address);
- device = adapter_get_device(connection, adapter, address);
+ device = adapter_get_device(adapter, address);
if (device)
adapter_add_connection(adapter, device);
}
@@ -2135,7 +2120,7 @@ static void emit_device_disappeared(gpointer data, gpointer user_data)
ba2str(&dev->bdaddr, address);
- g_dbus_emit_signal(connection, adapter->path,
+ g_dbus_emit_signal(btd_get_dbus_connection(), adapter->path,
ADAPTER_INTERFACE, "DeviceDisappeared",
DBUS_TYPE_STRING, &paddr,
DBUS_TYPE_INVALID);
@@ -2332,7 +2317,7 @@ static void set_mode_complete(struct btd_adapter *adapter)
reply = g_dbus_create_reply(msg, DBUS_TYPE_INVALID);
}
- g_dbus_send_message(connection, reply);
+ g_dbus_send_message(btd_get_dbus_connection(), reply);
}
if (err != 0)
@@ -2449,7 +2434,8 @@ void btd_adapter_unref(struct btd_adapter *adapter)
path = g_strdup(adapter->path);
- g_dbus_unregister_interface(connection, path, ADAPTER_INTERFACE);
+ g_dbus_unregister_interface(btd_get_dbus_connection(),
+ path, ADAPTER_INTERFACE);
g_free(path);
}
@@ -2491,15 +2477,12 @@ gboolean adapter_init(struct btd_adapter *adapter, gboolean up)
return TRUE;
}
-struct btd_adapter *adapter_create(DBusConnection *conn, int id)
+struct btd_adapter *adapter_create(int id)
{
char path[MAX_PATH_LENGTH];
struct btd_adapter *adapter;
const char *base_path = manager_get_base_path();
- if (!connection)
- connection = conn;
-
adapter = g_try_new0(struct btd_adapter, 1);
if (!adapter) {
error("adapter_create: failed to alloc memory for hci%d", id);
@@ -2511,7 +2494,8 @@ struct btd_adapter *adapter_create(DBusConnection *conn, int id)
snprintf(path, sizeof(path), "%s/hci%d", base_path, id);
adapter->path = g_strdup(path);
- if (!g_dbus_register_interface(conn, path, ADAPTER_INTERFACE,
+ if (!g_dbus_register_interface(btd_get_dbus_connection(),
+ path, ADAPTER_INTERFACE,
adapter_methods, adapter_signals, NULL,
adapter, adapter_free)) {
error("Adapter interface init failed on path %s", path);
@@ -2702,7 +2686,7 @@ static void emit_device_found(const char *path, const char *address,
append_dict_valist(&iter, first_key, var_args);
va_end(var_args);
- g_dbus_send_message(connection, signal);
+ g_dbus_send_message(btd_get_dbus_connection(), signal);
}
static char **strlist2array(GSList *list)
@@ -3109,7 +3093,7 @@ void adapter_remove_connection(struct btd_adapter *adapter,
const char *path = device_get_path(device);
DBG("Removing temporary device %s", path);
- adapter_remove_device(connection, adapter, device, TRUE);
+ adapter_remove_device(adapter, device, TRUE);
}
}
@@ -3552,7 +3536,7 @@ void adapter_bonding_complete(struct btd_adapter *adapter, bdaddr_t *bdaddr,
ba2str(bdaddr, addr);
if (status == 0)
- device = adapter_get_device(connection, adapter, addr);
+ device = adapter_get_device(adapter, addr);
else
device = adapter_find_device(adapter, addr);
diff --git a/src/adapter.h b/src/adapter.h
index cd37b15..eece6f5 100644
--- a/src/adapter.h
+++ b/src/adapter.h
@@ -87,16 +87,16 @@ void btd_adapter_get_mode(struct btd_adapter *adapter, uint8_t *mode,
void btd_adapter_get_class(struct btd_adapter *adapter, uint8_t *major,
uint8_t *minor);
const char *btd_adapter_get_name(struct btd_adapter *adapter);
-struct btd_device *adapter_get_device(DBusConnection *conn,
- struct btd_adapter *adapter, const char *address);
+struct btd_device *adapter_get_device(struct btd_adapter *adapter,
+ const char *address);
struct btd_device *adapter_find_device(struct btd_adapter *adapter, const char *dest);
-void adapter_remove_device(DBusConnection *conn, struct btd_adapter *adapter,
+void adapter_remove_device(struct btd_adapter *adapter,
struct btd_device *device,
gboolean remove_storage);
-struct btd_adapter *adapter_create(DBusConnection *conn, int id);
+struct btd_adapter *adapter_create(int id);
gboolean adapter_init(struct btd_adapter *adapter, gboolean up);
void adapter_remove(struct btd_adapter *adapter);
void adapter_set_allow_name_changes(struct btd_adapter *adapter,
diff --git a/src/event.c b/src/event.c
index f1f5aaf..1db73be 100644
--- a/src/event.c
+++ b/src/event.c
@@ -56,7 +56,6 @@ static gboolean get_adapter_and_device(bdaddr_t *src, bdaddr_t *dst,
struct btd_device **device,
gboolean create)
{
- DBusConnection *conn = btd_get_dbus_connection();
char peer_addr[18];
*adapter = manager_find_adapter(src);
@@ -68,7 +67,7 @@ static gboolean get_adapter_and_device(bdaddr_t *src, bdaddr_t *dst,
ba2str(dst, peer_addr);
if (create)
- *device = adapter_get_device(conn, *adapter, peer_addr);
+ *device = adapter_get_device(*adapter, peer_addr);
else
*device = adapter_find_device(*adapter, peer_addr);
@@ -483,7 +482,6 @@ void btd_event_conn_failed(bdaddr_t *local, bdaddr_t *peer, uint8_t status)
{
struct btd_adapter *adapter;
struct btd_device *device;
- DBusConnection *conn = btd_get_dbus_connection();
DBG("status 0x%02x", status);
@@ -497,7 +495,7 @@ void btd_event_conn_failed(bdaddr_t *local, bdaddr_t *peer, uint8_t status)
device_cancel_bonding(device, status);
if (device_is_temporary(device))
- adapter_remove_device(conn, adapter, device, TRUE);
+ adapter_remove_device(adapter, device, TRUE);
}
void btd_event_disconn_complete(bdaddr_t *local, bdaddr_t *peer)
@@ -544,7 +542,6 @@ void btd_event_device_unpaired(bdaddr_t *local, bdaddr_t *peer)
{
struct btd_adapter *adapter;
struct btd_device *device;
- DBusConnection *conn = btd_get_dbus_connection();
if (!get_adapter_and_device(local, peer, &adapter, &device, FALSE))
return;
@@ -554,7 +551,7 @@ void btd_event_device_unpaired(bdaddr_t *local, bdaddr_t *peer)
if (device_is_connected(device))
device_request_disconnect(device, NULL);
else
- adapter_remove_device(conn, adapter, device, TRUE);
+ adapter_remove_device(adapter, device, TRUE);
}
/* Section reserved to device HCI callbacks */
diff --git a/src/manager.c b/src/manager.c
index fe8706b..15a2571 100644
--- a/src/manager.c
+++ b/src/manager.c
@@ -352,7 +352,7 @@ struct btd_adapter *btd_manager_register_adapter(int id, gboolean up)
return NULL;
}
- adapter = adapter_create(btd_get_dbus_connection(), id);
+ adapter = adapter_create(id);
if (!adapter)
return NULL;
--
1.7.11.3
This patch removes local reference to DBusConnection object and uses
btd_get_dbus_connection() call wherever such object is needed instead.
Pointer returned by this call is guaranteed to be valid for entire
bluetoothd lifetime and thus do not need to be refcounted.
---
src/agent.c | 44 +++++++++++++++++---------------------------
src/agent.h | 3 ---
src/main.c | 4 ----
3 files changed, 17 insertions(+), 34 deletions(-)
diff --git a/src/agent.c b/src/agent.c
index 36e96e9..8cf37b1 100644
--- a/src/agent.c
+++ b/src/agent.c
@@ -42,6 +42,7 @@
#include "log.h"
+#include "dbus-common.h"
#include "adapter.h"
#include "device.h"
#include "agent.h"
@@ -79,8 +80,6 @@ struct agent_request {
GDestroyNotify destroy;
};
-static DBusConnection *connection = NULL;
-
static void agent_release(struct agent *agent)
{
DBusMessage *message;
@@ -97,7 +96,7 @@ static void agent_release(struct agent *agent)
return;
}
- g_dbus_send_message(connection, message);
+ g_dbus_send_message(btd_get_dbus_connection(), message);
}
static int send_cancel_request(struct agent_request *req)
@@ -114,7 +113,7 @@ static int send_cancel_request(struct agent_request *req)
return -ENOMEM;
}
- g_dbus_send_message(connection, message);
+ g_dbus_send_message(btd_get_dbus_connection(), message);
return 0;
}
@@ -180,7 +179,8 @@ void agent_free(struct agent *agent)
}
if (!agent->exited) {
- g_dbus_remove_watch(connection, agent->listener_id);
+ g_dbus_remove_watch(btd_get_dbus_connection(),
+ agent->listener_id);
agent_release(agent);
}
@@ -205,9 +205,9 @@ struct agent *agent_create(struct btd_adapter *adapter, const char *name,
agent->remove_cb = cb;
agent->remove_cb_data = remove_cb_data;
- agent->listener_id = g_dbus_add_disconnect_watch(connection, name,
- agent_exited, agent,
- NULL);
+ agent->listener_id =
+ g_dbus_add_disconnect_watch(btd_get_dbus_connection(), name,
+ agent_exited, agent, NULL);
return agent;
}
@@ -311,8 +311,9 @@ static int agent_call_authorize(struct agent_request *req,
DBUS_TYPE_STRING, &uuid,
DBUS_TYPE_INVALID);
- if (dbus_connection_send_with_reply(connection, req->msg,
- &req->call, REQUEST_TIMEOUT) == FALSE) {
+ if (dbus_connection_send_with_reply(btd_get_dbus_connection(),
+ req->msg, &req->call,
+ REQUEST_TIMEOUT) == FALSE) {
error("D-Bus send failed");
return -EIO;
}
@@ -427,7 +428,7 @@ static int pincode_request_new(struct agent_request *req, const char *device_pat
dbus_message_append_args(req->msg, DBUS_TYPE_OBJECT_PATH, &device_path,
DBUS_TYPE_INVALID);
- if (dbus_connection_send_with_reply(connection, req->msg,
+ if (dbus_connection_send_with_reply(btd_get_dbus_connection(), req->msg,
&req->call, REQUEST_TIMEOUT) == FALSE) {
error("D-Bus send failed");
return -EIO;
@@ -480,7 +481,7 @@ static int confirm_mode_change_request_new(struct agent_request *req,
DBUS_TYPE_STRING, &mode,
DBUS_TYPE_INVALID);
- if (dbus_connection_send_with_reply(connection, req->msg,
+ if (dbus_connection_send_with_reply(btd_get_dbus_connection(), req->msg,
&req->call, REQUEST_TIMEOUT) == FALSE) {
error("D-Bus send failed");
return -EIO;
@@ -576,7 +577,7 @@ static int passkey_request_new(struct agent_request *req,
dbus_message_append_args(req->msg, DBUS_TYPE_OBJECT_PATH, &device_path,
DBUS_TYPE_INVALID);
- if (dbus_connection_send_with_reply(connection, req->msg,
+ if (dbus_connection_send_with_reply(btd_get_dbus_connection(), req->msg,
&req->call, REQUEST_TIMEOUT) == FALSE) {
error("D-Bus send failed");
return -EIO;
@@ -634,7 +635,7 @@ static int confirmation_request_new(struct agent_request *req,
DBUS_TYPE_UINT32, &passkey,
DBUS_TYPE_INVALID);
- if (dbus_connection_send_with_reply(connection, req->msg,
+ if (dbus_connection_send_with_reply(btd_get_dbus_connection(), req->msg,
&req->call, REQUEST_TIMEOUT) == FALSE) {
error("D-Bus send failed");
return -EIO;
@@ -694,7 +695,7 @@ int agent_display_passkey(struct agent *agent, struct btd_device *device,
DBUS_TYPE_UINT16, &entered,
DBUS_TYPE_INVALID);
- if (!g_dbus_send_message(connection, message)) {
+ if (!g_dbus_send_message(btd_get_dbus_connection(), message)) {
error("D-Bus send failed");
return -1;
}
@@ -768,7 +769,7 @@ static int display_pincode_request_new(struct agent_request *req,
DBUS_TYPE_STRING, &pincode,
DBUS_TYPE_INVALID);
- if (dbus_connection_send_with_reply(connection, req->msg,
+ if (dbus_connection_send_with_reply(btd_get_dbus_connection(), req->msg,
&req->call, REQUEST_TIMEOUT) == FALSE) {
error("D-Bus send failed");
return -EIO;
@@ -833,14 +834,3 @@ gboolean agent_is_busy(struct agent *agent, void *user_data)
return TRUE;
}
-
-void agent_exit(void)
-{
- dbus_connection_unref(connection);
- connection = NULL;
-}
-
-void agent_init(void)
-{
- connection = dbus_bus_get(DBUS_BUS_SYSTEM, NULL);
-}
diff --git a/src/agent.h b/src/agent.h
index a729633..8fb4758 100644
--- a/src/agent.h
+++ b/src/agent.h
@@ -75,6 +75,3 @@ gboolean agent_is_busy(struct agent *agent, void *user_data);
uint8_t agent_get_io_capability(struct agent *agent);
gboolean agent_matches(struct agent *agent, const char *name, const char *path);
-
-void agent_init(void);
-void agent_exit(void);
diff --git a/src/main.c b/src/main.c
index 7593b15..f8c9369 100644
--- a/src/main.c
+++ b/src/main.c
@@ -513,8 +513,6 @@ int main(int argc, char *argv[])
parse_config(config);
- agent_init();
-
if (option_udev == FALSE) {
if (connect_dbus() < 0) {
error("Unable to get on D-Bus");
@@ -562,8 +560,6 @@ int main(int argc, char *argv[])
stop_sdp_server();
- agent_exit();
-
g_main_loop_unref(event_loop);
if (config)
--
1.7.11.3
DBusConnection pointer is already stored in connection static variable
so it's redundant to pass it as function parameter.
---
src/adapter.c | 7 ++++---
src/dbus-common.c | 5 ++---
src/dbus-common.h | 3 +--
src/device.c | 6 +++---
src/manager.c | 3 +--
5 files changed, 11 insertions(+), 13 deletions(-)
diff --git a/src/adapter.c b/src/adapter.c
index 2db3200..fb6a2e5 100644
--- a/src/adapter.c
+++ b/src/adapter.c
@@ -811,7 +811,7 @@ static void adapter_update_devices(struct btd_adapter *adapter)
devices[i] = (char *) device_get_path(dev);
}
- emit_array_property_changed(connection, adapter->path,
+ emit_array_property_changed(adapter->path,
ADAPTER_INTERFACE, "Devices",
DBUS_TYPE_OBJECT_PATH, &devices, i);
g_free(devices);
@@ -837,8 +837,9 @@ static void adapter_emit_uuids_updated(struct btd_adapter *adapter)
uuids[i++] = uuid;
}
- emit_array_property_changed(connection, adapter->path,
- ADAPTER_INTERFACE, "UUIDs", DBUS_TYPE_STRING, &uuids, i);
+ emit_array_property_changed(adapter->path,
+ ADAPTER_INTERFACE, "UUIDs",
+ DBUS_TYPE_STRING, &uuids, i);
g_strfreev(uuids);
}
diff --git a/src/dbus-common.c b/src/dbus-common.c
index 21395d9..afd07de 100644
--- a/src/dbus-common.c
+++ b/src/dbus-common.c
@@ -143,8 +143,7 @@ dbus_bool_t emit_property_changed(const char *path,
return g_dbus_send_message(connection, signal);
}
-dbus_bool_t emit_array_property_changed(DBusConnection *conn,
- const char *path,
+dbus_bool_t emit_array_property_changed(const char *path,
const char *interface,
const char *name,
int type, void *value, int num)
@@ -166,7 +165,7 @@ dbus_bool_t emit_array_property_changed(DBusConnection *conn,
append_array_variant(&iter, type, value, num);
- return g_dbus_send_message(conn, signal);
+ return g_dbus_send_message(connection, signal);
}
void set_dbus_connection(DBusConnection *conn)
diff --git a/src/dbus-common.h b/src/dbus-common.h
index ff130ff..823a292 100644
--- a/src/dbus-common.h
+++ b/src/dbus-common.h
@@ -34,8 +34,7 @@ dbus_bool_t emit_property_changed(const char *path,
const char *name,
int type, void *value);
-dbus_bool_t emit_array_property_changed(DBusConnection *conn,
- const char *path,
+dbus_bool_t emit_array_property_changed(const char *path,
const char *interface,
const char *name,
int type, void *value, int num);
diff --git a/src/device.c b/src/device.c
index b732cc6..3e28608 100644
--- a/src/device.c
+++ b/src/device.c
@@ -1377,7 +1377,6 @@ static void device_remove_profiles(struct btd_device *device, GSList *uuids)
static void uuids_changed(struct btd_device *device)
{
- DBusConnection *conn = btd_get_dbus_connection();
char **uuids;
GSList *l;
int i;
@@ -1386,8 +1385,9 @@ static void uuids_changed(struct btd_device *device)
for (i = 0, l = device->uuids; l; l = l->next, i++)
uuids[i] = l->data;
- emit_array_property_changed(conn, device->path, DEVICE_INTERFACE,
- "UUIDs", DBUS_TYPE_STRING, &uuids, i);
+ emit_array_property_changed(device->path,
+ DEVICE_INTERFACE, "UUIDs",
+ DBUS_TYPE_STRING, &uuids, i);
g_free(uuids);
}
diff --git a/src/manager.c b/src/manager.c
index 738bf0b..31feb84 100644
--- a/src/manager.c
+++ b/src/manager.c
@@ -217,8 +217,7 @@ static void manager_update_adapters(void)
i++;
}
- emit_array_property_changed(connection, "/",
- MANAGER_INTERFACE, "Adapters",
+ emit_array_property_changed("/", MANAGER_INTERFACE, "Adapters",
DBUS_TYPE_OBJECT_PATH, &array, i);
g_free(array);
--
1.7.11.3
Valid DBusConnection pointer is available static variable 'connection' so it's
it's redundant to pass it as function parameter.
---
audio/control.c | 8 ++---
audio/device.c | 2 +-
audio/gateway.c | 6 ++--
audio/headset.c | 18 +++++-----
audio/sink.c | 10 +++---
audio/source.c | 2 +-
audio/transport.c | 8 ++---
profiles/health/hdp.c | 12 +++----
profiles/input/device.c | 10 +++---
profiles/network/connection.c | 12 +++----
profiles/proximity/immalert.c | 2 +-
profiles/proximity/linkloss.c | 2 +-
profiles/proximity/monitor.c | 21 +++++------
profiles/sap/server.c | 8 ++---
profiles/thermometer/thermometer.c | 8 ++---
src/adapter.c | 34 +++++++++---------
src/dbus-common.c | 5 ++-
src/dbus-common.h | 3 +-
src/device.c | 72 ++++++++++++++++++--------------------
19 files changed, 118 insertions(+), 125 deletions(-)
diff --git a/audio/control.c b/audio/control.c
index 5477c2d..02aea33 100644
--- a/audio/control.c
+++ b/audio/control.c
@@ -80,7 +80,7 @@ static void state_changed(struct audio_device *dev, avctp_state_t old_state,
g_dbus_emit_signal(dev->conn, dev->path,
AUDIO_CONTROL_INTERFACE,
"Disconnected", DBUS_TYPE_INVALID);
- emit_property_changed(dev->conn, dev->path,
+ emit_property_changed(dev->path,
AUDIO_CONTROL_INTERFACE, "Connected",
DBUS_TYPE_BOOLEAN, &value);
@@ -97,9 +97,9 @@ static void state_changed(struct audio_device *dev, avctp_state_t old_state,
g_dbus_emit_signal(dev->conn, dev->path,
AUDIO_CONTROL_INTERFACE, "Connected",
DBUS_TYPE_INVALID);
- emit_property_changed(dev->conn, dev->path,
- AUDIO_CONTROL_INTERFACE, "Connected",
- DBUS_TYPE_BOOLEAN, &value);
+ emit_property_changed(dev->path,
+ AUDIO_CONTROL_INTERFACE, "Connected",
+ DBUS_TYPE_BOOLEAN, &value);
break;
default:
return;
diff --git a/audio/device.c b/audio/device.c
index 4952b57..b93a294 100644
--- a/audio/device.c
+++ b/audio/device.c
@@ -280,7 +280,7 @@ static void device_set_state(struct audio_device *dev, audio_state_t new_state)
g_dbus_send_message(dev->conn, reply);
}
- emit_property_changed(dev->conn, dev->path,
+ emit_property_changed(dev->path,
AUDIO_INTERFACE, "State",
DBUS_TYPE_STRING, &state_str);
}
diff --git a/audio/gateway.c b/audio/gateway.c
index 53094af..0fe29d1 100644
--- a/audio/gateway.c
+++ b/audio/gateway.c
@@ -129,9 +129,9 @@ static void change_state(struct audio_device *dev, gateway_state_t new_state)
old_state = gw->state;
gw->state = new_state;
- emit_property_changed(dev->conn, dev->path,
- AUDIO_GATEWAY_INTERFACE, "State",
- DBUS_TYPE_STRING, &val);
+ emit_property_changed(dev->path,
+ AUDIO_GATEWAY_INTERFACE, "State",
+ DBUS_TYPE_STRING, &val);
for (l = gateway_callbacks; l != NULL; l = l->next) {
struct gateway_state_callback *cb = l->data;
diff --git a/audio/headset.c b/audio/headset.c
index 1ef6c49..3ded18e 100644
--- a/audio/headset.c
+++ b/audio/headset.c
@@ -988,7 +988,7 @@ static int headset_set_gain(struct audio_device *device, uint16_t gain, char typ
DBUS_TYPE_UINT16, &gain,
DBUS_TYPE_INVALID);
- emit_property_changed(device->conn, device->path,
+ emit_property_changed(device->path,
AUDIO_HEADSET_INTERFACE, property,
DBUS_TYPE_UINT16, &gain);
@@ -2343,7 +2343,7 @@ void headset_set_state(struct audio_device *dev, headset_state_t state)
value = FALSE;
close_sco(dev);
headset_close_rfcomm(dev);
- emit_property_changed(dev->conn, dev->path,
+ emit_property_changed(dev->path,
AUDIO_HEADSET_INTERFACE, "State",
DBUS_TYPE_STRING, &state_str);
g_dbus_emit_signal(dev->conn, dev->path,
@@ -2351,7 +2351,7 @@ void headset_set_state(struct audio_device *dev, headset_state_t state)
"Disconnected",
DBUS_TYPE_INVALID);
if (hs->state > HEADSET_STATE_CONNECTING) {
- emit_property_changed(dev->conn, dev->path,
+ emit_property_changed(dev->path,
AUDIO_HEADSET_INTERFACE, "Connected",
DBUS_TYPE_BOOLEAN, &value);
telephony_device_disconnected(dev);
@@ -2359,14 +2359,14 @@ void headset_set_state(struct audio_device *dev, headset_state_t state)
active_devices = g_slist_remove(active_devices, dev);
break;
case HEADSET_STATE_CONNECTING:
- emit_property_changed(dev->conn, dev->path,
+ emit_property_changed(dev->path,
AUDIO_HEADSET_INTERFACE, "State",
DBUS_TYPE_STRING, &state_str);
break;
case HEADSET_STATE_CONNECTED:
close_sco(dev);
if (hs->state != HEADSET_STATE_PLAY_IN_PROGRESS)
- emit_property_changed(dev->conn, dev->path,
+ emit_property_changed(dev->path,
AUDIO_HEADSET_INTERFACE, "State",
DBUS_TYPE_STRING, &state_str);
if (hs->state < state) {
@@ -2379,7 +2379,7 @@ void headset_set_state(struct audio_device *dev, headset_state_t state)
"Connected",
DBUS_TYPE_INVALID);
value = TRUE;
- emit_property_changed(dev->conn, dev->path,
+ emit_property_changed(dev->path,
AUDIO_HEADSET_INTERFACE,
"Connected",
DBUS_TYPE_BOOLEAN, &value);
@@ -2391,7 +2391,7 @@ void headset_set_state(struct audio_device *dev, headset_state_t state)
AUDIO_HEADSET_INTERFACE,
"Stopped",
DBUS_TYPE_INVALID);
- emit_property_changed(dev->conn, dev->path,
+ emit_property_changed(dev->path,
AUDIO_HEADSET_INTERFACE,
"Playing",
DBUS_TYPE_BOOLEAN, &value);
@@ -2401,7 +2401,7 @@ void headset_set_state(struct audio_device *dev, headset_state_t state)
break;
case HEADSET_STATE_PLAYING:
value = TRUE;
- emit_property_changed(dev->conn, dev->path,
+ emit_property_changed(dev->path,
AUDIO_HEADSET_INTERFACE, "State",
DBUS_TYPE_STRING, &state_str);
@@ -2414,7 +2414,7 @@ void headset_set_state(struct audio_device *dev, headset_state_t state)
g_dbus_emit_signal(dev->conn, dev->path,
AUDIO_HEADSET_INTERFACE, "Playing",
DBUS_TYPE_INVALID);
- emit_property_changed(dev->conn, dev->path,
+ emit_property_changed(dev->path,
AUDIO_HEADSET_INTERFACE, "Playing",
DBUS_TYPE_BOOLEAN, &value);
diff --git a/audio/sink.c b/audio/sink.c
index 53a0b80..6201d85 100644
--- a/audio/sink.c
+++ b/audio/sink.c
@@ -116,7 +116,7 @@ static void sink_set_state(struct audio_device *dev, sink_state_t new_state)
state_str = state2str(new_state);
if (state_str)
- emit_property_changed(dev->conn, dev->path,
+ emit_property_changed(dev->path,
AUDIO_SINK_INTERFACE, "State",
DBUS_TYPE_STRING, &state_str);
@@ -147,7 +147,7 @@ static void avdtp_state_callback(struct audio_device *dev,
g_dbus_emit_signal(dev->conn, dev->path,
AUDIO_SINK_INTERFACE, "Disconnected",
DBUS_TYPE_INVALID);
- emit_property_changed(dev->conn, dev->path,
+ emit_property_changed(dev->path,
AUDIO_SINK_INTERFACE, "Connected",
DBUS_TYPE_BOOLEAN, &value);
}
@@ -218,7 +218,7 @@ static void stream_state_changed(struct avdtp_stream *stream,
AUDIO_SINK_INTERFACE,
"Connected",
DBUS_TYPE_INVALID);
- emit_property_changed(dev->conn, dev->path,
+ emit_property_changed(dev->path,
AUDIO_SINK_INTERFACE,
"Connected",
DBUS_TYPE_BOOLEAN, &value);
@@ -228,7 +228,7 @@ static void stream_state_changed(struct avdtp_stream *stream,
AUDIO_SINK_INTERFACE,
"Stopped",
DBUS_TYPE_INVALID);
- emit_property_changed(dev->conn, dev->path,
+ emit_property_changed(dev->path,
AUDIO_SINK_INTERFACE,
"Playing",
DBUS_TYPE_BOOLEAN, &value);
@@ -239,7 +239,7 @@ static void stream_state_changed(struct avdtp_stream *stream,
value = TRUE;
g_dbus_emit_signal(dev->conn, dev->path, AUDIO_SINK_INTERFACE,
"Playing", DBUS_TYPE_INVALID);
- emit_property_changed(dev->conn, dev->path,
+ emit_property_changed(dev->path,
AUDIO_SINK_INTERFACE, "Playing",
DBUS_TYPE_BOOLEAN, &value);
sink_set_state(dev, SINK_STATE_PLAYING);
diff --git a/audio/source.c b/audio/source.c
index e4ba211..8e01666 100644
--- a/audio/source.c
+++ b/audio/source.c
@@ -110,7 +110,7 @@ static void source_set_state(struct audio_device *dev, source_state_t new_state)
state_str = state2str(new_state);
if (state_str)
- emit_property_changed(dev->conn, dev->path,
+ emit_property_changed(dev->path,
AUDIO_SOURCE_INTERFACE, "State",
DBUS_TYPE_STRING, &state_str);
diff --git a/audio/transport.c b/audio/transport.c
index 281895e..6541fc1 100644
--- a/audio/transport.c
+++ b/audio/transport.c
@@ -203,7 +203,7 @@ static void transport_set_state(struct media_transport *transport,
str = state2str(state);
if (g_strcmp0(str, state2str(old_state)) != 0)
- emit_property_changed(transport->conn, transport->path,
+ emit_property_changed(transport->path,
MEDIA_TRANSPORT_INTERFACE, "State",
DBUS_TYPE_STRING, &str);
}
@@ -1168,7 +1168,7 @@ static void headset_nrec_changed(struct audio_device *dev, gboolean nrec,
DBG("");
- emit_property_changed(transport->conn, transport->path,
+ emit_property_changed(transport->path,
MEDIA_TRANSPORT_INTERFACE, "NREC",
DBUS_TYPE_BOOLEAN, &nrec);
}
@@ -1367,7 +1367,7 @@ void media_transport_update_delay(struct media_transport *transport,
a2dp->delay = delay;
- emit_property_changed(transport->conn, transport->path,
+ emit_property_changed(transport->path,
MEDIA_TRANSPORT_INTERFACE, "Delay",
DBUS_TYPE_UINT16, &a2dp->delay);
}
@@ -1388,7 +1388,7 @@ void media_transport_update_volume(struct media_transport *transport,
a2dp->volume = volume;
- emit_property_changed(transport->conn, transport->path,
+ emit_property_changed(transport->path,
MEDIA_TRANSPORT_INTERFACE, "Volume",
DBUS_TYPE_UINT16, &a2dp->volume);
}
diff --git a/profiles/health/hdp.c b/profiles/health/hdp.c
index 5d62d35..351fe1e 100644
--- a/profiles/health/hdp.c
+++ b/profiles/health/hdp.c
@@ -977,9 +977,9 @@ static void hdp_mcap_mdl_connected_cb(struct mcap_mdl *mdl, void *data)
dev->fr = hdp_channel_ref(chan);
- emit_property_changed(dev->conn, device_get_path(dev->dev),
- HEALTH_DEVICE, "MainChannel",
- DBUS_TYPE_OBJECT_PATH, &dev->fr->path);
+ emit_property_changed(device_get_path(dev->dev),
+ HEALTH_DEVICE, "MainChannel",
+ DBUS_TYPE_OBJECT_PATH, &dev->fr->path);
end:
hdp_channel_unref(dev->ndc);
@@ -1696,9 +1696,9 @@ static void hdp_mdl_conn_cb(struct mcap_mdl *mdl, GError *err, gpointer data)
dev->fr = hdp_channel_ref(hdp_chann);
- emit_property_changed(dev->conn, device_get_path(dev->dev),
- HEALTH_DEVICE, "MainChannel",
- DBUS_TYPE_OBJECT_PATH, &dev->fr->path);
+ emit_property_changed(device_get_path(dev->dev),
+ HEALTH_DEVICE, "MainChannel",
+ DBUS_TYPE_OBJECT_PATH, &dev->fr->path);
}
static void device_create_mdl_cb(struct mcap_mdl *mdl, uint8_t conf,
diff --git a/profiles/input/device.c b/profiles/input/device.c
index 1954b34..dc3da80 100644
--- a/profiles/input/device.c
+++ b/profiles/input/device.c
@@ -147,8 +147,9 @@ static gboolean intr_watch_cb(GIOChannel *chan, GIOCondition cond, gpointer data
if ((cond & (G_IO_HUP | G_IO_ERR)) && idev->ctrl_watch)
g_io_channel_shutdown(chan, TRUE, NULL);
- emit_property_changed(idev->conn, idev->path, INPUT_DEVICE_INTERFACE,
- "Connected", DBUS_TYPE_BOOLEAN, &connected);
+ emit_property_changed(idev->path,
+ INPUT_DEVICE_INTERFACE, "Connected",
+ DBUS_TYPE_BOOLEAN, &connected);
device_remove_disconnect_watch(idev->device, idev->dc_id);
idev->dc_id = 0;
@@ -492,8 +493,9 @@ static int input_device_connected(struct input_device *idev)
return err;
connected = TRUE;
- emit_property_changed(idev->conn, idev->path, INPUT_DEVICE_INTERFACE,
- "Connected", DBUS_TYPE_BOOLEAN, &connected);
+ emit_property_changed(idev->path,
+ INPUT_DEVICE_INTERFACE, "Connected",
+ DBUS_TYPE_BOOLEAN, &connected);
idev->dc_id = device_add_disconnect_watch(idev->device, disconnect_cb,
idev, NULL);
diff --git a/profiles/network/connection.c b/profiles/network/connection.c
index b81d5b5..178f51f 100644
--- a/profiles/network/connection.c
+++ b/profiles/network/connection.c
@@ -119,13 +119,13 @@ static gboolean bnep_watchdog_cb(GIOChannel *chan, GIOCondition cond,
if (connection != NULL) {
gboolean connected = FALSE;
const char *property = "";
- emit_property_changed(connection, nc->peer->path,
+ emit_property_changed(nc->peer->path,
NETWORK_PEER_INTERFACE, "Connected",
DBUS_TYPE_BOOLEAN, &connected);
- emit_property_changed(connection, nc->peer->path,
+ emit_property_changed(nc->peer->path,
NETWORK_PEER_INTERFACE, "Interface",
DBUS_TYPE_STRING, &property);
- emit_property_changed(connection, nc->peer->path,
+ emit_property_changed(nc->peer->path,
NETWORK_PEER_INTERFACE, "UUID",
DBUS_TYPE_STRING, &property);
device_remove_disconnect_watch(nc->peer->device, nc->dc_id);
@@ -274,13 +274,13 @@ static gboolean bnep_setup_cb(GIOChannel *chan, GIOCondition cond,
DBUS_TYPE_INVALID);
connected = TRUE;
- emit_property_changed(connection, nc->peer->path,
+ emit_property_changed(nc->peer->path,
NETWORK_PEER_INTERFACE, "Connected",
DBUS_TYPE_BOOLEAN, &connected);
- emit_property_changed(connection, nc->peer->path,
+ emit_property_changed(nc->peer->path,
NETWORK_PEER_INTERFACE, "Interface",
DBUS_TYPE_STRING, &pdev);
- emit_property_changed(connection, nc->peer->path,
+ emit_property_changed(nc->peer->path,
NETWORK_PEER_INTERFACE, "UUID",
DBUS_TYPE_STRING, &uuid);
diff --git a/profiles/proximity/immalert.c b/profiles/proximity/immalert.c
index ebd788a..59e4f12 100644
--- a/profiles/proximity/immalert.c
+++ b/profiles/proximity/immalert.c
@@ -136,7 +136,7 @@ static void imm_alert_emit_alert_signal(struct connected_device *condev,
DBG("alert %s remote %s", alert_level_str, path);
- emit_property_changed(btd_get_dbus_connection(), path,
+ emit_property_changed(path,
PROXIMITY_REPORTER_INTERFACE, "ImmediateAlertLevel",
DBUS_TYPE_STRING, &alert_level_str);
}
diff --git a/profiles/proximity/linkloss.c b/profiles/proximity/linkloss.c
index 37d1f86..659eaa8 100644
--- a/profiles/proximity/linkloss.c
+++ b/profiles/proximity/linkloss.c
@@ -137,7 +137,7 @@ static void link_loss_emit_alert_signal(struct connected_device *condev)
DBG("alert %s remote %s", alert_level_str, path);
- emit_property_changed(btd_get_dbus_connection(), path,
+ emit_property_changed(path,
PROXIMITY_REPORTER_INTERFACE, "LinkLossAlertLevel",
DBUS_TYPE_STRING, &alert_level_str);
}
diff --git a/profiles/proximity/monitor.c b/profiles/proximity/monitor.c
index a9de85b..a791916 100644
--- a/profiles/proximity/monitor.c
+++ b/profiles/proximity/monitor.c
@@ -160,7 +160,7 @@ static void linkloss_written(guint8 status, const guint8 *pdu, guint16 plen,
DBG("Link Loss Alert Level written");
- emit_property_changed(btd_get_dbus_connection(), path,
+ emit_property_changed(path,
PROXIMITY_INTERFACE, "LinkLossAlertLevel",
DBUS_TYPE_STRING, &monitor->linklosslevel);
}
@@ -289,10 +289,9 @@ static gboolean immediate_timeout(gpointer user_data)
g_free(monitor->immediatelevel);
monitor->immediatelevel = g_strdup("none");
- emit_property_changed(btd_get_dbus_connection(),
- path, PROXIMITY_INTERFACE,
- "ImmediateAlertLevel", DBUS_TYPE_STRING,
- &monitor->immediatelevel);
+ emit_property_changed(path,
+ PROXIMITY_INTERFACE, "ImmediateAlertLevel",
+ DBUS_TYPE_STRING, &monitor->immediatelevel);
return FALSE;
}
@@ -305,9 +304,8 @@ static void immediate_written(gpointer user_data)
g_free(monitor->fallbacklevel);
monitor->fallbacklevel = NULL;
- emit_property_changed(btd_get_dbus_connection(),
- path, PROXIMITY_INTERFACE,
- "ImmediateAlertLevel",
+ emit_property_changed(path,
+ PROXIMITY_INTERFACE, "ImmediateAlertLevel",
DBUS_TYPE_STRING, &monitor->immediatelevel);
monitor->immediateto = g_timeout_add_seconds(IMMEDIATE_TIMEOUT,
@@ -392,10 +390,9 @@ static void attio_disconnected_cb(gpointer user_data)
g_free(monitor->immediatelevel);
monitor->immediatelevel = g_strdup("none");
- emit_property_changed(btd_get_dbus_connection(),
- path, PROXIMITY_INTERFACE,
- "ImmediateAlertLevel", DBUS_TYPE_STRING,
- &monitor->immediatelevel);
+ emit_property_changed(path,
+ PROXIMITY_INTERFACE, "ImmediateAlertLevel",
+ DBUS_TYPE_STRING, &monitor->immediatelevel);
}
static gboolean level_is_valid(const char *level)
diff --git a/profiles/sap/server.c b/profiles/sap/server.c
index 78a63bf..fc3d83c 100644
--- a/profiles/sap/server.c
+++ b/profiles/sap/server.c
@@ -622,9 +622,9 @@ static void sap_set_connected(struct sap_server *server)
{
gboolean connected = TRUE;
- emit_property_changed(connection, server->path,
- SAP_SERVER_INTERFACE,
- "Connected", DBUS_TYPE_BOOLEAN, &connected);
+ emit_property_changed(server->path,
+ SAP_SERVER_INTERFACE, "Connected",
+ DBUS_TYPE_BOOLEAN, &connected);
server->conn->state = SAP_STATE_CONNECTED;
}
@@ -1149,7 +1149,7 @@ static void sap_io_destroy(void *data)
if (conn->state != SAP_STATE_CONNECT_IN_PROGRESS &&
conn->state != SAP_STATE_CONNECT_MODEM_BUSY)
- emit_property_changed(connection, server->path,
+ emit_property_changed(server->path,
SAP_SERVER_INTERFACE, "Connected",
DBUS_TYPE_BOOLEAN, &connected);
diff --git a/profiles/thermometer/thermometer.c b/profiles/thermometer/thermometer.c
index f58e558..44043e8 100644
--- a/profiles/thermometer/thermometer.c
+++ b/profiles/thermometer/thermometer.c
@@ -265,7 +265,7 @@ static void change_property(struct thermometer *t, const char *name,
return;
t->intermediate = *intermediate;
- emit_property_changed(t->conn, device_get_path(t->dev),
+ emit_property_changed(device_get_path(t->dev),
THERMOMETER_INTERFACE, name,
DBUS_TYPE_BOOLEAN, &t->intermediate);
} else if (g_strcmp0(name, "Interval") == 0) {
@@ -275,7 +275,7 @@ static void change_property(struct thermometer *t, const char *name,
t->has_interval = TRUE;
t->interval = *interval;
- emit_property_changed(t->conn, device_get_path(t->dev),
+ emit_property_changed(device_get_path(t->dev),
THERMOMETER_INTERFACE, name,
DBUS_TYPE_UINT16, &t->interval);
} else if (g_strcmp0(name, "Maximum") == 0) {
@@ -284,7 +284,7 @@ static void change_property(struct thermometer *t, const char *name,
return;
t->max = *max;
- emit_property_changed(t->conn, device_get_path(t->dev),
+ emit_property_changed(device_get_path(t->dev),
THERMOMETER_INTERFACE, name,
DBUS_TYPE_UINT16, &t->max);
} else if (g_strcmp0(name, "Minimum") == 0) {
@@ -293,7 +293,7 @@ static void change_property(struct thermometer *t, const char *name,
return;
t->min = *min;
- emit_property_changed(t->conn, device_get_path(t->dev),
+ emit_property_changed(device_get_path(t->dev),
THERMOMETER_INTERFACE, name,
DBUS_TYPE_UINT16, &t->min);
} else
diff --git a/src/adapter.c b/src/adapter.c
index facfa23..2db3200 100644
--- a/src/adapter.c
+++ b/src/adapter.c
@@ -430,7 +430,7 @@ void btd_adapter_pairable_changed(struct btd_adapter *adapter,
write_device_pairable(&adapter->bdaddr, pairable);
- emit_property_changed(connection, adapter->path,
+ emit_property_changed(adapter->path,
ADAPTER_INTERFACE, "Pairable",
DBUS_TYPE_BOOLEAN, &pairable);
@@ -654,7 +654,7 @@ static DBusMessage *set_discoverable_timeout(DBusConnection *conn,
path = dbus_message_get_path(msg);
- emit_property_changed(conn, path,
+ emit_property_changed(path,
ADAPTER_INTERFACE, "DiscoverableTimeout",
DBUS_TYPE_UINT32, &timeout);
@@ -681,7 +681,7 @@ static DBusMessage *set_pairable_timeout(DBusConnection *conn,
path = dbus_message_get_path(msg);
- emit_property_changed(conn, path,
+ emit_property_changed(path,
ADAPTER_INTERFACE, "PairableTimeout",
DBUS_TYPE_UINT32, &timeout);
@@ -711,7 +711,7 @@ void btd_adapter_class_changed(struct btd_adapter *adapter, uint8_t *new_class)
attrib_gap_set(adapter, GATT_CHARAC_APPEARANCE, cls, 2);
}
- emit_property_changed(connection, adapter->path,
+ emit_property_changed(adapter->path,
ADAPTER_INTERFACE, "Class",
DBUS_TYPE_UINT32, &class);
}
@@ -724,8 +724,7 @@ void adapter_name_changed(struct btd_adapter *adapter, const char *name)
g_free(adapter->name);
adapter->name = g_strdup(name);
- if (connection)
- emit_property_changed(connection, adapter->path,
+ emit_property_changed(adapter->path,
ADAPTER_INTERFACE, "Name",
DBUS_TYPE_STRING, &name);
@@ -2240,9 +2239,9 @@ void btd_adapter_start(struct btd_adapter *adapter)
adapter->mode = MODE_CONNECTABLE;
powered = TRUE;
- emit_property_changed(connection, adapter->path,
- ADAPTER_INTERFACE, "Powered",
- DBUS_TYPE_BOOLEAN, &powered);
+ emit_property_changed(adapter->path,
+ ADAPTER_INTERFACE, "Powered",
+ DBUS_TYPE_BOOLEAN, &powered);
call_adapter_powered_callbacks(adapter, TRUE);
@@ -2363,22 +2362,23 @@ int btd_adapter_stop(struct btd_adapter *adapter)
}
if (adapter->scan_mode == (SCAN_PAGE | SCAN_INQUIRY))
- emit_property_changed(connection, adapter->path,
+ emit_property_changed(adapter->path,
ADAPTER_INTERFACE, "Discoverable",
DBUS_TYPE_BOOLEAN, &prop_false);
if ((adapter->scan_mode & SCAN_PAGE) && adapter->pairable == TRUE)
- emit_property_changed(connection, adapter->path,
+ emit_property_changed(adapter->path,
ADAPTER_INTERFACE, "Pairable",
DBUS_TYPE_BOOLEAN, &prop_false);
if (adapter->discovering)
- emit_property_changed(connection, adapter->path,
+ emit_property_changed(adapter->path,
ADAPTER_INTERFACE, "Discovering",
DBUS_TYPE_BOOLEAN, &prop_false);
- emit_property_changed(connection, adapter->path, ADAPTER_INTERFACE,
- "Powered", DBUS_TYPE_BOOLEAN, &prop_false);
+ emit_property_changed(adapter->path,
+ ADAPTER_INTERFACE, "Powered",
+ DBUS_TYPE_BOOLEAN, &prop_false);
adapter->discovering = FALSE;
adapter->scan_mode = SCAN_DISABLED;
@@ -2573,7 +2573,7 @@ void adapter_set_discovering(struct btd_adapter *adapter,
adapter->discovering = discovering;
- emit_property_changed(connection, path,
+ emit_property_changed(path,
ADAPTER_INTERFACE, "Discovering",
DBUS_TYPE_BOOLEAN, &discovering);
@@ -3053,11 +3053,11 @@ void adapter_mode_changed(struct btd_adapter *adapter, uint8_t scan_mode)
/* If page scanning gets toggled emit the Pairable property */
if ((adapter->scan_mode & SCAN_PAGE) != (scan_mode & SCAN_PAGE))
- emit_property_changed(connection, adapter->path,
+ emit_property_changed(adapter->path,
ADAPTER_INTERFACE, "Pairable",
DBUS_TYPE_BOOLEAN, &pairable);
- emit_property_changed(connection, path,
+ emit_property_changed(path,
ADAPTER_INTERFACE, "Discoverable",
DBUS_TYPE_BOOLEAN, &discoverable);
diff --git a/src/dbus-common.c b/src/dbus-common.c
index f7e9e8f..21395d9 100644
--- a/src/dbus-common.c
+++ b/src/dbus-common.c
@@ -118,8 +118,7 @@ void dict_append_array(DBusMessageIter *dict, const char *key, int type,
dbus_message_iter_close_container(dict, &entry);
}
-dbus_bool_t emit_property_changed(DBusConnection *conn,
- const char *path,
+dbus_bool_t emit_property_changed(const char *path,
const char *interface,
const char *name,
int type, void *value)
@@ -141,7 +140,7 @@ dbus_bool_t emit_property_changed(DBusConnection *conn,
append_variant(&iter, type, value);
- return g_dbus_send_message(conn, signal);
+ return g_dbus_send_message(connection, signal);
}
dbus_bool_t emit_array_property_changed(DBusConnection *conn,
diff --git a/src/dbus-common.h b/src/dbus-common.h
index 127cf9c..ff130ff 100644
--- a/src/dbus-common.h
+++ b/src/dbus-common.h
@@ -29,8 +29,7 @@ void dict_append_entry(DBusMessageIter *dict,
void dict_append_array(DBusMessageIter *dict, const char *key, int type,
void *val, int n_elements);
-dbus_bool_t emit_property_changed(DBusConnection *conn,
- const char *path,
+dbus_bool_t emit_property_changed(const char *path,
const char *interface,
const char *name,
int type, void *value);
diff --git a/src/device.c b/src/device.c
index 278d721..b732cc6 100644
--- a/src/device.c
+++ b/src/device.c
@@ -463,7 +463,7 @@ static DBusMessage *set_alias(DBusConnection *conn, DBusMessage *msg,
g_free(device->alias);
device->alias = g_str_equal(alias, "") ? NULL : g_strdup(alias);
- emit_property_changed(conn, dbus_message_get_path(msg),
+ emit_property_changed(dbus_message_get_path(msg),
DEVICE_INTERFACE, "Alias",
DBUS_TYPE_STRING, &alias);
@@ -492,7 +492,7 @@ static DBusMessage *set_trust(DBusConnection *conn, DBusMessage *msg,
device->trusted = value;
- emit_property_changed(conn, dbus_message_get_path(msg),
+ emit_property_changed(dbus_message_get_path(msg),
DEVICE_INTERFACE, "Trusted",
DBUS_TYPE_BOOLEAN, &value);
@@ -550,8 +550,9 @@ int device_block(DBusConnection *conn, struct btd_device *device,
device_set_temporary(device, FALSE);
- emit_property_changed(conn, device->path, DEVICE_INTERFACE, "Blocked",
- DBUS_TYPE_BOOLEAN, &device->blocked);
+ emit_property_changed(device->path,
+ DEVICE_INTERFACE, "Blocked",
+ DBUS_TYPE_BOOLEAN, &device->blocked);
return 0;
}
@@ -581,7 +582,7 @@ int device_unblock(DBusConnection *conn, struct btd_device *device,
error("write_blocked(): %s (%d)", strerror(-err), -err);
if (!silent) {
- emit_property_changed(conn, device->path,
+ emit_property_changed(device->path,
DEVICE_INTERFACE, "Blocked",
DBUS_TYPE_BOOLEAN, &device->blocked);
device_probe_profiles(device, device->uuids);
@@ -914,7 +915,7 @@ void device_add_connection(struct btd_device *device, DBusConnection *conn)
device->connected = TRUE;
- emit_property_changed(conn, device->path,
+ emit_property_changed(device->path,
DEVICE_INTERFACE, "Connected",
DBUS_TYPE_BOOLEAN, &device->connected);
}
@@ -945,9 +946,9 @@ void device_remove_connection(struct btd_device *device, DBusConnection *conn)
if (device_is_paired(device) && !device_is_bonded(device))
device_set_paired(device, FALSE);
- emit_property_changed(conn, device->path,
- DEVICE_INTERFACE, "Connected",
- DBUS_TYPE_BOOLEAN, &device->connected);
+ emit_property_changed(device->path,
+ DEVICE_INTERFACE, "Connected",
+ DBUS_TYPE_BOOLEAN, &device->connected);
}
guint device_add_disconnect_watch(struct btd_device *device,
@@ -988,53 +989,49 @@ void device_remove_disconnect_watch(struct btd_device *device, guint id)
static void device_set_vendor(struct btd_device *device, uint16_t value)
{
- DBusConnection *conn = btd_get_dbus_connection();
-
if (device->vendor == value)
return;
device->vendor = value;
- emit_property_changed(conn, device->path, DEVICE_INTERFACE, "Vendor",
+ emit_property_changed(device->path,
+ DEVICE_INTERFACE, "Vendor",
DBUS_TYPE_UINT16, &value);
}
static void device_set_vendor_src(struct btd_device *device, uint16_t value)
{
- DBusConnection *conn = btd_get_dbus_connection();
-
if (device->vendor_src == value)
return;
device->vendor_src = value;
- emit_property_changed(conn, device->path, DEVICE_INTERFACE,
- "VendorSource", DBUS_TYPE_UINT16, &value);
+ emit_property_changed(device->path,
+ DEVICE_INTERFACE, "VendorSource",
+ DBUS_TYPE_UINT16, &value);
}
static void device_set_product(struct btd_device *device, uint16_t value)
{
- DBusConnection *conn = btd_get_dbus_connection();
-
if (device->product == value)
return;
device->product = value;
- emit_property_changed(conn, device->path, DEVICE_INTERFACE, "Product",
+ emit_property_changed(device->path,
+ DEVICE_INTERFACE, "Product",
DBUS_TYPE_UINT16, &value);
}
static void device_set_version(struct btd_device *device, uint16_t value)
{
- DBusConnection *conn = btd_get_dbus_connection();
-
if (device->version == value)
return;
device->version = value;
- emit_property_changed(conn, device->path, DEVICE_INTERFACE, "Version",
+ emit_property_changed(device->path,
+ DEVICE_INTERFACE, "Version",
DBUS_TYPE_UINT16, &value);
}
@@ -1106,21 +1103,19 @@ struct btd_device *device_create(DBusConnection *conn,
void device_set_name(struct btd_device *device, const char *name)
{
- DBusConnection *conn = btd_get_dbus_connection();
-
if (strncmp(name, device->name, MAX_NAME_LENGTH) == 0)
return;
strncpy(device->name, name, MAX_NAME_LENGTH);
- emit_property_changed(conn, device->path,
+ emit_property_changed(device->path,
DEVICE_INTERFACE, "Name",
DBUS_TYPE_STRING, &name);
if (device->alias != NULL)
return;
- emit_property_changed(conn, device->path,
+ emit_property_changed(device->path,
DEVICE_INTERFACE, "Alias",
DBUS_TYPE_STRING, &name);
}
@@ -2344,8 +2339,6 @@ static void bonding_request_free(struct bonding_req *bonding)
void device_set_paired(struct btd_device *device, gboolean value)
{
- DBusConnection *conn = btd_get_dbus_connection();
-
if (device->paired == value)
return;
@@ -2355,7 +2348,8 @@ void device_set_paired(struct btd_device *device, gboolean value)
device->paired = value;
- emit_property_changed(conn, device->path, DEVICE_INTERFACE, "Paired",
+ emit_property_changed(device->path,
+ DEVICE_INTERFACE, "Paired",
DBUS_TYPE_BOOLEAN, &value);
}
@@ -3075,15 +3069,16 @@ void btd_device_unref(struct btd_device *device)
void device_set_class(struct btd_device *device, uint32_t value)
{
- DBusConnection *conn = btd_get_dbus_connection();
const char *icon = class_to_icon(value);
- emit_property_changed(conn, device->path, DEVICE_INTERFACE, "Class",
+ emit_property_changed(device->path,
+ DEVICE_INTERFACE, "Class",
DBUS_TYPE_UINT32, &value);
if (icon)
- emit_property_changed(conn, device->path, DEVICE_INTERFACE,
- "Icon", DBUS_TYPE_STRING, &icon);
+ emit_property_changed(device->path,
+ DEVICE_INTERFACE, "Icon",
+ DBUS_TYPE_STRING, &icon);
}
int device_get_appearance(struct btd_device *device, uint16_t *value)
@@ -3107,16 +3102,17 @@ int device_get_appearance(struct btd_device *device, uint16_t *value)
void device_set_appearance(struct btd_device *device, uint16_t value)
{
- DBusConnection *conn = btd_get_dbus_connection();
const char *icon = gap_appearance_to_icon(value);
bdaddr_t src;
- emit_property_changed(conn, device->path, DEVICE_INTERFACE,
- "Appearance", DBUS_TYPE_UINT16, &value);
+ emit_property_changed(device->path,
+ DEVICE_INTERFACE, "Appearance",
+ DBUS_TYPE_UINT16, &value);
if (icon)
- emit_property_changed(conn, device->path, DEVICE_INTERFACE,
- "Icon", DBUS_TYPE_STRING, &icon);
+ emit_property_changed(device->path,
+ DEVICE_INTERFACE, "Icon",
+ DBUS_TYPE_STRING, &icon);
adapter_get_address(device_get_adapter(device), &src);
write_remote_appearance(&src, &device->bdaddr, device->bdaddr_type,
--
1.7.11.3
D-Bus is connected before any subsystem needs to use it and disconnected only
after nothing uses it (i.e. plugins). This is to guarantee that every call to
btd_get_dbus_connection() will return valid DBusConnection object so various
components and plugins do not need to store it somewhere and care about ref
counting.
---
src/main.c | 14 ++++++++------
1 file changed, 8 insertions(+), 6 deletions(-)
diff --git a/src/main.c b/src/main.c
index 249d29e..31af12a 100644
--- a/src/main.c
+++ b/src/main.c
@@ -388,8 +388,6 @@ static void disconnect_dbus(void)
if (!conn || !dbus_connection_get_is_connected(conn))
return;
- manager_cleanup(conn, "/");
-
set_dbus_connection(NULL);
dbus_connection_unref(conn);
@@ -418,9 +416,6 @@ static int connect_dbus(void)
return -EALREADY;
}
- if (!manager_init(conn, "/"))
- return -EIO;
-
set_dbus_connection(conn);
g_dbus_set_disconnect_function(conn, disconnected_dbus, NULL, NULL);
@@ -532,6 +527,11 @@ int main(int argc, char *argv[])
}
}
+ if (!manager_init(btd_get_dbus_connection(), "/")) {
+ error("Can't register manager interface");
+ exit(1);
+ }
+
start_sdp_server(mtu, SDP_SERVER_COMPAT);
/* Loading plugins has to be done after D-Bus has been setup since
@@ -554,7 +554,7 @@ int main(int argc, char *argv[])
g_source_remove(signal);
- disconnect_dbus();
+ manager_cleanup(btd_get_dbus_connection(), "/");
rfkill_exit();
@@ -571,6 +571,8 @@ int main(int argc, char *argv[])
mgmt_cleanup();
+ disconnect_dbus();
+
info("Exit");
__btd_log_cleanup();
--
1.7.11.3
This patch removes local reference to DBusConnection object and uses
btd_get_dbus_connection() call wherever such object is needed instead.
---
src/main.c | 4 ++--
src/manager.c | 38 ++++++++++++++++++--------------------
src/manager.h | 4 ++--
3 files changed, 22 insertions(+), 24 deletions(-)
diff --git a/src/main.c b/src/main.c
index 31af12a..7593b15 100644
--- a/src/main.c
+++ b/src/main.c
@@ -527,7 +527,7 @@ int main(int argc, char *argv[])
}
}
- if (!manager_init(btd_get_dbus_connection(), "/")) {
+ if (!manager_init("/")) {
error("Can't register manager interface");
exit(1);
}
@@ -554,7 +554,7 @@ int main(int argc, char *argv[])
g_source_remove(signal);
- manager_cleanup(btd_get_dbus_connection(), "/");
+ manager_cleanup("/");
rfkill_exit();
diff --git a/src/manager.c b/src/manager.c
index 31feb84..fe8706b 100644
--- a/src/manager.c
+++ b/src/manager.c
@@ -53,7 +53,6 @@
static char base_path[50] = "/org/bluez";
-static DBusConnection *connection = NULL;
static int default_adapter_id = -1;
static GSList *adapters = NULL;
@@ -192,15 +191,14 @@ static const GDBusSignalTable manager_signals[] = {
{ }
};
-dbus_bool_t manager_init(DBusConnection *conn, const char *path)
+dbus_bool_t manager_init(const char *path)
{
- connection = conn;
-
snprintf(base_path, sizeof(base_path), "/org/bluez/%d", getpid());
- return g_dbus_register_interface(conn, "/", MANAGER_INTERFACE,
- manager_methods, manager_signals,
- NULL, NULL, NULL);
+ return g_dbus_register_interface(btd_get_dbus_connection(),
+ "/", MANAGER_INTERFACE,
+ manager_methods, manager_signals, NULL,
+ NULL, NULL);
}
static void manager_update_adapters(void)
@@ -236,11 +234,10 @@ static void manager_set_default_adapter(int id)
path = adapter_get_path(adapter);
- g_dbus_emit_signal(connection, "/",
- MANAGER_INTERFACE,
- "DefaultAdapterChanged",
- DBUS_TYPE_OBJECT_PATH, &path,
- DBUS_TYPE_INVALID);
+ g_dbus_emit_signal(btd_get_dbus_connection(), "/",
+ MANAGER_INTERFACE, "DefaultAdapterChanged",
+ DBUS_TYPE_OBJECT_PATH, &path,
+ DBUS_TYPE_INVALID);
}
struct btd_adapter *manager_get_default_adapter(void)
@@ -263,10 +260,10 @@ static void manager_remove_adapter(struct btd_adapter *adapter)
manager_set_default_adapter(new_default);
}
- g_dbus_emit_signal(connection, "/",
- MANAGER_INTERFACE, "AdapterRemoved",
- DBUS_TYPE_OBJECT_PATH, &path,
- DBUS_TYPE_INVALID);
+ g_dbus_emit_signal(btd_get_dbus_connection(), "/",
+ MANAGER_INTERFACE, "AdapterRemoved",
+ DBUS_TYPE_OBJECT_PATH, &path,
+ DBUS_TYPE_INVALID);
adapter_remove(adapter);
btd_adapter_unref(adapter);
@@ -275,7 +272,7 @@ static void manager_remove_adapter(struct btd_adapter *adapter)
btd_start_exit_timer();
}
-void manager_cleanup(DBusConnection *conn, const char *path)
+void manager_cleanup(const char *path)
{
while (adapters) {
struct btd_adapter *adapter = adapters->data;
@@ -287,7 +284,8 @@ void manager_cleanup(DBusConnection *conn, const char *path)
btd_start_exit_timer();
- g_dbus_unregister_interface(conn, "/", MANAGER_INTERFACE);
+ g_dbus_unregister_interface(btd_get_dbus_connection(),
+ "/", MANAGER_INTERFACE);
}
static gint adapter_id_cmp(gconstpointer a, gconstpointer b)
@@ -354,7 +352,7 @@ struct btd_adapter *btd_manager_register_adapter(int id, gboolean up)
return NULL;
}
- adapter = adapter_create(connection, id);
+ adapter = adapter_create(btd_get_dbus_connection(), id);
if (!adapter)
return NULL;
@@ -367,7 +365,7 @@ struct btd_adapter *btd_manager_register_adapter(int id, gboolean up)
}
path = adapter_get_path(adapter);
- g_dbus_emit_signal(connection, "/",
+ g_dbus_emit_signal(btd_get_dbus_connection(), "/",
MANAGER_INTERFACE, "AdapterAdded",
DBUS_TYPE_OBJECT_PATH, &path,
DBUS_TYPE_INVALID);
diff --git a/src/manager.h b/src/manager.h
index f3c100e..0bb8b2c 100644
--- a/src/manager.h
+++ b/src/manager.h
@@ -29,8 +29,8 @@
typedef void (*adapter_cb) (struct btd_adapter *adapter, gpointer user_data);
-dbus_bool_t manager_init(DBusConnection *conn, const char *path);
-void manager_cleanup(DBusConnection *conn, const char *path);
+dbus_bool_t manager_init(const char *path);
+void manager_cleanup(const char *path);
const char *manager_get_base_path(void);
struct btd_adapter *manager_find_adapter(const bdaddr_t *sba);
--
1.7.11.3
get_dbus_connection is exported function which can be used by plugins thus
should be prefixed with "btd_"
---
plugins/dbusoob.c | 2 +-
profiles/proximity/immalert.c | 2 +-
profiles/proximity/linkloss.c | 2 +-
profiles/proximity/monitor.c | 15 +++++++++------
profiles/proximity/reporter.c | 4 ++--
src/dbus-common.c | 2 +-
src/dbus-common.h | 2 +-
src/device.c | 28 ++++++++++++++--------------
src/event.c | 10 +++++-----
src/main.c | 2 +-
10 files changed, 36 insertions(+), 33 deletions(-)
diff --git a/plugins/dbusoob.c b/plugins/dbusoob.c
index a7259ba..11b2594 100644
--- a/plugins/dbusoob.c
+++ b/plugins/dbusoob.c
@@ -358,7 +358,7 @@ static int dbusoob_init(void)
{
DBG("Setup dbusoob plugin");
- connection = get_dbus_connection();
+ connection = btd_get_dbus_connection();
oob_register_cb(read_local_data_complete);
diff --git a/profiles/proximity/immalert.c b/profiles/proximity/immalert.c
index d0480e4..ebd788a 100644
--- a/profiles/proximity/immalert.c
+++ b/profiles/proximity/immalert.c
@@ -136,7 +136,7 @@ static void imm_alert_emit_alert_signal(struct connected_device *condev,
DBG("alert %s remote %s", alert_level_str, path);
- emit_property_changed(get_dbus_connection(), path,
+ emit_property_changed(btd_get_dbus_connection(), path,
PROXIMITY_REPORTER_INTERFACE, "ImmediateAlertLevel",
DBUS_TYPE_STRING, &alert_level_str);
}
diff --git a/profiles/proximity/linkloss.c b/profiles/proximity/linkloss.c
index 82df3a1..37d1f86 100644
--- a/profiles/proximity/linkloss.c
+++ b/profiles/proximity/linkloss.c
@@ -137,7 +137,7 @@ static void link_loss_emit_alert_signal(struct connected_device *condev)
DBG("alert %s remote %s", alert_level_str, path);
- emit_property_changed(get_dbus_connection(), path,
+ emit_property_changed(btd_get_dbus_connection(), path,
PROXIMITY_REPORTER_INTERFACE, "LinkLossAlertLevel",
DBUS_TYPE_STRING, &alert_level_str);
}
diff --git a/profiles/proximity/monitor.c b/profiles/proximity/monitor.c
index f7100f9..a9de85b 100644
--- a/profiles/proximity/monitor.c
+++ b/profiles/proximity/monitor.c
@@ -160,7 +160,7 @@ static void linkloss_written(guint8 status, const guint8 *pdu, guint16 plen,
DBG("Link Loss Alert Level written");
- emit_property_changed(get_dbus_connection(), path,
+ emit_property_changed(btd_get_dbus_connection(), path,
PROXIMITY_INTERFACE, "LinkLossAlertLevel",
DBUS_TYPE_STRING, &monitor->linklosslevel);
}
@@ -289,7 +289,8 @@ static gboolean immediate_timeout(gpointer user_data)
g_free(monitor->immediatelevel);
monitor->immediatelevel = g_strdup("none");
- emit_property_changed(get_dbus_connection(), path, PROXIMITY_INTERFACE,
+ emit_property_changed(btd_get_dbus_connection(),
+ path, PROXIMITY_INTERFACE,
"ImmediateAlertLevel", DBUS_TYPE_STRING,
&monitor->immediatelevel);
@@ -304,7 +305,8 @@ static void immediate_written(gpointer user_data)
g_free(monitor->fallbacklevel);
monitor->fallbacklevel = NULL;
- emit_property_changed(get_dbus_connection(), path, PROXIMITY_INTERFACE,
+ emit_property_changed(btd_get_dbus_connection(),
+ path, PROXIMITY_INTERFACE,
"ImmediateAlertLevel",
DBUS_TYPE_STRING, &monitor->immediatelevel);
@@ -390,7 +392,8 @@ static void attio_disconnected_cb(gpointer user_data)
g_free(monitor->immediatelevel);
monitor->immediatelevel = g_strdup("none");
- emit_property_changed(get_dbus_connection(), path, PROXIMITY_INTERFACE,
+ emit_property_changed(btd_get_dbus_connection(),
+ path, PROXIMITY_INTERFACE,
"ImmediateAlertLevel", DBUS_TYPE_STRING,
&monitor->immediatelevel);
}
@@ -607,7 +610,7 @@ int monitor_register(struct btd_device *device,
monitor->signallevel = g_strdup("unknown");
monitor->immediatelevel = g_strdup("none");
- if (g_dbus_register_interface(get_dbus_connection(), path,
+ if (g_dbus_register_interface(btd_get_dbus_connection(), path,
PROXIMITY_INTERFACE,
monitor_methods, monitor_signals,
NULL, monitor, monitor_destroy) == FALSE) {
@@ -663,6 +666,6 @@ void monitor_unregister(struct btd_device *device)
{
const char *path = device_get_path(device);
- g_dbus_unregister_interface(get_dbus_connection(), path,
+ g_dbus_unregister_interface(btd_get_dbus_connection(), path,
PROXIMITY_INTERFACE);
}
diff --git a/profiles/proximity/reporter.c b/profiles/proximity/reporter.c
index 3843018..a425d53 100644
--- a/profiles/proximity/reporter.c
+++ b/profiles/proximity/reporter.c
@@ -199,7 +199,7 @@ static void unregister_reporter_device(gpointer data, gpointer user_data)
DBG("unregister on device %s", path);
- g_dbus_unregister_interface(get_dbus_connection(), path,
+ g_dbus_unregister_interface(btd_get_dbus_connection(), path,
PROXIMITY_REPORTER_INTERFACE);
radapter->devices = g_slist_remove(radapter->devices, device);
@@ -213,7 +213,7 @@ static void register_reporter_device(struct btd_device *device,
DBG("register on device %s", path);
- g_dbus_register_interface(get_dbus_connection(), path,
+ g_dbus_register_interface(btd_get_dbus_connection(), path,
PROXIMITY_REPORTER_INTERFACE,
reporter_methods, reporter_signals,
NULL, device, NULL);
diff --git a/src/dbus-common.c b/src/dbus-common.c
index fb55027..f7e9e8f 100644
--- a/src/dbus-common.c
+++ b/src/dbus-common.c
@@ -175,7 +175,7 @@ void set_dbus_connection(DBusConnection *conn)
connection = conn;
}
-DBusConnection *get_dbus_connection(void)
+DBusConnection *btd_get_dbus_connection(void)
{
return connection;
}
diff --git a/src/dbus-common.h b/src/dbus-common.h
index b9531f2..127cf9c 100644
--- a/src/dbus-common.h
+++ b/src/dbus-common.h
@@ -42,7 +42,7 @@ dbus_bool_t emit_array_property_changed(DBusConnection *conn,
int type, void *value, int num);
void set_dbus_connection(DBusConnection *conn);
-DBusConnection *get_dbus_connection(void);
+DBusConnection *btd_get_dbus_connection(void);
const char *class_to_icon(uint32_t class);
const char *gap_appearance_to_icon(uint16_t appearance);
diff --git a/src/device.c b/src/device.c
index 77215f1..278d721 100644
--- a/src/device.c
+++ b/src/device.c
@@ -821,7 +821,7 @@ static void bonding_request_cancel(struct bonding_req *bonding)
void device_request_disconnect(struct btd_device *device, DBusMessage *msg)
{
- DBusConnection *conn = get_dbus_connection();
+ DBusConnection *conn = btd_get_dbus_connection();
if (device->bonding)
bonding_request_cancel(device->bonding);
@@ -988,7 +988,7 @@ void device_remove_disconnect_watch(struct btd_device *device, guint id)
static void device_set_vendor(struct btd_device *device, uint16_t value)
{
- DBusConnection *conn = get_dbus_connection();
+ DBusConnection *conn = btd_get_dbus_connection();
if (device->vendor == value)
return;
@@ -1001,7 +1001,7 @@ static void device_set_vendor(struct btd_device *device, uint16_t value)
static void device_set_vendor_src(struct btd_device *device, uint16_t value)
{
- DBusConnection *conn = get_dbus_connection();
+ DBusConnection *conn = btd_get_dbus_connection();
if (device->vendor_src == value)
return;
@@ -1014,7 +1014,7 @@ static void device_set_vendor_src(struct btd_device *device, uint16_t value)
static void device_set_product(struct btd_device *device, uint16_t value)
{
- DBusConnection *conn = get_dbus_connection();
+ DBusConnection *conn = btd_get_dbus_connection();
if (device->product == value)
return;
@@ -1027,7 +1027,7 @@ static void device_set_product(struct btd_device *device, uint16_t value)
static void device_set_version(struct btd_device *device, uint16_t value)
{
- DBusConnection *conn = get_dbus_connection();
+ DBusConnection *conn = btd_get_dbus_connection();
if (device->version == value)
return;
@@ -1106,7 +1106,7 @@ struct btd_device *device_create(DBusConnection *conn,
void device_set_name(struct btd_device *device, const char *name)
{
- DBusConnection *conn = get_dbus_connection();
+ DBusConnection *conn = btd_get_dbus_connection();
if (strncmp(name, device->name, MAX_NAME_LENGTH) == 0)
return;
@@ -1154,7 +1154,7 @@ static void device_remove_stored(struct btd_device *device)
{
bdaddr_t src, dst;
uint8_t dst_type;
- DBusConnection *conn = get_dbus_connection();
+ DBusConnection *conn = btd_get_dbus_connection();
adapter_get_address(device->adapter, &src);
device_get_address(device, &dst, &dst_type);
@@ -1382,7 +1382,7 @@ static void device_remove_profiles(struct btd_device *device, GSList *uuids)
static void uuids_changed(struct btd_device *device)
{
- DBusConnection *conn = get_dbus_connection();
+ DBusConnection *conn = btd_get_dbus_connection();
char **uuids;
GSList *l;
int i;
@@ -2077,7 +2077,7 @@ int device_browse_primary(struct btd_device *device, DBusConnection *conn,
done:
if (conn == NULL)
- conn = get_dbus_connection();
+ conn = btd_get_dbus_connection();
req->conn = dbus_connection_ref(conn);
@@ -2129,7 +2129,7 @@ int device_browse_sdp(struct btd_device *device, DBusConnection *conn,
}
if (conn == NULL)
- conn = get_dbus_connection();
+ conn = btd_get_dbus_connection();
req->conn = dbus_connection_ref(conn);
device->browse = req;
@@ -2344,7 +2344,7 @@ static void bonding_request_free(struct bonding_req *bonding)
void device_set_paired(struct btd_device *device, gboolean value)
{
- DBusConnection *conn = get_dbus_connection();
+ DBusConnection *conn = btd_get_dbus_connection();
if (device->paired == value)
return;
@@ -3056,7 +3056,7 @@ struct btd_device *btd_device_ref(struct btd_device *device)
void btd_device_unref(struct btd_device *device)
{
- DBusConnection *conn = get_dbus_connection();
+ DBusConnection *conn = btd_get_dbus_connection();
gchar *path;
device->ref--;
@@ -3075,7 +3075,7 @@ void btd_device_unref(struct btd_device *device)
void device_set_class(struct btd_device *device, uint32_t value)
{
- DBusConnection *conn = get_dbus_connection();
+ DBusConnection *conn = btd_get_dbus_connection();
const char *icon = class_to_icon(value);
emit_property_changed(conn, device->path, DEVICE_INTERFACE, "Class",
@@ -3107,7 +3107,7 @@ int device_get_appearance(struct btd_device *device, uint16_t *value)
void device_set_appearance(struct btd_device *device, uint16_t value)
{
- DBusConnection *conn = get_dbus_connection();
+ DBusConnection *conn = btd_get_dbus_connection();
const char *icon = gap_appearance_to_icon(value);
bdaddr_t src;
diff --git a/src/event.c b/src/event.c
index 3b85961..e720b26 100644
--- a/src/event.c
+++ b/src/event.c
@@ -56,7 +56,7 @@ static gboolean get_adapter_and_device(bdaddr_t *src, bdaddr_t *dst,
struct btd_device **device,
gboolean create)
{
- DBusConnection *conn = get_dbus_connection();
+ DBusConnection *conn = btd_get_dbus_connection();
char peer_addr[18];
*adapter = manager_find_adapter(src);
@@ -483,7 +483,7 @@ void btd_event_conn_failed(bdaddr_t *local, bdaddr_t *peer, uint8_t status)
{
struct btd_adapter *adapter;
struct btd_device *device;
- DBusConnection *conn = get_dbus_connection();
+ DBusConnection *conn = btd_get_dbus_connection();
DBG("status 0x%02x", status);
@@ -521,7 +521,7 @@ void btd_event_device_blocked(bdaddr_t *local, bdaddr_t *peer)
struct btd_adapter *adapter;
struct btd_device *device;
- DBusConnection *conn = get_dbus_connection();
+ DBusConnection *conn = btd_get_dbus_connection();
if (!get_adapter_and_device(local, peer, &adapter, &device, FALSE))
return;
@@ -535,7 +535,7 @@ void btd_event_device_unblocked(bdaddr_t *local, bdaddr_t *peer)
struct btd_adapter *adapter;
struct btd_device *device;
- DBusConnection *conn = get_dbus_connection();
+ DBusConnection *conn = btd_get_dbus_connection();
if (!get_adapter_and_device(local, peer, &adapter, &device, FALSE))
return;
@@ -548,7 +548,7 @@ void btd_event_device_unpaired(bdaddr_t *local, bdaddr_t *peer)
{
struct btd_adapter *adapter;
struct btd_device *device;
- DBusConnection *conn = get_dbus_connection();
+ DBusConnection *conn = btd_get_dbus_connection();
if (!get_adapter_and_device(local, peer, &adapter, &device, FALSE))
return;
diff --git a/src/main.c b/src/main.c
index 34c74ec..249d29e 100644
--- a/src/main.c
+++ b/src/main.c
@@ -383,7 +383,7 @@ void btd_stop_exit_timer(void)
static void disconnect_dbus(void)
{
- DBusConnection *conn = get_dbus_connection();
+ DBusConnection *conn = btd_get_dbus_connection();
if (!conn || !dbus_connection_get_is_connected(conn))
return;
--
1.7.11.3