From dd80cad906f33d39cc900b1ae2e5fd3de29fe4ce Mon Sep 17 00:00:00 2001 From: Johan Hedberg Date: Thu, 13 Mar 2014 16:58:51 +0200 Subject: [PATCH] core: Refactor calls to attrib_channel_attach This patch creates a new public device_attach_attrib function to deal with attrib_channel_attach. This is needed so we get a central place which can also be used by attrib-server.c (which the next patch deals with). --- src/device.c | 38 +++++++++++++++++++++++++------------- src/device.h | 1 + 2 files changed, 26 insertions(+), 13 deletions(-) diff --git a/src/device.c b/src/device.c index c06ee0bec..300c2ba64 100644 --- a/src/device.c +++ b/src/device.c @@ -3443,13 +3443,36 @@ static void primary_cb(uint8_t status, GSList *services, void *user_data) find_included_services(req, services); } +bool device_attach_attrib(struct btd_device *dev, GIOChannel *io) +{ + GAttrib *attrib; + + attrib = g_attrib_new(io); + if (!attrib) { + error("Unable to create new GAttrib instance"); + return false; + } + + dev->attachid = attrib_channel_attach(attrib); + if (dev->attachid == 0) { + g_attrib_unref(attrib); + error("Attribute server attach failure!"); + return false; + } + + dev->attrib = attrib; + dev->cleanup_id = g_io_add_watch(io, G_IO_HUP, + attrib_disconnected_cb, dev); + + return true; +} + static void att_connect_cb(GIOChannel *io, GError *gerr, gpointer user_data) { struct att_callbacks *attcb = user_data; struct btd_device *device = attcb->user_data; DBusMessage *reply; uint8_t io_cap; - GAttrib *attrib; int err = 0; g_io_channel_unref(device->att_io); @@ -3465,19 +3488,8 @@ static void att_connect_cb(GIOChannel *io, GError *gerr, gpointer user_data) goto done; } - attrib = g_attrib_new(io); - if (!attrib) { - error("Unable to create new GAttrib instance"); + if (!device_attach_attrib(device, io)) goto done; - } - - device->attachid = attrib_channel_attach(attrib); - if (device->attachid == 0) - error("Attribute server attach failure!"); - - device->attrib = attrib; - device->cleanup_id = g_io_add_watch(io, G_IO_HUP, - attrib_disconnected_cb, device); if (attcb->success) attcb->success(user_data); diff --git a/src/device.h b/src/device.h index d8e4df247..66b257de9 100644 --- a/src/device.h +++ b/src/device.h @@ -60,6 +60,7 @@ struct gatt_primary *btd_device_get_primary(struct btd_device *device, 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); +bool device_attach_attrib(struct btd_device *dev, GIOChannel *io); void btd_device_add_uuid(struct btd_device *device, const char *uuid); void device_add_eir_uuids(struct btd_device *dev, GSList *uuids); void device_probe_profile(gpointer a, gpointer b); -- 2.47.3