resource: pass the resource id in the error

This commit is contained in:
Wim Taymans 2018-10-03 19:24:53 +02:00
parent 4401e479c6
commit f46a83dcb7
15 changed files with 46 additions and 54 deletions

View file

@ -168,18 +168,18 @@ static void *create_object(void *_data,
no_resource: no_resource:
pw_log_error("audio-dsp needs a resource"); pw_log_error("audio-dsp needs a resource");
pw_resource_error(resource, -EINVAL, "no resource"); pw_resource_error(resource, new_id, -EINVAL, "no resource");
goto done; goto done;
no_props: no_props:
pw_log_error("audio-dsp needs a property"); pw_log_error("audio-dsp needs a property");
pw_resource_error(resource, -EINVAL, "no property"); pw_resource_error(resource, new_id, -EINVAL, "no property");
goto done; goto done;
no_mem: no_mem:
pw_log_error("can't create node"); pw_log_error("can't create node");
pw_resource_error(resource, -ENOMEM, "no memory"); pw_resource_error(resource, new_id, -ENOMEM, "no memory");
goto done; goto done;
no_bind: no_bind:
pw_resource_error(resource, res, "can't bind dsp node"); pw_resource_error(resource, new_id, res, "can't bind dsp node");
goto done; goto done;
done: done:
if (properties) if (properties)

View file

@ -83,11 +83,11 @@ static void *create_object(void *_data,
no_resource: no_resource:
pw_log_error("client-node needs a resource"); pw_log_error("client-node needs a resource");
pw_resource_error(resource, -EINVAL, "no resource"); pw_resource_error(resource, new_id, -EINVAL, "no resource");
goto done; goto done;
no_mem: no_mem:
pw_log_error("can't create node"); pw_log_error("can't create node");
pw_resource_error(resource, -ENOMEM, "no memory"); pw_resource_error(resource, new_id, -ENOMEM, "no memory");
goto done; goto done;
done: done:
if (properties) if (properties)

View file

@ -308,6 +308,7 @@ static void do_portal_check(struct client_info *cinfo)
const char *handle; const char *handle;
const char *device; const char *device;
struct async_pending *p; struct async_pending *p;
struct pw_resource *core_resource;
pw_log_info("ask portal for client %p", client); pw_log_info("ask portal for client %p", client);
pw_client_set_busy(client, true); pw_client_set_busy(client, true);
@ -382,7 +383,8 @@ static void do_portal_check(struct client_info *cinfo)
dbus_error_free(&error); dbus_error_free(&error);
goto not_allowed; goto not_allowed;
not_allowed: not_allowed:
pw_resource_error(pw_client_get_core_resource(client), -EPERM, "not allowed"); core_resource = pw_client_get_core_resource(client);
pw_resource_error(core_resource, 0, -EPERM, "not allowed");
return; return;
} }

View file

@ -114,7 +114,7 @@ static void *create_object(void *_data,
uint32_t new_id) uint32_t new_id)
{ {
struct factory_data *d = _data; struct factory_data *d = _data;
struct pw_client *client; struct pw_client *client = NULL;
struct pw_node *output_node, *input_node; struct pw_node *output_node, *input_node;
struct pw_port *outport, *inport; struct pw_port *outport, *inport;
struct pw_core *core; struct pw_core *core;
@ -129,8 +129,8 @@ static void *create_object(void *_data,
int res; int res;
bool linger; bool linger;
if (resource == NULL) client = pw_resource_get_client(resource);
goto no_resource; core = pw_client_get_core(client);
if (properties == NULL) if (properties == NULL)
goto no_properties; goto no_properties;
@ -151,9 +151,6 @@ static void *create_object(void *_data,
str = pw_properties_get(properties, PW_LINK_INPUT_PORT_ID); str = pw_properties_get(properties, PW_LINK_INPUT_PORT_ID);
input_port_id = str ? pw_properties_parse_int(str) : -1; input_port_id = str ? pw_properties_parse_int(str) : -1;
client = pw_resource_get_client(resource);
core = pw_client_get_core(client);
global = pw_core_find_global(core, output_node_id); global = pw_core_find_global(core, output_node_id);
if (global == NULL || pw_global_get_type(global) != PW_TYPE_INTERFACE_Node) if (global == NULL || pw_global_get_type(global) != PW_TYPE_INTERFACE_Node)
goto no_output; goto no_output;
@ -224,36 +221,32 @@ static void *create_object(void *_data,
return link; return link;
no_resource:
pw_log_error("link factory needs a resource");
pw_resource_error(resource, -EINVAL, "no resource");
goto done;
no_properties: no_properties:
pw_log_error("link-factory needs properties"); pw_log_error("link-factory needs properties");
pw_resource_error(resource, -EINVAL, "no properties"); pw_resource_error(resource, new_id, -EINVAL, "no properties");
goto done; goto done;
no_output: no_output:
pw_log_error("link-factory unknown output node %d", output_node_id); pw_log_error("link-factory unknown output node %d", output_node_id);
pw_resource_error(resource, -EINVAL, "unknown output node"); pw_resource_error(resource, new_id, -EINVAL, "unknown output node");
goto done; goto done;
no_input: no_input:
pw_log_error("link-factory unknown input node %d", input_node_id); pw_log_error("link-factory unknown input node %d", input_node_id);
pw_resource_error(resource, -EINVAL, "unknown input node"); pw_resource_error(resource, new_id, -EINVAL, "unknown input node");
goto done; goto done;
no_output_port: no_output_port:
pw_log_error("link-factory unknown output port %d", output_port_id); pw_log_error("link-factory unknown output port %d", output_port_id);
pw_resource_error(resource, -EINVAL, "unknown output port"); pw_resource_error(resource, new_id, -EINVAL, "unknown output port");
goto done; goto done;
no_input_port: no_input_port:
pw_log_error("link-factory unknown input port %d", input_port_id); pw_log_error("link-factory unknown input port %d", input_port_id);
pw_resource_error(resource, -EINVAL, "unknown input port"); pw_resource_error(resource, new_id, -EINVAL, "unknown input port");
goto done; goto done;
no_mem: no_mem:
pw_log_error("can't create link"); pw_log_error("can't create link");
pw_resource_error(resource, -ENOMEM, "no memory"); pw_resource_error(resource, new_id, -ENOMEM, "no memory");
goto done; goto done;
no_bind: no_bind:
pw_resource_error(resource, res, "can't bind link"); pw_resource_error(resource, new_id, res, "can't bind link");
goto done; goto done;
done: done:
if (properties) if (properties)

View file

@ -120,7 +120,7 @@ static void *create_object(void *_data,
no_properties: no_properties:
pw_log_error("needed properties: spa.library.name=<library-name> spa.factory.name=<factory-name>"); pw_log_error("needed properties: spa.library.name=<library-name> spa.factory.name=<factory-name>");
if (resource) { if (resource) {
pw_resource_error(resource, -EINVAL, pw_resource_error(resource, new_id, -EINVAL,
"needed properties: " "needed properties: "
"spa.library.name=<library-name> " "spa.library.name=<library-name> "
"spa.factory.name=<factory-name>"); "spa.factory.name=<factory-name>");
@ -129,7 +129,7 @@ static void *create_object(void *_data,
no_mem: no_mem:
pw_log_error("can't create node"); pw_log_error("can't create node");
if (resource) { if (resource) {
pw_resource_error(resource, -ENOMEM, "no memory"); pw_resource_error(resource, new_id, -ENOMEM, "no memory");
} }
return NULL; return NULL;
} }

View file

@ -117,7 +117,7 @@ global_bind(void *_data, struct pw_client *client, uint32_t permissions,
no_mem: no_mem:
pw_log_error("can't create client resource"); pw_log_error("can't create client resource");
pw_resource_error(client->core_resource, -ENOMEM, "no memory"); pw_resource_error(client->core_resource, id, -ENOMEM, "no memory");
return; return;
} }

View file

@ -212,8 +212,9 @@ static void core_get_registry(void *object, uint32_t version, uint32_t new_id)
no_mem: no_mem:
pw_log_error("can't create registry resource"); pw_log_error("can't create registry resource");
pw_core_resource_error(client->core_resource, pw_core_resource_error(client->core_resource, new_id, -ENOMEM, "no memory");
resource->id, -ENOMEM, "no memory"); pw_map_insert_at(&client->objects, new_id, NULL);
pw_core_resource_remove_id(client->core_resource, new_id);
} }
static void static void
@ -253,29 +254,32 @@ core_create_object(void *object,
/* error will be posted */ /* error will be posted */
obj = pw_factory_create_object(factory, resource, type, version, properties, new_id); obj = pw_factory_create_object(factory, resource, type, version, properties, new_id);
if (obj == NULL) if (obj == NULL)
goto no_mem; goto error;
done:
return; return;
no_factory: no_factory:
pw_log_error("can't find node factory %s", factory_name); pw_log_error("can't find node factory %s", factory_name);
pw_core_resource_error(client->core_resource, pw_core_resource_error(client->core_resource,
resource->id, -EINVAL, "unknown factory name %s", factory_name); new_id, -EINVAL, "unknown factory name %s", factory_name);
goto done; goto error;
wrong_version: wrong_version:
wrong_type: wrong_type:
pw_log_error("invalid resource type/version"); pw_log_error("invalid resource type/version");
pw_core_resource_error(client->core_resource, pw_core_resource_error(client->core_resource,
resource->id, -EINVAL, "wrong resource type/version"); new_id, -EINVAL, "wrong resource type/version");
goto done; goto error;
no_properties: no_properties:
pw_log_error("can't create properties"); pw_log_error("can't create properties");
goto no_mem; goto no_mem;
no_mem: no_mem:
pw_core_resource_error(client->core_resource, pw_core_resource_error(client->core_resource,
resource->id, -ENOMEM, "no memory"); new_id, -ENOMEM, "no memory");
goto done; goto error;
error:
pw_map_insert_at(&client->objects, new_id, NULL);
pw_core_resource_remove_id(client->core_resource, new_id);
return;
} }
static void core_destroy(void *object, uint32_t id) static void core_destroy(void *object, uint32_t id)
@ -296,8 +300,7 @@ static void core_destroy(void *object, uint32_t id)
no_resource: no_resource:
pw_log_error("can't find resouce %d", id); pw_log_error("can't find resouce %d", id);
pw_core_resource_error(client->core_resource, pw_core_resource_error(client->core_resource, id, -EINVAL, "unknown resouce %d", id);
resource->id, -EINVAL, "unknown resouce %d", id);
goto done; goto done;
} }

View file

@ -116,8 +116,7 @@ global_bind(void *_data, struct pw_client *client, uint32_t permissions,
no_mem: no_mem:
pw_log_error("can't create factory resource"); pw_log_error("can't create factory resource");
pw_core_resource_error(client->core_resource, pw_core_resource_error(client->core_resource, id, -ENOMEM, "no memory");
client->core_resource->id, -ENOMEM, "no memory");
return; return;
} }

View file

@ -242,8 +242,7 @@ pw_global_bind(struct pw_global *global, struct pw_client *client, uint32_t perm
wrong_version: wrong_version:
res = -EINVAL; res = -EINVAL;
pw_core_resource_error(client->core_resource, pw_core_resource_error(client->core_resource, id,
client->core_resource->id,
res, "id %d: interface version %d < %d", res, "id %d: interface version %d < %d",
id, global->version, version); id, global->version, version);
return res; return res;

View file

@ -1168,8 +1168,7 @@ global_bind(void *_data, struct pw_client *client, uint32_t permissions,
no_mem: no_mem:
pw_log_error("can't create link resource"); pw_log_error("can't create link resource");
pw_core_resource_error(client->core_resource, pw_core_resource_error(client->core_resource, id, -ENOMEM, "no memory");
client->core_resource->id, -ENOMEM, "no memory");
return; return;
} }

View file

@ -133,8 +133,7 @@ global_bind(void *_data, struct pw_client *client, uint32_t permissions,
no_mem: no_mem:
pw_log_error("can't create module resource"); pw_log_error("can't create module resource");
pw_core_resource_error(client->core_resource, pw_core_resource_error(client->core_resource, id, -ENOMEM, "no memory");
client->core_resource->id, -ENOMEM, "no memory");
return; return;
} }

View file

@ -401,8 +401,7 @@ global_bind(void *_data, struct pw_client *client, uint32_t permissions,
no_mem: no_mem:
pw_log_error("can't create node resource"); pw_log_error("can't create node resource");
pw_core_resource_error(client->core_resource, pw_core_resource_error(client->core_resource, id, -ENOMEM, "no memory");
client->core_resource->id, -ENOMEM, "no memory");
return; return;
} }

View file

@ -435,8 +435,7 @@ global_bind(void *_data, struct pw_client *client, uint32_t permissions,
no_mem: no_mem:
pw_log_error("can't create port resource"); pw_log_error("can't create port resource");
pw_core_resource_error(client->core_resource, pw_core_resource_error(client->core_resource, id, -ENOMEM, "no memory");
client->core_resource->id, -ENOMEM, "no memory");
return; return;
} }

View file

@ -146,10 +146,10 @@ const struct pw_protocol_marshal *pw_resource_get_marshal(struct pw_resource *re
return resource->marshal; return resource->marshal;
} }
void pw_resource_error(struct pw_resource *resource, int result, const char *error) void pw_resource_error(struct pw_resource *resource, uint32_t id, int result, const char *error)
{ {
if (resource->client->core_resource) if (resource->client->core_resource)
pw_core_resource_error(resource->client->core_resource, resource->id, result, error); pw_core_resource_error(resource->client->core_resource, id, result, error);
} }
void pw_resource_destroy(struct pw_resource *resource) void pw_resource_destroy(struct pw_resource *resource)

View file

@ -115,7 +115,7 @@ void pw_resource_add_override(struct pw_resource *resource,
void *data); void *data);
/** Generate an error for a resource */ /** Generate an error for a resource */
void pw_resource_error(struct pw_resource *resource, int result, const char *error); void pw_resource_error(struct pw_resource *resource, uint32_t id, int result, const char *error);
/** Get the implementation list of a resource */ /** Get the implementation list of a resource */
struct spa_hook_list *pw_resource_get_implementation(struct pw_resource *resource); struct spa_hook_list *pw_resource_get_implementation(struct pw_resource *resource);