[PATCH 1/3] Add mode callback to btd_adapter

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

 



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
From 489843b65a43773d678bdfe5a3669e3408fdaccc Mon Sep 17 00:00:00 2001
From: Daniel Orstadius <daniel.orstadius@xxxxxxxxx>
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


[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