mirror of
https://gitlab.freedesktop.org/pulseaudio/pulseaudio.git
synced 2025-11-20 06:59:53 -05:00
module-gsettings: new module to store configuration using gsettings
GConf is deprecated, and distributions are removing it. paprefs depends on GConf, so in order to avoid paprefs getting removed as well, paprefs has to be changed to use something else than GConf. GSettings is the easiest alternative to migrate to, although it has the same problems that GConf had: no support for system mode or networking. This patch takes the non-GConf specific code from module-gconf and puts it in stdin-util.[ch], which is then reused by module-gsettings. module-gsettings is designed to be very similar to module-gconf. Migration is expected to happen as follows: Distributions update PulseAudio and paprefs at the same time, or first PulseAudio and then paprefs. paprefs depends on module-gsettings, and module-gsettings conflicts with module-gconf. Therefore module-gconf gets automatically removed during the paprefs update. After the update an old PulseAudio is likely to be running with module-gconf loaded. If the user tries to use paprefs during this period, whatever the user does in paprefs won't have any effect until PulseAudio is restarted (probably by a reboot or relogin). This is not ideal, but will have to do. When module-gsettings is loaded, it runs gsettings-data-convert (implemented in a later patch). That will copy the settings from GConf to GSettings. If gsettings-data-convert is not available (it's part of GConf, so it may have already been uninstalled), then any previous paprefs settings are lost.
This commit is contained in:
parent
ba2b748d40
commit
785b660d8a
8 changed files with 747 additions and 291 deletions
|
|
@ -17,25 +17,13 @@
|
|||
along with PulseAudio; if not, see <http://www.gnu.org/licenses/>.
|
||||
***/
|
||||
|
||||
#ifdef HAVE_CONFIG_H
|
||||
#include <config.h>
|
||||
#endif
|
||||
#include "../stdin-util.h"
|
||||
|
||||
#include <string.h>
|
||||
#include <unistd.h>
|
||||
#include <stdlib.h>
|
||||
#include <errno.h>
|
||||
#include <signal.h>
|
||||
#include <sys/types.h>
|
||||
#include <sys/wait.h>
|
||||
|
||||
#include <pulse/xmalloc.h>
|
||||
#include <pulsecore/module.h>
|
||||
#include <pulsecore/core.h>
|
||||
#include <pulsecore/core-util.h>
|
||||
#include <pulsecore/log.h>
|
||||
#include <pulse/mainloop-api.h>
|
||||
#include <pulsecore/core-error.h>
|
||||
#include <pulsecore/core-util.h>
|
||||
#include <pulsecore/start-child.h>
|
||||
|
||||
PA_MODULE_AUTHOR("Lennart Poettering");
|
||||
|
|
@ -43,282 +31,6 @@ PA_MODULE_DESCRIPTION("GConf Adapter");
|
|||
PA_MODULE_VERSION(PACKAGE_VERSION);
|
||||
PA_MODULE_LOAD_ONCE(true);
|
||||
|
||||
#define MAX_MODULES 10
|
||||
#define BUF_MAX 2048
|
||||
|
||||
struct userdata;
|
||||
|
||||
struct module_item {
|
||||
char *name;
|
||||
char *args;
|
||||
uint32_t index;
|
||||
};
|
||||
|
||||
struct pa_module_info {
|
||||
struct userdata *userdata;
|
||||
char *name;
|
||||
|
||||
struct module_item items[MAX_MODULES];
|
||||
unsigned n_items;
|
||||
};
|
||||
|
||||
struct userdata {
|
||||
pa_core *core;
|
||||
pa_module *module;
|
||||
|
||||
pa_hashmap *module_infos;
|
||||
|
||||
pid_t pid;
|
||||
|
||||
int fd;
|
||||
int fd_type;
|
||||
pa_io_event *io_event;
|
||||
|
||||
char buf[BUF_MAX];
|
||||
size_t buf_fill;
|
||||
};
|
||||
|
||||
static int fill_buf(struct userdata *u) {
|
||||
ssize_t r;
|
||||
pa_assert(u);
|
||||
|
||||
if (u->buf_fill >= BUF_MAX) {
|
||||
pa_log("read buffer overflow");
|
||||
return -1;
|
||||
}
|
||||
|
||||
if ((r = pa_read(u->fd, u->buf + u->buf_fill, BUF_MAX - u->buf_fill, &u->fd_type)) <= 0)
|
||||
return -1;
|
||||
|
||||
u->buf_fill += (size_t) r;
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int read_byte(struct userdata *u) {
|
||||
int ret;
|
||||
pa_assert(u);
|
||||
|
||||
if (u->buf_fill < 1)
|
||||
if (fill_buf(u) < 0)
|
||||
return -1;
|
||||
|
||||
ret = u->buf[0];
|
||||
pa_assert(u->buf_fill > 0);
|
||||
u->buf_fill--;
|
||||
memmove(u->buf, u->buf+1, u->buf_fill);
|
||||
return ret;
|
||||
}
|
||||
|
||||
static char *read_string(struct userdata *u) {
|
||||
pa_assert(u);
|
||||
|
||||
for (;;) {
|
||||
char *e;
|
||||
|
||||
if ((e = memchr(u->buf, 0, u->buf_fill))) {
|
||||
char *ret = pa_xstrdup(u->buf);
|
||||
u->buf_fill -= (size_t) (e - u->buf +1);
|
||||
memmove(u->buf, e+1, u->buf_fill);
|
||||
return ret;
|
||||
}
|
||||
|
||||
if (fill_buf(u) < 0)
|
||||
return NULL;
|
||||
}
|
||||
}
|
||||
|
||||
static void unload_one_module(struct pa_module_info *m, unsigned i) {
|
||||
struct userdata *u;
|
||||
|
||||
pa_assert(m);
|
||||
pa_assert(i < m->n_items);
|
||||
|
||||
u = m->userdata;
|
||||
|
||||
if (m->items[i].index == PA_INVALID_INDEX)
|
||||
return;
|
||||
|
||||
pa_log_debug("Unloading module #%i", m->items[i].index);
|
||||
pa_module_unload_by_index(u->core, m->items[i].index, true);
|
||||
m->items[i].index = PA_INVALID_INDEX;
|
||||
pa_xfree(m->items[i].name);
|
||||
pa_xfree(m->items[i].args);
|
||||
m->items[i].name = m->items[i].args = NULL;
|
||||
}
|
||||
|
||||
static void unload_all_modules(struct pa_module_info *m) {
|
||||
unsigned i;
|
||||
|
||||
pa_assert(m);
|
||||
|
||||
for (i = 0; i < m->n_items; i++)
|
||||
unload_one_module(m, i);
|
||||
|
||||
m->n_items = 0;
|
||||
}
|
||||
|
||||
static void load_module(
|
||||
struct pa_module_info *m,
|
||||
unsigned i,
|
||||
const char *name,
|
||||
const char *args,
|
||||
bool is_new) {
|
||||
|
||||
struct userdata *u;
|
||||
pa_module *mod;
|
||||
|
||||
pa_assert(m);
|
||||
pa_assert(name);
|
||||
pa_assert(args);
|
||||
|
||||
u = m->userdata;
|
||||
|
||||
if (!is_new) {
|
||||
if (m->items[i].index != PA_INVALID_INDEX &&
|
||||
pa_streq(m->items[i].name, name) &&
|
||||
pa_streq(m->items[i].args, args))
|
||||
return;
|
||||
|
||||
unload_one_module(m, i);
|
||||
}
|
||||
|
||||
pa_log_debug("Loading module '%s' with args '%s' due to GConf configuration.", name, args);
|
||||
|
||||
m->items[i].name = pa_xstrdup(name);
|
||||
m->items[i].args = pa_xstrdup(args);
|
||||
m->items[i].index = PA_INVALID_INDEX;
|
||||
|
||||
if (pa_module_load(&mod, u->core, name, args) < 0) {
|
||||
pa_log("pa_module_load() failed");
|
||||
return;
|
||||
}
|
||||
|
||||
m->items[i].index = mod->index;
|
||||
}
|
||||
|
||||
static void module_info_free(void *p) {
|
||||
struct pa_module_info *m = p;
|
||||
|
||||
pa_assert(m);
|
||||
|
||||
unload_all_modules(m);
|
||||
pa_xfree(m->name);
|
||||
pa_xfree(m);
|
||||
}
|
||||
|
||||
static int handle_event(struct userdata *u) {
|
||||
int opcode;
|
||||
int ret = 0;
|
||||
|
||||
do {
|
||||
if ((opcode = read_byte(u)) < 0) {
|
||||
if (errno == EINTR || errno == EAGAIN)
|
||||
break;
|
||||
goto fail;
|
||||
}
|
||||
|
||||
switch (opcode) {
|
||||
case '!':
|
||||
/* The helper tool is now initialized */
|
||||
ret = 1;
|
||||
break;
|
||||
|
||||
case '+': {
|
||||
char *name;
|
||||
struct pa_module_info *m;
|
||||
unsigned i, j;
|
||||
|
||||
if (!(name = read_string(u)))
|
||||
goto fail;
|
||||
|
||||
if (!(m = pa_hashmap_get(u->module_infos, name))) {
|
||||
m = pa_xnew(struct pa_module_info, 1);
|
||||
m->userdata = u;
|
||||
m->name = name;
|
||||
m->n_items = 0;
|
||||
pa_hashmap_put(u->module_infos, m->name, m);
|
||||
} else
|
||||
pa_xfree(name);
|
||||
|
||||
i = 0;
|
||||
while (i < MAX_MODULES) {
|
||||
char *module, *args;
|
||||
|
||||
if (!(module = read_string(u))) {
|
||||
if (i > m->n_items) m->n_items = i;
|
||||
goto fail;
|
||||
}
|
||||
|
||||
if (!*module) {
|
||||
pa_xfree(module);
|
||||
break;
|
||||
}
|
||||
|
||||
if (!(args = read_string(u))) {
|
||||
pa_xfree(module);
|
||||
|
||||
if (i > m->n_items) m->n_items = i;
|
||||
goto fail;
|
||||
}
|
||||
|
||||
load_module(m, i, module, args, i >= m->n_items);
|
||||
|
||||
i++;
|
||||
|
||||
pa_xfree(module);
|
||||
pa_xfree(args);
|
||||
}
|
||||
|
||||
/* Unload all removed modules */
|
||||
for (j = i; j < m->n_items; j++)
|
||||
unload_one_module(m, j);
|
||||
|
||||
m->n_items = i;
|
||||
|
||||
break;
|
||||
}
|
||||
|
||||
case '-': {
|
||||
char *name;
|
||||
|
||||
if (!(name = read_string(u)))
|
||||
goto fail;
|
||||
|
||||
pa_hashmap_remove_and_free(u->module_infos, name);
|
||||
pa_xfree(name);
|
||||
|
||||
break;
|
||||
}
|
||||
}
|
||||
} while (u->buf_fill > 0 && ret == 0);
|
||||
|
||||
return ret;
|
||||
|
||||
fail:
|
||||
pa_log("Unable to read or parse data from client.");
|
||||
return -1;
|
||||
}
|
||||
|
||||
static void io_event_cb(
|
||||
pa_mainloop_api*a,
|
||||
pa_io_event* e,
|
||||
int fd,
|
||||
pa_io_event_flags_t events,
|
||||
void *userdata) {
|
||||
|
||||
struct userdata *u = userdata;
|
||||
|
||||
if (handle_event(u) < 0) {
|
||||
|
||||
if (u->io_event) {
|
||||
u->core->mainloop->io_free(u->io_event);
|
||||
u->io_event = NULL;
|
||||
}
|
||||
|
||||
pa_module_unload_request(u->module, true);
|
||||
}
|
||||
}
|
||||
|
||||
int pa__init(pa_module*m) {
|
||||
struct userdata *u;
|
||||
int r;
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue