access: cleanups

Rename some callbacks
Pass result in complete callback
This commit is contained in:
Wim Taymans 2017-06-09 17:42:29 +02:00
parent 34450ed7ed
commit b5e60ad02a
3 changed files with 24 additions and 29 deletions

View file

@ -124,8 +124,8 @@ add_pending(struct client_info *cinfo, const char *handle, struct pw_access_data
struct async_pending *p;
struct pw_access_data *ad;
ad = access_data->async_copy(access_data, sizeof(struct async_pending));
ad->free_cb = free_pending;
ad = access_data->async_start(access_data, sizeof(struct async_pending));
ad->free = free_pending;
p = ad->user_data;
p->info = cinfo;
@ -142,8 +142,7 @@ static void client_info_free(struct client_info *cinfo)
struct async_pending *p, *tmp;
spa_list_for_each_safe(p, tmp, &cinfo->async_pending, link) {
p->access_data->res = SPA_RESULT_NO_PERMISSION;
p->access_data->complete_cb(p->access_data);
p->access_data->complete(p->access_data, SPA_RESULT_NO_PERMISSION);
}
spa_list_remove(&cinfo->link);
free(cinfo);
@ -272,8 +271,7 @@ portal_response(DBusConnection *connection, DBusMessage *msg, void *user_data)
pw_log_debug("portal check result: %d", response);
d->res = response == 0 ? SPA_RESULT_OK : SPA_RESULT_NO_PERMISSION;
d->complete_cb(d);
d->complete(d, response == 0 ? SPA_RESULT_OK : SPA_RESULT_NO_PERMISSION);
return DBUS_HANDLER_RESULT_HANDLED;
}
@ -298,13 +296,11 @@ do_create_node(struct pw_access *access,
const char *device;
if (!cinfo->is_sandboxed) {
data->res = SPA_RESULT_OK;
data->complete_cb(data);
data->complete(data, SPA_RESULT_OK);
return SPA_RESULT_OK;
}
if (strcmp(factory_name, "client-node") != 0) {
data->res = SPA_RESULT_NO_PERMISSION;
data->complete_cb(data);
data->complete(data, SPA_RESULT_NO_PERMISSION);
return SPA_RESULT_NO_PERMISSION;
}
@ -387,13 +383,14 @@ do_create_link(struct pw_access *access,
{
struct impl *impl = SPA_CONTAINER_OF(access, struct impl, access);
struct client_info *cinfo = find_client_info(impl, data->resource->client);
int res;
if (cinfo->is_sandboxed)
data->res = SPA_RESULT_NO_PERMISSION;
res = SPA_RESULT_NO_PERMISSION;
else
data->res = SPA_RESULT_OK;
res = SPA_RESULT_OK;
data->complete_cb(data);
data->complete(data, res);
return SPA_RESULT_OK;
}

View file

@ -32,12 +32,11 @@ extern "C" {
#include <pipewire/server/resource.h>
struct pw_access_data {
int res;
struct pw_resource *resource;
void *(*async_copy) (struct pw_access_data *data, size_t size);
void (*complete_cb) (struct pw_access_data *data);
void (*free_cb) (struct pw_access_data *data);
void *(*async_start) (struct pw_access_data *data, size_t size);
void (*complete) (struct pw_access_data *data, int res);
void (*free) (struct pw_access_data *data);
void *user_data;
};

View file

@ -143,7 +143,7 @@ static void core_get_registry(void *object, uint32_t new_id)
resource->id, SPA_RESULT_NO_MEMORY, "no memory");
}
static void *async_create_node_copy(struct pw_access_data *data, size_t size)
static void *async_create_node_start(struct pw_access_data *data, size_t size)
{
struct access_create_node *d;
@ -163,22 +163,22 @@ static void async_create_node_free(struct pw_access_data *data)
if (d->properties)
pw_properties_free(d->properties);
if (d->async) {
if (d->data.free_cb)
d->data.free_cb(&d->data);
if (d->data.free)
d->data.free(&d->data);
free(d->factory_name);
free(d->name);
free(d);
}
}
static void async_create_node_complete(struct pw_access_data *data)
static void async_create_node_complete(struct pw_access_data *data, int res)
{
struct access_create_node *d = (struct access_create_node *) data;
struct pw_resource *resource = d->data.resource;
struct pw_client *client = resource->client;
struct pw_node_factory *factory;
if (data->res != SPA_RESULT_OK)
if (res != SPA_RESULT_OK)
goto denied;
factory = pw_core_find_node_factory(client->core, d->factory_name);
@ -197,7 +197,7 @@ static void async_create_node_complete(struct pw_access_data *data)
resource->id, SPA_RESULT_INVALID_ARGUMENTS, "unknown factory name");
goto done;
denied:
pw_log_error("create node refused");
pw_log_error("create node refused %d", res);
pw_core_notify_error(client->core_resource,
resource->id, SPA_RESULT_NO_PERMISSION, "operation not allowed");
done:
@ -228,9 +228,9 @@ core_create_node(void *object,
}
access_data.data.resource = resource;
access_data.data.async_copy = async_create_node_copy;
access_data.data.complete_cb = async_create_node_complete;
access_data.data.free_cb = NULL;
access_data.data.async_start = async_create_node_start;
access_data.data.complete = async_create_node_complete;
access_data.data.free = NULL;
access_data.factory_name = (char *) factory_name;
access_data.name = (char *) name;
access_data.properties = properties;
@ -238,17 +238,16 @@ core_create_node(void *object,
access_data.async = false;
if (client->core->access) {
access_data.data.res = SPA_RESULT_NO_PERMISSION;
res = client->core->access->create_node(client->core->access,
&access_data.data,
factory_name,
name,
properties);
} else {
res = access_data.data.res = SPA_RESULT_OK;
res = SPA_RESULT_OK;
}
if (!SPA_RESULT_IS_ASYNC(res))
async_create_node_complete(&access_data.data);
async_create_node_complete(&access_data.data, res);
return;
no_mem: