Move listeners to spa and rename to hooks

The listeners are generally useful in spa, move it there and rename
to hooks. Implement loop hooks with it.
Fix some cleanup issues in stream and remote
This commit is contained in:
Wim Taymans 2017-08-08 16:56:29 +02:00
parent 6b6b827a3b
commit 600055bd68
55 changed files with 428 additions and 383 deletions

View file

@ -33,7 +33,7 @@ struct impl {
struct pw_module *module;
struct pw_properties *properties;
struct pw_listener core_listener;
struct spa_hook core_listener;
struct spa_list node_list;
};
@ -43,10 +43,10 @@ struct node_info {
struct impl *impl;
struct pw_node *node;
struct pw_listener node_listener;
struct spa_hook node_listener;
struct pw_link *link;
struct pw_listener link_listener;
struct spa_hook link_listener;
};
static struct node_info *find_node_info(struct impl *impl, struct pw_node *node)
@ -63,8 +63,8 @@ static struct node_info *find_node_info(struct impl *impl, struct pw_node *node)
static void node_info_free(struct node_info *info)
{
spa_list_remove(&info->l);
pw_listener_remove(&info->node_listener);
pw_listener_remove(&info->link_listener);
spa_hook_remove(&info->node_listener);
spa_hook_remove(&info->link_listener);
free(info);
}
@ -117,7 +117,7 @@ link_destroy(void *data)
struct impl *impl = info->impl;
pw_log_debug("module %p: link %p destroyed", impl, link);
pw_listener_remove(&info->link_listener);
spa_hook_remove(&info->link_listener);
spa_list_init(&info->link_listener.link);
}
@ -310,7 +310,7 @@ static void module_destroy(struct impl *impl)
{
pw_log_debug("module %p: destroy", impl);
pw_listener_remove(&impl->core_listener);
spa_hook_remove(&impl->core_listener);
free(impl);
}
#endif

View file

