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

@ -33,6 +33,7 @@
#include <spa/support/log.h>
#include <spa/utils/type.h>
#include <spa/node/node.h>
#include <spa/utils/keys.h>
#include <spa/utils/names.h>
#include <spa/support/loop.h>
@ -124,6 +125,7 @@ static int emit_node(struct impl *this, snd_pcm_info_t *pcminfo, uint32_t id)
info = SPA_DEVICE_OBJECT_INFO_INIT();
info.type = SPA_TYPE_INTERFACE_Node;
if (snd_pcm_info_get_stream(pcminfo) == SND_PCM_STREAM_PLAYBACK) {
info.factory_name = SPA_NAME_API_ALSA_PCM_SINK;
stream = "playback";
@ -433,7 +435,7 @@ static const struct spa_device_methods impl_device = {
.set_param = impl_set_param,
};
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;
@ -442,7 +444,7 @@ static int impl_get_interface(struct spa_handle *handle, uint32_t type, void **i
this = (struct impl *) handle;
if (type == SPA_TYPE_INTERFACE_Device)
if (strcmp(type, SPA_TYPE_INTERFACE_Device) == 0)
*interface = &this->device;
else
return -ENOENT;
@ -471,7 +473,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);
@ -481,13 +482,7 @@ impl_init(const struct spa_handle_factory *factory,
this = (struct impl *) handle;
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->device.iface = SPA_INTERFACE_INIT(
SPA_TYPE_INTERFACE_Device,

View file

@ -652,7 +652,7 @@ static const struct spa_node_methods impl_node = {
.process = impl_node_process,
};
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 state *this;
@ -661,7 +661,7 @@ static int impl_get_interface(struct spa_handle *handle, uint32_t type, void **i
this = (struct state *) handle;
if (type == SPA_TYPE_INTERFACE_Node)
if (strcmp(type, SPA_TYPE_INTERFACE_Node) == 0)
*interface = &this->node;
else
return -ENOENT;
@ -695,19 +695,11 @@ impl_init(const struct spa_handle_factory *factory,
handle->clear = impl_clear;
this = (struct state *) handle;
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_DataSystem:
this->data_system = support[i].data;
break;
case SPA_TYPE_INTERFACE_DataLoop:
this->data_loop = support[i].data;
break;
}
}
this->log = spa_support_find(support, n_support, SPA_TYPE_INTERFACE_Log);
this->data_system = spa_support_find(support, n_support, SPA_TYPE_INTERFACE_DataSystem);
this->data_loop = spa_support_find(support, n_support, SPA_TYPE_INTERFACE_DataLoop);
if (this->data_loop == NULL) {
spa_log_error(this->log, "a data loop is needed");
return -EINVAL;

View file

@ -683,7 +683,7 @@ static const struct spa_node_methods impl_node = {
.process = impl_node_process,
};
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 state *this;
@ -692,7 +692,7 @@ static int impl_get_interface(struct spa_handle *handle, uint32_t type, void **i
this = (struct state *) handle;
if (type == SPA_TYPE_INTERFACE_Node)
if (strcmp(type, SPA_TYPE_INTERFACE_Node) == 0)
*interface = &this->node;
else
return -ENOENT;
@ -730,19 +730,10 @@ impl_init(const struct spa_handle_factory *factory,
this = (struct state *) handle;
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_DataSystem:
this->data_system = support[i].data;
break;
case SPA_TYPE_INTERFACE_DataLoop:
this->data_loop = support[i].data;
break;
}
}
this->log = spa_support_find(support, n_support, SPA_TYPE_INTERFACE_Log);
this->data_system = spa_support_find(support, n_support, SPA_TYPE_INTERFACE_DataSystem);
this->data_loop = spa_support_find(support, n_support, SPA_TYPE_INTERFACE_DataLoop);
if (this->data_loop == NULL) {
spa_log_error(this->log, NAME" %p: a data loop is needed", this);
return -EINVAL;

View file

@ -796,7 +796,7 @@ static const struct spa_node_methods impl_node = {
.process = impl_node_process,
};
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 seq_state *this;
@ -805,7 +805,7 @@ static int impl_get_interface(struct spa_handle *handle, uint32_t type, void **i
this = (struct seq_state *) handle;
if (type == SPA_TYPE_INTERFACE_Node)
if (strcmp(type, SPA_TYPE_INTERFACE_Node) == 0)
*interface = &this->node;
else
return -ENOENT;
@ -851,22 +851,11 @@ impl_init(const struct spa_handle_factory *factory,
this = (struct seq_state *) handle;
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_DataSystem:
this->data_system = support[i].data;
break;
case SPA_TYPE_INTERFACE_DataLoop:
this->data_loop = support[i].data;
break;
case SPA_TYPE_INTERFACE_Loop:
this->main_loop = support[i].data;
break;
}
}
this->log = spa_support_find(support, n_support, SPA_TYPE_INTERFACE_Log);
this->data_system = spa_support_find(support, n_support, SPA_TYPE_INTERFACE_DataSystem);
this->data_loop = spa_support_find(support, n_support, SPA_TYPE_INTERFACE_DataLoop);
this->main_loop = spa_support_find(support, n_support, SPA_TYPE_INTERFACE_Loop);
if (this->data_loop == NULL) {
spa_log_error(this->log, "a data loop is needed");
return -EINVAL;

View file

@ -541,7 +541,7 @@ static const struct spa_device_methods impl_device = {
.add_listener = impl_device_add_listener,
};
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;
@ -550,13 +550,11 @@ static int impl_get_interface(struct spa_handle *handle, uint32_t type, void **i
this = (struct impl *) handle;
switch (type) {
case SPA_TYPE_INTERFACE_Device:
if (strcmp(type, SPA_TYPE_INTERFACE_Device) == 0)
*interface = &this->device;
break;
default:
else
return -ENOENT;
}
return 0;
}
@ -583,7 +581,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);
@ -593,18 +590,9 @@ impl_init(const struct spa_handle_factory *factory,
this = (struct impl *) handle;
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_Loop:
this->main_loop = support[i].data;
break;
default:
break;
}
}
this->log = spa_support_find(support, n_support, SPA_TYPE_INTERFACE_Log);
this->main_loop = spa_support_find(support, n_support, SPA_TYPE_INTERFACE_Loop);
if (this->main_loop == NULL) {
spa_log_error(this->log, "a main-loop is needed");
return -EINVAL;