mirror of
https://gitlab.freedesktop.org/pipewire/pipewire.git
synced 2025-11-04 13:30:12 -05:00
modules: handle factory destroy
Listen for factory destroy and clean up the module. See #565
This commit is contained in:
parent
95f8c569a0
commit
383df85466
12 changed files with 264 additions and 90 deletions
|
|
@ -78,11 +78,12 @@ struct resource_data
|
|||
|
||||
struct factory_data
|
||||
{
|
||||
struct pw_impl_factory *this;
|
||||
|
||||
struct pw_impl_module *module;
|
||||
struct spa_hook module_listener;
|
||||
|
||||
struct pw_impl_factory *factory;
|
||||
struct spa_hook factory_listener;
|
||||
|
||||
struct pw_export_type export;
|
||||
};
|
||||
|
||||
|
|
@ -463,7 +464,7 @@ static void *create_object(void *data,
|
|||
pw_properties_setf(properties, PW_KEY_CLIENT_ID, "%d",
|
||||
pw_impl_client_get_info(client)->id);
|
||||
pw_properties_setf(properties, PW_KEY_FACTORY_ID, "%d",
|
||||
pw_impl_factory_get_info(d->this)->id);
|
||||
pw_impl_factory_get_info(d->factory)->id);
|
||||
|
||||
result = stream_new(pw_impl_client_get_context(client), impl_resource, properties);
|
||||
if (result == NULL) {
|
||||
|
|
@ -493,20 +494,37 @@ static const struct pw_impl_factory_implementation impl_factory = {
|
|||
.create_object = create_object,
|
||||
};
|
||||
|
||||
static void factory_destroy(void *data)
|
||||
{
|
||||
struct factory_data *d = data;
|
||||
spa_hook_remove(&d->factory_listener);
|
||||
d->factory = NULL;
|
||||
if (d->module)
|
||||
pw_impl_module_destroy(d->module);
|
||||
}
|
||||
|
||||
static const struct pw_impl_factory_events factory_events = {
|
||||
PW_VERSION_IMPL_FACTORY_EVENTS,
|
||||
.destroy = factory_destroy,
|
||||
};
|
||||
|
||||
static void module_destroy(void *data)
|
||||
{
|
||||
struct factory_data *d = data;
|
||||
|
||||
spa_hook_remove(&d->module_listener);
|
||||
spa_list_remove(&d->export.link);
|
||||
pw_impl_factory_destroy(d->this);
|
||||
d->module = NULL;
|
||||
|
||||
if (d->factory)
|
||||
pw_impl_factory_destroy(d->factory);
|
||||
}
|
||||
|
||||
static void module_registered(void *data)
|
||||
{
|
||||
struct factory_data *d = data;
|
||||
struct pw_impl_module *module = d->module;
|
||||
struct pw_impl_factory *factory = d->this;
|
||||
struct pw_impl_factory *factory = d->factory;
|
||||
struct spa_dict_item items[1];
|
||||
char id[16];
|
||||
int res;
|
||||
|
|
@ -543,7 +561,7 @@ int endpoint_stream_factory_init(struct pw_impl_module *module)
|
|||
return -errno;
|
||||
|
||||
data = pw_impl_factory_get_user_data(factory);
|
||||
data->this = factory;
|
||||
data->factory = factory;
|
||||
data->module = module;
|
||||
|
||||
pw_impl_factory_set_implementation(factory, &impl_factory, data);
|
||||
|
|
@ -553,10 +571,11 @@ int endpoint_stream_factory_init(struct pw_impl_module *module)
|
|||
if ((res = pw_context_register_export_type(context, &data->export)) < 0)
|
||||
goto error;
|
||||
|
||||
pw_impl_factory_add_listener(factory, &data->factory_listener, &factory_events, data);
|
||||
pw_impl_module_add_listener(module, &data->module_listener, &module_events, data);
|
||||
|
||||
return 0;
|
||||
error:
|
||||
pw_impl_factory_destroy(data->this);
|
||||
pw_impl_factory_destroy(data->factory);
|
||||
return res;
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue