Пример #1
0
static void media_owner_free(struct media_owner *owner)
{
	DBG("Owner %s", owner->name);

	media_owner_remove(owner);

	g_free(owner->name);
	g_free(owner);
}
Пример #2
0
static DBusMessage *release(DBusConnection *conn, DBusMessage *msg,
					void *data)
{
	struct media_transport *transport = data;
	struct media_owner *owner;
	const char *accesstype, *sender;
	struct media_request *req;

	if (!dbus_message_get_args(msg, NULL,
				DBUS_TYPE_STRING, &accesstype,
				DBUS_TYPE_INVALID))
		return NULL;

	sender = dbus_message_get_sender(msg);

	owner = media_transport_find_owner(transport, sender);
	if (owner == NULL)
		return btd_error_not_authorized(msg);

	if (g_strcmp0(owner->accesstype, accesstype) == 0) {
		guint id;

		/* Not the last owner, no need to suspend */
		if (g_slist_length(transport->owners) != 1) {
			media_transport_remove(transport, owner);
			return g_dbus_create_reply(msg, DBUS_TYPE_INVALID);
		}

		if (owner->pending) {
			const char *member;

			member = dbus_message_get_member(owner->pending->msg);
			/* Cancel Acquire request if that exist */
			if (g_str_equal(member, "Acquire"))
				media_owner_remove(owner);
			else
				return btd_error_in_progress(msg);
		}

		id = transport->suspend(transport, owner);
		if (id == 0) {
			media_transport_remove(transport, owner);
			return g_dbus_create_reply(msg, DBUS_TYPE_INVALID);
		}

		req = media_request_create(msg, id);
		media_owner_add(owner, req);

		return NULL;
	} else if (g_strstr_len(owner->accesstype, -1, accesstype) != NULL) {
		media_transport_release(transport, accesstype);
		g_strdelimit(owner->accesstype, accesstype, ' ');
	} else
		return btd_error_not_authorized(msg);

	return g_dbus_create_reply(msg, DBUS_TYPE_INVALID);
}
Пример #3
0
static void media_owner_exit(DBusConnection *connection, void *user_data)
{
	struct media_owner *owner = user_data;

	owner->watch = 0;

	media_owner_remove(owner);

	media_transport_remove_owner(owner->transport);
}
Пример #4
0
static void gateway_resume_complete(struct audio_device *dev, GError *err,
							void *user_data)
{
	struct media_owner *owner = user_data;
	struct media_request *req = owner->pending;
	struct media_transport *transport = owner->transport;
	int fd;
	uint16_t imtu, omtu;
	gboolean ret;

	req->id = 0;

	if (dev == NULL)
		goto fail;

	if (err) {
		error("Failed to resume gateway: error %s", err->message);
		goto fail;
	}

	fd = gateway_get_sco_fd(dev);
	if (fd < 0)
		goto fail;

	imtu = 48;
	omtu = 48;

	media_transport_set_fd(transport, fd, imtu, omtu);

	if (g_strstr_len(owner->accesstype, -1, "r") == NULL)
		imtu = 0;

	if (g_strstr_len(owner->accesstype, -1, "w") == NULL)
		omtu = 0;

	ret = g_dbus_send_reply(transport->conn, req->msg,
						DBUS_TYPE_UNIX_FD, &fd,
						DBUS_TYPE_UINT16, &imtu,
						DBUS_TYPE_UINT16, &omtu,
						DBUS_TYPE_INVALID);
	if (ret == FALSE)
		goto fail;

	media_owner_remove(owner);

	return;

fail:
	media_transport_remove(transport, owner);
}
Пример #5
0
static void a2dp_resume_complete(struct avdtp *session,
				struct avdtp_error *err, void *user_data)
{
	struct media_owner *owner = user_data;
	struct media_request *req = owner->pending;
	struct media_transport *transport = owner->transport;
	struct a2dp_sep *sep = media_endpoint_get_sep(transport->endpoint);
	struct avdtp_stream *stream;
	int fd;
	uint16_t imtu, omtu;
	gboolean ret;

	req->id = 0;

	if (err)
		goto fail;

	stream = a2dp_sep_get_stream(sep);
	if (stream == NULL)
		goto fail;

	ret = avdtp_stream_get_transport(stream, &fd, &imtu, &omtu, NULL);
	if (ret == FALSE)
		goto fail;

	media_transport_set_fd(transport, fd, imtu, omtu);

	if (g_strstr_len(owner->accesstype, -1, "r") == NULL)
		imtu = 0;

