summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorChengyi Zhao <chengyix.zhao@gmail.com>2013-09-22 14:14:06 +0800
committerZhang zhengguang <zhengguang.zhang@intel.com>2014-07-31 15:51:58 +0800
commit5debe1bbb96daac56ff7685221b20c770d9fc65f (patch)
treee4127d9c86eab0ebaecf16f86bd98e42a4dd76b0
parent514f99422eecb6b8970546cd2f3a6c71e501067c (diff)
downloadconnman-5debe1bbb96daac56ff7685221b20c770d9fc65f.tar.gz
connman-5debe1bbb96daac56ff7685221b20c770d9fc65f.tar.bz2
connman-5debe1bbb96daac56ff7685221b20c770d9fc65f.zip
Tethering: Watch the connection and disconnection signal of Bluetooth
Signed-off-by: Chengyi Zhao <chengyix.zhao@intel.com> Change-Id: I38bb9b799c3e4c4c25acd9d264a4225bf59401dc
-rw-r--r--plugins/bluetooth_legacy.c75
1 files changed, 72 insertions, 3 deletions
diff --git a/plugins/bluetooth_legacy.c b/plugins/bluetooth_legacy.c
index a9ff5743..5a9a3955 100644
--- a/plugins/bluetooth_legacy.c
+++ b/plugins/bluetooth_legacy.c
@@ -51,6 +51,9 @@
#define ADAPTER_REMOVED "AdapterRemoved"
#define DEVICE_REMOVED "DeviceRemoved"
+#define PEER_CONNECTED "PeerConnected"
+#define PEER_DISCONNECTED "PeerDisconnected"
+
#define PROPERTY_CHANGED "PropertyChanged"
#define GET_PROPERTIES "GetProperties"
#define SET_PROPERTY "SetProperty"
@@ -334,6 +337,53 @@ static gboolean network_changed(DBusConnection *conn,
return TRUE;
}
+static void parse_peer_device(DBusMessage *message, char **dev,
+ char **address)
+{
+ const char *path = dbus_message_get_path(message);
+ DBusMessageIter iter;
+
+ DBG("path %s", path);
+
+ if (dbus_message_iter_init(message, &iter) == FALSE)
+ return;
+
+ dbus_message_iter_get_basic(&iter, dev);
+ dbus_message_iter_next(&iter);
+ dbus_message_iter_get_basic(&iter, address);
+}
+
+static gboolean peer_connected(DBusConnection *connection,
+ DBusMessage *message, void *user_data)
+{
+ char *dev, *address;
+
+ parse_peer_device(message, &dev, &address);
+
+ DBG("connection device is %s", dev);
+ DBG("connection address is %s", address);
+
+ connman_technology_tethering_add_station(
+ CONNMAN_SERVICE_TYPE_BLUETOOTH, address);
+
+ return TRUE;
+}
+
+static gboolean peer_disconnected(DBusConnection *connection,
+ DBusMessage *message, void *user_data)
+{
+ char *dev, *address;
+
+ parse_peer_device(message, &dev, &address);
+
+ DBG("disconnection device is %s", dev);
+ DBG("disconnection address is %s", address);
+
+ connman_technology_tethering_remove_station(address);
+
+ return TRUE;
+}
+
static void extract_properties(DBusMessage *reply, const char **parent,
const char **address,
const char **name,
@@ -1270,6 +1320,8 @@ static guint adapter_watch;
static guint device_watch;
static guint device_removed_watch;
static guint network_watch;
+static guint peerconnected_watch;
+static guint peerdisconnected_watch;
static int bluetooth_init(void)
{
@@ -1313,10 +1365,23 @@ static int bluetooth_init(void)
PROPERTY_CHANGED, network_changed,
NULL, NULL);
+ peerconnected_watch = g_dbus_add_signal_watch(connection,
+ BLUEZ_SERVICE,
+ NULL, BLUEZ_NETWORK_SERVER,
+ PEER_CONNECTED, peer_connected,
+ NULL, NULL);
+
+ peerdisconnected_watch = g_dbus_add_signal_watch(connection,
+ BLUEZ_SERVICE,
+ NULL, BLUEZ_NETWORK_SERVER,
+ PEER_DISCONNECTED,
+ peer_disconnected,
+ NULL, NULL);
+
if (watch == 0 || added_watch == 0 || removed_watch == 0
- || adapter_watch == 0 || network_watch == 0
- || device_watch == 0
- || device_removed_watch == 0) {
+ || adapter_watch == 0 || network_watch == 0 || device_watch == 0
+ || peerconnected_watch == 0 || peerdisconnected_watch == 0
+ || device_removed_watch == 0) {
err = -EIO;
goto remove;
}
@@ -1348,6 +1413,8 @@ remove:
g_dbus_remove_watch(connection, device_removed_watch);
g_dbus_remove_watch(connection, device_watch);
g_dbus_remove_watch(connection, network_watch);
+ g_dbus_remove_watch(connection, peerconnected_watch);
+ g_dbus_remove_watch(connection, peerdisconnected_watch);
dbus_connection_unref(connection);
@@ -1363,6 +1430,8 @@ static void bluetooth_exit(void)
g_dbus_remove_watch(connection, device_removed_watch);
g_dbus_remove_watch(connection, device_watch);
g_dbus_remove_watch(connection, network_watch);
+ g_dbus_remove_watch(connection, peerconnected_watch);
+ g_dbus_remove_watch(connection, peerdisconnected_watch);
/*
* We unset the disabling of the Bluetooth device when shutting down