meta-oe: fix refactor to a better layout
[scm/bb/meta-tizen.git] / meta-tizen-adaptation-oe-core / recipes-connectivity / connman / connman / 0024-Tethering-Watch-the-connection-and-disconnection-sig.patch
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
5  signal of Bluetooth
6
7 Signed-off-by: Chengyi Zhao <chengyix.zhao@intel.com>
8
9 Change-Id: I38bb9b799c3e4c4c25acd9d264a4225bf59401dc
10 ---
11  plugins/bluetooth_legacy.c | 75 ++++++++++++++++++++++++++++++++++++++++++++--
12  1 file changed, 72 insertions(+), 3 deletions(-)
13
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
18 @@ -51,6 +51,9 @@
19  #define ADAPTER_REMOVED                        "AdapterRemoved"
20  #define DEVICE_REMOVED                 "DeviceRemoved"
21  
22 +#define PEER_CONNECTED                 "PeerConnected"
23 +#define PEER_DISCONNECTED              "PeerDisconnected"
24 +
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,
29         return TRUE;
30  }
31  
32 +static void parse_peer_device(DBusMessage *message, char **dev,
33 +                               char **address)
34 +{
35 +       const char *path = dbus_message_get_path(message);
36 +       DBusMessageIter iter;
37 +
38 +       DBG("path %s", path);
39 +
40 +       if (dbus_message_iter_init(message, &iter) == FALSE)
41 +               return;
42 +
43 +       dbus_message_iter_get_basic(&iter, dev);
44 +       dbus_message_iter_next(&iter);
45 +       dbus_message_iter_get_basic(&iter, address);
46 +}
47 +
48 +static gboolean peer_connected(DBusConnection *connection,
49 +                               DBusMessage *message, void *user_data)
50 +{
51 +       char *dev, *address;
52 +
53 +       parse_peer_device(message, &dev, &address);
54 +
55 +       DBG("connection device is %s", dev);
56 +       DBG("connection address is %s", address);
57 +
58 +       connman_technology_tethering_add_station(
59 +                       CONNMAN_SERVICE_TYPE_BLUETOOTH, address);
60 +
61 +       return TRUE;
62 +}
63 +
64 +static gboolean peer_disconnected(DBusConnection *connection,
65 +                               DBusMessage *message, void *user_data)
66 +{
67 +       char *dev, *address;
68 +
69 +       parse_peer_device(message, &dev, &address);
70 +
71 +       DBG("disconnection device is %s", dev);
72 +       DBG("disconnection address is %s", address);
73 +
74 +       connman_technology_tethering_remove_station(address);
75 +
76 +       return TRUE;
77 +}
78 +
79  static void extract_properties(DBusMessage *reply, const char **parent,
80                                                 const char **address,
81                                                 const char **name,
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;
88  
89  static int bluetooth_init(void)
90  {
91 @@ -1313,10 +1365,23 @@ static int bluetooth_init(void)
92                                                 PROPERTY_CHANGED, network_changed,
93                                                 NULL, NULL);
94  
95 +       peerconnected_watch = g_dbus_add_signal_watch(connection,
96 +                                               BLUEZ_SERVICE,
97 +                                               NULL, BLUEZ_NETWORK_SERVER,
98 +                                               PEER_CONNECTED, peer_connected,
99 +                                               NULL, NULL);
100 +
101 +       peerdisconnected_watch = g_dbus_add_signal_watch(connection,
102 +                                               BLUEZ_SERVICE,
103 +                                               NULL, BLUEZ_NETWORK_SERVER,
104 +                                               PEER_DISCONNECTED,
105 +                                               peer_disconnected,
106 +                                               NULL, NULL);
107 +
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) {
115                 err = -EIO;
116                 goto remove;
117         }
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);
124  
125         dbus_connection_unref(connection);
126  
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);
133  
134         /*
135          * We unset the disabling of the Bluetooth device when shutting down
136 -- 
137 1.8.1.4
138