Diff between 6ba4ea63efe5376064dfb267f8bc46e1ad5ec328 and afc8cdfb40888c6029d7fdbbf902e9e55dfcd758

Changed Files

File Additions Deletions Status
profiles/audio/manager.c +13 -19 modified
profiles/input/device.c +5 -8 modified
profiles/input/device.h +3 -4 modified
profiles/network/manager.c +20 -20 modified
src/device.c +10 -10 modified
src/device.h +7 -0 modified
src/profile.c +8 -10 modified
src/profile.h +5 -6 modified

Full Patch

diff --git a/profiles/audio/manager.c b/profiles/audio/manager.c
index 3498945..689a309 100644
--- a/profiles/audio/manager.c
+++ b/profiles/audio/manager.c
@@ -199,14 +199,13 @@ static void profile_cb(struct audio_device *dev, int err, void *data)
 	struct profile_req *req = data;
 
 	if (req->cb)
-		req->cb(req->profile, req->device, err);
+		req->cb(req->device, req->profile, err);
 
 	g_free(req);
 }
 
 static int a2dp_source_connect(struct btd_device *dev,
-						struct btd_profile *profile,
-						btd_profile_cb cb)
+						struct btd_profile *profile)
 {
 	const gchar *path = device_get_path(dev);
 	struct audio_device *audio_dev;
@@ -221,7 +220,7 @@ static int a2dp_source_connect(struct btd_device *dev,
 		return -1;
 	}
 
-	req = new_profile_request(dev, profile, cb);
+	req = new_profile_request(dev, profile, device_profile_connected);
 
 	err = source_connect(audio_dev, profile_cb, req);
 	if (err < 0) {
@@ -233,8 +232,7 @@ static int a2dp_source_connect(struct btd_device *dev,
 }
 
 static int a2dp_source_disconnect(struct btd_device *dev,
-						struct btd_profile *profile,
-						btd_profile_cb cb)
+						struct btd_profile *profile)
 {
 	const gchar *path = device_get_path(dev);
 	struct audio_device *audio_dev;
@@ -249,7 +247,7 @@ static int a2dp_source_disconnect(struct btd_device *dev,
 		return -1;
 	}
 
-	req = new_profile_request(dev, profile, cb);
+	req = new_profile_request(dev, profile, device_profile_disconnected);
 
 	err = source_disconnect(audio_dev, FALSE, profile_cb, req);
 	if (err < 0) {
@@ -261,8 +259,7 @@ static int a2dp_source_disconnect(struct btd_device *dev,
 }
 
 static int a2dp_sink_connect(struct btd_device *dev,
-						struct btd_profile *profile,
-						btd_profile_cb cb)
+						struct btd_profile *profile)
 {
 	const gchar *path = device_get_path(dev);
 	struct audio_device *audio_dev;
@@ -277,7 +274,7 @@ static int a2dp_sink_connect(struct btd_device *dev,
 		return -1;
 	}
 
-	req = new_profile_request(dev, profile, cb);
+	req = new_profile_request(dev, profile, device_profile_connected);
 
 	err = sink_connect(audio_dev, profile_cb, req);
 	if (err < 0) {
@@ -289,8 +286,7 @@ static int a2dp_sink_connect(struct btd_device *dev,
 }
 
 static int a2dp_sink_disconnect(struct btd_device *dev,
-						struct btd_profile *profile,
-						btd_profile_cb cb)
+						struct btd_profile *profile)
 {
 	const gchar *path = device_get_path(dev);
 	struct audio_device *audio_dev;
@@ -305,7 +301,7 @@ static int a2dp_sink_disconnect(struct btd_device *dev,
 		return -1;
 	}
 
-	req = new_profile_request(dev, profile, cb);
+	req = new_profile_request(dev, profile, device_profile_disconnected);
 
 	err = sink_disconnect(audio_dev, FALSE, profile_cb, req);
 	if (err < 0) {
@@ -317,8 +313,7 @@ static int a2dp_sink_disconnect(struct btd_device *dev,
 }
 
 static int avrcp_control_connect(struct btd_device *dev,
-						struct btd_profile *profile,
-						btd_profile_cb cb)
+						struct btd_profile *profile)
 {
 	const gchar *path = device_get_path(dev);
 	struct audio_device *audio_dev;
@@ -333,7 +328,7 @@ static int avrcp_control_connect(struct btd_device *dev,
 		return -1;
 	}
 
-	req = new_profile_request(dev, profile, cb);
+	req = new_profile_request(dev, profile, device_profile_connected);
 
 	err = control_connect(audio_dev, profile_cb, req);
 	if (err < 0) {
@@ -345,8 +340,7 @@ static int avrcp_control_connect(struct btd_device *dev,
 }
 
 static int avrcp_control_disconnect(struct btd_device *dev,
-						struct btd_profile *profile,
-						btd_profile_cb cb)
+						struct btd_profile *profile)
 {
 	const gchar *path = device_get_path(dev);
 	struct audio_device *audio_dev;
@@ -361,7 +355,7 @@ static int avrcp_control_disconnect(struct btd_device *dev,
 		return -1;
 	}
 
-	req = new_profile_request(dev, profile, cb);
+	req = new_profile_request(dev, profile, device_profile_disconnected);
 
 	err = control_disconnect(audio_dev, profile_cb, req);
 	if (err < 0) {
diff --git a/profiles/input/device.c b/profiles/input/device.c
index b22e0a7..aaf1ff8 100644
--- a/profiles/input/device.c
+++ b/profiles/input/device.c
@@ -498,7 +498,7 @@ static void connect_reply(struct input_device *idev, int err,
 	if (err_msg)
 		error("%s", err_msg);
 
-	pending->cb(pending->profile, idev->device, err);
+	pending->cb(idev->device, pending->profile, err);
 	g_free(pending);
 }
 
@@ -615,8 +615,7 @@ static int dev_connect(struct input_device *idev)
 	return -EIO;
 }
 
-int input_device_connect(struct btd_device *dev, struct btd_profile *profile,
-							btd_profile_cb cb)
+int input_device_connect(struct btd_device *dev, struct btd_profile *profile)
 {
 	struct input_device *idev;
 
@@ -632,13 +631,12 @@ int input_device_connect(struct btd_device *dev, struct btd_profile *profile,
 
 	idev->pending = g_new0(struct pending_connect, 1);
 	idev->pending->profile = profile;
-	idev->pending->cb = cb;
+	idev->pending->cb = device_profile_connected;
 
 	return dev_connect(idev);
 }
 
-int input_device_disconnect(struct btd_device *dev, struct btd_profile *profile,
-							btd_profile_cb cb)
+int input_device_disconnect(struct btd_device *dev, struct btd_profile *profile)
 {
 	struct input_device *idev;
 	int err;
@@ -651,8 +649,7 @@ int input_device_disconnect(struct btd_device *dev, struct btd_profile *profile,
 	if (err < 0)
 		return err;
 
-	if (cb)
-		cb(profile, dev, 0);
+	device_profile_disconnected(dev, profile, 0);
 
 	return 0;
 }
diff --git a/profiles/input/device.h b/profiles/input/device.h
index d68798c..aabc79c 100644
--- a/profiles/input/device.h
+++ b/profiles/input/device.h
@@ -36,7 +36,6 @@ int input_device_set_channel(const bdaddr_t *src, const bdaddr_t *dst, int psm,
 							GIOChannel *io);
 int input_device_close_channels(const bdaddr_t *src, const bdaddr_t *dst);
 
-int input_device_connect(struct btd_device *dev, struct btd_profile *profile,
-							btd_profile_cb cb);
-int input_device_disconnect(struct btd_device *dev, struct btd_profile *profile,
-							btd_profile_cb cb);
+int input_device_connect(struct btd_device *dev, struct btd_profile *profile);
+int input_device_disconnect(struct btd_device *dev,
+						struct btd_profile *profile);
diff --git a/profiles/network/manager.c b/profiles/network/manager.c
index e737f6d..1c75e8f 100644
--- a/profiles/network/manager.c
+++ b/profiles/network/manager.c
@@ -83,7 +83,7 @@ static void connect_profile_cb(struct btd_device *device, int err,
 {
 	struct connect_req *req = data;
 
-	req->cb(req->profile, device, err);
+	req->cb(device, req->profile, err);
 
 	g_free(req);
 }
@@ -122,7 +122,7 @@ static int disconnect_profile(struct btd_device *dev,
 		return err;
 
 	if (cb)
-		cb(profile, dev, 0);
+		cb(dev, profile, 0);
 
 	return 0;
 }
@@ -142,16 +142,16 @@ static void network_remove(struct btd_profile *p, struct btd_device *device)
 	connection_unregister(device);
 }
 
-static int panu_connect(struct btd_device *dev, struct btd_profile *profile,
-							btd_profile_cb cb)
+static int panu_connect(struct btd_device *dev, struct btd_profile *profile)
 {
-	return connect_profile(dev, profile, BNEP_SVC_PANU, cb);
+	return connect_profile(dev, profile, BNEP_SVC_PANU,
+						device_profile_connected);
 }
 
-static int panu_disconnect(struct btd_device *dev, struct btd_profile *profile,
-							btd_profile_cb cb)
+static int panu_disconnect(struct btd_device *dev, struct btd_profile *profile)
 {
-	return disconnect_profile(dev, profile, BNEP_SVC_PANU, cb);
+	return disconnect_profile(dev, profile, BNEP_SVC_PANU,
+						device_profile_disconnected);
 }
 
 static int panu_server_probe(struct btd_profile *p, struct btd_adapter *adapter)
@@ -181,16 +181,16 @@ static int gn_probe(struct btd_profile *p, struct btd_device *device,
 	return connection_register(device, BNEP_SVC_GN);
 }
 
-static int gn_connect(struct btd_device *dev, struct btd_profile *profile,
-							btd_profile_cb cb)
+static int gn_connect(struct btd_device *dev, struct btd_profile *profile)
 {
-	return connect_profile(dev, profile, BNEP_SVC_GN, cb);
+	return connect_profile(dev, profile, BNEP_SVC_GN,
+						device_profile_connected);
 }
 
-static int gn_disconnect(struct btd_device *dev, struct btd_profile *profile,
-							btd_profile_cb cb)
+static int gn_disconnect(struct btd_device *dev, struct btd_profile *profile)
 {
-	return disconnect_profile(dev, profile, BNEP_SVC_GN, cb);
+	return disconnect_profile(dev, profile, BNEP_SVC_GN,
+						device_profile_disconnected);
 }
 
 static int gn_server_probe(struct btd_profile *p, struct btd_adapter *adapter)
@@ -220,16 +220,16 @@ static int nap_probe(struct btd_profile *p, struct btd_device *device,
 	return connection_register(device, BNEP_SVC_NAP);
 }
 
-static int nap_connect(struct btd_device *dev, struct btd_profile *profile,
-							btd_profile_cb cb)
+static int nap_connect(struct btd_device *dev, struct btd_profile *profile)
 {
-	return connect_profile(dev, profile, BNEP_SVC_NAP, cb);
+	return connect_profile(dev, profile, BNEP_SVC_NAP,
+						device_profile_connected);
 }
 
-static int nap_disconnect(struct btd_device *dev, struct btd_profile *profile,
-							btd_profile_cb cb)
+static int nap_disconnect(struct btd_device *dev, struct btd_profile *profile)
 {
-	return disconnect_profile(dev, profile, BNEP_SVC_NAP, cb);
+	return disconnect_profile(dev, profile, BNEP_SVC_NAP,
+						device_profile_disconnected);
 }
 
 static int nap_server_probe(struct btd_profile *p, struct btd_adapter *adapter)
diff --git a/src/device.c b/src/device.c
index 419bf9b..e97265b 100644
--- a/src/device.c
+++ b/src/device.c
@@ -1149,7 +1149,7 @@ static void dev_disconn_profile(gpointer a, gpointer b)
 	if (!profile->disconnect)
 		return;
 
-	profile->disconnect(dev, profile, NULL);
+	profile->disconnect(dev, profile);
 }
 
 void device_request_disconnect(struct btd_device *device, DBusMessage *msg)
@@ -1221,7 +1221,7 @@ static DBusMessage *disconnect(DBusConnection *conn, DBusMessage *msg,
 	return NULL;
 }
 
-static int connect_next(struct btd_device *dev, btd_profile_cb cb)
+static int connect_next(struct btd_device *dev)
 {
 	struct btd_profile *profile;
 	int err = -ENOENT;
@@ -1231,7 +1231,7 @@ static int connect_next(struct btd_device *dev, btd_profile_cb cb)
 
 		profile = dev->pending->data;
 
-		err = profile->connect(dev, profile, cb);
+		err = profile->connect(dev, profile);
 		if (err == 0)
 			return 0;
 
@@ -1243,15 +1243,15 @@ static int connect_next(struct btd_device *dev, btd_profile_cb cb)
 	return err;
 }
 
-static void dev_profile_connected(struct btd_profile *profile,
-					struct btd_device *dev, int err)
+void device_profile_connected(struct btd_device *dev,
+					struct btd_profile *profile, int err)
 {
 	DBG("%s (%d)", strerror(-err), -err);
 
 	dev->pending = g_slist_remove(dev->pending, profile);
 
 	if (!err) {
-		if (connect_next(dev, dev_profile_connected) == 0)
+		if (connect_next(dev) == 0)
 			return;
 		dev->profiles_connected = TRUE;
 	}
@@ -1379,7 +1379,7 @@ static DBusMessage *connect_profiles(struct btd_device *dev, DBusMessage *msg,
 		return btd_error_not_available(msg);
 
 start_connect:
-	err = connect_next(dev, dev_profile_connected);
+	err = connect_next(dev);
 	if (err < 0)
 		return btd_error_failed(msg, strerror(-err));
 
@@ -1415,8 +1415,8 @@ static DBusMessage *connect_profile(DBusConnection *conn, DBusMessage *msg,
 	return reply;
 }
 
-static void profile_disconnected(struct btd_profile *profile,
-					struct btd_device *dev, int err)
+void device_profile_disconnected(struct btd_device *dev,
+					struct btd_profile *profile, int err)
 {
 	if (!dev->disconnect)
 		return;
@@ -1457,7 +1457,7 @@ static DBusMessage *disconnect_profile(DBusConnection *conn, DBusMessage *msg,
 	if (!p->disconnect)
 		return btd_error_not_supported(msg);
 
-	err = p->disconnect(dev, p, profile_disconnected);
+	err = p->disconnect(dev, p);
 	if (err < 0)
 		return btd_error_failed(msg, strerror(-err));
 
diff --git a/src/device.h b/src/device.h
index 5e173bd..1987a80 100644
--- a/src/device.h
+++ b/src/device.h
@@ -109,3 +109,10 @@ void btd_device_set_pnpid(struct btd_device *device, uint8_t vendor_id_src,
 			uint16_t vendor_id, uint16_t product_id,
 			uint16_t product_ver);
 GIOChannel *device_att_connect(gpointer user_data);
+
+struct btd_profile;
+
+void device_profile_connected(struct btd_device *dev,
+					struct btd_profile *profile, int err);
+void device_profile_disconnected(struct btd_device *dev,
+					struct btd_profile *profile, int err);
diff --git a/src/profile.c b/src/profile.c
index afa487b..da34e25 100644
--- a/src/profile.c
+++ b/src/profile.c
@@ -645,7 +645,7 @@ static void pending_reply(DBusPendingCall *call, void *user_data)
 
 	if (!dbus_error_is_set(&err)) {
 		if (conn->cb) {
-			conn->cb(&ext->p, conn->device, 0);
+			conn->cb(conn->device, &ext->p, 0);
 			conn->cb = NULL;
 		}
 
@@ -660,7 +660,7 @@ static void pending_reply(DBusPendingCall *call, void *user_data)
 						err.name, err.message);
 
 	if (conn->cb) {
-		conn->cb(&ext->p, conn->device, -ECONNREFUSED);
+		conn->cb(conn->device, &ext->p, -ECONNREFUSED);
 		conn->cb = NULL;
 	}
 
@@ -798,7 +798,7 @@ static void ext_connect(GIOChannel *io, GError *err, gpointer user_data)
 
 drop:
 	if (conn->cb) {
-		conn->cb(&ext->p, conn->device, err ? -err->code : -EIO);
+		conn->cb(conn->device, &ext->p, err ? -err->code : -EIO);
 		conn->cb = NULL;
 	}
 	if (io_err)
@@ -1374,7 +1374,7 @@ static void record_cb(sdp_list_t *recs, int err, gpointer user_data)
 	return;
 
 failed:
-	conn->cb(&ext->p, conn->device, err);
+	conn->cb(conn->device, &ext->p, err);
 	ext->conns = g_slist_remove(ext->conns, conn);
 	ext_io_destroy(conn);
 }
@@ -1396,8 +1396,7 @@ static int resolve_service(struct ext_io *conn, const bdaddr_t *src,
 	return err;
 }
 
-static int ext_connect_dev(struct btd_device *dev, struct btd_profile *profile,
-							btd_profile_cb cb)
+static int ext_connect_dev(struct btd_device *dev, struct btd_profile *profile)
 {
 	struct btd_adapter *adapter;
 	struct ext_io *conn;
@@ -1432,7 +1431,7 @@ static int ext_connect_dev(struct btd_device *dev, struct btd_profile *profile,
 
 	conn->adapter = btd_adapter_ref(adapter);
 	conn->device = btd_device_ref(dev);
-	conn->cb = cb;
+	conn->cb = device_profile_connected;
 
 	ext->conns = g_slist_append(ext->conns, conn);
 
@@ -1476,8 +1475,7 @@ static int send_disconn_req(struct ext_profile *ext, struct ext_io *conn)
 }
 
 static int ext_disconnect_dev(struct btd_device *dev,
-						struct btd_profile *profile,
-						btd_profile_cb cb)
+						struct btd_profile *profile)
 {
 	struct ext_profile *ext;
 	struct ext_io *conn;
@@ -1498,7 +1496,7 @@ static int ext_disconnect_dev(struct btd_device *dev,
 	if (err < 0)
 		return err;
 
-	conn->cb = cb;
+	conn->cb = device_profile_disconnected;
 
 	return 0;
 }
diff --git a/src/profile.h b/src/profile.h
index 6991041..826d8dd 100644
--- a/src/profile.h
+++ b/src/profile.h
@@ -29,8 +29,8 @@
 
 struct btd_profile;
 
-typedef void (*btd_profile_cb)(struct btd_profile *profile,
-					struct btd_device *device, int err);
+typedef void (*btd_profile_cb)(struct btd_device *device,
+					struct btd_profile *profile, int err);
 
 struct btd_profile {
 	const char *name;
@@ -46,11 +46,10 @@ struct btd_profile {
 	void (*device_remove) (struct btd_profile *p,
 						struct btd_device *device);
 
-	int (*connect) (struct btd_device *device, struct btd_profile *profile,
-							btd_profile_cb cb);
+	int (*connect) (struct btd_device *device,
+						struct btd_profile *profile);
 	int (*disconnect) (struct btd_device *device,
-						struct btd_profile *profile,
-						btd_profile_cb cb);
+						struct btd_profile *profile);
 
 	int (*adapter_probe) (struct btd_profile *p,
 						struct btd_adapter *adapter);