From: Luiz Augusto von Dentz <luiz.dentz@gmail.com>
To: linux-bluetooth@vger.kernel.org
Subject: [RFC 10/20] audio/control: Remove dependency on struct audio_device
Date: Wed, 3 Jul 2013 18:15:31 +0300 [thread overview]
Message-ID: <1372864541-10763-11-git-send-email-luiz.dentz@gmail.com> (raw)
In-Reply-To: <1372864541-10763-1-git-send-email-luiz.dentz@gmail.com>
From: Luiz Augusto von Dentz <luiz.von.dentz@intel.com>
This is part of the work necessary to completely remove
struct audio_device
---
profiles/audio/control.c | 82 ++++++++++++++++++++++++++++--------------------
profiles/audio/control.h | 6 ++--
profiles/audio/manager.c | 4 +--
3 files changed, 52 insertions(+), 40 deletions(-)
diff --git a/profiles/audio/control.c b/profiles/audio/control.c
index 86d38f5..bffcb09 100644
--- a/profiles/audio/control.c
+++ b/profiles/audio/control.c
@@ -46,14 +46,13 @@
#include <gdbus/gdbus.h>
#include "lib/uuid.h"
-#include "../src/adapter.h"
-#include "../src/device.h"
-#include "../src/profile.h"
-#include "../src/service.h"
+#include "src/adapter.h"
+#include "src/device.h"
+#include "src/profile.h"
+#include "src/service.h"
#include "log.h"
#include "error.h"
-#include "device.h"
#include "manager.h"
#include "avctp.h"
#include "control.h"
@@ -61,8 +60,10 @@
#include "glib-helper.h"
#include "dbus-common.h"
+static GSList *devices = NULL;
+
struct control {
- struct audio_device *dev;
+ struct btd_device *dev;
struct avctp *session;
struct btd_service *target;
struct btd_service *remote;
@@ -110,7 +111,7 @@ int control_connect(struct btd_service *service)
if (!control->target)
return -ENOTSUP;
- control->session = avctp_connect(control->dev->btd_dev);
+ control->session = avctp_connect(control->dev);
if (!control->session)
return -EIO;
@@ -132,8 +133,7 @@ int control_disconnect(struct btd_service *service)
static DBusMessage *key_pressed(DBusConnection *conn, DBusMessage *msg,
uint8_t op, void *data)
{
- struct audio_device *device = data;
- struct control *control = btd_service_get_user_data(device->control);
+ struct control *control = data;
int err;
if (!control->session)
@@ -207,8 +207,7 @@ static gboolean control_property_get_connected(
const GDBusPropertyTable *property,
DBusMessageIter *iter, void *data)
{
- struct audio_device *device = data;
- struct control *control = btd_service_get_user_data(device->control);
+ struct control *control = data;
dbus_bool_t value = (control->session != NULL);
dbus_message_iter_append_basic(iter, DBUS_TYPE_BOOLEAN, &value);
@@ -236,11 +235,10 @@ static const GDBusPropertyTable control_properties[] = {
static void path_unregister(void *data)
{
- struct audio_device *dev = data;
- struct control *control = btd_service_get_user_data(dev->control);
+ struct control *control = data;
- DBG("Unregistered interface %s on path %s",
- AUDIO_CONTROL_INTERFACE, device_get_path(dev->btd_dev));
+ DBG("Unregistered interface %s on path %s", AUDIO_CONTROL_INTERFACE,
+ device_get_path(control->dev));
if (control->session)
avctp_disconnect(control->session);
@@ -253,8 +251,8 @@ static void path_unregister(void *data)
if (control->remote)
btd_service_unref(control->remote);
+ devices = g_slist_remove(devices, control);
g_free(control);
- dev->control = NULL;
}
void control_unregister(struct btd_service *service)
@@ -266,39 +264,56 @@ void control_unregister(struct btd_service *service)
AUDIO_CONTROL_INTERFACE);
}
-static struct control *control_init(struct audio_device *dev)
+static struct control *find_control(struct btd_device *dev)
+{
+ GSList *l;
+
+ for (l = devices; l; l = l->next) {
+ struct control *control = l->data;
+
+ if (control->dev == dev)
+ return control;
+ }
+
+ return NULL;
+}
+
+static struct control *control_init(struct btd_service *service)
{
struct control *control;
+ struct btd_device *dev = btd_service_get_device(service);
- if (dev->control != NULL)
- return btd_service_get_user_data(dev->control);
+ control = find_control(dev);
+ if (control != NULL)
+ return control;
+
+ control = g_new0(struct control, 1);
if (!g_dbus_register_interface(btd_get_dbus_connection(),
- device_get_path(dev->btd_dev),
+ device_get_path(dev),
AUDIO_CONTROL_INTERFACE,
control_methods, NULL,
- control_properties, dev,
- path_unregister))
+ control_properties, control,
+ path_unregister)) {
+ g_free(control);
return NULL;
+ }
- DBG("Registered interface %s on path %s",
- AUDIO_CONTROL_INTERFACE, device_get_path(dev->btd_dev));
-
- control = g_new0(struct control, 1);
+ DBG("Registered interface %s on path %s", AUDIO_CONTROL_INTERFACE,
+ device_get_path(dev));
control->dev = dev;
- control->avctp_id = avctp_add_state_cb(dev->btd_dev, state_changed,
- control);
+ control->avctp_id = avctp_add_state_cb(dev, state_changed, control);
+ devices = g_slist_prepend(devices, control);
return control;
}
-struct btd_service *control_init_target(struct audio_device *dev,
- struct btd_service *service)
+struct btd_service *control_init_target(struct btd_service *service)
{
struct control *control;
- control = control_init(dev);
+ control = control_init(service);
if (control == NULL)
return NULL;
@@ -309,12 +324,11 @@ struct btd_service *control_init_target(struct audio_device *dev,
return service;
}
-struct btd_service *control_init_remote(struct audio_device *dev,
- struct btd_service *service)
+struct btd_service *control_init_remote(struct btd_service *service)
{
struct control *control;
- control = control_init(dev);
+ control = control_init(service);
if (control == NULL)
return NULL;
diff --git a/profiles/audio/control.h b/profiles/audio/control.h
index 57668f9..ae5baae 100644
--- a/profiles/audio/control.h
+++ b/profiles/audio/control.h
@@ -26,10 +26,8 @@
struct btd_service;
-struct btd_service *control_init_target(struct audio_device *dev,
- struct btd_service *service);
-struct btd_service *control_init_remote(struct audio_device *dev,
- struct btd_service *service);
+struct btd_service *control_init_target(struct btd_service *service);
+struct btd_service *control_init_remote(struct btd_service *service);
void control_unregister(struct btd_service *service);
gboolean control_is_active(struct btd_service *service);
diff --git a/profiles/audio/manager.c b/profiles/audio/manager.c
index c2898b5..4940012 100644
--- a/profiles/audio/manager.c
+++ b/profiles/audio/manager.c
@@ -146,7 +146,7 @@ static int avrcp_target_probe(struct btd_service *service)
return -1;
}
- audio_dev->control = control_init_target(audio_dev, service);
+ audio_dev->control = control_init_target(service);
if (audio_dev->sink && sink_is_active(audio_dev->sink))
avrcp_connect(audio_dev->btd_dev);
@@ -165,7 +165,7 @@ static int avrcp_remote_probe(struct btd_service *service)
return -1;
}
- audio_dev->control = control_init_remote(audio_dev, service);
+ audio_dev->control = control_init_remote(service);
return 0;
}
--
1.8.1.4
next prev parent reply other threads:[~2013-07-03 15:15 UTC|newest]
Thread overview: 28+ messages / expand[flat|nested] mbox.gz Atom feed top
2013-07-03 15:15 [RFC 00/20] Remove audio_device and introduce policy plugin Luiz Augusto von Dentz
2013-07-03 15:15 ` [RFC 01/20] audio/sink: Use service user_data for private data Luiz Augusto von Dentz
2013-07-04 6:36 ` Mikel Astiz
2013-07-04 6:49 ` Luiz Augusto von Dentz
2013-07-04 14:28 ` Vinicius Costa Gomes
2013-07-05 6:38 ` Mikel Astiz
2013-07-08 10:00 ` Luiz Augusto von Dentz
2013-07-03 15:15 ` [RFC 02/20] audio/source: " Luiz Augusto von Dentz
2013-07-03 15:15 ` [RFC 03/20] audio/control: " Luiz Augusto von Dentz
2013-07-03 15:15 ` [RFC 04/20] audio/sink: Reduce dependency on struct audio_device Luiz Augusto von Dentz
2013-07-03 15:15 ` [RFC 05/20] audio/source: " Luiz Augusto von Dentz
2013-07-03 15:15 ` [RFC 06/20] audio/control: " Luiz Augusto von Dentz
2013-07-03 15:15 ` [RFC 07/20] audio/AVCTP: Remove " Luiz Augusto von Dentz
2013-07-03 15:15 ` [RFC 08/20] audio/AVDTP: " Luiz Augusto von Dentz
2013-07-03 15:15 ` [RFC 09/20] audio/AVRCP: " Luiz Augusto von Dentz
2013-07-03 15:15 ` Luiz Augusto von Dentz [this message]
2013-07-03 15:15 ` [RFC 11/20] audio/A2DP: " Luiz Augusto von Dentz
2013-07-03 15:15 ` [RFC 12/20] audio/sink: " Luiz Augusto von Dentz
2013-07-03 15:15 ` [RFC 13/20] audio/source: " Luiz Augusto von Dentz
2013-07-03 15:15 ` [RFC 14/20] audio/media: " Luiz Augusto von Dentz
2013-07-03 15:15 ` [RFC 15/20] audio/transport: " Luiz Augusto von Dentz
2013-07-03 15:15 ` [RFC 16/20] audio/manager: " Luiz Augusto von Dentz
2013-07-03 15:15 ` [RFC 17/20] audio/main: " Luiz Augusto von Dentz
2013-07-03 15:15 ` [RFC 18/20] plugins/policy: Reword audio policy code in a simple plugin Luiz Augusto von Dentz
2013-07-03 15:15 ` [RFC 19/20] audio/sink: Fix not notifying service about connection state Luiz Augusto von Dentz
2013-07-04 7:05 ` Mikel Astiz
2013-07-04 7:17 ` Luiz Augusto von Dentz
2013-07-03 15:15 ` [RFC 20/20] audio/source: " Luiz Augusto von Dentz
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=1372864541-10763-11-git-send-email-luiz.dentz@gmail.com \
--to=luiz.dentz@gmail.com \
--cc=linux-bluetooth@vger.kernel.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).