mirror of
				https://gitlab.freedesktop.org/pipewire/pipewire.git
				synced 2025-11-03 09:01:54 -05:00 
			
		
		
		
	use global_update_keys
First set the properties in the object itself and then copy them over to the global. This ensure that the global properties are also in the object and makes code a bit cleaner. It also make it possible to use the global id to make the property values unique, if we want to later .
This commit is contained in:
		
							parent
							
								
									f79c347667
								
							
						
					
					
						commit
						469dff0153
					
				
					 9 changed files with 32 additions and 72 deletions
				
			
		| 
						 | 
				
			
			@ -324,16 +324,10 @@ int endpoint_init(struct endpoint *this,
 | 
			
		|||
	this->client_ep = client_ep;
 | 
			
		||||
	this->props = properties;
 | 
			
		||||
 | 
			
		||||
	properties = pw_properties_new(NULL, NULL);
 | 
			
		||||
	if (!properties)
 | 
			
		||||
		goto no_mem;
 | 
			
		||||
 | 
			
		||||
	pw_properties_update_keys(properties, &this->props->dict, keys);
 | 
			
		||||
 | 
			
		||||
	this->global = pw_global_new (context,
 | 
			
		||||
			PW_TYPE_INTERFACE_Endpoint,
 | 
			
		||||
			PW_VERSION_ENDPOINT,
 | 
			
		||||
			properties, endpoint_bind, this);
 | 
			
		||||
			NULL, endpoint_bind, this);
 | 
			
		||||
	if (!this->global)
 | 
			
		||||
		goto no_mem;
 | 
			
		||||
 | 
			
		||||
| 
						 | 
				
			
			@ -344,6 +338,8 @@ int endpoint_init(struct endpoint *this,
 | 
			
		|||
	this->info.id = pw_global_get_id(this->global);
 | 
			
		||||
	this->info.props = &this->props->dict;
 | 
			
		||||
 | 
			
		||||
	pw_global_update_keys(this->global, &this->props->dict, keys);
 | 
			
		||||
 | 
			
		||||
	pw_resource_set_bound_id(client_ep->resource, this->info.id);
 | 
			
		||||
 | 
			
		||||
	return pw_global_register(this->global);
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -286,16 +286,10 @@ int session_init(struct session *this,
 | 
			
		|||
	this->client_sess = client_sess;
 | 
			
		||||
	this->props = properties;
 | 
			
		||||
 | 
			
		||||
	properties = pw_properties_new(NULL, NULL);
 | 
			
		||||
	if (!properties)
 | 
			
		||||
		goto no_mem;
 | 
			
		||||
 | 
			
		||||
	pw_properties_update_keys(properties, &this->props->dict, keys);
 | 
			
		||||
 | 
			
		||||
	this->global = pw_global_new (context,
 | 
			
		||||
			PW_TYPE_INTERFACE_Session,
 | 
			
		||||
			PW_VERSION_SESSION,
 | 
			
		||||
			properties, session_bind, this);
 | 
			
		||||
			NULL, session_bind, this);
 | 
			
		||||
	if (!this->global)
 | 
			
		||||
		goto no_mem;
 | 
			
		||||
 | 
			
		||||
| 
						 | 
				
			
			@ -306,6 +300,8 @@ int session_init(struct session *this,
 | 
			
		|||
	this->info.id = pw_global_get_id(this->global);
 | 
			
		||||
	this->info.props = &this->props->dict;
 | 
			
		||||
 | 
			
		||||
	pw_global_update_keys(this->global, &this->props->dict, keys);
 | 
			
		||||
 | 
			
		||||
	pw_resource_set_bound_id(client_sess->resource, this->info.id);
 | 
			
		||||
 | 
			
		||||
	return pw_global_register(this->global);
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -437,13 +437,6 @@ int pw_impl_client_register(struct pw_impl_client *client,
 | 
			
		|||
 | 
			
		||||
	pw_log_debug(NAME" %p: register", client);
 | 
			
		||||
 | 
			
		||||
	if (properties == NULL)
 | 
			
		||||
		properties = pw_properties_new(NULL, NULL);
 | 
			
		||||
	if (properties == NULL)
 | 
			
		||||
		return -errno;
 | 
			
		||||
 | 
			
		||||
	pw_properties_update_keys(properties, &client->properties->dict, keys);
 | 
			
		||||
 | 
			
		||||
	client->global = pw_global_new(context,
 | 
			
		||||
				       PW_TYPE_INTERFACE_Client,
 | 
			
		||||
				       PW_VERSION_CLIENT,
 | 
			
		||||
| 
						 | 
				
			
			@ -460,6 +453,8 @@ int pw_impl_client_register(struct pw_impl_client *client,
 | 
			
		|||
	pw_properties_setf(client->properties, PW_KEY_OBJECT_ID, "%d", client->info.id);
 | 
			
		||||
	client->info.props = &client->properties->dict;
 | 
			
		||||
 | 
			
		||||
	pw_global_update_keys(client->global, client->info.props, keys);
 | 
			
		||||
 | 
			
		||||
	pw_impl_client_emit_initialized(client);
 | 
			
		||||
 | 
			
		||||
	pw_global_add_listener(client->global, &client->global_listener, &global_events, client);
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -564,13 +564,6 @@ int pw_impl_core_register(struct pw_impl_core *core,
 | 
			
		|||
	if (core->registered)
 | 
			
		||||
		goto error_existed;
 | 
			
		||||
 | 
			
		||||
	if (properties == NULL)
 | 
			
		||||
		properties = pw_properties_new(NULL, NULL);
 | 
			
		||||
	if (properties == NULL)
 | 
			
		||||
		return -errno;
 | 
			
		||||
 | 
			
		||||
	pw_properties_update_keys(properties, &core->properties->dict, keys);
 | 
			
		||||
 | 
			
		||||
        core->global = pw_global_new(context,
 | 
			
		||||
					PW_TYPE_INTERFACE_Core,
 | 
			
		||||
					PW_VERSION_CORE,
 | 
			
		||||
| 
						 | 
				
			
			@ -587,16 +580,18 @@ int pw_impl_core_register(struct pw_impl_core *core,
 | 
			
		|||
	pw_properties_setf(core->properties, PW_KEY_OBJECT_ID, "%d", core->info.id);
 | 
			
		||||
	core->info.props = &core->properties->dict;
 | 
			
		||||
 | 
			
		||||
	pw_global_update_keys(core->global, core->info.props, keys);
 | 
			
		||||
 | 
			
		||||
	pw_impl_core_emit_initialized(core);
 | 
			
		||||
 | 
			
		||||
	pw_global_add_listener(core->global, &core->global_listener, &global_events, core);
 | 
			
		||||
	pw_global_register(core->global);
 | 
			
		||||
 | 
			
		||||
	return 0;
 | 
			
		||||
 | 
			
		||||
error_existed:
 | 
			
		||||
	res = -EEXIST;
 | 
			
		||||
	goto error_exit;
 | 
			
		||||
 | 
			
		||||
error_exit:
 | 
			
		||||
	if (properties)
 | 
			
		||||
		pw_properties_free(properties);
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -479,13 +479,6 @@ int pw_impl_device_register(struct pw_impl_device *device,
 | 
			
		|||
	if (device->registered)
 | 
			
		||||
		goto error_existed;
 | 
			
		||||
 | 
			
		||||
	if (properties == NULL)
 | 
			
		||||
		properties = pw_properties_new(NULL, NULL);
 | 
			
		||||
	if (properties == NULL)
 | 
			
		||||
		return -errno;
 | 
			
		||||
 | 
			
		||||
	pw_properties_update_keys(properties, &device->properties->dict, keys);
 | 
			
		||||
 | 
			
		||||
        device->global = pw_global_new(context,
 | 
			
		||||
				       PW_TYPE_INTERFACE_Device,
 | 
			
		||||
				       PW_VERSION_DEVICE,
 | 
			
		||||
| 
						 | 
				
			
			@ -502,6 +495,8 @@ int pw_impl_device_register(struct pw_impl_device *device,
 | 
			
		|||
	pw_properties_setf(device->properties, PW_KEY_OBJECT_ID, "%d", device->info.id);
 | 
			
		||||
	device->info.props = &device->properties->dict;
 | 
			
		||||
 | 
			
		||||
	pw_global_update_keys(device->global, device->info.props, keys);
 | 
			
		||||
 | 
			
		||||
	pw_impl_device_emit_initialized(device);
 | 
			
		||||
 | 
			
		||||
	pw_global_add_listener(device->global, &device->global_listener, &global_events, device);
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -176,23 +176,15 @@ int pw_impl_factory_register(struct pw_impl_factory *factory,
 | 
			
		|||
	struct pw_context *context = factory->context;
 | 
			
		||||
	const char *keys[] = {
 | 
			
		||||
		PW_KEY_MODULE_ID,
 | 
			
		||||
		PW_KEY_FACTORY_NAME,
 | 
			
		||||
		PW_KEY_FACTORY_TYPE_NAME,
 | 
			
		||||
		PW_KEY_FACTORY_TYPE_VERSION,
 | 
			
		||||
		NULL
 | 
			
		||||
	};
 | 
			
		||||
 | 
			
		||||
	if (factory->registered)
 | 
			
		||||
		goto error_existed;
 | 
			
		||||
 | 
			
		||||
	if (properties == NULL)
 | 
			
		||||
		properties = pw_properties_new(NULL, NULL);
 | 
			
		||||
	if (properties == NULL)
 | 
			
		||||
		return -errno;
 | 
			
		||||
 | 
			
		||||
	pw_properties_update_keys(properties, &factory->properties->dict, keys);
 | 
			
		||||
 | 
			
		||||
	pw_properties_set(properties, PW_KEY_FACTORY_NAME, factory->info.name);
 | 
			
		||||
	pw_properties_setf(properties, PW_KEY_FACTORY_TYPE_NAME, "%s", factory->info.type);
 | 
			
		||||
	pw_properties_setf(properties, PW_KEY_FACTORY_TYPE_VERSION, "%d", factory->info.version);
 | 
			
		||||
 | 
			
		||||
        factory->global = pw_global_new(context,
 | 
			
		||||
					PW_TYPE_INTERFACE_Factory,
 | 
			
		||||
					PW_VERSION_FACTORY,
 | 
			
		||||
| 
						 | 
				
			
			@ -207,8 +199,13 @@ int pw_impl_factory_register(struct pw_impl_factory *factory,
 | 
			
		|||
 | 
			
		||||
	factory->info.id = factory->global->id;
 | 
			
		||||
	pw_properties_setf(factory->properties, PW_KEY_OBJECT_ID, "%d", factory->info.id);
 | 
			
		||||
	pw_properties_set(factory->properties, PW_KEY_FACTORY_NAME, factory->info.name);
 | 
			
		||||
	pw_properties_setf(factory->properties, PW_KEY_FACTORY_TYPE_NAME, "%s", factory->info.type);
 | 
			
		||||
	pw_properties_setf(factory->properties, PW_KEY_FACTORY_TYPE_VERSION, "%d", factory->info.version);
 | 
			
		||||
	factory->info.props = &factory->properties->dict;
 | 
			
		||||
 | 
			
		||||
	pw_global_update_keys(factory->global, factory->info.props, keys);
 | 
			
		||||
 | 
			
		||||
	pw_impl_factory_emit_initialized(factory);
 | 
			
		||||
 | 
			
		||||
	pw_global_add_listener(factory->global, &factory->global_listener, &global_events, factory);
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -1177,17 +1177,14 @@ int pw_impl_link_register(struct pw_impl_link *link,
 | 
			
		|||
		PW_KEY_MODULE_ID,
 | 
			
		||||
		PW_KEY_FACTORY_ID,
 | 
			
		||||
		PW_KEY_CLIENT_ID,
 | 
			
		||||
		PW_KEY_LINK_OUTPUT_PORT,
 | 
			
		||||
		PW_KEY_LINK_INPUT_PORT,
 | 
			
		||||
		NULL
 | 
			
		||||
	};
 | 
			
		||||
 | 
			
		||||
	if (link->registered)
 | 
			
		||||
		goto error_existed;
 | 
			
		||||
 | 
			
		||||
	if (properties == NULL)
 | 
			
		||||
		properties = pw_properties_new(NULL, NULL);
 | 
			
		||||
	if (properties == NULL)
 | 
			
		||||
		return -errno;
 | 
			
		||||
 | 
			
		||||
	output_node = link->output->node;
 | 
			
		||||
	input_node = link->input->node;
 | 
			
		||||
 | 
			
		||||
| 
						 | 
				
			
			@ -1196,11 +1193,6 @@ int pw_impl_link_register(struct pw_impl_link *link,
 | 
			
		|||
	link->info.input_node_id = input_node->global->id;
 | 
			
		||||
	link->info.input_port_id = link->input->global->id;
 | 
			
		||||
 | 
			
		||||
	pw_properties_update_keys(properties, &link->properties->dict, keys);
 | 
			
		||||
 | 
			
		||||
	pw_properties_setf(properties, PW_KEY_LINK_OUTPUT_PORT, "%d", link->info.output_port_id);
 | 
			
		||||
	pw_properties_setf(properties, PW_KEY_LINK_INPUT_PORT, "%d", link->info.input_port_id);
 | 
			
		||||
 | 
			
		||||
	link->global = pw_global_new(context,
 | 
			
		||||
				     PW_TYPE_INTERFACE_Link,
 | 
			
		||||
				     PW_VERSION_LINK,
 | 
			
		||||
| 
						 | 
				
			
			@ -1215,8 +1207,12 @@ int pw_impl_link_register(struct pw_impl_link *link,
 | 
			
		|||
 | 
			
		||||
	link->info.id = link->global->id;
 | 
			
		||||
	pw_properties_setf(link->properties, PW_KEY_OBJECT_ID, "%d", link->info.id);
 | 
			
		||||
	pw_properties_setf(link->properties, PW_KEY_LINK_OUTPUT_PORT, "%d", link->info.output_port_id);
 | 
			
		||||
	pw_properties_setf(link->properties, PW_KEY_LINK_INPUT_PORT, "%d", link->info.input_port_id);
 | 
			
		||||
	link->info.props = &link->properties->dict;
 | 
			
		||||
 | 
			
		||||
	pw_global_update_keys(link->global, link->info.props, keys);
 | 
			
		||||
 | 
			
		||||
	pw_impl_link_emit_initialized(link);
 | 
			
		||||
 | 
			
		||||
	pw_global_add_listener(link->global, &link->global_listener, &global_events, link);
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -634,13 +634,6 @@ int pw_impl_node_register(struct pw_impl_node *this,
 | 
			
		|||
	if (this->registered)
 | 
			
		||||
		goto error_existed;
 | 
			
		||||
 | 
			
		||||
	if (properties == NULL)
 | 
			
		||||
		properties = pw_properties_new(NULL, NULL);
 | 
			
		||||
	if (properties == NULL)
 | 
			
		||||
		return -errno;
 | 
			
		||||
 | 
			
		||||
	pw_properties_update_keys(properties, &this->properties->dict, keys);
 | 
			
		||||
 | 
			
		||||
	this->global = pw_global_new(context,
 | 
			
		||||
				     PW_TYPE_INTERFACE_Node,
 | 
			
		||||
				     PW_VERSION_NODE,
 | 
			
		||||
| 
						 | 
				
			
			@ -661,6 +654,8 @@ int pw_impl_node_register(struct pw_impl_node *this,
 | 
			
		|||
	pw_properties_setf(this->properties, PW_KEY_OBJECT_ID, "%d", this->info.id);
 | 
			
		||||
	this->info.props = &this->properties->dict;
 | 
			
		||||
 | 
			
		||||
	pw_global_update_keys(this->global, &this->properties->dict, keys);
 | 
			
		||||
 | 
			
		||||
	pw_impl_node_initialized(this);
 | 
			
		||||
 | 
			
		||||
	pw_global_add_listener(this->global, &this->global_listener, &global_events, this);
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -782,6 +782,7 @@ int pw_impl_port_register(struct pw_impl_port *port,
 | 
			
		|||
	const char *keys[] = {
 | 
			
		||||
		PW_KEY_OBJECT_PATH,
 | 
			
		||||
		PW_KEY_FORMAT_DSP,
 | 
			
		||||
		PW_KEY_NODE_ID,
 | 
			
		||||
		PW_KEY_AUDIO_CHANNEL,
 | 
			
		||||
		PW_KEY_PORT_NAME,
 | 
			
		||||
		PW_KEY_PORT_DIRECTION,
 | 
			
		||||
| 
						 | 
				
			
			@ -795,14 +796,6 @@ int pw_impl_port_register(struct pw_impl_port *port,
 | 
			
		|||
	if (node == NULL || node->global == NULL)
 | 
			
		||||
		return -EIO;
 | 
			
		||||
 | 
			
		||||
	if (properties == NULL)
 | 
			
		||||
		properties = pw_properties_new(NULL, NULL);
 | 
			
		||||
	if (properties == NULL)
 | 
			
		||||
		return -errno;
 | 
			
		||||
 | 
			
		||||
	pw_properties_setf(properties, PW_KEY_NODE_ID, "%d", node->global->id);
 | 
			
		||||
	pw_properties_update_keys(properties, &port->properties->dict, keys);
 | 
			
		||||
 | 
			
		||||
	port->global = pw_global_new(node->context,
 | 
			
		||||
				PW_TYPE_INTERFACE_Port,
 | 
			
		||||
				PW_VERSION_PORT,
 | 
			
		||||
| 
						 | 
				
			
			@ -819,6 +812,8 @@ int pw_impl_port_register(struct pw_impl_port *port,
 | 
			
		|||
	pw_properties_setf(port->properties, PW_KEY_OBJECT_ID, "%d", port->info.id);
 | 
			
		||||
	port->info.props = &port->properties->dict;
 | 
			
		||||
 | 
			
		||||
	pw_global_update_keys(port->global, &port->properties->dict, keys);
 | 
			
		||||
 | 
			
		||||
	pw_impl_port_emit_initialized(port);
 | 
			
		||||
 | 
			
		||||
	return pw_global_register(port->global);
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue