From bef8a121edcda710c1c3ed2074a505557dd7d225 Mon Sep 17 00:00:00 2001 From: Johan Hedberg Date: Tue, 11 Dec 2012 10:46:44 +0200 Subject: [PATCH] profile: Get rid of not needed btd_profile_cb define --- profiles/audio/manager.c | 43 ++++++++++++++----------- profiles/input/device.c | 4 +-- profiles/network/manager.c | 51 +++++++---------------------- src/profile.c | 66 ++++++++++++++++++++++++-------------- src/profile.h | 5 --- 5 files changed, 79 insertions(+), 90 deletions(-) diff --git a/profiles/audio/manager.c b/profiles/audio/manager.c index 689a30962..dece7f687 100644 --- a/profiles/audio/manager.c +++ b/profiles/audio/manager.c @@ -77,7 +77,6 @@ struct audio_adapter { struct profile_req { struct btd_device *device; struct btd_profile *profile; - btd_profile_cb cb; }; static GKeyFile *config = NULL; @@ -181,25 +180,31 @@ static int avrcp_probe(struct btd_profile *p, struct btd_device *device, } static struct profile_req *new_profile_request(struct btd_device *dev, - struct btd_profile *profile, - btd_profile_cb cb) + struct btd_profile *profile) { struct profile_req *req; req = g_new0(struct profile_req, 1); req->device = dev; req->profile = profile; - req->cb = cb; return req; } -static void profile_cb(struct audio_device *dev, int err, void *data) +static void connect_cb(struct audio_device *dev, int err, void *data) +{ + struct profile_req *req = data; + + device_profile_connected(req->device, req->profile, err); + + g_free(req); +} + +static void disconnect_cb(struct audio_device *dev, int err, void *data) { struct profile_req *req = data; - if (req->cb) - req->cb(req->device, req->profile, err); + device_profile_disconnected(req->device, req->profile, err); g_free(req); } @@ -220,9 +225,9 @@ static int a2dp_source_connect(struct btd_device *dev, return -1; } - req = new_profile_request(dev, profile, device_profile_connected); + req = new_profile_request(dev, profile); - err = source_connect(audio_dev, profile_cb, req); + err = source_connect(audio_dev, connect_cb, req); if (err < 0) { g_free(req); return err; @@ -247,9 +252,9 @@ static int a2dp_source_disconnect(struct btd_device *dev, return -1; } - req = new_profile_request(dev, profile, device_profile_disconnected); + req = new_profile_request(dev, profile); - err = source_disconnect(audio_dev, FALSE, profile_cb, req); + err = source_disconnect(audio_dev, FALSE, disconnect_cb, req); if (err < 0) { g_free(req); return err; @@ -274,9 +279,9 @@ static int a2dp_sink_connect(struct btd_device *dev, return -1; } - req = new_profile_request(dev, profile, device_profile_connected); + req = new_profile_request(dev, profile); - err = sink_connect(audio_dev, profile_cb, req); + err = sink_connect(audio_dev, connect_cb, req); if (err < 0) { g_free(req); return err; @@ -301,9 +306,9 @@ static int a2dp_sink_disconnect(struct btd_device *dev, return -1; } - req = new_profile_request(dev, profile, device_profile_disconnected); + req = new_profile_request(dev, profile); - err = sink_disconnect(audio_dev, FALSE, profile_cb, req); + err = sink_disconnect(audio_dev, FALSE, disconnect_cb, req); if (err < 0) { g_free(req); return err; @@ -328,9 +333,9 @@ static int avrcp_control_connect(struct btd_device *dev, return -1; } - req = new_profile_request(dev, profile, device_profile_connected); + req = new_profile_request(dev, profile); - err = control_connect(audio_dev, profile_cb, req); + err = control_connect(audio_dev, connect_cb, req); if (err < 0) { g_free(req); return err; @@ -355,9 +360,9 @@ static int avrcp_control_disconnect(struct btd_device *dev, return -1; } - req = new_profile_request(dev, profile, device_profile_disconnected); + req = new_profile_request(dev, profile); - err = control_disconnect(audio_dev, profile_cb, req); + err = control_disconnect(audio_dev, disconnect_cb, req); if (err < 0) { g_free(req); return err; diff --git a/profiles/input/device.c b/profiles/input/device.c index aaf1ff8a3..9120a05e3 100644 --- a/profiles/input/device.c +++ b/profiles/input/device.c @@ -55,7 +55,6 @@ struct pending_connect { struct btd_profile *profile; - btd_profile_cb cb; }; struct input_device { @@ -498,7 +497,7 @@ static void connect_reply(struct input_device *idev, int err, if (err_msg) error("%s", err_msg); - pending->cb(idev->device, pending->profile, err); + device_profile_connected(idev->device, pending->profile, err); g_free(pending); } @@ -631,7 +630,6 @@ 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 = device_profile_connected; return dev_connect(idev); } diff --git a/profiles/network/manager.c b/profiles/network/manager.c index 1c75e8f7e..995809905 100644 --- a/profiles/network/manager.c +++ b/profiles/network/manager.c @@ -47,11 +47,6 @@ static gboolean conf_security = TRUE; -struct connect_req { - struct btd_profile *profile; - btd_profile_cb cb; -}; - static void read_config(const char *file) { GKeyFile *keyfile; @@ -81,37 +76,22 @@ done: static void connect_profile_cb(struct btd_device *device, int err, const char *pdev, void *data) { - struct connect_req *req = data; - - req->cb(device, req->profile, err); + struct btd_profile *profile = data; - g_free(req); + device_profile_connected(device, profile, err); } static int connect_profile(struct btd_device *dev, struct btd_profile *profile, - uint16_t id, btd_profile_cb cb) + uint16_t id) { - struct connect_req *req; - int err; - DBG("path %s id %u", device_get_path(dev), id); - req = g_new0(struct connect_req, 1); - req->profile = profile; - req->cb = cb; - - err = connection_connect(dev, id, NULL, connect_profile_cb, req); - if (err < 0) { - g_free(req); - return err; - } - - return 0; + return connection_connect(dev, id, NULL, connect_profile_cb, profile); } static int disconnect_profile(struct btd_device *dev, struct btd_profile *profile, - uint16_t id, btd_profile_cb cb) + uint16_t id) { int err; @@ -121,8 +101,7 @@ static int disconnect_profile(struct btd_device *dev, if (err < 0) return err; - if (cb) - cb(dev, profile, 0); + device_profile_disconnected(dev, profile, 0); return 0; } @@ -144,14 +123,12 @@ static void network_remove(struct btd_profile *p, struct btd_device *device) static int panu_connect(struct btd_device *dev, struct btd_profile *profile) { - return connect_profile(dev, profile, BNEP_SVC_PANU, - device_profile_connected); + return connect_profile(dev, profile, BNEP_SVC_PANU); } static int panu_disconnect(struct btd_device *dev, struct btd_profile *profile) { - return disconnect_profile(dev, profile, BNEP_SVC_PANU, - device_profile_disconnected); + return disconnect_profile(dev, profile, BNEP_SVC_PANU); } static int panu_server_probe(struct btd_profile *p, struct btd_adapter *adapter) @@ -183,14 +160,12 @@ static int gn_probe(struct btd_profile *p, struct btd_device *device, static int gn_connect(struct btd_device *dev, struct btd_profile *profile) { - return connect_profile(dev, profile, BNEP_SVC_GN, - device_profile_connected); + return connect_profile(dev, profile, BNEP_SVC_GN); } static int gn_disconnect(struct btd_device *dev, struct btd_profile *profile) { - return disconnect_profile(dev, profile, BNEP_SVC_GN, - device_profile_disconnected); + return disconnect_profile(dev, profile, BNEP_SVC_GN); } static int gn_server_probe(struct btd_profile *p, struct btd_adapter *adapter) @@ -222,14 +197,12 @@ static int nap_probe(struct btd_profile *p, struct btd_device *device, static int nap_connect(struct btd_device *dev, struct btd_profile *profile) { - return connect_profile(dev, profile, BNEP_SVC_NAP, - device_profile_connected); + return connect_profile(dev, profile, BNEP_SVC_NAP); } static int nap_disconnect(struct btd_device *dev, struct btd_profile *profile) { - return disconnect_profile(dev, profile, BNEP_SVC_NAP, - device_profile_disconnected); + return disconnect_profile(dev, profile, BNEP_SVC_NAP); } static int nap_server_probe(struct btd_profile *p, struct btd_adapter *adapter) diff --git a/src/profile.c b/src/profile.c index da34e2533..65dc7234f 100644 --- a/src/profile.c +++ b/src/profile.c @@ -475,7 +475,6 @@ struct ext_io { bool resolving; bool connected; - btd_profile_cb cb; uint16_t version; uint16_t features; @@ -628,7 +627,7 @@ drop: return FALSE; } -static void pending_reply(DBusPendingCall *call, void *user_data) +static void new_conn_reply(DBusPendingCall *call, void *user_data) { struct ext_io *conn = user_data; struct ext_profile *ext = conn->ext; @@ -644,14 +643,7 @@ static void pending_reply(DBusPendingCall *call, void *user_data) conn->pending = NULL; if (!dbus_error_is_set(&err)) { - if (conn->cb) { - conn->cb(conn->device, &ext->p, 0); - conn->cb = NULL; - } - - if (conn->connected) - goto disconnect; - + device_profile_connected(conn->device, &ext->p, 0); conn->connected = true; return; } @@ -659,11 +651,42 @@ static void pending_reply(DBusPendingCall *call, void *user_data) error("%s replied with an error: %s, %s", ext->name, err.name, err.message); - if (conn->cb) { - conn->cb(conn->device, &ext->p, -ECONNREFUSED); - conn->cb = NULL; + device_profile_connected(conn->device, &ext->p, -ECONNREFUSED); + + if (dbus_error_has_name(&err, DBUS_ERROR_NO_REPLY)) + ext_cancel(ext); + + dbus_error_free(&err); + + ext->conns = g_slist_remove(ext->conns, conn); + ext_io_destroy(conn); +} + +static void disconn_reply(DBusPendingCall *call, void *user_data) +{ + struct ext_io *conn = user_data; + struct ext_profile *ext = conn->ext; + DBusMessage *reply = dbus_pending_call_steal_reply(call); + DBusError err; + + dbus_error_init(&err); + dbus_set_error_from_message(&err, reply); + + dbus_message_unref(reply); + + dbus_pending_call_unref(conn->pending); + conn->pending = NULL; + + if (!dbus_error_is_set(&err)) { + device_profile_disconnected(conn->device, &ext->p, 0); + goto disconnect; } + error("%s replied with an error: %s, %s", ext->name, + err.name, err.message); + + device_profile_disconnected(conn->device, &ext->p, -ECONNREFUSED); + if (dbus_error_has_name(&err, DBUS_ERROR_NO_REPLY)) ext_cancel(ext); @@ -753,7 +776,7 @@ static bool send_new_connection(struct ext_profile *ext, struct ext_io *conn) dbus_message_unref(msg); - dbus_pending_call_set_notify(conn->pending, pending_reply, conn, NULL); + dbus_pending_call_set_notify(conn->pending, new_conn_reply, conn, NULL); return true; } @@ -797,10 +820,8 @@ static void ext_connect(GIOChannel *io, GError *err, gpointer user_data) return; drop: - if (conn->cb) { - conn->cb(conn->device, &ext->p, err ? -err->code : -EIO); - conn->cb = NULL; - } + device_profile_connected(conn->device, &ext->p, + err ? -err->code : -EIO); if (io_err) g_error_free(io_err); ext->conns = g_slist_remove(ext->conns, conn); @@ -1374,7 +1395,7 @@ static void record_cb(sdp_list_t *recs, int err, gpointer user_data) return; failed: - conn->cb(conn->device, &ext->p, err); + device_profile_connected(conn->device, &ext->p, err); ext->conns = g_slist_remove(ext->conns, conn); ext_io_destroy(conn); } @@ -1431,7 +1452,6 @@ 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 = device_profile_connected; ext->conns = g_slist_append(ext->conns, conn); @@ -1469,7 +1489,7 @@ static int send_disconn_req(struct ext_profile *ext, struct ext_io *conn) dbus_message_unref(msg); - dbus_pending_call_set_notify(conn->pending, pending_reply, conn, NULL); + dbus_pending_call_set_notify(conn->pending, disconn_reply, conn, NULL); return 0; } @@ -1489,15 +1509,13 @@ static int ext_disconnect_dev(struct btd_device *dev, if (!conn || !conn->connected) return -ENOTCONN; - if (conn->cb) + if (conn->pending) return -EBUSY; err = send_disconn_req(ext, conn); if (err < 0) return err; - conn->cb = device_profile_disconnected; - return 0; } diff --git a/src/profile.h b/src/profile.h index 826d8dd52..8339c7a63 100644 --- a/src/profile.h +++ b/src/profile.h @@ -27,11 +27,6 @@ #define BTD_PROFILE_PRIORITY_MEDIUM 1 #define BTD_PROFILE_PRIORITY_HIGH 2 -struct btd_profile; - -typedef void (*btd_profile_cb)(struct btd_device *device, - struct btd_profile *profile, int err); - struct btd_profile { const char *name; int priority; -- 2.47.3