Make separate _register function so that we can first configure the
object before making it publicly visible.
This commit is contained in:
Wim Taymans 2017-09-18 11:54:25 +02:00
parent 67d4dd8656
commit f64c28c091
25 changed files with 131 additions and 99 deletions

View file

@ -473,11 +473,11 @@ static void make_node(struct data *data)
if (data->path) if (data->path)
pw_properties_set(props, "pipewire.target.node", data->path); pw_properties_set(props, "pipewire.target.node", data->path);
data->node = pw_node_new(data->core, NULL, NULL, "SDL-sink", props, 0); data->node = pw_node_new(data->core, "SDL-sink", props, 0);
data->impl_node = impl_node; data->impl_node = impl_node;
pw_node_set_implementation(data->node, &data->impl_node); pw_node_set_implementation(data->node, &data->impl_node);
pw_node_register(data->node); pw_node_register(data->node, NULL, NULL);
pw_remote_export(data->remote, data->node); pw_remote_export(data->remote, data->node);
} }
@ -519,8 +519,6 @@ int main(int argc, char *argv[])
data.remote = pw_remote_new(data.core, NULL, 0); data.remote = pw_remote_new(data.core, NULL, 0);
data.path = argc > 1 ? argv[1] : NULL; data.path = argc > 1 ? argv[1] : NULL;
pw_module_load(data.core, "libpipewire-module-spa-node-factory", NULL);
init_type(&data.type, data.t->map); init_type(&data.type, data.t->map);
spa_debug_set_type_map(data.t->map); spa_debug_set_type_map(data.t->map);

View file

@ -367,11 +367,11 @@ static void make_node(struct data *data)
if (data->path) if (data->path)
pw_properties_set(props, "pipewire.target.node", data->path); pw_properties_set(props, "pipewire.target.node", data->path);
data->node = pw_node_new(data->core, NULL, NULL, "sine-source", props, 0); data->node = pw_node_new(data->core, "sine-source", props, 0);
data->impl_node = impl_node; data->impl_node = impl_node;
pw_node_set_implementation(data->node, &data->impl_node); pw_node_set_implementation(data->node, &data->impl_node);
pw_node_register(data->node); pw_node_register(data->node, NULL, NULL);
pw_remote_export(data->remote, data->node); pw_remote_export(data->remote, data->node);
} }

View file

@ -450,11 +450,11 @@ static void make_nodes(struct data *data)
struct pw_factory *factory; struct pw_factory *factory;
struct pw_properties *props; struct pw_properties *props;
data->node = pw_node_new(data->core, NULL, NULL, "SDL-sink", NULL, 0); data->node = pw_node_new(data->core, "SDL-sink", NULL, 0);
data->impl_node = impl_node; data->impl_node = impl_node;
pw_node_set_implementation(data->node, &data->impl_node); pw_node_set_implementation(data->node, &data->impl_node);
pw_node_register(data->node); pw_node_register(data->node, NULL, NULL);
factory = pw_core_find_factory(data->core, "spa-node-factory"); factory = pw_core_find_factory(data->core, "spa-node-factory");
props = pw_properties_new("spa.library.name", "v4l2/libspa-v4l2", props = pw_properties_new("spa.library.name", "v4l2/libspa-v4l2",
@ -467,13 +467,13 @@ static void make_nodes(struct data *data)
SPA_ID_INVALID); SPA_ID_INVALID);
data->link = pw_link_new(data->core, data->link = pw_link_new(data->core,
NULL,
pw_node_get_free_port(data->v4l2, PW_DIRECTION_OUTPUT), pw_node_get_free_port(data->v4l2, PW_DIRECTION_OUTPUT),
pw_node_find_port(data->node, PW_DIRECTION_INPUT, 0), pw_node_find_port(data->node, PW_DIRECTION_INPUT, 0),
NULL, NULL,
NULL, NULL,
NULL, NULL,
0); 0);
pw_link_register(data->link, NULL, NULL);
pw_link_activate(data->link); pw_link_activate(data->link);
} }

View file

