mirror of
				https://gitlab.freedesktop.org/pipewire/pipewire.git
				synced 2025-11-03 09:01:54 -05:00 
			
		
		
		
	resource: pass the resource id in the error
This commit is contained in:
		
							parent
							
								
									4401e479c6
								
							
						
					
					
						commit
						f46a83dcb7
					
				
					 15 changed files with 46 additions and 54 deletions
				
			
		| 
						 | 
				
			
			@ -168,18 +168,18 @@ static void *create_object(void *_data,
 | 
			
		|||
 | 
			
		||||
      no_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;
 | 
			
		||||
      no_props:
 | 
			
		||||
	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;
 | 
			
		||||
      no_mem:
 | 
			
		||||
	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;
 | 
			
		||||
      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;
 | 
			
		||||
      done:
 | 
			
		||||
	if (properties)
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -83,11 +83,11 @@ static void *create_object(void *_data,
 | 
			
		|||
 | 
			
		||||
      no_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;
 | 
			
		||||
      no_mem:
 | 
			
		||||
	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;
 | 
			
		||||
      done:
 | 
			
		||||
	if (properties)
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -308,6 +308,7 @@ static void do_portal_check(struct client_info *cinfo)
 | 
			
		|||
	const char *handle;
 | 
			
		||||
	const char *device;
 | 
			
		||||
	struct async_pending *p;
 | 
			
		||||
	struct pw_resource *core_resource;
 | 
			
		||||
 | 
			
		||||
	pw_log_info("ask portal for client %p", client);
 | 
			
		||||
	pw_client_set_busy(client, true);
 | 
			
		||||
| 
						 | 
				
			
			@ -382,7 +383,8 @@ static void do_portal_check(struct client_info *cinfo)
 | 
			
		|||
	dbus_error_free(&error);
 | 
			
		||||
	goto 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;
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -114,7 +114,7 @@ static void *create_object(void *_data,
 | 
			
		|||
			   uint32_t new_id)
 | 
			
		||||
{
 | 
			
		||||
	struct factory_data *d = _data;
 | 
			
		||||
	struct pw_client *client;
 | 
			
		||||
	struct pw_client *client = NULL;
 | 
			
		||||
	struct pw_node *output_node, *input_node;
 | 
			
		||||
	struct pw_port *outport, *inport;
 | 
			
		||||
	struct pw_core *core;
 | 
			
		||||
| 
						 | 
				
			
			@ -129,8 +129,8 @@ static void *create_object(void *_data,
 | 
			
		|||
	int res;
 | 
			
		||||
	bool linger;
 | 
			
		||||
 | 
			
		||||
	if (resource == NULL)
 | 
			
		||||
		goto no_resource;
 | 
			
		||||
	client = pw_resource_get_client(resource);
 | 
			
		||||
	core = pw_client_get_core(client);
 | 
			
		||||
 | 
			
		||||
	if (properties == NULL)
 | 
			
		||||
		goto no_properties;
 | 
			
		||||
| 
						 | 
				
			
			@ -151,9 +151,6 @@ static void *create_object(void *_data,
 | 
			
		|||
	str = pw_properties_get(properties, PW_LINK_INPUT_PORT_ID);
 | 
			
		||||
	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);
 | 
			
		||||
	if (global == NULL || pw_global_get_type(global) != PW_TYPE_INTERFACE_Node)
 | 
			
		||||
		goto no_output;
 | 
			
		||||
| 
						 | 
				
			
			@ -224,36 +221,32 @@ static void *create_object(void *_data,
 | 
			
		|||
 | 
			
		||||
	return link;
 | 
			
		||||
 | 
			
		||||
      no_resource:
 | 
			
		||||
	pw_log_error("link factory needs a resource");
 | 
			
		||||
	pw_resource_error(resource, -EINVAL, "no resource");
 | 
			
		||||
	goto done;
 | 
			
		||||
      no_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;
 | 
			
		||||
      no_output:
 | 
			
		||||
	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;
 | 
			
		||||
      no_input:
 | 
			
		||||
	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;
 | 
			
		||||
      no_output_port:
 | 
			
		||||
	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;
 | 
			
		||||
      no_input_port:
 | 
			
		||||
	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;
 | 
			
		||||
      no_mem:
 | 
			
		||||
	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;
 | 
			
		||||
      no_bind:
 | 
			
		||||
	pw_resource_error(resource, res, "can't bind link");
 | 
			
		||||
	pw_resource_error(resource, new_id, res, "can't bind link");
 | 
			
		||||
	goto done;
 | 
			
		||||
      done:
 | 
			
		||||
	if (properties)
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -120,7 +120,7 @@ static void *create_object(void *_data,
 | 
			
		|||
      no_properties:
 | 
			
		||||
	pw_log_error("needed properties: spa.library.name=<library-name> spa.factory.name=<factory-name>");
 | 
			
		||||
	if (resource) {
 | 
			
		||||
		pw_resource_error(resource, -EINVAL,
 | 
			
		||||
		pw_resource_error(resource, new_id, -EINVAL,
 | 
			
		||||
					"needed properties: "
 | 
			
		||||
						"spa.library.name=<library-name> "
 | 
			
		||||
						"spa.factory.name=<factory-name>");
 | 
			
		||||
| 
						 | 
				
			
			@ -129,7 +129,7 @@ static void *create_object(void *_data,
 | 
			
		|||
      no_mem:
 | 
			
		||||
	pw_log_error("can't create node");
 | 
			
		||||
	if (resource) {
 | 
			
		||||
		pw_resource_error(resource, -ENOMEM, "no memory");
 | 
			
		||||
		pw_resource_error(resource, new_id, -ENOMEM, "no memory");
 | 
			
		||||
	}
 | 
			
		||||
	return NULL;
 | 
			
		||||
}
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -117,7 +117,7 @@ global_bind(void *_data, struct pw_client *client, uint32_t permissions,
 | 
			
		|||
 | 
			
		||||
      no_mem:
 | 
			
		||||
	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;
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -212,8 +212,9 @@ static void core_get_registry(void *object, uint32_t version, uint32_t new_id)
 | 
			
		|||
 | 
			
		||||
      no_mem:
 | 
			
		||||
	pw_log_error("can't create registry resource");
 | 
			
		||||
	pw_core_resource_error(client->core_resource,
 | 
			
		||||
			       resource->id, -ENOMEM, "no memory");
 | 
			
		||||
	pw_core_resource_error(client->core_resource, new_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
 | 
			
		||||
| 
						 | 
				
			
			@ -253,29 +254,32 @@ core_create_object(void *object,
 | 
			
		|||
	/* error will be posted */
 | 
			
		||||
	obj = pw_factory_create_object(factory, resource, type, version, properties, new_id);
 | 
			
		||||
	if (obj == NULL)
 | 
			
		||||
		goto no_mem;
 | 
			
		||||
		goto error;
 | 
			
		||||
 | 
			
		||||
      done:
 | 
			
		||||
	return;
 | 
			
		||||
 | 
			
		||||
      no_factory:
 | 
			
		||||
	pw_log_error("can't find node factory %s", factory_name);
 | 
			
		||||
	pw_core_resource_error(client->core_resource,
 | 
			
		||||
			       resource->id, -EINVAL, "unknown factory name %s", factory_name);
 | 
			
		||||
	goto done;
 | 
			
		||||
			       new_id, -EINVAL, "unknown factory name %s", factory_name);
 | 
			
		||||
	goto error;
 | 
			
		||||
      wrong_version:
 | 
			
		||||
      wrong_type:
 | 
			
		||||
	pw_log_error("invalid resource type/version");
 | 
			
		||||
	pw_core_resource_error(client->core_resource,
 | 
			
		||||
			       resource->id, -EINVAL, "wrong resource type/version");
 | 
			
		||||
	goto done;
 | 
			
		||||
			       new_id, -EINVAL, "wrong resource type/version");
 | 
			
		||||
	goto error;
 | 
			
		||||
      no_properties:
 | 
			
		||||
	pw_log_error("can't create properties");
 | 
			
		||||
	goto no_mem;
 | 
			
		||||
      no_mem:
 | 
			
		||||
	pw_core_resource_error(client->core_resource,
 | 
			
		||||
			       resource->id, -ENOMEM, "no memory");
 | 
			
		||||
	goto done;
 | 
			
		||||
			       new_id, -ENOMEM, "no memory");
 | 
			
		||||
	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)
 | 
			
		||||
| 
						 | 
				
			
			@ -296,8 +300,7 @@ static void core_destroy(void *object, uint32_t id)
 | 
			
		|||
 | 
			
		||||
      no_resource:
 | 
			
		||||
	pw_log_error("can't find resouce %d", id);
 | 
			
		||||
	pw_core_resource_error(client->core_resource,
 | 
			
		||||
			       resource->id, -EINVAL, "unknown resouce %d", id);
 | 
			
		||||
	pw_core_resource_error(client->core_resource, id, -EINVAL, "unknown resouce %d", id);
 | 
			
		||||
	goto done;
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -116,8 +116,7 @@ global_bind(void *_data, struct pw_client *client, uint32_t permissions,
 | 
			
		|||
 | 
			
		||||
      no_mem:
 | 
			
		||||
	pw_log_error("can't create factory resource");
 | 
			
		||||
	pw_core_resource_error(client->core_resource,
 | 
			
		||||
			       client->core_resource->id, -ENOMEM, "no memory");
 | 
			
		||||
	pw_core_resource_error(client->core_resource, id, -ENOMEM, "no memory");
 | 
			
		||||
	return;
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -242,8 +242,7 @@ pw_global_bind(struct pw_global *global, struct pw_client *client, uint32_t perm
 | 
			
		|||
 | 
			
		||||
     wrong_version:
 | 
			
		||||
	res = -EINVAL;
 | 
			
		||||
	pw_core_resource_error(client->core_resource,
 | 
			
		||||
			       client->core_resource->id,
 | 
			
		||||
	pw_core_resource_error(client->core_resource, id,
 | 
			
		||||
			     res, "id %d: interface version %d < %d",
 | 
			
		||||
			     id, global->version, version);
 | 
			
		||||
	return res;
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -1168,8 +1168,7 @@ global_bind(void *_data, struct pw_client *client, uint32_t permissions,
 | 
			
		|||
 | 
			
		||||
      no_mem:
 | 
			
		||||
	pw_log_error("can't create link resource");
 | 
			
		||||
	pw_core_resource_error(client->core_resource,
 | 
			
		||||
			       client->core_resource->id, -ENOMEM, "no memory");
 | 
			
		||||
	pw_core_resource_error(client->core_resource, id, -ENOMEM, "no memory");
 | 
			
		||||
	return;
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -133,8 +133,7 @@ global_bind(void *_data, struct pw_client *client, uint32_t permissions,
 | 
			
		|||
 | 
			
		||||
      no_mem:
 | 
			
		||||
	pw_log_error("can't create module resource");
 | 
			
		||||
	pw_core_resource_error(client->core_resource,
 | 
			
		||||
			       client->core_resource->id, -ENOMEM, "no memory");
 | 
			
		||||
	pw_core_resource_error(client->core_resource, id, -ENOMEM, "no memory");
 | 
			
		||||
	return;
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -401,8 +401,7 @@ global_bind(void *_data, struct pw_client *client, uint32_t permissions,
 | 
			
		|||
 | 
			
		||||
      no_mem:
 | 
			
		||||
	pw_log_error("can't create node resource");
 | 
			
		||||
	pw_core_resource_error(client->core_resource,
 | 
			
		||||
			       client->core_resource->id, -ENOMEM, "no memory");
 | 
			
		||||
	pw_core_resource_error(client->core_resource, id, -ENOMEM, "no memory");
 | 
			
		||||
	return;
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -435,8 +435,7 @@ global_bind(void *_data, struct pw_client *client, uint32_t permissions,
 | 
			
		|||
 | 
			
		||||
      no_mem:
 | 
			
		||||
	pw_log_error("can't create port resource");
 | 
			
		||||
	pw_core_resource_error(client->core_resource,
 | 
			
		||||
			       client->core_resource->id, -ENOMEM, "no memory");
 | 
			
		||||
	pw_core_resource_error(client->core_resource, id, -ENOMEM, "no memory");
 | 
			
		||||
	return;
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -146,10 +146,10 @@ const struct pw_protocol_marshal *pw_resource_get_marshal(struct pw_resource *re
 | 
			
		|||
	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)
 | 
			
		||||
		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)
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -115,7 +115,7 @@ void pw_resource_add_override(struct pw_resource *resource,
 | 
			
		|||
			      void *data);
 | 
			
		||||
 | 
			
		||||
/** 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 */
 | 
			
		||||
struct spa_hook_list *pw_resource_get_implementation(struct pw_resource *resource);
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue