Use errno for result errors

Make new enumeration for data transport status and use errno
style error numbers for errors.
This commit is contained in:
Wim Taymans 2017-11-13 09:41:41 +01:00
parent dda28b1589
commit 6fb0f580ea
86 changed files with 2019 additions and 1988 deletions

View file

@ -151,24 +151,24 @@ static int impl_get_interface(struct spa_handle *handle, uint32_t interface_id,
{
struct impl *this;
spa_return_val_if_fail(handle != NULL, SPA_RESULT_INVALID_ARGUMENTS);
spa_return_val_if_fail(interface != NULL, SPA_RESULT_INVALID_ARGUMENTS);
spa_return_val_if_fail(handle != NULL, -EINVAL);
spa_return_val_if_fail(interface != NULL, -EINVAL);
this = (struct impl *) handle;
if (interface_id == this->type.log)
*interface = &this->log;
else
return SPA_RESULT_UNKNOWN_INTERFACE;
return -ENOENT;
return SPA_RESULT_OK;
return 0;
}
static int impl_clear(struct spa_handle *handle)
{
struct impl *this;
spa_return_val_if_fail(handle != NULL, SPA_RESULT_INVALID_ARGUMENTS);
spa_return_val_if_fail(handle != NULL, -EINVAL);
this = (struct impl *) handle;
@ -177,7 +177,7 @@ static int impl_clear(struct spa_handle *handle)
close(this->source.fd);
this->have_source = false;
}
return SPA_RESULT_OK;
return 0;
}
static int
@ -191,8 +191,8 @@ impl_init(const struct spa_handle_factory *factory,
uint32_t i;
struct spa_loop *loop = NULL;
spa_return_val_if_fail(factory != NULL, SPA_RESULT_INVALID_ARGUMENTS);
spa_return_val_if_fail(handle != NULL, SPA_RESULT_INVALID_ARGUMENTS);
spa_return_val_if_fail(factory != NULL, -EINVAL);
spa_return_val_if_fail(handle != NULL, -EINVAL);
handle->get_interface = impl_get_interface;
handle->clear = impl_clear;
@ -209,7 +209,7 @@ impl_init(const struct spa_handle_factory *factory,
}
if (this->map == NULL) {
spa_log_error(&this->log, "a type-map is needed");
return SPA_RESULT_ERROR;
return -EINVAL;
}
init_type(&this->type, this->map);
@ -227,7 +227,7 @@ impl_init(const struct spa_handle_factory *factory,
spa_log_debug(&this->log, NAME " %p: initialized", this);
return SPA_RESULT_OK;
return 0;
}
static const struct spa_interface_info impl_interfaces[] = {
@ -237,19 +237,22 @@ static const struct spa_interface_info impl_interfaces[] = {
static int
impl_enum_interface_info(const struct spa_handle_factory *factory,
const struct spa_interface_info **info,
uint32_t index)
uint32_t *index)
{
spa_return_val_if_fail(factory != NULL, SPA_RESULT_INVALID_ARGUMENTS);
spa_return_val_if_fail(info != NULL, SPA_RESULT_INVALID_ARGUMENTS);
spa_return_val_if_fail(factory != NULL, -EINVAL);
spa_return_val_if_fail(info != NULL, -EINVAL);
spa_return_val_if_fail(index != NULL, -EINVAL);
switch (index) {
switch (*index) {
case 0:
*info = &impl_interfaces[index];
*info = &impl_interfaces[*index];
break;
default:
return SPA_RESULT_ENUM_END;
return 0;
}
return SPA_RESULT_OK;
(*index)++;
return 1;
}
static const struct spa_handle_factory logger_factory = {

View file

@ -157,9 +157,9 @@ static int loop_add_source(struct spa_loop *loop, struct spa_source *source)
ep.data.ptr = source;
if (epoll_ctl(impl->epoll_fd, EPOLL_CTL_ADD, source->fd, &ep) < 0)
return SPA_RESULT_ERRNO;
return errno;
}
return SPA_RESULT_OK;
return 0;
}
static int loop_update_source(struct spa_source *source)
@ -175,9 +175,9 @@ static int loop_update_source(struct spa_source *source)
ep.data.ptr = source;
if (epoll_ctl(impl->epoll_fd, EPOLL_CTL_MOD, source->fd, &ep) < 0)
return SPA_RESULT_ERRNO;
return errno;
}
return SPA_RESULT_OK;
return 0;
}
static void loop_remove_source(struct spa_source *source)
@ -215,12 +215,12 @@ loop_invoke(struct spa_loop *loop,
filled = spa_ringbuffer_get_write_index(&impl->buffer, &idx);
if (filled < 0 || filled > impl->buffer.size) {
spa_log_warn(impl->log, NAME " %p: queue xrun %d", impl, filled);
return SPA_RESULT_ERROR;
return -EPIPE;
}
avail = impl->buffer.size - filled;
if (avail < sizeof(struct invoke_item)) {
spa_log_warn(impl->log, NAME " %p: queue full %d", impl, avail);
return SPA_RESULT_ERROR;
return -EPIPE;
}
offset = idx & impl->buffer.mask;
@ -258,7 +258,7 @@ loop_invoke(struct spa_loop *loop,
if (seq != SPA_ID_INVALID)
res = SPA_RESULT_RETURN_ASYNC(seq);
else
res = SPA_RESULT_OK;
res = 0;
}
}
return res;
@ -329,10 +329,8 @@ static int loop_iterate(struct spa_loop_control *ctrl, int timeout)
spa_hook_list_call(&impl->hooks_list, struct spa_loop_control_hooks, after);
if (SPA_UNLIKELY(nfds < 0)) {
errno = save_errno;
return SPA_RESULT_ERRNO;
}
if (SPA_UNLIKELY(nfds < 0))
return save_errno;
/* first we set all the rmasks, then call the callbacks. The reason is that
* some callback might also want to look at other sources it manages and
@ -352,7 +350,7 @@ static int loop_iterate(struct spa_loop_control *ctrl, int timeout)
spa_list_init(&impl->destroy_list);
return SPA_RESULT_OK;
return 0;
}
static void source_io_func(struct spa_source *source)
@ -555,9 +553,9 @@ loop_update_timer(struct spa_source *source,
flags |= TFD_TIMER_ABSTIME;
if (timerfd_settime(source->fd, flags, &its, NULL) < 0)
return SPA_RESULT_ERRNO;
return errno;
return SPA_RESULT_OK;
return 0;
}
static void source_signal_func(struct spa_source *source)
@ -660,8 +658,8 @@ static int impl_get_interface(struct spa_handle *handle, uint32_t interface_id,
{
struct impl *impl;
spa_return_val_if_fail(handle != NULL, SPA_RESULT_INVALID_ARGUMENTS);
spa_return_val_if_fail(interface != NULL, SPA_RESULT_INVALID_ARGUMENTS);
spa_return_val_if_fail(handle != NULL, -EINVAL);
spa_return_val_if_fail(interface != NULL, -EINVAL);
impl = (struct impl *) handle;
@ -672,9 +670,9 @@ static int impl_get_interface(struct spa_handle *handle, uint32_t interface_id,
else if (interface_id == impl->type.loop_utils)
*interface = &impl->utils;
else
return SPA_RESULT_UNKNOWN_INTERFACE;
return -ENOENT;
return SPA_RESULT_OK;
return 0;
}
static int impl_clear(struct spa_handle *handle)
@ -682,7 +680,7 @@ static int impl_clear(struct spa_handle *handle)
struct impl *impl;
struct source_impl *source, *tmp;
spa_return_val_if_fail(handle != NULL, SPA_RESULT_INVALID_ARGUMENTS);
spa_return_val_if_fail(handle != NULL, -EINVAL);
impl = (struct impl *) handle;
@ -694,7 +692,7 @@ static int impl_clear(struct spa_handle *handle)
close(impl->ack_fd);
close(impl->epoll_fd);
return SPA_RESULT_OK;
return 0;
}
static int
@ -707,8 +705,8 @@ impl_init(const struct spa_handle_factory *factory,
struct impl *impl;
uint32_t i;
spa_return_val_if_fail(factory != NULL, SPA_RESULT_INVALID_ARGUMENTS);
spa_return_val_if_fail(handle != NULL, SPA_RESULT_INVALID_ARGUMENTS);
spa_return_val_if_fail(factory != NULL, -EINVAL);
spa_return_val_if_fail(handle != NULL, -EINVAL);
handle->get_interface = impl_get_interface;
handle->clear = impl_clear;
@ -726,13 +724,13 @@ impl_init(const struct spa_handle_factory *factory,
}
if (impl->map == NULL) {
spa_log_error(impl->log, NAME " %p: a type-map is needed", impl);
return SPA_RESULT_ERROR;
return -EINVAL;
}
init_type(&impl->type, impl->map);
impl->epoll_fd = epoll_create1(EPOLL_CLOEXEC);
if (impl->epoll_fd == -1)
return SPA_RESULT_ERRNO;
return errno;
spa_list_init(&impl->source_list);
spa_list_init(&impl->destroy_list);
@ -745,7 +743,7 @@ impl_init(const struct spa_handle_factory *factory,
spa_log_info(impl->log, NAME " %p: initialized", impl);
return SPA_RESULT_OK;
return 0;
}
static const struct spa_interface_info impl_interfaces[] = {
@ -757,16 +755,17 @@ static const struct spa_interface_info impl_interfaces[] = {
static int
impl_enum_interface_info(const struct spa_handle_factory *factory,
const struct spa_interface_info **info,
uint32_t index)
uint32_t *index)
{
spa_return_val_if_fail(factory != NULL, SPA_RESULT_INVALID_ARGUMENTS);
spa_return_val_if_fail(info != NULL, SPA_RESULT_INVALID_ARGUMENTS);
spa_return_val_if_fail(factory != NULL, -EINVAL);
spa_return_val_if_fail(info != NULL, -EINVAL);
spa_return_val_if_fail(index != NULL, -EINVAL);
if (index >= SPA_N_ELEMENTS(impl_interfaces))
return SPA_RESULT_ENUM_END;
if (*index >= SPA_N_ELEMENTS(impl_interfaces))
return 0;
*info = &impl_interfaces[index];
return SPA_RESULT_OK;
*info = &impl_interfaces[(*index)++];
return 1;
}
static const struct spa_handle_factory loop_factory = {

View file

@ -125,24 +125,24 @@ static int impl_get_interface(struct spa_handle *handle, uint32_t interface_id,
{
struct impl *impl;
spa_return_val_if_fail(handle != NULL, SPA_RESULT_INVALID_ARGUMENTS);
spa_return_val_if_fail(interface != NULL, SPA_RESULT_INVALID_ARGUMENTS);
spa_return_val_if_fail(handle != NULL, -EINVAL);
spa_return_val_if_fail(interface != NULL, -EINVAL);
impl = (struct impl *) handle;
if (interface_id == impl->type.type_map)
*interface = &impl->map;
else
return SPA_RESULT_UNKNOWN_INTERFACE;
return -ENOENT;
return SPA_RESULT_OK;
return 0;
}
static int impl_clear(struct spa_handle *handle)
{
struct impl *impl;
spa_return_val_if_fail(handle != NULL, SPA_RESULT_INVALID_ARGUMENTS);
spa_return_val_if_fail(handle != NULL, -EINVAL);
impl = (struct impl *) handle;
@ -151,7 +151,7 @@ static int impl_clear(struct spa_handle *handle)
if (impl->strings.data)
free(impl->strings.data);
return SPA_RESULT_OK;
return 0;
}
static int
@ -163,8 +163,8 @@ impl_init(const struct spa_handle_factory *factory,
{
struct impl *impl;
spa_return_val_if_fail(factory != NULL, SPA_RESULT_INVALID_ARGUMENTS);
spa_return_val_if_fail(handle != NULL, SPA_RESULT_INVALID_ARGUMENTS);
spa_return_val_if_fail(factory != NULL, -EINVAL);
spa_return_val_if_fail(handle != NULL, -EINVAL);
handle->get_interface = impl_get_interface;
handle->clear = impl_clear;
@ -175,7 +175,7 @@ impl_init(const struct spa_handle_factory *factory,
init_type(&impl->type, &impl->map);
return SPA_RESULT_OK;
return 0;
}
static const struct spa_interface_info impl_interfaces[] = {
@ -185,19 +185,21 @@ static const struct spa_interface_info impl_interfaces[] = {
static int
impl_enum_interface_info(const struct spa_handle_factory *factory,
const struct spa_interface_info **info,
uint32_t index)
uint32_t *index)
{
spa_return_val_if_fail(factory != NULL, SPA_RESULT_INVALID_ARGUMENTS);
spa_return_val_if_fail(info != NULL, SPA_RESULT_INVALID_ARGUMENTS);
spa_return_val_if_fail(factory != NULL, -EINVAL);
spa_return_val_if_fail(info != NULL, -EINVAL);
spa_return_val_if_fail(index != NULL, -EINVAL);
switch (index) {
switch (*index) {
case 0:
*info = &impl_interfaces[index];
*info = &impl_interfaces[*index];
break;
default:
return SPA_RESULT_ENUM_END;
return 0;
}
return SPA_RESULT_OK;
(*index)++;
return 1;
}
static const struct spa_handle_factory type_map_factory = {

View file

@ -17,6 +17,7 @@
* Boston, MA 02110-1301, USA.
*/
#include <errno.h>
#include <stdio.h>
#include <spa/support/plugin.h>
@ -36,13 +37,14 @@ spa_handle_factory_register(const struct spa_handle_factory *factory)
}
int
spa_handle_factory_enum(const struct spa_handle_factory **factory, uint32_t index)
spa_handle_factory_enum(const struct spa_handle_factory **factory, uint32_t *index)
{
spa_return_val_if_fail(factory != NULL, SPA_RESULT_INVALID_ARGUMENTS);
spa_return_val_if_fail(factory != NULL, -EINVAL);
spa_return_val_if_fail(index != NULL, -EINVAL);
if (index >= n_factories)
return SPA_RESULT_ENUM_END;
if (*index >= n_factories)
return 0;
*factory = factories[index];
return SPA_RESULT_OK;
*factory = factories[(*index)++];
return 1;
}