diff --git a/profiles/audio/manager.c b/profiles/audio/manager.c
index 3a6ea85..7025868 100644
--- a/profiles/audio/manager.c
+++ b/profiles/audio/manager.c
return -1;
}
- return source_connect(audio_dev, connect_cb, profile);
+ return source_connect(audio_dev);
}
static int a2dp_source_disconnect(struct btd_device *dev,
return -1;
}
- return source_disconnect(audio_dev, FALSE, disconnect_cb, profile);
+ return source_disconnect(audio_dev, FALSE);
}
static int a2dp_sink_connect(struct btd_device *dev,
.remove = media_server_remove,
};
+void audio_sink_connected(struct btd_device *dev, int err)
+{
+ device_profile_connected(dev, &a2dp_sink_profile, err);
+}
+
+void audio_sink_disconnected(struct btd_device *dev, int err)
+{
+ device_profile_connected(dev, &a2dp_sink_profile, err);
+}
+
+void audio_source_connected(struct btd_device *dev, int err)
+{
+ device_profile_connected(dev, &a2dp_source_profile, err);
+}
+
+void audio_source_disconnected(struct btd_device *dev, int err)
+{
+ device_profile_connected(dev, &a2dp_source_profile, err);
+}
+
int audio_manager_init(GKeyFile *conf)
{
char **list;
diff --git a/profiles/audio/manager.h b/profiles/audio/manager.h
index 5691063..75c1308 100644
--- a/profiles/audio/manager.h
+++ b/profiles/audio/manager.h
gboolean media_player;
};
+void audio_sink_connected(struct btd_device *dev, int err);
+void audio_sink_disconnected(struct btd_device *dev, int err);
+void audio_source_connected(struct btd_device *dev, int err);
+void audio_source_disconnected(struct btd_device *dev, int err);
+
int audio_manager_init(GKeyFile *config);
void audio_manager_exit(void);
diff --git a/profiles/audio/source.c b/profiles/audio/source.c
index 85aeb4f..ef6cf7a 100644
--- a/profiles/audio/source.c
+++ b/profiles/audio/source.c
#include "media.h"
#include "a2dp.h"
#include "error.h"
+#include "manager.h"
#include "source.h"
#include "dbus-common.h"
#include "../src/adapter.h"
#define STREAM_SETUP_RETRY_TIMER 2
-struct pending_request {
- audio_device_cb cb;
- void *cb_data;
- unsigned int id;
-};
-
struct source {
struct audio_device *dev;
struct avdtp *session;
avdtp_session_state_t session_state;
avdtp_state_t stream_state;
source_state_t state;
- struct pending_request *connect;
- struct pending_request *disconnect;
+ unsigned int connect_id;
+ unsigned int disconnect_id;
};
struct source_state_callback {
source->session_state = new_state;
}
-static void pending_request_free(struct audio_device *dev,
- struct pending_request *pending,
- int err)
-{
- if (pending->cb)
- pending->cb(dev, err, pending->cb_data);
-
- if (pending->id)
- a2dp_cancel(dev, pending->id);
-
- g_free(pending);
-}
-
static void stream_state_changed(struct avdtp_stream *stream,
avdtp_state_t old_state,
avdtp_state_t new_state,
switch (new_state) {
case AVDTP_STATE_IDLE:
- if (source->disconnect) {
- struct pending_request *p;
-
- p = source->disconnect;
- source->disconnect = NULL;
+ audio_source_disconnected(dev->btd_dev, 0);
- pending_request_free(dev, p, 0);
+ if (source->disconnect_id > 0) {
+ a2dp_cancel(dev, source->disconnect_id);
+ source->disconnect_id = 0;
}
if (source->session) {
static gboolean stream_setup_retry(gpointer user_data)
{
struct source *source = user_data;
- struct pending_request *pending = source->connect;
int err;
source->retry_id = 0;
err = -EIO;
}
- source->connect = NULL;
- pending_request_free(source->dev, pending, err);
+ audio_source_connected(source->dev->btd_dev, err);
+
+ if (source->connect_id > 0) {
+ a2dp_cancel(source->dev, source->connect_id);
+ source->connect_id = 0;
+ }
return FALSE;
}
struct avdtp_error *err, void *user_data)
{
struct source *source = user_data;
- struct pending_request *pending;
-
- pending = source->connect;
- pending->id = 0;
+ source->connect_id = 0;
if (stream) {
DBG("Stream successfully created");
-
- source->connect = NULL;
- pending_request_free(source->dev, pending, 0);
-
+ audio_source_connected(source->dev->btd_dev, 0);
return;
}
stream_setup_retry,
source);
} else {
- source->connect = NULL;
- pending_request_free(source->dev, pending, -EIO);
DBG("Stream setup failed : %s", avdtp_strerror(err));
+ audio_source_connected(source->dev->btd_dev, -EIO);
}
}
GSList *caps, void *user_data)
{
struct source *source = user_data;
- struct pending_request *pending;
int id;
- pending = source->connect;
-
- pending->id = 0;
+ source->connect_id = 0;
if (caps == NULL)
goto failed;
if (id == 0)
goto failed;
- pending->id = id;
+ source->connect_id = id;
return;
failed:
- pending_request_free(source->dev, pending, -EIO);
- source->connect = NULL;
+ audio_source_connected(source->dev->btd_dev, -EIO);
+
avdtp_unref(source->session);
source->session = NULL;
}
void *user_data)
{
struct source *source = user_data;
- struct pending_request *pending;
int id;
- pending = source->connect;
-
if (err) {
avdtp_unref(source->session);
source->session = NULL;
if (id == 0)
goto failed;
- pending->id = id;
+ source->connect_id = id;
return;
failed:
- pending_request_free(source->dev, pending, -EIO);
- source->connect = NULL;
+ audio_source_connected(source->dev->btd_dev, -EIO);
avdtp_unref(source->session);
source->session = NULL;
}
gboolean source_setup_stream(struct source *source, struct avdtp *session)
{
- if (source->connect || source->disconnect)
+ if (source->connect_id > 0 || source->disconnect_id > 0)
return FALSE;
if (session && !source->session)
if (avdtp_discover(source->session, discovery_complete, source) < 0)
return FALSE;
- source->connect = g_new0(struct pending_request, 1);
-
return TRUE;
}
-int source_connect(struct audio_device *dev, audio_device_cb cb, void *data)
+int source_connect(struct audio_device *dev)
{
struct source *source = dev->source;
- struct pending_request *pending;
if (!source->session)
source->session = avdtp_get(dev);
return -EIO;
}
- if (source->connect || source->disconnect)
+ if (source->connect_id > 0 || source->disconnect_id > 0)
return -EBUSY;
if (source->stream_state >= AVDTP_STATE_OPEN)
return -EIO;
}
- pending = source->connect;
- pending->cb = cb;
- pending->cb_data = data;
-
DBG("stream creation in progress");
return 0;
if (source->session)
avdtp_unref(source->session);
- if (source->connect)
- pending_request_free(dev, source->connect, -ECANCELED);
+ if (source->connect_id > 0) {
+ audio_source_connected(dev->btd_dev, -ECANCELED);
+ a2dp_cancel(dev, source->disconnect_id);
+ source->disconnect_id = 0;
+ }
- if (source->disconnect)
- pending_request_free(dev, source->disconnect, -ECANCELED);
+ if (source->disconnect_id > 0) {
+ audio_source_disconnected(dev->btd_dev, -ECANCELED);
+ a2dp_cancel(dev, source->disconnect_id);
+ source->disconnect_id = 0;
+ }
if (source->retry_id)
g_source_remove(source->retry_id);
return TRUE;
}
-int source_disconnect(struct audio_device *dev, gboolean shutdown,
- audio_device_cb cb, void *data)
+int source_disconnect(struct audio_device *dev, gboolean shutdown)
{
struct source *source = dev->source;
- struct pending_request *pending;
- int err;
if (!source->session)
return -ENOTCONN;
avdtp_set_device_disconnect(source->session, TRUE);
/* cancel pending connect */
- if (source->connect) {
- struct pending_request *pending = source->connect;
-
- pending_request_free(source->dev, pending, -ECANCELED);
- source->connect = NULL;
+ if (source->connect_id > 0) {
+ a2dp_cancel(dev, source->connect_id);
+ source->connect_id = 0;
+ audio_source_connected(dev->btd_dev, -ECANCELED);
avdtp_unref(source->session);
source->session = NULL;
}
/* disconnect already ongoing */
- if (source->disconnect)
+ if (source->disconnect_id > 0)
return -EBUSY;
if (!source->stream)
return -ENOTCONN;
- err = avdtp_close(source->session, source->stream, FALSE);
- if (err < 0)
- return err;
-
- pending = g_new0(struct pending_request, 1);
- pending->cb = cb;
- pending->cb_data = data;
- source->disconnect = pending;
-
- return 0;
+ return avdtp_close(source->session, source->stream, FALSE);
}
unsigned int source_add_state_cb(source_state_cb cb, void *user_data)
diff --git a/profiles/audio/source.h b/profiles/audio/source.h
index 2d382b5..a11bcff 100644
--- a/profiles/audio/source.h
+++ b/profiles/audio/source.h
void source_unregister(struct audio_device *dev);
gboolean source_is_active(struct audio_device *dev);
source_state_t source_get_state(struct audio_device *dev);
-int source_connect(struct audio_device *dev, audio_device_cb cb, void *data);
+int source_connect(struct audio_device *dev);
gboolean source_new_stream(struct audio_device *dev, struct avdtp *session,
struct avdtp_stream *stream);
gboolean source_setup_stream(struct source *source, struct avdtp *session);
-int source_disconnect(struct audio_device *dev, gboolean shutdown,
- audio_device_cb cb, void *data);
+int source_disconnect(struct audio_device *dev, gboolean shutdown);