diff --git a/src/device.c b/src/device.c
index 8836194..6362130 100644
--- a/src/device.c
+++ b/src/device.c
#define DISCONNECT_TIMER 2
#define DISCOVERY_TIMER 1
+static DBusConnection *dbus_conn = NULL;
+
struct btd_disconnect_data {
guint id;
disconnect_watch watch;
static void browse_request_free(struct browse_req *req)
{
if (req->listener_id)
- g_dbus_remove_watch(btd_get_dbus_connection(),
- req->listener_id);
+ g_dbus_remove_watch(dbus_conn, req->listener_id);
if (req->msg)
dbus_message_unref(req->msg);
if (req->device)
store_device_info(device);
- g_dbus_emit_property_changed(btd_get_dbus_connection(),
- device->path, DEVICE_INTERFACE, "Alias");
+ g_dbus_emit_property_changed(dbus_conn, device->path,
+ DEVICE_INTERFACE, "Alias");
g_dbus_pending_property_success(id);
}
store_device_info(device);
- g_dbus_emit_property_changed(btd_get_dbus_connection(),
- device->path, DEVICE_INTERFACE, "Trusted");
+ g_dbus_emit_property_changed(dbus_conn, device->path,
+ DEVICE_INTERFACE, "Trusted");
g_dbus_pending_property_success(id);
}
device_set_temporary(device, FALSE);
- g_dbus_emit_property_changed(btd_get_dbus_connection(), device->path,
+ g_dbus_emit_property_changed(dbus_conn, device->path,
DEVICE_INTERFACE, "Blocked");
return 0;
store_device_info(device);
if (!silent) {
- g_dbus_emit_property_changed(btd_get_dbus_connection(),
- device->path, DEVICE_INTERFACE,
- "Blocked");
+ g_dbus_emit_property_changed(dbus_conn, device->path,
+ DEVICE_INTERFACE, "Blocked");
device_probe_profiles(device, device->uuids);
}
if (device->connect) {
DBusMessage *reply = btd_error_failed(device->connect,
"Cancelled");
- g_dbus_send_message(btd_get_dbus_connection(), reply);
+ g_dbus_send_message(dbus_conn, reply);
dbus_message_unref(device->connect);
device->connect = NULL;
}
DBG("returning response to %s", dbus_message_get_sender(dev->connect));
if (err && dev->connected_profiles == NULL)
- g_dbus_send_message(btd_get_dbus_connection(),
+ g_dbus_send_message(dbus_conn,
btd_error_failed(dev->connect, strerror(-err)));
else
- g_dbus_send_reply(btd_get_dbus_connection(), dev->connect,
- DBUS_TYPE_INVALID);
+ g_dbus_send_reply(dbus_conn, dev->connect, DBUS_TYPE_INVALID);
g_slist_free(dev->pending);
dev->pending = NULL;
}
if (added)
- g_dbus_emit_property_changed(btd_get_dbus_connection(),
- dev->path, DEVICE_INTERFACE,
- "UUIDs");
+ g_dbus_emit_property_changed(dbus_conn, dev->path,
+ DEVICE_INTERFACE, "UUIDs");
}
static int device_resolve_svc(struct btd_device *dev, DBusMessage *msg)
return;
if (err)
- g_dbus_send_message(btd_get_dbus_connection(),
+ g_dbus_send_message(dbus_conn,
btd_error_failed(dev->disconnect,
strerror(-err)));
else
- g_dbus_send_reply(btd_get_dbus_connection(), dev->disconnect,
+ g_dbus_send_reply(dbus_conn, dev->disconnect,
DBUS_TYPE_INVALID);
dbus_message_unref(dev->disconnect);
static void device_svc_resolved(struct btd_device *dev, int err)
{
DBusMessage *reply;
- DBusConnection *conn = btd_get_dbus_connection();
struct browse_req *req = dev->browse;
dev->svc_resolved = true;
if (dbus_message_is_method_call(req->msg, DEVICE_INTERFACE,
"Pair")) {
reply = dbus_message_new_method_return(req->msg);
- g_dbus_send_message(conn, reply);
+ g_dbus_send_message(dbus_conn, reply);
return;
}
if (err) {
reply = btd_error_failed(req->msg, strerror(-err));
- g_dbus_send_message(conn, reply);
+ g_dbus_send_message(dbus_conn, reply);
return;
}
if (dbus_message_is_method_call(req->msg, DEVICE_INTERFACE, "Connect"))
- reply = dev_connect(conn, req->msg, dev);
+ reply = dev_connect(dbus_conn, req->msg, dev);
else if (dbus_message_is_method_call(req->msg, DEVICE_INTERFACE,
"ConnectProfile"))
- reply = connect_profile(conn, req->msg, dev);
+ reply = connect_profile(dbus_conn, req->msg, dev);
else
return;
req->msg = NULL;
if (reply)
- g_dbus_send_message(conn, reply);
+ g_dbus_send_message(dbus_conn, reply);
}
static struct bonding_req *bonding_request_new(DBusMessage *msg,
if (agent)
agent_unref(agent);
- bonding->listener_id = g_dbus_add_disconnect_watch(
- btd_get_dbus_connection(),
+ bonding->listener_id = g_dbus_add_disconnect_watch(dbus_conn,
sender, create_bond_req_exit,
device, NULL);
return;
if (bonding->listener_id)
- g_dbus_remove_watch(btd_get_dbus_connection(),
- bonding->listener_id);
+ g_dbus_remove_watch(dbus_conn, bonding->listener_id);
if (bonding->msg)
dbus_message_unref(bonding->msg);
device_cancel_authentication(device, FALSE);
reply = new_authentication_return(bonding->msg, status);
- g_dbus_send_message(btd_get_dbus_connection(), reply);
+ g_dbus_send_message(dbus_conn, reply);
bonding_request_cancel(bonding);
bonding_request_free(bonding);
device->connected = TRUE;
- g_dbus_emit_property_changed(btd_get_dbus_connection(), device->path,
+ g_dbus_emit_property_changed(dbus_conn, device->path,
DEVICE_INTERFACE, "Connected");
}
while (device->disconnects) {
DBusMessage *msg = device->disconnects->data;
- g_dbus_send_reply(btd_get_dbus_connection(),
- msg, DBUS_TYPE_INVALID);
+ g_dbus_send_reply(dbus_conn, msg, DBUS_TYPE_INVALID);
device->disconnects = g_slist_remove(device->disconnects, msg);
dbus_message_unref(msg);
}
if (device_is_paired(device) && !device_is_bonded(device))
device_set_paired(device, FALSE);
- g_dbus_emit_property_changed(btd_get_dbus_connection(), device->path,
+ g_dbus_emit_property_changed(dbus_conn, device->path,
DEVICE_INTERFACE, "Connected");
}
DBG("Creating device %s", device->path);
- if (g_dbus_register_interface(btd_get_dbus_connection(),
+ if (g_dbus_register_interface(dbus_conn,
device->path, DEVICE_INTERFACE,
device_methods, NULL,
device_properties, device,
store_device_info(device);
- g_dbus_emit_property_changed(btd_get_dbus_connection(), device->path,
+ g_dbus_emit_property_changed(dbus_conn, device->path,
DEVICE_INTERFACE, "Name");
if (device->alias != NULL)
return;
- g_dbus_emit_property_changed(btd_get_dbus_connection(), device->path,
+ g_dbus_emit_property_changed(dbus_conn, device->path,
DEVICE_INTERFACE, "Alias");
}
store_device_info(device);
- g_dbus_emit_property_changed(btd_get_dbus_connection(), device->path,
+ g_dbus_emit_property_changed(dbus_conn, device->path,
DEVICE_INTERFACE, "Class");
}
}
device->svc_resolved = true;
- g_dbus_emit_property_changed(btd_get_dbus_connection(),
- device->path, DEVICE_INTERFACE,
- "UUIDs");
+ g_dbus_emit_property_changed(dbus_conn, device->path,
+ DEVICE_INTERFACE, "UUIDs");
}
static void device_remove_profiles(struct btd_device *device, GSList *uuids)
device_remove_profiles(device, req->profiles_removed);
/* Propagate services changes */
- g_dbus_emit_property_changed(btd_get_dbus_connection(),
- req->device->path, DEVICE_INTERFACE,
- "UUIDs");
+ g_dbus_emit_property_changed(dbus_conn, req->device->path,
+ DEVICE_INTERFACE, "UUIDs");
send_reply:
device_svc_resolved(device, err);
if (device->attios == NULL && device->attios_offline == NULL)
attio_cleanup(device);
- g_dbus_emit_property_changed(btd_get_dbus_connection(), device->path,
+ g_dbus_emit_property_changed(dbus_conn, device->path,
DEVICE_INTERFACE, "UUIDs");
device_svc_resolved(device, 0);
DBusMessage *reply;
reply = btd_error_failed(req->msg,
att_ecode2str(status));
- g_dbus_send_message(btd_get_dbus_connection(), reply);
+ g_dbus_send_message(dbus_conn, reply);
}
device->browse = NULL;
if (err < 0) {
DBusMessage *reply = btd_error_failed(device->bonding->msg,
strerror(-err));
- g_dbus_send_message(btd_get_dbus_connection(), reply);
+ g_dbus_send_message(dbus_conn, reply);
bonding_request_cancel(device->bonding);
bonding_request_free(device->bonding);
}
if (io == NULL) {
DBusMessage *reply = btd_error_failed(
device->bonding->msg, gerr->message);
- g_dbus_send_message(btd_get_dbus_connection(), reply);
+ g_dbus_send_message(dbus_conn, reply);
bonding_request_cancel(device->bonding);
bonding_request_free(device->bonding);
}
DBusMessage *reply;
reply = btd_error_failed(req->msg, gerr->message);
- g_dbus_send_message(btd_get_dbus_connection(), reply);
+ g_dbus_send_message(dbus_conn, reply);
}
device->browse = NULL;
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(
- btd_get_dbus_connection(),
+ req->listener_id = g_dbus_add_disconnect_watch(dbus_conn,
sender,
discover_services_req_exit,
req, NULL);
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(
- btd_get_dbus_connection(),
+ req->listener_id = g_dbus_add_disconnect_watch(dbus_conn,
sender,
discover_services_req_exit,
req, NULL);
device->legacy = legacy;
- g_dbus_emit_property_changed(btd_get_dbus_connection(), device->path,
+ g_dbus_emit_property_changed(dbus_conn, device->path,
DEVICE_INTERFACE, "LegacyPairing");
}
device->rssi = rssi;
}
- g_dbus_emit_property_changed(btd_get_dbus_connection(), device->path,
+ g_dbus_emit_property_changed(dbus_conn, device->path,
DEVICE_INTERFACE, "RSSI");
}
device->paired = value;
- g_dbus_emit_property_changed(btd_get_dbus_connection(), device->path,
+ g_dbus_emit_property_changed(dbus_conn, device->path,
DEVICE_INTERFACE, "Paired");
}
device_cancel_authentication(device, FALSE);
reply = new_authentication_return(bonding->msg, status);
- g_dbus_send_message(btd_get_dbus_connection(), reply);
+ g_dbus_send_message(dbus_conn, reply);
bonding_request_free(bonding);
}
store_device_info(device);
- g_dbus_emit_property_changed(btd_get_dbus_connection(), device->path,
+ g_dbus_emit_property_changed(dbus_conn, device->path,
DEVICE_INTERFACE, "UUIDs");
}
path = g_strdup(device->path);
- g_dbus_unregister_interface(btd_get_dbus_connection(),
- path, DEVICE_INTERFACE);
+ g_dbus_unregister_interface(dbus_conn, path, DEVICE_INTERFACE);
g_free(path);
}
{
const char *icon = gap_appearance_to_icon(value);
- g_dbus_emit_property_changed(btd_get_dbus_connection(), device->path,
+ g_dbus_emit_property_changed(dbus_conn, device->path,
DEVICE_INTERFACE, "Appearance");
if (icon)
- g_dbus_emit_property_changed(btd_get_dbus_connection(),
- device->path, DEVICE_INTERFACE, "Icon");
+ g_dbus_emit_property_changed(dbus_conn, device->path,
+ DEVICE_INTERFACE, "Icon");
device->appearance = value;
store_device_info(device);
g_free(device->modalias);
device->modalias = bt_modalias(source, vendor, product, version);
- g_dbus_emit_property_changed(btd_get_dbus_connection(), device->path,
+ g_dbus_emit_property_changed(dbus_conn, device->path,
DEVICE_INTERFACE, "Modalias");
store_device_info(device);
void btd_device_init(void)
{
+ dbus_conn = btd_get_dbus_connection();
}
void btd_device_cleanup(void)
{
+ dbus_conn = NULL;
}