mirror of
https://gitlab.freedesktop.org/pipewire/pipewire.git
synced 2025-11-01 22:58:50 -04:00
protocol-native: move to separate file
Move protocol-native to separate client and server file
This commit is contained in:
parent
b9a0b067be
commit
842d73ca4b
10 changed files with 1196 additions and 1061 deletions
|
|
@ -34,6 +34,7 @@
|
|||
#include "pinos/client/interfaces.h"
|
||||
|
||||
#include "pinos/server/core.h"
|
||||
#include "pinos/server/protocol-native.h"
|
||||
#include "pinos/server/node.h"
|
||||
#include "pinos/server/module.h"
|
||||
#include "pinos/server/client-node.h"
|
||||
|
|
@ -95,586 +96,37 @@ client_destroy (PinosProtocolNativeClient *this)
|
|||
free (this);
|
||||
}
|
||||
|
||||
typedef void (*MarshallFunc) (void *object, void *data, size_t size);
|
||||
|
||||
static void
|
||||
core_event_info (void *object,
|
||||
PinosCoreInfo *info)
|
||||
{
|
||||
PinosResource *resource = object;
|
||||
PinosProtocolNativeClient *client = resource->client->protocol_private;
|
||||
PinosMessageCoreInfo m = { info };
|
||||
|
||||
pinos_connection_add_message (client->connection,
|
||||
resource->id,
|
||||
PINOS_MESSAGE_CORE_INFO,
|
||||
&m);
|
||||
pinos_connection_flush (client->connection);
|
||||
}
|
||||
|
||||
static void
|
||||
core_event_done (void *object,
|
||||
uint32_t seq)
|
||||
{
|
||||
PinosResource *resource = object;
|
||||
PinosProtocolNativeClient *client = resource->client->protocol_private;
|
||||
PinosMessageNotifyDone m = { seq };
|
||||
|
||||
pinos_connection_add_message (client->connection,
|
||||
resource->id,
|
||||
PINOS_MESSAGE_NOTIFY_DONE,
|
||||
&m);
|
||||
pinos_connection_flush (client->connection);
|
||||
}
|
||||
|
||||
static void
|
||||
core_event_error (void *object,
|
||||
uint32_t id,
|
||||
SpaResult res,
|
||||
const char *error, ...)
|
||||
{
|
||||
PinosResource *resource = object;
|
||||
PinosProtocolNativeClient *client = resource->client->protocol_private;
|
||||
char buffer[128];
|
||||
PinosMessageError m = { id, res, buffer };
|
||||
va_list ap;
|
||||
|
||||
va_start (ap, error);
|
||||
vsnprintf (buffer, sizeof (buffer), error, ap);
|
||||
va_end (ap);
|
||||
|
||||
pinos_connection_add_message (client->connection,
|
||||
resource->id,
|
||||
PINOS_MESSAGE_ERROR,
|
||||
&m);
|
||||
pinos_connection_flush (client->connection);
|
||||
}
|
||||
|
||||
static void
|
||||
core_event_remove_id (void *object,
|
||||
uint32_t id)
|
||||
{
|
||||
PinosResource *resource = object;
|
||||
PinosProtocolNativeClient *client = resource->client->protocol_private;
|
||||
PinosMessageRemoveId m = { id };
|
||||
|
||||
pinos_connection_add_message (client->connection,
|
||||
resource->id,
|
||||
PINOS_MESSAGE_REMOVE_ID,
|
||||
&m);
|
||||
pinos_connection_flush (client->connection);
|
||||
}
|
||||
|
||||
static void
|
||||
core_marshall_client_update (void *object,
|
||||
void *data,
|
||||
size_t size)
|
||||
{
|
||||
PinosResource *resource = object;
|
||||
PinosMessageClientUpdate *m = data;
|
||||
pinos_core_do_client_update (resource, m->props);
|
||||
}
|
||||
|
||||
static void
|
||||
core_marshall_sync (void *object,
|
||||
void *data,
|
||||
size_t size)
|
||||
{
|
||||
PinosResource *resource = object;
|
||||
PinosMessageSync *m = data;
|
||||
pinos_core_do_sync (resource, m->seq);
|
||||
}
|
||||
|
||||
static void
|
||||
core_marshall_get_registry (void *object,
|
||||
void *data,
|
||||
size_t size)
|
||||
{
|
||||
PinosResource *resource = object;
|
||||
PinosMessageGetRegistry *m = data;
|
||||
pinos_core_do_get_registry (resource, m->seq, m->new_id);
|
||||
}
|
||||
|
||||
static void
|
||||
core_marshall_create_node (void *object,
|
||||
void *data,
|
||||
size_t size)
|
||||
{
|
||||
PinosResource *resource = object;
|
||||
PinosMessageCreateNode *m = data;
|
||||
pinos_core_do_create_node (resource,
|
||||
m->seq,
|
||||
m->factory_name,
|
||||
m->name,
|
||||
m->props,
|
||||
m->new_id);
|
||||
}
|
||||
|
||||
static void
|
||||
core_marshall_create_client_node (void *object,
|
||||
void *data,
|
||||
size_t size)
|
||||
{
|
||||
PinosResource *resource = object;
|
||||
PinosMessageCreateClientNode *m = data;
|
||||
pinos_core_do_create_client_node (resource,
|
||||
m->seq,
|
||||
m->name,
|
||||
m->props,
|
||||
m->new_id);
|
||||
}
|
||||
|
||||
static void
|
||||
registry_event_global (void *object,
|
||||
uint32_t id,
|
||||
const char *type)
|
||||
{
|
||||
PinosResource *resource = object;
|
||||
PinosProtocolNativeClient *client = resource->client->protocol_private;
|
||||
PinosMessageNotifyGlobal m = { id, type };
|
||||
|
||||
pinos_connection_add_message (client->connection,
|
||||
resource->id,
|
||||
PINOS_MESSAGE_NOTIFY_GLOBAL,
|
||||
&m);
|
||||
pinos_connection_flush (client->connection);
|
||||
}
|
||||
|
||||
static void
|
||||
registry_event_global_remove (void *object,
|
||||
uint32_t id)
|
||||
{
|
||||
PinosResource *resource = object;
|
||||
PinosProtocolNativeClient *client = resource->client->protocol_private;
|
||||
PinosMessageNotifyGlobalRemove m = { id };
|
||||
|
||||
pinos_connection_add_message (client->connection,
|
||||
resource->id,
|
||||
PINOS_MESSAGE_NOTIFY_GLOBAL_REMOVE,
|
||||
&m);
|
||||
pinos_connection_flush (client->connection);
|
||||
}
|
||||
|
||||
static void
|
||||
registry_marshall_bind (void *object,
|
||||
void *data,
|
||||
size_t size)
|
||||
{
|
||||
PinosResource *resource = object;
|
||||
PinosMessageBind *m = data;
|
||||
pinos_registry_do_bind (resource,
|
||||
m->id,
|
||||
m->new_id);
|
||||
}
|
||||
|
||||
static void
|
||||
module_event_info (void *object,
|
||||
PinosModuleInfo *info)
|
||||
{
|
||||
PinosResource *resource = object;
|
||||
PinosProtocolNativeClient *client = resource->client->protocol_private;
|
||||
PinosMessageModuleInfo m = { info };
|
||||
|
||||
pinos_connection_add_message (client->connection,
|
||||
resource->id,
|
||||
PINOS_MESSAGE_MODULE_INFO,
|
||||
&m);
|
||||
pinos_connection_flush (client->connection);
|
||||
}
|
||||
|
||||
static void
|
||||
node_event_done (void *object,
|
||||
uint32_t seq)
|
||||
{
|
||||
PinosResource *resource = object;
|
||||
PinosProtocolNativeClient *client = resource->client->protocol_private;
|
||||
PinosMessageCreateNodeDone m = { seq };
|
||||
|
||||
pinos_connection_add_message (client->connection,
|
||||
resource->id,
|
||||
PINOS_MESSAGE_CREATE_NODE_DONE,
|
||||
&m);
|
||||
pinos_connection_flush (client->connection);
|
||||
}
|
||||
|
||||
static void
|
||||
node_event_info (void *object,
|
||||
PinosNodeInfo *info)
|
||||
{
|
||||
PinosResource *resource = object;
|
||||
PinosProtocolNativeClient *client = resource->client->protocol_private;
|
||||
PinosMessageNodeInfo m = { info };
|
||||
|
||||
pinos_connection_add_message (client->connection,
|
||||
resource->id,
|
||||
PINOS_MESSAGE_NODE_INFO,
|
||||
&m);
|
||||
pinos_connection_flush (client->connection);
|
||||
}
|
||||
|
||||
static void
|
||||
client_event_info (void *object,
|
||||
PinosClientInfo *info)
|
||||
{
|
||||
PinosResource *resource = object;
|
||||
PinosProtocolNativeClient *client = resource->client->protocol_private;
|
||||
PinosMessageClientInfo m = { info };
|
||||
|
||||
pinos_connection_add_message (client->connection,
|
||||
resource->id,
|
||||
PINOS_MESSAGE_CLIENT_INFO,
|
||||
&m);
|
||||
pinos_connection_flush (client->connection);
|
||||
}
|
||||
|
||||
static void
|
||||
client_node_event_done (void *object,
|
||||
uint32_t seq,
|
||||
int datafd)
|
||||
{
|
||||
PinosResource *resource = object;
|
||||
PinosProtocolNativeClient *client = resource->client->protocol_private;
|
||||
PinosMessageCreateClientNodeDone m = { seq, datafd };
|
||||
|
||||
pinos_connection_add_message (client->connection,
|
||||
resource->id,
|
||||
PINOS_MESSAGE_CREATE_CLIENT_NODE_DONE,
|
||||
&m);
|
||||
pinos_connection_flush (client->connection);
|
||||
}
|
||||
|
||||
static void
|
||||
client_node_event_event (void *object,
|
||||
SpaNodeEvent *event)
|
||||
{
|
||||
PinosResource *resource = object;
|
||||
PinosProtocolNativeClient *client = resource->client->protocol_private;
|
||||
PinosMessageNodeEvent m = { event };
|
||||
|
||||
pinos_connection_add_message (client->connection,
|
||||
resource->id,
|
||||
PINOS_MESSAGE_NODE_EVENT,
|
||||
&m);
|
||||
pinos_connection_flush (client->connection);
|
||||
}
|
||||
|
||||
static void
|
||||
client_node_event_add_port (void *object,
|
||||
uint32_t seq,
|
||||
SpaDirection direction,
|
||||
uint32_t port_id)
|
||||
{
|
||||
PinosResource *resource = object;
|
||||
PinosProtocolNativeClient *client = resource->client->protocol_private;
|
||||
PinosMessageAddPort m = { seq, direction, port_id };
|
||||
|
||||
pinos_connection_add_message (client->connection,
|
||||
resource->id,
|
||||
PINOS_MESSAGE_ADD_PORT,
|
||||
&m);
|
||||
pinos_connection_flush (client->connection);
|
||||
}
|
||||
static void
|
||||
client_node_event_remove_port (void *object,
|
||||
uint32_t seq,
|
||||
SpaDirection direction,
|
||||
uint32_t port_id)
|
||||
{
|
||||
PinosResource *resource = object;
|
||||
PinosProtocolNativeClient *client = resource->client->protocol_private;
|
||||
PinosMessageRemovePort m = { seq, direction, port_id };
|
||||
|
||||
pinos_connection_add_message (client->connection,
|
||||
resource->id,
|
||||
PINOS_MESSAGE_REMOVE_PORT,
|
||||
&m);
|
||||
pinos_connection_flush (client->connection);
|
||||
}
|
||||
static void
|
||||
client_node_event_set_format (void *object,
|
||||
uint32_t seq,
|
||||
SpaDirection direction,
|
||||
uint32_t port_id,
|
||||
SpaPortFormatFlags flags,
|
||||
const SpaFormat *format)
|
||||
{
|
||||
PinosResource *resource = object;
|
||||
PinosProtocolNativeClient *client = resource->client->protocol_private;
|
||||
PinosMessageSetFormat m = { seq, direction, port_id, flags, format };
|
||||
|
||||
pinos_connection_add_message (client->connection,
|
||||
resource->id,
|
||||
PINOS_MESSAGE_SET_FORMAT,
|
||||
&m);
|
||||
pinos_connection_flush (client->connection);
|
||||
}
|
||||
|
||||
static void
|
||||
client_node_event_set_property (void *object,
|
||||
uint32_t seq,
|
||||
uint32_t id,
|
||||
size_t size,
|
||||
void *value)
|
||||
{
|
||||
PinosResource *resource = object;
|
||||
PinosProtocolNativeClient *client = resource->client->protocol_private;
|
||||
PinosMessageSetProperty m = { seq, id, size, value };
|
||||
|
||||
pinos_connection_add_message (client->connection,
|
||||
resource->id,
|
||||
PINOS_MESSAGE_SET_PROPERTY,
|
||||
&m);
|
||||
pinos_connection_flush (client->connection);
|
||||
}
|
||||
static void
|
||||
client_node_event_add_mem (void *object,
|
||||
SpaDirection direction,
|
||||
uint32_t port_id,
|
||||
uint32_t mem_id,
|
||||
SpaDataType type,
|
||||
int memfd,
|
||||
uint32_t flags,
|
||||
off_t offset,
|
||||
size_t size)
|
||||
{
|
||||
PinosResource *resource = object;
|
||||
PinosProtocolNativeClient *client = resource->client->protocol_private;
|
||||
PinosMessageAddMem m = { direction, port_id, mem_id, type, memfd, flags, offset, size };
|
||||
|
||||
pinos_connection_add_message (client->connection,
|
||||
resource->id,
|
||||
PINOS_MESSAGE_ADD_MEM,
|
||||
&m);
|
||||
pinos_connection_flush (client->connection);
|
||||
}
|
||||
static void
|
||||
client_node_event_use_buffers (void *object,
|
||||
uint32_t seq,
|
||||
SpaDirection direction,
|
||||
uint32_t port_id,
|
||||
unsigned int n_buffers,
|
||||
PinosClientNodeBuffer *buffers)
|
||||
{
|
||||
PinosResource *resource = object;
|
||||
PinosProtocolNativeClient *client = resource->client->protocol_private;
|
||||
PinosMessageUseBuffers m = { seq, direction, port_id, n_buffers, buffers };
|
||||
|
||||
pinos_connection_add_message (client->connection,
|
||||
resource->id,
|
||||
PINOS_MESSAGE_USE_BUFFERS,
|
||||
&m);
|
||||
pinos_connection_flush (client->connection);
|
||||
}
|
||||
static void
|
||||
client_node_event_node_command (void *object,
|
||||
uint32_t seq,
|
||||
SpaNodeCommand *command)
|
||||
{
|
||||
PinosResource *resource = object;
|
||||
PinosProtocolNativeClient *client = resource->client->protocol_private;
|
||||
PinosMessageNodeCommand m = { seq, command };
|
||||
|
||||
pinos_connection_add_message (client->connection,
|
||||
resource->id,
|
||||
PINOS_MESSAGE_NODE_COMMAND,
|
||||
&m);
|
||||
pinos_connection_flush (client->connection);
|
||||
}
|
||||
static void
|
||||
client_node_event_port_command (void *object,
|
||||
uint32_t port_id,
|
||||
SpaNodeCommand *command)
|
||||
{
|
||||
PinosResource *resource = object;
|
||||
PinosProtocolNativeClient *client = resource->client->protocol_private;
|
||||
PinosMessagePortCommand m = { port_id, command };
|
||||
|
||||
pinos_connection_add_message (client->connection,
|
||||
resource->id,
|
||||
PINOS_MESSAGE_PORT_COMMAND,
|
||||
&m);
|
||||
pinos_connection_flush (client->connection);
|
||||
}
|
||||
|
||||
static void
|
||||
client_node_event_transport (void *object,
|
||||
int memfd,
|
||||
off_t offset,
|
||||
size_t size)
|
||||
{
|
||||
PinosResource *resource = object;
|
||||
PinosProtocolNativeClient *client = resource->client->protocol_private;
|
||||
PinosMessageTransportUpdate m = { memfd, offset, size };
|
||||
|
||||
pinos_connection_add_message (client->connection,
|
||||
resource->id,
|
||||
PINOS_MESSAGE_TRANSPORT_UPDATE,
|
||||
&m);
|
||||
pinos_connection_flush (client->connection);
|
||||
}
|
||||
|
||||
static void
|
||||
client_node_marshall_update (void *object,
|
||||
void *data,
|
||||
size_t size)
|
||||
{
|
||||
PinosResource *resource = object;
|
||||
PinosMessageNodeUpdate *m = data;
|
||||
pinos_client_node_do_update (resource,
|
||||
m->change_mask,
|
||||
m->max_input_ports,
|
||||
m->max_output_ports,
|
||||
m->props);
|
||||
}
|
||||
|
||||
static void
|
||||
client_node_marshall_port_update (void *object,
|
||||
void *data,
|
||||
size_t size)
|
||||
{
|
||||
PinosResource *resource = object;
|
||||
PinosMessagePortUpdate *m = data;
|
||||
pinos_client_node_do_port_update (resource,
|
||||
m->direction,
|
||||
m->port_id,
|
||||
m->change_mask,
|
||||
m->n_possible_formats,
|
||||
m->possible_formats,
|
||||
m->format,
|
||||
m->props,
|
||||
m->info);
|
||||
}
|
||||
|
||||
static void
|
||||
client_node_marshall_state_change (void *object,
|
||||
void *data,
|
||||
size_t size)
|
||||
{
|
||||
PinosResource *resource = object;
|
||||
PinosMessageNodeStateChange *m = data;
|
||||
pinos_client_node_do_state_change (resource, m->state);
|
||||
}
|
||||
|
||||
static void
|
||||
client_node_marshall_event (void *object,
|
||||
void *data,
|
||||
size_t size)
|
||||
{
|
||||
PinosResource *resource = object;
|
||||
PinosMessageNodeEvent *m = data;
|
||||
pinos_client_node_do_event (resource, m->event);
|
||||
}
|
||||
|
||||
static void
|
||||
client_node_marshall_destroy (void *object,
|
||||
void *data,
|
||||
size_t size)
|
||||
{
|
||||
PinosResource *resource = object;
|
||||
PinosMessageDestroy *m = data;
|
||||
pinos_client_node_do_destroy (resource, m->seq);
|
||||
}
|
||||
|
||||
static void
|
||||
link_event_info (void *object,
|
||||
PinosLinkInfo *info)
|
||||
{
|
||||
PinosResource *resource = object;
|
||||
PinosProtocolNativeClient *client = resource->client->protocol_private;
|
||||
PinosMessageLinkInfo m;
|
||||
|
||||
m.info = info;
|
||||
pinos_connection_add_message (client->connection,
|
||||
resource->id,
|
||||
PINOS_MESSAGE_LINK_INFO,
|
||||
&m);
|
||||
pinos_connection_flush (client->connection);
|
||||
}
|
||||
|
||||
static void
|
||||
on_resource_added (PinosListener *listener,
|
||||
PinosClient *client,
|
||||
PinosResource *resource)
|
||||
{
|
||||
if (resource->type == resource->core->uri.core) {
|
||||
static const PinosCoreEvent core_event = {
|
||||
&core_event_info,
|
||||
&core_event_done,
|
||||
&core_event_error,
|
||||
&core_event_remove_id
|
||||
};
|
||||
static const MarshallFunc core_marshall[] = {
|
||||
[PINOS_MESSAGE_CLIENT_UPDATE] = &core_marshall_client_update,
|
||||
[PINOS_MESSAGE_SYNC] = &core_marshall_sync,
|
||||
[PINOS_MESSAGE_GET_REGISTRY] = &core_marshall_get_registry,
|
||||
[PINOS_MESSAGE_CREATE_NODE] = &core_marshall_create_node,
|
||||
[PINOS_MESSAGE_CREATE_CLIENT_NODE] = &core_marshall_create_client_node
|
||||
};
|
||||
resource->event = &core_event;
|
||||
resource->marshall = &core_marshall;
|
||||
resource->event = &pinos_protocol_native_server_core_event;
|
||||
resource->marshall = &pinos_protocol_native_server_core_marshall;
|
||||
}
|
||||
else if (resource->type == resource->core->uri.registry) {
|
||||
static const PinosRegistryEvent registry_event = {
|
||||
®istry_event_global,
|
||||
®istry_event_global_remove,
|
||||
};
|
||||
static const MarshallFunc registry_marshall[] = {
|
||||
[PINOS_MESSAGE_BIND] = ®istry_marshall_bind,
|
||||
};
|
||||
resource->event = ®istry_event;
|
||||
resource->marshall = ®istry_marshall;
|
||||
resource->event = &pinos_protocol_native_server_registry_event;
|
||||
resource->marshall = &pinos_protocol_native_server_registry_marshall;
|
||||
}
|
||||
else if (resource->type == resource->core->uri.module) {
|
||||
static const PinosModuleEvent module_event = {
|
||||
&module_event_info,
|
||||
};
|
||||
resource->event = &module_event;
|
||||
resource->event = &pinos_protocol_native_server_module_event;
|
||||
resource->marshall = NULL;
|
||||
}
|
||||
else if (resource->type == resource->core->uri.node) {
|
||||
static const PinosNodeEvent node_event = {
|
||||
&node_event_done,
|
||||
&node_event_info,
|
||||
};
|
||||
resource->event = &node_event;
|
||||
resource->event = &pinos_protocol_native_server_node_event;
|
||||
resource->marshall = NULL;
|
||||
}
|
||||
else if (resource->type == resource->core->uri.client) {
|
||||
static const PinosClientEvent client_event = {
|
||||
&client_event_info,
|
||||
};
|
||||
resource->event = &client_event;
|
||||
resource->event = &pinos_protocol_native_server_client_event;
|
||||
resource->marshall = NULL;
|
||||
}
|
||||
else if (resource->type == resource->core->uri.client_node) {
|
||||
static const PinosClientNodeEvent client_node_events = {
|
||||
&client_node_event_done,
|
||||
&client_node_event_event,
|
||||
&client_node_event_add_port,
|
||||
&client_node_event_remove_port,
|
||||
&client_node_event_set_format,
|
||||
&client_node_event_set_property,
|
||||
&client_node_event_add_mem,
|
||||
&client_node_event_use_buffers,
|
||||
&client_node_event_node_command,
|
||||
&client_node_event_port_command,
|
||||
&client_node_event_transport,
|
||||
};
|
||||
static const MarshallFunc client_node_marshall[] = {
|
||||
[PINOS_MESSAGE_NODE_UPDATE] = &client_node_marshall_update,
|
||||
[PINOS_MESSAGE_PORT_UPDATE] = &client_node_marshall_port_update,
|
||||
[PINOS_MESSAGE_NODE_STATE_CHANGE] = &client_node_marshall_state_change,
|
||||
[PINOS_MESSAGE_NODE_EVENT] = &client_node_marshall_event,
|
||||
[PINOS_MESSAGE_DESTROY] = &client_node_marshall_destroy,
|
||||
};
|
||||
resource->event = &client_node_events;
|
||||
resource->marshall = &client_node_marshall;
|
||||
resource->event = &pinos_protocol_native_server_client_node_events;
|
||||
resource->marshall = &pinos_protocol_native_server_client_node_marshall;
|
||||
}
|
||||
else if (resource->type == resource->core->uri.link) {
|
||||
static const PinosLinkEvent link_event = {
|
||||
&link_event_info,
|
||||
};
|
||||
resource->event = &link_event;
|
||||
resource->event = &pinos_protocol_native_server_link_event;
|
||||
resource->marshall = NULL;
|
||||
}
|
||||
}
|
||||
|
|
@ -701,7 +153,7 @@ connection_data (SpaSource *source,
|
|||
while (pinos_connection_get_next (conn, &type, &id, &size)) {
|
||||
PinosResource *resource;
|
||||
void *message = alloca (size);
|
||||
const MarshallFunc *marshall;
|
||||
const PinosMarshallFunc *marshall;
|
||||
|
||||
pinos_log_debug ("protocol-native %p: got message %d from %u", client->impl, type, id);
|
||||
|
||||
|
|
@ -763,7 +215,7 @@ client_new (PinosProtocolNative *impl,
|
|||
if (client == NULL)
|
||||
goto no_client;
|
||||
|
||||
client->protocol_private = this;
|
||||
client->protocol_private = this->connection;
|
||||
|
||||
this->client = client;
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue