Diff between 76384036b43f97e171ef189caae58226df35084a and dd80cad906f33d39cc900b1ae2e5fd3de29fe4ce

Changed Files

File Additions Deletions Status
src/device.c +25 -13 modified
src/device.h +1 -0 modified

Full Patch

diff --git a/src/device.c b/src/device.c
index c06ee0b..300c2ba 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 d8e4df2..66b257d 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);