1 From 4f74881432eee7f368ae6827aa2453115749734e Mon Sep 17 00:00:00 2001
2 From: Chengyi Zhao <chengyix.zhao@gmail.com>
3 Date: Sun, 22 Sep 2013 14:14:06 +0800
4 Subject: [PATCH 24/32] Tethering: Watch the connection and disconnection
7 Signed-off-by: Chengyi Zhao <chengyix.zhao@intel.com>
9 Change-Id: I38bb9b799c3e4c4c25acd9d264a4225bf59401dc
11 plugins/bluetooth_legacy.c | 75 ++++++++++++++++++++++++++++++++++++++++++++--
12 1 file changed, 72 insertions(+), 3 deletions(-)
14 diff --git a/plugins/bluetooth_legacy.c b/plugins/bluetooth_legacy.c
15 index a9ff574..5a9a395 100644
16 --- a/plugins/bluetooth_legacy.c
17 +++ b/plugins/bluetooth_legacy.c
19 #define ADAPTER_REMOVED "AdapterRemoved"
20 #define DEVICE_REMOVED "DeviceRemoved"
22 +#define PEER_CONNECTED "PeerConnected"
23 +#define PEER_DISCONNECTED "PeerDisconnected"
25 #define PROPERTY_CHANGED "PropertyChanged"
26 #define GET_PROPERTIES "GetProperties"
27 #define SET_PROPERTY "SetProperty"
28 @@ -334,6 +337,53 @@ static gboolean network_changed(DBusConnection *conn,
32 +static void parse_peer_device(DBusMessage *message, char **dev,
35 + const char *path = dbus_message_get_path(message);
36 + DBusMessageIter iter;
38 + DBG("path %s", path);
40 + if (dbus_message_iter_init(message, &iter) == FALSE)
43 + dbus_message_iter_get_basic(&iter, dev);
44 + dbus_message_iter_next(&iter);
45 + dbus_message_iter_get_basic(&iter, address);
48 +static gboolean peer_connected(DBusConnection *connection,
49 + DBusMessage *message, void *user_data)
51 + char *dev, *address;
53 + parse_peer_device(message, &dev, &address);
55 + DBG("connection device is %s", dev);
56 + DBG("connection address is %s", address);
58 + connman_technology_tethering_add_station(
59 + CONNMAN_SERVICE_TYPE_BLUETOOTH, address);
64 +static gboolean peer_disconnected(DBusConnection *connection,
65 + DBusMessage *message, void *user_data)
67 + char *dev, *address;
69 + parse_peer_device(message, &dev, &address);
71 + DBG("disconnection device is %s", dev);
72 + DBG("disconnection address is %s", address);
74 + connman_technology_tethering_remove_station(address);
79 static void extract_properties(DBusMessage *reply, const char **parent,
82 @@ -1270,6 +1320,8 @@ static guint adapter_watch;
83 static guint device_watch;
84 static guint device_removed_watch;
85 static guint network_watch;
86 +static guint peerconnected_watch;
87 +static guint peerdisconnected_watch;
89 static int bluetooth_init(void)
91 @@ -1313,10 +1365,23 @@ static int bluetooth_init(void)
92 PROPERTY_CHANGED, network_changed,
95 + peerconnected_watch = g_dbus_add_signal_watch(connection,
97 + NULL, BLUEZ_NETWORK_SERVER,
98 + PEER_CONNECTED, peer_connected,
101 + peerdisconnected_watch = g_dbus_add_signal_watch(connection,
103 + NULL, BLUEZ_NETWORK_SERVER,
108 if (watch == 0 || added_watch == 0 || removed_watch == 0
109 - || adapter_watch == 0 || network_watch == 0
110 - || device_watch == 0
111 - || device_removed_watch == 0) {
112 + || adapter_watch == 0 || network_watch == 0 || device_watch == 0
113 + || peerconnected_watch == 0 || peerdisconnected_watch == 0
114 + || device_removed_watch == 0) {
118 @@ -1348,6 +1413,8 @@ remove:
119 g_dbus_remove_watch(connection, device_removed_watch);
120 g_dbus_remove_watch(connection, device_watch);
121 g_dbus_remove_watch(connection, network_watch);
122 + g_dbus_remove_watch(connection, peerconnected_watch);
123 + g_dbus_remove_watch(connection, peerdisconnected_watch);
125 dbus_connection_unref(connection);
127 @@ -1363,6 +1430,8 @@ static void bluetooth_exit(void)
128 g_dbus_remove_watch(connection, device_removed_watch);
129 g_dbus_remove_watch(connection, device_watch);
130 g_dbus_remove_watch(connection, network_watch);
131 + g_dbus_remove_watch(connection, peerconnected_watch);
132 + g_dbus_remove_watch(connection, peerdisconnected_watch);
135 * We unset the disabling of the Bluetooth device when shutting down