diff --git a/profiles/audio/a2dp.c b/profiles/audio/a2dp.c
index 33e66a7..1ecbf3a 100644
--- a/profiles/audio/a2dp.c
+++ b/profiles/audio/a2dp.c
#include "src/service.h"
#include "src/log.h"
#include "src/sdpd.h"
+#include "src/shared/queue.h"
#include "btio/btio.h"
struct avdtp_server {
struct btd_adapter *adapter;
GIOChannel *io;
- GSList *seps;
+ struct queue *seps;
GSList *sessions;
};
struct avdtp_server *server = avdtp_get_server(lsep);
- server->seps = g_slist_remove(server->seps, lsep);
- if (!server->seps)
+ queue_remove(server->seps, lsep);
+ if (queue_isempty(server->seps))
avdtp_server_destroy(server);
avdtp_unregister_sep(lsep);
diff --git a/profiles/audio/avdtp.c b/profiles/audio/avdtp.c
index 7b43613..4d0b506 100644
--- a/profiles/audio/avdtp.c
+++ b/profiles/audio/avdtp.c
#include "src/log.h"
#include "src/shared/util.h"
+#include "src/shared/queue.h"
#include "btio/btio.h"
#include "lib/uuid.h"
struct avdtp_server {
struct btd_adapter *adapter;
GIOChannel *io;
- GSList *seps;
+ struct queue *seps;
GSList *sessions;
};
return session;
}
-static struct avdtp_local_sep *find_local_sep_by_seid(struct avdtp_server *server,
- uint8_t seid)
+static bool match_by_seid(const void *data, const void *user_data)
{
- GSList *l;
-
- for (l = server->seps; l != NULL; l = g_slist_next(l)) {
- struct avdtp_local_sep *sep = l->data;
+ const struct avdtp_local_sep *sep = data;
+ uint8_t seid = PTR_TO_UINT(user_data);
- if (sep->info.seid == seid)
- return sep;
- }
+ return sep->info.seid == seid;
+}
- return NULL;
+static struct avdtp_local_sep *find_local_sep_by_seid(struct avdtp_server *server,
+ uint8_t seid)
+{
+ return queue_find(server->seps, match_by_seid, INT_TO_PTR(seid));
}
struct avdtp_remote_sep *avdtp_find_remote_sep(struct avdtp *session,
signal_id, NULL, 0);
}
+static void copy_seps(void *data, void *user_data)
+{
+ struct avdtp_local_sep *sep = data;
+ struct seid_info **p = user_data;
+
+ memcpy(*p, &sep->info, sizeof(struct seid_info));
+ *p = *p + 1;
+}
+
static gboolean avdtp_discover_cmd(struct avdtp *session, uint8_t transaction,
void *buf, int size)
{
- GSList *l;
- unsigned int rsp_size, sep_count, i;
- struct seid_info *seps;
+ unsigned int rsp_size, sep_count;
+ struct seid_info *seps, *p;
gboolean ret;
- sep_count = g_slist_length(session->server->seps);
+ sep_count = queue_length(session->server->seps);
if (sep_count == 0) {
uint8_t err = AVDTP_NOT_SUPPORTED_COMMAND;
rsp_size = sep_count * sizeof(struct seid_info);
seps = g_new0(struct seid_info, sep_count);
+ p = seps;
- for (l = session->server->seps, i = 0; l != NULL; l = l->next, i++) {
- struct avdtp_local_sep *sep = l->data;
-
- memcpy(&seps[i], &sep->info, sizeof(struct seid_info));
- }
+ queue_foreach(session->server->seps, copy_seps, &p);
ret = avdtp_send(session, transaction, AVDTP_MSG_TYPE_ACCEPT,
AVDTP_DISCOVER, seps, rsp_size);
DBG("SEP %p registered: type:%d codec:%d seid:%d", sep,
sep->info.type, sep->codec, sep->info.seid);
- server->seps = g_slist_append(server->seps, sep);
+
+ if (!queue_push_tail(server->seps, sep)) {
+ g_free(sep);
+ return NULL;
+ }
return sep;
}