Make interface types a string

This is more in line with wayland and it allows us to create new
interfaces in modules without having to add anything to the type
enum. It also removes some lookups to map type_id to readable
name in debug.
This commit is contained in:
Wim Taymans 2019-12-19 13:15:10 +01:00
parent 9657486a81
commit f391353c7f
123 changed files with 791 additions and 1251 deletions

View file

@ -122,7 +122,7 @@ static const struct spa_cpu_methods impl_cpu = {
.get_max_align = impl_cpu_get_max_align,
};
static int impl_get_interface(struct spa_handle *handle, uint32_t type, void **interface)
static int impl_get_interface(struct spa_handle *handle, const char *type, void **interface)
{
struct impl *this;
@ -131,7 +131,7 @@ static int impl_get_interface(struct spa_handle *handle, uint32_t type, void **i
this = (struct impl *) handle;
if (type == SPA_TYPE_INTERFACE_CPU)
if (strcmp(type, SPA_TYPE_INTERFACE_CPU) == 0)
*interface = &this->cpu;
else
return -ENOENT;
@ -160,7 +160,6 @@ impl_init(const struct spa_handle_factory *factory,
{
struct impl *this;
const char *str;
uint32_t i;
spa_return_val_if_fail(factory != NULL, -EINVAL);
spa_return_val_if_fail(handle != NULL, -EINVAL);
@ -175,13 +174,8 @@ impl_init(const struct spa_handle_factory *factory,
SPA_VERSION_CPU,
&impl_cpu, this);
for (i = 0; i < n_support; i++) {
switch (support[i].type) {
case SPA_TYPE_INTERFACE_Log:
this->log = support[i].data;
break;
}
}
this->log = spa_support_find(support, n_support, SPA_TYPE_INTERFACE_Log);
this->flags = 0;
this->force = SPA_CPU_FORCE_AUTODETECT;
this->max_align = 16;

View file

@ -339,7 +339,7 @@ static const struct spa_dbus_methods impl_dbus = {
.get_connection = impl_get_connection,
};
static int impl_get_interface(struct spa_handle *handle, uint32_t type, void **interface)
static int impl_get_interface(struct spa_handle *handle, const char *type, void **interface)
{
struct impl *this;
@ -348,7 +348,7 @@ static int impl_get_interface(struct spa_handle *handle, uint32_t type, void **i
this = (struct impl *) handle;
if (type == SPA_TYPE_INTERFACE_DBus)
if (strcmp(type, SPA_TYPE_INTERFACE_DBus) == 0)
*interface = &this->dbus;
else
return -ENOENT;
@ -377,7 +377,6 @@ impl_init(const struct spa_handle_factory *factory,
uint32_t n_support)
{
struct impl *this;
uint32_t i;
spa_return_val_if_fail(factory != NULL, -EINVAL);
spa_return_val_if_fail(handle != NULL, -EINVAL);
@ -393,16 +392,9 @@ impl_init(const struct spa_handle_factory *factory,
SPA_VERSION_DBUS,
&impl_dbus, this);
for (i = 0; i < n_support; i++) {
switch (support[i].type) {
case SPA_TYPE_INTERFACE_Log:
this->log = support[i].data;
break;
case SPA_TYPE_INTERFACE_LoopUtils:
this->utils = support[i].data;
break;
}
}
this->log = spa_support_find(support, n_support, SPA_TYPE_INTERFACE_Log);
this->utils = spa_support_find(support, n_support, SPA_TYPE_INTERFACE_LoopUtils);
if (this->utils == NULL) {
spa_log_error(this->log, "a LoopUtils is needed");
return -EINVAL;

View file

@ -362,7 +362,7 @@ static const struct spa_system_methods impl_system = {
.signalfd_read = impl_signalfd_read,
};
static int impl_get_interface(struct spa_handle *handle, uint32_t type, void **interface)
static int impl_get_interface(struct spa_handle *handle, const char *type, void **interface)
{
struct impl *impl;
@ -371,13 +371,11 @@ static int impl_get_interface(struct spa_handle *handle, uint32_t type, void **i
impl = (struct impl *) handle;
switch (type) {
case SPA_TYPE_INTERFACE_System:
if (strcmp(type, SPA_TYPE_INTERFACE_System) == 0)
*interface = &impl->system;
break;
default:
else
return -ENOENT;
}
return 0;
}
@ -402,7 +400,6 @@ impl_init(const struct spa_handle_factory *factory,
uint32_t n_support)
{
struct impl *impl;
uint32_t i;
int res;
spa_return_val_if_fail(factory != NULL, -EINVAL);
@ -417,13 +414,8 @@ impl_init(const struct spa_handle_factory *factory,
SPA_VERSION_SYSTEM,
&impl_system, impl);
for (i = 0; i < n_support; i++) {
switch (support[i].type) {
case SPA_TYPE_INTERFACE_Log:
impl->log = support[i].data;
break;
}
}
impl->log = spa_support_find(support, n_support, SPA_TYPE_INTERFACE_Log);
impl->pid = getpid();
if ((res = evl_attach_self("evl-system-%d-%p", impl->pid, impl)) < 0) {

View file

@ -174,7 +174,7 @@ static const struct spa_log_methods impl_log = {
.logv = impl_log_logv,
};
static int impl_get_interface(struct spa_handle *handle, uint32_t type, void **interface)
static int impl_get_interface(struct spa_handle *handle, const char *type, void **interface)
{
struct impl *this;
@ -183,7 +183,7 @@ static int impl_get_interface(struct spa_handle *handle, uint32_t type, void **i
this = (struct impl *) handle;
if (type == SPA_TYPE_INTERFACE_Log)
if (strcmp(type, SPA_TYPE_INTERFACE_Log) == 0)
*interface = &this->log;
else
return -ENOENT;
@ -222,7 +222,6 @@ impl_init(const struct spa_handle_factory *factory,
uint32_t n_support)
{
struct impl *this;
uint32_t i;
struct spa_loop *loop = NULL;
const char *str;
@ -240,16 +239,9 @@ impl_init(const struct spa_handle_factory *factory,
&impl_log, this);
this->log.level = DEFAULT_LOG_LEVEL;
for (i = 0; i < n_support; i++) {
switch (support[i].type) {
case SPA_TYPE_INTERFACE_Loop:
loop = support[i].data;
break;
case SPA_TYPE_INTERFACE_System:
this->system = support[i].data;
break;
}
}
loop = spa_support_find(support, n_support, SPA_TYPE_INTERFACE_Loop);
this->system = spa_support_find(support, n_support, SPA_TYPE_INTERFACE_System);
if (loop != NULL && this->system != NULL) {
this->source.func = on_trace_event;
this->source.data = this;

View file

@ -664,7 +664,7 @@ static const struct spa_loop_utils_methods impl_loop_utils = {
.destroy_source = loop_destroy_source,
};
static int impl_get_interface(struct spa_handle *handle, uint32_t type, void **interface)
static int impl_get_interface(struct spa_handle *handle, const char *type, void **interface)
{
struct impl *impl;
@ -673,19 +673,15 @@ static int impl_get_interface(struct spa_handle *handle, uint32_t type, void **i
impl = (struct impl *) handle;
switch (type) {
case SPA_TYPE_INTERFACE_Loop:
if (strcmp(type, SPA_TYPE_INTERFACE_Loop) == 0)
*interface = &impl->loop;
break;
case SPA_TYPE_INTERFACE_LoopControl:
else if (strcmp(type, SPA_TYPE_INTERFACE_LoopControl) == 0)
*interface = &impl->control;
break;
case SPA_TYPE_INTERFACE_LoopUtils:
else if (strcmp(type, SPA_TYPE_INTERFACE_LoopUtils) == 0)
*interface = &impl->utils;
break;
default:
else
return -ENOENT;
}
return 0;
}
@ -724,7 +720,6 @@ impl_init(const struct spa_handle_factory *factory,
uint32_t n_support)
{
struct impl *impl;
uint32_t i;
int res;
spa_return_val_if_fail(factory != NULL, -EINVAL);
@ -747,16 +742,9 @@ impl_init(const struct spa_handle_factory *factory,
SPA_VERSION_LOOP_UTILS,
&impl_loop_utils, impl);
for (i = 0; i < n_support; i++) {
switch (support[i].type) {
case SPA_TYPE_INTERFACE_Log:
impl->log = support[i].data;
break;
case SPA_TYPE_INTERFACE_System:
impl->system = support[i].data;
break;
}
}
impl->log = spa_support_find(support, n_support, SPA_TYPE_INTERFACE_Log);
impl->system = spa_support_find(support, n_support, SPA_TYPE_INTERFACE_System);
if (impl->system == NULL) {
spa_log_error(impl->log, NAME " %p: a System is needed", impl);
res = -EINVAL;

View file

@ -278,7 +278,7 @@ static const struct spa_system_methods impl_system = {
.signalfd_read = impl_signalfd_read,
};
static int impl_get_interface(struct spa_handle *handle, uint32_t type, void **interface)
static int impl_get_interface(struct spa_handle *handle, const char *type, void **interface)
{
struct impl *impl;
@ -287,13 +287,11 @@ static int impl_get_interface(struct spa_handle *handle, uint32_t type, void **i
impl = (struct impl *) handle;
switch (type) {
case SPA_TYPE_INTERFACE_System:
if (strcmp(type, SPA_TYPE_INTERFACE_System) == 0)
*interface = &impl->system;
break;
default:
else
return -ENOENT;
}
return 0;
}
@ -318,7 +316,6 @@ impl_init(const struct spa_handle_factory *factory,
uint32_t n_support)
{
struct impl *impl;
uint32_t i;
spa_return_val_if_fail(factory != NULL, -EINVAL);
spa_return_val_if_fail(handle != NULL, -EINVAL);
@ -332,13 +329,7 @@ impl_init(const struct spa_handle_factory *factory,
SPA_VERSION_SYSTEM,
&impl_system, impl);
for (i = 0; i < n_support; i++) {
switch (support[i].type) {
case SPA_TYPE_INTERFACE_Log:
impl->log = support[i].data;
break;
}
}
impl->log = spa_support_find(support, n_support, SPA_TYPE_INTERFACE_Log);
spa_log_debug(impl->log, NAME " %p: initialized", impl);