From 1ad4df62d7b0ca988bc5ae62444420fc0273d53a Mon Sep 17 00:00:00 2001 From: Luiz Augusto von Dentz Date: Fri, 22 Jun 2007 19:47:53 +0000 Subject: Merge changes from git://git.infradead.org/users/vudentz/bluez-utils.git. --- audio/device.c | 201 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 201 insertions(+) create mode 100644 audio/device.c (limited to 'audio/device.c') diff --git a/audio/device.c b/audio/device.c new file mode 100644 index 00000000..50d07a2c --- /dev/null +++ b/audio/device.c @@ -0,0 +1,201 @@ +/* + * + * BlueZ - Bluetooth protocol stack for Linux + * + * Copyright (C) 2004-2007 Marcel Holtmann + * + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * This program 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 General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA + * + */ + +#ifdef HAVE_CONFIG_H +#include +#endif + +#include +#include + +#include +#include +#include + +#include "dbus.h" +#include "dbus-helper.h" +#include "logging.h" + +#include "device.h" + +void device_finish_sdp_transaction(struct device *device) +{ + char address[18], *addr_ptr = address; + DBusMessage *msg, *reply; + DBusError derr; + + ba2str(&device->bda, address); + + msg = dbus_message_new_method_call("org.bluez", device->adapter_path, + "org.bluez.Adapter", + "FinishRemoteServiceTransaction"); + if (!msg) { + error("Unable to allocate new method call"); + return; + } + + dbus_message_append_args(msg, DBUS_TYPE_STRING, &addr_ptr, + DBUS_TYPE_INVALID); + + dbus_error_init(&derr); + reply = dbus_connection_send_with_reply_and_block(device->conn, msg, -1, + &derr); + + dbus_message_unref(msg); + + if (dbus_error_is_set(&derr) || + dbus_set_error_from_message(&derr, reply)) { + error("FinishRemoteServiceTransaction(%s) failed: %s", + address, derr.message); + dbus_error_free(&derr); + return; + } + + dbus_message_unref(reply); +} + +static DBusHandlerResult device_get_address(DBusConnection *conn, + DBusMessage *msg, + void *data) +{ + struct device *device = data; + DBusMessage *reply; + char address[18], *ptr = address; + + reply = dbus_message_new_method_return(msg); + if (!reply) + return DBUS_HANDLER_RESULT_NEED_MEMORY; + + ba2str(&device->bda, address); + + dbus_message_append_args(reply, DBUS_TYPE_STRING, &ptr, + DBUS_TYPE_INVALID); + + return send_message_and_unref(conn, reply); +} + +static DBusHandlerResult device_get_connected(DBusConnection *conn, + DBusMessage *msg, + void *data) +{ + DBusMessageIter iter, array_iter; + struct device *device = data; + DBusMessage *reply; + const char *iface; + + reply = dbus_message_new_method_return(msg); + if (!reply) + return DBUS_HANDLER_RESULT_NEED_MEMORY; + + dbus_message_iter_init_append(reply, &iter); + + dbus_message_iter_open_container(&iter, DBUS_TYPE_ARRAY, + DBUS_TYPE_STRING_AS_STRING, &array_iter); + + if (device->headset && + headset_get_state(device->headset) >= HEADSET_STATE_CONNECTED) { + iface = AUDIO_HEADSET_INTERFACE; + dbus_message_iter_append_basic(&array_iter, + DBUS_TYPE_STRING, &iface); + } + + dbus_message_iter_close_container(&iter, &array_iter); + + return send_message_and_unref(conn, reply); +} + +static DBusMethodVTable device_methods[] = { + { "GetAddress", device_get_address, + "", "s" }, + { "GetConnectedInterfaces", device_get_connected, + "", "s" }, + { NULL, NULL, NULL, NULL } +}; + +static void device_free(struct device *device) +{ + if (device->headset) + headset_free(device); + + if (device->conn) + dbus_connection_unref(device->conn); + + if (device->adapter_path) + g_free(device->adapter_path); + + if (device->path) + g_free(device->path); + + g_free(device); +} + +static void device_unregister(DBusConnection *conn, void *data) +{ + struct device *device = data; + + info("Unregistered device path:%s", device->path); + + device_free(device); +} + +struct device * device_register(DBusConnection *conn, const char *path, bdaddr_t *bda) +{ + struct device *device; + bdaddr_t src; + int dev_id; + + if (!conn || !path) + return NULL; + + bacpy(&src, BDADDR_ANY); + dev_id = hci_get_route(NULL); + if ((dev_id < 0) || (hci_devba(dev_id, &src) < 0)) + return NULL; + + device = g_new0(struct device, 1); + + if (!dbus_connection_create_object_path(conn, path, device, + device_unregister)) { + error("D-Bus failed to register %s path", path); + device_free(device); + return NULL; + } + + if (!dbus_connection_register_interface(conn, + path, + AUDIO_DEVICE_INTERFACE, + device_methods, NULL, NULL)) { + error("Failed to register %s interface to %s", + AUDIO_DEVICE_INTERFACE, path); + dbus_connection_destroy_object_path(conn, path); + return NULL; + } + + device->path = g_strdup(path); + bacpy(&device->bda, bda); + device->conn = dbus_connection_ref(conn); + device->adapter_path = g_malloc0(16); + snprintf(device->adapter_path, 16, "/org/bluez/hci%d", dev_id); + + return device; +} -- cgit From d42edde61115b525ac1e9fe6ba8ead1c791d12ca Mon Sep 17 00:00:00 2001 From: Marcel Holtmann Date: Fri, 22 Jun 2007 20:09:09 +0000 Subject: Remove wrongly committed files --- audio/device.c | 201 --------------------------------------------------------- 1 file changed, 201 deletions(-) delete mode 100644 audio/device.c (limited to 'audio/device.c') diff --git a/audio/device.c b/audio/device.c deleted file mode 100644 index 50d07a2c..00000000 --- a/audio/device.c +++ /dev/null @@ -1,201 +0,0 @@ -/* - * - * BlueZ - Bluetooth protocol stack for Linux - * - * Copyright (C) 2004-2007 Marcel Holtmann - * - * - * This program is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation; either version 2 of the License, or - * (at your option) any later version. - * - * This program 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 General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program; if not, write to the Free Software - * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA - * - */ - -#ifdef HAVE_CONFIG_H -#include -#endif - -#include -#include - -#include -#include -#include - -#include "dbus.h" -#include "dbus-helper.h" -#include "logging.h" - -#include "device.h" - -void device_finish_sdp_transaction(struct device *device) -{ - char address[18], *addr_ptr = address; - DBusMessage *msg, *reply; - DBusError derr; - - ba2str(&device->bda, address); - - msg = dbus_message_new_method_call("org.bluez", device->adapter_path, - "org.bluez.Adapter", - "FinishRemoteServiceTransaction"); - if (!msg) { - error("Unable to allocate new method call"); - return; - } - - dbus_message_append_args(msg, DBUS_TYPE_STRING, &addr_ptr, - DBUS_TYPE_INVALID); - - dbus_error_init(&derr); - reply = dbus_connection_send_with_reply_and_block(device->conn, msg, -1, - &derr); - - dbus_message_unref(msg); - - if (dbus_error_is_set(&derr) || - dbus_set_error_from_message(&derr, reply)) { - error("FinishRemoteServiceTransaction(%s) failed: %s", - address, derr.message); - dbus_error_free(&derr); - return; - } - - dbus_message_unref(reply); -} - -static DBusHandlerResult device_get_address(DBusConnection *conn, - DBusMessage *msg, - void *data) -{ - struct device *device = data; - DBusMessage *reply; - char address[18], *ptr = address; - - reply = dbus_message_new_method_return(msg); - if (!reply) - return DBUS_HANDLER_RESULT_NEED_MEMORY; - - ba2str(&device->bda, address); - - dbus_message_append_args(reply, DBUS_TYPE_STRING, &ptr, - DBUS_TYPE_INVALID); - - return send_message_and_unref(conn, reply); -} - -static DBusHandlerResult device_get_connected(DBusConnection *conn, - DBusMessage *msg, - void *data) -{ - DBusMessageIter iter, array_iter; - struct device *device = data; - DBusMessage *reply; - const char *iface; - - reply = dbus_message_new_method_return(msg); - if (!reply) - return DBUS_HANDLER_RESULT_NEED_MEMORY; - - dbus_message_iter_init_append(reply, &iter); - - dbus_message_iter_open_container(&iter, DBUS_TYPE_ARRAY, - DBUS_TYPE_STRING_AS_STRING, &array_iter); - - if (device->headset && - headset_get_state(device->headset) >= HEADSET_STATE_CONNECTED) { - iface = AUDIO_HEADSET_INTERFACE; - dbus_message_iter_append_basic(&array_iter, - DBUS_TYPE_STRING, &iface); - } - - dbus_message_iter_close_container(&iter, &array_iter); - - return send_message_and_unref(conn, reply); -} - -static DBusMethodVTable device_methods[] = { - { "GetAddress", device_get_address, - "", "s" }, - { "GetConnectedInterfaces", device_get_connected, - "", "s" }, - { NULL, NULL, NULL, NULL } -}; - -static void device_free(struct device *device) -{ - if (device->headset) - headset_free(device); - - if (device->conn) - dbus_connection_unref(device->conn); - - if (device->adapter_path) - g_free(device->adapter_path); - - if (device->path) - g_free(device->path); - - g_free(device); -} - -static void device_unregister(DBusConnection *conn, void *data) -{ - struct device *device = data; - - info("Unregistered device path:%s", device->path); - - device_free(device); -} - -struct device * device_register(DBusConnection *conn, const char *path, bdaddr_t *bda) -{ - struct device *device; - bdaddr_t src; - int dev_id; - - if (!conn || !path) - return NULL; - - bacpy(&src, BDADDR_ANY); - dev_id = hci_get_route(NULL); - if ((dev_id < 0) || (hci_devba(dev_id, &src) < 0)) - return NULL; - - device = g_new0(struct device, 1); - - if (!dbus_connection_create_object_path(conn, path, device, - device_unregister)) { - error("D-Bus failed to register %s path", path); - device_free(device); - return NULL; - } - - if (!dbus_connection_register_interface(conn, - path, - AUDIO_DEVICE_INTERFACE, - device_methods, NULL, NULL)) { - error("Failed to register %s interface to %s", - AUDIO_DEVICE_INTERFACE, path); - dbus_connection_destroy_object_path(conn, path); - return NULL; - } - - device->path = g_strdup(path); - bacpy(&device->bda, bda); - device->conn = dbus_connection_ref(conn); - device->adapter_path = g_malloc0(16); - snprintf(device->adapter_path, 16, "/org/bluez/hci%d", dev_id); - - return device; -} -- cgit From a53371133fb399bd7fc70c131a82b64e7e20bac8 Mon Sep 17 00:00:00 2001 From: Luiz Augusto von Dentz Date: Fri, 22 Jun 2007 20:30:35 +0000 Subject: Add device files that implements org.bluez.audio.Device interface. --- audio/device.c | 201 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 201 insertions(+) create mode 100644 audio/device.c (limited to 'audio/device.c') diff --git a/audio/device.c b/audio/device.c new file mode 100644 index 00000000..88edfc70 --- /dev/null +++ b/audio/device.c @@ -0,0 +1,201 @@ +/* + * + * BlueZ - Bluetooth protocol stack for Linux + * + * Copyright (C) 2004-2007 Marcel Holtmann + * + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * This program 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 General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA + * + */ + +#ifdef HAVE_CONFIG_H +#include +#endif + +#include +#include + +#include +#include +#include + +#include "dbus.h" +#include "dbus-helper.h" +#include "logging.h" + +#include "device.h" + +void device_finish_sdp_transaction(struct device *device) +{ + char address[18], *addr_ptr = address; + DBusMessage *msg, *reply; + DBusError derr; + + ba2str(&device->bda, address); + + msg = dbus_message_new_method_call("org.bluez", device->adapter_path, + "org.bluez.Adapter", + "FinishRemoteServiceTransaction"); + if (!msg) { + error("Unable to allocate new method call"); + return; + } + + dbus_message_append_args(msg, DBUS_TYPE_STRING, &addr_ptr, + DBUS_TYPE_INVALID); + + dbus_error_init(&derr); + reply = dbus_connection_send_with_reply_and_block(device->conn, msg, -1, + &derr); + + dbus_message_unref(msg); + + if (dbus_error_is_set(&derr) || + dbus_set_error_from_message(&derr, reply)) { + error("FinishRemoteServiceTransaction(%s) failed: %s", + address, derr.message); + dbus_error_free(&derr); + return; + } + + dbus_message_unref(reply); +} + +static DBusHandlerResult device_get_address(DBusConnection *conn, + DBusMessage *msg, + void *data) +{ + struct device *device = data; + DBusMessage *reply; + char address[18], *ptr = address; + + reply = dbus_message_new_method_return(msg); + if (!reply) + return DBUS_HANDLER_RESULT_NEED_MEMORY; + + ba2str(&device->bda, address); + + dbus_message_append_args(reply, DBUS_TYPE_STRING, &ptr, + DBUS_TYPE_INVALID); + + return send_message_and_unref(conn, reply); +} + +static DBusHandlerResult device_get_connected(DBusConnection *conn, + DBusMessage *msg, + void *data) +{ + DBusMessageIter iter, array_iter; + struct device *device = data; + DBusMessage *reply; + const char *iface; + + reply = dbus_message_new_method_return(msg); + if (!reply) + return DBUS_HANDLER_RESULT_NEED_MEMORY; + + dbus_message_iter_init_append(reply, &iter); + + dbus_message_iter_open_container(&iter, DBUS_TYPE_ARRAY, + DBUS_TYPE_STRING_AS_STRING, &array_iter); + + if (device->headset && + headset_get_state(device->headset) >= HEADSET_STATE_CONNECTED) { + iface = AUDIO_HEADSET_INTERFACE; + dbus_message_iter_append_basic(&array_iter, + DBUS_TYPE_STRING, &iface); + } + + dbus_message_iter_close_container(&iter, &array_iter); + + return send_message_and_unref(conn, reply); +} + +static DBusMethodVTable device_methods[] = { + { "GetAddress", device_get_address, + "", "s" }, + { "GetConnectedInterfaces", device_get_connected, + "", "s" }, + { NULL, NULL, NULL, NULL } +}; + +static void device_free(struct device *device) +{ + if (device->headset) + headset_free(device); + + if (device->conn) + dbus_connection_unref(device->conn); + + if (device->adapter_path) + g_free(device->adapter_path); + + if (device->path) + g_free(device->path); + + g_free(device); +} + +static void device_unregister(DBusConnection *conn, void *data) +{ + struct device *device = data; + + info("Unregistered device path:%s", device->path); + + device_free(device); +} + +struct device * device_register(DBusConnection *conn, const char *path, bdaddr_t *bda) +{ + struct device *device; + bdaddr_t src; + int dev_id; + + if (!conn || !path) + return NULL; + + bacpy(&src, BDADDR_ANY); + dev_id = hci_get_route(NULL); + if ((dev_id < 0) || (hci_devba(dev_id, &src) < 0)) + return NULL; + + device = g_new0(struct device, 1); + + if (!dbus_connection_create_object_path(conn, path, device, + device_unregister)) { + error("D-Bus failed to register %s path", path); + device_free(device); + return NULL; + } + + if (!dbus_connection_register_interface(conn, + path, + AUDIO_DEVICE_INTERFACE, + device_methods, NULL, NULL)) { + error("Failed to register %s interface to %s", + AUDIO_DEVICE_INTERFACE, path); + dbus_connection_destroy_object_path(conn, path); + return NULL; + } + + device->path = g_strdup(path); + bacpy(&device->bda, bda); + device->conn = dbus_connection_ref(conn); + device->adapter_path = g_malloc0(16); + snprintf(device->adapter_path, 16, "/org/bluez/hci%d", dev_id); + + return device; +} -- cgit From 1a03aad91407d5b170787c24e32edfc2e673d76c Mon Sep 17 00:00:00 2001 From: Marcel Holtmann Date: Fri, 22 Jun 2007 23:50:24 +0000 Subject: Add storage support and fixup messed up coding style --- audio/device.c | 289 ++++++++++++++++++++++++++++++++------------------------- 1 file changed, 165 insertions(+), 124 deletions(-) (limited to 'audio/device.c') diff --git a/audio/device.c b/audio/device.c index 88edfc70..8442a87c 100644 --- a/audio/device.c +++ b/audio/device.c @@ -25,6 +25,12 @@ #include #endif +#include +#include +#include +#include +#include + #include #include @@ -35,167 +41,202 @@ #include "dbus.h" #include "dbus-helper.h" #include "logging.h" +#include "textfile.h" #include "device.h" -void device_finish_sdp_transaction(struct device *device) -{ - char address[18], *addr_ptr = address; - DBusMessage *msg, *reply; - DBusError derr; - - ba2str(&device->bda, address); - - msg = dbus_message_new_method_call("org.bluez", device->adapter_path, - "org.bluez.Adapter", - "FinishRemoteServiceTransaction"); - if (!msg) { - error("Unable to allocate new method call"); - return; - } - - dbus_message_append_args(msg, DBUS_TYPE_STRING, &addr_ptr, - DBUS_TYPE_INVALID); - - dbus_error_init(&derr); - reply = dbus_connection_send_with_reply_and_block(device->conn, msg, -1, - &derr); - - dbus_message_unref(msg); - - if (dbus_error_is_set(&derr) || - dbus_set_error_from_message(&derr, reply)) { - error("FinishRemoteServiceTransaction(%s) failed: %s", - address, derr.message); - dbus_error_free(&derr); - return; - } - - dbus_message_unref(reply); -} - static DBusHandlerResult device_get_address(DBusConnection *conn, - DBusMessage *msg, - void *data) + DBusMessage *msg, void *data) { - struct device *device = data; - DBusMessage *reply; - char address[18], *ptr = address; + struct device *device = data; + DBusMessage *reply; + char address[18], *ptr = address; - reply = dbus_message_new_method_return(msg); - if (!reply) - return DBUS_HANDLER_RESULT_NEED_MEMORY; + reply = dbus_message_new_method_return(msg); + if (!reply) + return DBUS_HANDLER_RESULT_NEED_MEMORY; - ba2str(&device->bda, address); + ba2str(&device->dst, address); - dbus_message_append_args(reply, DBUS_TYPE_STRING, &ptr, - DBUS_TYPE_INVALID); + dbus_message_append_args(reply, DBUS_TYPE_STRING, &ptr, + DBUS_TYPE_INVALID); - return send_message_and_unref(conn, reply); + return send_message_and_unref(conn, reply); } static DBusHandlerResult device_get_connected(DBusConnection *conn, - DBusMessage *msg, - void *data) + DBusMessage *msg, void *data) { - DBusMessageIter iter, array_iter; - struct device *device = data; - DBusMessage *reply; - const char *iface; + DBusMessageIter iter, array_iter; + struct device *device = data; + DBusMessage *reply; + const char *iface; - reply = dbus_message_new_method_return(msg); - if (!reply) - return DBUS_HANDLER_RESULT_NEED_MEMORY; + reply = dbus_message_new_method_return(msg); + if (!reply) + return DBUS_HANDLER_RESULT_NEED_MEMORY; - dbus_message_iter_init_append(reply, &iter); + dbus_message_iter_init_append(reply, &iter); - dbus_message_iter_open_container(&iter, DBUS_TYPE_ARRAY, - DBUS_TYPE_STRING_AS_STRING, &array_iter); + dbus_message_iter_open_container(&iter, DBUS_TYPE_ARRAY, + DBUS_TYPE_STRING_AS_STRING, + &array_iter); - if (device->headset && - headset_get_state(device->headset) >= HEADSET_STATE_CONNECTED) { - iface = AUDIO_HEADSET_INTERFACE; - dbus_message_iter_append_basic(&array_iter, - DBUS_TYPE_STRING, &iface); - } + if (device->headset && + headset_get_state(device->headset) >= HEADSET_STATE_CONNECTED) { + iface = AUDIO_HEADSET_INTERFACE; + dbus_message_iter_append_basic(&array_iter, + DBUS_TYPE_STRING, &iface); + } - dbus_message_iter_close_container(&iter, &array_iter); + dbus_message_iter_close_container(&iter, &array_iter); - return send_message_and_unref(conn, reply); + return send_message_and_unref(conn, reply); } static DBusMethodVTable device_methods[] = { - { "GetAddress", device_get_address, - "", "s" }, - { "GetConnectedInterfaces", device_get_connected, - "", "s" }, - { NULL, NULL, NULL, NULL } + { "GetAddress", device_get_address, "", "s" }, + { "GetConnectedInterfaces", device_get_connected, "", "s" }, + { NULL, NULL, NULL, NULL } }; static void device_free(struct device *device) { - if (device->headset) - headset_free(device); + if (device->headset) + headset_free(device); - if (device->conn) - dbus_connection_unref(device->conn); + if (device->conn) + dbus_connection_unref(device->conn); - if (device->adapter_path) - g_free(device->adapter_path); + if (device->adapter_path) + g_free(device->adapter_path); - if (device->path) - g_free(device->path); + if (device->path) + g_free(device->path); - g_free(device); + g_free(device); } static void device_unregister(DBusConnection *conn, void *data) { - struct device *device = data; + struct device *device = data; + + info("Unregistered device path:%s", device->path); - info("Unregistered device path:%s", device->path); + device_free(device); +} + +struct device *device_register(DBusConnection *conn, + const char *path, bdaddr_t *bda) +{ + struct device *device; + bdaddr_t src; + int dev_id; + + if (!conn || !path) + return NULL; + + bacpy(&src, BDADDR_ANY); + dev_id = hci_get_route(NULL); + if ((dev_id < 0) || (hci_devba(dev_id, &src) < 0)) + return NULL; + + device = g_new0(struct device, 1); + + if (!dbus_connection_create_object_path(conn, path, device, + device_unregister)) { + error("D-Bus failed to register %s path", path); + device_free(device); + return NULL; + } + + if (!dbus_connection_register_interface(conn, path, + AUDIO_DEVICE_INTERFACE, device_methods, NULL, NULL)) { + error("Failed to register %s interface to %s", + AUDIO_DEVICE_INTERFACE, path); + dbus_connection_destroy_object_path(conn, path); + return NULL; + } + + device->path = g_strdup(path); + bacpy(&device->dst, bda); + bacpy(&device->src, &src); + device->conn = dbus_connection_ref(conn); + device->adapter_path = g_malloc0(16); + snprintf(device->adapter_path, 16, "/org/bluez/hci%d", dev_id); + + return device; +} - device_free(device); +int device_store(struct device *device, gboolean is_default) +{ + char value[64]; + char filename[PATH_MAX + 1]; + char src_addr[18], dst_addr[18]; + int err; + + if (!device->path) + return -EINVAL; + + ba2str(&device->dst, dst_addr); + ba2str(&device->src, src_addr); + + create_name(filename, PATH_MAX, STORAGEDIR, src_addr, "audio"); + create_file(filename, S_IRUSR | S_IWUSR | S_IRGRP | S_IROTH); + + if (is_default) + err = textfile_put(filename, "default", dst_addr); + else { + if (device->headset) + snprintf(value, 64, "headset"); + if (device->gateway) + snprintf(value, 64, "%s:gateway", value); + if (device->sink) + snprintf(value, 64, "%s:sink", value); + if (device->source) + snprintf(value, 64, "%s:source", value); + if (device->control) + snprintf(value, 64, "%s:control", value); + if (device->target) + snprintf(value, 64, "%s:target", value); + err = textfile_put(filename, dst_addr, value); + } + + return err; } -struct device * device_register(DBusConnection *conn, const char *path, bdaddr_t *bda) +void device_finish_sdp_transaction(struct device *device) { - struct device *device; - bdaddr_t src; - int dev_id; - - if (!conn || !path) - return NULL; - - bacpy(&src, BDADDR_ANY); - dev_id = hci_get_route(NULL); - if ((dev_id < 0) || (hci_devba(dev_id, &src) < 0)) - return NULL; - - device = g_new0(struct device, 1); - - if (!dbus_connection_create_object_path(conn, path, device, - device_unregister)) { - error("D-Bus failed to register %s path", path); - device_free(device); - return NULL; - } - - if (!dbus_connection_register_interface(conn, - path, - AUDIO_DEVICE_INTERFACE, - device_methods, NULL, NULL)) { - error("Failed to register %s interface to %s", - AUDIO_DEVICE_INTERFACE, path); - dbus_connection_destroy_object_path(conn, path); - return NULL; - } - - device->path = g_strdup(path); - bacpy(&device->bda, bda); - device->conn = dbus_connection_ref(conn); - device->adapter_path = g_malloc0(16); - snprintf(device->adapter_path, 16, "/org/bluez/hci%d", dev_id); - - return device; + char address[18], *addr_ptr = address; + DBusMessage *msg, *reply; + DBusError derr; + + ba2str(&device->dst, address); + + msg = dbus_message_new_method_call("org.bluez", device->adapter_path, + "org.bluez.Adapter", + "FinishRemoteServiceTransaction"); + if (!msg) { + error("Unable to allocate new method call"); + return; + } + + dbus_message_append_args(msg, DBUS_TYPE_STRING, &addr_ptr, + DBUS_TYPE_INVALID); + + dbus_error_init(&derr); + reply = dbus_connection_send_with_reply_and_block(device->conn, + msg, -1, &derr); + + dbus_message_unref(msg); + + if (dbus_error_is_set(&derr) || + dbus_set_error_from_message(&derr, reply)) { + error("FinishRemoteServiceTransaction(%s) failed: %s", + address, derr.message); + dbus_error_free(&derr); + return; + } + + dbus_message_unref(reply); } -- cgit From 2cc84f09868d94aad737853b12ab41f4b83a1db9 Mon Sep 17 00:00:00 2001 From: Luiz Augusto von Dentz Date: Sat, 23 Jun 2007 18:21:23 +0000 Subject: Fix storage code. --- audio/device.c | 36 ++++++++++++++++-------------------- 1 file changed, 16 insertions(+), 20 deletions(-) (limited to 'audio/device.c') diff --git a/audio/device.c b/audio/device.c index 8442a87c..785d0115 100644 --- a/audio/device.c +++ b/audio/device.c @@ -83,7 +83,7 @@ static DBusHandlerResult device_get_connected(DBusConnection *conn, &array_iter); if (device->headset && - headset_get_state(device->headset) >= HEADSET_STATE_CONNECTED) { + headset_get_state(device) >= HEADSET_STATE_CONNECTED) { iface = AUDIO_HEADSET_INTERFACE; dbus_message_iter_append_basic(&array_iter, DBUS_TYPE_STRING, &iface); @@ -173,7 +173,6 @@ int device_store(struct device *device, gboolean is_default) char value[64]; char filename[PATH_MAX + 1]; char src_addr[18], dst_addr[18]; - int err; if (!device->path) return -EINVAL; @@ -185,24 +184,21 @@ int device_store(struct device *device, gboolean is_default) create_file(filename, S_IRUSR | S_IWUSR | S_IRGRP | S_IROTH); if (is_default) - err = textfile_put(filename, "default", dst_addr); - else { - if (device->headset) - snprintf(value, 64, "headset"); - if (device->gateway) - snprintf(value, 64, "%s:gateway", value); - if (device->sink) - snprintf(value, 64, "%s:sink", value); - if (device->source) - snprintf(value, 64, "%s:source", value); - if (device->control) - snprintf(value, 64, "%s:control", value); - if (device->target) - snprintf(value, 64, "%s:target", value); - err = textfile_put(filename, dst_addr, value); - } - - return err; + textfile_put(filename, "default", dst_addr); + if (device->headset) + snprintf(value, 64, "headset"); + else if (device->gateway) + snprintf(value, 64, "gateway"); + else if (device->sink) + snprintf(value, 64, "sink"); + else if (device->source) + snprintf(value, 64, "source"); + else if (device->control) + snprintf(value, 64, "control"); + else + snprintf(value, 64, "target"); + + return textfile_put(filename, dst_addr, value); } void device_finish_sdp_transaction(struct device *device) -- cgit From 2a2c204cd0e4bcf0a603ba72be9a50203a817b54 Mon Sep 17 00:00:00 2001 From: Luiz Augusto von Dentz Date: Wed, 27 Jun 2007 17:03:07 +0000 Subject: Make storage to also save rfcomm channel, minor fixes to alsa plugin and fixes for service shutdown. --- audio/device.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'audio/device.c') diff --git a/audio/device.c b/audio/device.c index 785d0115..884a2661 100644 --- a/audio/device.c +++ b/audio/device.c @@ -186,7 +186,7 @@ int device_store(struct device *device, gboolean is_default) if (is_default) textfile_put(filename, "default", dst_addr); if (device->headset) - snprintf(value, 64, "headset"); + snprintf(value, 64, "headset#%d", headset_get_channel(device)); else if (device->gateway) snprintf(value, 64, "gateway"); else if (device->sink) -- cgit From 389d6a32fa14abefec394b9ebfa3b2deb51489c7 Mon Sep 17 00:00:00 2001 From: Luiz Augusto von Dentz Date: Wed, 27 Jun 2007 18:31:08 +0000 Subject: Revert changes on storage, rfcomm might change over time. --- audio/device.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'audio/device.c') diff --git a/audio/device.c b/audio/device.c index 884a2661..785d0115 100644 --- a/audio/device.c +++ b/audio/device.c @@ -186,7 +186,7 @@ int device_store(struct device *device, gboolean is_default) if (is_default) textfile_put(filename, "default", dst_addr); if (device->headset) - snprintf(value, 64, "headset#%d", headset_get_channel(device)); + snprintf(value, 64, "headset"); else if (device->gateway) snprintf(value, 64, "gateway"); else if (device->sink) -- cgit From 6763ebb3c231740c66a235f94d56e8d8cc213d90 Mon Sep 17 00:00:00 2001 From: Johan Hedberg Date: Sat, 11 Aug 2007 11:05:24 +0000 Subject: Integrate A2DP work from Johan's and Luiz's GIT trees --- audio/device.c | 207 +++++++++++++++++++++++++++++++++++++++++++++------------ 1 file changed, 166 insertions(+), 41 deletions(-) (limited to 'audio/device.c') diff --git a/audio/device.c b/audio/device.c index 785d0115..af7cca80 100644 --- a/audio/device.c +++ b/audio/device.c @@ -100,21 +100,24 @@ static DBusMethodVTable device_methods[] = { { NULL, NULL, NULL, NULL } }; -static void device_free(struct device *device) +static void device_free(struct device *dev) { - if (device->headset) - headset_free(device); + if (dev->headset) + headset_free(dev); - if (device->conn) - dbus_connection_unref(device->conn); + if (dev->sink) + sink_free(dev); - if (device->adapter_path) - g_free(device->adapter_path); + if (dev->conn) + dbus_connection_unref(dev->conn); - if (device->path) - g_free(device->path); + if (dev->adapter_path) + g_free(dev->adapter_path); - g_free(device); + if (dev->path) + g_free(dev->path); + + g_free(dev); } static void device_unregister(DBusConnection *conn, void *data) @@ -129,7 +132,7 @@ static void device_unregister(DBusConnection *conn, void *data) struct device *device_register(DBusConnection *conn, const char *path, bdaddr_t *bda) { - struct device *device; + struct device *dev; bdaddr_t src; int dev_id; @@ -141,12 +144,12 @@ struct device *device_register(DBusConnection *conn, if ((dev_id < 0) || (hci_devba(dev_id, &src) < 0)) return NULL; - device = g_new0(struct device, 1); + dev = g_new0(struct device, 1); - if (!dbus_connection_create_object_path(conn, path, device, + if (!dbus_connection_create_object_path(conn, path, dev, device_unregister)) { error("D-Bus failed to register %s path", path); - device_free(device); + device_free(dev); return NULL; } @@ -158,58 +161,69 @@ struct device *device_register(DBusConnection *conn, return NULL; } - device->path = g_strdup(path); - bacpy(&device->dst, bda); - bacpy(&device->src, &src); - device->conn = dbus_connection_ref(conn); - device->adapter_path = g_malloc0(16); - snprintf(device->adapter_path, 16, "/org/bluez/hci%d", dev_id); + dev->path = g_strdup(path); + bacpy(&dev->dst, bda); + bacpy(&dev->src, &src); + dev->conn = dbus_connection_ref(conn); + dev->adapter_path = g_malloc0(16); + snprintf(dev->adapter_path, 16, "/org/bluez/hci%d", dev_id); - return device; + return dev; } -int device_store(struct device *device, gboolean is_default) +int device_store(struct device *dev, gboolean is_default) { char value[64]; char filename[PATH_MAX + 1]; char src_addr[18], dst_addr[18]; + int offset = 0; - if (!device->path) + if (!dev->path) return -EINVAL; - ba2str(&device->dst, dst_addr); - ba2str(&device->src, src_addr); + ba2str(&dev->dst, dst_addr); + ba2str(&dev->src, src_addr); create_name(filename, PATH_MAX, STORAGEDIR, src_addr, "audio"); create_file(filename, S_IRUSR | S_IWUSR | S_IRGRP | S_IROTH); if (is_default) textfile_put(filename, "default", dst_addr); - if (device->headset) - snprintf(value, 64, "headset"); - else if (device->gateway) - snprintf(value, 64, "gateway"); - else if (device->sink) - snprintf(value, 64, "sink"); - else if (device->source) - snprintf(value, 64, "source"); - else if (device->control) - snprintf(value, 64, "control"); - else - snprintf(value, 64, "target"); + if (dev->headset) { + snprintf(value, 64, "headset "); + offset += strlen("headset "); + } + if (dev->gateway) { + snprintf(value + offset, 64 - offset, "gateway "); + offset += strlen("gateway "); + } + if (dev->sink) { + snprintf(value + offset, 64 - offset, "sink "); + offset += strlen("sink "); + } + if (dev->source) { + snprintf(value + offset, 64 - offset, "source "); + offset += strlen("source "); + } + if (dev->control) { + snprintf(value + offset, 64 - offset, "control "); + offset += strlen("control "); + } + if (dev->target) + snprintf(value + offset, 64 - offset, "target"); return textfile_put(filename, dst_addr, value); } -void device_finish_sdp_transaction(struct device *device) +void device_finish_sdp_transaction(struct device *dev) { char address[18], *addr_ptr = address; DBusMessage *msg, *reply; DBusError derr; - ba2str(&device->dst, address); + ba2str(&dev->dst, address); - msg = dbus_message_new_method_call("org.bluez", device->adapter_path, + msg = dbus_message_new_method_call("org.bluez", dev->adapter_path, "org.bluez.Adapter", "FinishRemoteServiceTransaction"); if (!msg) { @@ -221,7 +235,7 @@ void device_finish_sdp_transaction(struct device *device) DBUS_TYPE_INVALID); dbus_error_init(&derr); - reply = dbus_connection_send_with_reply_and_block(device->conn, + reply = dbus_connection_send_with_reply_and_block(dev->conn, msg, -1, &derr); dbus_message_unref(msg); @@ -236,3 +250,114 @@ void device_finish_sdp_transaction(struct device *device) dbus_message_unref(reply); } + +int device_get_config(struct device *dev, int sock, struct ipc_packet *req, + int pkt_len, struct ipc_data_cfg **rsp) +{ + if (dev->sink && sink_is_active(dev)) + return sink_get_config(dev, sock, req, pkt_len, rsp); + else if (dev->headset && headset_is_active(dev)) + return headset_get_config(dev, sock, req, pkt_len, rsp); + else if (dev->sink) + return sink_get_config(dev, sock, req, pkt_len, rsp); + else if (dev->headset) + return headset_get_config(dev, sock, req, pkt_len, rsp); + + return -EINVAL; +} + +static avdtp_state_t ipc_to_avdtp_state(uint8_t ipc_state) +{ + switch (ipc_state) { + case STATE_DISCONNECTED: + return AVDTP_STATE_IDLE; + case STATE_CONNECTING: + return AVDTP_STATE_CONFIGURED; + case STATE_CONNECTED: + return AVDTP_STATE_OPEN; + case STATE_STREAM_STARTING: + case STATE_STREAMING: + return AVDTP_STATE_STREAMING; + default: + error("Unknown ipc state"); + return AVDTP_STATE_IDLE; + } +} + +static headset_state_t ipc_to_hs_state(uint8_t ipc_state) +{ + switch (ipc_state) { + case STATE_DISCONNECTED: + return HEADSET_STATE_DISCONNECTED; + case STATE_CONNECTING: + return HEADSET_STATE_CONNECT_IN_PROGRESS; + case STATE_CONNECTED: + return HEADSET_STATE_CONNECTED; + case STATE_STREAM_STARTING: + return HEADSET_STATE_PLAY_IN_PROGRESS; + case STATE_STREAMING: + return HEADSET_STATE_PLAYING; + default: + error("Unknown ipc state"); + return HEADSET_STATE_DISCONNECTED; + } +} + +void device_set_state(struct device *dev, uint8_t state) +{ + if (dev->sink && sink_is_active(dev)) + sink_set_state(dev, ipc_to_avdtp_state(state)); + else if (dev->headset && headset_is_active(dev)) + headset_set_state(dev, ipc_to_hs_state(state)); +} + +static uint8_t avdtp_to_ipc_state(avdtp_state_t state) +{ + switch (state) { + case AVDTP_STATE_IDLE: + return STATE_DISCONNECTED; + case AVDTP_STATE_CONFIGURED: + return STATE_CONNECTING; + case AVDTP_STATE_OPEN: + return STATE_CONNECTED; + case AVDTP_STATE_STREAMING: + return STATE_STREAMING; + default: + error("Unknown avdt state"); + return AVDTP_STATE_IDLE; + } +} + +static uint8_t hs_to_ipc_state(headset_state_t state) +{ + switch (state) { + case HEADSET_STATE_DISCONNECTED: + return STATE_DISCONNECTED; + case HEADSET_STATE_CONNECT_IN_PROGRESS: + return STATE_CONNECTING; + case HEADSET_STATE_CONNECTED: + return STATE_CONNECTED; + case HEADSET_STATE_PLAY_IN_PROGRESS: + return STATE_STREAMING; + default: + error("Unknown headset state"); + return AVDTP_STATE_IDLE; + } +} + +uint8_t device_get_state(struct device *dev) +{ + avdtp_state_t sink_state; + headset_state_t hs_state; + + if (dev->sink && sink_is_active(dev)) { + sink_state = sink_get_state(dev); + return avdtp_to_ipc_state(sink_state); + } + else if (dev->headset && headset_is_active(dev)) { + hs_state = headset_get_state(dev); + return hs_to_ipc_state(hs_state); + } + + return STATE_DISCONNECTED; +} -- cgit From c1761757dfeb3bf1802c5486d652d8f3852f939e Mon Sep 17 00:00:00 2001 From: Johan Hedberg Date: Sat, 11 Aug 2007 15:11:13 +0000 Subject: Get rid of some valgrind warnings caused by hci_get_route(NULL) calls --- audio/device.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'audio/device.c') diff --git a/audio/device.c b/audio/device.c index af7cca80..1d39cb16 100644 --- a/audio/device.c +++ b/audio/device.c @@ -140,7 +140,7 @@ struct device *device_register(DBusConnection *conn, return NULL; bacpy(&src, BDADDR_ANY); - dev_id = hci_get_route(NULL); + dev_id = hci_get_route(&src); if ((dev_id < 0) || (hci_devba(dev_id, &src) < 0)) return NULL; -- cgit From 9494c146cec1df466c2f331957748beeac8d745a Mon Sep 17 00:00:00 2001 From: Johan Hedberg Date: Sat, 11 Aug 2007 15:52:27 +0000 Subject: Remove redundant stream fd from config response --- audio/device.c | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) (limited to 'audio/device.c') diff --git a/audio/device.c b/audio/device.c index 1d39cb16..18e494c1 100644 --- a/audio/device.c +++ b/audio/device.c @@ -252,16 +252,16 @@ void device_finish_sdp_transaction(struct device *dev) } int device_get_config(struct device *dev, int sock, struct ipc_packet *req, - int pkt_len, struct ipc_data_cfg **rsp) + int pkt_len, struct ipc_data_cfg **rsp, int *fd) { if (dev->sink && sink_is_active(dev)) - return sink_get_config(dev, sock, req, pkt_len, rsp); + return sink_get_config(dev, sock, req, pkt_len, rsp, fd); else if (dev->headset && headset_is_active(dev)) - return headset_get_config(dev, sock, req, pkt_len, rsp); + return headset_get_config(dev, sock, req, pkt_len, rsp, fd); else if (dev->sink) - return sink_get_config(dev, sock, req, pkt_len, rsp); + return sink_get_config(dev, sock, req, pkt_len, rsp, fd); else if (dev->headset) - return headset_get_config(dev, sock, req, pkt_len, rsp); + return headset_get_config(dev, sock, req, pkt_len, rsp, fd); return -EINVAL; } -- cgit From d013a1eaa7beebbb49c1fe0015c70ad81566d97c Mon Sep 17 00:00:00 2001 From: Johan Hedberg Date: Sun, 12 Aug 2007 23:58:15 +0000 Subject: Clean up mess with header files --- audio/device.c | 2 ++ 1 file changed, 2 insertions(+) (limited to 'audio/device.c') diff --git a/audio/device.c b/audio/device.c index 18e494c1..54d4bb6f 100644 --- a/audio/device.c +++ b/audio/device.c @@ -43,6 +43,8 @@ #include "logging.h" #include "textfile.h" +#include "headset.h" +#include "sink.h" #include "device.h" static DBusHandlerResult device_get_address(DBusConnection *conn, -- cgit From c2833e263d6cfc4cf82f4bfdcc59640a4071aeae Mon Sep 17 00:00:00 2001 From: Johan Hedberg Date: Mon, 13 Aug 2007 08:14:22 +0000 Subject: Remove ifndef protections and includes from .h files --- audio/device.c | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) (limited to 'audio/device.c') diff --git a/audio/device.c b/audio/device.c index 54d4bb6f..119a4e4f 100644 --- a/audio/device.c +++ b/audio/device.c @@ -37,15 +37,19 @@ #include #include #include +#include +#include #include "dbus.h" #include "dbus-helper.h" #include "logging.h" #include "textfile.h" +#include "ipc.h" +#include "device.h" +#include "avdtp.h" #include "headset.h" #include "sink.h" -#include "device.h" static DBusHandlerResult device_get_address(DBusConnection *conn, DBusMessage *msg, void *data) -- cgit From 8f0de90a8fd518bc5a1b0c63a6b9d2357375a287 Mon Sep 17 00:00:00 2001 From: Luiz Augusto von Dentz Date: Mon, 13 Aug 2007 17:16:12 +0000 Subject: Fix RemoveDevice bug that prevent its removal from storage. --- audio/device.c | 13 +++++++++++++ 1 file changed, 13 insertions(+) (limited to 'audio/device.c') diff --git a/audio/device.c b/audio/device.c index 119a4e4f..450b2afe 100644 --- a/audio/device.c +++ b/audio/device.c @@ -221,6 +221,19 @@ int device_store(struct device *dev, gboolean is_default) return textfile_put(filename, dst_addr, value); } +int device_remove_stored(struct device *dev) +{ + char filename[PATH_MAX + 1]; + char src_addr[18], dst_addr[18]; + + ba2str(&dev->dst, dst_addr); + ba2str(&dev->src, src_addr); + + create_name(filename, PATH_MAX, STORAGEDIR, src_addr, "audio"); + + return textfile_del(filename, dst_addr); +} + void device_finish_sdp_transaction(struct device *dev) { char address[18], *addr_ptr = address; -- cgit From 962e84af6703db98d6fccaa654502f040619a846 Mon Sep 17 00:00:00 2001 From: Johan Hedberg Date: Wed, 15 Aug 2007 09:56:28 +0000 Subject: Use FindAdapter to resolve adapter paths --- audio/device.c | 60 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++-- 1 file changed, 58 insertions(+), 2 deletions(-) (limited to 'audio/device.c') diff --git a/audio/device.c b/audio/device.c index 450b2afe..87ddf5b7 100644 --- a/audio/device.c +++ b/audio/device.c @@ -135,12 +135,67 @@ static void device_unregister(DBusConnection *conn, void *data) device_free(device); } +char *find_adapter(DBusConnection *conn, bdaddr_t *src) +{ + DBusMessage *msg, *reply; + DBusError derr; + char address[18], *addr_ptr = address; + char *path, *ret; + + msg = dbus_message_new_method_call("org.bluez", "/org/bluez", + "org.bluez.Manager", + "FindAdapter"); + if (!msg) { + error("Unable to allocate new method call"); + return NULL; + } + + ba2str(src, address); + + dbus_message_append_args(msg, DBUS_TYPE_STRING, &addr_ptr, + DBUS_TYPE_INVALID); + + dbus_error_init(&derr); + reply = dbus_connection_send_with_reply_and_block(conn, msg, -1, + &derr); + + dbus_message_unref(msg); + + if (dbus_error_is_set(&derr) || + dbus_set_error_from_message(&derr, reply)) { + error("FindAdapter(%s) failed: %s", address, derr.message); + dbus_error_free(&derr); + return NULL; + } + + dbus_error_init(&derr); + dbus_message_get_args(reply, &derr, + DBUS_TYPE_STRING, &path, + DBUS_TYPE_INVALID); + + if (dbus_error_is_set(&derr)) { + error("Unable to get message args"); + dbus_message_unref(reply); + dbus_error_free(&derr); + return FALSE; + } + + ret = g_strdup(path); + + dbus_message_unref(reply); + + debug("Got path %s for adapter with address %s", ret, address); + + return ret; +} + struct device *device_register(DBusConnection *conn, const char *path, bdaddr_t *bda) { struct device *dev; bdaddr_t src; int dev_id; + char *adapter_path; if (!conn || !path) return NULL; @@ -150,6 +205,8 @@ struct device *device_register(DBusConnection *conn, if ((dev_id < 0) || (hci_devba(dev_id, &src) < 0)) return NULL; + adapter_path = find_adapter(conn, &src); + dev = g_new0(struct device, 1); if (!dbus_connection_create_object_path(conn, path, dev, @@ -171,8 +228,7 @@ struct device *device_register(DBusConnection *conn, bacpy(&dev->dst, bda); bacpy(&dev->src, &src); dev->conn = dbus_connection_ref(conn); - dev->adapter_path = g_malloc0(16); - snprintf(dev->adapter_path, 16, "/org/bluez/hci%d", dev_id); + dev->adapter_path = adapter_path; return dev; } -- cgit From a79bcc5733cb5898abb878fb3cfe8ba27fef7bdf Mon Sep 17 00:00:00 2001 From: Johan Hedberg Date: Wed, 15 Aug 2007 09:58:19 +0000 Subject: check find_adapter return value for NULL --- audio/device.c | 2 ++ 1 file changed, 2 insertions(+) (limited to 'audio/device.c') diff --git a/audio/device.c b/audio/device.c index 87ddf5b7..63ab7778 100644 --- a/audio/device.c +++ b/audio/device.c @@ -206,6 +206,8 @@ struct device *device_register(DBusConnection *conn, return NULL; adapter_path = find_adapter(conn, &src); + if (!adapter_path) + return NULL; dev = g_new0(struct device, 1); -- cgit From b1cd269c68b76018c2aabd550d37b3b7348e5cd6 Mon Sep 17 00:00:00 2001 From: Johan Hedberg Date: Wed, 15 Aug 2007 10:00:51 +0000 Subject: Yet another fix (memory leak) to using find_adapter --- audio/device.c | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) (limited to 'audio/device.c') diff --git a/audio/device.c b/audio/device.c index 63ab7778..fe3af8cb 100644 --- a/audio/device.c +++ b/audio/device.c @@ -195,7 +195,6 @@ struct device *device_register(DBusConnection *conn, struct device *dev; bdaddr_t src; int dev_id; - char *adapter_path; if (!conn || !path) return NULL; @@ -205,12 +204,14 @@ struct device *device_register(DBusConnection *conn, if ((dev_id < 0) || (hci_devba(dev_id, &src) < 0)) return NULL; - adapter_path = find_adapter(conn, &src); - if (!adapter_path) - return NULL; - dev = g_new0(struct device, 1); + dev->adapter_path = find_adapter(conn, &src); + if (!dev->adapter_path) { + device_free(dev); + return NULL; + } + if (!dbus_connection_create_object_path(conn, path, dev, device_unregister)) { error("D-Bus failed to register %s path", path); @@ -230,7 +231,6 @@ struct device *device_register(DBusConnection *conn, bacpy(&dev->dst, bda); bacpy(&dev->src, &src); dev->conn = dbus_connection_ref(conn); - dev->adapter_path = adapter_path; return dev; } -- cgit From cdd9e2e17ad674e5fc1a5ed19643880ef61d28c7 Mon Sep 17 00:00:00 2001 From: Johan Hedberg Date: Thu, 16 Aug 2007 15:42:10 +0000 Subject: Rework interfacing with the avdtp state machine --- audio/device.c | 25 ++----------------------- 1 file changed, 2 insertions(+), 23 deletions(-) (limited to 'audio/device.c') diff --git a/audio/device.c b/audio/device.c index fe3af8cb..2a6498ee 100644 --- a/audio/device.c +++ b/audio/device.c @@ -328,21 +328,7 @@ void device_finish_sdp_transaction(struct device *dev) dbus_message_unref(reply); } -int device_get_config(struct device *dev, int sock, struct ipc_packet *req, - int pkt_len, struct ipc_data_cfg **rsp, int *fd) -{ - if (dev->sink && sink_is_active(dev)) - return sink_get_config(dev, sock, req, pkt_len, rsp, fd); - else if (dev->headset && headset_is_active(dev)) - return headset_get_config(dev, sock, req, pkt_len, rsp, fd); - else if (dev->sink) - return sink_get_config(dev, sock, req, pkt_len, rsp, fd); - else if (dev->headset) - return headset_get_config(dev, sock, req, pkt_len, rsp, fd); - - return -EINVAL; -} - +#if 0 static avdtp_state_t ipc_to_avdtp_state(uint8_t ipc_state) { switch (ipc_state) { @@ -379,14 +365,7 @@ static headset_state_t ipc_to_hs_state(uint8_t ipc_state) return HEADSET_STATE_DISCONNECTED; } } - -void device_set_state(struct device *dev, uint8_t state) -{ - if (dev->sink && sink_is_active(dev)) - sink_set_state(dev, ipc_to_avdtp_state(state)); - else if (dev->headset && headset_is_active(dev)) - headset_set_state(dev, ipc_to_hs_state(state)); -} +#endif static uint8_t avdtp_to_ipc_state(avdtp_state_t state) { -- cgit From 92f94938b981fe6a892e365670d5fa4d58c94283 Mon Sep 17 00:00:00 2001 From: Marcel Holtmann Date: Thu, 23 Aug 2007 23:37:15 +0000 Subject: Add support for ALSA parameters --- audio/device.c | 23 +++++++++++++++++++++++ 1 file changed, 23 insertions(+) (limited to 'audio/device.c') diff --git a/audio/device.c b/audio/device.c index 2a6498ee..2c06233e 100644 --- a/audio/device.c +++ b/audio/device.c @@ -417,3 +417,26 @@ uint8_t device_get_state(struct device *dev) return STATE_DISCONNECTED; } + +gboolean device_is_connected(struct device *dev, const char *interface) +{ + if (!interface) { + if ((dev->sink || dev->source) && + avdtp_is_connected(&dev->src, &dev->dst)) + return TRUE; + + if (dev->headset && headset_is_active(dev)) + return TRUE; + } + else if (!strcmp(interface, AUDIO_SINK_INTERFACE) && dev->sink && + avdtp_is_connected(&dev->src, &dev->dst)) + return TRUE; + else if (!strcmp(interface, AUDIO_SOURCE_INTERFACE) && dev->source && + avdtp_is_connected(&dev->src, &dev->dst)) + return TRUE; + else if (!strcmp(interface, AUDIO_HEADSET_INTERFACE) && dev->headset && + headset_is_active(dev)) + return TRUE; + + return FALSE; +} -- cgit From dad4c62b54ab078c1d5525e80be9c6391ea1731a Mon Sep 17 00:00:00 2001 From: Johan Hedberg Date: Wed, 29 Aug 2007 11:23:12 +0000 Subject: Add GetName method to Device interface --- audio/device.c | 52 +++++++++++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 51 insertions(+), 1 deletion(-) (limited to 'audio/device.c') diff --git a/audio/device.c b/audio/device.c index 2c06233e..4f47bcb2 100644 --- a/audio/device.c +++ b/audio/device.c @@ -45,6 +45,7 @@ #include "logging.h" #include "textfile.h" +#include "error.h" #include "ipc.h" #include "device.h" #include "avdtp.h" @@ -70,6 +71,54 @@ static DBusHandlerResult device_get_address(DBusConnection *conn, return send_message_and_unref(conn, reply); } +static DBusHandlerResult device_get_name(DBusConnection *conn, + DBusMessage *msg, void *data) +{ + struct device *device = data; + DBusMessage *reply, *reply2, *msg2; + DBusError derr; + const char *name; + char address[18], *addr_ptr = address; + + msg2 = dbus_message_new_method_call("org.bluez", device->adapter_path, + "org.bluez.Adapter", "GetRemoteName"); + if (!msg2) + return DBUS_HANDLER_RESULT_NEED_MEMORY; + + ba2str(&device->dst, address); + dbus_message_append_args(msg2, DBUS_TYPE_STRING, &addr_ptr, + DBUS_TYPE_INVALID); + + dbus_error_init(&derr); + reply2 = dbus_connection_send_with_reply_and_block(conn, msg2, -1, + &derr); + + dbus_message_unref(msg2); + + if (dbus_error_is_set(&derr)) { + error("%s GetRemoteName(): %s", device->adapter_path, + derr.message); + dbus_error_free(&derr); + return err_failed(conn, msg, "Unable to get remote name"); + } + + + reply = dbus_message_new_method_return(msg); + if (!reply) + return DBUS_HANDLER_RESULT_NEED_MEMORY; + + dbus_message_get_args(reply2, NULL, + DBUS_TYPE_STRING, &name, + DBUS_TYPE_INVALID); + + dbus_message_append_args(reply, DBUS_TYPE_STRING, &name, + DBUS_TYPE_INVALID); + + dbus_message_unref(reply2); + + return send_message_and_unref(conn, reply); +} + static DBusHandlerResult device_get_connected(DBusConnection *conn, DBusMessage *msg, void *data) { @@ -102,7 +151,8 @@ static DBusHandlerResult device_get_connected(DBusConnection *conn, static DBusMethodVTable device_methods[] = { { "GetAddress", device_get_address, "", "s" }, - { "GetConnectedInterfaces", device_get_connected, "", "s" }, + { "GetName", device_get_name, "", "s" }, + { "GetConnectedInterfaces", device_get_connected, "", "as" }, { NULL, NULL, NULL, NULL } }; -- cgit From c13f5169711913b9b6d3ee40740480fe234491cd Mon Sep 17 00:00:00 2001 From: Johan Hedberg Date: Wed, 29 Aug 2007 11:41:15 +0000 Subject: Add GetAdapter method and update API documentation --- audio/device.c | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) (limited to 'audio/device.c') diff --git a/audio/device.c b/audio/device.c index 4f47bcb2..9c90ed43 100644 --- a/audio/device.c +++ b/audio/device.c @@ -119,6 +119,26 @@ static DBusHandlerResult device_get_name(DBusConnection *conn, return send_message_and_unref(conn, reply); } +static DBusHandlerResult device_get_adapter(DBusConnection *conn, + DBusMessage *msg, void *data) +{ + struct device *device = data; + DBusMessage *reply; + char address[18], *ptr = address; + + reply = dbus_message_new_method_return(msg); + if (!reply) + return DBUS_HANDLER_RESULT_NEED_MEMORY; + + ba2str(&device->src, address); + + dbus_message_append_args(reply, DBUS_TYPE_STRING, &ptr, + DBUS_TYPE_INVALID); + + return send_message_and_unref(conn, reply); +} + + static DBusHandlerResult device_get_connected(DBusConnection *conn, DBusMessage *msg, void *data) { @@ -152,6 +172,7 @@ static DBusHandlerResult device_get_connected(DBusConnection *conn, static DBusMethodVTable device_methods[] = { { "GetAddress", device_get_address, "", "s" }, { "GetName", device_get_name, "", "s" }, + { "GetAdapter", device_get_adapter, "", "s" }, { "GetConnectedInterfaces", device_get_connected, "", "as" }, { NULL, NULL, NULL, NULL } }; -- cgit From af44f3cafbe4a2a2f2c4bb5879d803f766cf775a Mon Sep 17 00:00:00 2001 From: Luiz Augusto von Dentz Date: Tue, 9 Oct 2007 13:31:57 +0000 Subject: Fix device removal when it is not the current adapter. --- audio/device.c | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) (limited to 'audio/device.c') diff --git a/audio/device.c b/audio/device.c index 9c90ed43..9b76e019 100644 --- a/audio/device.c +++ b/audio/device.c @@ -301,6 +301,7 @@ struct device *device_register(DBusConnection *conn, dev->path = g_strdup(path); bacpy(&dev->dst, bda); bacpy(&dev->src, &src); + bacpy(&dev->store, &src); dev->conn = dbus_connection_ref(conn); return dev; @@ -317,7 +318,7 @@ int device_store(struct device *dev, gboolean is_default) return -EINVAL; ba2str(&dev->dst, dst_addr); - ba2str(&dev->src, src_addr); + ba2str(&dev->store, src_addr); create_name(filename, PATH_MAX, STORAGEDIR, src_addr, "audio"); create_file(filename, S_IRUSR | S_IWUSR | S_IRGRP | S_IROTH); @@ -356,7 +357,7 @@ int device_remove_stored(struct device *dev) char src_addr[18], dst_addr[18]; ba2str(&dev->dst, dst_addr); - ba2str(&dev->src, src_addr); + ba2str(&dev->store, src_addr); create_name(filename, PATH_MAX, STORAGEDIR, src_addr, "audio"); -- cgit From 0ad3f2251089e00a57b6aa6def396e24f30ab1e4 Mon Sep 17 00:00:00 2001 From: Johan Hedberg Date: Tue, 23 Oct 2007 07:54:36 +0000 Subject: Integrate AVRCP further with the rest of the audio service --- audio/device.c | 9 +++++++++ 1 file changed, 9 insertions(+) (limited to 'audio/device.c') diff --git a/audio/device.c b/audio/device.c index 9b76e019..a2047b9e 100644 --- a/audio/device.c +++ b/audio/device.c @@ -49,6 +49,7 @@ #include "ipc.h" #include "device.h" #include "avdtp.h" +#include "control.h" #include "headset.h" #include "sink.h" @@ -185,6 +186,9 @@ static void device_free(struct device *dev) if (dev->sink) sink_free(dev); + if (dev->control) + control_free(dev); + if (dev->conn) dbus_connection_unref(dev->conn); @@ -486,6 +490,8 @@ uint8_t device_get_state(struct device *dev) hs_state = headset_get_state(dev); return hs_to_ipc_state(hs_state); } + else if (dev->control && control_is_active(dev)) + return STATE_CONNECTED; return STATE_DISCONNECTED; } @@ -509,6 +515,9 @@ gboolean device_is_connected(struct device *dev, const char *interface) else if (!strcmp(interface, AUDIO_HEADSET_INTERFACE) && dev->headset && headset_is_active(dev)) return TRUE; + else if (!strcmp(interface, AUDIO_CONTROL_INTERFACE) && dev->headset && + control_is_active(dev)) + return TRUE; return FALSE; } -- cgit From de72271829f6bfd21aa6550a2ac6d81e35b53cad Mon Sep 17 00:00:00 2001 From: Marcel Holtmann Date: Tue, 23 Oct 2007 17:17:47 +0000 Subject: Update copyright information --- audio/device.c | 1 + 1 file changed, 1 insertion(+) (limited to 'audio/device.c') diff --git a/audio/device.c b/audio/device.c index a2047b9e..f3567189 100644 --- a/audio/device.c +++ b/audio/device.c @@ -2,6 +2,7 @@ * * BlueZ - Bluetooth protocol stack for Linux * + * Copyright (C) 2006-2007 Nokia Corporation * Copyright (C) 2004-2007 Marcel Holtmann * * -- cgit From 589d60855eedc4d207ed6e79cae3e18c48a4586f Mon Sep 17 00:00:00 2001 From: Johan Hedberg Date: Thu, 25 Oct 2007 10:38:47 +0000 Subject: Add uinput support for AVRCP --- audio/device.c | 62 +++++++++++++++++++++++++++++++++------------------------- 1 file changed, 35 insertions(+), 27 deletions(-) (limited to 'audio/device.c') diff --git a/audio/device.c b/audio/device.c index f3567189..c86f711d 100644 --- a/audio/device.c +++ b/audio/device.c @@ -73,51 +73,60 @@ static DBusHandlerResult device_get_address(DBusConnection *conn, return send_message_and_unref(conn, reply); } -static DBusHandlerResult device_get_name(DBusConnection *conn, - DBusMessage *msg, void *data) +static char *get_dev_name(DBusConnection *conn, const char *adapter_path, + bdaddr_t *bda) { - struct device *device = data; - DBusMessage *reply, *reply2, *msg2; + DBusMessage *msg, *reply; DBusError derr; const char *name; - char address[18], *addr_ptr = address; + char address[18], *addr_ptr = address, *ret; - msg2 = dbus_message_new_method_call("org.bluez", device->adapter_path, + msg = dbus_message_new_method_call("org.bluez", adapter_path, "org.bluez.Adapter", "GetRemoteName"); - if (!msg2) - return DBUS_HANDLER_RESULT_NEED_MEMORY; + if (!msg) + return NULL; - ba2str(&device->dst, address); - dbus_message_append_args(msg2, DBUS_TYPE_STRING, &addr_ptr, + ba2str(bda, address); + dbus_message_append_args(msg, DBUS_TYPE_STRING, &addr_ptr, DBUS_TYPE_INVALID); dbus_error_init(&derr); - reply2 = dbus_connection_send_with_reply_and_block(conn, msg2, -1, + reply = dbus_connection_send_with_reply_and_block(conn, msg, -1, &derr); - - dbus_message_unref(msg2); + dbus_message_unref(msg); if (dbus_error_is_set(&derr)) { - error("%s GetRemoteName(): %s", device->adapter_path, - derr.message); + error("%s GetRemoteName(): %s", adapter_path, derr.message); dbus_error_free(&derr); - return err_failed(conn, msg, "Unable to get remote name"); + return NULL; } + if (!dbus_message_get_args(reply, NULL, + DBUS_TYPE_STRING, &name, + DBUS_TYPE_INVALID)) + return NULL; + + ret = g_strdup(name); + + dbus_message_unref(reply); + + return ret; +} + +static DBusHandlerResult device_get_name(DBusConnection *conn, + DBusMessage *msg, void *data) +{ + struct device *dev = data; + DBusMessage *reply; + const char *name = dev->name ? dev->name : ""; reply = dbus_message_new_method_return(msg); if (!reply) return DBUS_HANDLER_RESULT_NEED_MEMORY; - dbus_message_get_args(reply2, NULL, - DBUS_TYPE_STRING, &name, - DBUS_TYPE_INVALID); - dbus_message_append_args(reply, DBUS_TYPE_STRING, &name, DBUS_TYPE_INVALID); - dbus_message_unref(reply2); - return send_message_and_unref(conn, reply); } @@ -193,11 +202,9 @@ static void device_free(struct device *dev) if (dev->conn) dbus_connection_unref(dev->conn); - if (dev->adapter_path) - g_free(dev->adapter_path); - - if (dev->path) - g_free(dev->path); + g_free(dev->adapter_path); + g_free(dev->path); + g_free(dev->name); g_free(dev); } @@ -303,6 +310,7 @@ struct device *device_register(DBusConnection *conn, return NULL; } + dev->name = get_dev_name(conn, dev->adapter_path, bda); dev->path = g_strdup(path); bacpy(&dev->dst, bda); bacpy(&dev->src, &src); -- cgit From d4e24bf6a3d8af6479abce92fbbf1869a59669aa Mon Sep 17 00:00:00 2001 From: Luiz Augusto von Dentz Date: Wed, 21 Nov 2007 20:24:11 +0000 Subject: Integrate new ipc API implementation. --- audio/device.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'audio/device.c') diff --git a/audio/device.c b/audio/device.c index c86f711d..a5b9b0a9 100644 --- a/audio/device.c +++ b/audio/device.c @@ -450,7 +450,6 @@ static headset_state_t ipc_to_hs_state(uint8_t ipc_state) return HEADSET_STATE_DISCONNECTED; } } -#endif static uint8_t avdtp_to_ipc_state(avdtp_state_t state) { @@ -504,6 +503,7 @@ uint8_t device_get_state(struct device *dev) return STATE_DISCONNECTED; } +#endif gboolean device_is_connected(struct device *dev, const char *interface) { -- cgit From e823c15e43a6f924779e466d434c51157002d9ee Mon Sep 17 00:00:00 2001 From: Marcel Holtmann Date: Sat, 2 Feb 2008 03:37:05 +0000 Subject: Update copyright information --- audio/device.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'audio/device.c') diff --git a/audio/device.c b/audio/device.c index a5b9b0a9..2f5bf417 100644 --- a/audio/device.c +++ b/audio/device.c @@ -3,7 +3,7 @@ * BlueZ - Bluetooth protocol stack for Linux * * Copyright (C) 2006-2007 Nokia Corporation - * Copyright (C) 2004-2007 Marcel Holtmann + * Copyright (C) 2004-2008 Marcel Holtmann * * * This program is free software; you can redistribute it and/or modify -- cgit From 1152fc72d35de616d5d2d3a29525fd6aacb852f9 Mon Sep 17 00:00:00 2001 From: Luiz Augusto von Dentz Date: Thu, 27 Mar 2008 14:05:37 +0000 Subject: Remove blocking call of FinishRemoteServiceTransaction. --- audio/device.c | 19 ++----------------- 1 file changed, 2 insertions(+), 17 deletions(-) (limited to 'audio/device.c') diff --git a/audio/device.c b/audio/device.c index 2f5bf417..7510d9a4 100644 --- a/audio/device.c +++ b/audio/device.c @@ -380,8 +380,7 @@ int device_remove_stored(struct device *dev) void device_finish_sdp_transaction(struct device *dev) { char address[18], *addr_ptr = address; - DBusMessage *msg, *reply; - DBusError derr; + DBusMessage *msg; ba2str(&dev->dst, address); @@ -396,21 +395,7 @@ void device_finish_sdp_transaction(struct device *dev) dbus_message_append_args(msg, DBUS_TYPE_STRING, &addr_ptr, DBUS_TYPE_INVALID); - dbus_error_init(&derr); - reply = dbus_connection_send_with_reply_and_block(dev->conn, - msg, -1, &derr); - - dbus_message_unref(msg); - - if (dbus_error_is_set(&derr) || - dbus_set_error_from_message(&derr, reply)) { - error("FinishRemoteServiceTransaction(%s) failed: %s", - address, derr.message); - dbus_error_free(&derr); - return; - } - - dbus_message_unref(reply); + send_message_and_unref(dev->conn, msg); } #if 0 -- cgit From 7299869ac79b76564cd68411acb18f4233ddbbb7 Mon Sep 17 00:00:00 2001 From: Luiz Augusto von Dentz Date: Thu, 27 Mar 2008 23:07:19 +0000 Subject: Convert audio service into a plugin. --- audio/device.c | 57 ++------------------------------------------------------- 1 file changed, 2 insertions(+), 55 deletions(-) (limited to 'audio/device.c') diff --git a/audio/device.c b/audio/device.c index 7510d9a4..7e25fe90 100644 --- a/audio/device.c +++ b/audio/device.c @@ -218,60 +218,6 @@ static void device_unregister(DBusConnection *conn, void *data) device_free(device); } -char *find_adapter(DBusConnection *conn, bdaddr_t *src) -{ - DBusMessage *msg, *reply; - DBusError derr; - char address[18], *addr_ptr = address; - char *path, *ret; - - msg = dbus_message_new_method_call("org.bluez", "/org/bluez", - "org.bluez.Manager", - "FindAdapter"); - if (!msg) { - error("Unable to allocate new method call"); - return NULL; - } - - ba2str(src, address); - - dbus_message_append_args(msg, DBUS_TYPE_STRING, &addr_ptr, - DBUS_TYPE_INVALID); - - dbus_error_init(&derr); - reply = dbus_connection_send_with_reply_and_block(conn, msg, -1, - &derr); - - dbus_message_unref(msg); - - if (dbus_error_is_set(&derr) || - dbus_set_error_from_message(&derr, reply)) { - error("FindAdapter(%s) failed: %s", address, derr.message); - dbus_error_free(&derr); - return NULL; - } - - dbus_error_init(&derr); - dbus_message_get_args(reply, &derr, - DBUS_TYPE_STRING, &path, - DBUS_TYPE_INVALID); - - if (dbus_error_is_set(&derr)) { - error("Unable to get message args"); - dbus_message_unref(reply); - dbus_error_free(&derr); - return FALSE; - } - - ret = g_strdup(path); - - dbus_message_unref(reply); - - debug("Got path %s for adapter with address %s", ret, address); - - return ret; -} - struct device *device_register(DBusConnection *conn, const char *path, bdaddr_t *bda) { @@ -289,7 +235,8 @@ struct device *device_register(DBusConnection *conn, dev = g_new0(struct device, 1); - dev->adapter_path = find_adapter(conn, &src); + /* FIXME just to maintain compatibility */ + dev->adapter_path = g_strdup_printf("/org/bluez/hci%d", dev_id); if (!dev->adapter_path) { device_free(dev); return NULL; -- cgit From 2fff5cdc8c0d7a626890ee8f0dd82d464e4fd375 Mon Sep 17 00:00:00 2001 From: Luiz Augusto von Dentz Date: Fri, 28 Mar 2008 13:00:18 +0000 Subject: Remove blocking calls to GetRemoteName. --- audio/device.c | 43 ++++++++----------------------------------- 1 file changed, 8 insertions(+), 35 deletions(-) (limited to 'audio/device.c') diff --git a/audio/device.c b/audio/device.c index 7e25fe90..0debe220 100644 --- a/audio/device.c +++ b/audio/device.c @@ -73,44 +73,17 @@ static DBusHandlerResult device_get_address(DBusConnection *conn, return send_message_and_unref(conn, reply); } -static char *get_dev_name(DBusConnection *conn, const char *adapter_path, - bdaddr_t *bda) +static char *get_dev_name(DBusConnection *conn, bdaddr_t *src, bdaddr_t *bda) { - DBusMessage *msg, *reply; - DBusError derr; - const char *name; - char address[18], *addr_ptr = address, *ret; - - msg = dbus_message_new_method_call("org.bluez", adapter_path, - "org.bluez.Adapter", "GetRemoteName"); - if (!msg) - return NULL; - - ba2str(bda, address); - dbus_message_append_args(msg, DBUS_TYPE_STRING, &addr_ptr, - DBUS_TYPE_INVALID); - - dbus_error_init(&derr); - reply = dbus_connection_send_with_reply_and_block(conn, msg, -1, - &derr); - dbus_message_unref(msg); + char address[18], filename[PATH_MAX + 1]; - if (dbus_error_is_set(&derr)) { - error("%s GetRemoteName(): %s", adapter_path, derr.message); - dbus_error_free(&derr); - return NULL; - } - - if (!dbus_message_get_args(reply, NULL, - DBUS_TYPE_STRING, &name, - DBUS_TYPE_INVALID)) - return NULL; - - ret = g_strdup(name); + ba2str(src, address); - dbus_message_unref(reply); + /* check if it is in the cache */ + create_name(filename, PATH_MAX, STORAGEDIR, address, "names"); - return ret; + ba2str(bda, address); + return textfile_caseget(filename, address); } static DBusHandlerResult device_get_name(DBusConnection *conn, @@ -257,7 +230,7 @@ struct device *device_register(DBusConnection *conn, return NULL; } - dev->name = get_dev_name(conn, dev->adapter_path, bda); + dev->name = get_dev_name(conn, &src, bda); dev->path = g_strdup(path); bacpy(&dev->dst, bda); bacpy(&dev->src, &src); -- cgit From e7d668ac9e813bc9922ee7d771848bd8822d5d1f Mon Sep 17 00:00:00 2001 From: Marcel Holtmann Date: Thu, 8 May 2008 20:23:45 +0000 Subject: Move D-Bus watch functions into libgdbus --- audio/device.c | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) (limited to 'audio/device.c') diff --git a/audio/device.c b/audio/device.c index 0debe220..c385c7ca 100644 --- a/audio/device.c +++ b/audio/device.c @@ -32,16 +32,15 @@ #include #include -#include -#include - #include #include #include #include #include -#include "dbus.h" +#include +#include + #include "dbus-helper.h" #include "logging.h" #include "textfile.h" -- cgit From 15ea15b3a752f0487bc50d0ea04925f1b9d33dcb Mon Sep 17 00:00:00 2001 From: Marcel Holtmann Date: Thu, 8 May 2008 22:19:14 +0000 Subject: Move D-Bus object and interface helpers into libgdbus --- audio/device.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'audio/device.c') diff --git a/audio/device.c b/audio/device.c index c385c7ca..b240bdae 100644 --- a/audio/device.c +++ b/audio/device.c @@ -40,8 +40,8 @@ #include #include +#include -#include "dbus-helper.h" #include "logging.h" #include "textfile.h" -- cgit From 0094809955895c974fbe95f2d3ed13f420a6a6ed Mon Sep 17 00:00:00 2001 From: Luiz Augusto von Dentz Date: Wed, 14 May 2008 22:16:16 +0000 Subject: Make bt_io_callback_t to take both source and destination. --- audio/device.c | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) (limited to 'audio/device.c') diff --git a/audio/device.c b/audio/device.c index b240bdae..120d45f3 100644 --- a/audio/device.c +++ b/audio/device.c @@ -72,7 +72,8 @@ static DBusHandlerResult device_get_address(DBusConnection *conn, return send_message_and_unref(conn, reply); } -static char *get_dev_name(DBusConnection *conn, bdaddr_t *src, bdaddr_t *bda) +static char *get_dev_name(DBusConnection *conn, const bdaddr_t *src, + const bdaddr_t *bda) { char address[18], filename[PATH_MAX + 1]; @@ -191,7 +192,7 @@ static void device_unregister(DBusConnection *conn, void *data) } struct device *device_register(DBusConnection *conn, - const char *path, bdaddr_t *bda) + const char *path, const bdaddr_t *bda) { struct device *dev; bdaddr_t src; -- cgit From 30751fe0c0430e0757c018de4f8e6bceee5e85f7 Mon Sep 17 00:00:00 2001 From: Marcel Holtmann Date: Tue, 20 May 2008 21:54:12 +0000 Subject: Fix issues with missing include for PATH_MAX --- audio/device.c | 1 + 1 file changed, 1 insertion(+) (limited to 'audio/device.c') diff --git a/audio/device.c b/audio/device.c index 120d45f3..6760d4bb 100644 --- a/audio/device.c +++ b/audio/device.c @@ -30,6 +30,7 @@ #include #include #include +#include #include #include -- cgit From caf9fdd6d0183afc3b21d1cd82eb637773c131de Mon Sep 17 00:00:00 2001 From: Marcel Holtmann Date: Thu, 29 May 2008 08:05:16 +0000 Subject: Replace struct device with struct audio_device --- audio/device.c | 28 ++++++++++++++-------------- 1 file changed, 14 insertions(+), 14 deletions(-) (limited to 'audio/device.c') diff --git a/audio/device.c b/audio/device.c index 6760d4bb..6b8c5318 100644 --- a/audio/device.c +++ b/audio/device.c @@ -57,7 +57,7 @@ static DBusHandlerResult device_get_address(DBusConnection *conn, DBusMessage *msg, void *data) { - struct device *device = data; + struct audio_device *device = data; DBusMessage *reply; char address[18], *ptr = address; @@ -90,7 +90,7 @@ static char *get_dev_name(DBusConnection *conn, const bdaddr_t *src, static DBusHandlerResult device_get_name(DBusConnection *conn, DBusMessage *msg, void *data) { - struct device *dev = data; + struct audio_device *dev = data; DBusMessage *reply; const char *name = dev->name ? dev->name : ""; @@ -107,7 +107,7 @@ static DBusHandlerResult device_get_name(DBusConnection *conn, static DBusHandlerResult device_get_adapter(DBusConnection *conn, DBusMessage *msg, void *data) { - struct device *device = data; + struct audio_device *device = data; DBusMessage *reply; char address[18], *ptr = address; @@ -128,7 +128,7 @@ static DBusHandlerResult device_get_connected(DBusConnection *conn, DBusMessage *msg, void *data) { DBusMessageIter iter, array_iter; - struct device *device = data; + struct audio_device *device = data; DBusMessage *reply; const char *iface; @@ -162,7 +162,7 @@ static DBusMethodVTable device_methods[] = { { NULL, NULL, NULL, NULL } }; -static void device_free(struct device *dev) +static void device_free(struct audio_device *dev) { if (dev->headset) headset_free(dev); @@ -185,17 +185,17 @@ static void device_free(struct device *dev) static void device_unregister(DBusConnection *conn, void *data) { - struct device *device = data; + struct audio_device *device = data; info("Unregistered device path:%s", device->path); device_free(device); } -struct device *device_register(DBusConnection *conn, +struct audio_device *device_register(DBusConnection *conn, const char *path, const bdaddr_t *bda) { - struct device *dev; + struct audio_device *dev; bdaddr_t src; int dev_id; @@ -207,7 +207,7 @@ struct device *device_register(DBusConnection *conn, if ((dev_id < 0) || (hci_devba(dev_id, &src) < 0)) return NULL; - dev = g_new0(struct device, 1); + dev = g_new0(struct audio_device, 1); /* FIXME just to maintain compatibility */ dev->adapter_path = g_strdup_printf("/org/bluez/hci%d", dev_id); @@ -241,7 +241,7 @@ struct device *device_register(DBusConnection *conn, return dev; } -int device_store(struct device *dev, gboolean is_default) +int device_store(struct audio_device *dev, gboolean is_default) { char value[64]; char filename[PATH_MAX + 1]; @@ -285,7 +285,7 @@ int device_store(struct device *dev, gboolean is_default) return textfile_put(filename, dst_addr, value); } -int device_remove_stored(struct device *dev) +int device_remove_stored(struct audio_device *dev) { char filename[PATH_MAX + 1]; char src_addr[18], dst_addr[18]; @@ -298,7 +298,7 @@ int device_remove_stored(struct device *dev) return textfile_del(filename, dst_addr); } -void device_finish_sdp_transaction(struct device *dev) +void device_finish_sdp_transaction(struct audio_device *dev) { char address[18], *addr_ptr = address; DBusMessage *msg; @@ -391,7 +391,7 @@ static uint8_t hs_to_ipc_state(headset_state_t state) } } -uint8_t device_get_state(struct device *dev) +uint8_t device_get_state(struct audio_device *dev) { avdtp_state_t sink_state; headset_state_t hs_state; @@ -411,7 +411,7 @@ uint8_t device_get_state(struct device *dev) } #endif -gboolean device_is_connected(struct device *dev, const char *interface) +gboolean device_is_connected(struct audio_device *dev, const char *interface) { if (!interface) { if ((dev->sink || dev->source) && -- cgit From b6029c0ffd7facd5f41bd665c84043d08961847d Mon Sep 17 00:00:00 2001 From: Luiz Augusto von Dentz Date: Mon, 2 Jun 2008 14:34:58 +0000 Subject: Make audio service to use libgdbus functions. --- audio/device.c | 53 ++++++++++++++++++++++++----------------------------- 1 file changed, 24 insertions(+), 29 deletions(-) (limited to 'audio/device.c') diff --git a/audio/device.c b/audio/device.c index 6b8c5318..c9608b96 100644 --- a/audio/device.c +++ b/audio/device.c @@ -54,7 +54,7 @@ #include "headset.h" #include "sink.h" -static DBusHandlerResult device_get_address(DBusConnection *conn, +static DBusMessage *device_get_address(DBusConnection *conn, DBusMessage *msg, void *data) { struct audio_device *device = data; @@ -63,14 +63,14 @@ static DBusHandlerResult device_get_address(DBusConnection *conn, reply = dbus_message_new_method_return(msg); if (!reply) - return DBUS_HANDLER_RESULT_NEED_MEMORY; + return NULL; ba2str(&device->dst, address); dbus_message_append_args(reply, DBUS_TYPE_STRING, &ptr, DBUS_TYPE_INVALID); - return send_message_and_unref(conn, reply); + return reply; } static char *get_dev_name(DBusConnection *conn, const bdaddr_t *src, @@ -87,7 +87,7 @@ static char *get_dev_name(DBusConnection *conn, const bdaddr_t *src, return textfile_caseget(filename, address); } -static DBusHandlerResult device_get_name(DBusConnection *conn, +static DBusMessage *device_get_name(DBusConnection *conn, DBusMessage *msg, void *data) { struct audio_device *dev = data; @@ -96,15 +96,15 @@ static DBusHandlerResult device_get_name(DBusConnection *conn, reply = dbus_message_new_method_return(msg); if (!reply) - return DBUS_HANDLER_RESULT_NEED_MEMORY; + return NULL; dbus_message_append_args(reply, DBUS_TYPE_STRING, &name, DBUS_TYPE_INVALID); - return send_message_and_unref(conn, reply); + return reply; } -static DBusHandlerResult device_get_adapter(DBusConnection *conn, +static DBusMessage *device_get_adapter(DBusConnection *conn, DBusMessage *msg, void *data) { struct audio_device *device = data; @@ -113,18 +113,18 @@ static DBusHandlerResult device_get_adapter(DBusConnection *conn, reply = dbus_message_new_method_return(msg); if (!reply) - return DBUS_HANDLER_RESULT_NEED_MEMORY; + return NULL; ba2str(&device->src, address); dbus_message_append_args(reply, DBUS_TYPE_STRING, &ptr, DBUS_TYPE_INVALID); - return send_message_and_unref(conn, reply); + return reply; } -static DBusHandlerResult device_get_connected(DBusConnection *conn, +static DBusMessage *device_get_connected(DBusConnection *conn, DBusMessage *msg, void *data) { DBusMessageIter iter, array_iter; @@ -134,7 +134,7 @@ static DBusHandlerResult device_get_connected(DBusConnection *conn, reply = dbus_message_new_method_return(msg); if (!reply) - return DBUS_HANDLER_RESULT_NEED_MEMORY; + return NULL; dbus_message_iter_init_append(reply, &iter); @@ -151,15 +151,15 @@ static DBusHandlerResult device_get_connected(DBusConnection *conn, dbus_message_iter_close_container(&iter, &array_iter); - return send_message_and_unref(conn, reply); + return reply; } -static DBusMethodVTable device_methods[] = { - { "GetAddress", device_get_address, "", "s" }, - { "GetName", device_get_name, "", "s" }, - { "GetAdapter", device_get_adapter, "", "s" }, - { "GetConnectedInterfaces", device_get_connected, "", "as" }, - { NULL, NULL, NULL, NULL } +static GDBusMethodTable device_methods[] = { + { "GetAddress", "", "s", device_get_address }, + { "GetName", "", "s", device_get_name }, + { "GetAdapter", "", "s", device_get_adapter }, + { "GetConnectedInterfaces", "", "as", device_get_connected }, + { } }; static void device_free(struct audio_device *dev) @@ -183,7 +183,7 @@ static void device_free(struct audio_device *dev) g_free(dev); } -static void device_unregister(DBusConnection *conn, void *data) +static void device_unregister(void *data) { struct audio_device *device = data; @@ -216,18 +216,13 @@ struct audio_device *device_register(DBusConnection *conn, return NULL; } - if (!dbus_connection_create_object_path(conn, path, dev, - device_unregister)) { - error("D-Bus failed to register %s path", path); - device_free(dev); - return NULL; - } - - if (!dbus_connection_register_interface(conn, path, - AUDIO_DEVICE_INTERFACE, device_methods, NULL, NULL)) { + if (!g_dbus_register_interface(conn, path, + AUDIO_DEVICE_INTERFACE, + device_methods, NULL, NULL, + dev, device_unregister)) { error("Failed to register %s interface to %s", AUDIO_DEVICE_INTERFACE, path); - dbus_connection_destroy_object_path(conn, path); + device_free(dev); return NULL; } -- cgit From f269e27ce7e39e6484cf02a137dcda7458a7fd85 Mon Sep 17 00:00:00 2001 From: Marcel Holtmann Date: Fri, 6 Jun 2008 10:20:21 +0000 Subject: Fix the last remains of sending helpers --- audio/device.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) (limited to 'audio/device.c') diff --git a/audio/device.c b/audio/device.c index c9608b96..2f5f834f 100644 --- a/audio/device.c +++ b/audio/device.c @@ -311,7 +311,9 @@ void device_finish_sdp_transaction(struct audio_device *dev) dbus_message_append_args(msg, DBUS_TYPE_STRING, &addr_ptr, DBUS_TYPE_INVALID); - send_message_and_unref(dev->conn, msg); + dbus_connection_send(dev->conn, msg, NULL); + + dbus_message_unref(msg); } #if 0 -- cgit