@ -118,11 +118,12 @@ link_state_changed(void *data, enum pw_link_state old, enum pw_link_state state,
switch (state) { switch (state) {
case PW_LINK_STATE_ERROR: case PW_LINK_STATE_ERROR:
{ {
struct pw_resource *owner = pw_node_get_owner(info->node); struct pw_global *global = pw_node_get_global(info->node);
struct pw_client *owner = pw_global_get_owner(global);
pw_log_debug("module %p: link %p: state error: %s", impl, link, error); pw_log_debug("module %p: link %p: state error: %s", impl, link, error);
if (owner) if (owner)
pw_resource_error(owner, SPA_RESULT_ERROR, error); pw_resource_error(pw_client_get_core_resource(owner), SPA_RESULT_ERROR, error);
break; break;
} }
@ -193,7 +194,6 @@ static void try_link_port(struct pw_node *node, struct pw_port *port, struct nod
} }
link = pw_link_new(impl->core, link = pw_link_new(impl->core,
pw_module_get_global(impl->module),
port, target, port, target,
NULL, NULL, NULL, NULL,
&error, &error,
@ -207,6 +207,7 @@ static void try_link_port(struct pw_node *node, struct pw_port *port, struct nod
pw_link_add_listener(link, &ld->link_listener, &link_events, ld); pw_link_add_listener(link, &ld->link_listener, &link_events, ld);
spa_list_append(&info->links, &ld->l); spa_list_append(&info->links, &ld->l);
pw_link_register(link, NULL, pw_module_get_global(impl->module));
pw_link_activate(link); pw_link_activate(link);
@ -215,9 +216,10 @@ static void try_link_port(struct pw_node *node, struct pw_port *port, struct nod
error: error:
pw_log_error("module %p: can't link node '%s'", impl, error); pw_log_error("module %p: can't link node '%s'", impl, error);
{ {
struct pw_resource *owner = pw_node_get_owner(info->node); struct pw_global *global = pw_node_get_global(info->node);
struct pw_client *owner = pw_global_get_owner(global);
if (owner) if (owner)
pw_resource_error(owner, SPA_RESULT_ERROR, error); pw_resource_error(pw_client_get_core_resource(owner), SPA_RESULT_ERROR, error);
} }
free(error); free(error);
return; return;

View file

@ -1161,7 +1161,7 @@ struct pw_client_node *pw_client_node_new(struct pw_resource *resource,
this->resource = resource; this->resource = resource;
this->node = pw_spa_node_new(core, this->node = pw_spa_node_new(core,
this->resource, pw_resource_get_client(this->resource),
NULL, NULL,
name, name,
true, true,

View file

@ -796,7 +796,6 @@ handle_connect_name_ports(struct client *client)
pw_log_debug("protocol-jack %p: connected ports %p %p", impl, out_port, in_port); pw_log_debug("protocol-jack %p: connected ports %p %p", impl, out_port, in_port);
link = pw_link_new(impl->core, link = pw_link_new(impl->core,
pw_module_get_global(impl->module),
out_port->port, out_port->port,
in_port->port, in_port->port,
NULL, NULL,
@ -810,6 +809,7 @@ handle_connect_name_ports(struct client *client)
ld->in_port = in_port; ld->in_port = in_port;
spa_list_append(&impl->link_list, &ld->link_link); spa_list_append(&impl->link_list, &ld->link_link);
pw_link_add_listener(link, &ld->link_listener, &link_events, ld); pw_link_add_listener(link, &ld->link_listener, &link_events, ld);
pw_link_register(link, NULL, pw_module_get_global(impl->module));
pw_link_activate(link); pw_link_activate(link);
notify_clients(impl, jack_notify_PortConnectCallback, false, "", src_id, dst_id); notify_clients(impl, jack_notify_PortConnectCallback, false, "", src_id, dst_id);
@ -1038,8 +1038,7 @@ static struct client *client_new(struct impl *impl, int fd)
if (properties == NULL) if (properties == NULL)
goto no_props; goto no_props;
client = pw_client_new(impl->core, pw_module_get_global(impl->module), client = pw_client_new(impl->core, ucredp, properties, sizeof(struct client));
ucredp, properties, sizeof(struct client));
if (client == NULL) if (client == NULL)
goto no_client; goto no_client;
@ -1058,6 +1057,8 @@ static struct client *client_new(struct impl *impl, int fd)
pw_client_add_listener(client, &this->client_listener, &client_events, this); pw_client_add_listener(client, &this->client_listener, &client_events, this);
pw_client_register(client, NULL, pw_module_get_global(impl->module));
pw_log_debug("module-jack %p: added new client", impl); pw_log_debug("module-jack %p: added new client", impl);
return this; return this;
@ -1277,7 +1278,6 @@ make_freewheel_client(struct impl *impl)
} }
static bool on_global(void *data, struct pw_global *global) static bool on_global(void *data, struct pw_global *global)
{ {
struct impl *impl = data; struct impl *impl = data;
struct pw_node *node; struct pw_node *node;
@ -1302,7 +1302,7 @@ static bool on_global(void *data, struct pw_global *global)
if (out_port == NULL || in_port == NULL) if (out_port == NULL || in_port == NULL)
return true; return true;
impl->sink_link = pw_link_new(impl->core, pw_module_get_global(impl->module), impl->sink_link = pw_link_new(impl->core,
out_port, out_port,
in_port, in_port,
NULL, NULL,
@ -1310,6 +1310,7 @@ static bool on_global(void *data, struct pw_global *global)
NULL, NULL,
0); 0);
pw_link_inc_idle(impl->sink_link); pw_link_inc_idle(impl->sink_link);
pw_link_register(impl->sink_link, NULL, pw_module_get_global(impl->module));
return false; return false;
} }

View file

@ -886,7 +886,7 @@ struct pw_jack_node *pw_jack_node_new(struct pw_core *core,
} }
pw_properties_setf(properties, "jack.ref-num", "%d", ref_num); pw_properties_setf(properties, "jack.ref-num", "%d", ref_num);
node = pw_node_new(core, NULL, parent, name, properties, sizeof(struct node_data) + user_data_size); node = pw_node_new(core, name, properties, sizeof(struct node_data) + user_data_size);
if (node == NULL) if (node == NULL)
return NULL; return NULL;
@ -917,7 +917,7 @@ struct pw_jack_node *pw_jack_node_new(struct pw_core *core,
jack_connection_manager_init_ref_num(conn, ref_num); jack_connection_manager_init_ref_num(conn, ref_num);
jack_graph_manager_next_stop(mgr); jack_graph_manager_next_stop(mgr);
pw_node_register(node); pw_node_register(node, NULL, parent);
return this; return this;
} }
@ -960,7 +960,7 @@ pw_jack_driver_new(struct pw_core *core,
} }
pw_properties_setf(properties, "jack.ref-num", "%d", ref_num); pw_properties_setf(properties, "jack.ref-num", "%d", ref_num);
node = pw_node_new(core, NULL, parent, name, properties, sizeof(struct node_data) + user_data_size); node = pw_node_new(core, name, properties, sizeof(struct node_data) + user_data_size);
if (node == NULL) if (node == NULL)
return NULL; return NULL;
@ -1013,7 +1013,7 @@ pw_jack_driver_new(struct pw_core *core,
this->driver_out = alloc_port(this, PW_DIRECTION_OUTPUT, 0); this->driver_out = alloc_port(this, PW_DIRECTION_OUTPUT, 0);
pw_port_add(this->driver_out->port, node); pw_port_add(this->driver_out->port, node);
} }
pw_node_register(node); pw_node_register(node, NULL, parent);
return this; return this;
} }

View file

@ -161,8 +161,9 @@ static bool on_global(void *data, struct pw_global *global)
if (op == NULL) if (op == NULL)
return true; return true;
link = pw_link_new(impl->core, pw_module_get_global(impl->module), op, ip, NULL, NULL, &error, 0); link = pw_link_new(impl->core, op, ip, NULL, NULL, &error, 0);
pw_link_inc_idle(link); pw_link_inc_idle(link);
pw_link_register(link, NULL, pw_module_get_global(impl->module));
return true; return true;
} }

View file

@ -231,7 +231,7 @@ static struct client *client_new(struct impl *impl, const char *sender)
struct client *this; struct client *this;
struct pw_client *client; struct pw_client *client;
client = pw_client_new(impl->core, NULL, NULL); client = pw_client_new(impl->core, NULL, NULL, 0);
if ((this = (struct client *) find_object(impl, client))) { if ((this = (struct client *) find_object(impl, client))) {
pipewire_client1_set_sender(this->parent.iface, sender); pipewire_client1_set_sender(this->parent.iface, sender);

View file

@ -120,7 +120,7 @@ process_messages(struct client_data *data)
pw_log_trace("protocol-native %p: got message %d from %u", client->protocol, pw_log_trace("protocol-native %p: got message %d from %u", client->protocol,
opcode, id); opcode, id);
resource = pw_client_get_resource(client, id); resource = pw_client_find_resource(client, id);
if (resource == NULL) { if (resource == NULL) {
pw_log_error("protocol-native %p: unknown resource %u", pw_log_error("protocol-native %p: unknown resource %u",
client->protocol, id); client->protocol, id);
@ -246,7 +246,6 @@ static struct pw_client *client_new(struct server *s, int fd)
goto no_props; goto no_props;
client = pw_client_new(protocol->core, client = pw_client_new(protocol->core,
pw_module_get_global(pd->module),
ucredp, ucredp,
props, props,
sizeof(struct client_data)); sizeof(struct client_data));
@ -268,6 +267,7 @@ static struct pw_client *client_new(struct server *s, int fd)
spa_list_append(&s->this.client_list, &client->protocol_link); spa_list_append(&s->this.client_list, &client->protocol_link);
pw_client_add_listener(client, &this->client_listener, &client_events, this); pw_client_add_listener(client, &this->client_listener, &client_events, this);
pw_client_register(client, NULL, pw_module_get_global(pd->module));
pw_global_bind(pw_core_get_global(core), client, PW_PERM_RWX, PW_VERSION_CORE, 0); pw_global_bind(pw_core_get_global(core), client, PW_PERM_RWX, PW_VERSION_CORE, 0);
@ -491,7 +491,7 @@ on_remote_data(void *data, int fd, enum spa_io mask)
pw_log_trace("protocol-native %p: got message %d from %u", this, opcode, id); pw_log_trace("protocol-native %p: got message %d from %u", this, opcode, id);
proxy = pw_remote_get_proxy(this, id); proxy = pw_remote_find_proxy(this, id);
if (proxy == NULL) { if (proxy == NULL) {
pw_log_error("protocol-native %p: could not find proxy %u", this, id); pw_log_error("protocol-native %p: could not find proxy %u", this, id);

View file

@ -37,6 +37,9 @@
struct impl { struct impl {
struct pw_node *this; struct pw_node *this;
struct pw_client *owner;
struct pw_global *parent;
bool async_init; bool async_init;
void *hnd; void *hnd;
@ -68,7 +71,7 @@ static void pw_spa_node_destroy(void *data)
static void complete_init(struct impl *impl) static void complete_init(struct impl *impl)
{ {
struct pw_node *this = impl->this; struct pw_node *this = impl->this;
pw_node_register(this); pw_node_register(this, impl->owner, impl->parent);
} }
static void on_node_done(void *data, uint32_t seq, int res) static void on_node_done(void *data, uint32_t seq, int res)
@ -91,7 +94,7 @@ static const struct pw_node_events node_events = {
struct pw_node * struct pw_node *
pw_spa_node_new(struct pw_core *core, pw_spa_node_new(struct pw_core *core,
struct pw_resource *owner, struct pw_client *owner,
struct pw_global *parent, struct pw_global *parent,
const char *name, const char *name,
bool async, bool async,
@ -103,7 +106,7 @@ pw_spa_node_new(struct pw_core *core,
struct pw_node *this; struct pw_node *this;
struct impl *impl; struct impl *impl;
this = pw_node_new(core, owner, parent, name, properties, sizeof(struct impl) + user_data_size); this = pw_node_new(core, name, properties, sizeof(struct impl) + user_data_size);
if (this == NULL) if (this == NULL)
return NULL; return NULL;
@ -111,6 +114,8 @@ pw_spa_node_new(struct pw_core *core,
impl = this->user_data; impl = this->user_data;
impl->this = this; impl->this = this;
impl->owner = owner;
impl->parent = parent;
impl->node = node; impl->node = node;
impl->async_init = async; impl->async_init = async;
@ -187,7 +192,7 @@ setup_props(struct pw_core *core, struct spa_node *spa_node, struct pw_propertie
struct pw_node *pw_spa_node_load(struct pw_core *core, struct pw_node *pw_spa_node_load(struct pw_core *core,
struct pw_resource *owner, struct pw_client *owner,
struct pw_global *parent, struct pw_global *parent,
const char *lib, const char *lib,
const char *factory_name, const char *factory_name,

View file

@ -32,8 +32,8 @@ extern "C" {
struct pw_node * struct pw_node *
pw_spa_node_new(struct pw_core *core, pw_spa_node_new(struct pw_core *core,
struct pw_resource *owner, /**< optional owner */ struct pw_client *owner, /**< optional owner */
struct pw_global *parent, /**< optional parent */ struct pw_global *parent, /**< optional parent */
const char *name, const char *name,
bool async, bool async,
struct spa_node *node, struct spa_node *node,
@ -43,8 +43,8 @@ pw_spa_node_new(struct pw_core *core,
struct pw_node * struct pw_node *
pw_spa_node_load(struct pw_core *core, pw_spa_node_load(struct pw_core *core,
struct pw_resource *owner, /**< optional owner */ struct pw_client *owner, /**< optional owner */
struct pw_global *parent, /**< optional parent */ struct pw_global *parent, /**< optional parent */
const char *lib, const char *lib,
const char *factory_name, const char *factory_name,
const char *name, const char *name,

View file

@ -90,7 +90,6 @@ client_bind_func(struct pw_global *global,
* \memberof pw_client * \memberof pw_client
*/ */
struct pw_client *pw_client_new(struct pw_core *core, struct pw_client *pw_client_new(struct pw_core *core,
struct pw_global *parent,
struct ucred *ucred, struct ucred *ucred,
struct pw_properties *properties, struct pw_properties *properties,
size_t user_data_size) size_t user_data_size)
@ -102,9 +101,9 @@ struct pw_client *pw_client_new(struct pw_core *core,
if (impl == NULL) if (impl == NULL)
return NULL; return NULL;
pw_log_debug("client %p: new parent %d", impl, parent ? parent->id : 0);
this = &impl->this; this = &impl->this;
pw_log_debug("client %p: new", this);
this->core = core; this->core = core;
if ((this->ucred_valid = (ucred != NULL))) if ((this->ucred_valid = (ucred != NULL)))
this->ucred = *ucred; this->ucred = *ucred;
@ -131,18 +130,24 @@ struct pw_client *pw_client_new(struct pw_core *core,
pw_map_init(&this->objects, 0, 32); pw_map_init(&this->objects, 0, 32);
pw_map_init(&this->types, 0, 32); pw_map_init(&this->types, 0, 32);
spa_list_insert(core->client_list.prev, &this->link);
this->info.props = this->properties ? &this->properties->dict : NULL; this->info.props = this->properties ? &this->properties->dict : NULL;
this->global = pw_core_add_global(core, NULL, parent, core->type.client, PW_VERSION_CLIENT,
client_bind_func, this);
this->info.id = this->global->id;
return this; return this;
} }
void pw_client_register(struct pw_client *client,
struct pw_client *owner,
struct pw_global *parent)
{
struct pw_core *core = client->core;
pw_log_debug("client %p: register parent %d", client, parent ? parent->id : SPA_ID_INVALID);
spa_list_insert(core->client_list.prev, &client->link);
client->global = pw_core_add_global(core, owner, parent, core->type.client, PW_VERSION_CLIENT,
client_bind_func, client);
client->info.id = client->global->id;
}
struct pw_core *pw_client_get_core(struct pw_client *client) struct pw_core *pw_client_get_core(struct pw_client *client)
{ {
return client->core; return client->core;
@ -153,7 +158,7 @@ struct pw_resource *pw_client_get_core_resource(struct pw_client *client)
return client->core_resource; return client->core_resource;
} }
struct pw_resource *pw_client_get_resource(struct pw_client *client, uint32_t id) struct pw_resource *pw_client_find_resource(struct pw_client *client, uint32_t id)
{ {
return pw_map_lookup(&client->objects, id); return pw_map_lookup(&client->objects, id);
} }
@ -201,8 +206,10 @@ void pw_client_destroy(struct pw_client *client)
pw_log_debug("client %p: destroy", client); pw_log_debug("client %p: destroy", client);
spa_hook_list_call(&client->listener_list, struct pw_client_events, destroy); spa_hook_list_call(&client->listener_list, struct pw_client_events, destroy);
spa_list_remove(&client->link); if (client->global) {
pw_global_destroy(client->global); spa_list_remove(&client->link);
pw_global_destroy(client->global);
}
spa_list_for_each_safe(resource, tmp, &client->resource_list, link) spa_list_for_each_safe(resource, tmp, &client->resource_list, link)
pw_resource_destroy(resource); pw_resource_destroy(resource);

View file

@ -116,7 +116,6 @@ struct pw_client_events {
/** Create a new client. This is mainly used by protocols. */ /** Create a new client. This is mainly used by protocols. */
struct pw_client * struct pw_client *
pw_client_new(struct pw_core *core, /**< the core object */ pw_client_new(struct pw_core *core, /**< the core object */
struct pw_global *parent, /**< the client parent */
struct ucred *ucred, /**< optional ucred */ struct ucred *ucred, /**< optional ucred */
struct pw_properties *properties, /**< client properties */ struct pw_properties *properties, /**< client properties */
size_t user_data_size /**< extra user data size */); size_t user_data_size /**< extra user data size */);
@ -124,6 +123,11 @@ pw_client_new(struct pw_core *core, /**< the core object */
/** Destroy a previously created client */ /** Destroy a previously created client */
void pw_client_destroy(struct pw_client *client); void pw_client_destroy(struct pw_client *client);
/** Finish configuration and register a client */
void pw_client_register(struct pw_client *client, /**< the client to register */
struct pw_client *owner, /**< optional owner */
struct pw_global *parent /**< the client parent */);
/** Get the client user data */ /** Get the client user data */
void *pw_client_get_user_data(struct pw_client *client); void *pw_client_get_user_data(struct pw_client *client);
@ -143,7 +147,7 @@ struct pw_core *pw_client_get_core(struct pw_client *client);
struct pw_resource *pw_client_get_core_resource(struct pw_client *client); struct pw_resource *pw_client_get_core_resource(struct pw_client *client);
/** Get a resource with the given id */ /** Get a resource with the given id */
struct pw_resource *pw_client_get_resource(struct pw_client *client, uint32_t id); struct pw_resource *pw_client_find_resource(struct pw_client *client, uint32_t id);
/** Get the global associated with this client */ /** Get the global associated with this client */
struct pw_global *pw_client_get_global(struct pw_client *client); struct pw_global *pw_client_get_global(struct pw_client *client);

View file

@ -270,10 +270,12 @@ core_create_link(void *object,
if (inport == NULL) if (inport == NULL)
goto no_input_port; goto no_input_port;
link = pw_link_new(core, pw_client_get_global(client), outport, inport, NULL, NULL, &error, 0); link = pw_link_new(core, outport, inport, NULL, NULL, &error, 0);
if (link == NULL) if (link == NULL)
goto no_link; goto no_link;
pw_link_register(link, client, pw_client_get_global(client));
res = pw_global_bind(pw_link_get_global(link), client, PW_PERM_RWX, PW_VERSION_LINK, new_id); res = pw_global_bind(pw_link_get_global(link), client, PW_PERM_RWX, PW_VERSION_LINK, new_id);
if (res < 0) if (res < 0)
goto no_bind; goto no_bind;

View file

@ -1055,7 +1055,6 @@ static const struct pw_node_events output_node_events = {
}; };
struct pw_link *pw_link_new(struct pw_core *core, struct pw_link *pw_link_new(struct pw_core *core,
struct pw_global *parent,
struct pw_port *output, struct pw_port *output,
struct pw_port *input, struct pw_port *input,
struct spa_format *format_filter, struct spa_format *format_filter,
@ -1118,8 +1117,6 @@ struct pw_link *pw_link_new(struct pw_core *core,
spa_list_insert(output->links.prev, &this->output_link); spa_list_insert(output->links.prev, &this->output_link);
spa_list_insert(input->links.prev, &this->input_link); spa_list_insert(input->links.prev, &this->input_link);
spa_list_insert(core->link_list.prev, &this->link);
this->info.output_node_id = output_node->global->id; this->info.output_node_id = output_node->global->id;
this->info.output_port_id = output->port_id; this->info.output_port_id = output->port_id;
this->info.input_node_id = input_node->global->id; this->info.input_node_id = input_node->global->id;
@ -1150,10 +1147,6 @@ struct pw_link *pw_link_new(struct pw_core *core,
spa_hook_list_call(&output->listener_list, struct pw_port_events, link_added, this); spa_hook_list_call(&output->listener_list, struct pw_port_events, link_added, this);
spa_hook_list_call(&input->listener_list, struct pw_port_events, link_added, this); spa_hook_list_call(&input->listener_list, struct pw_port_events, link_added, this);
this->global = pw_core_add_global(core, NULL, parent, core->type.link, PW_VERSION_LINK,
link_bind_func, this);
this->info.id = this->global->id;
return this; return this;
same_ports: same_ports:
@ -1167,6 +1160,19 @@ struct pw_link *pw_link_new(struct pw_core *core,
return NULL; return NULL;
} }
void pw_link_register(struct pw_link *link,
struct pw_client *owner,
struct pw_global *parent)
{
struct pw_core *core = link->core;
spa_list_insert(core->link_list.prev, &link->link);
link->global = pw_core_add_global(core, owner, parent, core->type.link, PW_VERSION_LINK,
link_bind_func, link);
link->info.id = link->global->id;
}
void pw_link_destroy(struct pw_link *link) void pw_link_destroy(struct pw_link *link)
{ {
struct impl *impl = SPA_CONTAINER_OF(link, struct impl, this); struct impl *impl = SPA_CONTAINER_OF(link, struct impl, this);
@ -1177,8 +1183,10 @@ void pw_link_destroy(struct pw_link *link)
pw_link_deactivate(link); pw_link_deactivate(link);
pw_global_destroy(link->global); if (link->global) {
spa_list_remove(&link->link); spa_list_remove(&link->link);
pw_global_destroy(link->global);
}
spa_list_for_each_safe(resource, tmp, &link->resource_list, link) spa_list_for_each_safe(resource, tmp, &link->resource_list, link)
pw_resource_destroy(resource); pw_resource_destroy(resource);

View file

@ -75,7 +75,6 @@ struct pw_link_events {
* \return a newly allocated link */ * \return a newly allocated link */
struct pw_link * struct pw_link *
pw_link_new(struct pw_core *core, /**< the core object */ pw_link_new(struct pw_core *core, /**< the core object */
struct pw_global *parent, /**< parent global */
struct pw_port *output, /**< an output port */ struct pw_port *output, /**< an output port */
struct pw_port *input, /**< an input port */ struct pw_port *input, /**< an input port */
struct spa_format *format_filter, /**< an optional format filter */ struct spa_format *format_filter, /**< an optional format filter */
@ -92,6 +91,11 @@ void pw_link_add_listener(struct pw_link *link,
const struct pw_link_events *events, const struct pw_link_events *events,
void *data); void *data);
/** Finish link configuration and register */
void pw_link_register(struct pw_link *link, /**< the link to register */
struct pw_client *owner, /**< optional link owner */
struct pw_global *parent /**< parent global */);
/** Get the core of a link */ /** Get the core of a link */
struct pw_core *pw_link_get_core(struct pw_link *link); struct pw_core *pw_link_get_core(struct pw_link *link);

View file

@ -224,7 +224,7 @@ struct pw_module *pw_module_load(struct pw_core *core, const char *name, const c
this->info.id = this->global->id; this->info.id = this->global->id;
if (!init_func(this, (char *) args)) if (!init_func(this, args))
goto init_failed; goto init_failed;
pw_log_debug("loaded module: %s", this->info.name); pw_log_debug("loaded module: %s", this->info.name);

View file

@ -51,7 +51,7 @@ struct pw_module;
* *
* \memberof pw_module * \memberof pw_module
*/ */
typedef bool (*pw_module_init_func_t) (struct pw_module *module, char *args); typedef bool (*pw_module_init_func_t) (struct pw_module *module, const char *args);
/** Module events added with \ref pw_module_add_listener */ /** Module events added with \ref pw_module_add_listener */
struct pw_module_events { struct pw_module_events {
@ -62,7 +62,7 @@ struct pw_module_events {
void (*destroy) (void *data); void (*destroy) (void *data);
}; };
/** Load a module by name and arguments */ /** Load a module by name and arguments and register it */
struct pw_module * struct pw_module *
pw_module_load(struct pw_core *core, const char *name, const char *args); pw_module_load(struct pw_core *core, const char *name, const char *args);

View file

@ -37,11 +37,7 @@
struct impl { struct impl {
struct pw_node this; struct pw_node this;
struct pw_global *parent;
struct pw_work_queue *work; struct pw_work_queue *work;
bool registered;
}; };
struct resource_data { struct resource_data {
@ -335,9 +331,10 @@ do_node_add(struct spa_loop *loop,
} }
void pw_node_register(struct pw_node *this) void pw_node_register(struct pw_node *this,
struct pw_client *owner,
struct pw_global *parent)
{ {
struct impl *impl = SPA_CONTAINER_OF(this, struct impl, this);
struct pw_core *core = this->core; struct pw_core *core = this->core;
pw_log_debug("node %p: register", this); pw_log_debug("node %p: register", this);
@ -348,21 +345,17 @@ void pw_node_register(struct pw_node *this)
pw_loop_invoke(this->data_loop, do_node_add, 1, 0, NULL, false, this); pw_loop_invoke(this->data_loop, do_node_add, 1, 0, NULL, false, this);
spa_list_insert(core->node_list.prev, &this->link); spa_list_insert(core->node_list.prev, &this->link);
this->global = pw_core_add_global(core, this->owner ? this->owner->client : NULL, this->global = pw_core_add_global(core, owner, parent,
impl->parent,
core->type.node, PW_VERSION_NODE, core->type.node, PW_VERSION_NODE,
node_bind_func, this); node_bind_func, this);
this->info.id = this->global->id; this->info.id = this->global->id;
impl->registered = true;
spa_hook_list_call(&this->listener_list, struct pw_node_events, initialized); spa_hook_list_call(&this->listener_list, struct pw_node_events, initialized);
pw_node_update_state(this, PW_NODE_STATE_SUSPENDED, NULL); pw_node_update_state(this, PW_NODE_STATE_SUSPENDED, NULL);
} }
struct pw_node *pw_node_new(struct pw_core *core, struct pw_node *pw_node_new(struct pw_core *core,
struct pw_resource *owner,
struct pw_global *parent,
const char *name, const char *name,
struct pw_properties *properties, struct pw_properties *properties,
size_t user_data_size) size_t user_data_size)
@ -376,9 +369,7 @@ struct pw_node *pw_node_new(struct pw_core *core,
this = &impl->this; this = &impl->this;
this->core = core; this->core = core;
this->owner = owner; pw_log_debug("node %p: new \"%s\"", this, name);
impl->parent = parent;
pw_log_debug("node %p: new, owner %p", this, owner);
if (user_data_size > 0) if (user_data_size > 0)
this->user_data = SPA_MEMBER(impl, sizeof(struct impl), void); this->user_data = SPA_MEMBER(impl, sizeof(struct impl), void);
@ -433,11 +424,6 @@ struct pw_core * pw_node_get_core(struct pw_node *node)
return node->core; return node->core;
} }
struct pw_resource *pw_node_get_owner(struct pw_node *node)
{
return node->owner;
}
struct pw_global *pw_node_get_global(struct pw_node *node) struct pw_global *pw_node_get_global(struct pw_node *node)
{ {
return node->global; return node->global;
@ -584,7 +570,7 @@ void pw_node_destroy(struct pw_node *node)
pw_loop_invoke(node->data_loop, do_node_remove, 1, 0, NULL, true, node); pw_loop_invoke(node->data_loop, do_node_remove, 1, 0, NULL, true, node);
if (impl->registered) { if (node->global) {
spa_list_remove(&node->link); spa_list_remove(&node->link);
pw_global_destroy(node->global); pw_global_destroy(node->global);
node->global = NULL; node->global = NULL;

View file

@ -89,14 +89,14 @@ struct pw_node_events {
/** Create a new node \memberof pw_node */ /** Create a new node \memberof pw_node */
struct pw_node * struct pw_node *
pw_node_new(struct pw_core *core, /**< the core */ pw_node_new(struct pw_core *core, /**< the core */
struct pw_resource *owner, /**< optional owner */
struct pw_global *parent, /**< optional parent */
const char *name, /**< node name */ const char *name, /**< node name */
struct pw_properties *properties, /**< extra properties */ struct pw_properties *properties, /**< extra properties */
size_t user_data_size /**< user data size */); size_t user_data_size /**< user data size */);
/** Complete initialization of the node and register */ /** Complete initialization of the node and register */
void pw_node_register(struct pw_node *node); void pw_node_register(struct pw_node *node, /**< node to register */
struct pw_client *owner, /**< optional owner */
struct pw_global *parent /**< optional parent */);
/** Destroy a node */ /** Destroy a node */
void pw_node_destroy(struct pw_node *node); void pw_node_destroy(struct pw_node *node);
@ -110,9 +110,6 @@ void * pw_node_get_user_data(struct pw_node *node);
/** Get the core of this node */ /** Get the core of this node */
struct pw_core *pw_node_get_core(struct pw_node *node); struct pw_core *pw_node_get_core(struct pw_node *node);
/** Get the node owner or NULL when not owned by a remote client */
struct pw_resource *pw_node_get_owner(struct pw_node *node);
/** Get the global of this node */ /** Get the global of this node */
struct pw_global *pw_node_get_global(struct pw_node *node); struct pw_global *pw_node_get_global(struct pw_node *node);

View file

@ -221,7 +221,6 @@ struct pw_node {
struct spa_list link; /**< link in core node_list */ struct spa_list link; /**< link in core node_list */
struct pw_global *global; /**< global for this node */ struct pw_global *global; /**< global for this node */
struct pw_resource *owner; /**< owner resource if any */
struct pw_properties *properties; /**< properties of the node */ struct pw_properties *properties; /**< properties of the node */
struct pw_node_info info; /**< introspectable node info */ struct pw_node_info info; /**< introspectable node info */

View file

@ -265,10 +265,19 @@ struct pw_remote *pw_remote_new(struct pw_core *core,
return this; return this;
no_connection:
no_protocol:
pw_properties_free(properties);
no_mem: no_mem:
pw_log_error("no memory");
goto exit;
no_protocol:
pw_log_error("can't load native protocol");
goto exit_free_props;
no_connection:
pw_log_error("can't create new native protocol connection");
goto exit_free_props;
exit_free_props:
pw_properties_free(properties);
exit:
free(impl); free(impl);
return NULL; return NULL;
} }
@ -356,7 +365,7 @@ const struct pw_core_info *pw_remote_get_core_info(struct pw_remote *remote)
return remote->info; return remote->info;
} }
struct pw_proxy *pw_remote_get_proxy(struct pw_remote *remote, uint32_t id) struct pw_proxy *pw_remote_find_proxy(struct pw_remote *remote, uint32_t id)
{ {
return pw_map_lookup(&remote->objects, id); return pw_map_lookup(&remote->objects, id);
} }

View file

@ -180,7 +180,7 @@ struct pw_core_proxy * pw_remote_get_core_proxy(struct pw_remote *remote);
const struct pw_core_info *pw_remote_get_core_info(struct pw_remote *remote); const struct pw_core_info *pw_remote_get_core_info(struct pw_remote *remote);
/** Get the proxy with the given id */ /** Get the proxy with the given id */
struct pw_proxy *pw_remote_get_proxy(struct pw_remote *remote, uint32_t id); struct pw_proxy *pw_remote_find_proxy(struct pw_remote *remote, uint32_t id);
/** Disconnect from the remote PipeWire. \memberof pw_remote */ /** Disconnect from the remote PipeWire. \memberof pw_remote */
void pw_remote_disconnect(struct pw_remote *remote); void pw_remote_disconnect(struct pw_remote *remote);

View file

@ -435,15 +435,24 @@ int main(int argc, char *argv[])
pw_init(&argc, &argv); pw_init(&argc, &argv);
data.loop = pw_main_loop_new(NULL); data.loop = pw_main_loop_new(NULL);
if (data.loop == NULL)
return -1;
l = pw_main_loop_get_loop(data.loop); l = pw_main_loop_get_loop(data.loop);
pw_loop_add_signal(l, SIGINT, do_quit, &data); pw_loop_add_signal(l, SIGINT, do_quit, &data);
pw_loop_add_signal(l, SIGTERM, do_quit, &data); pw_loop_add_signal(l, SIGTERM, do_quit, &data);
data.core = pw_core_new(l, NULL); data.core = pw_core_new(l, NULL);
if (data.core == NULL)
return -1;
data.remote = pw_remote_new(data.core, NULL, 0); data.remote = pw_remote_new(data.core, NULL, 0);
if (data.remote == NULL)
return -1;
pw_remote_add_listener(data.remote, &data.remote_listener, &remote_events, &data); pw_remote_add_listener(data.remote, &data.remote_listener, &remote_events, &data);
pw_remote_connect(data.remote); if (pw_remote_connect(data.remote) < 0)
return -1;
pw_main_loop_run(data.loop); pw_main_loop_run(data.loop);