OSDN Git Service

profile: Get rid of not needed btd_profile_cb define
authorJohan Hedberg <johan.hedberg@intel.com>
Tue, 11 Dec 2012 08:46:44 +0000 (10:46 +0200)
committerJohan Hedberg <johan.hedberg@intel.com>
Tue, 11 Dec 2012 08:46:44 +0000 (10:46 +0200)
profiles/audio/manager.c
profiles/input/device.c
profiles/network/manager.c
src/profile.c
src/profile.h

index 689a309..dece7f6 100644 (file)
@@ -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;
index aaf1ff8..9120a05 100644 (file)
@@ -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);
 }
index 1c75e8f..9958099 100644 (file)
 
 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)
index da34e25..65dc723 100644 (file)
@@ -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;
 }
 
index 826d8dd..8339c7a 100644 (file)
 #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;