[PATCH 6/7] Initial steps to manage thermometer objects

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



---
 thermometer/thermometer.c |   63 +++++++++++++++++++++++++++++++++++++++++++++
 1 files changed, 63 insertions(+), 0 deletions(-)

diff --git a/thermometer/thermometer.c b/thermometer/thermometer.c
index a05d37d..b8c0b82 100644
--- a/thermometer/thermometer.c
+++ b/thermometer/thermometer.c
@@ -27,15 +27,78 @@
 
 #include "adapter.h"
 #include "device.h"
+#include "log.h"
 #include "thermometer.h"
 
+struct thermometer {
+	DBusConnection		*conn;	/* The connection to the bus */
+	struct btd_device	*dev;	/* Device reference */
+	gint			ref;	/* Reference counter */
+};
+
+static GSList *thermometers = NULL;
+
+static struct thermometer *thermometer_ref(struct thermometer *t)
+{
+	t->ref++;
+
+	DBG("%p: ref=%d", t, t->ref);
+
+	return t;
+}
+
+static void thermometer_unref(struct thermometer *t)
+{
+	t->ref--;
+
+	DBG("%p: ref=%d", t, t->ref);
+
+	if (t->ref > 0)
+		return;
+
+	dbus_connection_unref(t->conn);
+	btd_device_unref(t->dev);
+	g_free(t);
+}
+
+static gint cmp_device(gconstpointer a, gconstpointer b)
+{
+	const struct thermometer *t = a;
+	const struct btd_device *dev = b;
+
+	if (dev == t->dev)
+		return 0;
+
+	return -1;
+}
+
 int thermometer_register(DBusConnection *connection, struct btd_device *device)
 {
+	struct thermometer *t;
+
+	t = g_new0(struct thermometer, 1);
+	t->conn = dbus_connection_ref(connection);
+	t->dev = btd_device_ref(device);
+
 	/* TODO: Register Health Thermometer Interface */
+
+	thermometers = g_slist_prepend(thermometers, thermometer_ref(t));
+
 	return 0;
 }
 
 void thermometer_unregister(struct btd_device *device)
 {
+	struct thermometer *t;
+	GSList *l;
+
+	l = g_slist_find_custom(thermometers, device, cmp_device);
+	if (!l)
+		return;
+
 	/* TODO: Unregister Health Thermometer Interface */
+
+	t = l->data;
+	thermometers = g_slist_remove(thermometers, t);
+	thermometer_unref(t);
 }
\ No newline at end of file
-- 
1.7.6

--
To unsubscribe from this list: send the line "unsubscribe linux-bluetooth" in
the body of a message to majordomo@xxxxxxxxxxxxxxx
More majordomo info at  http://vger.kernel.org/majordomo-info.html


[Index of Archives]     [Bluez Devel]     [Linux Wireless Networking]     [Linux Wireless Personal Area Networking]     [Linux ATH6KL]     [Linux USB Devel]     [Linux Media Drivers]     [Linux Audio Users]     [Linux Kernel]     [Linux SCSI]     [Big List of Linux Books]

  Powered by Linux