diff --git a/profiles/audio/avctp.c b/profiles/audio/avctp.c
index a4d0153..627252a 100644
--- a/profiles/audio/avctp.c
+++ b/profiles/audio/avctp.c
#include <btio/btio.h>
#include "lib/uuid.h"
-#include "adapter.h"
-#include "../src/device.h"
+#include "src/adapter.h"
+#include "src/device.h"
#include "log.h"
#include "error.h"
#include "uinput.h"
#include "manager.h"
-#include "device.h"
#include "avctp.h"
#include "avrcp.h"
struct avctp_state_callback {
avctp_state_cb cb;
- struct audio_device *dev;
+ struct btd_device *dev;
unsigned int id;
+ void *user_data;
};
struct avctp_server {
static void avctp_set_state(struct avctp *session, avctp_state_t new_state)
{
GSList *l;
- struct audio_device *dev;
avctp_state_t old_state = session->state;
- dev = manager_get_audio_device(session->device, FALSE);
- if (dev == NULL) {
- error("%s(): No matching audio device", __func__);
- return;
- }
-
session->state = new_state;
for (l = callbacks; l != NULL; l = l->next) {
struct avctp_state_callback *cb = l->data;
- if (cb->dev && cb->dev != dev)
+ if (cb->dev && cb->dev != session->device)
continue;
- cb->cb(dev, old_state, new_state);
+ cb->cb(session->device, old_state, new_state, cb->user_data);
}
switch (new_state) {
static void init_uinput(struct avctp *session)
{
- struct audio_device *dev;
char address[18], name[248 + 1];
- dev = manager_get_audio_device(session->device, FALSE);
-
- device_get_name(dev->btd_dev, name, sizeof(name));
+ device_get_name(session->device, name, sizeof(name));
if (g_str_equal(name, "Nokia CK-20W")) {
session->key_quirks[AVC_FORWARD] |= QUIRK_NO_RELEASE;
session->key_quirks[AVC_BACKWARD] |= QUIRK_NO_RELEASE;
}
static void avctp_control_confirm(struct avctp *session, GIOChannel *chan,
- struct audio_device *dev)
+ struct btd_device *dev)
{
const bdaddr_t *src;
const bdaddr_t *dst;
avctp_set_state(session, AVCTP_STATE_CONNECTING);
session->control = avctp_channel_create(session, chan, NULL);
- src = adapter_get_address(device_get_adapter(dev->btd_dev));
- dst = device_get_address(dev->btd_dev);
+ src = adapter_get_address(device_get_adapter(dev));
+ dst = device_get_address(dev);
session->auth_id = btd_request_authorization(src, dst,
AVRCP_TARGET_UUID,
}
static void avctp_browsing_confirm(struct avctp *session, GIOChannel *chan,
- struct audio_device *dev)
+ struct btd_device *dev)
{
GError *err = NULL;
static void avctp_confirm_cb(GIOChannel *chan, gpointer data)
{
struct avctp *session;
- struct audio_device *dev;
char address[18];
bdaddr_t src, dst;
GError *err = NULL;
if (session == NULL)
return;
- dev = manager_get_audio_device(device, TRUE);
- if (!dev) {
- error("Unable to get audio device object for %s", address);
- goto drop;
- }
+ if (btd_device_get_service(device, AVRCP_REMOTE_UUID) == NULL)
+ btd_device_add_uuid(device, AVRCP_REMOTE_UUID);
- if (dev->control == NULL) {
- btd_device_add_uuid(dev->btd_dev, AVRCP_REMOTE_UUID);
- btd_device_add_uuid(dev->btd_dev, AVRCP_TARGET_UUID);
-
- if (dev->control == NULL)
- goto drop;
- }
+ if (btd_device_get_service(device, AVRCP_TARGET_UUID) == NULL)
+ btd_device_add_uuid(device, AVRCP_TARGET_UUID);
switch (psm) {
case AVCTP_CONTROL_PSM:
- avctp_control_confirm(session, chan, dev);
+ avctp_control_confirm(session, chan, device);
break;
case AVCTP_BROWSING_PSM:
- avctp_browsing_confirm(session, chan, dev);
+ avctp_browsing_confirm(session, chan, device);
break;
}
return;
-
-drop:
- if (psm == AVCTP_CONTROL_PSM)
- avctp_set_state(session, AVCTP_STATE_DISCONNECTED);
}
static GIOChannel *avctp_server_socket(const bdaddr_t *src, gboolean master,
func, user_data);
}
-unsigned int avctp_add_state_cb(struct audio_device *dev, avctp_state_cb cb)
+unsigned int avctp_add_state_cb(struct btd_device *dev, avctp_state_cb cb,
+ void *user_data)
{
struct avctp_state_callback *state_cb;
static unsigned int id = 0;
state_cb->cb = cb;
state_cb->dev = dev;
state_cb->id = ++id;
+ state_cb->user_data = user_data;
callbacks = g_slist_append(callbacks, state_cb);
return FALSE;
}
-struct avctp *avctp_connect(struct audio_device *device)
+struct avctp *avctp_connect(struct btd_device *device)
{
struct avctp *session;
GError *err = NULL;
GIOChannel *io;
- session = avctp_get_internal(device->btd_dev);
+ session = avctp_get_internal(device);
if (!session)
return NULL;
avctp_set_state(session, AVCTP_STATE_DISCONNECTED);
}
-struct avctp *avctp_get(struct audio_device *device)
+struct avctp *avctp_get(struct btd_device *device)
{
- return avctp_get_internal(device->btd_dev);
+ return avctp_get_internal(device);
}
bool avctp_is_initiator(struct avctp *session)
diff --git a/profiles/audio/avctp.h b/profiles/audio/avctp.h
index cd575cc..f9c665e 100644
--- a/profiles/audio/avctp.h
+++ b/profiles/audio/avctp.h
AVCTP_STATE_BROWSING_CONNECTED
} avctp_state_t;
-typedef void (*avctp_state_cb) (struct audio_device *dev,
+typedef void (*avctp_state_cb) (struct btd_device *dev,
avctp_state_t old_state,
- avctp_state_t new_state);
+ avctp_state_t new_state,
+ void *user_data);
typedef bool (*avctp_passthrough_cb) (struct avctp *session,
uint8_t op, bool pressed,
uint8_t *operands, size_t operand_count,
void *user_data);
-unsigned int avctp_add_state_cb(struct audio_device *dev, avctp_state_cb cb);
+unsigned int avctp_add_state_cb(struct btd_device *dev, avctp_state_cb cb,
+ void *user_data);
gboolean avctp_remove_state_cb(unsigned int id);
int avctp_register(struct btd_adapter *adapter, gboolean master);
void avctp_unregister(struct btd_adapter *adapter);
-struct avctp *avctp_connect(struct audio_device *device);
-struct avctp *avctp_get(struct audio_device *device);
+struct avctp *avctp_connect(struct btd_device *device);
+struct avctp *avctp_get(struct btd_device *device);
bool avctp_is_initiator(struct avctp *session);
int avctp_connect_browsing(struct avctp *session);
void avctp_disconnect(struct avctp *session);
diff --git a/profiles/audio/avrcp.c b/profiles/audio/avrcp.c
index cc007c5..1a5c477 100644
--- a/profiles/audio/avrcp.c
+++ b/profiles/audio/avrcp.c
session);
}
-static struct avrcp *find_session(GSList *list, struct audio_device *dev)
+static struct avrcp *find_session(GSList *list, struct btd_device *dev)
{
for (; list; list = list->next) {
struct avrcp *session = list->data;
- if (session->dev == dev)
+ if (session->dev->btd_dev == dev)
return session;
}
}
static struct avrcp *session_create(struct avrcp_server *server,
- struct audio_device *dev)
+ struct btd_device *device)
{
struct avrcp *session;
const sdp_record_t *rec;
sdp_list_t *list;
sdp_profile_desc_t *desc;
+ struct audio_device *dev = manager_get_audio_device(device, FALSE);
session = g_new0(struct avrcp, 1);
session->server = server;
- session->conn = avctp_connect(dev);
+ session->conn = avctp_connect(device);
session->dev = dev;
server->sessions = g_slist_append(server->sessions, session);
session->init_browsing = session_tg_init_browsing;
session->destroy = session_tg_destroy;
- rec = btd_device_get_record(dev->btd_dev, AVRCP_REMOTE_UUID);
+ rec = btd_device_get_record(device, AVRCP_REMOTE_UUID);
if (rec == NULL)
- btd_device_add_uuid(dev->btd_dev, AVRCP_REMOTE_UUID);
+ btd_device_add_uuid(device, AVRCP_REMOTE_UUID);
} else {
session->init_control = session_ct_init_control;
session->init_browsing = session_ct_init_browsing;
session->destroy = session_ct_destroy;
- rec = btd_device_get_record(dev->btd_dev, AVRCP_TARGET_UUID);
+ rec = btd_device_get_record(device, AVRCP_TARGET_UUID);
if (rec == NULL)
- btd_device_add_uuid(dev->btd_dev, AVRCP_TARGET_UUID);
+ btd_device_add_uuid(device, AVRCP_TARGET_UUID);
}
if (rec == NULL)
return session;
}
-static void state_changed(struct audio_device *dev, avctp_state_t old_state,
- avctp_state_t new_state)
+static void state_changed(struct btd_device *device, avctp_state_t old_state,
+ avctp_state_t new_state, void *user_data)
{
struct avrcp_server *server;
struct avrcp *session;
- server = find_server(servers, device_get_adapter(dev->btd_dev));
+ server = find_server(servers, device_get_adapter(device));
if (!server)
return;
- session = find_session(server->sessions, dev);
+ session = find_session(server->sessions, device);
switch (new_state) {
case AVCTP_STATE_DISCONNECTED:
if (session != NULL)
break;
- session_create(server, dev);
+ session_create(server, device);
break;
case AVCTP_STATE_CONNECTED:
{
struct avctp *session;
- session = avctp_connect(dev);
+ session = avctp_connect(dev->btd_dev);
if (session)
return FALSE;
{
struct avctp *session;
- session = avctp_get(dev);
+ session = avctp_get(dev->btd_dev);
if (!session)
return;
servers = g_slist_append(servers, server);
if (!avctp_id)
- avctp_id = avctp_add_state_cb(NULL, state_changed);
+ avctp_id = avctp_add_state_cb(NULL, state_changed, NULL);
return server;
}
if (server == NULL)
return -EINVAL;
- session = find_session(server->sessions, dev);
+ session = find_session(server->sessions, dev->btd_dev);
if (session == NULL)
return -ENOTCONN;
diff --git a/profiles/audio/control.c b/profiles/audio/control.c
index 7cfbcc6..9b614c3 100644
--- a/profiles/audio/control.c
+++ b/profiles/audio/control.c
unsigned int avctp_id;
};
-static void state_changed(struct audio_device *dev, avctp_state_t old_state,
- avctp_state_t new_state)
+static void state_changed(struct btd_device *dev, avctp_state_t old_state,
+ avctp_state_t new_state, void *user_data)
{
+ struct control *control = user_data;
DBusConnection *conn = btd_get_dbus_connection();
- struct control *control = btd_service_get_user_data(dev->control);
- const char *path = device_get_path(dev->btd_dev);
+ const char *path = device_get_path(dev);
switch (new_state) {
case AVCTP_STATE_DISCONNECTED:
if (!control->target)
return -ENOTSUP;
- control->session = avctp_connect(control->dev);
+ control->session = avctp_connect(control->dev->btd_dev);
if (!control->session)
return -EIO;
control = g_new0(struct control, 1);
control->dev = dev;
- control->avctp_id = avctp_add_state_cb(dev, state_changed);
+ control->avctp_id = avctp_add_state_cb(dev->btd_dev, state_changed,
+ control);
return control;
}
diff --git a/profiles/audio/device.c b/profiles/audio/device.c
index 416e1b2..0112cd1 100644
--- a/profiles/audio/device.c
+++ b/profiles/audio/device.c
}
}
-static void device_avctp_cb(struct audio_device *dev, avctp_state_t old_state,
- avctp_state_t new_state)
+static void device_avctp_cb(struct btd_device *device, avctp_state_t old_state,
+ avctp_state_t new_state, void *user_data)
{
+ struct audio_device *dev = user_data;
+
if (!dev->control)
return;
NULL);
dev->priv->service_cb_id = btd_service_add_state_cb(service_cb, dev);
dev->priv->avdtp_callback_id = avdtp_add_state_cb(dev, device_avdtp_cb);
- dev->priv->avctp_callback_id = avctp_add_state_cb(dev, device_avctp_cb);
+ dev->priv->avctp_callback_id = avctp_add_state_cb(device,
+ device_avctp_cb, dev);
return dev;
}