mirror of
https://gitlab.freedesktop.org/pipewire/pipewire.git
synced 2025-11-03 09:01:54 -05:00
pulse-server: pass already created module object to module_info::create()
All modules need to manually create a `module` object and check if it was successfully created. The same with argument parsing. To simplify modules, move the module object creation and argument parsing into `module_create()`, and pass the already initialized module to `module_info::create()`. The semantics of `module_info::create()` are kept, that is, if it fails, `module_info::unload()` will not be called.
This commit is contained in:
parent
5ad52bb88a
commit
fa3a28ab68
25 changed files with 210 additions and 548 deletions
|
|
@ -59,16 +59,17 @@ void module_schedule_unload(struct module *module)
|
|||
module->unloading = true;
|
||||
}
|
||||
|
||||
struct module *module_new(struct impl *impl, size_t user_data)
|
||||
static struct module *module_new(struct impl *impl, const struct module_info *info)
|
||||
{
|
||||
struct module *module;
|
||||
|
||||
module = calloc(1, sizeof(struct module) + user_data);
|
||||
module = calloc(1, sizeof(*module) + info->data_size);
|
||||
if (module == NULL)
|
||||
return NULL;
|
||||
|
||||
module->index = SPA_ID_INVALID;
|
||||
module->impl = impl;
|
||||
module->info = info;
|
||||
spa_hook_list_init(&module->listener_list);
|
||||
module->user_data = SPA_PTROFF(module, sizeof(*module), void);
|
||||
module->loaded = false;
|
||||
|
|
@ -304,17 +305,34 @@ struct module *module_create(struct client *client, const char *name, const char
|
|||
}
|
||||
}
|
||||
|
||||
module = info->create(impl, args);
|
||||
module = module_new(impl, info);
|
||||
if (module == NULL)
|
||||
return NULL;
|
||||
|
||||
module->info = info;
|
||||
module->props = pw_properties_new(NULL, NULL);
|
||||
if (module->props == NULL) {
|
||||
module_free(module);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
if (args)
|
||||
module_args_add_props(module->props, args);
|
||||
|
||||
int res = module->info->create(module);
|
||||
if (res < 0) {
|
||||
module_free(module);
|
||||
errno = -res;
|
||||
return NULL;
|
||||
}
|
||||
|
||||
module->index = pw_map_insert_new(&impl->modules, module);
|
||||
if (module->index == SPA_ID_INVALID) {
|
||||
module_unload(module);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
module->args = args ? strdup(args) : NULL;
|
||||
module->index |= MODULE_FLAG;
|
||||
|
||||
return module;
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue