mirror of
				https://gitlab.freedesktop.org/pipewire/pipewire.git
				synced 2025-11-03 09:01:54 -05:00 
			
		
		
		
	interfaces: improve remote API
Add return values to events and method callbacks. This makes it possible to pass any error or async return value. Add sync/done/error in both directions so that both proxy and resource and perform/reply sync and produce errors. Return a SPA_ASYNC from remote method calls (and events), keep the sequence number in the connection. With the core sync/done we can remove the client-node done method and it's internal sequence number along with the seq number in method calls. We can also use the method/event async return value to perform a sync with as the unique sequence number for this method. Add sync method and done/error event to proxy and resource.
This commit is contained in:
		
							parent
							
								
									0d8821096a
								
							
						
					
					
						commit
						eea062ee53
					
				
					 41 changed files with 1180 additions and 817 deletions
				
			
		| 
						 | 
				
			
			@ -242,12 +242,13 @@ static bool do_load_module(struct data *data, const char *cmd, char *args, char
 | 
			
		|||
	return true;
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
static void on_core_info(void *_data, const struct pw_core_info *info)
 | 
			
		||||
static int on_core_info(void *_data, const struct pw_core_info *info)
 | 
			
		||||
{
 | 
			
		||||
	struct remote_data *rd = _data;
 | 
			
		||||
	free(rd->name);
 | 
			
		||||
	rd->name = strdup(info->name);
 | 
			
		||||
	fprintf(stdout, "remote %d is named '%s'\n", rd->id, rd->name);
 | 
			
		||||
	return 0;
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
static void show_prompt(struct remote_data *rd)
 | 
			
		||||
| 
						 | 
				
			
			@ -256,7 +257,7 @@ static void show_prompt(struct remote_data *rd)
 | 
			
		|||
	fflush(stdout);
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
static void on_core_done(void *_data, uint32_t seq)
 | 
			
		||||
static int on_core_done(void *_data, uint32_t id, uint32_t seq)
 | 
			
		||||
{
 | 
			
		||||
	struct remote_data *rd = _data;
 | 
			
		||||
 | 
			
		||||
| 
						 | 
				
			
			@ -267,6 +268,7 @@ static void on_core_done(void *_data, uint32_t seq)
 | 
			
		|||
	default:
 | 
			
		||||
		break;
 | 
			
		||||
	}
 | 
			
		||||
	return 0;
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
static int print_global(void *obj, void *data)
 | 
			
		||||
| 
						 | 
				
			
			@ -285,9 +287,9 @@ static int print_global(void *obj, void *data)
 | 
			
		|||
	return 0;
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
static void registry_event_global(void *data, uint32_t id, uint32_t parent_id,
 | 
			
		||||
				  uint32_t permissions, uint32_t type, uint32_t version,
 | 
			
		||||
				  const struct spa_dict *props)
 | 
			
		||||
static int registry_event_global(void *data, uint32_t id, uint32_t parent_id,
 | 
			
		||||
		uint32_t permissions, uint32_t type, uint32_t version,
 | 
			
		||||
		const struct spa_dict *props)
 | 
			
		||||
{
 | 
			
		||||
	struct remote_data *rd = data;
 | 
			
		||||
	struct global *global;
 | 
			
		||||
| 
						 | 
				
			
			@ -309,6 +311,7 @@ static void registry_event_global(void *data, uint32_t id, uint32_t parent_id,
 | 
			
		|||
	while (id > size)
 | 
			
		||||
		pw_map_insert_at(&rd->globals, size++, NULL);
 | 
			
		||||
	pw_map_insert_at(&rd->globals, id, global);
 | 
			
		||||
	return 0;
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
static int destroy_global(void *obj, void *data)
 | 
			
		||||
| 
						 | 
				
			
			@ -325,7 +328,7 @@ static int destroy_global(void *obj, void *data)
 | 
			
		|||
	return 0;
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
static void registry_event_global_remove(void *data, uint32_t id)
 | 
			
		||||
static int registry_event_global_remove(void *data, uint32_t id)
 | 
			
		||||
{
 | 
			
		||||
	struct remote_data *rd = data;
 | 
			
		||||
	struct global *global;
 | 
			
		||||
| 
						 | 
				
			
			@ -333,12 +336,13 @@ static void registry_event_global_remove(void *data, uint32_t id)
 | 
			
		|||
	global = pw_map_lookup(&rd->globals, id);
 | 
			
		||||
	if (global == NULL) {
 | 
			
		||||
		fprintf(stdout, "remote %d removed unknown global %d\n", rd->id, id);
 | 
			
		||||
		return;
 | 
			
		||||
		return -EINVAL;
 | 
			
		||||
	}
 | 
			
		||||
 | 
			
		||||
	fprintf(stdout, "remote %d removed global: ", rd->id);
 | 
			
		||||
	print_global(global, NULL);
 | 
			
		||||
	destroy_global(global, rd);
 | 
			
		||||
	return 0;
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
static const struct pw_registry_proxy_events registry_events = {
 | 
			
		||||
| 
						 | 
				
			
			@ -392,7 +396,7 @@ static void on_state_changed(void *_data, enum pw_remote_state old,
 | 
			
		|||
		pw_registry_proxy_add_listener(rd->registry_proxy,
 | 
			
		||||
					       &rd->registry_listener,
 | 
			
		||||
					       ®istry_events, rd);
 | 
			
		||||
		pw_core_proxy_sync(rd->core_proxy, 1);
 | 
			
		||||
		pw_core_proxy_sync(rd->core_proxy, 0, 1);
 | 
			
		||||
		break;
 | 
			
		||||
 | 
			
		||||
	default:
 | 
			
		||||
| 
						 | 
				
			
			@ -627,7 +631,7 @@ static void info_device(struct proxy_data *pd)
 | 
			
		|||
	info->change_mask = 0;
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
static void core_event_info(void *object, const struct pw_core_info *info)
 | 
			
		||||
static int core_event_info(void *object, const struct pw_core_info *info)
 | 
			
		||||
{
 | 
			
		||||
	struct proxy_data *pd = object;
 | 
			
		||||
	struct remote_data *rd = pd->rd;
 | 
			
		||||
| 
						 | 
				
			
			@ -640,6 +644,7 @@ static void core_event_info(void *object, const struct pw_core_info *info)
 | 
			
		|||
		info_core(pd);
 | 
			
		||||
		pd->global->info_pending = false;
 | 
			
		||||
	}
 | 
			
		||||
	return 0;
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
static const struct pw_core_proxy_events core_events = {
 | 
			
		||||
| 
						 | 
				
			
			@ -648,7 +653,7 @@ static const struct pw_core_proxy_events core_events = {
 | 
			
		|||
};
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
static void module_event_info(void *object, const struct pw_module_info *info)
 | 
			
		||||
static int module_event_info(void *object, const struct pw_module_info *info)
 | 
			
		||||
{
 | 
			
		||||
	struct proxy_data *pd = object;
 | 
			
		||||
	struct remote_data *rd = pd->rd;
 | 
			
		||||
| 
						 | 
				
			
			@ -661,6 +666,7 @@ static void module_event_info(void *object, const struct pw_module_info *info)
 | 
			
		|||
		info_module(pd);
 | 
			
		||||
		pd->global->info_pending = false;
 | 
			
		||||
	}
 | 
			
		||||
	return 0;
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
static const struct pw_module_proxy_events module_events = {
 | 
			
		||||
| 
						 | 
				
			
			@ -668,7 +674,7 @@ static const struct pw_module_proxy_events module_events = {
 | 
			
		|||
	.info = module_event_info
 | 
			
		||||
};
 | 
			
		||||
 | 
			
		||||
static void node_event_info(void *object, const struct pw_node_info *info)
 | 
			
		||||
static int node_event_info(void *object, const struct pw_node_info *info)
 | 
			
		||||
{
 | 
			
		||||
	struct proxy_data *pd = object;
 | 
			
		||||
	struct remote_data *rd = pd->rd;
 | 
			
		||||
| 
						 | 
				
			
			@ -681,9 +687,10 @@ static void node_event_info(void *object, const struct pw_node_info *info)
 | 
			
		|||
		info_node(pd);
 | 
			
		||||
		pd->global->info_pending = false;
 | 
			
		||||
	}
 | 
			
		||||
	return 0;
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
static void node_event_param(void *object, uint32_t id, uint32_t index, uint32_t next,
 | 
			
		||||
static int node_event_param(void *object, uint32_t id, uint32_t index, uint32_t next,
 | 
			
		||||
		const struct spa_pod *param)
 | 
			
		||||
{
 | 
			
		||||
        struct proxy_data *data = object;
 | 
			
		||||
| 
						 | 
				
			
			@ -696,6 +703,7 @@ static void node_event_param(void *object, uint32_t id, uint32_t index, uint32_t
 | 
			
		|||
		spa_debug_format(2, NULL, param);
 | 
			
		||||
	else
 | 
			
		||||
		spa_debug_pod(2, NULL, param);
 | 
			
		||||
	return 0;
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
static const struct pw_node_proxy_events node_events = {
 | 
			
		||||
| 
						 | 
				
			
			@ -705,7 +713,7 @@ static const struct pw_node_proxy_events node_events = {
 | 
			
		|||
};
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
static void port_event_info(void *object, const struct pw_port_info *info)
 | 
			
		||||
static int port_event_info(void *object, const struct pw_port_info *info)
 | 
			
		||||
{
 | 
			
		||||
	struct proxy_data *pd = object;
 | 
			
		||||
	struct remote_data *rd = pd->rd;
 | 
			
		||||
| 
						 | 
				
			
			@ -718,9 +726,10 @@ static void port_event_info(void *object, const struct pw_port_info *info)
 | 
			
		|||
		info_port(pd);
 | 
			
		||||
		pd->global->info_pending = false;
 | 
			
		||||
	}
 | 
			
		||||
	return 0;
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
static void port_event_param(void *object, uint32_t id, uint32_t index, uint32_t next,
 | 
			
		||||
static int port_event_param(void *object, uint32_t id, uint32_t index, uint32_t next,
 | 
			
		||||
		const struct spa_pod *param)
 | 
			
		||||
{
 | 
			
		||||
        struct proxy_data *data = object;
 | 
			
		||||
| 
						 | 
				
			
			@ -733,6 +742,7 @@ static void port_event_param(void *object, uint32_t id, uint32_t index, uint32_t
 | 
			
		|||
		spa_debug_format(2, NULL, param);
 | 
			
		||||
	else
 | 
			
		||||
		spa_debug_pod(2, NULL, param);
 | 
			
		||||
	return 0;
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
static const struct pw_port_proxy_events port_events = {
 | 
			
		||||
| 
						 | 
				
			
			@ -741,7 +751,7 @@ static const struct pw_port_proxy_events port_events = {
 | 
			
		|||
	.param = port_event_param
 | 
			
		||||
};
 | 
			
		||||
 | 
			
		||||
static void factory_event_info(void *object, const struct pw_factory_info *info)
 | 
			
		||||
static int factory_event_info(void *object, const struct pw_factory_info *info)
 | 
			
		||||
{
 | 
			
		||||
	struct proxy_data *pd = object;
 | 
			
		||||
	struct remote_data *rd = pd->rd;
 | 
			
		||||
| 
						 | 
				
			
			@ -754,6 +764,7 @@ static void factory_event_info(void *object, const struct pw_factory_info *info)
 | 
			
		|||
		info_factory(pd);
 | 
			
		||||
		pd->global->info_pending = false;
 | 
			
		||||
	}
 | 
			
		||||
	return 0;
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
static const struct pw_factory_proxy_events factory_events = {
 | 
			
		||||
| 
						 | 
				
			
			@ -761,7 +772,7 @@ static const struct pw_factory_proxy_events factory_events = {
 | 
			
		|||
	.info = factory_event_info
 | 
			
		||||
};
 | 
			
		||||
 | 
			
		||||
static void client_event_info(void *object, const struct pw_client_info *info)
 | 
			
		||||
static int client_event_info(void *object, const struct pw_client_info *info)
 | 
			
		||||
{
 | 
			
		||||
	struct proxy_data *pd = object;
 | 
			
		||||
	struct remote_data *rd = pd->rd;
 | 
			
		||||
| 
						 | 
				
			
			@ -774,9 +785,10 @@ static void client_event_info(void *object, const struct pw_client_info *info)
 | 
			
		|||
		info_client(pd);
 | 
			
		||||
		pd->global->info_pending = false;
 | 
			
		||||
	}
 | 
			
		||||
	return 0;
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
static void client_event_permissions(void *object, uint32_t index,
 | 
			
		||||
static int client_event_permissions(void *object, uint32_t index,
 | 
			
		||||
		uint32_t n_permissions, const struct pw_permission *permissions)
 | 
			
		||||
{
 | 
			
		||||
        struct proxy_data *data = object;
 | 
			
		||||
| 
						 | 
				
			
			@ -793,6 +805,7 @@ static void client_event_permissions(void *object, uint32_t index,
 | 
			
		|||
			fprintf(stdout, "  %u:", permissions[i].id);
 | 
			
		||||
		fprintf(stdout, " %08x\n", permissions[i].permissions);
 | 
			
		||||
	}
 | 
			
		||||
	return 0;
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
static const struct pw_client_proxy_events client_events = {
 | 
			
		||||
| 
						 | 
				
			
			@ -801,7 +814,7 @@ static const struct pw_client_proxy_events client_events = {
 | 
			
		|||
	.permissions = client_event_permissions
 | 
			
		||||
};
 | 
			
		||||
 | 
			
		||||
static void link_event_info(void *object, const struct pw_link_info *info)
 | 
			
		||||
static int link_event_info(void *object, const struct pw_link_info *info)
 | 
			
		||||
{
 | 
			
		||||
	struct proxy_data *pd = object;
 | 
			
		||||
	struct remote_data *rd = pd->rd;
 | 
			
		||||
| 
						 | 
				
			
			@ -814,6 +827,7 @@ static void link_event_info(void *object, const struct pw_link_info *info)
 | 
			
		|||
		info_link(pd);
 | 
			
		||||
		pd->global->info_pending = false;
 | 
			
		||||
	}
 | 
			
		||||
	return 0;
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
static const struct pw_link_proxy_events link_events = {
 | 
			
		||||
| 
						 | 
				
			
			@ -822,7 +836,7 @@ static const struct pw_link_proxy_events link_events = {
 | 
			
		|||
};
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
static void device_event_info(void *object, const struct pw_device_info *info)
 | 
			
		||||
static int device_event_info(void *object, const struct pw_device_info *info)
 | 
			
		||||
{
 | 
			
		||||
	struct proxy_data *pd = object;
 | 
			
		||||
	struct remote_data *rd = pd->rd;
 | 
			
		||||
| 
						 | 
				
			
			@ -835,6 +849,7 @@ static void device_event_info(void *object, const struct pw_device_info *info)
 | 
			
		|||
		info_device(pd);
 | 
			
		||||
		pd->global->info_pending = false;
 | 
			
		||||
	}
 | 
			
		||||
	return 0;
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
static const struct pw_device_proxy_events device_events = {
 | 
			
		||||
| 
						 | 
				
			
			@ -1375,7 +1390,7 @@ static void do_input(void *data, int fd, enum spa_io mask)
 | 
			
		|||
		if (d->current == NULL)
 | 
			
		||||
			pw_main_loop_quit(d->loop);
 | 
			
		||||
		else if (d->current->core_proxy)
 | 
			
		||||
			pw_core_proxy_sync(d->current->core_proxy, 1);
 | 
			
		||||
			pw_core_proxy_sync(d->current->core_proxy, 0, 1);
 | 
			
		||||
	}
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue