mirror of
				https://gitlab.freedesktop.org/pipewire/pipewire.git
				synced 2025-11-03 09:01:54 -05:00 
			
		
		
		
	pulse-server: add event to the implementation
Add events when a server is started and stopped
This commit is contained in:
		
							parent
							
								
									ab5fe8957b
								
							
						
					
					
						commit
						a11612bdad
					
				
					 3 changed files with 30 additions and 1 deletions
				
			
		| 
						 | 
				
			
			@ -36,6 +36,7 @@
 | 
			
		|||
#include <pipewire/private.h>
 | 
			
		||||
 | 
			
		||||
#include "format.h"
 | 
			
		||||
#include "server.h"
 | 
			
		||||
 | 
			
		||||
struct pw_loop;
 | 
			
		||||
struct pw_context;
 | 
			
		||||
| 
						 | 
				
			
			@ -72,6 +73,7 @@ struct impl {
 | 
			
		|||
 | 
			
		||||
	struct ratelimit rate_limit;
 | 
			
		||||
 | 
			
		||||
	struct spa_hook_list hooks;
 | 
			
		||||
	struct spa_list servers;
 | 
			
		||||
 | 
			
		||||
	struct pw_work_queue *work_queue;
 | 
			
		||||
| 
						 | 
				
			
			@ -85,6 +87,19 @@ struct impl {
 | 
			
		|||
	struct stats stat;
 | 
			
		||||
};
 | 
			
		||||
 | 
			
		||||
struct impl_events {
 | 
			
		||||
#define VERSION_IMPL_EVENTS	0
 | 
			
		||||
	uint32_t version;
 | 
			
		||||
 | 
			
		||||
	void (*server_started) (void *data, struct server *server);
 | 
			
		||||
 | 
			
		||||
	void (*server_stopped) (void *data, struct server *server);
 | 
			
		||||
};
 | 
			
		||||
 | 
			
		||||
void impl_add_listener(struct impl *impl,
 | 
			
		||||
		struct spa_hook *listener,
 | 
			
		||||
		const struct impl_events *events, void *data);
 | 
			
		||||
 | 
			
		||||
extern bool debug_messages;
 | 
			
		||||
 | 
			
		||||
void broadcast_subscribe_event(struct impl *impl, uint32_t mask, uint32_t event, uint32_t id);
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -5461,6 +5461,8 @@ static void impl_clear(struct impl *impl)
 | 
			
		|||
	pw_map_for_each(&impl->samples, impl_free_sample, impl);
 | 
			
		||||
	pw_map_clear(&impl->samples);
 | 
			
		||||
 | 
			
		||||
	spa_hook_list_clean(&impl->hooks);
 | 
			
		||||
 | 
			
		||||
#ifdef HAVE_DBUS
 | 
			
		||||
	if (impl->dbus_name) {
 | 
			
		||||
		dbus_release_name(impl->dbus_name);
 | 
			
		||||
| 
						 | 
				
			
			@ -5599,6 +5601,7 @@ struct pw_protocol_pulse *pw_protocol_pulse_new(struct pw_context *context,
 | 
			
		|||
 | 
			
		||||
	impl->work_queue = pw_context_get_work_queue(context);
 | 
			
		||||
 | 
			
		||||
	spa_hook_list_init(&impl->hooks);
 | 
			
		||||
	spa_list_init(&impl->servers);
 | 
			
		||||
	impl->rate_limit.interval = 2 * SPA_NSEC_PER_SEC;
 | 
			
		||||
	impl->rate_limit.burst = 1;
 | 
			
		||||
| 
						 | 
				
			
			@ -5650,6 +5653,13 @@ error_exit:
 | 
			
		|||
	return NULL;
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
void impl_add_listener(struct impl *impl,
 | 
			
		||||
		struct spa_hook *listener,
 | 
			
		||||
		const struct impl_events *events, void *data)
 | 
			
		||||
{
 | 
			
		||||
	spa_hook_list_append(&impl->hooks, listener, events, data);
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
void *pw_protocol_pulse_get_user_data(struct pw_protocol_pulse *pulse)
 | 
			
		||||
{
 | 
			
		||||
	return SPA_PTROFF(pulse, sizeof(struct impl), void);
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -899,7 +899,7 @@ static struct server *server_new(struct impl *impl)
 | 
			
		|||
 | 
			
		||||
static int server_start(struct server *server, const struct sockaddr_storage *addr)
 | 
			
		||||
{
 | 
			
		||||
	const struct impl * const impl = server->impl;
 | 
			
		||||
	struct impl * const impl = server->impl;
 | 
			
		||||
	int res = 0, fd;
 | 
			
		||||
 | 
			
		||||
	switch (addr->ss_family) {
 | 
			
		||||
| 
						 | 
				
			
			@ -924,6 +924,8 @@ static int server_start(struct server *server, const struct sockaddr_storage *ad
 | 
			
		|||
		res = -errno;
 | 
			
		||||
		pw_log_error("server %p: can't create server source: %m", impl);
 | 
			
		||||
	}
 | 
			
		||||
	if (res >= 0)
 | 
			
		||||
		spa_hook_list_call(&impl->hooks, struct impl_events, server_started, 0, server);
 | 
			
		||||
 | 
			
		||||
	return res;
 | 
			
		||||
}
 | 
			
		||||
| 
						 | 
				
			
			@ -1069,6 +1071,8 @@ void server_free(struct server *server)
 | 
			
		|||
		client_unref(c);
 | 
			
		||||
	}
 | 
			
		||||
 | 
			
		||||
	spa_hook_list_call(&impl->hooks, struct impl_events, server_stopped, 0, server);
 | 
			
		||||
 | 
			
		||||
	if (server->source)
 | 
			
		||||
		pw_loop_destroy_source(impl->loop, server->source);
 | 
			
		||||
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue