rework initial connection

Make a steal_fd method on the remote.
Add a hello method that sends the initial core info and types to
the client.
With an explicit method we can do this multiple times when we steal
the fd from a remote and use it to make a new remote.
This commit is contained in:
Wim Taymans 2018-01-19 17:57:59 +01:00
parent 527f4683ba
commit 1c44629cf9
8 changed files with 84 additions and 18 deletions

View file

@ -527,14 +527,19 @@ static int impl_connect(struct pw_protocol_client *client)
return -1;
}
static int impl_get_fd(struct pw_protocol_client *client)
static int impl_steal_fd(struct pw_protocol_client *client)
{
struct client *impl = SPA_CONTAINER_OF(client, struct client, this);
int fd;
if (impl->source == NULL)
return -EIO;
return impl->source->fd;
fd = dup(impl->source->fd);
pw_protocol_client_disconnect(client);
return fd;
}
static void
@ -636,6 +641,8 @@ static int impl_connect_fd(struct pw_protocol_client *client, int fd)
struct client *impl = SPA_CONTAINER_OF(client, struct client, this);
struct pw_remote *remote = client->remote;
impl->disconnecting = false;
impl->connection = pw_protocol_native_connection_new(fd);
if (impl->connection == NULL)
goto error_close;
@ -707,7 +714,7 @@ impl_new_client(struct pw_protocol *protocol,
impl->properties = properties ? pw_properties_copy(properties) : NULL;
this->connect = impl_connect;
this->get_fd = impl_get_fd;
this->steal_fd = impl_steal_fd;
this->connect_fd = impl_connect_fd;
this->disconnect = impl_disconnect;
this->destroy = impl_destroy;

View file

@ -30,6 +30,18 @@
#include "connection.h"
static void core_marshal_hello(void *object)
{
struct pw_proxy *proxy = object;
struct spa_pod_builder *b;
b = pw_protocol_native_begin_proxy(proxy, PW_CORE_PROXY_METHOD_HELLO);
spa_pod_builder_struct(b, "P", NULL);
pw_protocol_native_end_proxy(proxy, b);
}
static void core_marshal_client_update(void *object, const struct spa_dict *props)
{
struct pw_proxy *proxy = object;
@ -403,6 +415,20 @@ static int core_demarshal_permissions(void *object, void *data, size_t size)
return 0;
}
static int core_demarshal_hello(void *object, void *data, size_t size)
{
struct pw_resource *resource = object;
struct spa_pod_parser prs;
void *ptr;
spa_pod_parser_init(&prs, data, size, 0);
if (spa_pod_parser_get(&prs, "[P]", &ptr, NULL) < 0)
return -EINVAL;
pw_resource_do(resource, struct pw_core_proxy_methods, hello);
return 0;
}
static int core_demarshal_sync(void *object, void *data, size_t size)
{
struct pw_resource *resource = object;
@ -947,6 +973,7 @@ static void registry_marshal_bind(void *object, uint32_t id,
static const struct pw_core_proxy_methods pw_protocol_native_core_method_marshal = {
PW_VERSION_CORE_PROXY_METHODS,
&core_marshal_hello,
&core_marshal_update_types_client,
&core_marshal_sync,
&core_marshal_get_registry,
@ -956,6 +983,7 @@ static const struct pw_core_proxy_methods pw_protocol_native_core_method_marshal
};
static const struct pw_protocol_native_demarshal pw_protocol_native_core_method_demarshal[PW_CORE_PROXY_METHOD_NUM] = {
{ &core_demarshal_hello, 0, },
{ &core_demarshal_update_types_server, 0, },
{ &core_demarshal_sync, 0, },
{ &core_demarshal_get_registry, 0, },