	if (g_strstr_len(owner->accesstype, -1, "w") == NULL)
		omtu = 0;

	ret = g_dbus_send_reply(transport->conn, req->msg,
						DBUS_TYPE_UNIX_FD, &fd,
						DBUS_TYPE_UINT16, &imtu,
						DBUS_TYPE_UINT16, &omtu,
						DBUS_TYPE_INVALID);
	if (ret == FALSE)
		goto fail;

	media_owner_remove(owner);

	return;

fail:
	media_transport_remove(transport, owner);
}
Пример #6
0
static void headset_suspend_complete(struct audio_device *dev, void *user_data)
{
	struct media_owner *owner = user_data;
	struct media_transport *transport = owner->transport;

	/* Release always succeeds */
	if (owner->pending) {
		owner->pending->id = 0;
		media_request_reply(owner->pending, transport->conn, 0);
		media_owner_remove(owner);
	}

	headset_unlock(dev, HEADSET_LOCK_READ | HEADSET_LOCK_WRITE);
	transport->in_use = FALSE;
	media_transport_remove(transport, owner);
}
Пример #7
0
static gboolean gateway_suspend_complete(gpointer user_data)
{
	struct media_owner *owner = user_data;
	struct media_transport *transport = owner->transport;

	/* Release always succeeds */
	if (owner->pending) {
		owner->pending->id = 0;
		media_request_reply(owner->pending, transport->conn, 0);
		media_owner_remove(owner);
	}

	transport->in_use = FALSE;
	media_transport_remove(transport, owner);
	return FALSE;
}
Пример #8
0
static gboolean gateway_suspend_complete(gpointer user_data)
{
	struct media_owner *owner = user_data;
	struct media_transport *transport = owner->transport;
	struct audio_device *device = transport->device;

	/* Release always succeeds */
	if (owner->pending) {
		owner->pending->id = 0;
		media_request_reply(owner->pending, transport->conn, 0);
		media_owner_remove(owner);
	}

	gateway_unlock(device, GATEWAY_LOCK_READ | GATEWAY_LOCK_WRITE);
	transport->in_use = FALSE;
	media_transport_remove(transport, owner);
	return FALSE;
}
Пример #9
0
static void a2dp_suspend_complete(struct avdtp *session,
				struct avdtp_error *err, void *user_data)
{
	struct media_owner *owner = user_data;
	struct media_transport *transport = owner->transport;
	struct a2dp_sep *sep = media_endpoint_get_sep(transport->endpoint);

	/* Release always succeeds */
	if (owner->pending) {
		owner->pending->id = 0;
		media_request_reply(owner->pending, transport->conn, 0);
		media_owner_remove(owner);
	}

	a2dp_sep_unlock(sep, transport->session);
	transport->in_use = FALSE;
	media_transport_remove(transport, owner);
}
Пример #10
0
static void a2dp_suspend_complete(struct avdtp *session,
				struct avdtp_error *err, void *user_data)
{
	struct media_owner *owner = user_data;
	struct media_transport *transport = owner->transport;
	struct a2dp_transport *a2dp = transport->data;
	struct a2dp_sep *sep = media_endpoint_get_sep(transport->endpoint);

	/* Release always succeeds */
	if (owner->pending) {
		owner->pending->id = 0;
		media_request_reply(owner->pending, 0);
		media_owner_remove(owner);
	}

	a2dp_sep_unlock(sep, a2dp->session);
	transport_set_state(transport, TRANSPORT_STATE_IDLE);
	media_transport_remove_owner(transport);
}
Пример #11
0
static DBusMessage *release(DBusConnection *conn, DBusMessage *msg,
					void *data)
{
	struct media_transport *transport = data;
	struct media_owner *owner = transport->owner;
	const char *sender;
	struct media_request *req;
	guint id;

	sender = dbus_message_get_sender(msg);

	if (owner == NULL || g_strcmp0(owner->name, sender) != 0)
		return btd_error_not_authorized(msg);

	if (owner->pending) {
		const char *member;

		member = dbus_message_get_member(owner->pending->msg);
		/* Cancel Acquire request if that exist */
		if (g_str_equal(member, "Acquire"))
			media_owner_remove(owner);
		else
			return btd_error_in_progress(msg);
	}

	transport_set_state(transport, TRANSPORT_STATE_SUSPENDING);

	id = transport->suspend(transport, owner);
	if (id == 0) {
		media_transport_remove_owner(transport);
		return g_dbus_create_reply(msg, DBUS_TYPE_INVALID);
	}

	req = media_request_create(msg, id);
	media_owner_add(owner, req);

	return NULL;
}