Rework serialization

Move serialization to the protocol, we now just send blocks of bytes
over the connection and let the protocol deserialize them.
This commit is contained in:
Wim Taymans 2017-03-06 15:48:04 +01:00
parent 842d73ca4b
commit 41399b0b25
26 changed files with 1617 additions and 2501 deletions

File diff suppressed because it is too large Load diff

View file

@ -25,300 +25,29 @@ extern "C" {
#endif
#include <spa/defs.h>
#include <spa/props.h>
#include <spa/format.h>
#include <spa/port.h>
#include <spa/node.h>
#include <pinos/client/interfaces.h>
typedef struct _PinosConnection PinosConnection;
typedef enum {
PINOS_MESSAGE_INVALID = 0,
PINOS_MESSAGE_CLIENT_UPDATE,
PINOS_MESSAGE_SYNC,
PINOS_MESSAGE_NOTIFY_DONE,
PINOS_MESSAGE_ERROR,
PINOS_MESSAGE_GET_REGISTRY,
PINOS_MESSAGE_REMOVE_ID,
PINOS_MESSAGE_CORE_INFO,
PINOS_MESSAGE_BIND,
PINOS_MESSAGE_NOTIFY_GLOBAL,
PINOS_MESSAGE_NOTIFY_GLOBAL_REMOVE,
PINOS_MESSAGE_CREATE_NODE,
PINOS_MESSAGE_CREATE_NODE_DONE,
PINOS_MESSAGE_CREATE_CLIENT_NODE,
PINOS_MESSAGE_CREATE_CLIENT_NODE_DONE,
PINOS_MESSAGE_DESTROY,
PINOS_MESSAGE_MODULE_INFO,
PINOS_MESSAGE_NODE_INFO,
PINOS_MESSAGE_CLIENT_INFO,
PINOS_MESSAGE_LINK_INFO,
/* client to server */
PINOS_MESSAGE_NODE_UPDATE,
PINOS_MESSAGE_PORT_UPDATE,
PINOS_MESSAGE_NODE_STATE_CHANGE,
PINOS_MESSAGE_NODE_EVENT,
/* server to client */
PINOS_MESSAGE_TRANSPORT_UPDATE,
PINOS_MESSAGE_ADD_PORT,
PINOS_MESSAGE_REMOVE_PORT,
PINOS_MESSAGE_SET_FORMAT,
PINOS_MESSAGE_SET_PROPERTY,
PINOS_MESSAGE_NODE_COMMAND,
PINOS_MESSAGE_PORT_COMMAND,
/* both */
PINOS_MESSAGE_ADD_MEM,
PINOS_MESSAGE_USE_BUFFERS,
} PinosMessageType;
#include <pinos/client/introspect.h>
/* PINOS_MESSAGE_CLIENT_UPDATE */
typedef struct {
const SpaDict *props;
} PinosMessageClientUpdate;
/* PINOS_MESSAGE_SYNC */
typedef struct {
uint32_t seq;
} PinosMessageSync;
/* PINOS_MESSAGE_NOTIFY_DONE */
typedef struct {
uint32_t seq;
} PinosMessageNotifyDone;
/* PINOS_MESSAGE_ERROR */
typedef struct {
uint32_t id;
SpaResult res;
const char *error;
} PinosMessageError;
/* PINOS_MESSAGE_GET_REGISTRY */
typedef struct {
uint32_t seq;
uint32_t new_id;
} PinosMessageGetRegistry;
/* PINOS_MESSAGE_REMOVE_ID */
typedef struct {
uint32_t id;
} PinosMessageRemoveId;
/* PINOS_MESSAGE_CORE_INFO */
typedef struct {
PinosCoreInfo *info;
} PinosMessageCoreInfo;
/* PINOS_MESSAGE_MODULE_INFO */
typedef struct {
PinosModuleInfo *info;
} PinosMessageModuleInfo;
/* PINOS_MESSAGE_NODE_INFO */
typedef struct {
PinosNodeInfo *info;
} PinosMessageNodeInfo;
/* PINOS_MESSAGE_CLIENT_INFO */
typedef struct {
PinosClientInfo *info;
} PinosMessageClientInfo;
/* PINOS_MESSAGE_LINK_INFO */
typedef struct {
PinosLinkInfo *info;
} PinosMessageLinkInfo;
/* PINOS_MESSAGE_BIND */
typedef struct {
uint32_t id;
uint32_t new_id;
} PinosMessageBind;
/* PINOS_MESSAGE_NOTIFY_GLOBAL */
typedef struct {
uint32_t id;
const char *type;
} PinosMessageNotifyGlobal;
/* PINOS_MESSAGE_NOTIFY_GLOBAL_REMOVE */
typedef struct {
uint32_t id;
} PinosMessageNotifyGlobalRemove;
/* PINOS_MESSAGE_CREATE_NODE */
typedef struct {
uint32_t seq;
const char *factory_name;
const char *name;
const SpaDict *props;
uint32_t new_id;
} PinosMessageCreateNode;
/* PINOS_MESSAGE_CREATE_NODE_DONE */
typedef struct {
uint32_t seq;
} PinosMessageCreateNodeDone;
/* PINOS_MESSAGE_CREATE_CLIENT_NODE */
typedef struct {
uint32_t seq;
const char *name;
const SpaDict *props;
uint32_t new_id;
} PinosMessageCreateClientNode;
/* PINOS_MESSAGE_CREATE_CLIENT_NODE_DONE */
typedef struct {
uint32_t seq;
int datafd;
} PinosMessageCreateClientNodeDone;
/* PINOS_MESSAGE_DESTROY */
typedef struct {
uint32_t seq;
} PinosMessageDestroy;
/* PINOS_MESSAGE_NODE_UPDATE */
typedef struct {
#define PINOS_MESSAGE_NODE_UPDATE_MAX_INPUTS (1 << 0)
#define PINOS_MESSAGE_NODE_UPDATE_MAX_OUTPUTS (1 << 1)
#define PINOS_MESSAGE_NODE_UPDATE_PROPS (1 << 2)
uint32_t change_mask;
unsigned int max_input_ports;
unsigned int max_output_ports;
const SpaProps *props;
} PinosMessageNodeUpdate;
/* PINOS_MESSAGE_PORT_UPDATE */
typedef struct {
SpaDirection direction;
uint32_t port_id;
#define PINOS_MESSAGE_PORT_UPDATE_POSSIBLE_FORMATS (1 << 0)
#define PINOS_MESSAGE_PORT_UPDATE_FORMAT (1 << 1)
#define PINOS_MESSAGE_PORT_UPDATE_PROPS (1 << 2)
#define PINOS_MESSAGE_PORT_UPDATE_INFO (1 << 3)
uint32_t change_mask;
unsigned int n_possible_formats;
SpaFormat **possible_formats;
SpaFormat *format;
const SpaProps *props;
const SpaPortInfo *info;
} PinosMessagePortUpdate;
/* PINOS_MESSAGE_NODE_STATE_CHANGE */
typedef struct {
SpaNodeState state;
} PinosMessageNodeStateChange;
/* PINOS_MESSAGE_NODE_EVENT */
typedef struct {
SpaNodeEvent *event;
} PinosMessageNodeEvent;
/* PINOS_MESSAGE_ADD_PORT */
typedef struct {
uint32_t seq;
SpaDirection direction;
uint32_t port_id;
} PinosMessageAddPort;
/* PINOS_MESSAGE_REMOVE_PORT */
typedef struct {
uint32_t seq;
SpaDirection direction;
uint32_t port_id;
} PinosMessageRemovePort;
/* PINOS_MESSAGE_SET_FORMAT */
typedef struct {
uint32_t seq;
SpaDirection direction;
uint32_t port_id;
SpaPortFormatFlags flags;
const SpaFormat *format;
} PinosMessageSetFormat;
/* PINOS_MESSAGE_SET_PROPERTY */
typedef struct {
uint32_t seq;
uint32_t id;
size_t size;
void *value;
} PinosMessageSetProperty;
/* PINOS_MESSAGE_NODE_COMMAND */
typedef struct {
uint32_t seq;
SpaNodeCommand *command;
} PinosMessageNodeCommand;
/* PINOS_MESSAGE_PORT_COMMAND */
typedef struct {
uint32_t port_id;
SpaNodeCommand *command;
} PinosMessagePortCommand;
/* PINOS_MESSAGE_TRANSPORT_UPDATE */
typedef struct {
int memfd;
off_t offset;
size_t size;
} PinosMessageTransportUpdate;
/* PINOS_MESSAGE_ADD_MEM */
typedef struct {
SpaDirection direction;
uint32_t port_id;
uint32_t mem_id;
SpaDataType type;
int memfd;
uint32_t flags;
off_t offset;
size_t size;
} PinosMessageAddMem;
/* PINOS_MESSAGE_USE_BUFFERS */
typedef struct {
uint32_t seq;
SpaDirection direction;
uint32_t port_id;
unsigned int n_buffers;
PinosClientNodeBuffer *buffers;
} PinosMessageUseBuffers;
PinosConnection * pinos_connection_new (int fd);
void pinos_connection_destroy (PinosConnection *conn);
int pinos_connection_add_fd (PinosConnection *conn,
int fd);
int pinos_connection_get_fd (PinosConnection *conn,
int index);
bool pinos_connection_get_next (PinosConnection *conn,
PinosMessageType *type,
uint8_t *opcode,
uint32_t *dest_id,
void **data,
size_t *size);
bool pinos_connection_parse_message (PinosConnection *conn,
void *msg);
bool pinos_connection_add_message (PinosConnection *conn,
void * pinos_connection_begin_write (PinosConnection *conn,
size_t size);
void pinos_connection_end_write (PinosConnection *conn,
uint32_t dest_id,
PinosMessageType type,
void *msg);
uint8_t opcode,
size_t size);
bool pinos_connection_flush (PinosConnection *conn);
bool pinos_connection_clear (PinosConnection *conn);

View file

@ -303,7 +303,7 @@ registry_event_global (void *object,
goto no_mem;
proxy->event = &node_events;
proxy->marshall = &pinos_protocol_native_client_node_marshall;
proxy->demarshal = &pinos_protocol_native_client_node_demarshal;
proxy->interface = NULL;
} else if (!strcmp (type, PINOS_MODULE_URI)) {
proxy = pinos_proxy_new (this,
@ -313,7 +313,7 @@ registry_event_global (void *object,
goto no_mem;
proxy->event = &module_events;
proxy->marshall = &pinos_protocol_native_client_module_marshall;
proxy->demarshal = &pinos_protocol_native_client_module_demarshal;
proxy->interface = NULL;
} else if (!strcmp (type, PINOS_CLIENT_URI)) {
proxy = pinos_proxy_new (this,
@ -323,7 +323,7 @@ registry_event_global (void *object,
goto no_mem;
proxy->event = &client_events;
proxy->marshall = &pinos_protocol_native_client_client_marshall;
proxy->demarshal = &pinos_protocol_native_client_client_demarshal;
proxy->interface = NULL;
} else if (!strcmp (type, PINOS_LINK_URI)) {
proxy = pinos_proxy_new (this,
@ -333,7 +333,7 @@ registry_event_global (void *object,
goto no_mem;
proxy->event = &link_events;
proxy->marshall = &pinos_protocol_native_client_link_marshall;
proxy->demarshal = &pinos_protocol_native_client_link_demarshal;
proxy->interface = NULL;
}
if (proxy)
@ -385,32 +385,27 @@ on_context_data (SpaSource *source,
if (mask & SPA_IO_IN) {
PinosConnection *conn = impl->connection;
PinosMessageType type;
uint8_t opcode;
uint32_t id;
size_t size;
void *message;
while (pinos_connection_get_next (conn, &type, &id, &size)) {
void *p = alloca (size);
while (pinos_connection_get_next (conn, &opcode, &id, &message, &size)) {
PinosProxy *proxy;
const PinosMarshallFunc *marshall;
if (!pinos_connection_parse_message (conn, p)) {
pinos_log_error ("context %p: failed to parse message", this);
continue;
}
const PinosDemarshalFunc *demarshal;
proxy = pinos_map_lookup (&this->objects, id);
if (proxy == NULL) {
pinos_log_error ("context %p: could not find proxy %u", this, id);
continue;
}
pinos_log_debug ("context %p: object marshall %u, %u", this, id, type);
pinos_log_debug ("context %p: object demarshal %u, %u", this, id, opcode);
marshall = proxy->marshall;
if (marshall[type])
marshall[type] (proxy, p, size);
demarshal = proxy->demarshal;
if (demarshal[opcode])
demarshal[opcode] (proxy, message, size);
else
pinos_log_error ("context %p: function %d not implemented", this, type);
pinos_log_error ("context %p: function %d not implemented", this, opcode);
}
}
@ -602,7 +597,7 @@ pinos_context_connect_fd (PinosContext *context,
context->core_proxy->event = &core_events;
context->core_proxy->interface = &pinos_protocol_native_client_core_interface;
context->core_proxy->marshall = &pinos_protocol_native_client_core_marshall;
context->core_proxy->demarshal = &pinos_protocol_native_client_core_demarshal;
pinos_core_do_client_update (context->core_proxy,
&context->properties->dict);
@ -615,7 +610,7 @@ pinos_context_connect_fd (PinosContext *context,
context->registry_proxy->event = &registry_events;
context->registry_proxy->interface = &pinos_protocol_native_client_registry_interface;
context->registry_proxy->marshall = &pinos_protocol_native_client_registry_marshall;
context->registry_proxy->demarshal = &pinos_protocol_native_client_registry_demarshal;
pinos_core_do_get_registry (context->core_proxy,
0,

View file

@ -34,12 +34,6 @@ typedef struct _PinosClientNodeBuffer PinosClientNodeBuffer;
#include <pinos/client/introspect.h>
#define PINOS_CORE_CLIENT_UPDATE 0
#define PINOS_CORE_SYNC 1
#define PINOS_CORE_GET_REGISTRY 2
#define PINOS_CORE_CREATE_NODE 3
#define PINOS_CORE_CREATE_CLIENT_NODE 4
typedef struct {
void (*client_update) (void *object,
const SpaDict *props);
@ -85,8 +79,6 @@ typedef struct {
#define pinos_core_notify_error(r,...) ((PinosCoreEvent*)r->event)->error(r,__VA_ARGS__)
#define pinos_core_notify_remove_id(r,...) ((PinosCoreEvent*)r->event)->remove_id(r,__VA_ARGS__)
#define PINOS_REGISTRY_BIND 0
typedef struct {
void (*bind) (void *object,
uint32_t id,
@ -123,17 +115,11 @@ typedef struct {
#define pinos_node_notify_done(r,...) ((PinosNodeEvent*)r->event)->done(r,__VA_ARGS__)
#define pinos_node_notify_info(r,...) ((PinosNodeEvent*)r->event)->info(r,__VA_ARGS__)
#define PINOS_CLIENT_NODE_UPDATE 0
#define PINOS_CLIENT_NODE_PORT_UPDATE 1
#define PINOS_CLIENT_NODE_STATE_CHANGE 2
#define PINOS_CLIENT_NODE_EVENT 3
#define PINOS_CLIENT_NODE_DESTROY 4
struct _PinosClientNodeBuffer {
SpaBuffer *buffer;
uint32_t mem_id;
off_t offset;
size_t size;
SpaBuffer *buffer;
};
typedef struct {
@ -155,8 +141,8 @@ typedef struct {
#define PINOS_MESSAGE_PORT_UPDATE_INFO (1 << 3)
uint32_t change_mask,
unsigned int n_possible_formats,
SpaFormat **possible_formats,
SpaFormat *format,
const SpaFormat **possible_formats,
const SpaFormat *format,
const SpaProps *props,
const SpaPortInfo *info);
void (*state_change) (void *object,
@ -177,8 +163,8 @@ typedef struct {
void (*done) (void *object,
uint32_t seq,
int datafd);
void (*event) (void *object,
SpaNodeEvent *event);
void (*event) (void *object,
const SpaNodeEvent *event);
void (*add_port) (void *object,
uint32_t seq,
SpaDirection direction,
@ -197,7 +183,7 @@ typedef struct {
uint32_t seq,
uint32_t id,
size_t size,
void *value);
const void *value);
void (*add_mem) (void *object,
SpaDirection direction,
uint32_t port_id,
@ -215,10 +201,10 @@ typedef struct {
PinosClientNodeBuffer *buffers);
void (*node_command) (void *object,
uint32_t seq,
SpaNodeCommand *command);
const SpaNodeCommand *command);
void (*port_command) (void *object,
uint32_t port_id,
SpaNodeCommand *command);
const SpaNodeCommand *command);
void (*transport) (void *object,
int memfd,
off_t offset,

View file

@ -20,7 +20,6 @@
#include <string.h>
#include "pinos/client/pinos.h"
#include "pinos/client/serialize.h"
#include "pinos/client/context.h"
#include "pinos/client/subscribe.h"
@ -254,8 +253,8 @@ pinos_node_info_update (PinosNodeInfo *info,
info->input_formats = NULL;
}
for (i = 0; i < info->n_input_formats; i++) {
size = pinos_serialize_format_get_size (update->input_formats[i]);
info->input_formats[i] = size ? pinos_serialize_format_copy_into (malloc (size), update->input_formats[i]) : NULL;
size = SPA_POD_SIZE (update->input_formats[i]);
info->input_formats[i] = memcpy (malloc (size), update->input_formats[i], size);
}
}
if (update->change_mask & (1 << 3))
@ -271,8 +270,8 @@ pinos_node_info_update (PinosNodeInfo *info,
info->output_formats = NULL;
}
for (i = 0; i < info->n_output_formats; i++) {
size = pinos_serialize_format_get_size (update->output_formats[i]);
info->output_formats[i] = size ? pinos_serialize_format_copy_into (malloc (size), update->output_formats[i]) : NULL;
size = SPA_POD_SIZE (update->output_formats[i]);
info->output_formats[i] = memcpy (malloc (size), update->output_formats[i], size);
}
}

View file

@ -21,6 +21,7 @@
#define __PINOS_INTROSPECT_H__
#include <spa/include/spa/defs.h>
#include <spa/include/spa/format.h>
#ifdef __cplusplus
extern "C" {

File diff suppressed because it is too large Load diff

View file

@ -18,17 +18,18 @@
*/
#include "pinos/client/pinos.h"
#include "pinos/client/interfaces.h"
typedef void (*PinosMarshallFunc) (void *object, void *data, size_t size);
typedef void (*PinosDemarshalFunc) (void *object, void *data, size_t size);
extern const PinosCoreInterface pinos_protocol_native_client_core_interface;
extern const PinosRegistryInterface pinos_protocol_native_client_registry_interface;
extern const PinosClientNodeInterface pinos_protocol_native_client_client_node_interface;
extern const PinosMarshallFunc pinos_protocol_native_client_core_marshall[];
extern const PinosMarshallFunc pinos_protocol_native_client_module_marshall[];
extern const PinosMarshallFunc pinos_protocol_native_client_node_marshall[];
extern const PinosMarshallFunc pinos_protocol_native_client_client_node_marshall[];
extern const PinosMarshallFunc pinos_protocol_native_client_client_marshall[];
extern const PinosMarshallFunc pinos_protocol_native_client_link_marshall[];
extern const PinosMarshallFunc pinos_protocol_native_client_registry_marshall[];
extern const PinosDemarshalFunc pinos_protocol_native_client_core_demarshal[];
extern const PinosDemarshalFunc pinos_protocol_native_client_module_demarshal[];
extern const PinosDemarshalFunc pinos_protocol_native_client_node_demarshal[];
extern const PinosDemarshalFunc pinos_protocol_native_client_client_node_demarshal[];
extern const PinosDemarshalFunc pinos_protocol_native_client_client_demarshal[];
extern const PinosDemarshalFunc pinos_protocol_native_client_link_demarshal[];
extern const PinosDemarshalFunc pinos_protocol_native_client_registry_demarshal[];

View file

@ -40,7 +40,7 @@ struct _PinosProxy {
const void *interface;
const void *event;
const void *marshall;
const void *demarshal;
PINOS_SIGNAL (destroy_signal, (PinosListener *listener,
PinosProxy *proxy));

View file

@ -89,45 +89,6 @@ pinos_serialize_buffer_copy_into (void *dest, const SpaBuffer *buffer)
return pinos_serialize_buffer_deserialize (dest, 0);
}
size_t
pinos_serialize_format_get_size (const SpaFormat *format)
{
if (format == NULL)
return 0;
return SPA_POD_SIZE (format);
}
size_t
pinos_serialize_format_serialize (void *dest, const SpaFormat *format)
{
size_t size;
if (format == NULL)
return 0;
size = SPA_POD_SIZE (format);
memcpy (dest, format, size);
return size;
}
SpaFormat *
pinos_serialize_format_deserialize (void *src, off_t offset)
{
return SPA_MEMBER (src, offset, SpaFormat);
}
SpaFormat *
pinos_serialize_format_copy_into (void *dest, const SpaFormat *format)
{
if (format == NULL)
return NULL;
pinos_serialize_format_serialize (dest, format);
return pinos_serialize_format_deserialize (dest, 0);
}
size_t
pinos_serialize_port_info_get_size (const SpaPortInfo *info)
{
@ -201,130 +162,3 @@ pinos_serialize_port_info_copy_into (void *dest, const SpaPortInfo *info)
pinos_serialize_port_info_serialize (dest, info);
return pinos_serialize_port_info_deserialize (dest, 0);
}
size_t
pinos_serialize_props_get_size (const SpaProps *props)
{
if (props == NULL)
return 0;
return SPA_POD_SIZE (props);
}
size_t
pinos_serialize_props_serialize (void *p, const SpaProps *props)
{
size_t size;
if (props == NULL)
return 0;
size = SPA_POD_SIZE (props);
memcpy (p, props, size);
return size;
}
SpaProps *
pinos_serialize_props_deserialize (void *p, off_t offset)
{
return SPA_MEMBER (p, offset, SpaProps);
}
SpaProps *
pinos_serialize_props_copy_into (void *dest, const SpaProps *props)
{
if (props == NULL)
return NULL;
pinos_serialize_props_serialize (dest, props);
return pinos_serialize_props_deserialize (dest, 0);
}
size_t
pinos_serialize_dict_get_size (const SpaDict *dict)
{
size_t len;
unsigned int i;
if (dict == NULL)
return 0;
len = sizeof (SpaDict);
len += dict->n_items * sizeof (SpaDictItem);
for (i = 0; i < dict->n_items; i++) {
SpaDictItem *di = &dict->items[i];
len += di->key ? strlen (di->key) + 1 : 0;
len += di->value ? strlen (di->value) + 1 : 0;
}
return len;
}
size_t
pinos_serialize_dict_serialize (void *p, const SpaDict *dict)
{
SpaDict *pi;
SpaDictItem *di;
int i;
size_t len;
if (dict == NULL)
return 0;
pi = p;
memcpy (pi, dict, sizeof (SpaDict));
di = SPA_MEMBER (pi, sizeof (SpaDict), SpaDictItem);
if (dict->n_items)
pi->items = SPA_INT_TO_PTR (SPA_PTRDIFF (di, pi));
else
pi->items = 0;
p = SPA_MEMBER (di, sizeof (SpaDictItem) * dict->n_items, void);
for (i = 0; i < dict->n_items; i++) {
if (dict->items[i].key) {
len = strlen (dict->items[i].key) + 1;
memcpy (p, dict->items[i].key, len);
di[i].key = SPA_INT_TO_PTR (SPA_PTRDIFF (p, pi));
p += len;
} else {
di[i].key = NULL;
}
if (dict->items[i].value) {
len = strlen (dict->items[i].value) + 1;
memcpy (p, dict->items[i].value, len);
di[i].value = SPA_INT_TO_PTR (SPA_PTRDIFF (p, pi));
p += len;
} else {
di[i].value = NULL;
}
}
return SPA_PTRDIFF (p, pi);
}
SpaDict *
pinos_serialize_dict_deserialize (void *p, off_t offset)
{
SpaDict *pi;
unsigned int i;
pi = SPA_MEMBER (p, offset, SpaDict);
if (pi->items)
pi->items = SPA_MEMBER (pi, SPA_PTR_TO_INT (pi->items), SpaDictItem);
for (i = 0; i < pi->n_items; i++) {
pi->items[i].key = SPA_MEMBER (pi, SPA_PTR_TO_INT (pi->items[i].key), char);
pi->items[i].value = SPA_MEMBER (pi, SPA_PTR_TO_INT (pi->items[i].value), char);
}
return pi;
}
SpaDict *
pinos_serialize_dict_copy_into (void *dest, const SpaDict *dict)
{
if (dict == NULL)
return NULL;
pinos_serialize_dict_serialize (dest, dict);
return pinos_serialize_dict_deserialize (dest, 0);
}

View file

@ -34,26 +34,11 @@ size_t pinos_serialize_buffer_serialize (void *dest, const SpaBuff
SpaBuffer * pinos_serialize_buffer_deserialize (void *src, off_t offset);
SpaBuffer * pinos_serialize_buffer_copy_into (void *dest, const SpaBuffer *buffer);
size_t pinos_serialize_format_get_size (const SpaFormat *format);
size_t pinos_serialize_format_serialize (void *dest, const SpaFormat *format);
SpaFormat * pinos_serialize_format_deserialize (void *src, off_t offset);
SpaFormat * pinos_serialize_format_copy_into (void *dest, const SpaFormat *format);
size_t pinos_serialize_port_info_get_size (const SpaPortInfo *info);
size_t pinos_serialize_port_info_serialize (void *dest, const SpaPortInfo *info);
SpaPortInfo * pinos_serialize_port_info_deserialize (void *src, off_t offset);
SpaPortInfo * pinos_serialize_port_info_copy_into (void *dest, const SpaPortInfo *info);
size_t pinos_serialize_props_get_size (const SpaProps *props);
size_t pinos_serialize_props_serialize (void *dest, const SpaProps *props);
SpaProps * pinos_serialize_props_deserialize (void *src, off_t offset);
SpaProps * pinos_serialize_props_copy_into (void *dest, const SpaProps *props);
size_t pinos_serialize_dict_get_size (const SpaDict *dict);
size_t pinos_serialize_dict_serialize (void *dest, const SpaDict *dict);
SpaDict * pinos_serialize_dict_deserialize (void *src, off_t offset);
SpaDict * pinos_serialize_dict_copy_into (void *dest, const SpaDict *dict);
#ifdef __cplusplus
}
#endif

View file

@ -27,6 +27,7 @@
#include "spa/lib/debug.h"
#include "pinos/client/pinos.h"
#include "pinos/client/interfaces.h"
#include "pinos/client/protocol-native.h"
#include "pinos/client/array.h"
#include "pinos/client/connection.h"
@ -34,6 +35,7 @@
#include "pinos/client/stream.h"
#include "pinos/client/serialize.h"
#include "pinos/client/transport.h"
#include "pinos/client/utils.h"
#define MAX_BUFFER_SIZE 4096
#define MAX_FDS 32
@ -344,8 +346,8 @@ add_port_update (PinosStream *stream, uint32_t change_mask, bool flush)
impl->port_id,
change_mask,
impl->n_possible_formats,
impl->possible_formats,
impl->format,
(const SpaFormat **) impl->possible_formats,
(const SpaFormat *) impl->format,
NULL,
&impl->port_info);
}
@ -582,8 +584,8 @@ handle_socket (PinosStream *stream, int rtfd)
}
static void
handle_node_event (PinosStream *stream,
SpaNodeEvent *event)
handle_node_event (PinosStream *stream,
const SpaNodeEvent *event)
{
switch (event->type) {
case SPA_NODE_EVENT_TYPE_INVALID:
@ -601,9 +603,9 @@ handle_node_event (PinosStream *stream,
}
static bool
handle_node_command (PinosStream *stream,
uint32_t seq,
SpaNodeCommand *command)
handle_node_command (PinosStream *stream,
uint32_t seq,
const SpaNodeCommand *command)
{
PinosStreamImpl *impl = SPA_CONTAINER_OF (stream, PinosStreamImpl, this);
@ -671,8 +673,8 @@ client_node_done (void *object,
}
static void
client_node_event (void *object,
SpaNodeEvent *event)
client_node_event (void *object,
const SpaNodeEvent *event)
{
PinosProxy *proxy = object;
PinosStream *stream = proxy->user_data;
@ -708,13 +710,10 @@ client_node_set_format (void *object,
PinosProxy *proxy = object;
PinosStream *stream = proxy->user_data;
PinosStreamImpl *impl = SPA_CONTAINER_OF (stream, PinosStreamImpl, this);
void *mem;
if (impl->format)
free (impl->format);
mem = malloc (pinos_serialize_format_get_size (format));
impl->format = pinos_serialize_format_copy_into (mem, format);
impl->format = spa_format_copy (format);
impl->pending_seq = seq;
pinos_signal_emit (&stream->format_changed, stream, impl->format);
@ -722,11 +721,11 @@ client_node_set_format (void *object,
}
static void
client_node_set_property (void *object,
uint32_t seq,
uint32_t id,
size_t size,
void *value)
client_node_set_property (void *object,
uint32_t seq,
uint32_t id,
size_t size,
const void *value)
{
pinos_log_warn ("set property not implemented");
}
@ -874,9 +873,9 @@ client_node_use_buffers (void *object,
}
static void
client_node_node_command (void *object,
uint32_t seq,
SpaNodeCommand *command)
client_node_node_command (void *object,
uint32_t seq,
const SpaNodeCommand *command)
{
PinosProxy *proxy = object;
PinosStream *stream = proxy->user_data;
@ -884,9 +883,9 @@ client_node_node_command (void *object,
}
static void
client_node_port_command (void *object,
uint32_t port_id,
SpaNodeCommand *command)
client_node_port_command (void *object,
uint32_t port_id,
const SpaNodeCommand *command)
{
pinos_log_warn ("port command not supported");
}
@ -1000,7 +999,7 @@ pinos_stream_connect (PinosStream *stream,
impl->node_proxy->user_data = stream;
impl->node_proxy->event = &client_node_events;
impl->node_proxy->interface = &pinos_protocol_native_client_client_node_interface;
impl->node_proxy->marshall = &pinos_protocol_native_client_client_node_marshall;
impl->node_proxy->demarshal = &pinos_protocol_native_client_client_node_demarshal;
pinos_core_do_create_client_node (stream->context->core_proxy,
++impl->seq,

View file

@ -25,6 +25,7 @@ extern "C" {
#endif
#include <spa/defs.h>
#include <spa/pod.h>
const char * pinos_split_walk (const char *str,
const char *delimiter,
@ -39,6 +40,15 @@ void pinos_free_strv (char **str);
char * pinos_strip (char *str,
const char *whitespace);
static inline SpaPOD *
pinos_spa_pod_copy (const SpaPOD *pod)
{
return pod ? memcpy (malloc (SPA_POD_SIZE (pod)), pod, SPA_POD_SIZE (pod)) : NULL;
}
#define spa_format_copy(f) ((SpaFormat*)pinos_spa_pod_copy(&(f)->pod))
#define spa_props_copy(p) ((SpaProps*)pinos_spa_pod_copy(&(p)->pod))
#ifdef __cplusplus
} /* extern "C" */
#endif

View file

@ -63,8 +63,9 @@ do_check_send (PinosListener *listener,
PinosCore *core = client->core;
if (data->resource->type == core->uri.registry) {
#if 0
switch (data->opcode) {
case PINOS_MESSAGE_NOTIFY_GLOBAL:
case 0:
{
PinosMessageNotifyGlobal *m = data->message;
@ -74,7 +75,7 @@ do_check_send (PinosListener *listener,
data->res = SPA_RESULT_SKIPPED;
break;
}
case PINOS_MESSAGE_NOTIFY_GLOBAL_REMOVE:
case 1:
{
PinosMessageNotifyGlobalRemove *m = data->message;
@ -89,6 +90,7 @@ do_check_send (PinosListener *listener,
data->res = SPA_RESULT_NO_PERMISSION;
break;
}
#endif
}
else {
data->res = SPA_RESULT_OK;
@ -104,7 +106,8 @@ do_check_dispatch (PinosListener *listener,
PinosCore *core = client->core;
if (data->resource->type == core->uri.registry) {
if (data->opcode == PINOS_MESSAGE_BIND) {
#if 0
if (data->opcode == 0) {
PinosMessageBind *m = data->message;
if (check_global_owner (core, client, m->id))
@ -114,6 +117,7 @@ do_check_dispatch (PinosListener *listener,
} else {
data->res = SPA_RESULT_NO_PERMISSION;
}
#endif
}
else {
data->res = SPA_RESULT_OK;

View file

@ -103,31 +103,31 @@ on_resource_added (PinosListener *listener,
{
if (resource->type == resource->core->uri.core) {
resource->event = &pinos_protocol_native_server_core_event;
resource->marshall = &pinos_protocol_native_server_core_marshall;
resource->demarshal = &pinos_protocol_native_server_core_demarshal;
}
else if (resource->type == resource->core->uri.registry) {
resource->event = &pinos_protocol_native_server_registry_event;
resource->marshall = &pinos_protocol_native_server_registry_marshall;
resource->demarshal = &pinos_protocol_native_server_registry_demarshal;
}
else if (resource->type == resource->core->uri.module) {
resource->event = &pinos_protocol_native_server_module_event;
resource->marshall = NULL;
resource->demarshal = NULL;
}
else if (resource->type == resource->core->uri.node) {
resource->event = &pinos_protocol_native_server_node_event;
resource->marshall = NULL;
resource->demarshal = NULL;
}
else if (resource->type == resource->core->uri.client) {
resource->event = &pinos_protocol_native_server_client_event;
resource->marshall = NULL;
resource->demarshal = NULL;
}
else if (resource->type == resource->core->uri.client_node) {
resource->event = &pinos_protocol_native_server_client_node_events;
resource->marshall = &pinos_protocol_native_server_client_node_marshall;
resource->demarshal = &pinos_protocol_native_server_client_node_demarshal;
}
else if (resource->type == resource->core->uri.link) {
resource->event = &pinos_protocol_native_server_link_event;
resource->marshall = NULL;
resource->demarshal = NULL;
}
}
@ -139,10 +139,11 @@ connection_data (SpaSource *source,
{
PinosProtocolNativeClient *client = data;
PinosConnection *conn = client->connection;
PinosMessageType type;
uint8_t opcode;
uint32_t id;
size_t size;
PinosClient *c = client->client;
void *message;
if (mask & (SPA_IO_ERR | SPA_IO_HUP)) {
pinos_log_debug ("protocol-native %p: got connection error", client->impl);
@ -150,28 +151,22 @@ connection_data (SpaSource *source,
return;
}
while (pinos_connection_get_next (conn, &type, &id, &size)) {
while (pinos_connection_get_next (conn, &opcode, &id, &message, &size)) {
PinosResource *resource;
void *message = alloca (size);
const PinosMarshallFunc *marshall;
const PinosDemarshalFunc *demarshal;
pinos_log_debug ("protocol-native %p: got message %d from %u", client->impl, type, id);
if (!pinos_connection_parse_message (conn, message)) {
pinos_log_error ("protocol-native %p: failed to parse message", client->impl);
continue;
}
pinos_log_debug ("protocol-native %p: got message %d from %u", client->impl, opcode, id);
resource = pinos_map_lookup (&c->objects, id);
if (resource == NULL) {
pinos_log_error ("protocol-native %p: unknown resource %u", client->impl, id);
continue;
}
marshall = resource->marshall;
if (marshall[type])
marshall[type] (resource, message, size);
demarshal = resource->demarshal;
if (demarshal[opcode])
demarshal[opcode] (resource, message, size);
else
pinos_log_error ("protocol-native %p: function %d not implemented", client->impl, type);
pinos_log_error ("protocol-native %p: function %d not implemented", client->impl, opcode);
}
}

View file

@ -314,8 +314,8 @@ do_update_port (SpaProxy *this,
uint32_t port_id,
uint32_t change_mask,
unsigned int n_possible_formats,
SpaFormat **possible_formats,
SpaFormat *format,
const SpaFormat **possible_formats,
const SpaFormat *format,
const SpaProps *props,
const SpaPortInfo *info)
{
@ -340,15 +340,13 @@ do_update_port (SpaProxy *this,
port->formats = NULL;
}
for (i = 0; i < port->n_formats; i++) {
size = pinos_serialize_format_get_size (possible_formats[i]);
port->formats[i] = size ? pinos_serialize_format_copy_into (malloc (size), possible_formats[i]) : NULL;
port->formats[i] = spa_format_copy (possible_formats[i]);
}
}
if (change_mask & PINOS_MESSAGE_PORT_UPDATE_FORMAT) {
if (port->format)
free (port->format);
size = pinos_serialize_format_get_size (format);
port->format = size ? pinos_serialize_format_copy_into (malloc (size), format) : NULL;
port->format = spa_format_copy (format);
}
if (change_mask & PINOS_MESSAGE_PORT_UPDATE_PROPS) {
@ -912,8 +910,8 @@ client_node_port_update (void *object,
uint32_t port_id,
uint32_t change_mask,
unsigned int n_possible_formats,
SpaFormat **possible_formats,
SpaFormat *format,
const SpaFormat **possible_formats,
const SpaFormat *format,
const SpaProps *props,
const SpaPortInfo *info)
{
@ -961,8 +959,8 @@ client_node_state_change (void *object,
}
static void
client_node_event (void *object,
SpaNodeEvent *event)
client_node_event (void *object,
SpaNodeEvent *event)
{
PinosResource *resource = object;
PinosClientNode *node = resource->object;

View file

@ -54,10 +54,6 @@ void pinos_client_node_destroy (PinosClientNode *node);
SpaResult pinos_client_node_get_data_socket (PinosClientNode *node, int *fd);
SpaResult pinos_client_node_dispatch_message (PinosClientNode *node,
PinosMessageType type,
void *message);
#ifdef __cplusplus
}
#endif

View file

@ -23,7 +23,6 @@
#include "pinos/client/pinos.h"
#include "pinos/client/interfaces.h"
#include "pinos/client/serialize.h"
#include "pinos/server/node.h"
#include "pinos/server/data-loop.h"
@ -404,7 +403,6 @@ node_bind_func (PinosGlobal *global,
info.input_formats = NULL;
for (info.n_input_formats = 0; ; info.n_input_formats++) {
SpaFormat *fmt;
void *p;
if (spa_node_port_enum_formats (this->node,
SPA_DIRECTION_INPUT,
@ -415,16 +413,13 @@ node_bind_func (PinosGlobal *global,
break;
info.input_formats = realloc (info.input_formats, sizeof (SpaFormat*) * (info.n_input_formats + 1));
p = malloc (pinos_serialize_format_get_size (fmt));
info.input_formats[info.n_input_formats] = pinos_serialize_format_copy_into (p, fmt);
info.input_formats[info.n_input_formats] = spa_format_copy (fmt);
}
info.max_outputs = this->transport->area->max_outputs;
info.n_outputs = this->transport->area->n_outputs;
info.output_formats = NULL;
for (info.n_output_formats = 0; ; info.n_output_formats++) {
SpaFormat *fmt;
void *p;
if (spa_node_port_enum_formats (this->node,
SPA_DIRECTION_OUTPUT,
@ -435,9 +430,7 @@ node_bind_func (PinosGlobal *global,
break;
info.output_formats = realloc (info.output_formats, sizeof (SpaFormat*) * (info.n_output_formats + 1));
p = malloc (pinos_serialize_format_get_size (fmt));
info.output_formats[info.n_output_formats] = pinos_serialize_format_copy_into (p, fmt);
info.output_formats[info.n_output_formats] = spa_format_copy (fmt);
}
info.state = this->state;
info.error = this->error;

File diff suppressed because it is too large Load diff

View file

@ -19,7 +19,7 @@
#include "pinos/client/pinos.h"
typedef void (*PinosMarshallFunc) (void *object, void *data, size_t size);
typedef void (*PinosDemarshalFunc) (void *object, void *data, size_t size);
extern const PinosCoreEvent pinos_protocol_native_server_core_event;
extern const PinosRegistryEvent pinos_protocol_native_server_registry_event;
@ -29,6 +29,6 @@ extern const PinosClientEvent pinos_protocol_native_server_client_event;
extern const PinosClientNodeEvent pinos_protocol_native_server_client_node_events;
extern const PinosLinkEvent pinos_protocol_native_server_link_event;
extern const PinosMarshallFunc pinos_protocol_native_server_core_marshall[];
extern const PinosMarshallFunc pinos_protocol_native_server_registry_marshall[];
extern const PinosMarshallFunc pinos_protocol_native_server_client_node_marshall[];
extern const PinosDemarshalFunc pinos_protocol_native_server_core_demarshal[];
extern const PinosDemarshalFunc pinos_protocol_native_server_registry_demarshal[];
extern const PinosDemarshalFunc pinos_protocol_native_server_client_node_demarshal[];

View file

@ -50,7 +50,7 @@ struct _PinosResource {
const void *interface;
const void *event;
const void *marshall;
const void *demarshal;
PINOS_SIGNAL (destroy_signal, (PinosListener *listener,
PinosResource *resource));