Implement protocol extensions

Add hooks that contain protocol specific interfaces that can be used
to extend the protocol. This makes it possible to add new interfaces
to the protocol and implement the protocol specific data transport.
Move these protocol specific extension to the extensions directory.
This commit is contained in:
Wim Taymans 2017-07-12 18:04:00 +02:00
parent 267547c884
commit 465f12241e
43 changed files with 661 additions and 471 deletions

View file

@ -30,7 +30,7 @@
#include "module-client-node/client-node.h"
struct pw_protocol *pw_protocol_native_ext_client_node_init(void);
struct pw_protocol *pw_protocol_native_ext_client_node_init(struct pw_core *core);
struct impl {
struct pw_node_factory this;
@ -68,11 +68,11 @@ static struct impl *module_new(struct pw_core *core, struct pw_properties *prope
impl->this.core = core;
impl->this.name = "client-node";
impl->this.type = spa_type_map_get_id(core->type.map, PIPEWIRE_TYPE__ClientNode);
impl->this.type = spa_type_map_get_id(core->type.map, PW_TYPE__ClientNode);
pw_signal_init(&impl->this.destroy_signal);
impl->this.create_node = create_node;
pw_protocol_native_ext_client_node_init();
pw_protocol_native_ext_client_node_init(core);
spa_list_insert(core->node_factory_list.prev, &impl->this.link);

View file

@ -1150,7 +1150,7 @@ struct pw_client_node *pw_client_node_new(struct pw_resource *resource,
impl->fds[0] = impl->fds[1] = -1;
pw_log_debug("client-node %p: new", impl);
impl->type_client_node = spa_type_map_get_id(core->type.map, PIPEWIRE_TYPE__ClientNode);
impl->type_client_node = spa_type_map_get_id(core->type.map, PW_TYPE__ClientNode);
pw_signal_init(&this->destroy_signal);

View file

@ -25,9 +25,9 @@
#include "pipewire/interfaces.h"
#include "pipewire/protocol.h"
#include "pipewire/client.h"
#include "extensions/client-node.h"
#include "modules/module-protocol-native/connection.h"
#include "extensions/protocol-native.h"
#include "extensions/client-node.h"
/** \cond */
@ -39,17 +39,16 @@ static void
client_node_marshal_done(void *object, int seq, int res)
{
struct pw_proxy *proxy = object;
struct pw_connection *connection = proxy->remote->protocol_private;
struct spa_pod_builder *b;
struct spa_pod_frame f;
b = pw_connection_begin_write_proxy(connection, proxy, PW_CLIENT_NODE_METHOD_DONE);
b = pw_protocol_native_begin_proxy(proxy, PW_CLIENT_NODE_METHOD_DONE);
spa_pod_builder_struct(b, &f,
SPA_POD_TYPE_INT, seq,
SPA_POD_TYPE_INT, res);
pw_connection_end_write(connection, b);
pw_protocol_native_end_proxy(proxy, b);
}
@ -60,18 +59,17 @@ client_node_marshal_update(void *object,
uint32_t max_output_ports, const struct spa_props *props)
{
struct pw_proxy *proxy = object;
struct pw_connection *connection = proxy->remote->protocol_private;
struct spa_pod_builder *b;
struct spa_pod_frame f;
b = pw_connection_begin_write_proxy(connection, proxy, PW_CLIENT_NODE_METHOD_UPDATE);
b = pw_protocol_native_begin_proxy(proxy, PW_CLIENT_NODE_METHOD_UPDATE);
spa_pod_builder_struct(b, &f,
SPA_POD_TYPE_INT, change_mask,
SPA_POD_TYPE_INT, max_input_ports,
SPA_POD_TYPE_INT, max_output_ports, SPA_POD_TYPE_POD, props);
pw_connection_end_write(connection, b);
pw_protocol_native_end_proxy(proxy, b);
}
static void
@ -86,12 +84,11 @@ client_node_marshal_port_update(void *object,
const struct spa_param **params, const struct spa_port_info *info)
{
struct pw_proxy *proxy = object;
struct pw_connection *connection = proxy->remote->protocol_private;
struct spa_pod_builder *b;
struct spa_pod_frame f[2];
int i;
b = pw_connection_begin_write_proxy(connection, proxy, PW_CLIENT_NODE_METHOD_PORT_UPDATE);
b = pw_protocol_native_begin_proxy(proxy, PW_CLIENT_NODE_METHOD_PORT_UPDATE);
spa_pod_builder_add(b,
SPA_POD_TYPE_STRUCT, &f[0],
@ -119,35 +116,33 @@ client_node_marshal_port_update(void *object,
}
spa_pod_builder_add(b, -SPA_POD_TYPE_STRUCT, &f[0], 0);
pw_connection_end_write(connection, b);
pw_protocol_native_end_proxy(proxy, b);
}
static void client_node_marshal_event_method(void *object, struct spa_event *event)
{
struct pw_proxy *proxy = object;
struct pw_connection *connection = proxy->remote->protocol_private;
struct spa_pod_builder *b;
struct spa_pod_frame f;
b = pw_connection_begin_write_proxy(connection, proxy, PW_CLIENT_NODE_METHOD_EVENT);
b = pw_protocol_native_begin_proxy(proxy, PW_CLIENT_NODE_METHOD_EVENT);
spa_pod_builder_struct(b, &f, SPA_POD_TYPE_POD, event);
pw_connection_end_write(connection, b);
pw_protocol_native_end_proxy(proxy, b);
}
static void client_node_marshal_destroy(void *object)
{
struct pw_proxy *proxy = object;
struct pw_connection *connection = proxy->remote->protocol_private;
struct spa_pod_builder *b;
struct spa_pod_frame f;
b = pw_connection_begin_write_proxy(connection, proxy, PW_CLIENT_NODE_METHOD_DESTROY);
b = pw_protocol_native_begin_proxy(proxy, PW_CLIENT_NODE_METHOD_DESTROY);
spa_pod_builder_struct(b, &f, 0);
pw_connection_end_write(connection, b);
pw_protocol_native_end_proxy(proxy, b);
}
static bool client_node_demarshal_set_props(void *object, void *data, size_t size)
@ -264,7 +259,6 @@ static bool client_node_demarshal_add_mem(void *object, void *data, size_t size)
{
struct pw_proxy *proxy = object;
struct spa_pod_iter it;
struct pw_connection *connection = proxy->remote->protocol_private;
uint32_t direction, port_id, mem_id, type, memfd_idx, flags, offset, sz;
int memfd;
@ -280,7 +274,7 @@ static bool client_node_demarshal_add_mem(void *object, void *data, size_t size)
SPA_POD_TYPE_INT, &offset, SPA_POD_TYPE_INT, &sz, 0))
return false;
memfd = pw_connection_get_fd(connection, memfd_idx);
memfd = pw_protocol_native_get_proxy_fd(proxy, memfd_idx);
((struct pw_client_node_events *) proxy->implementation)->add_mem(proxy,
direction,
@ -396,7 +390,6 @@ static bool client_node_demarshal_transport(void *object, void *data, size_t siz
{
struct pw_proxy *proxy = object;
struct spa_pod_iter it;
struct pw_connection *connection = proxy->remote->protocol_private;
uint32_t node_id, ridx, widx, memfd_idx, offset, sz;
int readfd, writefd, memfd;
@ -410,9 +403,9 @@ static bool client_node_demarshal_transport(void *object, void *data, size_t siz
SPA_POD_TYPE_INT, &sz, 0))
return false;
readfd = pw_connection_get_fd(connection, ridx);
writefd = pw_connection_get_fd(connection, widx);
memfd = pw_connection_get_fd(connection, memfd_idx);
readfd = pw_protocol_native_get_proxy_fd(proxy, ridx);
writefd = pw_protocol_native_get_proxy_fd(proxy, widx);
memfd = pw_protocol_native_get_proxy_fd(proxy, memfd_idx);
if (readfd == -1 || writefd == -1 || memfd_idx == -1)
return false;
@ -426,31 +419,29 @@ static void
client_node_marshal_set_props(void *object, uint32_t seq, const struct spa_props *props)
{
struct pw_resource *resource = object;
struct pw_connection *connection = resource->client->protocol_private;
struct spa_pod_builder *b;
struct spa_pod_frame f;
b = pw_connection_begin_write_resource(connection, resource, PW_CLIENT_NODE_EVENT_SET_PROPS);
b = pw_protocol_native_begin_resource(resource, PW_CLIENT_NODE_EVENT_SET_PROPS);
spa_pod_builder_struct(b, &f,
SPA_POD_TYPE_INT, seq,
SPA_POD_TYPE_POD, props);
pw_connection_end_write(connection, b);
pw_protocol_native_end_resource(resource, b);
}
static void client_node_marshal_event_event(void *object, const struct spa_event *event)
{
struct pw_resource *resource = object;
struct pw_connection *connection = resource->client->protocol_private;
struct spa_pod_builder *b;
struct spa_pod_frame f;
b = pw_connection_begin_write_resource(connection, resource, PW_CLIENT_NODE_EVENT_EVENT);
b = pw_protocol_native_begin_resource(resource, PW_CLIENT_NODE_EVENT_EVENT);
spa_pod_builder_struct(b, &f, SPA_POD_TYPE_POD, event);
pw_connection_end_write(connection, b);
pw_protocol_native_end_resource(resource, b);
}
static void
@ -458,17 +449,16 @@ client_node_marshal_add_port(void *object,
uint32_t seq, enum spa_direction direction, uint32_t port_id)
{
struct pw_resource *resource = object;
struct pw_connection *connection = resource->client->protocol_private;
struct spa_pod_builder *b;
struct spa_pod_frame f;
b = pw_connection_begin_write_resource(connection, resource, PW_CLIENT_NODE_EVENT_ADD_PORT);
b = pw_protocol_native_begin_resource(resource, PW_CLIENT_NODE_EVENT_ADD_PORT);
spa_pod_builder_struct(b, &f,
SPA_POD_TYPE_INT, seq,
SPA_POD_TYPE_INT, direction, SPA_POD_TYPE_INT, port_id);
pw_connection_end_write(connection, b);
pw_protocol_native_end_resource(resource, b);
}
static void
@ -476,17 +466,16 @@ client_node_marshal_remove_port(void *object,
uint32_t seq, enum spa_direction direction, uint32_t port_id)
{
struct pw_resource *resource = object;
struct pw_connection *connection = resource->client->protocol_private;
struct spa_pod_builder *b;
struct spa_pod_frame f;
b = pw_connection_begin_write_resource(connection, resource, PW_CLIENT_NODE_EVENT_REMOVE_PORT);
b = pw_protocol_native_begin_resource(resource, PW_CLIENT_NODE_EVENT_REMOVE_PORT);
spa_pod_builder_struct(b, &f,
SPA_POD_TYPE_INT, seq,
SPA_POD_TYPE_INT, direction, SPA_POD_TYPE_INT, port_id);
pw_connection_end_write(connection, b);
pw_protocol_native_end_resource(resource, b);
}
static void
@ -498,11 +487,10 @@ client_node_marshal_set_format(void *object,
const struct spa_format *format)
{
struct pw_resource *resource = object;
struct pw_connection *connection = resource->client->protocol_private;
struct spa_pod_builder *b;
struct spa_pod_frame f;
b = pw_connection_begin_write_resource(connection, resource, PW_CLIENT_NODE_EVENT_SET_FORMAT);
b = pw_protocol_native_begin_resource(resource, PW_CLIENT_NODE_EVENT_SET_FORMAT);
spa_pod_builder_struct(b, &f,
SPA_POD_TYPE_INT, seq,
@ -511,7 +499,7 @@ client_node_marshal_set_format(void *object,
SPA_POD_TYPE_INT, flags,
SPA_POD_TYPE_POD, format);
pw_connection_end_write(connection, b);
pw_protocol_native_end_resource(resource, b);
}
static void
@ -522,11 +510,10 @@ client_node_marshal_set_param(void *object,
const struct spa_param *param)
{
struct pw_resource *resource = object;
struct pw_connection *connection = resource->client->protocol_private;
struct spa_pod_builder *b;
struct spa_pod_frame f;
b = pw_connection_begin_write_resource(connection, resource, PW_CLIENT_NODE_EVENT_SET_PARAM);
b = pw_protocol_native_begin_resource(resource, PW_CLIENT_NODE_EVENT_SET_PARAM);
spa_pod_builder_struct(b, &f,
SPA_POD_TYPE_INT, seq,
@ -534,7 +521,7 @@ client_node_marshal_set_param(void *object,
SPA_POD_TYPE_INT, port_id,
SPA_POD_TYPE_POD, param);
pw_connection_end_write(connection, b);
pw_protocol_native_end_resource(resource, b);
}
static void
@ -546,22 +533,21 @@ client_node_marshal_add_mem(void *object,
int memfd, uint32_t flags, uint32_t offset, uint32_t size)
{
struct pw_resource *resource = object;
struct pw_connection *connection = resource->client->protocol_private;
struct spa_pod_builder *b;
struct spa_pod_frame f;
b = pw_connection_begin_write_resource(connection, resource, PW_CLIENT_NODE_EVENT_ADD_MEM);
b = pw_protocol_native_begin_resource(resource, PW_CLIENT_NODE_EVENT_ADD_MEM);
spa_pod_builder_struct(b, &f,
SPA_POD_TYPE_INT, direction,
SPA_POD_TYPE_INT, port_id,
SPA_POD_TYPE_INT, mem_id,
SPA_POD_TYPE_ID, type,
SPA_POD_TYPE_INT, pw_connection_add_fd(connection, memfd),
SPA_POD_TYPE_INT, pw_protocol_native_add_resource_fd(resource, memfd),
SPA_POD_TYPE_INT, flags,
SPA_POD_TYPE_INT, offset, SPA_POD_TYPE_INT, size);
pw_connection_end_write(connection, b);
pw_protocol_native_end_resource(resource, b);
}
static void
@ -572,12 +558,11 @@ client_node_marshal_use_buffers(void *object,
uint32_t n_buffers, struct pw_client_node_buffer *buffers)
{
struct pw_resource *resource = object;
struct pw_connection *connection = resource->client->protocol_private;
struct spa_pod_builder *b;
struct spa_pod_frame f;
uint32_t i, j;
b = pw_connection_begin_write_resource(connection, resource, PW_CLIENT_NODE_EVENT_USE_BUFFERS);
b = pw_protocol_native_begin_resource(resource, PW_CLIENT_NODE_EVENT_USE_BUFFERS);
spa_pod_builder_add(b,
SPA_POD_TYPE_STRUCT, &f,
@ -612,22 +597,21 @@ client_node_marshal_use_buffers(void *object,
}
spa_pod_builder_add(b, -SPA_POD_TYPE_STRUCT, &f, 0);
pw_connection_end_write(connection, b);
pw_protocol_native_end_resource(resource, b);
}
static void
client_node_marshal_node_command(void *object, uint32_t seq, const struct spa_command *command)
{
struct pw_resource *resource = object;
struct pw_connection *connection = resource->client->protocol_private;
struct spa_pod_builder *b;
struct spa_pod_frame f;
b = pw_connection_begin_write_resource(connection, resource, PW_CLIENT_NODE_EVENT_NODE_COMMAND);
b = pw_protocol_native_begin_resource(resource, PW_CLIENT_NODE_EVENT_NODE_COMMAND);
spa_pod_builder_struct(b, &f, SPA_POD_TYPE_INT, seq, SPA_POD_TYPE_POD, command);
pw_connection_end_write(connection, b);
pw_protocol_native_end_resource(resource, b);
}
static void
@ -637,38 +621,36 @@ client_node_marshal_port_command(void *object,
const struct spa_command *command)
{
struct pw_resource *resource = object;
struct pw_connection *connection = resource->client->protocol_private;
struct spa_pod_builder *b;
struct spa_pod_frame f;
b = pw_connection_begin_write_resource(connection, resource, PW_CLIENT_NODE_EVENT_PORT_COMMAND);
b = pw_protocol_native_begin_resource(resource, PW_CLIENT_NODE_EVENT_PORT_COMMAND);
spa_pod_builder_struct(b, &f,
SPA_POD_TYPE_INT, direction,
SPA_POD_TYPE_INT, port_id,
SPA_POD_TYPE_POD, command);
pw_connection_end_write(connection, b);
pw_protocol_native_end_resource(resource, b);
}
static void client_node_marshal_transport(void *object, uint32_t node_id, int readfd, int writefd,
int memfd, uint32_t offset, uint32_t size)
{
struct pw_resource *resource = object;
struct pw_connection *connection = resource->client->protocol_private;
struct spa_pod_builder *b;
struct spa_pod_frame f;
b = pw_connection_begin_write_resource(connection, resource, PW_CLIENT_NODE_EVENT_TRANSPORT);
b = pw_protocol_native_begin_resource(resource, PW_CLIENT_NODE_EVENT_TRANSPORT);
spa_pod_builder_struct(b, &f,
SPA_POD_TYPE_INT, node_id,
SPA_POD_TYPE_INT, pw_connection_add_fd(connection, readfd),
SPA_POD_TYPE_INT, pw_connection_add_fd(connection, writefd),
SPA_POD_TYPE_INT, pw_connection_add_fd(connection, memfd),
SPA_POD_TYPE_INT, pw_protocol_native_add_resource_fd(resource, readfd),
SPA_POD_TYPE_INT, pw_protocol_native_add_resource_fd(resource, writefd),
SPA_POD_TYPE_INT, pw_protocol_native_add_resource_fd(resource, memfd),
SPA_POD_TYPE_INT, offset, SPA_POD_TYPE_INT, size);
pw_connection_end_write(connection, b);
pw_protocol_native_end_resource(resource, b);
}
@ -818,7 +800,7 @@ static const demarshal_func_t pw_protocol_native_client_client_node_demarshal[]
};
static const struct pw_interface pw_protocol_native_client_client_node_interface = {
PIPEWIRE_TYPE_NODE_BASE "Client",
PW_TYPE__ClientNode,
PW_VERSION_CLIENT_NODE,
PW_CLIENT_NODE_METHOD_NUM, &pw_protocol_native_client_client_node_methods,
PW_CLIENT_NODE_EVENT_NUM, pw_protocol_native_client_client_node_demarshal,
@ -847,27 +829,24 @@ static const struct pw_client_node_events pw_protocol_native_server_client_node_
};
const struct pw_interface pw_protocol_native_server_client_node_interface = {
PIPEWIRE_TYPE_NODE_BASE "Client",
PW_TYPE__ClientNode,
PW_VERSION_CLIENT_NODE,
PW_CLIENT_NODE_METHOD_NUM, &pw_protocol_native_server_client_node_demarshal,
PW_CLIENT_NODE_EVENT_NUM, &pw_protocol_native_server_client_node_events,
};
struct pw_protocol *pw_protocol_native_ext_client_node_init(void)
struct pw_protocol *pw_protocol_native_ext_client_node_init(struct pw_core *core)
{
static bool init = false;
struct pw_protocol *protocol;
protocol = pw_protocol_get(PW_TYPE_PROTOCOL__Native);
protocol = pw_core_find_protocol(core, PW_TYPE_PROTOCOL__Native);
if (init)
return protocol;
if (protocol == NULL)
return NULL;
pw_protocol_add_interfaces(protocol,
&pw_protocol_native_client_client_node_interface,
&pw_protocol_native_server_client_node_interface);
init = true;
return protocol;
}

View file

@ -42,6 +42,7 @@
#include "pipewire/data-loop.h"
#include "pipewire/main-loop.h"
#include "extensions/protocol-native.h"
#include "modules/module-protocol-native/connection.h"
#ifndef UNIX_PATH_MAX
@ -51,7 +52,7 @@
#define LOCK_SUFFIX ".lock"
#define LOCK_SUFFIXLEN 5
struct pw_protocol *pw_protocol_native_init(void);
void pw_protocol_native_init(struct pw_protocol *protocol);
typedef bool(*demarshal_func_t) (void *object, void *data, size_t size);
@ -61,7 +62,7 @@ struct connection {
int fd;
struct spa_source *source;
struct pw_connection *connection;
struct pw_protocol_native_connection *connection;
bool disconnecting;
struct pw_listener need_flush;
@ -78,79 +79,57 @@ struct listener {
struct pw_loop *loop;
struct spa_source *source;
};
struct impl {
struct pw_core *core;
struct spa_list link;
struct pw_protocol *protocol;
struct pw_properties *properties;
struct spa_list client_list;
struct spa_loop_control_hooks hooks;
};
struct native_client {
struct impl *impl;
struct spa_list link;
struct pw_client *client;
struct protocol_data {
void *unused;
};
struct client_data {
int fd;
struct spa_source *source;
struct pw_connection *connection;
struct pw_protocol_native_connection *connection;
struct pw_listener busy_changed;
};
static void client_destroy(void *data)
{
struct pw_client *client = data;
struct native_client *this = client->user_data;
pw_loop_destroy_source(this->impl->core->main_loop, this->source);
spa_list_remove(&this->link);
pw_connection_destroy(this->connection);
close(this->fd);
}
static void
process_messages(struct native_client *client)
process_messages(struct pw_client *client)
{
struct pw_connection *conn = client->connection;
struct client_data *data = client->user_data;
struct pw_protocol_native_connection *conn = data->connection;
uint8_t opcode;
uint32_t id;
uint32_t size;
struct pw_client *c = client->client;
void *message;
while (pw_connection_get_next(conn, &opcode, &id, &message, &size)) {
while (pw_protocol_native_connection_get_next(conn, &opcode, &id, &message, &size)) {
struct pw_resource *resource;
const demarshal_func_t *demarshal;
pw_log_trace("protocol-native %p: got message %d from %u", client->impl,
pw_log_trace("protocol-native %p: got message %d from %u", client->protocol,
opcode, id);
resource = pw_map_lookup(&c->objects, id);
resource = pw_map_lookup(&client->objects, id);
if (resource == NULL) {
pw_log_error("protocol-native %p: unknown resource %u",
client->impl, id);
client->protocol, id);
continue;
}
if (opcode >= resource->iface->n_methods) {
pw_log_error("protocol-native %p: invalid method %u %u", client->impl,
pw_log_error("protocol-native %p: invalid method %u %u", client->protocol,
id, opcode);
pw_client_destroy(c);
pw_client_destroy(client);
break;
}
demarshal = resource->iface->methods;
if (!demarshal[opcode] || !demarshal[opcode] (resource, message, size)) {
pw_log_error("protocol-native %p: invalid message received %u %u",
client->impl, id, opcode);
pw_client_destroy(c);
client->protocol, id, opcode);
pw_client_destroy(client);
break;
}
if (c->busy) {
if (client->busy) {
break;
}
}
@ -160,37 +139,41 @@ static void
on_busy_changed(struct pw_listener *listener,
struct pw_client *client)
{
struct native_client *c = SPA_CONTAINER_OF(listener, struct native_client, busy_changed);
struct client_data *data = SPA_CONTAINER_OF(listener, struct client_data, busy_changed);
enum spa_io mask = SPA_IO_ERR | SPA_IO_HUP;
if (!client->busy)
mask |= SPA_IO_IN;
pw_loop_update_io(c->impl->core->main_loop, c->source, mask);
pw_loop_update_io(client->core->main_loop, data->source, mask);
if (!client->busy)
process_messages(c);
process_messages(client);
}
static void on_before_hook(const struct spa_loop_control_hooks *hooks)
{
struct impl *this = SPA_CONTAINER_OF(hooks, struct impl, hooks);
struct native_client *client, *tmp;
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, link)
pw_connection_flush(client->connection);
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)
{
struct native_client *client = data;
struct pw_client *client = data;
if (mask & (SPA_IO_ERR | SPA_IO_HUP)) {
pw_log_error("protocol-native %p: got connection error", client->impl);
pw_client_destroy(client->client);
pw_log_error("protocol-native %p: got connection error", client->protocol);
pw_client_destroy(client);
return;
}
@ -198,10 +181,23 @@ connection_data(struct spa_loop_utils *utils,
process_messages(client);
}
static struct native_client *client_new(struct impl *impl, int fd)
static void client_destroy(void *data)
{
struct native_client *this;
struct pw_client *client = data;
struct client_data *this = client->user_data;
pw_loop_destroy_source(client->protocol->core->main_loop, this->source);
spa_list_remove(&client->protocol_link);
pw_protocol_native_connection_destroy(this->connection);
close(this->fd);
}
static struct pw_client *client_new(struct listener *l, int fd)
{
struct client_data *this;
struct pw_client *client;
struct pw_protocol *protocol = l->this.protocol;
socklen_t len;
struct ucred ucred, *ucredp;
@ -213,61 +209,41 @@ static struct native_client *client_new(struct impl *impl, int fd)
ucredp = &ucred;
}
client = pw_client_new(impl->core, ucredp, NULL, sizeof(struct native_client));
client = pw_client_new(protocol->core, ucredp, NULL, sizeof(struct client_data));
if (client == NULL)
goto no_client;
client->destroy = client_destroy;
this = client->user_data;
this->impl = impl;
this->fd = fd;
this->source = pw_loop_add_io(impl->core->main_loop,
this->source = pw_loop_add_io(protocol->core->main_loop,
this->fd,
SPA_IO_ERR | SPA_IO_HUP, false, connection_data, this);
SPA_IO_ERR | SPA_IO_HUP, false, connection_data, client);
if (this->source == NULL)
goto no_source;
this->connection = pw_connection_new(fd);
this->connection = pw_protocol_native_connection_new(fd);
if (this->connection == NULL)
goto no_connection;
client->protocol = impl->protocol;
client->protocol_private = this->connection;
this->client = client;
spa_list_insert(impl->client_list.prev, &this->link);
client->protocol = protocol;
spa_list_insert(l->this.client_list.prev, &client->protocol_link);
pw_signal_add(&client->busy_changed, &this->busy_changed, on_busy_changed);
pw_global_bind(impl->core->global, client, 0, 0);
pw_global_bind(protocol->core->global, client, PW_VERSION_CORE, 0);
return this;
return client;
no_connection:
pw_loop_destroy_source(impl->core->main_loop, this->source);
pw_loop_destroy_source(protocol->core->main_loop, this->source);
no_source:
free(this);
pw_client_destroy(client);
no_client:
return NULL;
}
static void destroy_listener(struct listener *l)
{
if (l->source)
pw_loop_destroy_source(l->loop, l->source);
if (l->addr.sun_path[0])
unlink(l->addr.sun_path);
if (l->fd >= 0)
close(l->fd);
if (l->lock_addr[0])
unlink(l->lock_addr);
if (l->fd_lock >= 0)
close(l->fd_lock);
free(l);
}
static bool init_socket_name(struct listener *l, const char *name)
{
int name_size;
@ -334,8 +310,9 @@ static void
socket_data(struct spa_loop_utils *utils,
struct spa_source *source, int fd, enum spa_io mask, void *data)
{
struct impl *impl = data;
struct native_client *client;
struct listener *l = data;
struct pw_client *client;
struct client_data *c;
struct sockaddr_un name;
socklen_t length;
int client_fd;
@ -347,18 +324,19 @@ socket_data(struct spa_loop_utils *utils,
return;
}
client = client_new(impl, client_fd);
client = client_new(l, client_fd);
if (client == NULL) {
pw_log_error("failed to create client");
close(client_fd);
return;
}
c = client->user_data;
pw_loop_update_io(impl->core->main_loop,
client->source, SPA_IO_IN | SPA_IO_ERR | SPA_IO_HUP);
pw_loop_update_io(client->protocol->core->main_loop,
c->source, SPA_IO_IN | SPA_IO_ERR | SPA_IO_HUP);
}
static bool add_socket(struct impl *impl, struct listener *l)
static bool add_socket(struct pw_protocol *protocol, struct listener *l)
{
socklen_t size;
@ -376,8 +354,8 @@ static bool add_socket(struct impl *impl, struct listener *l)
return false;
}
l->loop = impl->core->main_loop;
l->source = pw_loop_add_io(l->loop, l->fd, SPA_IO_IN, false, socket_data, impl);
l->loop = protocol->core->main_loop;
l->source = pw_loop_add_io(l->loop, l->fd, SPA_IO_IN, false, socket_data, l);
if (l->source == NULL)
return false;
@ -441,11 +419,11 @@ static int impl_connect(struct pw_protocol_connection *conn)
static void
on_remote_data(struct spa_loop_utils *utils,
struct spa_source *source, int fd, enum spa_io mask, void *data)
struct spa_source *source, int fd, enum spa_io mask, void *data)
{
struct connection *impl = data;
struct pw_remote *this = impl->this.remote;
struct pw_connection *conn = impl->connection;
struct pw_protocol_native_connection *conn = impl->connection;
if (mask & (SPA_IO_ERR | SPA_IO_HUP)) {
pw_log_error("protocol-native %p: got connection error", impl);
@ -460,7 +438,7 @@ on_remote_data(struct spa_loop_utils *utils,
void *message;
while (!impl->disconnecting
&& pw_connection_get_next(conn, &opcode, &id, &message, &size)) {
&& pw_protocol_native_connection_get_next(conn, &opcode, &id, &message, &size)) {
struct pw_proxy *proxy;
const demarshal_func_t *demarshal;
@ -496,11 +474,11 @@ static void do_flush_event(struct spa_loop_utils *utils, struct spa_source *sour
{
struct connection *impl = data;
if (impl->connection)
if (!pw_connection_flush(impl->connection))
if (!pw_protocol_native_connection_flush(impl->connection))
impl->this.disconnect(&impl->this);
}
static void on_need_flush(struct pw_listener *listener, struct pw_connection *connection)
static void on_need_flush(struct pw_listener *listener, struct pw_protocol_native_connection *connection)
{
struct connection *impl = SPA_CONTAINER_OF(listener, struct connection, need_flush);
struct pw_remote *remote = impl->this.remote;
@ -510,14 +488,12 @@ static void on_need_flush(struct pw_listener *listener, struct pw_connection *co
static int impl_connect_fd(struct pw_protocol_connection *conn, int fd)
{
struct connection *impl = SPA_CONTAINER_OF(conn, struct connection, this);
struct pw_remote *remote = impl->this.remote;
struct pw_remote *remote = conn->remote;
impl->connection = pw_connection_new(fd);
impl->connection = pw_protocol_native_connection_new(fd);
if (impl->connection == NULL)
goto error_close;
conn->remote->protocol_private = impl->connection;
pw_signal_add(&impl->connection->need_flush, &impl->need_flush, on_need_flush);
impl->fd = fd;
@ -533,10 +509,10 @@ static int impl_connect_fd(struct pw_protocol_connection *conn, int fd)
return -1;
}
static int impl_disconnect(struct pw_protocol_connection *conn)
static void impl_disconnect(struct pw_protocol_connection *conn)
{
struct connection *impl = SPA_CONTAINER_OF(conn, struct connection, this);
struct pw_remote *remote = impl->this.remote;
struct pw_remote *remote = conn->remote;
impl->disconnecting = true;
@ -545,17 +521,15 @@ static int impl_disconnect(struct pw_protocol_connection *conn)
impl->source = NULL;
if (impl->connection)
pw_connection_destroy(impl->connection);
pw_protocol_native_connection_destroy(impl->connection);
impl->connection = NULL;
if (impl->fd != -1)
close(impl->fd);
impl->fd = -1;
return 0;
}
static int impl_destroy(struct pw_protocol_connection *conn)
static void impl_destroy(struct pw_protocol_connection *conn)
{
struct connection *impl = SPA_CONTAINER_OF(conn, struct connection, this);
struct pw_remote *remote = conn->remote;
@ -564,8 +538,6 @@ static int impl_destroy(struct pw_protocol_connection *conn)
spa_list_remove(&conn->link);
free(impl);
return 0;
}
static struct pw_protocol_connection *
@ -573,14 +545,14 @@ impl_new_connection(struct pw_protocol *protocol,
struct pw_remote *remote,
struct pw_properties *properties)
{
struct impl *impl = protocol->protocol_private;
struct connection *c;
struct connection *impl;
struct pw_protocol_connection *this;
if ((c = calloc(1, sizeof(struct connection))) == NULL)
if ((impl = calloc(1, sizeof(struct connection))) == NULL)
return NULL;
this = &c->this;
this = &impl->this;
this->protocol = protocol;
this->remote = remote;
this->connect = impl_connect;
@ -588,19 +560,36 @@ impl_new_connection(struct pw_protocol *protocol,
this->disconnect = impl_disconnect;
this->destroy = impl_destroy;
c->flush_event = pw_loop_add_event(remote->core->main_loop, do_flush_event, c);
impl->flush_event = pw_loop_add_event(remote->core->main_loop, do_flush_event, impl);
spa_list_insert(impl->protocol->connection_list.prev, &c->this.link);
spa_list_insert(protocol->connection_list.prev, &this->link);
return this;
}
static void destroy_listener(struct pw_protocol_listener *listener)
{
struct listener *l = SPA_CONTAINER_OF(listener, struct listener, this);
if (l->source)
pw_loop_destroy_source(l->loop, l->source);
if (l->addr.sun_path[0])
unlink(l->addr.sun_path);
if (l->fd >= 0)
close(l->fd);
if (l->lock_addr[0])
unlink(l->lock_addr);
if (l->fd_lock >= 0)
close(l->fd_lock);
free(l);
}
static struct pw_protocol_listener *
impl_add_listener(struct pw_protocol *protocol,
struct pw_core *core,
struct pw_properties *properties)
{
struct impl *impl = protocol->protocol_private;
struct pw_protocol_listener *this;
struct listener *l;
const char *name;
@ -610,6 +599,11 @@ impl_add_listener(struct pw_protocol *protocol,
l->fd = -1;
l->fd_lock = -1;
this = &l->this;
this->protocol = protocol;
spa_list_init(&this->client_list);
this->destroy = destroy_listener;
name = get_name(core->properties);
if (!init_socket_name(l, name))
@ -618,46 +612,113 @@ impl_add_listener(struct pw_protocol *protocol,
if (!lock_socket(l))
goto error;
if (!add_socket(impl, l))
if (!add_socket(protocol, l))
goto error;
spa_list_insert(impl->protocol->listener_list.prev, &l->this.link);
spa_list_insert(protocol->listener_list.prev, &this->link);
impl->hooks.before = on_before_hook;
pw_loop_add_hooks(impl->core->main_loop, &impl->hooks);
l->hooks.before = on_before_hook;
pw_loop_add_hooks(protocol->core->main_loop, &l->hooks);
pw_log_info("protocol-native %p: Added listener", protocol);
pw_log_info("protocol-native %p: Added listener %p", protocol, this);
return &l->this;
return this;
error:
destroy_listener(l);
destroy_listener(this);
return NULL;
}
const static struct pw_protocol_implementaton protocol_impl = {
PW_VERSION_PROTOCOL_IMPLEMENTATION,
impl_new_connection,
impl_add_listener,
};
static struct impl *pw_protocol_native_new(struct pw_core *core, struct pw_properties *properties)
static struct spa_pod_builder *
impl_ext_begin_proxy(struct pw_proxy *proxy, uint8_t opcode)
{
struct impl *impl;
struct connection *impl = SPA_CONTAINER_OF(proxy->remote->conn, struct connection, this);
return pw_protocol_native_connection_begin_proxy(impl->connection, proxy, opcode);
}
static uint32_t impl_ext_add_proxy_fd(struct pw_proxy *proxy, int fd)
{
struct connection *impl = SPA_CONTAINER_OF(proxy->remote->conn, struct connection, this);
return pw_protocol_native_connection_add_fd(impl->connection, fd);
}
static int impl_ext_get_proxy_fd(struct pw_proxy *proxy, uint32_t index)
{
struct connection *impl = SPA_CONTAINER_OF(proxy->remote->conn, struct connection, this);
return pw_protocol_native_connection_get_fd(impl->connection, index);
}
static void impl_ext_end_proxy(struct pw_proxy *proxy,
struct spa_pod_builder *builder)
{
struct connection *impl = SPA_CONTAINER_OF(proxy->remote->conn, struct connection, this);
pw_protocol_native_connection_end(impl->connection, builder);
}
static struct spa_pod_builder *
impl_ext_begin_resource(struct pw_resource *resource, uint8_t opcode)
{
struct client_data *data = resource->client->user_data;
return pw_protocol_native_connection_begin_resource(data->connection, resource, opcode);
}
static uint32_t impl_ext_add_resource_fd(struct pw_resource *resource, int fd)
{
struct client_data *data = resource->client->user_data;
return pw_protocol_native_connection_add_fd(data->connection, fd);
}
static int impl_ext_get_resource_fd(struct pw_resource *resource, uint32_t index)
{
struct client_data *data = resource->client->user_data;
return pw_protocol_native_connection_get_fd(data->connection, index);
}
static void impl_ext_end_resource(struct pw_resource *resource,
struct spa_pod_builder *builder)
{
struct client_data *data = resource->client->user_data;
pw_protocol_native_connection_end(data->connection, builder);
}
const static struct pw_protocol_native_ext protocol_ext_impl = {
PW_VERSION_PROTOCOL_NATIVE_EXT,
impl_ext_begin_proxy,
impl_ext_add_proxy_fd,
impl_ext_get_proxy_fd,
impl_ext_end_proxy,
impl_ext_begin_resource,
impl_ext_add_resource_fd,
impl_ext_get_resource_fd,
impl_ext_end_resource,
};
static struct pw_protocol *pw_protocol_native_new(struct pw_core *core, struct pw_properties *properties)
{
struct pw_protocol *this;
const char *val;
impl = calloc(1, sizeof(struct impl));
this = pw_protocol_new(core, PW_TYPE_PROTOCOL__Native, sizeof(struct protocol_data));
if (this == NULL)
return NULL;
impl->core = core;
impl->properties = properties;
impl->protocol = pw_protocol_native_init();
impl->protocol->new_connection = impl_new_connection;
impl->protocol->add_listener = impl_add_listener;
impl->protocol->protocol_private = impl;
pw_log_debug("protocol-native %p: new %p", impl, impl->protocol);
this->implementation = &protocol_impl;
this->extension = &protocol_ext_impl;
spa_list_init(&impl->client_list);
pw_protocol_native_init(this);
pw_log_debug("protocol-native %p: new", this);
if ((val = pw_properties_get(core->properties, "pipewire.daemon"))) {
if (atoi(val) == 1)
impl_add_listener(impl->protocol, core, properties);
impl_add_listener(this, core, properties);
}
return impl;
return this;
}
#if 0

View file

@ -53,7 +53,7 @@ struct buffer {
};
struct impl {
struct pw_connection this;
struct pw_protocol_native_connection this;
struct buffer in, out;
@ -70,9 +70,9 @@ struct impl {
* \param index the index of the fd to get
* \return the fd at \a index or -1 when no such fd exists
*
* \memberof pw_connection
* \memberof pw_protocol_native_connection
*/
int pw_connection_get_fd(struct pw_connection *conn, uint32_t index)
int pw_protocol_native_connection_get_fd(struct pw_protocol_native_connection *conn, uint32_t index)
{
struct impl *impl = SPA_CONTAINER_OF(conn, struct impl, this);
@ -88,9 +88,9 @@ int pw_connection_get_fd(struct pw_connection *conn, uint32_t index)
* \param fd the fd to add
* \return the index of the fd or -1 when an error occured
*
* \memberof pw_connection
* \memberof pw_protocol_native_connection
*/
uint32_t pw_connection_add_fd(struct pw_connection *conn, int fd)
uint32_t pw_protocol_native_connection_add_fd(struct pw_protocol_native_connection *conn, int fd)
{
struct impl *impl = SPA_CONTAINER_OF(conn, struct impl, this);
uint32_t index, i;
@ -112,7 +112,7 @@ uint32_t pw_connection_add_fd(struct pw_connection *conn, int fd)
return index;
}
static void *connection_ensure_size(struct pw_connection *conn, struct buffer *buf, size_t size)
static void *connection_ensure_size(struct pw_protocol_native_connection *conn, struct buffer *buf, size_t size)
{
if (buf->buffer_size + size > buf->buffer_maxsize) {
buf->buffer_maxsize = SPA_ROUND_UP_N(buf->buffer_size + size, MAX_BUFFER_SIZE);
@ -124,7 +124,7 @@ static void *connection_ensure_size(struct pw_connection *conn, struct buffer *b
return (uint8_t *) buf->buffer_data + buf->buffer_size;
}
static bool refill_buffer(struct pw_connection *conn, struct buffer *buf)
static bool refill_buffer(struct pw_protocol_native_connection *conn, struct buffer *buf)
{
ssize_t len;
struct cmsghdr *cmsg;
@ -186,12 +186,12 @@ static void clear_buffer(struct buffer *buf)
* \param fd the socket
* \returns a newly allocated connection object
*
* \memberof pw_connection
* \memberof pw_protocol_native_connection
*/
struct pw_connection *pw_connection_new(int fd)
struct pw_protocol_native_connection *pw_protocol_native_connection_new(int fd)
{
struct impl *impl;
struct pw_connection *this;
struct pw_protocol_native_connection *this;
impl = calloc(1, sizeof(struct impl));
if (impl == NULL)
@ -229,9 +229,9 @@ struct pw_connection *pw_connection_new(int fd)
*
* \param conn the connection to destroy
*
* \memberof pw_connection
* \memberof pw_protocol_native_connection
*/
void pw_connection_destroy(struct pw_connection *conn)
void pw_protocol_native_connection_destroy(struct pw_protocol_native_connection *conn)
{
struct impl *impl = SPA_CONTAINER_OF(conn, struct impl, this);
@ -256,10 +256,10 @@ void pw_connection_destroy(struct pw_connection *conn)
* Get the next packet in \a conn and store the opcode and destination
* id as well as the packet data and size.
*
* \memberof pw_connection
* \memberof pw_protocol_native_connection
*/
bool
pw_connection_get_next(struct pw_connection *conn,
pw_protocol_native_connection_get_next(struct pw_protocol_native_connection *conn,
uint8_t *opcode,
uint32_t *dest_id,
void **dt,
@ -330,7 +330,7 @@ pw_connection_get_next(struct pw_connection *conn,
return true;
}
static inline void *begin_write(struct pw_connection *conn, uint32_t size)
static inline void *begin_write(struct pw_protocol_native_connection *conn, uint32_t size)
{
struct impl *impl = SPA_CONTAINER_OF(conn, struct impl, this);
uint32_t *p;
@ -357,9 +357,9 @@ static uint32_t write_pod(struct spa_pod_builder *b, uint32_t ref, const void *d
}
struct spa_pod_builder *
pw_connection_begin_write_resource(struct pw_connection *conn,
struct pw_resource *resource,
uint8_t opcode)
pw_protocol_native_connection_begin_resource(struct pw_protocol_native_connection *conn,
struct pw_resource *resource,
uint8_t opcode)
{
struct impl *impl = SPA_CONTAINER_OF(conn, struct impl, this);
uint32_t diff, base, i, b;
@ -386,9 +386,9 @@ pw_connection_begin_write_resource(struct pw_connection *conn,
}
struct spa_pod_builder *
pw_connection_begin_write_proxy(struct pw_connection *conn,
struct pw_proxy *proxy,
uint8_t opcode)
pw_protocol_native_connection_begin_proxy(struct pw_protocol_native_connection *conn,
struct pw_proxy *proxy,
uint8_t opcode)
{
struct impl *impl = SPA_CONTAINER_OF(conn, struct impl, this);
uint32_t diff, base, i, b;
@ -415,8 +415,8 @@ pw_connection_begin_write_proxy(struct pw_connection *conn,
}
void
pw_connection_end_write(struct pw_connection *conn,
struct spa_pod_builder *builder)
pw_protocol_native_connection_end(struct pw_protocol_native_connection *conn,
struct spa_pod_builder *builder)
{
struct impl *impl = SPA_CONTAINER_OF(conn, struct impl, this);
uint32_t *p, size = builder->offset;
@ -443,9 +443,9 @@ pw_connection_end_write(struct pw_connection *conn,
*
* Write the queued messages on the connection to the socket
*
* \memberof pw_connection
* \memberof pw_protocol_native_connection
*/
bool pw_connection_flush(struct pw_connection *conn)
bool pw_protocol_native_connection_flush(struct pw_protocol_native_connection *conn)
{
struct impl *impl = SPA_CONTAINER_OF(conn, struct impl, this);
ssize_t len;
@ -515,9 +515,9 @@ bool pw_connection_flush(struct pw_connection *conn)
*
* Remove all queued messages from \a conn
*
* \memberof pw_connection
* \memberof pw_protocol_native_connection
*/
bool pw_connection_clear(struct pw_connection *conn)
bool pw_protocol_native_connection_clear(struct pw_protocol_native_connection *conn)
{
struct impl *impl = SPA_CONTAINER_OF(conn, struct impl, this);

View file

@ -17,8 +17,8 @@
* Boston, MA 02110-1301, USA.
*/
#ifndef __PIPEWIRE_CONNECTION_H__
#define __PIPEWIRE_CONNECTION_H__
#ifndef __PIPEWIRE_PROTOCOL_NATIVE_CONNECTION_H__
#define __PIPEWIRE_PROTOCOL_NATIVE_CONNECTION_H__
#ifdef __cplusplus
extern "C" {
@ -27,63 +27,61 @@ extern "C" {
#include <spa/defs.h>
#include <pipewire/sig.h>
/** \class pw_connection
/** \class pw_protocol_native_connection
*
* \brief Manages the connection between client and server
*
* The \ref pw_connection handles the connection between client
* The \ref pw_protocol_native_connection handles the connection between client
* and server on a given socket.
*/
struct pw_connection {
struct pw_protocol_native_connection {
int fd; /**< the socket */
/** Emited when data has been written that needs to be flushed */
PW_SIGNAL(need_flush, (struct pw_listener *listener, struct pw_connection *conn));
PW_SIGNAL(need_flush, (struct pw_listener *listener,
struct pw_protocol_native_connection *conn));
/** Emited when the connection is destroyed */
PW_SIGNAL(destroy_signal, (struct pw_listener *listener, struct pw_connection *conn));
PW_SIGNAL(destroy_signal, (struct pw_listener *listener,
struct pw_protocol_native_connection *conn));
};
struct pw_connection *
pw_connection_new(int fd);
struct pw_protocol_native_connection *
pw_protocol_native_connection_new(int fd);
void
pw_connection_destroy(struct pw_connection *conn);
uint32_t
pw_connection_add_fd(struct pw_connection *conn, int fd);
int
pw_connection_get_fd(struct pw_connection *conn, uint32_t index);
pw_protocol_native_connection_destroy(struct pw_protocol_native_connection *conn);
bool
pw_connection_get_next(struct pw_connection *conn,
uint8_t *opcode,
uint32_t *dest_id,
void **data, uint32_t *size);
pw_protocol_native_connection_get_next(struct pw_protocol_native_connection *conn,
uint8_t *opcode,
uint32_t *dest_id,
void **data, uint32_t *size);
uint32_t pw_protocol_native_connection_add_fd(struct pw_protocol_native_connection *conn, int fd);
int pw_protocol_native_connection_get_fd(struct pw_protocol_native_connection *conn, uint32_t index);
struct spa_pod_builder *
pw_connection_begin_write_resource(struct pw_connection *conn,
struct pw_resource *resource,
uint8_t opcode);
pw_protocol_native_connection_begin_resource(struct pw_protocol_native_connection *conn,
struct pw_resource *resource,
uint8_t opcode);
struct spa_pod_builder *
pw_connection_begin_write_proxy(struct pw_connection *conn,
struct pw_proxy *proxy,
uint8_t opcode);
pw_protocol_native_connection_begin_proxy(struct pw_protocol_native_connection *conn,
struct pw_proxy *proxy,
uint8_t opcode);
void
pw_connection_end_write(struct pw_connection *conn,
struct spa_pod_builder *builder);
pw_protocol_native_connection_end(struct pw_protocol_native_connection *conn,
struct spa_pod_builder *builder);
bool
pw_connection_flush(struct pw_connection *conn);
pw_protocol_native_connection_flush(struct pw_protocol_native_connection *conn);
bool
pw_connection_clear(struct pw_connection *conn);
pw_protocol_native_connection_clear(struct pw_protocol_native_connection *conn);
#ifdef __cplusplus
} /* extern "C" */
#endif
#endif /* __PIPEWIRE_CONNECTION_H__ */
#endif /* __PIPEWIRE_PROTOCOL_NATIVE_CONNECTION_H__ */

View file

@ -17,6 +17,7 @@
* Boston, MA 02110-1301, USA.
*/
#include <stdio.h>
#include <errno.h>
#include "spa/pod-iter.h"
@ -25,6 +26,7 @@
#include "pipewire/protocol.h"
#include "pipewire/interfaces.h"
#include "pipewire/resource.h"
#include "extensions/protocol-native.h"
#include "connection.h"
@ -37,12 +39,11 @@ typedef bool(*demarshal_func_t) (void *object, void *data, size_t size);
static void core_marshal_client_update(void *object, const struct spa_dict *props)
{
struct pw_proxy *proxy = object;
struct pw_connection *connection = proxy->remote->protocol_private;
struct spa_pod_builder *b;
struct spa_pod_frame f;
int i, n_items;
b = pw_connection_begin_write_proxy(connection, proxy, PW_CORE_METHOD_CLIENT_UPDATE);
b = pw_protocol_native_begin_proxy(proxy, PW_CORE_METHOD_CLIENT_UPDATE);
n_items = props ? props->n_items : 0;
@ -55,37 +56,35 @@ static void core_marshal_client_update(void *object, const struct spa_dict *prop
}
spa_pod_builder_add(b, -SPA_POD_TYPE_STRUCT, &f, 0);
pw_connection_end_write(connection, b);
pw_protocol_native_end_proxy(proxy, b);
}
static void core_marshal_sync(void *object, uint32_t seq)
{
struct pw_proxy *proxy = object;
struct pw_connection *connection = proxy->remote->protocol_private;
struct spa_pod_builder *b;
struct spa_pod_frame f;
b = pw_connection_begin_write_proxy(connection, proxy, PW_CORE_METHOD_SYNC);
b = pw_protocol_native_begin_proxy(proxy, PW_CORE_METHOD_SYNC);
spa_pod_builder_struct(b, &f, SPA_POD_TYPE_INT, seq);
pw_connection_end_write(connection, b);
pw_protocol_native_end_proxy(proxy, b);
}
static void core_marshal_get_registry(void *object, uint32_t version, uint32_t new_id)
{
struct pw_proxy *proxy = object;
struct pw_connection *connection = proxy->remote->protocol_private;
struct spa_pod_builder *b;
struct spa_pod_frame f;
b = pw_connection_begin_write_proxy(connection, proxy, PW_CORE_METHOD_GET_REGISTRY);
b = pw_protocol_native_begin_proxy(proxy, PW_CORE_METHOD_GET_REGISTRY);
spa_pod_builder_struct(b, &f,
SPA_POD_TYPE_INT, version,
SPA_POD_TYPE_INT, new_id);
pw_connection_end_write(connection, b);
pw_protocol_native_end_proxy(proxy, b);
}
static void
@ -95,12 +94,11 @@ core_marshal_create_node(void *object,
uint32_t version, uint32_t new_id)
{
struct pw_proxy *proxy = object;
struct pw_connection *connection = proxy->remote->protocol_private;
struct spa_pod_builder *b;
struct spa_pod_frame f;
uint32_t i, n_items;
b = pw_connection_begin_write_proxy(connection, proxy, PW_CORE_METHOD_CREATE_NODE);
b = pw_protocol_native_begin_proxy(proxy, PW_CORE_METHOD_CREATE_NODE);
n_items = props ? props->n_items : 0;
@ -119,7 +117,7 @@ core_marshal_create_node(void *object,
SPA_POD_TYPE_INT, new_id,
-SPA_POD_TYPE_STRUCT, &f, 0);
pw_connection_end_write(connection, b);
pw_protocol_native_end_proxy(proxy, b);
}
static void
@ -133,12 +131,11 @@ core_marshal_create_link(void *object,
uint32_t new_id)
{
struct pw_proxy *proxy = object;
struct pw_connection *connection = proxy->remote->protocol_private;
struct spa_pod_builder *b;
struct spa_pod_frame f;
uint32_t i, n_items;
b = pw_connection_begin_write_proxy(connection, proxy, PW_CORE_METHOD_CREATE_LINK);
b = pw_protocol_native_begin_proxy(proxy, PW_CORE_METHOD_CREATE_LINK);
n_items = props ? props->n_items : 0;
@ -160,19 +157,18 @@ core_marshal_create_link(void *object,
SPA_POD_TYPE_INT, new_id,
-SPA_POD_TYPE_STRUCT, &f, 0);
pw_connection_end_write(connection, b);
pw_protocol_native_end_proxy(proxy, b);
}
static void
core_marshal_update_types_client(void *object, uint32_t first_id, uint32_t n_types, const char **types)
{
struct pw_proxy *proxy = object;
struct pw_connection *connection = proxy->remote->protocol_private;
struct spa_pod_builder *b;
struct spa_pod_frame f;
uint32_t i;
b = pw_connection_begin_write_proxy(connection, proxy, PW_CORE_METHOD_UPDATE_TYPES);
b = pw_protocol_native_begin_proxy(proxy, PW_CORE_METHOD_UPDATE_TYPES);
spa_pod_builder_add(b,
SPA_POD_TYPE_STRUCT, &f,
@ -183,7 +179,7 @@ core_marshal_update_types_client(void *object, uint32_t first_id, uint32_t n_typ
}
spa_pod_builder_add(b, -SPA_POD_TYPE_STRUCT, &f, 0);
pw_connection_end_write(connection, b);
pw_protocol_native_end_proxy(proxy, b);
}
static bool core_demarshal_info(void *object, void *data, size_t size)
@ -286,12 +282,11 @@ static bool core_demarshal_update_types_client(void *object, void *data, size_t
static void core_marshal_info(void *object, struct pw_core_info *info)
{
struct pw_resource *resource = object;
struct pw_connection *connection = resource->client->protocol_private;
struct spa_pod_builder *b;
struct spa_pod_frame f;
uint32_t i, n_items;
b = pw_connection_begin_write_resource(connection, resource, PW_CORE_EVENT_INFO);
b = pw_protocol_native_begin_resource(resource, PW_CORE_EVENT_INFO);
n_items = info->props ? info->props->n_items : 0;
@ -312,33 +307,31 @@ static void core_marshal_info(void *object, struct pw_core_info *info)
}
spa_pod_builder_add(b, -SPA_POD_TYPE_STRUCT, &f, 0);
pw_connection_end_write(connection, b);
pw_protocol_native_end_resource(resource, b);
}
static void core_marshal_done(void *object, uint32_t seq)
{
struct pw_resource *resource = object;
struct pw_connection *connection = resource->client->protocol_private;
struct spa_pod_builder *b;
struct spa_pod_frame f;
b = pw_connection_begin_write_resource(connection, resource, PW_CORE_EVENT_DONE);
b = pw_protocol_native_begin_resource(resource, PW_CORE_EVENT_DONE);
spa_pod_builder_struct(b, &f, SPA_POD_TYPE_INT, seq);
pw_connection_end_write(connection, b);
pw_protocol_native_end_resource(resource, b);
}
static void core_marshal_error(void *object, uint32_t id, int res, const char *error, ...)
{
struct pw_resource *resource = object;
struct pw_connection *connection = resource->client->protocol_private;
char buffer[128];
struct spa_pod_builder *b;
struct spa_pod_frame f;
va_list ap;
b = pw_connection_begin_write_resource(connection, resource, PW_CORE_EVENT_ERROR);
b = pw_protocol_native_begin_resource(resource, PW_CORE_EVENT_ERROR);
va_start(ap, error);
vsnprintf(buffer, sizeof(buffer), error, ap);
@ -349,33 +342,31 @@ static void core_marshal_error(void *object, uint32_t id, int res, const char *e
SPA_POD_TYPE_INT, res,
SPA_POD_TYPE_STRING, buffer);
pw_connection_end_write(connection, b);
pw_protocol_native_end_resource(resource, b);
}
static void core_marshal_remove_id(void *object, uint32_t id)
{
struct pw_resource *resource = object;
struct pw_connection *connection = resource->client->protocol_private;
struct spa_pod_builder *b;
struct spa_pod_frame f;
b = pw_connection_begin_write_resource(connection, resource, PW_CORE_EVENT_REMOVE_ID);
b = pw_protocol_native_begin_resource(resource, PW_CORE_EVENT_REMOVE_ID);
spa_pod_builder_struct(b, &f, SPA_POD_TYPE_INT, id);
pw_connection_end_write(connection, b);
pw_protocol_native_end_resource(resource, b);
}
static void
core_marshal_update_types_server(void *object, uint32_t first_id, uint32_t n_types, const char **types)
{
struct pw_resource *resource = object;
struct pw_connection *connection = resource->client->protocol_private;
struct spa_pod_builder *b;
struct spa_pod_frame f;
uint32_t i;
b = pw_connection_begin_write_resource(connection, resource, PW_CORE_EVENT_UPDATE_TYPES);
b = pw_protocol_native_begin_resource(resource, PW_CORE_EVENT_UPDATE_TYPES);
spa_pod_builder_add(b,
SPA_POD_TYPE_STRUCT, &f,
@ -386,7 +377,7 @@ core_marshal_update_types_server(void *object, uint32_t first_id, uint32_t n_typ
}
spa_pod_builder_add(b, -SPA_POD_TYPE_STRUCT, &f, 0);
pw_connection_end_write(connection, b);
pw_protocol_native_end_resource(resource, b);
}
static bool core_demarshal_client_update(void *object, void *data, size_t size)
@ -537,32 +528,30 @@ static bool core_demarshal_update_types_server(void *object, void *data, size_t
static void registry_marshal_global(void *object, uint32_t id, uint32_t type, uint32_t version)
{
struct pw_resource *resource = object;
struct pw_connection *connection = resource->client->protocol_private;
struct spa_pod_builder *b;
struct spa_pod_frame f;
b = pw_connection_begin_write_resource(connection, resource, PW_REGISTRY_EVENT_GLOBAL);
b = pw_protocol_native_begin_resource(resource, PW_REGISTRY_EVENT_GLOBAL);
spa_pod_builder_struct(b, &f,
SPA_POD_TYPE_INT, id,
SPA_POD_TYPE_ID, type,
SPA_POD_TYPE_INT, version);
pw_connection_end_write(connection, b);
pw_protocol_native_end_resource(resource, b);
}
static void registry_marshal_global_remove(void *object, uint32_t id)
{
struct pw_resource *resource = object;
struct pw_connection *connection = resource->client->protocol_private;
struct spa_pod_builder *b;
struct spa_pod_frame f;
b = pw_connection_begin_write_resource(connection, resource, PW_REGISTRY_EVENT_GLOBAL_REMOVE);
b = pw_protocol_native_begin_resource(resource, PW_REGISTRY_EVENT_GLOBAL_REMOVE);
spa_pod_builder_struct(b, &f, SPA_POD_TYPE_INT, id);
pw_connection_end_write(connection, b);
pw_protocol_native_end_resource(resource, b);
}
static bool registry_demarshal_bind(void *object, void *data, size_t size)
@ -585,12 +574,11 @@ static bool registry_demarshal_bind(void *object, void *data, size_t size)
static void module_marshal_info(void *object, struct pw_module_info *info)
{
struct pw_resource *resource = object;
struct pw_connection *connection = resource->client->protocol_private;
struct spa_pod_builder *b;
struct spa_pod_frame f;
uint32_t i, n_items;
b = pw_connection_begin_write_resource(connection, resource, PW_MODULE_EVENT_INFO);
b = pw_protocol_native_begin_resource(resource, PW_MODULE_EVENT_INFO);
n_items = info->props ? info->props->n_items : 0;
@ -609,7 +597,7 @@ static void module_marshal_info(void *object, struct pw_module_info *info)
}
spa_pod_builder_add(b, -SPA_POD_TYPE_STRUCT, &f, 0);
pw_connection_end_write(connection, b);
pw_protocol_native_end_resource(resource, b);
}
static bool module_demarshal_info(void *object, void *data, size_t size)
@ -644,12 +632,11 @@ static bool module_demarshal_info(void *object, void *data, size_t size)
static void node_marshal_info(void *object, struct pw_node_info *info)
{
struct pw_resource *resource = object;
struct pw_connection *connection = resource->client->protocol_private;
struct spa_pod_builder *b;
struct spa_pod_frame f;
uint32_t i, n_items;
b = pw_connection_begin_write_resource(connection, resource, PW_NODE_EVENT_INFO);
b = pw_protocol_native_begin_resource(resource, PW_NODE_EVENT_INFO);
spa_pod_builder_add(b,
SPA_POD_TYPE_STRUCT, &f,
@ -684,7 +671,7 @@ static void node_marshal_info(void *object, struct pw_node_info *info)
}
spa_pod_builder_add(b, -SPA_POD_TYPE_STRUCT, &f, 0);
pw_connection_end_write(connection, b);
pw_protocol_native_end_resource(resource, b);
}
static bool node_demarshal_info(void *object, void *data, size_t size)
@ -743,12 +730,11 @@ static bool node_demarshal_info(void *object, void *data, size_t size)
static void client_marshal_info(void *object, struct pw_client_info *info)
{
struct pw_resource *resource = object;
struct pw_connection *connection = resource->client->protocol_private;
struct spa_pod_builder *b;
struct spa_pod_frame f;
uint32_t i, n_items;
b = pw_connection_begin_write_resource(connection, resource, PW_CLIENT_EVENT_INFO);
b = pw_protocol_native_begin_resource(resource, PW_CLIENT_EVENT_INFO);
n_items = info->props ? info->props->n_items : 0;
@ -764,7 +750,7 @@ static void client_marshal_info(void *object, struct pw_client_info *info)
}
spa_pod_builder_add(b, -SPA_POD_TYPE_STRUCT, &f, 0);
pw_connection_end_write(connection, b);
pw_protocol_native_end_resource(resource, b);
}
static bool client_demarshal_info(void *object, void *data, size_t size)
@ -797,11 +783,10 @@ static bool client_demarshal_info(void *object, void *data, size_t size)
static void link_marshal_info(void *object, struct pw_link_info *info)
{
struct pw_resource *resource = object;
struct pw_connection *connection = resource->client->protocol_private;
struct spa_pod_builder *b;
struct spa_pod_frame f;
b = pw_connection_begin_write_resource(connection, resource, PW_LINK_EVENT_INFO);
b = pw_protocol_native_begin_resource(resource, PW_LINK_EVENT_INFO);
spa_pod_builder_struct(b, &f,
SPA_POD_TYPE_INT, info->id,
@ -812,7 +797,7 @@ static void link_marshal_info(void *object, struct pw_link_info *info)
SPA_POD_TYPE_INT, info->input_port_id,
SPA_POD_TYPE_POD, info->format);
pw_connection_end_write(connection, b);
pw_protocol_native_end_resource(resource, b);
}
static bool link_demarshal_info(void *object, void *data, size_t size)
@ -872,18 +857,17 @@ static bool registry_demarshal_global_remove(void *object, void *data, size_t si
static void registry_marshal_bind(void *object, uint32_t id, uint32_t version, uint32_t new_id)
{
struct pw_proxy *proxy = object;
struct pw_connection *connection = proxy->remote->protocol_private;
struct spa_pod_builder *b;
struct spa_pod_frame f;
b = pw_connection_begin_write_proxy(connection, proxy, PW_REGISTRY_METHOD_BIND);
b = pw_protocol_native_begin_proxy(proxy, PW_REGISTRY_METHOD_BIND);
spa_pod_builder_struct(b, &f,
SPA_POD_TYPE_INT, id,
SPA_POD_TYPE_INT, version,
SPA_POD_TYPE_INT, new_id);
pw_connection_end_write(connection, b);
pw_protocol_native_end_proxy(proxy, b);
}
static const struct pw_core_methods pw_protocol_native_client_core_methods = {
@ -904,7 +888,7 @@ static const demarshal_func_t pw_protocol_native_client_core_demarshal[PW_CORE_E
};
static const struct pw_interface pw_protocol_native_client_core_interface = {
PIPEWIRE_TYPE__Core,
PW_TYPE__Core,
PW_VERSION_CORE,
PW_CORE_METHOD_NUM, &pw_protocol_native_client_core_methods,
PW_CORE_EVENT_NUM, pw_protocol_native_client_core_demarshal
@ -920,7 +904,7 @@ static const demarshal_func_t pw_protocol_native_client_registry_demarshal[] = {
};
static const struct pw_interface pw_protocol_native_client_registry_interface = {
PIPEWIRE_TYPE__Registry,
PW_TYPE__Registry,
PW_VERSION_REGISTRY,
PW_REGISTRY_METHOD_NUM, &pw_protocol_native_client_registry_methods,
PW_REGISTRY_EVENT_NUM, pw_protocol_native_client_registry_demarshal,
@ -931,7 +915,7 @@ static const demarshal_func_t pw_protocol_native_client_module_demarshal[] = {
};
static const struct pw_interface pw_protocol_native_client_module_interface = {
PIPEWIRE_TYPE__Module,
PW_TYPE__Module,
PW_VERSION_MODULE,
0, NULL,
PW_MODULE_EVENT_NUM, pw_protocol_native_client_module_demarshal,
@ -942,7 +926,7 @@ static const demarshal_func_t pw_protocol_native_client_node_demarshal[] = {
};
static const struct pw_interface pw_protocol_native_client_node_interface = {
PIPEWIRE_TYPE__Node,
PW_TYPE__Node,
PW_VERSION_NODE,
0, NULL,
PW_NODE_EVENT_NUM, pw_protocol_native_client_node_demarshal,
@ -953,7 +937,7 @@ static const demarshal_func_t pw_protocol_native_client_client_demarshal[] = {
};
static const struct pw_interface pw_protocol_native_client_client_interface = {
PIPEWIRE_TYPE__Client,
PW_TYPE__Client,
PW_VERSION_CLIENT,
0, NULL,
PW_CLIENT_EVENT_NUM, pw_protocol_native_client_client_demarshal,
@ -964,7 +948,7 @@ static const demarshal_func_t pw_protocol_native_client_link_demarshal[] = {
};
static const struct pw_interface pw_protocol_native_client_link_interface = {
PIPEWIRE_TYPE__Link,
PW_TYPE__Link,
PW_VERSION_LINK,
0, NULL,
PW_LINK_EVENT_NUM, pw_protocol_native_client_link_demarshal,
@ -988,7 +972,7 @@ static const struct pw_core_events pw_protocol_native_server_core_events = {
};
const struct pw_interface pw_protocol_native_server_core_interface = {
PIPEWIRE_TYPE__Core,
PW_TYPE__Core,
PW_VERSION_CORE,
PW_CORE_METHOD_NUM, pw_protocol_native_server_core_demarshal,
PW_CORE_EVENT_NUM, &pw_protocol_native_server_core_events,
@ -1004,7 +988,7 @@ static const struct pw_registry_events pw_protocol_native_server_registry_events
};
const struct pw_interface pw_protocol_native_server_registry_interface = {
PIPEWIRE_TYPE__Registry,
PW_TYPE__Registry,
PW_VERSION_REGISTRY,
PW_REGISTRY_METHOD_NUM, pw_protocol_native_server_registry_demarshal,
PW_REGISTRY_EVENT_NUM, &pw_protocol_native_server_registry_events,
@ -1015,7 +999,7 @@ static const struct pw_module_events pw_protocol_native_server_module_events = {
};
const struct pw_interface pw_protocol_native_server_module_interface = {
PIPEWIRE_TYPE__Module,
PW_TYPE__Module,
PW_VERSION_MODULE,
0, NULL,
PW_MODULE_EVENT_NUM, &pw_protocol_native_server_module_events,
@ -1026,7 +1010,7 @@ static const struct pw_node_events pw_protocol_native_server_node_events = {
};
const struct pw_interface pw_protocol_native_server_node_interface = {
PIPEWIRE_TYPE__Node,
PW_TYPE__Node,
PW_VERSION_NODE,
0, NULL,
PW_NODE_EVENT_NUM, &pw_protocol_native_server_node_events,
@ -1037,7 +1021,7 @@ static const struct pw_client_events pw_protocol_native_server_client_events = {
};
const struct pw_interface pw_protocol_native_server_client_interface = {
PIPEWIRE_TYPE__Client,
PW_TYPE__Client,
PW_VERSION_CLIENT,
0, NULL,
PW_CLIENT_EVENT_NUM, &pw_protocol_native_server_client_events,
@ -1048,22 +1032,14 @@ static const struct pw_link_events pw_protocol_native_server_link_events = {
};
const struct pw_interface pw_protocol_native_server_link_interface = {
PIPEWIRE_TYPE__Link,
PW_TYPE__Link,
PW_VERSION_LINK,
0, NULL,
PW_LINK_EVENT_NUM, &pw_protocol_native_server_link_events,
};
struct pw_protocol *pw_protocol_native_init(void)
void pw_protocol_native_init(struct pw_protocol *protocol)
{
static bool init = false;
struct pw_protocol *protocol;
protocol = pw_protocol_get(PW_TYPE_PROTOCOL__Native);
if (init)
return protocol;
pw_protocol_add_interfaces(protocol,
&pw_protocol_native_client_core_interface,
&pw_protocol_native_server_core_interface);
@ -1083,7 +1059,4 @@ struct pw_protocol *pw_protocol_native_init(void)
&pw_protocol_native_client_link_interface,
&pw_protocol_native_server_link_interface);
init = true;
return protocol;
}

View file

@ -17,6 +17,7 @@
* Boston, MA 02110-1301, USA.
*/
#include <stdio.h>
#include <dlfcn.h>
#include <errno.h>
#include <poll.h>