mirror of
https://gitlab.freedesktop.org/pipewire/pipewire.git
synced 2025-11-07 13:30:09 -05:00
improve error handling some more
This commit is contained in:
parent
d1241e2c1c
commit
a212d2f9ed
30 changed files with 393 additions and 312 deletions
|
|
@ -57,6 +57,9 @@ struct device_data {
|
|||
static void module_destroy(void *_data)
|
||||
{
|
||||
struct device_data *data = _data;
|
||||
|
||||
spa_hook_remove(&data->module_listener);
|
||||
|
||||
pw_device_destroy(data->this);
|
||||
}
|
||||
|
||||
|
|
@ -69,23 +72,26 @@ SPA_EXPORT
|
|||
int pipewire__module_init(struct pw_module *module, const char *args)
|
||||
{
|
||||
struct pw_properties *props = NULL;
|
||||
char **argv;
|
||||
char **argv = NULL;
|
||||
int n_tokens;
|
||||
struct pw_core *core = pw_module_get_core(module);
|
||||
struct pw_device *device;
|
||||
struct device_data *data;
|
||||
int res;
|
||||
|
||||
if (args == NULL)
|
||||
goto wrong_arguments;
|
||||
goto error_arguments;
|
||||
|
||||
argv = pw_split_strv(args, " \t", 3, &n_tokens);
|
||||
if (n_tokens < 2)
|
||||
goto not_enough_arguments;
|
||||
goto error_arguments;
|
||||
|
||||
if (n_tokens == 3) {
|
||||
props = pw_properties_new_string(argv[2]);
|
||||
if (props == NULL)
|
||||
return -ENOMEM;
|
||||
if (props == NULL) {
|
||||
res = -errno;
|
||||
goto error_exit_cleanup;
|
||||
}
|
||||
}
|
||||
|
||||
device = pw_spa_device_load(core,
|
||||
|
|
@ -95,12 +101,13 @@ int pipewire__module_init(struct pw_module *module, const char *args)
|
|||
0,
|
||||
props,
|
||||
sizeof(struct device_data));
|
||||
if (device == NULL) {
|
||||
res = -errno;
|
||||
goto error_exit_cleanup;
|
||||
}
|
||||
|
||||
pw_free_strv(argv);
|
||||
|
||||
if (device == NULL)
|
||||
return -ENOMEM;
|
||||
|
||||
data = pw_spa_device_get_user_data(device);
|
||||
data->this = device;
|
||||
data->core = core;
|
||||
|
|
@ -112,9 +119,12 @@ int pipewire__module_init(struct pw_module *module, const char *args)
|
|||
|
||||
return 0;
|
||||
|
||||
not_enough_arguments:
|
||||
pw_free_strv(argv);
|
||||
wrong_arguments:
|
||||
error_arguments:
|
||||
res = -EINVAL;
|
||||
pw_log_error("usage: module-spa-device " MODULE_USAGE);
|
||||
return -EINVAL;
|
||||
goto error_exit_cleanup;
|
||||
error_exit_cleanup:
|
||||
if (argv)
|
||||
pw_free_strv(argv);
|
||||
return res;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -72,22 +72,24 @@ int pipewire__module_init(struct pw_module *module, const char *args)
|
|||
{
|
||||
struct pw_core *core = pw_module_get_core(module);
|
||||
struct pw_properties *props = NULL;
|
||||
char **argv;
|
||||
int n_tokens;
|
||||
char **argv = NULL;
|
||||
int n_tokens, res;
|
||||
struct pw_spa_monitor *monitor;
|
||||
struct data *data;
|
||||
|
||||
if (args == NULL)
|
||||
goto wrong_arguments;
|
||||
goto error_arguments;
|
||||
|
||||
argv = pw_split_strv(args, " \t", INT_MAX, &n_tokens);
|
||||
if (n_tokens < 2)
|
||||
goto not_enough_arguments;
|
||||
goto error_arguments;
|
||||
|
||||
if (n_tokens == 3) {
|
||||
props = pw_properties_new_string(argv[2]);
|
||||
if (props == NULL)
|
||||
return -ENOMEM;
|
||||
if (props == NULL) {
|
||||
res = -errno;
|
||||
goto error_exit_cleanup;
|
||||
}
|
||||
}
|
||||
|
||||
monitor = pw_spa_monitor_load(core,
|
||||
|
|
@ -95,23 +97,28 @@ int pipewire__module_init(struct pw_module *module, const char *args)
|
|||
argv[0], argv[1],
|
||||
props,
|
||||
sizeof(struct data));
|
||||
if (monitor == NULL)
|
||||
return -ENOMEM;
|
||||
if (monitor == NULL) {
|
||||
res = -errno;
|
||||
goto error_exit_cleanup;
|
||||
}
|
||||
|
||||
pw_free_strv(argv);
|
||||
|
||||
data = monitor->user_data;
|
||||
data->monitor = monitor;
|
||||
|
||||
pw_free_strv(argv);
|
||||
|
||||
pw_module_add_listener(module, &data->module_listener, &module_events, data);
|
||||
|
||||
pw_module_update_properties(module, &SPA_DICT_INIT_ARRAY(module_props));
|
||||
|
||||
return 0;
|
||||
|
||||
not_enough_arguments:
|
||||
pw_free_strv(argv);
|
||||
wrong_arguments:
|
||||
error_arguments:
|
||||
res = -EINVAL;
|
||||
pw_log_error("usage: module-spa-monitor " MODULE_USAGE);
|
||||
return -EINVAL;
|
||||
goto error_exit_cleanup;
|
||||
error_exit_cleanup:
|
||||
if (argv)
|
||||
pw_free_strv(argv);
|
||||
return res;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -83,13 +83,14 @@ static void *create_object(void *_data,
|
|||
struct pw_node *node;
|
||||
const char *factory_name, *name;
|
||||
struct node_data *nd;
|
||||
int res;
|
||||
|
||||
if (properties == NULL)
|
||||
goto no_properties;
|
||||
goto error_properties;
|
||||
|
||||
factory_name = pw_properties_get(properties, SPA_KEY_FACTORY_NAME);
|
||||
if (factory_name == NULL)
|
||||
goto no_properties;
|
||||
goto error_properties;
|
||||
|
||||
name = pw_properties_get(properties, PW_KEY_NODE_NAME);
|
||||
if (name == NULL)
|
||||
|
|
@ -104,7 +105,7 @@ static void *create_object(void *_data,
|
|||
properties,
|
||||
sizeof(struct node_data));
|
||||
if (node == NULL)
|
||||
goto no_mem;
|
||||
goto error_create_node;
|
||||
|
||||
nd = pw_spa_node_get_user_data(node);
|
||||
nd->node = node;
|
||||
|
|
@ -120,17 +121,24 @@ static void *create_object(void *_data,
|
|||
|
||||
return node;
|
||||
|
||||
no_properties:
|
||||
error_properties:
|
||||
res = -EINVAL;
|
||||
pw_log_error("factory %p: usage: " FACTORY_USAGE, data->this);
|
||||
if (resource) {
|
||||
pw_resource_error(resource, -EINVAL, "usage: " FACTORY_USAGE);
|
||||
}
|
||||
return NULL;
|
||||
no_mem:
|
||||
pw_log_error("can't create node: no memory");
|
||||
if (resource) {
|
||||
pw_resource_error(resource, -ENOMEM, "no memory");
|
||||
}
|
||||
if (resource)
|
||||
pw_resource_error(resource, res, "usage: " FACTORY_USAGE);
|
||||
goto error_exit_cleanup;
|
||||
error_create_node:
|
||||
res = -errno;
|
||||
pw_log_error("can't create node: %m");
|
||||
if (resource)
|
||||
pw_resource_error(resource, res, "can't create node: %s", spa_strerror(res));
|
||||
goto error_exit;
|
||||
|
||||
error_exit_cleanup:
|
||||
if (properties)
|
||||
pw_properties_free(properties);
|
||||
error_exit:
|
||||
errno = -res;
|
||||
return NULL;
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -60,6 +60,7 @@ struct node_data {
|
|||
static void module_destroy(void *_data)
|
||||
{
|
||||
struct node_data *data = _data;
|
||||
spa_hook_remove(&data->module_listener);
|
||||
pw_node_destroy(data->this);
|
||||
}
|
||||
|
||||
|
|
@ -72,23 +73,25 @@ SPA_EXPORT
|
|||
int pipewire__module_init(struct pw_module *module, const char *args)
|
||||
{
|
||||
struct pw_properties *props = NULL;
|
||||
char **argv;
|
||||
int n_tokens;
|
||||
char **argv = NULL;
|
||||
int n_tokens, res;
|
||||
struct pw_core *core = pw_module_get_core(module);
|
||||
struct pw_node *node;
|
||||
struct node_data *data;
|
||||
|
||||
if (args == NULL)
|
||||
goto wrong_arguments;
|
||||
goto error_arguments;
|
||||
|
||||
argv = pw_split_strv(args, " \t", 3, &n_tokens);
|
||||
if (n_tokens < 2)
|
||||
goto not_enough_arguments;
|
||||
goto error_arguments;
|
||||
|
||||
if (n_tokens == 3) {
|
||||
props = pw_properties_new_string(argv[2]);
|
||||
if (props == NULL)
|
||||
return -ENOMEM;
|
||||
if (props == NULL) {
|
||||
res = -errno;
|
||||
goto error_exit_cleanup;
|
||||
}
|
||||
}
|
||||
|
||||
node = pw_spa_node_load(core,
|
||||
|
|
@ -99,10 +102,12 @@ int pipewire__module_init(struct pw_module *module, const char *args)
|
|||
props,
|
||||
sizeof(struct node_data));
|
||||
|
||||
pw_free_strv(argv);
|
||||
if (node == NULL) {
|
||||
res = -errno;
|
||||
goto error_exit_cleanup;
|
||||
}
|
||||
|
||||
if (node == NULL)
|
||||
return -ENOMEM;
|
||||
pw_free_strv(argv);
|
||||
|
||||
data = pw_spa_node_get_user_data(node);
|
||||
data->this = node;
|
||||
|
|
@ -116,9 +121,12 @@ int pipewire__module_init(struct pw_module *module, const char *args)
|
|||
|
||||
return 0;
|
||||
|
||||
not_enough_arguments:
|
||||
pw_free_strv(argv);
|
||||
wrong_arguments:
|
||||
error_arguments:
|
||||
res = -EINVAL;
|
||||
pw_log_error("usage: module-spa-node " MODULE_USAGE);
|
||||
return -EINVAL;
|
||||
goto error_exit_cleanup;
|
||||
error_exit_cleanup:
|
||||
if (argv)
|
||||
pw_free_strv(argv);
|
||||
return res;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -142,30 +142,34 @@ struct pw_device *pw_spa_device_load(struct pw_core *core,
|
|||
|
||||
handle = pw_core_load_spa_handle(core, factory_name,
|
||||
properties ? &properties->dict : NULL);
|
||||
if (handle == NULL) {
|
||||
res = -errno;
|
||||
pw_log_error("can't load device handle: %m");
|
||||
goto exit;
|
||||
}
|
||||
if (handle == NULL)
|
||||
goto error_load;
|
||||
|
||||
if ((res = spa_handle_get_interface(handle, SPA_TYPE_INTERFACE_Device, &iface)) < 0) {
|
||||
pw_log_error("can't get device interface %d", res);
|
||||
goto exit_unload;
|
||||
}
|
||||
if ((res = spa_handle_get_interface(handle, SPA_TYPE_INTERFACE_Device, &iface)) < 0)
|
||||
goto error_interface;
|
||||
|
||||
this = pw_spa_device_new(core, owner, parent, name, flags,
|
||||
iface, handle, properties, user_data_size);
|
||||
if (this == NULL) {
|
||||
res = -errno;
|
||||
pw_log_error("can't create device: %m");
|
||||
goto exit_unload;
|
||||
}
|
||||
if (this == NULL)
|
||||
goto error_device;
|
||||
|
||||
return this;
|
||||
|
||||
exit_unload:
|
||||
error_load:
|
||||
res = -errno;
|
||||
pw_log_error("can't load device handle: %m");
|
||||
goto error_exit;
|
||||
error_interface:
|
||||
pw_log_error("can't get device interface %d", res);
|
||||
goto error_exit_unload;
|
||||
error_device:
|
||||
res = -errno;
|
||||
pw_log_error("can't create device: %m");
|
||||
goto error_exit_unload;
|
||||
|
||||
error_exit_unload:
|
||||
pw_unload_spa_handle(handle);
|
||||
exit:
|
||||
error_exit:
|
||||
errno = -res;
|
||||
return NULL;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -117,18 +117,18 @@ static struct monitor_object *add_object(struct pw_spa_monitor *this, uint32_t i
|
|||
if (handle == NULL) {
|
||||
res = -errno;
|
||||
pw_log_error("can't make factory instance: %m");
|
||||
goto error_free_props;
|
||||
goto error_exit_free_props;
|
||||
}
|
||||
|
||||
if ((res = spa_handle_get_interface(handle, info->type, &iface)) < 0) {
|
||||
pw_log_error("can't get %d interface: %s", info->type, spa_strerror(res));
|
||||
goto error_free_handle;
|
||||
goto error_exit_free_handle;
|
||||
}
|
||||
|
||||
obj = calloc(1, sizeof(struct monitor_object));
|
||||
if (obj == NULL) {
|
||||
res = -errno;
|
||||
goto error_free_handle;
|
||||
goto error_exit_free_handle;
|
||||
}
|
||||
obj->id = id;
|
||||
obj->name = strdup(name);
|
||||
|
|
@ -149,19 +149,19 @@ static struct monitor_object *add_object(struct pw_spa_monitor *this, uint32_t i
|
|||
default:
|
||||
res = -ENOTSUP;
|
||||
pw_log_error("interface %d not implemented", obj->type);
|
||||
goto error_free_object;
|
||||
goto error_exit_free_object;
|
||||
}
|
||||
|
||||
spa_list_append(&impl->item_list, &obj->link);
|
||||
|
||||
return obj;
|
||||
|
||||
error_free_object:
|
||||
error_exit_free_object:
|
||||
free(obj->name);
|
||||
free(obj);
|
||||
error_free_handle:
|
||||
error_exit_free_handle:
|
||||
pw_unload_spa_handle(handle);
|
||||
error_free_props:
|
||||
error_exit_free_props:
|
||||
pw_properties_free(props);
|
||||
errno = -res;
|
||||
return NULL;
|
||||
|
|
@ -279,18 +279,18 @@ struct pw_spa_monitor *pw_spa_monitor_load(struct pw_core *core,
|
|||
properties ? &properties->dict : NULL);
|
||||
if (handle == NULL) {
|
||||
res = -errno;
|
||||
goto exit;
|
||||
goto error_exit;
|
||||
}
|
||||
|
||||
if ((res = spa_handle_get_interface(handle, SPA_TYPE_INTERFACE_Monitor, &iface)) < 0) {
|
||||
pw_log_error("can't get MONITOR interface: %s", spa_strerror(res));
|
||||
goto exit_unload;
|
||||
goto error_exit_unload;
|
||||
}
|
||||
|
||||
impl = calloc(1, sizeof(struct impl) + user_data_size);
|
||||
if (impl == NULL) {
|
||||
res = -errno;
|
||||
goto exit_unload;
|
||||
goto error_exit_unload;
|
||||
}
|
||||
|
||||
impl->core = core;
|
||||
|
|
@ -313,12 +313,11 @@ struct pw_spa_monitor *pw_spa_monitor_load(struct pw_core *core,
|
|||
|
||||
return this;
|
||||
|
||||
exit_unload:
|
||||
error_exit_unload:
|
||||
pw_unload_spa_handle(handle);
|
||||
exit:
|
||||
error_exit:
|
||||
errno = -res;
|
||||
return NULL;
|
||||
|
||||
}
|
||||
|
||||
void pw_spa_monitor_destroy(struct pw_spa_monitor *monitor)
|
||||
|
|
|
|||
|
|
@ -125,14 +125,17 @@ pw_spa_node_new(struct pw_core *core,
|
|||
int res;
|
||||
|
||||
this = pw_node_new(core, name, properties, sizeof(struct impl) + user_data_size);
|
||||
if (this == NULL)
|
||||
return NULL;
|
||||
if (this == NULL) {
|
||||
res = -errno;
|
||||
goto error_exit;
|
||||
}
|
||||
|
||||
impl = this->user_data;
|
||||
impl->this = this;
|
||||
impl->owner = owner;
|
||||
impl->parent = parent;
|
||||
impl->node = node;
|
||||
impl->handle = handle;
|
||||
impl->flags = flags;
|
||||
|
||||
if (user_data_size > 0)
|
||||
|
|
@ -140,7 +143,7 @@ pw_spa_node_new(struct pw_core *core,
|
|||
|
||||
pw_node_add_listener(this, &impl->node_listener, &node_events, impl);
|
||||
if ((res = pw_node_set_implementation(this, impl->node)) < 0)
|
||||
goto clean_node;
|
||||
goto error_exit_clean_node;
|
||||
|
||||
if (flags & PW_SPA_NODE_FLAG_ASYNC) {
|
||||
impl->init_pending = spa_node_sync(impl->node, res);
|
||||
|
|
@ -149,8 +152,12 @@ pw_spa_node_new(struct pw_core *core,
|
|||
}
|
||||
return this;
|
||||
|
||||
clean_node:
|
||||
error_exit_clean_node:
|
||||
pw_node_destroy(this);
|
||||
handle = NULL;
|
||||
error_exit:
|
||||
if (handle)
|
||||
pw_unload_spa_handle(handle);
|
||||
errno = -res;
|
||||
return NULL;
|
||||
|
||||
|
|
@ -257,12 +264,12 @@ struct pw_node *pw_spa_node_load(struct pw_core *core,
|
|||
properties ? &properties->dict : NULL);
|
||||
if (handle == NULL) {
|
||||
res = -errno;
|
||||
goto exit;
|
||||
goto error_exit_cleanup;
|
||||
}
|
||||
|
||||
if ((res = spa_handle_get_interface(handle, SPA_TYPE_INTERFACE_Node, &iface)) < 0) {
|
||||
pw_log_error("can't get node interface %d", res);
|
||||
goto exit_unload;
|
||||
goto error_exit_unload;
|
||||
}
|
||||
if (SPA_RESULT_IS_ASYNC(res))
|
||||
flags |= PW_SPA_NODE_FLAG_ASYNC;
|
||||
|
|
@ -279,18 +286,20 @@ struct pw_node *pw_spa_node_load(struct pw_core *core,
|
|||
spa_node, handle, properties, user_data_size);
|
||||
if (this == NULL) {
|
||||
res = -errno;
|
||||
goto exit;
|
||||
goto error_exit;
|
||||
}
|
||||
|
||||
impl = this->user_data;
|
||||
impl->handle = handle;
|
||||
impl->factory_name = strdup(factory_name);
|
||||
|
||||
return this;
|
||||
|
||||
exit_unload:
|
||||
error_exit_unload:
|
||||
pw_unload_spa_handle(handle);
|
||||
exit:
|
||||
error_exit_cleanup:
|
||||
if (properties)
|
||||
pw_properties_free(properties);
|
||||
error_exit:
|
||||
errno = -res;
|
||||
return NULL;
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue