client-node: add get_node method

Make a get node method that binds to the server side node of the
client-node immediately. use this in the remote_export and always
return a node proxy.

Use the node proxy to get property updates and signal those in the
stream.
This commit is contained in:
Wim Taymans 2019-03-15 20:29:34 +01:00
parent 33afa18621
commit 9245c81227
9 changed files with 183 additions and 42 deletions

View file

@ -165,7 +165,9 @@ struct impl {
struct spa_hook resource_listener;
struct pw_array mems;
uint32_t init_seq;
uint32_t bind_node_version;
uint32_t bind_node_id;
int fds[2];
int other_fds[2];
@ -987,6 +989,20 @@ static int impl_node_process(struct spa_node *node)
return SPA_STATUS_OK;
}
static int
client_node_get_node(void *data,
uint32_t version,
uint32_t new_id)
{
struct impl *impl = data;
struct node *this = &impl->node;
pw_log_debug("node %p: bind %u/%u", this, new_id, version);
impl->bind_node_version = version;
impl->bind_node_id = new_id;
pw_map_insert_at(&this->resource->client->objects, new_id, NULL);
return 0;
}
static int
client_node_update(void *data,
uint32_t change_mask,
@ -1076,6 +1092,7 @@ static int client_node_event(void *data, struct spa_event *event)
static struct pw_client_node_proxy_methods client_node_methods = {
PW_VERSION_CLIENT_NODE_PROXY_METHODS,
.get_node = client_node_get_node,
.update = client_node_update,
.port_update = client_node_port_update,
.set_active = client_node_set_active,
@ -1232,10 +1249,11 @@ static void client_node_resource_pong(void *data, int seq)
spa_node_emit_result(&this->hooks, seq, 0, NULL);
}
void pw_client_node_registered(struct pw_client_node *this, uint32_t node_id)
void pw_client_node_registered(struct pw_client_node *this, struct pw_global *global)
{
struct impl *impl = SPA_CONTAINER_OF(this, struct impl, this);
struct pw_node *node = this->node;
uint32_t node_id = global->id;
struct mem *m;
pw_log_debug("client-node %p: %d", this, node_id);
@ -1252,6 +1270,11 @@ void pw_client_node_registered(struct pw_client_node *this, uint32_t node_id)
m->id,
0,
sizeof(struct pw_node_activation));
if (impl->bind_node_id) {
pw_global_bind(global, this->resource->client, PW_PERM_RWX,
impl->bind_node_version, impl->bind_node_id);
}
}
static void node_initialized(void *data)
@ -1287,7 +1310,7 @@ static void node_initialized(void *data)
pw_log_debug("client-node %p: io areas %p", node, impl->io_areas->ptr);
if ((global = pw_node_get_global(node)) != NULL)
pw_client_node_registered(this, pw_global_get_id(global));
pw_client_node_registered(this, global);
}
static void node_free(void *data)

View file

@ -53,7 +53,7 @@ pw_client_node_new(struct pw_resource *resource,
void
pw_client_node_destroy(struct pw_client_node *node);
void pw_client_node_registered(struct pw_client_node *node, uint32_t node_id);
void pw_client_node_registered(struct pw_client_node *node, struct pw_global *global);
#ifdef __cplusplus
}

View file

@ -1210,7 +1210,7 @@ static void node_free(void *data)
static void node_initialized(void *data)
{
struct impl *impl = data;
pw_client_node_registered(impl->client_node, impl->this.node->global->id);
pw_client_node_registered(impl->client_node, impl->this.node->global);
}
static const struct pw_node_events node_events = {

View file

@ -47,6 +47,21 @@ static void push_dict(struct spa_pod_builder *b, const struct spa_dict *dict)
spa_pod_builder_pop(b, &f);
}
static int
client_node_marshal_get_node(void *object, uint32_t version, uint32_t new_id)
{
struct pw_proxy *proxy = object;
struct spa_pod_builder *b;
b = pw_protocol_native_begin_proxy(proxy, PW_CLIENT_NODE_PROXY_METHOD_GET_NODE, NULL);
spa_pod_builder_add_struct(b,
SPA_POD_Int(version),
SPA_POD_Int(new_id));
return pw_protocol_native_end_proxy(proxy, b);
}
static int
client_node_marshal_update(void *object,
uint32_t change_mask,
@ -770,6 +785,22 @@ client_node_marshal_set_io(void *object,
return pw_protocol_native_end_resource(resource, b);
}
static int client_node_demarshal_get_node(void *object, void *data, size_t size)
{
struct pw_resource *resource = object;
struct spa_pod_parser prs;
int32_t version, new_id;
spa_pod_parser_init(&prs, data, size);
if (spa_pod_parser_get_struct(&prs,
SPA_POD_Int(&version),
SPA_POD_Int(&new_id)) < 0)
return -EINVAL;
return pw_resource_do(resource, struct pw_client_node_proxy_methods, get_node, 0,
version, new_id);
}
static int client_node_demarshal_update(void *object, void *data, size_t size)
{
struct pw_resource *resource = object;
@ -966,6 +997,7 @@ static int client_node_demarshal_event_method(void *object, void *data, size_t s
static const struct pw_client_node_proxy_methods pw_protocol_native_client_node_method_marshal = {
PW_VERSION_CLIENT_NODE_PROXY_METHODS,
&client_node_marshal_get_node,
&client_node_marshal_update,
&client_node_marshal_port_update,
&client_node_marshal_set_active,
@ -973,6 +1005,7 @@ static const struct pw_client_node_proxy_methods pw_protocol_native_client_node_
};
static const struct pw_protocol_native_demarshal pw_protocol_native_client_node_method_demarshal[] = {
{ &client_node_demarshal_get_node, 0 },
{ &client_node_demarshal_update, 0 },
{ &client_node_demarshal_port_update, 0 },
{ &client_node_demarshal_set_active, 0 },

View file

@ -107,6 +107,7 @@ struct node_data {
struct pw_client_node_proxy *node_proxy;
struct spa_hook node_proxy_listener;
struct spa_hook proxy_listener;
struct pw_proxy *proxy;
struct spa_io_position *position;
@ -419,7 +420,7 @@ static int client_node_transport(void *object, uint32_t node_id,
if (data->node->active)
pw_client_node_proxy_set_active(data->node_proxy, true);
pw_remote_emit_exported(remote, proxy->id, node_id);
pw_remote_emit_exported(remote, data->proxy->id, node_id);
return 0;
}
@ -1282,7 +1283,10 @@ static struct pw_proxy *node_export(struct pw_remote *remote, void *object, bool
proxy);
do_node_init(proxy);
return proxy;
data->proxy = (struct pw_proxy*) pw_client_node_proxy_get_node(data->node_proxy,
PW_VERSION_NODE, 0);
return data->proxy;
}
struct pw_proxy *pw_remote_node_export(struct pw_remote *remote,