diff --git a/android/Android.mk b/android/Android.mk
index ed72890..82c834b 100644
--- a/android/Android.mk
+++ b/android/Android.mk
bluez/android/a2dp.c \
bluez/android/avctp.c \
bluez/android/avrcp.c \
+ bluez/android/avrcp-lib.c \
bluez/android/pan.c \
bluez/android/handsfree.c \
bluez/src/log.c \
diff --git a/android/Makefile.am b/android/Makefile.am
index 36a9e82..50d0dc0 100644
--- a/android/Makefile.am
+++ b/android/Makefile.am
android/a2dp.h android/a2dp.c \
android/avctp.h android/avctp.c \
android/avrcp.h android/avrcp.c \
+ android/avrcp-lib.h android/avrcp-lib.c \
android/socket.h android/socket.c \
android/pan.h android/pan.c \
android/handsfree.h android/handsfree.c \
diff --git a/android/avrcp-lib.c b/android/avrcp-lib.c
new file mode 100644
index 0000000..ef48fa7
--- /dev/null
+++ b/android/avrcp-lib.c
+/*
+ *
+ * BlueZ - Bluetooth protocol stack for Linux
+ *
+ * Copyright (C) 2014 Intel Corporation. All rights reserved.
+ *
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2.1 of the License, or (at your option) any later version.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
+ *
+ */
+
+#ifdef HAVE_CONFIG_H
+#include <config.h>
+#endif
+
+#include <stdbool.h>
+#include <glib.h>
+
+#include "lib/bluetooth.h"
+
+#include "src/log.h"
+
+#include "avctp.h"
+#include "avrcp-lib.h"
+
+struct avrcp {
+ struct avctp *session;
+};
+
+void avrcp_shutdown(struct avrcp *session)
+{
+ if (session->session)
+ avctp_shutdown(session->session);
+
+ g_free(session);
+}
+
+struct avrcp *avrcp_new(int fd, size_t imtu, size_t omtu, uint16_t version)
+{
+ struct avrcp *session;
+
+ session = g_new0(struct avrcp, 1);
+
+ session->session = avctp_new(fd, imtu, omtu, version);
+ if (!session->session) {
+ g_free(session);
+ return NULL;
+ }
+
+ return session;
+}
+
+void avrcp_set_destroy_cb(struct avrcp *session, avrcp_destroy_cb_t cb,
+ void *user_data)
+{
+ avctp_set_destroy_cb(session->session, cb, user_data);
+}
+
+int avrcp_init_uinput(struct avrcp *session, const char *name,
+ const char *address)
+{
+ return avctp_init_uinput(session->session, name, address);
+}
diff --git a/android/avrcp-lib.h b/android/avrcp-lib.h
new file mode 100644
index 0000000..7955d56
--- /dev/null
+++ b/android/avrcp-lib.h
+/*
+ *
+ * BlueZ - Bluetooth protocol stack for Linux
+ *
+ * Copyright (C) 2014 Intel Corporation. All rights reserved.
+ *
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2.1 of the License, or (at your option) any later version.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
+ *
+ */
+
+typedef void (*avrcp_destroy_cb_t) (void *user_data);
+
+struct avrcp *avrcp_new(int fd, size_t imtu, size_t omtu, uint16_t version);
+void avrcp_shutdown(struct avrcp *session);
+void avrcp_set_destroy_cb(struct avrcp *session, avrcp_destroy_cb_t cb,
+ void *user_data);
+int avrcp_init_uinput(struct avrcp *session, const char *name,
+ const char *address);
diff --git a/android/avrcp.c b/android/avrcp.c
index 2cca64a..8ac9e2f 100644
--- a/android/avrcp.c
+++ b/android/avrcp.c
#include "src/log.h"
#include "bluetooth.h"
#include "avrcp.h"
+#include "avrcp-lib.h"
#include "hal-msg.h"
#include "ipc.h"
-#include "avctp.h"
#define L2CAP_PSM_AVCTP 0x17
struct avrcp_device {
bdaddr_t dst;
- struct avctp *session;
+ struct avrcp *session;
GIOChannel *io;
};
struct avrcp_device *dev = data;
if (dev->session)
- avctp_shutdown(dev->session);
+ avrcp_shutdown(dev->session);
if (dev->io) {
g_io_channel_shutdown(dev->io, FALSE, NULL);
return bacmp(&dev->dst, dst);
}
+static struct avrcp_device *avrcp_device_find(const bdaddr_t *dst)
+{
+ GSList *l;
+
+ l = g_slist_find_custom(devices, dst, device_cmp);
+ if (!l)
+ return NULL;
+
+ return l->data;
+}
+
static void disconnect_cb(void *data)
{
struct avrcp_device *dev = data;
char address[18];
uint16_t imtu, omtu;
GError *gerr = NULL;
- GSList *l;
int fd;
if (err) {
ba2str(&dst, address);
- l = g_slist_find_custom(devices, &dst, device_cmp);
- if (l) {
- dev = l->data;
+ dev = avrcp_device_find(&dst);
+ if (dev) {
if (dev->session) {
error("Unexpected connection");
return;
}
fd = g_io_channel_unix_get_fd(chan);
- dev->session = avctp_new(fd, imtu, omtu, 0x0100);
+ dev->session = avrcp_new(fd, imtu, omtu, 0x0100);
if (!dev->session) {
avrcp_device_free(dev);
return;
}
- avctp_set_destroy_cb(dev->session, disconnect_cb, dev);
+ avrcp_set_destroy_cb(dev->session, disconnect_cb, dev);
/* FIXME: get the real name of the device */
- avctp_init_uinput(dev->session, "bluetooth", address);
+ avrcp_init_uinput(dev->session, "bluetooth", address);
g_io_channel_set_close_on_unref(chan, FALSE);
{
struct avrcp_device *dev;
char addr[18];
- GSList *l;
DBG("");
- l = g_slist_find_custom(devices, dst, device_cmp);
- if (l)
+ if (avrcp_device_find(dst))
return;
dev = avrcp_device_new(dst);
void bt_avrcp_disconnect(const bdaddr_t *dst)
{
struct avrcp_device *dev;
- GSList *l;
DBG("");
- l = g_slist_find_custom(devices, dst, device_cmp);
- if (!l)
+ dev = avrcp_device_find(dst);
+ if (!dev)
return;
- dev = l->data;
-
if (dev->session) {
- avctp_shutdown(dev->session);
+ avrcp_shutdown(dev->session);
return;
}