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

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);
}
}