From ddaa8ad58cd798c218ed9cc2c798cdaac6ed4924 Mon Sep 17 00:00:00 2001
From: Luiz Augusto von Dentz <luiz.von.dentz@intel.com>
Date: Mon, 26 Sep 2016 16:44:03 +0300
Subject: [PATCH 5/7] input/hog: Use .accept and .disconnect instead of attio

This adds .accept and .disconnect callbacks instead of attio which
is deprecated.
---
 profiles/input/hog.c | 56 ++++++++++++++++++++++++++--------------------------
 src/device.c         |  8 ++++++++
 src/device.h         |  1 +
 3 files changed, 37 insertions(+), 28 deletions(-)

diff --git a/profiles/input/hog.c b/profiles/input/hog.c
index a934c6238525..b25437917188 100644
--- a/profiles/input/hog.c
+++ b/profiles/input/hog.c
@@ -69,24 +69,6 @@ struct hog_device {
 static gboolean suspend_supported = FALSE;
 static struct queue *devices = NULL;
 
-static void attio_connected_cb(GAttrib *attrib, gpointer user_data)
-{
-	struct hog_device *dev = user_data;
-
-	DBG("HoG connected");
-
-	bt_hog_attach(dev->hog, attrib);
-}
-
-static void attio_disconnected_cb(gpointer user_data)
-{
-	struct hog_device *dev = user_data;
-
-	DBG("HoG disconnected");
-
-	bt_hog_detach(dev->hog);
-}
-
 static struct hog_device *hog_device_new(struct btd_device *device,
 						struct gatt_primary *prim)
 {
@@ -115,15 +97,6 @@ static struct hog_device *hog_device_new(struct btd_device *device,
 
 	dev->device = btd_device_ref(device);
 
-	/*
-	 * TODO: Remove attio callback and use .accept once using
-	 * bt_gatt_client.
-	 */
-	dev->attioid = btd_device_add_attio_callback(device,
-							attio_connected_cb,
-							attio_disconnected_cb,
-							dev);
-
 	if (!devices)
 		devices = queue_new();
 
@@ -142,7 +115,6 @@ static void hog_device_free(void *data)
 		devices = NULL;
 	}
 
-	btd_device_remove_attio_callback(dev->device, dev->attioid);
 	btd_device_unref(dev->device);
 	bt_hog_unref(dev->hog);
 	free(dev);
@@ -215,11 +187,39 @@ static void hog_remove(struct btd_service *service)
 	hog_device_free(dev);
 }
 
+static int hog_accept(struct btd_service *service)
+{
+	struct hog_device *dev = btd_service_get_user_data(service);
+	struct btd_device *device = btd_service_get_device(service);
+	GAttrib *attrib = btd_device_get_attrib(device);
+
+	/* TODO: Replace GAttrib with bt_gatt_client */
+	bt_hog_attach(dev->hog, attrib);
+
+	btd_service_connecting_complete(service, 0);
+
+	return 0;
+}
+
+static int hog_disconnect(struct btd_service *service)
+{
+	struct hog_device *dev = btd_service_get_user_data(service);
+
+	bt_hog_detach(dev->hog);
+
+	btd_service_disconnecting_complete(service, 0);
+
+	return 0;
+}
+
 static struct btd_profile hog_profile = {
 	.name		= "input-hog",
 	.remote_uuid	= HOG_UUID,
 	.device_probe	= hog_probe,
 	.device_remove	= hog_remove,
+	.accept		= hog_accept,
+	.disconnect	= hog_disconnect,
+	.auto_connect	= true,
 };
 
 static int hog_init(void)
diff --git a/src/device.c b/src/device.c
index ade74e58a3bf..2a77a2e67232 100644
--- a/src/device.c
+++ b/src/device.c
@@ -5921,6 +5921,14 @@ struct bt_gatt_client *btd_device_get_gatt_client(struct btd_device *device)
 	return device->client;
 }
 
+void *btd_device_get_attrib(struct btd_device *device)
+{
+	if (!device)
+		return NULL;
+
+	return device->attrib;
+}
+
 struct bt_gatt_server *btd_device_get_gatt_server(struct btd_device *device)
 {
 	if (!device)
diff --git a/src/device.h b/src/device.h
index db108278a12e..387f598fb2e5 100644
--- a/src/device.h
+++ b/src/device.h
@@ -70,6 +70,7 @@ GSList *btd_device_get_primaries(struct btd_device *device);
 struct gatt_db *btd_device_get_gatt_db(struct btd_device *device);
 struct bt_gatt_client *btd_device_get_gatt_client(struct btd_device *device);
 struct bt_gatt_server *btd_device_get_gatt_server(struct btd_device *device);
+void *btd_device_get_attrib(struct btd_device *device);
 void btd_device_gatt_set_service_changed(struct btd_device *device,
 						uint16_t start, uint16_t end);
 bool device_attach_att(struct btd_device *dev, GIOChannel *io);
