From: Luiz Augusto von Dentz <luiz.dentz@gmail.com>
To: linux-bluetooth@vger.kernel.org
Subject: [PATCH BlueZ 9/9] AVRCP: Simplify state_changed callback
Date: Fri, 5 Oct 2012 23:20:50 +0200 [thread overview]
Message-ID: <1349472050-25928-9-git-send-email-luiz.dentz@gmail.com> (raw)
In-Reply-To: <1349472050-25928-1-git-send-email-luiz.dentz@gmail.com>
From: Luiz Augusto von Dentz <luiz.von.dentz@intel.com>
Move session creation and destroy to their own functions
---
audio/avrcp.c | 91 ++++++++++++++++++++++++++++++++++-------------------------
1 file changed, 53 insertions(+), 38 deletions(-)
diff --git a/audio/avrcp.c b/audio/avrcp.c
index f31372b..7188039 100644
--- a/audio/avrcp.c
+++ b/audio/avrcp.c
@@ -1352,15 +1352,63 @@ static struct avrcp *find_session(GSList *list, struct audio_device *dev)
return NULL;
}
-static void state_changed(struct audio_device *dev, avctp_state_t old_state,
- avctp_state_t new_state, void *user_data)
+static struct avrcp *session_create(struct avrcp_server *server,
+ struct audio_device *dev)
{
- struct avrcp_server *server;
struct avrcp *session;
const sdp_record_t *rec;
sdp_list_t *list;
sdp_profile_desc_t *desc;
+ session = g_new0(struct avrcp, 1);
+ session->server = server;
+ session->conn = avctp_connect(&dev->src, &dev->dst);
+ session->dev = dev;
+ session->player = g_slist_nth_data(server->players, 0);
+
+ server->sessions = g_slist_append(server->sessions, session);
+
+ rec = btd_device_get_record(dev->btd_dev, AVRCP_TARGET_UUID);
+ if (rec == NULL)
+ return session;
+
+ if (sdp_get_profile_descs(rec, &list) < 0)
+ return session;
+
+ desc = list->data;
+ session->version = desc->version;
+ sdp_get_int_attr(rec, SDP_ATTR_SUPPORTED_FEATURES, &session->features);
+
+ sdp_list_free(list, free);
+
+ return session;
+}
+
+static void session_destroy(struct avrcp *session)
+{
+ struct avrcp_server *server = session->server;
+ struct avrcp_player *player = session->player;
+
+ server->sessions = g_slist_remove(server->sessions, session);
+
+ if (session->control_id > 0)
+ avctp_unregister_pdu_handler(session->control_id);
+
+ if (session->browsing_id > 0)
+ avctp_unregister_browsing_pdu_handler(session->browsing_id);
+
+ if (player != NULL)
+ player->sessions = g_slist_remove(player->sessions, session);
+
+ g_free(session);
+}
+
+static void state_changed(struct audio_device *dev, avctp_state_t old_state,
+ avctp_state_t new_state, void *user_data)
+{
+ struct avrcp_server *server;
+ struct avrcp *session;
+
server = find_server(servers, &dev->src);
if (!server)
return;
@@ -1372,47 +1420,14 @@ static void state_changed(struct audio_device *dev, avctp_state_t old_state,
if (session == NULL)
break;
- server->sessions = g_slist_remove(server->sessions, session);
+ session_destroy(session);
- if (session->control_id > 0)
- avctp_unregister_pdu_handler(session->control_id);
-
- if (session->browsing_id > 0)
- avctp_unregister_browsing_pdu_handler(
- session->browsing_id);
-
- if (session->player != NULL)
- session->player->sessions = g_slist_remove(
- session->player->sessions,
- session);
-
- g_free(session);
break;
case AVCTP_STATE_CONNECTING:
if (session != NULL)
break;
- session = g_new0(struct avrcp, 1);
- session->server = server;
- session->conn = avctp_connect(&dev->src, &dev->dst);
- session->dev = dev;
- session->player = g_slist_nth_data(server->players, 0);
-
- server->sessions = g_slist_append(server->sessions, session);
-
- rec = btd_device_get_record(dev->btd_dev, AVRCP_TARGET_UUID);
- if (rec == NULL)
- return;
-
- if (sdp_get_profile_descs(rec, &list) < 0)
- return;
-
- desc = list->data;
- session->version = desc->version;
- sdp_get_int_attr(rec, SDP_ATTR_SUPPORTED_FEATURES,
- &session->features);
-
- sdp_list_free(list, free);
+ session_create(server, dev);
break;
case AVCTP_STATE_CONNECTED:
--
1.7.11.4
next prev parent reply other threads:[~2012-10-05 21:20 UTC|newest]
Thread overview: 11+ messages / expand[flat|nested] mbox.gz Atom feed top
2012-10-05 21:20 [PATCH BlueZ 1/9] gdbus: Remove connection from g_dbus_remove_watch Luiz Augusto von Dentz
2012-10-05 21:20 ` [PATCH BlueZ 2/9] Fix passing D-Bus connection to g_dbus_remove_watch Luiz Augusto von Dentz
2012-10-05 21:20 ` [PATCH BlueZ 3/9] audio: Fix not freeing gateway agent data on exit Luiz Augusto von Dentz
2012-10-05 21:20 ` [PATCH BlueZ 4/9] AVCTP: Simplify channel handling Luiz Augusto von Dentz
2012-10-05 21:20 ` [PATCH BlueZ 5/9] AVCTP: Allocate memory to hold incoming/outgoing PDUs Luiz Augusto von Dentz
2012-10-05 21:20 ` [PATCH BlueZ 6/9] AVRCP: Register to AVCTP state changes without depending on player Luiz Augusto von Dentz
2012-10-05 21:20 ` [PATCH BlueZ 7/9] AVRCP: Don't respond with errors when no player is registered Luiz Augusto von Dentz
2012-10-05 21:20 ` [PATCH BlueZ 8/9] AVRCP: Fix crash on disconnect Luiz Augusto von Dentz
2012-10-05 21:20 ` Luiz Augusto von Dentz [this message]
2012-10-06 13:40 ` [PATCH BlueZ 1/9] gdbus: Remove connection from g_dbus_remove_watch Marcel Holtmann
2012-10-06 15:09 ` Luiz Augusto von Dentz
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=1349472050-25928-9-git-send-email-luiz.dentz@gmail.com \
--to=luiz.dentz@gmail.com \
--cc=linux-bluetooth@vger.kernel.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox