Ejemplo n.º 1
0
static DBusMessage *try_acquire(DBusConnection *conn, DBusMessage *msg,
								void *data)
{
	struct media_transport *transport = data;
	struct media_owner *owner;
	struct media_request *req;
	guint id;

	if (transport->owner != NULL)
		return btd_error_not_authorized(msg);

	if (transport->state >= TRANSPORT_STATE_REQUESTING)
		return btd_error_not_authorized(msg);

	if (transport->state != TRANSPORT_STATE_PENDING)
		return btd_error_not_available(msg);

	owner = media_owner_create(msg);
	id = transport->resume(transport, owner);
	if (id == 0) {
		media_owner_free(owner);
		return btd_error_not_authorized(msg);
	}

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

	return NULL;
}
Ejemplo n.º 2
0
static void media_transport_remove_owner(struct media_transport *transport)
{
	struct media_owner *owner = transport->owner;

	DBG("Transport %s Owner %s", transport->path, owner->name);

	/* Reply if owner has a pending request */
	if (owner->pending)
		media_request_reply(owner->pending, EIO);

	transport->owner = NULL;

	if (owner->watch)
		g_dbus_remove_watch(btd_get_dbus_connection(), owner->watch);

	media_owner_free(owner);

	if (state_in_use(transport->state))
		transport->suspend(transport, NULL);
}
Ejemplo n.º 3
0
static void media_transport_remove(struct media_transport *transport,
						struct media_owner *owner)
{
	DBG("Transport %s Owner %s", transport->path, owner->name);

	media_transport_release(transport, owner->accesstype);

	/* Reply if owner has a pending request */
	if (owner->pending)
		media_request_reply(owner->pending, transport->conn, EIO);

	transport->owners = g_slist_remove(transport->owners, owner);

	if (owner->watch)
		g_dbus_remove_watch(transport->conn, owner->watch);

	media_owner_free(owner);

	/* Suspend if there is no longer any owner */
	if (transport->owners == NULL && transport->in_use)
		transport->suspend(transport, NULL);
}
Ejemplo n.º 4
0
static DBusMessage *acquire(DBusConnection *conn, DBusMessage *msg,
					void *data)
{
	struct media_transport *transport = data;
	struct media_owner *owner;
	struct media_request *req;
	const char *accesstype, *sender;
	guint id;

	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 (media_transport_acquire(transport, accesstype) == FALSE)
		return btd_error_not_authorized(msg);

	owner = media_owner_create(conn, msg, accesstype);
	id = transport->resume(transport, owner);
	if (id == 0) {
		media_transport_release(transport, accesstype);
		media_owner_free(owner);
		return btd_error_not_authorized(msg);
	}

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

	return NULL;
}