spa: don't use constructor attribute to register factories

This commit is contained in:
Wim Taymans 2019-02-06 11:38:12 +01:00
parent 30da60ab6b
commit a563050797
7 changed files with 40 additions and 85 deletions

View file

@ -2117,7 +2117,7 @@ impl_enum_interface_info(const struct spa_handle_factory *factory,
return 1; return 1;
} }
static const struct spa_handle_factory spa_bluez5_monitor_factory = { const struct spa_handle_factory spa_bluez5_monitor_factory = {
SPA_VERSION_MONITOR, SPA_VERSION_MONITOR,
NAME, NAME,
NULL, NULL,
@ -2125,11 +2125,3 @@ static const struct spa_handle_factory spa_bluez5_monitor_factory = {
impl_init, impl_init,
impl_enum_interface_info, impl_enum_interface_info,
}; };
int spa_handle_factory_register(const struct spa_handle_factory *factory);
static void reg(void) __attribute__ ((constructor));
static void reg(void)
{
spa_handle_factory_register(&spa_bluez5_monitor_factory);
}

View file

@ -27,21 +27,7 @@
#include <spa/support/plugin.h> #include <spa/support/plugin.h>
#define MAX_FACTORIES 16 extern const struct spa_handle_factory spa_bluez5_monitor_factory;
static const struct spa_handle_factory *factories[MAX_FACTORIES];
static uint32_t n_factories;
int spa_handle_factory_register(const struct spa_handle_factory *factory)
{
if (n_factories >= MAX_FACTORIES) {
fprintf(stderr, "too many factories\n");
return -ENOMEM;
}
factories[n_factories++] = factory;
return 0;
}
int 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)
@ -49,10 +35,13 @@ spa_handle_factory_enum(const struct spa_handle_factory **factory, uint32_t *ind
spa_return_val_if_fail(factory != NULL, -EINVAL); spa_return_val_if_fail(factory != NULL, -EINVAL);
spa_return_val_if_fail(index != NULL, -EINVAL); spa_return_val_if_fail(index != NULL, -EINVAL);
if (*index >= n_factories) switch (*index) {
case 0:
*factory = &spa_bluez5_monitor_factory;
break;
default:
return 0; return 0;
}
*factory = factories[(*index)++]; (*index)++;
return 1; return 1;
} }

View file

@ -192,7 +192,7 @@ impl_enum_interface_info(const struct spa_handle_factory *factory,
return 1; return 1;
} }
static const struct spa_handle_factory cpu_factory = { const struct spa_handle_factory spa_support_cpu_factory = {
SPA_VERSION_HANDLE_FACTORY, SPA_VERSION_HANDLE_FACTORY,
NAME, NAME,
NULL, NULL,
@ -200,11 +200,3 @@ static const struct spa_handle_factory cpu_factory = {
impl_init, impl_init,
impl_enum_interface_info, impl_enum_interface_info,
}; };
int spa_handle_factory_register(const struct spa_handle_factory *factory);
static void reg(void) __attribute__ ((constructor));
static void reg(void)
{
spa_handle_factory_register(&cpu_factory);
}

View file

@ -277,7 +277,7 @@ impl_enum_interface_info(const struct spa_handle_factory *factory,
return 1; return 1;
} }
static const struct spa_handle_factory logger_factory = { const struct spa_handle_factory spa_support_logger_factory = {
SPA_VERSION_HANDLE_FACTORY, SPA_VERSION_HANDLE_FACTORY,
NAME, NAME,
NULL, NULL,
@ -285,11 +285,3 @@ static const struct spa_handle_factory logger_factory = {
impl_init, impl_init,
impl_enum_interface_info, impl_enum_interface_info,
}; };
int spa_handle_factory_register(const struct spa_handle_factory *factory);
static void reg(void) __attribute__ ((constructor));
static void reg(void)
{
spa_handle_factory_register(&logger_factory);
}

View file

@ -775,7 +775,7 @@ impl_enum_interface_info(const struct spa_handle_factory *factory,
return 1; return 1;
} }
static const struct spa_handle_factory loop_factory = { const struct spa_handle_factory spa_support_loop_factory = {
SPA_VERSION_HANDLE_FACTORY, SPA_VERSION_HANDLE_FACTORY,
NAME, NAME,
NULL, NULL,
@ -783,11 +783,3 @@ static const struct spa_handle_factory loop_factory = {
impl_init, impl_init,
impl_enum_interface_info impl_enum_interface_info
}; };
int spa_handle_factory_register(const struct spa_handle_factory *factory);
static void reg(void) __attribute__ ((constructor));
static void reg(void)
{
spa_handle_factory_register(&loop_factory);
}

View file

@ -4,18 +4,18 @@ spa_support_sources = ['cpu.c',
'plugin.c'] 'plugin.c']
spa_support_lib = shared_library('spa-support', spa_support_lib = shared_library('spa-support',
spa_support_sources, spa_support_sources,
c_args : [ '-D_GNU_SOURCE' ], c_args : [ '-D_GNU_SOURCE' ],
include_directories : [ spa_inc], include_directories : [ spa_inc],
dependencies : threads_dep, dependencies : threads_dep,
install : true, install : true,
install_dir : '@0@/spa/support'.format(get_option('libdir'))) install_dir : '@0@/spa/support'.format(get_option('libdir')))
spa_dbus_sources = ['dbus.c'] spa_dbus_sources = ['dbus.c']
spa_dbus_lib = shared_library('spa-dbus', spa_dbus_lib = shared_library('spa-dbus',
spa_dbus_sources, spa_dbus_sources,
include_directories : [ spa_inc], include_directories : [ spa_inc],
dependencies : dbus_dep, dependencies : dbus_dep,
install : true, install : true,
install_dir : '@0@/spa/support'.format(get_option('libdir'))) install_dir : '@0@/spa/support'.format(get_option('libdir')))

View file

@ -27,31 +27,29 @@
#include <spa/support/plugin.h> #include <spa/support/plugin.h>
#define MAX_FACTORIES 16 extern const struct spa_handle_factory spa_support_logger_factory;
extern const struct spa_handle_factory spa_support_loop_factory;
extern const struct spa_handle_factory spa_support_cpu_factory;
static const struct spa_handle_factory *factories[MAX_FACTORIES]; SPA_EXPORT int
static uint32_t n_factories;
int spa_handle_factory_register(const struct spa_handle_factory *factory)
{
if (n_factories < MAX_FACTORIES)
factories[n_factories++] = factory;
else {
fprintf(stderr, "too many factories\n");
return -ENOMEM;
}
return 0;
}
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, -EINVAL); spa_return_val_if_fail(factory != NULL, -EINVAL);
spa_return_val_if_fail(index != NULL, -EINVAL); spa_return_val_if_fail(index != NULL, -EINVAL);
if (*index >= n_factories) switch (*index) {
case 0:
*factory = &spa_support_logger_factory;
break;
case 1:
*factory = &spa_support_loop_factory;
break;
case 2:
*factory = &spa_support_cpu_factory;
break;
default:
return 0; return 0;
}
*factory = factories[(*index)++]; (*index)++;
return 1; return 1;
} }