linux-bluetooth.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Santiago Carot-Nemesio <sancane@gmail.com>
To: linux-bluetooth@vger.kernel.org
Cc: Santiago Carot-Nemesio <sancane@gmail.com>
Subject: [PATCH 6/7] Initial steps to manage thermometer objects
Date: Mon, 18 Jul 2011 15:10:41 +0200	[thread overview]
Message-ID: <1310994642-16375-6-git-send-email-sancane@gmail.com> (raw)
In-Reply-To: <1310994642-16375-5-git-send-email-sancane@gmail.com>

---
 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


  reply	other threads:[~2011-07-18 13:10 UTC|newest]

Thread overview: 7+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2011-07-18 13:10 [PATCH 1/7] Initial support for Health Thermometer Profile (HTP) Santiago Carot-Nemesio
2011-07-18 13:10 ` [PATCH 2/7] Add manager files for HTP Santiago Carot-Nemesio
2011-07-18 13:10   ` [PATCH 3/7] Load HTP plugin only if LE is enabled Santiago Carot-Nemesio
2011-07-18 13:10     ` [PATCH 4/7] Register thermometer driver Santiago Carot-Nemesio
2011-07-18 13:10       ` [PATCH 5/7] Add thermometer driver skeleton Santiago Carot-Nemesio
2011-07-18 13:10         ` Santiago Carot-Nemesio [this message]
2011-07-18 13:10           ` [PATCH 7/7] Release resources allocated when the thermometer plugin is stopped Santiago Carot-Nemesio

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=1310994642-16375-6-git-send-email-sancane@gmail.com \
    --to=sancane@gmail.com \
    --cc=linux-bluetooth@vger.kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).