diff --git a/profiles/audio/control.c b/profiles/audio/control.c
index cdba385..f520e49 100644
--- a/profiles/audio/control.c
+++ b/profiles/audio/control.c
control->remote = btd_service_ref(service);
}
-struct control *control_init(struct audio_device *dev,
- struct btd_service *service)
+static struct control *control_init(struct audio_device *dev)
{
struct control *control;
+ if (dev->control != NULL)
+ return dev->control;
+
if (!g_dbus_register_interface(btd_get_dbus_connection(),
device_get_path(dev->btd_dev),
AUDIO_CONTROL_INTERFACE,
control = g_new0(struct control, 1);
- control_update(control, service);
-
control->avctp_id = avctp_add_state_cb(dev, state_changed);
return control;
}
+struct control *control_init_target(struct audio_device *dev,
+ struct btd_service *service)
+{
+ struct control *control;
+
+ control = control_init(dev);
+ if (control == NULL)
+ return NULL;
+
+ control->target = btd_service_ref(service);
+
+ return control;
+}
+
+struct control *control_init_remote(struct audio_device *dev,
+ struct btd_service *service)
+{
+ struct control *control;
+
+ control = control_init(dev);
+ if (control == NULL)
+ return NULL;
+
+ control->remote = btd_service_ref(service);
+
+ return control;
+}
+
gboolean control_is_active(struct audio_device *dev)
{
struct control *control = dev->control;
diff --git a/profiles/audio/control.h b/profiles/audio/control.h
index 0a0f208..369cca6 100644
--- a/profiles/audio/control.h
+++ b/profiles/audio/control.h
struct btd_service;
-struct control *control_init(struct audio_device *dev,
+struct control *control_init_target(struct audio_device *dev,
+ struct btd_service *service);
+struct control *control_init_remote(struct audio_device *dev,
struct btd_service *service);
void control_update(struct control *control, struct btd_service *service);
void control_unregister(struct audio_device *dev);
diff --git a/profiles/audio/manager.c b/profiles/audio/manager.c
index 1518e5d..7f02fbd 100644
--- a/profiles/audio/manager.c
+++ b/profiles/audio/manager.c
return 0;
}
-static int avrcp_probe(struct btd_service *service)
+static int avrcp_target_probe(struct btd_service *service)
{
struct btd_device *device = btd_service_get_device(service);
struct audio_device *audio_dev;
return -1;
}
- if (audio_dev->control)
- control_update(audio_dev->control, service);
- else
- audio_dev->control = control_init(audio_dev, service);
+ audio_dev->control = control_init_target(audio_dev, service);
if (audio_dev->sink && sink_is_active(audio_dev))
avrcp_connect(audio_dev);
return 0;
}
+static int avrcp_remote_probe(struct btd_service *service)
+{
+ struct btd_device *device = btd_service_get_device(service);
+ struct audio_device *audio_dev;
+
+ audio_dev = get_audio_dev(device);
+ if (!audio_dev) {
+ DBG("unable to get a device object");
+ return -1;
+ }
+
+ audio_dev->control = control_init_remote(audio_dev, service);
+
+ return 0;
+}
+
static int a2dp_source_connect(struct btd_service *service)
{
struct btd_device *dev = btd_service_get_device(service);
.name = "audio-avrcp-target",
.remote_uuid = AVRCP_TARGET_UUID,
- .device_probe = avrcp_probe,
+ .device_probe = avrcp_target_probe,
.device_remove = audio_remove,
.connect = avrcp_target_connect,
.name = "audio-avrcp-control",
.remote_uuid = AVRCP_REMOTE_UUID,
- .device_probe = avrcp_probe,
+ .device_probe = avrcp_remote_probe,
.device_remove = audio_remove,
.adapter_probe = avrcp_remote_server_probe,