Add dbus support interface

Add an interface that can manager a dbus connection.
Make a dbus interface in the core that can create connections running
in the core main loop. Keep this as support for spa plugins.
This commit is contained in:
Wim Taymans 2017-12-18 12:41:47 +01:00
parent 4d6ac37398
commit f7b6fea43d
7 changed files with 612 additions and 37 deletions

View file

@ -24,6 +24,7 @@
#define spa_debug pw_log_trace
#include <spa/lib/debug.h>
#include <spa/support/dbus.h>
#include <pipewire/pipewire.h>
#include <pipewire/private.h>
@ -407,6 +408,8 @@ struct pw_core *pw_core_new(struct pw_loop *main_loop, struct pw_properties *pro
if (this == NULL)
return NULL;
pw_log_debug("core %p: new", this);
if (properties == NULL)
properties = pw_properties_new(NULL, NULL);
if (properties == NULL)
@ -432,8 +435,12 @@ struct pw_core *pw_core_new(struct pw_loop *main_loop, struct pw_properties *pro
this->support[0] = SPA_SUPPORT_INIT(SPA_TYPE__TypeMap, this->type.map);
this->support[1] = SPA_SUPPORT_INIT(SPA_TYPE_LOOP__DataLoop, this->data_loop->loop);
this->support[2] = SPA_SUPPORT_INIT(SPA_TYPE_LOOP__MainLoop, this->main_loop->loop);
this->support[3] = SPA_SUPPORT_INIT(SPA_TYPE__Log, pw_log_get());
this->n_support = 4;
this->support[3] = SPA_SUPPORT_INIT(SPA_TYPE__LoopUtils, this->main_loop->utils);
this->support[4] = SPA_SUPPORT_INIT(SPA_TYPE__Log, pw_log_get());
this->support[5] = SPA_SUPPORT_INIT(SPA_TYPE__DBus, pw_get_spa_dbus(this->main_loop));
this->n_support = 6;
pw_log_debug("%p", this->support[5].data);
pw_data_loop_start(this->data_loop_impl);

View file

@ -29,6 +29,8 @@
#include <errno.h>
#include <dlfcn.h>
#include <spa/support/dbus.h>
#include "pipewire/pipewire.h"
#include "pipewire/private.h"
@ -37,7 +39,7 @@ static char **categories = NULL;
static struct support_info {
void *hnd;
spa_handle_factory_enum_func_t enum_func;
struct spa_support support[4];
struct spa_support support[16];
uint32_t n_support;
} support_info;
@ -71,6 +73,24 @@ open_support(const char *path,
return false;
}
static const struct spa_handle_factory *get_factory(struct support_info *info, const char *factory_name)
{
int res;
uint32_t index;
const struct spa_handle_factory *factory;
for (index = 0;;) {
if ((res = info->enum_func(&factory, &index)) <= 0) {
if (res != 0)
fprintf(stderr, "can't enumerate factories: %s\n", spa_strerror(res));
break;
}
if (strcmp(factory->name, factory_name) == 0)
return factory;
}
return NULL;
}
static void *
load_interface(struct support_info *info,
const char *factory_name,
@ -83,7 +103,7 @@ load_interface(struct support_info *info,
void *iface;
struct spa_type_map *map = NULL;
factory = pw_get_support_factory(factory_name);
factory = get_factory(info, factory_name);
if (factory == NULL)
goto not_found;
@ -101,6 +121,8 @@ load_interface(struct support_info *info,
fprintf(stderr, "can't get %s interface %d\n", type, res);
goto interface_failed;
}
fprintf(stderr, "loaded interface %s from %s\n", type, factory_name);
return iface;
interface_failed:
@ -124,22 +146,6 @@ static void configure_debug(const char *str)
categories = pw_split_strv(level[1], ",", INT_MAX, &n_tokens);
}
static void configure_support(struct support_info *info)
{
void *iface;
iface = load_interface(info, "mapper", SPA_TYPE__TypeMap);
if (iface != NULL) {
info->support[info->n_support++] = SPA_SUPPORT_INIT(SPA_TYPE__TypeMap, iface);
}
iface = load_interface(info, "logger", SPA_TYPE__Log);
if (iface != NULL) {
info->support[info->n_support++] = SPA_SUPPORT_INIT(SPA_TYPE__Log, iface);
pw_log_set(iface);
}
}
/** Get a support interface
* \param type the interface type
* \return the interface or NULL when not configured
@ -157,20 +163,7 @@ void *pw_get_support_interface(const char *type)
const struct spa_handle_factory *pw_get_support_factory(const char *factory_name)
{
int res;
uint32_t index;
const struct spa_handle_factory *factory;
for (index = 0;;) {
if ((res = support_info.enum_func(&factory, &index)) <= 0) {
if (res != 0)
fprintf(stderr, "can't enumerate factories: %s\n", spa_strerror(res));
break;
}
if (strcmp(factory->name, factory_name) == 0)
return factory;
}
return NULL;
return get_factory(&support_info, factory_name);
}
const struct spa_support *pw_get_support(uint32_t *n_support)
@ -179,6 +172,27 @@ const struct spa_support *pw_get_support(uint32_t *n_support)
return support_info.support;
}
void *pw_get_spa_dbus(struct pw_loop *loop)
{
struct support_info dbus_support_info;
const char *str;
dbus_support_info.n_support = support_info.n_support;
memcpy(dbus_support_info.support, support_info.support,
sizeof(struct spa_support) * dbus_support_info.n_support);
dbus_support_info.support[dbus_support_info.n_support++] =
SPA_SUPPORT_INIT(SPA_TYPE__LoopUtils, loop->utils);
if ((str = getenv("SPA_PLUGIN_DIR")) == NULL)
str = PLUGINDIR;
if (open_support(str, "support/libspa-dbus", &dbus_support_info))
return load_interface(&dbus_support_info, "dbus", SPA_TYPE__DBus);
return NULL;
}
/** Initialize PipeWire
*
* \param argc pointer to argc
@ -194,6 +208,8 @@ const struct spa_support *pw_get_support(uint32_t *n_support)
void pw_init(int *argc, char **argv[])
{
const char *str;
void *iface;
struct support_info *info = &support_info;
if ((str = getenv("PIPEWIRE_DEBUG")))
configure_debug(str);
@ -204,8 +220,17 @@ void pw_init(int *argc, char **argv[])
if (support_info.n_support > 0)
return;
if (open_support(str, "support/libspa-support", &support_info))
configure_support(&support_info);
if (open_support(str, "support/libspa-support", info)) {
iface = load_interface(info, "mapper", SPA_TYPE__TypeMap);
if (iface != NULL)
info->support[info->n_support++] = SPA_SUPPORT_INIT(SPA_TYPE__TypeMap, iface);
iface = load_interface(info, "logger", SPA_TYPE__Log);
if (iface != NULL) {
info->support[info->n_support++] = SPA_SUPPORT_INIT(SPA_TYPE__Log, iface);
pw_log_set(iface);
}
}
}
/** Check if a debug category is enabled

View file

@ -132,6 +132,8 @@ pw_direction_reverse(enum pw_direction direction);
void *
pw_get_support_interface(const char *type);
void *pw_get_spa_dbus(struct pw_loop *loop);
const struct spa_handle_factory *
pw_get_support_factory(const char *factory_name);

View file

@ -148,7 +148,7 @@ struct pw_core {
struct pw_loop *data_loop; /**< data loop for data passing */
struct pw_data_loop *data_loop_impl;
struct spa_support support[4]; /**< support for spa plugins */
struct spa_support support[16]; /**< support for spa plugins */
uint32_t n_support; /**< number of support items */
long sc_pagesize;