@ -121,8 +121,8 @@ struct impl {
struct pw_client_node_transport *transport;
struct pw_listener node_listener;
struct pw_listener resource_listener;
struct spa_hook node_listener;
struct spa_hook resource_listener;
int fds[2];
int other_fds[2];
@ -1098,7 +1098,7 @@ static void node_free(void *data)
if (impl->transport)
pw_client_node_transport_destroy(impl->transport);
pw_listener_remove(&impl->node_listener);
spa_hook_remove(&impl->node_listener);
if (impl->fds[0] != -1)
close(impl->fds[0]);

View file

@ -42,7 +42,7 @@ struct impl {
DBusConnection *bus;
struct pw_listener core_listener;
struct spa_hook core_listener;
struct spa_list client_list;
@ -55,9 +55,9 @@ struct client_info {
struct pw_client *client;
bool is_sandboxed;
struct pw_resource *core_resource;
struct pw_listener core_override;
struct spa_hook core_override;
struct spa_list async_pending;
struct pw_listener client_listener;
struct spa_hook client_listener;
};
struct async_pending {
@ -138,7 +138,7 @@ static void client_info_free(struct client_info *cinfo)
spa_list_for_each_safe(p, tmp, &cinfo->async_pending, link)
free_pending(p);
pw_listener_remove(&cinfo->client_listener);
spa_hook_remove(&cinfo->client_listener);
spa_list_remove(&cinfo->link);
free(cinfo);
}

View file

@ -96,7 +96,7 @@ struct client {
struct impl *impl;
struct spa_list link;
struct pw_client *client;
struct pw_listener client_listener;
struct spa_hook client_listener;
int fd;
struct spa_source *source;
};

View file

@ -67,7 +67,7 @@ struct connection {
struct spa_source *source;
struct pw_protocol_native_connection *connection;
struct pw_listener conn_listener;
struct spa_hook conn_listener;
bool disconnecting;
bool flush_signaled;
@ -84,12 +84,12 @@ struct listener {
struct pw_loop *loop;
struct spa_source *source;
struct spa_loop_control_hooks hooks;
struct spa_hook hook;
};
struct client_data {
struct pw_client *client;
struct pw_listener client_listener;
struct spa_hook client_listener;
int fd;
struct spa_source *source;
struct pw_protocol_native_connection *connection;
@ -189,19 +189,6 @@ client_busy_changed(void *data, bool busy)
}
static void on_before_hook(const struct spa_loop_control_hooks *hooks)
{
struct listener *listener = SPA_CONTAINER_OF(hooks, struct listener, hooks);
struct pw_protocol_listener *this = &listener->this;
struct pw_client *client, *tmp;
struct client_data *data;
spa_list_for_each_safe(client, tmp, &this->client_list, protocol_link) {
data = client->user_data;
pw_protocol_native_connection_flush(data->connection);
}
}
static void
connection_data(struct spa_loop_utils *utils,
struct spa_source *source, int fd, enum spa_io mask, void *data)
@ -664,6 +651,24 @@ static void destroy_listener(struct pw_protocol_listener *listener)
free(l);
}
static void on_before_hook(void *_data)
{
struct listener *listener = _data;
struct pw_protocol_listener *this = &listener->this;
struct pw_client *client, *tmp;
struct client_data *data;
spa_list_for_each_safe(client, tmp, &this->client_list, protocol_link) {
data = client->user_data;
pw_protocol_native_connection_flush(data->connection);
}
}
static const struct spa_loop_control_hooks impl_hooks = {
SPA_VERSION_LOOP_CONTROL_HOOKS,
.before = on_before_hook,
};
static struct pw_protocol_listener *
impl_add_listener(struct pw_protocol *protocol,
struct pw_core *core,
@ -697,8 +702,7 @@ impl_add_listener(struct pw_protocol *protocol,
spa_list_insert(protocol->listener_list.prev, &this->link);
l->hooks.before = on_before_hook;
pw_loop_add_hooks(pw_core_get_main_loop(core), &l->hooks);
pw_loop_add_hook(pw_core_get_main_loop(core), &l->hook, &impl_hooks, l);
pw_log_info("protocol-native %p: Added listener %p", protocol, this);

View file

@ -203,7 +203,7 @@ struct pw_protocol_native_connection *pw_protocol_native_connection_new(int fd)
pw_log_debug("connection %p: new", this);
this->fd = fd;
pw_listener_list_init(&this->listener_list);
spa_hook_list_init(&this->listener_list);
impl->out.buffer_data = malloc(MAX_BUFFER_SIZE);
impl->out.buffer_maxsize = MAX_BUFFER_SIZE;
@ -235,7 +235,7 @@ void pw_protocol_native_connection_destroy(struct pw_protocol_native_connection
pw_log_debug("connection %p: destroy", conn);
pw_listener_list_emit(&conn->listener_list, struct pw_protocol_native_connection_events, destroy);
spa_hook_list_call(&conn->listener_list, struct pw_protocol_native_connection_events, destroy);
free(impl->out.buffer_data);
free(impl->in.buffer_data);
@ -430,7 +430,7 @@ pw_protocol_native_connection_end(struct pw_protocol_native_connection *conn,
printf(">>>>>>>>> out:\n");
spa_debug_pod((struct spa_pod *)p);
}
pw_listener_list_emit(&conn->listener_list, struct pw_protocol_native_connection_events, need_flush);
spa_hook_list_call(&conn->listener_list, struct pw_protocol_native_connection_events, need_flush);
}
/** Flush the connection object

View file

@ -25,7 +25,7 @@ extern "C" {
#endif
#include <spa/defs.h>
#include <pipewire/listener.h>
#include <spa/hook.h>
struct pw_protocol_native_connection_events {
#define PW_VERSION_PROTOCOL_NATIVE_CONNECTION_EVENTS 0
@ -44,16 +44,16 @@ struct pw_protocol_native_connection_events {
struct pw_protocol_native_connection {
int fd; /**< the socket */
struct pw_listener_list listener_list;
struct spa_hook_list listener_list;
};
static inline void
pw_protocol_native_connection_add_listener(struct pw_protocol_native_connection *conn,
struct pw_listener *listener,
struct spa_hook *listener,
const struct pw_protocol_native_connection_events *events,
void *data)
{
pw_listener_list_add(&conn->listener_list, listener, events, data);
spa_hook_list_append(&conn->listener_list, listener, events, data);
}
struct pw_protocol_native_connection *

View file

@ -31,7 +31,7 @@ struct impl {
struct pw_type *t;
struct pw_properties *properties;
struct pw_listener core_listener;
struct spa_hook core_listener;
struct spa_list node_list;
};
@ -40,7 +40,7 @@ struct node_info {
struct spa_list link;
struct impl *impl;
struct pw_node *node;
struct pw_listener node_listener;
struct spa_hook node_listener;
struct spa_source *idle_timeout;
};
@ -67,7 +67,7 @@ static void node_info_free(struct node_info *info)
{
spa_list_remove(&info->link);
remove_idle_timeout(info);
pw_listener_remove(&info->node_listener);
spa_hook_remove(&info->node_listener);
free(info);
}

View file

@ -43,7 +43,7 @@ struct impl {
char *lib;
char *factory_name;
struct pw_listener node_listener;
struct spa_hook node_listener;
};
struct port {
@ -337,7 +337,7 @@ static void on_node_done(void *data, int seq, int res)
}
pw_log_debug("spa-node %p: async complete event %d %d", this, seq, res);
pw_listener_list_emit(&this->listener_list, struct pw_node_events, async_complete, seq, res);
spa_hook_list_call(&this->listener_list, struct pw_node_events, async_complete, seq, res);
}
static void on_node_event(void *data, struct spa_event *event)
@ -345,21 +345,21 @@ static void on_node_event(void *data, struct spa_event *event)
struct impl *impl = data;
struct pw_node *this = impl->this;
pw_listener_list_emit(&this->listener_list, struct pw_node_events, event, event);
spa_hook_list_call(&this->listener_list, struct pw_node_events, event, event);
}
static void on_node_need_input(void *data)
{
struct impl *impl = data;
struct pw_node *this = impl->this;
pw_listener_list_emit(&this->listener_list, struct pw_node_events, need_input);
spa_hook_list_call(&this->listener_list, struct pw_node_events, need_input);
}
static void on_node_have_output(void *data)
{
struct impl *impl = data;
struct pw_node *this = impl->this;
pw_listener_list_emit(&this->listener_list, struct pw_node_events, have_output);
spa_hook_list_call(&this->listener_list, struct pw_node_events, have_output);
}
static void