Linux bluetooth development
 help / color / mirror / Atom feed
* [PATCH 1/3] Add mode callback to btd_adapter
@ 2010-08-13  9:18 Daniel Örstadius
  2010-08-13 12:41 ` Johan Hedberg
  0 siblings, 1 reply; 4+ messages in thread
From: Daniel Örstadius @ 2010-08-13  9:18 UTC (permalink / raw)
  To: linux-bluetooth

[-- Attachment #1: Type: text/plain, Size: 346 bytes --]

With this patch callback functions can be registered to the
btd_adapter struct. The functions are then called when the powered
state of the adapter changes, with a boolean argument indicating
the new state. The reason for adding the functionality is that the
Maemo6 MCE plugin needs to be notified when the adapter is powered
on or off.

/Daniel

[-- Attachment #2: 0001-Add-mode-callback-to-btd_adapter.patch --]
[-- Type: text/x-patch, Size: 2710 bytes --]

From 489843b65a43773d678bdfe5a3669e3408fdaccc Mon Sep 17 00:00:00 2001
From: Daniel Orstadius <daniel.orstadius@nokia.com>
Date: Fri, 13 Aug 2010 10:30:37 +0300
Subject: [PATCH] Add mode callback to btd_adapter

With this patch callback functions can be registered to the
btd_adapter struct. The functions are then called when the powered
state of the adapter changes, with a boolean argument indicating
the new state. The reason for adding the functionality is that the
Maemo6 MCE plugin needs to be notified when the adapter is powered
on or off.
---
 src/adapter.c |   25 +++++++++++++++++++++++++
 src/adapter.h |    4 ++++
 2 files changed, 29 insertions(+), 0 deletions(-)

diff --git a/src/adapter.c b/src/adapter.c
index fc1e123..ff78539 100644
--- a/src/adapter.c
+++ b/src/adapter.c
@@ -135,6 +135,8 @@ struct btd_adapter {
 	gboolean cache_enable;
 
 	gint ref;
+
+	GSList *mode_callbacks;
 };
 
 static void adapter_set_pairable_timeout(struct btd_adapter *adapter,
@@ -2203,6 +2205,18 @@ static void adapter_disable_cod_cache(struct btd_adapter *adapter)
 		adapter->pending_cod = adapter->wanted_cod;
 }
 
+static void adapter_mode_callbacks(struct btd_adapter *adapter,
+						gboolean powered)
+{
+	GSList *l;
+
+	for (l = adapter->mode_callbacks; l; l = l->next) {
+		btd_adapter_mode_cb cb = l->data;
+
+		cb(adapter, powered);
+       }
+}
+
 static int adapter_up(struct btd_adapter *adapter, const char *mode)
 {
 	char srcaddr[18];
@@ -2283,6 +2297,8 @@ proceed:
 					ADAPTER_INTERFACE, "Powered",
 					DBUS_TYPE_BOOLEAN, &powered);
 
+	adapter_mode_callbacks(adapter, TRUE);
+
 	adapter_disable_cod_cache(adapter);
 
 	return 0;
@@ -2487,6 +2503,8 @@ int adapter_stop(struct btd_adapter *adapter)
 	adapter->cache_enable = TRUE;
 	adapter->pending_cod = 0;
 
+	adapter_mode_callbacks(adapter, FALSE);
+
 	info("Adapter %s has been disabled", adapter->path);
 
 	return 0;
@@ -3422,3 +3440,10 @@ int adapter_ops_setup(void)
 
 	return adapter_ops->setup();
 }
+
+void btd_adapter_register_mode_callback(struct btd_adapter *adapter,
+						btd_adapter_mode_cb cb)
+{
+	adapter->mode_callbacks =
+			g_slist_append(adapter->mode_callbacks, cb);
+}
diff --git a/src/adapter.h b/src/adapter.h
index a7eca0e..9c7cdf2 100644
--- a/src/adapter.h
+++ b/src/adapter.h
@@ -188,3 +188,7 @@ struct btd_adapter_ops {
 int btd_register_adapter_ops(struct btd_adapter_ops *btd_adapter_ops);
 void btd_adapter_cleanup_ops(struct btd_adapter_ops *btd_adapter_ops);
 int adapter_ops_setup(void);
+typedef void (*btd_adapter_mode_cb) (struct btd_adapter *adapter,
+						gboolean powered);
+void btd_adapter_register_mode_callback(struct btd_adapter *adapter,
+						btd_adapter_mode_cb cb);
-- 
1.6.0.4


^ permalink raw reply related	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2010-08-17  8:28 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2010-08-13  9:18 [PATCH 1/3] Add mode callback to btd_adapter Daniel Örstadius
2010-08-13 12:41 ` Johan Hedberg
2010-08-13 13:43   ` Daniel Örstadius
2010-08-17  8:28     ` Johan Hedberg

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox