Add update_uris method and event

Add a way to send mapper updates between client and server and a way
to map between client and server types.
This commit is contained in:
Wim Taymans 2017-03-14 20:18:31 +01:00
parent 997aa036ba
commit c1cf1e6f67
8 changed files with 302 additions and 21 deletions

View file

@ -157,11 +157,30 @@ core_event_remove_id (void *object,
}
}
static void
core_event_update_uris (void *object,
uint32_t first_id,
uint32_t n_uris,
const char **uris)
{
PinosProxy *proxy = object;
PinosContext *this = proxy->context;
int i;
for (i = 0; i < n_uris; i++, first_id++) {
uint32_t this_id = spa_id_map_get_id (this->uri.map, uris[i]);
printf ("update %d %s -> %d\n", first_id, uris[i], this_id);
if (!pinos_map_insert_at (&this->uris, first_id, SPA_UINT32_TO_PTR (this_id)))
pinos_log_error ("can't add uri for client");
}
}
static const PinosCoreEvents core_events = {
&core_event_info,
&core_event_done,
&core_event_error,
&core_event_remove_id
&core_event_remove_id,
&core_event_update_uris
};
static void
@ -460,6 +479,7 @@ pinos_context_new (PinosLoop *loop,
on_before_iterate);
pinos_map_init (&this->objects, 64);
pinos_map_init (&this->uris, 64);
spa_list_init (&this->stream_list);
spa_list_init (&this->global_list);

View file

@ -68,6 +68,8 @@ struct _PinosContext {
PinosProxy *registry_proxy;
PinosMap objects;
uint32_t n_uris;
PinosMap uris;
SpaList global_list;
SpaList stream_list;

View file

@ -58,6 +58,10 @@ typedef struct {
const char *name,
const SpaDict *props,
uint32_t new_id);
void (*update_uris) (void *object,
uint32_t first_id,
uint32_t n_uris,
const char **uris);
} PinosCoreMethods;
#define pinos_core_do_client_update(r,...) ((PinosCoreMethods*)r->iface->methods)->client_update(r,__VA_ARGS__)
@ -65,6 +69,7 @@ typedef struct {
#define pinos_core_do_get_registry(r,...) ((PinosCoreMethods*)r->iface->methods)->get_registry(r,__VA_ARGS__)
#define pinos_core_do_create_node(r,...) ((PinosCoreMethods*)r->iface->methods)->create_node(r,__VA_ARGS__)
#define pinos_core_do_create_client_node(r,...) ((PinosCoreMethods*)r->iface->methods)->create_client_node(r,__VA_ARGS__)
#define pinos_core_do_update_uris(r,...) ((PinosCoreMethods*)r->iface->methods)->update_uris(r,__VA_ARGS__)
typedef struct {
void (*info) (void *object,
@ -74,15 +79,20 @@ typedef struct {
void (*error) (void *object,
uint32_t id,
SpaResult res,
const char *error, ...);
const char *error, ...);
void (*remove_id) (void *object,
uint32_t id);
void (*update_uris) (void *object,
uint32_t first_id,
uint32_t n_uris,
const char **uris);
} PinosCoreEvents;
#define pinos_core_notify_info(r,...) ((PinosCoreEvents*)r->iface->events)->info(r,__VA_ARGS__)
#define pinos_core_notify_done(r,...) ((PinosCoreEvents*)r->iface->events)->done(r,__VA_ARGS__)
#define pinos_core_notify_error(r,...) ((PinosCoreEvents*)r->iface->events)->error(r,__VA_ARGS__)
#define pinos_core_notify_remove_id(r,...) ((PinosCoreEvents*)r->iface->events)->remove_id(r,__VA_ARGS__)
#define pinos_core_notify_info(r,...) ((PinosCoreEvents*)r->iface->events)->info(r,__VA_ARGS__)
#define pinos_core_notify_done(r,...) ((PinosCoreEvents*)r->iface->events)->done(r,__VA_ARGS__)
#define pinos_core_notify_error(r,...) ((PinosCoreEvents*)r->iface->events)->error(r,__VA_ARGS__)
#define pinos_core_notify_remove_id(r,...) ((PinosCoreEvents*)r->iface->events)->remove_id(r,__VA_ARGS__)
#define pinos_core_notify_update_uris(r,...) ((PinosCoreEvents*)r->iface->events)->update_uris(r,__VA_ARGS__)
typedef struct {
void (*bind) (void *object,

View file

@ -47,6 +47,28 @@ write_pod (SpaPODBuilder *b, uint32_t ref, const void *data, uint32_t size)
return ref;
}
static void
core_update_map (PinosContext *context)
{
uint32_t diff, base, i;
const char **uris;
base = context->n_uris;
diff = spa_id_map_get_size (context->uri.map) - base;
if (diff == 0)
return;
uris = alloca (diff * sizeof (char *));
for (i = 0; i < diff; i++, base++)
uris[i] = spa_id_map_get_uri (context->uri.map, base);
pinos_core_do_update_uris (context->core_proxy,
context->n_uris,
diff,
uris);
context->n_uris += diff;
}
static void
core_marshal_client_update (void *object,
const SpaDict *props)
@ -57,6 +79,8 @@ core_marshal_client_update (void *object,
SpaPODFrame f;
int i, n_items;
core_update_map (proxy->context);
n_items = props ? props->n_items : 0;
spa_pod_builder_add (&b.b,
@ -83,6 +107,8 @@ core_marshal_sync (void *object,
Builder b = { { NULL, 0, 0, NULL, write_pod }, connection };
SpaPODFrame f;
core_update_map (proxy->context);
spa_pod_builder_add (&b.b,
SPA_POD_TYPE_STRUCT, &f,
SPA_POD_TYPE_INT, seq,
@ -101,6 +127,8 @@ core_marshal_get_registry (void *object,
Builder b = { { NULL, 0, 0, NULL, write_pod }, connection };
SpaPODFrame f;
core_update_map (proxy->context);
spa_pod_builder_add (&b.b,
SPA_POD_TYPE_STRUCT, &f,
SPA_POD_TYPE_INT, new_id,
@ -123,6 +151,8 @@ core_marshal_create_node (void *object,
SpaPODFrame f;
uint32_t i, n_items;
core_update_map (proxy->context);
n_items = props ? props->n_items : 0;
spa_pod_builder_add (&b.b,
@ -156,6 +186,8 @@ core_marshal_create_client_node (void *object,
SpaPODFrame f;
uint32_t i, n_items;
core_update_map (proxy->context);
n_items = props ? props->n_items : 0;
spa_pod_builder_add (&b.b,
@ -176,6 +208,33 @@ core_marshal_create_client_node (void *object,
pinos_connection_end_write (connection, proxy->id, 4, b.b.offset);
}
static void
core_marshal_update_uris (void *object,
uint32_t first_id,
uint32_t n_uris,
const char **uris)
{
PinosProxy *proxy = object;
PinosConnection *connection = proxy->context->protocol_private;
Builder b = { { NULL, 0, 0, NULL, write_pod }, connection };
SpaPODFrame f;
uint32_t i;
spa_pod_builder_add (&b.b,
SPA_POD_TYPE_STRUCT, &f,
SPA_POD_TYPE_INT, first_id,
SPA_POD_TYPE_INT, n_uris, 0);
for (i = 0; i < n_uris; i++) {
spa_pod_builder_add (&b.b,
SPA_POD_TYPE_STRING, uris[i], 0);
}
spa_pod_builder_add (&b.b,
-SPA_POD_TYPE_STRUCT, &f, 0);
pinos_connection_end_write (connection, proxy->id, 5, b.b.offset);
}
static bool
core_demarshal_info (void *object,
void *data,
@ -273,6 +332,33 @@ core_demarshal_remove_id (void *object,
return true;
}
static bool
core_demarshal_update_uris (void *object,
void *data,
size_t size)
{
PinosProxy *proxy = object;
SpaPODIter it;
uint32_t first_id, n_uris;
const char **uris;
int i;
if (!spa_pod_iter_struct (&it, data, size) ||
!spa_pod_iter_get (&it,
SPA_POD_TYPE_INT, &first_id,
SPA_POD_TYPE_INT, &n_uris,
0))
return false;
uris = alloca (n_uris * sizeof (char *));
for (i = 0; i < n_uris; i++) {
if (!spa_pod_iter_get (&it, SPA_POD_TYPE_STRING, &uris[i], 0))
return false;
}
((PinosCoreEvents*)proxy->implementation)->update_uris (proxy, first_id, n_uris, uris);
return true;
}
static bool
module_demarshal_info (void *object,
void *data,
@ -379,6 +465,8 @@ client_node_marshal_update (void *object,
Builder b = { { NULL, 0, 0, NULL, write_pod }, connection };
SpaPODFrame f;
core_update_map (proxy->context);
spa_pod_builder_add (&b.b,
SPA_POD_TYPE_STRUCT, &f,
SPA_POD_TYPE_INT, change_mask,
@ -411,6 +499,8 @@ client_node_marshal_port_update (void *object,
SpaPODFrame f;
int i, n_items;
core_update_map (proxy->context);
spa_pod_builder_add (&b.b,
SPA_POD_TYPE_STRUCT, &f,
SPA_POD_TYPE_INT, direction,
@ -464,6 +554,8 @@ client_node_marshal_state_change (void *object,
Builder b = { { NULL, 0, 0, NULL, write_pod }, connection };
SpaPODFrame f;
core_update_map (proxy->context);
spa_pod_builder_add (&b.b,
SPA_POD_TYPE_STRUCT, &f,
SPA_POD_TYPE_INT, state,
@ -482,6 +574,8 @@ client_node_marshal_event (void *object,
Builder b = { { NULL, 0, 0, NULL, write_pod }, connection };
SpaPODFrame f;
core_update_map (proxy->context);
spa_pod_builder_add (&b.b,
SPA_POD_TYPE_STRUCT, &f,
SPA_POD_TYPE_BYTES, event, event->size,
@ -499,6 +593,8 @@ client_node_marshal_destroy (void *object)
Builder b = { { NULL, 0, 0, NULL, write_pod }, connection };
SpaPODFrame f;
core_update_map (proxy->context);
spa_pod_builder_add (&b.b,
SPA_POD_TYPE_STRUCT, &f,
-SPA_POD_TYPE_STRUCT, &f,
@ -923,6 +1019,8 @@ registry_marshal_bind (void *object,
Builder b = { { NULL, 0, 0, NULL, write_pod }, connection };
SpaPODFrame f;
core_update_map (proxy->context);
spa_pod_builder_add (&b.b,
SPA_POD_TYPE_STRUCT, &f,
SPA_POD_TYPE_INT, id,
@ -937,7 +1035,8 @@ static const PinosCoreMethods pinos_protocol_native_client_core_methods = {
&core_marshal_sync,
&core_marshal_get_registry,
&core_marshal_create_node,
&core_marshal_create_client_node
&core_marshal_create_client_node,
&core_marshal_update_uris,
};
static const PinosDemarshalFunc pinos_protocol_native_client_core_demarshal[] = {
@ -945,11 +1044,12 @@ static const PinosDemarshalFunc pinos_protocol_native_client_core_demarshal[] =
&core_demarshal_done,
&core_demarshal_error,
&core_demarshal_remove_id,
&core_demarshal_update_uris,
};
static const PinosInterface pinos_protocol_native_client_core_interface = {
5, &pinos_protocol_native_client_core_methods,
4, pinos_protocol_native_client_core_demarshal
6, &pinos_protocol_native_client_core_methods,
5, pinos_protocol_native_client_core_demarshal
};
static const PinosRegistryMethods pinos_protocol_native_client_registry_methods = {
@ -1036,17 +1136,23 @@ pinos_protocol_native_client_setup (PinosProxy *proxy)
if (proxy->type == proxy->context->uri.core) {
iface = &pinos_protocol_native_client_core_interface;
} else if (proxy->type == proxy->context->uri.registry) {
}
else if (proxy->type == proxy->context->uri.registry) {
iface = &pinos_protocol_native_client_registry_interface;
} else if (proxy->type == proxy->context->uri.module) {
}
else if (proxy->type == proxy->context->uri.module) {
iface = &pinos_protocol_native_client_module_interface;
} else if (proxy->type == proxy->context->uri.node) {
}
else if (proxy->type == proxy->context->uri.node) {
iface = &pinos_protocol_native_client_node_interface;
} else if (proxy->type == proxy->context->uri.client_node) {
}
else if (proxy->type == proxy->context->uri.client_node) {
iface = &pinos_protocol_native_client_client_node_interface;
} else if (proxy->type == proxy->context->uri.client) {
}
else if (proxy->type == proxy->context->uri.client) {
iface = &pinos_protocol_native_client_client_interface;
} else if (proxy->type == proxy->context->uri.link) {
}
else if (proxy->type == proxy->context->uri.link) {
iface = &pinos_protocol_native_client_link_interface;
} else
return false;

View file

@ -106,6 +106,7 @@ pinos_client_new (PinosCore *core,
pinos_signal_init (&this->resource_removed);
pinos_map_init (&this->objects, 0);
pinos_map_init (&this->uris, 0);
pinos_signal_init (&this->destroy_signal);
spa_list_insert (core->client_list.prev, &this->link);

View file

@ -55,6 +55,8 @@ struct _PinosClient {
PinosResource *core_resource;
PinosMap objects;
uint32_t n_uris;
PinosMap uris;
SpaList resource_list;
PINOS_SIGNAL (resource_added, (PinosListener *listener,

View file

@ -201,12 +201,32 @@ no_mem:
return;
}
static void
core_update_uris (void *object,
uint32_t first_id,
uint32_t n_uris,
const char **uris)
{
PinosResource *resource = object;
PinosCore *this = resource->core;
PinosClient *client = resource->client;
int i;
for (i = 0; i < n_uris; i++, first_id++) {
uint32_t this_id = spa_id_map_get_id (this->uri.map, uris[i]);
printf ("update %d %s -> %d\n", first_id, uris[i], this_id);
if (!pinos_map_insert_at (&client->uris, first_id, SPA_UINT32_TO_PTR (this_id)))
pinos_log_error ("can't add uri for client");
}
}
static PinosCoreMethods core_methods = {
&core_client_update,
&core_sync,
&core_get_registry,
&core_create_node,
&core_create_client_node
&core_create_client_node,
&core_update_uris
};
static void

View file

@ -45,6 +45,29 @@ write_pod (SpaPODBuilder *b, uint32_t ref, const void *data, uint32_t size)
return ref;
}
static void
core_update_map (PinosClient *client)
{
uint32_t diff, base, i;
PinosCore *core = client->core;
const char **uris;
base = client->n_uris;
diff = spa_id_map_get_size (core->uri.map) - base;
if (diff == 0)
return;
uris = alloca (diff * sizeof (char *));
for (i = 0; i < diff; i++, base++)
uris[i] = spa_id_map_get_uri (core->uri.map, base);
pinos_core_notify_update_uris (client->core_resource,
client->n_uris,
diff,
uris);
client->n_uris += diff;
}
static void
core_marshal_info (void *object,
PinosCoreInfo *info)
@ -55,6 +78,8 @@ core_marshal_info (void *object,
SpaPODFrame f;
uint32_t i, n_items;
core_update_map (resource->client);
n_items = info->props ? info->props->n_items : 0;
spa_pod_builder_add (&b.b,
@ -88,6 +113,8 @@ core_marshal_done (void *object,
Builder b = { { NULL, 0, 0, NULL, write_pod }, connection };
SpaPODFrame f;
core_update_map (resource->client);
spa_pod_builder_add (&b.b,
SPA_POD_TYPE_STRUCT, &f,
SPA_POD_TYPE_INT, seq,
@ -107,9 +134,10 @@ core_marshal_error (void *object,
char buffer[128];
Builder b = { { NULL, 0, 0, NULL, write_pod }, connection };
SpaPODFrame f;
va_list ap;
core_update_map (resource->client);
va_start (ap, error);
vsnprintf (buffer, sizeof (buffer), error, ap);
va_end (ap);
@ -133,6 +161,8 @@ core_marshal_remove_id (void *object,
Builder b = { { NULL, 0, 0, NULL, write_pod }, connection };
SpaPODFrame f;
core_update_map (resource->client);
spa_pod_builder_add (&b.b,
SPA_POD_TYPE_STRUCT, &f,
SPA_POD_TYPE_INT, id,
@ -141,6 +171,33 @@ core_marshal_remove_id (void *object,
pinos_connection_end_write (connection, resource->id, 3, b.b.offset);
}
static void
core_marshal_update_uris (void *object,
uint32_t first_id,
uint32_t n_uris,
const char **uris)
{
PinosResource *resource = object;
PinosConnection *connection = resource->client->protocol_private;
Builder b = { { NULL, 0, 0, NULL, write_pod }, connection };
SpaPODFrame f;
uint32_t i;
spa_pod_builder_add (&b.b,
SPA_POD_TYPE_STRUCT, &f,
SPA_POD_TYPE_INT, first_id,
SPA_POD_TYPE_INT, n_uris, 0);
for (i = 0; i < n_uris; i++) {
spa_pod_builder_add (&b.b,
SPA_POD_TYPE_STRING, uris[i], 0);
}
spa_pod_builder_add (&b.b,
-SPA_POD_TYPE_STRUCT, &f, 0);
pinos_connection_end_write (connection, resource->id, 4, b.b.offset);
}
static bool
core_demarshal_client_update (void *object,
void *data,
@ -281,6 +338,33 @@ core_demarshal_create_client_node (void *object,
return true;
}
static bool
core_demarshal_update_uris (void *object,
void *data,
size_t size)
{
PinosResource *resource = object;
SpaPODIter it;
uint32_t first_id, n_uris;
const char **uris;
int i;
if (!spa_pod_iter_struct (&it, data, size) ||
!spa_pod_iter_get (&it,
SPA_POD_TYPE_INT, &first_id,
SPA_POD_TYPE_INT, &n_uris,
0))
return false;
uris = alloca (n_uris * sizeof (char *));
for (i = 0; i < n_uris; i++) {
if (!spa_pod_iter_get (&it, SPA_POD_TYPE_STRING, &uris[i], 0))
return false;
}
((PinosCoreMethods*)resource->implementation)->update_uris (resource, first_id, n_uris, uris);
return true;
}
static void
registry_marshal_global (void *object,
uint32_t id,
@ -291,6 +375,8 @@ registry_marshal_global (void *object,
Builder b = { { NULL, 0, 0, NULL, write_pod }, connection };
SpaPODFrame f;
core_update_map (resource->client);
spa_pod_builder_add (&b.b,
SPA_POD_TYPE_STRUCT, &f,
SPA_POD_TYPE_INT, id,
@ -309,6 +395,8 @@ registry_marshal_global_remove (void *object,
Builder b = { { NULL, 0, 0, NULL, write_pod }, connection };
SpaPODFrame f;
core_update_map (resource->client);
spa_pod_builder_add (&b.b,
SPA_POD_TYPE_STRUCT, &f,
SPA_POD_TYPE_INT, id,
@ -347,6 +435,8 @@ module_marshal_info (void *object,
SpaPODFrame f;
uint32_t i, n_items;
core_update_map (resource->client);
n_items = info->props ? info->props->n_items : 0;
spa_pod_builder_add (&b.b,
@ -379,6 +469,8 @@ node_marshal_info (void *object,
SpaPODFrame f;
uint32_t i, n_items;
core_update_map (resource->client);
spa_pod_builder_add (&b.b,
SPA_POD_TYPE_STRUCT, &f,
SPA_POD_TYPE_INT, info->id,
@ -426,6 +518,8 @@ client_marshal_info (void *object,
SpaPODFrame f;
uint32_t i, n_items;
core_update_map (resource->client);
n_items = info->props ? info->props->n_items : 0;
spa_pod_builder_add (&b.b,
@ -453,6 +547,8 @@ client_node_marshal_done (void *object,
Builder b = { { NULL, 0, 0, NULL, write_pod }, connection };
SpaPODFrame f;
core_update_map (resource->client);
spa_pod_builder_add (&b.b,
SPA_POD_TYPE_STRUCT, &f,
SPA_POD_TYPE_INT, pinos_connection_add_fd (connection, datafd),
@ -470,6 +566,8 @@ client_node_marshal_event (void *object,
Builder b = { { NULL, 0, 0, NULL, write_pod }, connection };
SpaPODFrame f;
core_update_map (resource->client);
spa_pod_builder_add (&b.b,
SPA_POD_TYPE_STRUCT, &f,
SPA_POD_TYPE_BYTES, event, event->size,
@ -489,6 +587,8 @@ client_node_marshal_add_port (void *object,
Builder b = { { NULL, 0, 0, NULL, write_pod }, connection };
SpaPODFrame f;
core_update_map (resource->client);
spa_pod_builder_add (&b.b,
SPA_POD_TYPE_STRUCT, &f,
SPA_POD_TYPE_INT, seq,
@ -510,6 +610,8 @@ client_node_marshal_remove_port (void *object,
Builder b = { { NULL, 0, 0, NULL, write_pod }, connection };
SpaPODFrame f;
core_update_map (resource->client);
spa_pod_builder_add (&b.b,
SPA_POD_TYPE_STRUCT, &f,
SPA_POD_TYPE_INT, seq,
@ -533,6 +635,8 @@ client_node_marshal_set_format (void *object,
Builder b = { { NULL, 0, 0, NULL, write_pod }, connection };
SpaPODFrame f;
core_update_map (resource->client);
spa_pod_builder_add (&b.b,
SPA_POD_TYPE_STRUCT, &f,
SPA_POD_TYPE_INT, seq,
@ -559,6 +663,8 @@ client_node_marshal_set_property (void *object,
Builder b = { { NULL, 0, 0, NULL, write_pod }, connection };
SpaPODFrame f;
core_update_map (resource->client);
spa_pod_builder_add (&b.b,
SPA_POD_TYPE_STRUCT, &f,
SPA_POD_TYPE_INT, seq,
@ -585,6 +691,8 @@ client_node_marshal_add_mem (void *object,
Builder b = { { NULL, 0, 0, NULL, write_pod }, connection };
SpaPODFrame f;
core_update_map (resource->client);
spa_pod_builder_add (&b.b,
SPA_POD_TYPE_STRUCT, &f,
SPA_POD_TYPE_INT, direction,
@ -614,6 +722,8 @@ client_node_marshal_use_buffers (void *object,
SpaPODFrame f;
uint32_t i, j;
core_update_map (resource->client);
spa_pod_builder_add (&b.b,
SPA_POD_TYPE_STRUCT, &f,
SPA_POD_TYPE_INT, seq,
@ -663,6 +773,8 @@ client_node_marshal_node_command (void *object,
Builder b = { { NULL, 0, 0, NULL, write_pod }, connection };
SpaPODFrame f;
core_update_map (resource->client);
spa_pod_builder_add (&b.b,
SPA_POD_TYPE_STRUCT, &f,
SPA_POD_TYPE_INT, seq,
@ -682,6 +794,8 @@ client_node_marshal_port_command (void *object,
Builder b = { { NULL, 0, 0, NULL, write_pod }, connection };
SpaPODFrame f;
core_update_map (resource->client);
spa_pod_builder_add (&b.b,
SPA_POD_TYPE_STRUCT, &f,
SPA_POD_TYPE_INT, port_id,
@ -702,6 +816,8 @@ client_node_marshal_transport (void *object,
Builder b = { { NULL, 0, 0, NULL, write_pod }, connection };
SpaPODFrame f;
core_update_map (resource->client);
spa_pod_builder_add (&b.b,
SPA_POD_TYPE_STRUCT, &f,
SPA_POD_TYPE_INT, pinos_connection_add_fd (connection, memfd),
@ -877,6 +993,8 @@ link_marshal_info (void *object,
Builder b = { { NULL, 0, 0, NULL, write_pod }, connection };
SpaPODFrame f;
core_update_map (resource->client);
spa_pod_builder_add (&b.b,
SPA_POD_TYPE_STRUCT, &f,
SPA_POD_TYPE_INT, info->id,
@ -895,19 +1013,21 @@ static const PinosDemarshalFunc pinos_protocol_native_server_core_demarshal[] =
&core_demarshal_sync,
&core_demarshal_get_registry,
&core_demarshal_create_node,
&core_demarshal_create_client_node
&core_demarshal_create_client_node,
&core_demarshal_update_uris
};
static const PinosCoreEvents pinos_protocol_native_server_core_events = {
&core_marshal_info,
&core_marshal_done,
&core_marshal_error,
&core_marshal_remove_id
&core_marshal_remove_id,
&core_marshal_update_uris
};
const PinosInterface pinos_protocol_native_server_core_interface = {
5, pinos_protocol_native_server_core_demarshal,
4, &pinos_protocol_native_server_core_events,
6, pinos_protocol_native_server_core_demarshal,
5, &pinos_protocol_native_server_core_events,
};
static const PinosDemarshalFunc pinos_protocol_native_server_registry_demarshal[] = {