mirror of
https://gitlab.freedesktop.org/pulseaudio/pulseaudio.git
synced 2025-11-04 13:29:59 -05:00
Add the forgotten src/modules/dbus directory to git.
This commit is contained in:
parent
9347e90fed
commit
9a77d2f81d
15 changed files with 3274 additions and 0 deletions
61
src/modules/dbus/iface-card.c
Normal file
61
src/modules/dbus/iface-card.c
Normal file
|
|
@ -0,0 +1,61 @@
|
|||
/***
|
||||
This file is part of PulseAudio.
|
||||
|
||||
Copyright 2009 Tanu Kaskinen
|
||||
|
||||
PulseAudio is free software; you can redistribute it and/or modify
|
||||
it under the terms of the GNU Lesser General Public License as published
|
||||
by the Free Software Foundation; either version 2.1 of the License,
|
||||
or (at your option) any later version.
|
||||
|
||||
PulseAudio is distributed in the hope that it will be useful, but
|
||||
WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU Lesser General Public License
|
||||
along with PulseAudio; if not, write to the Free Software
|
||||
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
|
||||
USA.
|
||||
***/
|
||||
|
||||
#ifdef HAVE_CONFIG_H
|
||||
#include <config.h>
|
||||
#endif
|
||||
|
||||
#include <pulsecore/core-util.h>
|
||||
|
||||
#include "iface-card.h"
|
||||
|
||||
#define OBJECT_NAME "card"
|
||||
|
||||
struct pa_dbusiface_card {
|
||||
pa_card *card;
|
||||
char *path;
|
||||
};
|
||||
|
||||
pa_dbusiface_card *pa_dbusiface_card_new(pa_card *card, const char *path_prefix) {
|
||||
pa_dbusiface_card *c;
|
||||
|
||||
pa_assert(card);
|
||||
pa_assert(path_prefix);
|
||||
|
||||
c = pa_xnew(pa_dbusiface_card, 1);
|
||||
c->card = card;
|
||||
c->path = pa_sprintf_malloc("%s/%s%u", path_prefix, OBJECT_NAME, card->index);
|
||||
|
||||
return c;
|
||||
}
|
||||
|
||||
void pa_dbusiface_card_free(pa_dbusiface_card *c) {
|
||||
pa_assert(c);
|
||||
|
||||
pa_xfree(c->path);
|
||||
pa_xfree(c);
|
||||
}
|
||||
|
||||
const char *pa_dbusiface_card_get_path(pa_dbusiface_card *c) {
|
||||
pa_assert(c);
|
||||
|
||||
return c->path;
|
||||
}
|
||||
40
src/modules/dbus/iface-card.h
Normal file
40
src/modules/dbus/iface-card.h
Normal file
|
|
@ -0,0 +1,40 @@
|
|||
#ifndef foodbusifacecardhfoo
|
||||
#define foodbusifacecardhfoo
|
||||
|
||||
/***
|
||||
This file is part of PulseAudio.
|
||||
|
||||
Copyright 2009 Tanu Kaskinen
|
||||
|
||||
PulseAudio is free software; you can redistribute it and/or modify
|
||||
it under the terms of the GNU Lesser General Public License as published
|
||||
by the Free Software Foundation; either version 2.1 of the License,
|
||||
or (at your option) any later version.
|
||||
|
||||
PulseAudio is distributed in the hope that it will be useful, but
|
||||
WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU Lesser General Public License
|
||||
along with PulseAudio; if not, write to the Free Software
|
||||
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
|
||||
USA.
|
||||
***/
|
||||
|
||||
/* This object implements the D-Bus interface org.PulseAudio.Core1.Card.
|
||||
*
|
||||
* See http://pulseaudio.org/wiki/DBusInterface for the Card interface
|
||||
* documentation.
|
||||
*/
|
||||
|
||||
#include <pulsecore/card.h>
|
||||
|
||||
typedef struct pa_dbusiface_card pa_dbusiface_card;
|
||||
|
||||
pa_dbusiface_card *pa_dbusiface_card_new(pa_card *card, const char *path_prefix);
|
||||
void pa_dbusiface_card_free(pa_dbusiface_card *c);
|
||||
|
||||
const char *pa_dbusiface_card_get_path(pa_dbusiface_card *c);
|
||||
|
||||
#endif
|
||||
61
src/modules/dbus/iface-client.c
Normal file
61
src/modules/dbus/iface-client.c
Normal file
|
|
@ -0,0 +1,61 @@
|
|||
/***
|
||||
This file is part of PulseAudio.
|
||||
|
||||
Copyright 2009 Tanu Kaskinen
|
||||
|
||||
PulseAudio is free software; you can redistribute it and/or modify
|
||||
it under the terms of the GNU Lesser General Public License as published
|
||||
by the Free Software Foundation; either version 2.1 of the License,
|
||||
or (at your option) any later version.
|
||||
|
||||
PulseAudio is distributed in the hope that it will be useful, but
|
||||
WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU Lesser General Public License
|
||||
along with PulseAudio; if not, write to the Free Software
|
||||
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
|
||||
USA.
|
||||
***/
|
||||
|
||||
#ifdef HAVE_CONFIG_H
|
||||
#include <config.h>
|
||||
#endif
|
||||
|
||||
#include <pulsecore/core-util.h>
|
||||
|
||||
#include "iface-client.h"
|
||||
|
||||
#define OBJECT_NAME "client"
|
||||
|
||||
struct pa_dbusiface_client {
|
||||
pa_client *client;
|
||||
char *path;
|
||||
};
|
||||
|
||||
pa_dbusiface_client *pa_dbusiface_client_new(pa_client *client, const char *path_prefix) {
|
||||
pa_dbusiface_client *c;
|
||||
|
||||
pa_assert(client);
|
||||
pa_assert(path_prefix);
|
||||
|
||||
c = pa_xnew(pa_dbusiface_client, 1);
|
||||
c->client = client;
|
||||
c->path = pa_sprintf_malloc("%s/%s%u", path_prefix, OBJECT_NAME, client->index);
|
||||
|
||||
return c;
|
||||
}
|
||||
|
||||
void pa_dbusiface_client_free(pa_dbusiface_client *c) {
|
||||
pa_assert(c);
|
||||
|
||||
pa_xfree(c->path);
|
||||
pa_xfree(c);
|
||||
}
|
||||
|
||||
const char *pa_dbusiface_client_get_path(pa_dbusiface_client *c) {
|
||||
pa_assert(c);
|
||||
|
||||
return c->path;
|
||||
}
|
||||
40
src/modules/dbus/iface-client.h
Normal file
40
src/modules/dbus/iface-client.h
Normal file
|
|
@ -0,0 +1,40 @@
|
|||
#ifndef foodbusifaceclienthfoo
|
||||
#define foodbusifaceclienthfoo
|
||||
|
||||
/***
|
||||
This file is part of PulseAudio.
|
||||
|
||||
Copyright 2009 Tanu Kaskinen
|
||||
|
||||
PulseAudio is free software; you can redistribute it and/or modify
|
||||
it under the terms of the GNU Lesser General Public License as published
|
||||
by the Free Software Foundation; either version 2.1 of the License,
|
||||
or (at your option) any later version.
|
||||
|
||||
PulseAudio is distributed in the hope that it will be useful, but
|
||||
WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU Lesser General Public License
|
||||
along with PulseAudio; if not, write to the Free Software
|
||||
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
|
||||
USA.
|
||||
***/
|
||||
|
||||
/* This object implements the D-Bus interface org.PulseAudio.Core1.Card.
|
||||
*
|
||||
* See http://pulseaudio.org/wiki/DBusInterface for the Card interface
|
||||
* documentation.
|
||||
*/
|
||||
|
||||
#include <pulsecore/client.h>
|
||||
|
||||
typedef struct pa_dbusiface_client pa_dbusiface_client;
|
||||
|
||||
pa_dbusiface_client *pa_dbusiface_client_new(pa_client *client, const char *path_prefix);
|
||||
void pa_dbusiface_client_free(pa_dbusiface_client *c);
|
||||
|
||||
const char *pa_dbusiface_client_get_path(pa_dbusiface_client *c);
|
||||
|
||||
#endif
|
||||
1968
src/modules/dbus/iface-core.c
Normal file
1968
src/modules/dbus/iface-core.c
Normal file
File diff suppressed because it is too large
Load diff
38
src/modules/dbus/iface-core.h
Normal file
38
src/modules/dbus/iface-core.h
Normal file
|
|
@ -0,0 +1,38 @@
|
|||
#ifndef foodbusifacecorehfoo
|
||||
#define foodbusifacecorehfoo
|
||||
|
||||
/***
|
||||
This file is part of PulseAudio.
|
||||
|
||||
Copyright 2009 Tanu Kaskinen
|
||||
|
||||
PulseAudio is free software; you can redistribute it and/or modify
|
||||
it under the terms of the GNU Lesser General Public License as published
|
||||
by the Free Software Foundation; either version 2.1 of the License,
|
||||
or (at your option) any later version.
|
||||
|
||||
PulseAudio is distributed in the hope that it will be useful, but
|
||||
WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU Lesser General Public License
|
||||
along with PulseAudio; if not, write to the Free Software
|
||||
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
|
||||
USA.
|
||||
***/
|
||||
|
||||
/* This object implements the D-Bus interface org.PulseAudio.Core1.
|
||||
*
|
||||
* See http://pulseaudio.org/wiki/DBusInterface for the Core interface
|
||||
* documentation.
|
||||
*/
|
||||
|
||||
#include <pulsecore/core.h>
|
||||
|
||||
typedef struct pa_dbusiface_core pa_dbusiface_core;
|
||||
|
||||
pa_dbusiface_core *pa_dbusiface_core_new(pa_core *core);
|
||||
void pa_dbusiface_core_free(pa_dbusiface_core *c);
|
||||
|
||||
#endif
|
||||
105
src/modules/dbus/iface-device.c
Normal file
105
src/modules/dbus/iface-device.c
Normal file
|
|
@ -0,0 +1,105 @@
|
|||
/***
|
||||
This file is part of PulseAudio.
|
||||
|
||||
Copyright 2009 Tanu Kaskinen
|
||||
|
||||
PulseAudio is free software; you can redistribute it and/or modify
|
||||
it under the terms of the GNU Lesser General Public License as published
|
||||
by the Free Software Foundation; either version 2.1 of the License,
|
||||
or (at your option) any later version.
|
||||
|
||||
PulseAudio is distributed in the hope that it will be useful, but
|
||||
WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU Lesser General Public License
|
||||
along with PulseAudio; if not, write to the Free Software
|
||||
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
|
||||
USA.
|
||||
***/
|
||||
|
||||
#ifdef HAVE_CONFIG_H
|
||||
#include <config.h>
|
||||
#endif
|
||||
|
||||
#include <pulsecore/core-util.h>
|
||||
|
||||
#include "iface-device.h"
|
||||
|
||||
#define SINK_OBJECT_NAME "sink"
|
||||
#define SOURCE_OBJECT_NAME "source"
|
||||
|
||||
enum device_type {
|
||||
DEVICE_TYPE_SINK,
|
||||
DEVICE_TYPE_SOURCE
|
||||
};
|
||||
|
||||
struct pa_dbusiface_device {
|
||||
union {
|
||||
pa_sink *sink;
|
||||
pa_source *source;
|
||||
};
|
||||
enum device_type type;
|
||||
char *path;
|
||||
};
|
||||
|
||||
pa_dbusiface_device *pa_dbusiface_device_new_sink(pa_sink *sink, const char *path_prefix) {
|
||||
pa_dbusiface_device *d;
|
||||
|
||||
pa_assert(sink);
|
||||
pa_assert(path_prefix);
|
||||
|
||||
d = pa_xnew(pa_dbusiface_device, 1);
|
||||
d->sink = pa_sink_ref(sink);
|
||||
d->type = DEVICE_TYPE_SINK;
|
||||
d->path = pa_sprintf_malloc("%s/%s%u", path_prefix, SINK_OBJECT_NAME, sink->index);
|
||||
|
||||
return d;
|
||||
}
|
||||
|
||||
pa_dbusiface_device *pa_dbusiface_device_new_source(pa_source *source, const char *path_prefix) {
|
||||
pa_dbusiface_device *d;
|
||||
|
||||
pa_assert(source);
|
||||
pa_assert(path_prefix);
|
||||
|
||||
d = pa_xnew(pa_dbusiface_device, 1);
|
||||
d->source = pa_source_ref(source);
|
||||
d->type = DEVICE_TYPE_SOURCE;
|
||||
d->path = pa_sprintf_malloc("%s/%s%u", path_prefix, SOURCE_OBJECT_NAME, source->index);
|
||||
|
||||
return d;
|
||||
}
|
||||
|
||||
void pa_dbusiface_device_free(pa_dbusiface_device *d) {
|
||||
pa_assert(d);
|
||||
|
||||
if (d->type == DEVICE_TYPE_SINK)
|
||||
pa_sink_unref(d->sink);
|
||||
else
|
||||
pa_source_unref(d->source);
|
||||
|
||||
pa_xfree(d->path);
|
||||
pa_xfree(d);
|
||||
}
|
||||
|
||||
const char *pa_dbusiface_device_get_path(pa_dbusiface_device *d) {
|
||||
pa_assert(d);
|
||||
|
||||
return d->path;
|
||||
}
|
||||
|
||||
pa_sink *pa_dbusiface_device_get_sink(pa_dbusiface_device *d) {
|
||||
pa_assert(d);
|
||||
pa_assert(d->type == DEVICE_TYPE_SINK);
|
||||
|
||||
return d->sink;
|
||||
}
|
||||
|
||||
pa_source *pa_dbusiface_device_get_source(pa_dbusiface_device *d) {
|
||||
pa_assert(d);
|
||||
pa_assert(d->type == DEVICE_TYPE_SOURCE);
|
||||
|
||||
return d->source;
|
||||
}
|
||||
46
src/modules/dbus/iface-device.h
Normal file
46
src/modules/dbus/iface-device.h
Normal file
|
|
@ -0,0 +1,46 @@
|
|||
#ifndef foodbusifacedevicehfoo
|
||||
#define foodbusifacedevicehfoo
|
||||
|
||||
/***
|
||||
This file is part of PulseAudio.
|
||||
|
||||
Copyright 2009 Tanu Kaskinen
|
||||
|
||||
PulseAudio is free software; you can redistribute it and/or modify
|
||||
it under the terms of the GNU Lesser General Public License as published
|
||||
by the Free Software Foundation; either version 2.1 of the License,
|
||||
or (at your option) any later version.
|
||||
|
||||
PulseAudio is distributed in the hope that it will be useful, but
|
||||
WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU Lesser General Public License
|
||||
along with PulseAudio; if not, write to the Free Software
|
||||
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
|
||||
USA.
|
||||
***/
|
||||
|
||||
/* This object implements the D-Bus interfaces org.PulseAudio.Core1.Device,
|
||||
* org.PulseAudio.Core1.Sink and org.PulseAudio.Core1.Source.
|
||||
*
|
||||
* See http://pulseaudio.org/wiki/DBusInterface for the interface
|
||||
* documentation.
|
||||
*/
|
||||
|
||||
#include <pulsecore/sink.h>
|
||||
#include <pulsecore/source.h>
|
||||
|
||||
typedef struct pa_dbusiface_device pa_dbusiface_device;
|
||||
|
||||
pa_dbusiface_device *pa_dbusiface_device_new_sink(pa_sink *sink, const char *path_prefix);
|
||||
pa_dbusiface_device *pa_dbusiface_device_new_source(pa_source *source, const char *path_prefix);
|
||||
void pa_dbusiface_device_free(pa_dbusiface_device *d);
|
||||
|
||||
const char *pa_dbusiface_device_get_path(pa_dbusiface_device *d);
|
||||
|
||||
pa_sink *pa_dbusiface_device_get_sink(pa_dbusiface_device *d);
|
||||
pa_source *pa_dbusiface_device_get_source(pa_dbusiface_device *d);
|
||||
|
||||
#endif
|
||||
61
src/modules/dbus/iface-module.c
Normal file
61
src/modules/dbus/iface-module.c
Normal file
|
|
@ -0,0 +1,61 @@
|
|||
/***
|
||||
This file is part of PulseAudio.
|
||||
|
||||
Copyright 2009 Tanu Kaskinen
|
||||
|
||||
PulseAudio is free software; you can redistribute it and/or modify
|
||||
it under the terms of the GNU Lesser General Public License as published
|
||||
by the Free Software Foundation; either version 2.1 of the License,
|
||||
or (at your option) any later version.
|
||||
|
||||
PulseAudio is distributed in the hope that it will be useful, but
|
||||
WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU Lesser General Public License
|
||||
along with PulseAudio; if not, write to the Free Software
|
||||
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
|
||||
USA.
|
||||
***/
|
||||
|
||||
#ifdef HAVE_CONFIG_H
|
||||
#include <config.h>
|
||||
#endif
|
||||
|
||||
#include <pulsecore/core-util.h>
|
||||
|
||||
#include "iface-module.h"
|
||||
|
||||
#define OBJECT_NAME "module"
|
||||
|
||||
struct pa_dbusiface_module {
|
||||
pa_module *module;
|
||||
char *path;
|
||||
};
|
||||
|
||||
pa_dbusiface_module *pa_dbusiface_module_new(pa_module *module, const char *path_prefix) {
|
||||
pa_dbusiface_module *m;
|
||||
|
||||
pa_assert(module);
|
||||
pa_assert(path_prefix);
|
||||
|
||||
m = pa_xnew(pa_dbusiface_module, 1);
|
||||
m->module = module;
|
||||
m->path = pa_sprintf_malloc("%s/%s%u", path_prefix, OBJECT_NAME, module->index);
|
||||
|
||||
return m;
|
||||
}
|
||||
|
||||
void pa_dbusiface_module_free(pa_dbusiface_module *m) {
|
||||
pa_assert(m);
|
||||
|
||||
pa_xfree(m->path);
|
||||
pa_xfree(m);
|
||||
}
|
||||
|
||||
const char *pa_dbusiface_module_get_path(pa_dbusiface_module *m) {
|
||||
pa_assert(m);
|
||||
|
||||
return m->path;
|
||||
}
|
||||
40
src/modules/dbus/iface-module.h
Normal file
40
src/modules/dbus/iface-module.h
Normal file
|
|
@ -0,0 +1,40 @@
|
|||
#ifndef foodbusifacemodulehfoo
|
||||
#define foodbusifacemodulehfoo
|
||||
|
||||
/***
|
||||
This file is part of PulseAudio.
|
||||
|
||||
Copyright 2009 Tanu Kaskinen
|
||||
|
||||
PulseAudio is free software; you can redistribute it and/or modify
|
||||
it under the terms of the GNU Lesser General Public License as published
|
||||
by the Free Software Foundation; either version 2.1 of the License,
|
||||
or (at your option) any later version.
|
||||
|
||||
PulseAudio is distributed in the hope that it will be useful, but
|
||||
WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU Lesser General Public License
|
||||
along with PulseAudio; if not, write to the Free Software
|
||||
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
|
||||
USA.
|
||||
***/
|
||||
|
||||
/* This object implements the D-Bus interface org.PulseAudio.Core1.Module.
|
||||
*
|
||||
* See http://pulseaudio.org/wiki/DBusInterface for the Module interface
|
||||
* documentation.
|
||||
*/
|
||||
|
||||
#include <pulsecore/module.h>
|
||||
|
||||
typedef struct pa_dbusiface_module pa_dbusiface_module;
|
||||
|
||||
pa_dbusiface_module *pa_dbusiface_module_new(pa_module *module, const char *path_prefix);
|
||||
void pa_dbusiface_module_free(pa_dbusiface_module *m);
|
||||
|
||||
const char *pa_dbusiface_module_get_path(pa_dbusiface_module *m);
|
||||
|
||||
#endif
|
||||
61
src/modules/dbus/iface-sample.c
Normal file
61
src/modules/dbus/iface-sample.c
Normal file
|
|
@ -0,0 +1,61 @@
|
|||
/***
|
||||
This file is part of PulseAudio.
|
||||
|
||||
Copyright 2009 Tanu Kaskinen
|
||||
|
||||
PulseAudio is free software; you can redistribute it and/or modify
|
||||
it under the terms of the GNU Lesser General Public License as published
|
||||
by the Free Software Foundation; either version 2.1 of the License,
|
||||
or (at your option) any later version.
|
||||
|
||||
PulseAudio is distributed in the hope that it will be useful, but
|
||||
WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU Lesser General Public License
|
||||
along with PulseAudio; if not, write to the Free Software
|
||||
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
|
||||
USA.
|
||||
***/
|
||||
|
||||
#ifdef HAVE_CONFIG_H
|
||||
#include <config.h>
|
||||
#endif
|
||||
|
||||
#include <pulsecore/core-util.h>
|
||||
|
||||
#include "iface-sample.h"
|
||||
|
||||
#define OBJECT_NAME "sample"
|
||||
|
||||
struct pa_dbusiface_sample {
|
||||
pa_scache_entry *sample;
|
||||
char *path;
|
||||
};
|
||||
|
||||
pa_dbusiface_sample *pa_dbusiface_sample_new(pa_scache_entry *sample, const char *path_prefix) {
|
||||
pa_dbusiface_sample *s;
|
||||
|
||||
pa_assert(sample);
|
||||
pa_assert(path_prefix);
|
||||
|
||||
s = pa_xnew(pa_dbusiface_sample, 1);
|
||||
s->sample = sample;
|
||||
s->path = pa_sprintf_malloc("%s/%s%u", path_prefix, OBJECT_NAME, sample->index);
|
||||
|
||||
return s;
|
||||
}
|
||||
|
||||
void pa_dbusiface_sample_free(pa_dbusiface_sample *s) {
|
||||
pa_assert(s);
|
||||
|
||||
pa_xfree(s->path);
|
||||
pa_xfree(s);
|
||||
}
|
||||
|
||||
const char *pa_dbusiface_sample_get_path(pa_dbusiface_sample *s) {
|
||||
pa_assert(s);
|
||||
|
||||
return s->path;
|
||||
}
|
||||
40
src/modules/dbus/iface-sample.h
Normal file
40
src/modules/dbus/iface-sample.h
Normal file
|
|
@ -0,0 +1,40 @@
|
|||
#ifndef foodbusifacesamplehfoo
|
||||
#define foodbusifacesamplehfoo
|
||||
|
||||
/***
|
||||
This file is part of PulseAudio.
|
||||
|
||||
Copyright 2009 Tanu Kaskinen
|
||||
|
||||
PulseAudio is free software; you can redistribute it and/or modify
|
||||
it under the terms of the GNU Lesser General Public License as published
|
||||
by the Free Software Foundation; either version 2.1 of the License,
|
||||
or (at your option) any later version.
|
||||
|
||||
PulseAudio is distributed in the hope that it will be useful, but
|
||||
WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU Lesser General Public License
|
||||
along with PulseAudio; if not, write to the Free Software
|
||||
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
|
||||
USA.
|
||||
***/
|
||||
|
||||
/* This object implements the D-Bus interface org.PulseAudio.Core1.Sample.
|
||||
*
|
||||
* See http://pulseaudio.org/wiki/DBusInterface for the Sample interface
|
||||
* documentation.
|
||||
*/
|
||||
|
||||
#include <pulsecore/core-scache.h>
|
||||
|
||||
typedef struct pa_dbusiface_sample pa_dbusiface_sample;
|
||||
|
||||
pa_dbusiface_sample *pa_dbusiface_sample_new(pa_scache_entry *sample, const char *path_prefix);
|
||||
void pa_dbusiface_sample_free(pa_dbusiface_sample *c);
|
||||
|
||||
const char *pa_dbusiface_sample_get_path(pa_dbusiface_sample *c);
|
||||
|
||||
#endif
|
||||
91
src/modules/dbus/iface-stream.c
Normal file
91
src/modules/dbus/iface-stream.c
Normal file
|
|
@ -0,0 +1,91 @@
|
|||
/***
|
||||
This file is part of PulseAudio.
|
||||
|
||||
Copyright 2009 Tanu Kaskinen
|
||||
|
||||
PulseAudio is free software; you can redistribute it and/or modify
|
||||
it under the terms of the GNU Lesser General Public License as published
|
||||
by the Free Software Foundation; either version 2.1 of the License,
|
||||
or (at your option) any later version.
|
||||
|
||||
PulseAudio is distributed in the hope that it will be useful, but
|
||||
WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU Lesser General Public License
|
||||
along with PulseAudio; if not, write to the Free Software
|
||||
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
|
||||
USA.
|
||||
***/
|
||||
|
||||
#ifdef HAVE_CONFIG_H
|
||||
#include <config.h>
|
||||
#endif
|
||||
|
||||
#include <pulsecore/core-util.h>
|
||||
|
||||
#include "iface-stream.h"
|
||||
|
||||
#define PLAYBACK_OBJECT_NAME "playback_stream"
|
||||
#define RECORD_OBJECT_NAME "record_stream"
|
||||
|
||||
enum stream_type {
|
||||
STREAM_TYPE_PLAYBACK,
|
||||
STREAM_TYPE_RECORD
|
||||
};
|
||||
|
||||
struct pa_dbusiface_stream {
|
||||
union {
|
||||
pa_sink_input *sink_input;
|
||||
pa_source_output *source_output;
|
||||
};
|
||||
enum stream_type type;
|
||||
char *path;
|
||||
};
|
||||
|
||||
pa_dbusiface_stream *pa_dbusiface_stream_new_playback(pa_sink_input *sink_input, const char *path_prefix) {
|
||||
pa_dbusiface_stream *s;
|
||||
|
||||
pa_assert(sink_input);
|
||||
pa_assert(path_prefix);
|
||||
|
||||
s = pa_xnew(pa_dbusiface_stream, 1);
|
||||
s->sink_input = pa_sink_input_ref(sink_input);
|
||||
s->type = STREAM_TYPE_PLAYBACK;
|
||||
s->path = pa_sprintf_malloc("%s/%s%u", path_prefix, PLAYBACK_OBJECT_NAME, sink_input->index);
|
||||
|
||||
return s;
|
||||
}
|
||||
|
||||
pa_dbusiface_stream *pa_dbusiface_stream_new_record(pa_source_output *source_output, const char *path_prefix) {
|
||||
pa_dbusiface_stream *s;
|
||||
|
||||
pa_assert(source_output);
|
||||
pa_assert(path_prefix);
|
||||
|
||||
s = pa_xnew(pa_dbusiface_stream, 1);
|
||||
s->source_output = pa_source_output_ref(source_output);
|
||||
s->type = STREAM_TYPE_RECORD;
|
||||
s->path = pa_sprintf_malloc("%s/%s%u", path_prefix, RECORD_OBJECT_NAME, source_output->index);
|
||||
|
||||
return s;
|
||||
}
|
||||
|
||||
void pa_dbusiface_stream_free(pa_dbusiface_stream *s) {
|
||||
pa_assert(s);
|
||||
|
||||
if (s->type == STREAM_TYPE_PLAYBACK)
|
||||
pa_sink_input_unref(s->sink_input);
|
||||
else
|
||||
pa_source_output_unref(s->source_output);
|
||||
|
||||
pa_xfree(s->path);
|
||||
pa_xfree(s);
|
||||
}
|
||||
|
||||
const char *pa_dbusiface_stream_get_path(pa_dbusiface_stream *s) {
|
||||
pa_assert(s);
|
||||
|
||||
return s->path;
|
||||
}
|
||||
42
src/modules/dbus/iface-stream.h
Normal file
42
src/modules/dbus/iface-stream.h
Normal file
|
|
@ -0,0 +1,42 @@
|
|||
#ifndef foodbusifacestreamhfoo
|
||||
#define foodbusifacestreamhfoo
|
||||
|
||||
/***
|
||||
This file is part of PulseAudio.
|
||||
|
||||
Copyright 2009 Tanu Kaskinen
|
||||
|
||||
PulseAudio is free software; you can redistribute it and/or modify
|
||||
it under the terms of the GNU Lesser General Public License as published
|
||||
by the Free Software Foundation; either version 2.1 of the License,
|
||||
or (at your option) any later version.
|
||||
|
||||
PulseAudio is distributed in the hope that it will be useful, but
|
||||
WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU Lesser General Public License
|
||||
along with PulseAudio; if not, write to the Free Software
|
||||
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
|
||||
USA.
|
||||
***/
|
||||
|
||||
/* This object implements the D-Bus interface org.PulseAudio.Core1.Stream.
|
||||
*
|
||||
* See http://pulseaudio.org/wiki/DBusInterface for the Stream interface
|
||||
* documentation.
|
||||
*/
|
||||
|
||||
#include <pulsecore/sink-input.h>
|
||||
#include <pulsecore/source-output.h>
|
||||
|
||||
typedef struct pa_dbusiface_stream pa_dbusiface_stream;
|
||||
|
||||
pa_dbusiface_stream *pa_dbusiface_stream_new_playback(pa_sink_input *sink_input, const char *path_prefix);
|
||||
pa_dbusiface_stream *pa_dbusiface_stream_new_record(pa_source_output *source_output, const char *path_prefix);
|
||||
void pa_dbusiface_stream_free(pa_dbusiface_stream *s);
|
||||
|
||||
const char *pa_dbusiface_stream_get_path(pa_dbusiface_stream *s);
|
||||
|
||||
#endif
|
||||
580
src/modules/dbus/module-dbus-protocol.c
Normal file
580
src/modules/dbus/module-dbus-protocol.c
Normal file
|
|
@ -0,0 +1,580 @@
|
|||
/***
|
||||
This file is part of PulseAudio.
|
||||
|
||||
Copyright 2009 Tanu Kaskinen
|
||||
Copyright 2006 Lennart Poettering
|
||||
Copyright 2006 Shams E. King
|
||||
|
||||
PulseAudio is free software; you can redistribute it and/or modify
|
||||
it under the terms of the GNU Lesser General Public License as published
|
||||
by the Free Software Foundation; either version 2.1 of the License,
|
||||
or (at your option) any later version.
|
||||
|
||||
PulseAudio is distributed in the hope that it will be useful, but
|
||||
WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU Lesser General Public License
|
||||
along with PulseAudio; if not, write to the Free Software
|
||||
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
|
||||
USA.
|
||||
***/
|
||||
|
||||
#ifdef HAVE_CONFIG_H
|
||||
#include <config.h>
|
||||
#endif
|
||||
|
||||
#include <dbus/dbus.h>
|
||||
|
||||
#include <pulse/mainloop-api.h>
|
||||
#include <pulse/timeval.h>
|
||||
#include <pulse/xmalloc.h>
|
||||
|
||||
#include <pulsecore/client.h>
|
||||
#include <pulsecore/core-util.h>
|
||||
#include <pulsecore/dbus-util.h>
|
||||
#include <pulsecore/idxset.h>
|
||||
#include <pulsecore/macro.h>
|
||||
#include <pulsecore/modargs.h>
|
||||
#include <pulsecore/module.h>
|
||||
#include <pulsecore/protocol-dbus.h>
|
||||
|
||||
#include "iface-core.h"
|
||||
|
||||
#include "module-dbus-protocol-symdef.h"
|
||||
|
||||
PA_MODULE_DESCRIPTION("D-Bus interface");
|
||||
PA_MODULE_USAGE(
|
||||
"access=local|remote|local,remote "
|
||||
"tcp_port=<port number>");
|
||||
PA_MODULE_LOAD_ONCE(TRUE);
|
||||
PA_MODULE_AUTHOR("Tanu Kaskinen");
|
||||
PA_MODULE_VERSION(PACKAGE_VERSION);
|
||||
|
||||
#define CLEANUP_INTERVAL 10 /* seconds */
|
||||
|
||||
enum server_type {
|
||||
SERVER_TYPE_LOCAL,
|
||||
SERVER_TYPE_TCP
|
||||
};
|
||||
|
||||
struct server;
|
||||
struct connection;
|
||||
|
||||
struct userdata {
|
||||
pa_module *module;
|
||||
pa_bool_t local_access;
|
||||
pa_bool_t remote_access;
|
||||
uint32_t tcp_port;
|
||||
|
||||
struct server *local_server;
|
||||
struct server *tcp_server;
|
||||
|
||||
pa_idxset *connections;
|
||||
|
||||
pa_time_event *cleanup_event;
|
||||
|
||||
pa_dbus_protocol *dbus_protocol;
|
||||
pa_dbusiface_core *core_iface;
|
||||
};
|
||||
|
||||
struct server {
|
||||
struct userdata *userdata;
|
||||
enum server_type type;
|
||||
DBusServer *dbus_server;
|
||||
};
|
||||
|
||||
struct connection {
|
||||
struct server *server;
|
||||
pa_dbus_wrap_connection *wrap_conn;
|
||||
pa_client *client;
|
||||
};
|
||||
|
||||
static const char* const valid_modargs[] = {
|
||||
"access",
|
||||
"tcp_port",
|
||||
NULL
|
||||
};
|
||||
|
||||
static void connection_free(struct connection *c) {
|
||||
pa_assert(c);
|
||||
|
||||
pa_assert_se(pa_dbus_protocol_unregister_connection(c->server->userdata->dbus_protocol, pa_dbus_wrap_connection_get(c->wrap_conn)) >= 0);
|
||||
|
||||
pa_client_free(c->client);
|
||||
pa_assert_se(pa_idxset_remove_by_data(c->server->userdata->connections, c, NULL));
|
||||
pa_dbus_wrap_connection_free(c->wrap_conn);
|
||||
pa_xfree(c);
|
||||
}
|
||||
|
||||
/* Called from pa_client_kill(). */
|
||||
static void client_kill_cb(pa_client *c) {
|
||||
struct connection *conn;
|
||||
|
||||
pa_assert(c);
|
||||
pa_assert(c->userdata);
|
||||
|
||||
conn = c->userdata;
|
||||
connection_free(conn);
|
||||
|
||||
pa_log_info("Connection killed.");
|
||||
}
|
||||
|
||||
static dbus_bool_t user_check_cb(DBusConnection *connection, unsigned long uid, void *data) {
|
||||
pa_log_debug("Allowing connection by user %lu.", uid);
|
||||
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
/* Called by D-Bus when a new client connection is received. */
|
||||
static void connection_new_cb(DBusServer *dbus_server, DBusConnection *new_connection, void *data) {
|
||||
struct server *s = data;
|
||||
struct connection *c;
|
||||
pa_client_new_data new_data;
|
||||
pa_client *client;
|
||||
|
||||
pa_assert(new_connection);
|
||||
pa_assert(s);
|
||||
|
||||
pa_client_new_data_init(&new_data);
|
||||
new_data.module = s->userdata->module;
|
||||
new_data.driver = __FILE__;
|
||||
pa_proplist_sets(new_data.proplist, PA_PROP_APPLICATION_NAME, "D-Bus client"); /* TODO: It's probably possible to generate a fancier name. Other props? */
|
||||
client = pa_client_new(s->userdata->module->core, &new_data);
|
||||
pa_client_new_data_done(&new_data);
|
||||
|
||||
if (!client) {
|
||||
dbus_connection_close(new_connection);
|
||||
return;
|
||||
}
|
||||
|
||||
if (s->type == SERVER_TYPE_TCP || s->userdata->module->core->server_type == PA_SERVER_TYPE_SYSTEM) {
|
||||
/* FIXME: Here we allow anyone from anywhere to access the server,
|
||||
* anonymously. Access control should be configurable. */
|
||||
dbus_connection_set_unix_user_function(new_connection, user_check_cb, NULL, NULL);
|
||||
dbus_connection_set_allow_anonymous(new_connection, TRUE);
|
||||
}
|
||||
|
||||
c = pa_xnew(struct connection, 1);
|
||||
c->server = s;
|
||||
c->wrap_conn = pa_dbus_wrap_connection_new_from_existing(s->userdata->module->core->mainloop, TRUE, new_connection);
|
||||
c->client = client;
|
||||
|
||||
c->client->kill = client_kill_cb;
|
||||
c->client->send_event = NULL; /* TODO: Implement this. */
|
||||
c->client->userdata = c;
|
||||
|
||||
pa_idxset_put(s->userdata->connections, c, NULL);
|
||||
|
||||
pa_assert_se(pa_dbus_protocol_register_connection(s->userdata->dbus_protocol, new_connection, c->client) >= 0);
|
||||
}
|
||||
|
||||
/* Called by PA mainloop when a D-Bus fd watch event needs handling. */
|
||||
static void io_event_cb(pa_mainloop_api *mainloop, pa_io_event *e, int fd, pa_io_event_flags_t events, void *userdata) {
|
||||
unsigned int flags = 0;
|
||||
DBusWatch *watch = userdata;
|
||||
|
||||
#if HAVE_DBUS_WATCH_GET_UNIX_FD
|
||||
pa_assert(fd == dbus_watch_get_unix_fd(watch));
|
||||
#else
|
||||
pa_assert(fd == dbus_watch_get_fd(watch));
|
||||
#endif
|
||||
|
||||
if (!dbus_watch_get_enabled(watch)) {
|
||||
pa_log_warn("Asked to handle disabled watch: %p %i", (void*) watch, fd);
|
||||
return;
|
||||
}
|
||||
|
||||
if (events & PA_IO_EVENT_INPUT)
|
||||
flags |= DBUS_WATCH_READABLE;
|
||||
if (events & PA_IO_EVENT_OUTPUT)
|
||||
flags |= DBUS_WATCH_WRITABLE;
|
||||
if (events & PA_IO_EVENT_HANGUP)
|
||||
flags |= DBUS_WATCH_HANGUP;
|
||||
if (events & PA_IO_EVENT_ERROR)
|
||||
flags |= DBUS_WATCH_ERROR;
|
||||
|
||||
dbus_watch_handle(watch, flags);
|
||||
}
|
||||
|
||||
/* Called by PA mainloop when a D-Bus timer event needs handling. */
|
||||
static void time_event_cb(pa_mainloop_api *mainloop, pa_time_event* e, const struct timeval *tv, void *userdata) {
|
||||
DBusTimeout *timeout = userdata;
|
||||
|
||||
if (dbus_timeout_get_enabled(timeout)) {
|
||||
struct timeval next = *tv;
|
||||
dbus_timeout_handle(timeout);
|
||||
|
||||
/* restart it for the next scheduled time */
|
||||
pa_timeval_add(&next, (pa_usec_t) dbus_timeout_get_interval(timeout) * 1000);
|
||||
mainloop->time_restart(e, &next);
|
||||
}
|
||||
}
|
||||
|
||||
/* Translates D-Bus fd watch event flags to PA IO event flags. */
|
||||
static pa_io_event_flags_t get_watch_flags(DBusWatch *watch) {
|
||||
unsigned int flags;
|
||||
pa_io_event_flags_t events = 0;
|
||||
|
||||
pa_assert(watch);
|
||||
|
||||
flags = dbus_watch_get_flags(watch);
|
||||
|
||||
/* no watch flags for disabled watches */
|
||||
if (!dbus_watch_get_enabled(watch))
|
||||
return PA_IO_EVENT_NULL;
|
||||
|
||||
if (flags & DBUS_WATCH_READABLE)
|
||||
events |= PA_IO_EVENT_INPUT;
|
||||
if (flags & DBUS_WATCH_WRITABLE)
|
||||
events |= PA_IO_EVENT_OUTPUT;
|
||||
|
||||
return events | PA_IO_EVENT_HANGUP | PA_IO_EVENT_ERROR;
|
||||
}
|
||||
|
||||
/* Called by D-Bus when a D-Bus fd watch event is added. */
|
||||
static dbus_bool_t watch_add_cb(DBusWatch *watch, void *data) {
|
||||
struct server *s = data;
|
||||
pa_mainloop_api *mainloop;
|
||||
pa_io_event *ev;
|
||||
|
||||
pa_assert(watch);
|
||||
pa_assert(s);
|
||||
|
||||
mainloop = s->userdata->module->core->mainloop;
|
||||
|
||||
ev = mainloop->io_new(
|
||||
mainloop,
|
||||
#if HAVE_DBUS_WATCH_GET_UNIX_FD
|
||||
dbus_watch_get_unix_fd(watch),
|
||||
#else
|
||||
dbus_watch_get_fd(watch),
|
||||
#endif
|
||||
get_watch_flags(watch), io_event_cb, watch);
|
||||
|
||||
dbus_watch_set_data(watch, ev, NULL);
|
||||
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
/* Called by D-Bus when a D-Bus fd watch event is removed. */
|
||||
static void watch_remove_cb(DBusWatch *watch, void *data) {
|
||||
struct server *s = data;
|
||||
pa_io_event *ev;
|
||||
|
||||
pa_assert(watch);
|
||||
pa_assert(s);
|
||||
|
||||
if ((ev = dbus_watch_get_data(watch)))
|
||||
s->userdata->module->core->mainloop->io_free(ev);
|
||||
}
|
||||
|
||||
/* Called by D-Bus when a D-Bus fd watch event is toggled. */
|
||||
static void watch_toggled_cb(DBusWatch *watch, void *data) {
|
||||
struct server *s = data;
|
||||
pa_io_event *ev;
|
||||
|
||||
pa_assert(watch);
|
||||
pa_assert(s);
|
||||
|
||||
pa_assert_se(ev = dbus_watch_get_data(watch));
|
||||
|
||||
/* get_watch_flags() checks if the watch is enabled */
|
||||
s->userdata->module->core->mainloop->io_enable(ev, get_watch_flags(watch));
|
||||
}
|
||||
|
||||
/* Called by D-Bus when a D-Bus timer event is added. */
|
||||
static dbus_bool_t timeout_add_cb(DBusTimeout *timeout, void *data) {
|
||||
struct server *s = data;
|
||||
pa_mainloop_api *mainloop;
|
||||
pa_time_event *ev;
|
||||
struct timeval tv;
|
||||
|
||||
pa_assert(timeout);
|
||||
pa_assert(s);
|
||||
|
||||
if (!dbus_timeout_get_enabled(timeout))
|
||||
return FALSE;
|
||||
|
||||
mainloop = s->userdata->module->core->mainloop;
|
||||
|
||||
pa_gettimeofday(&tv);
|
||||
pa_timeval_add(&tv, (pa_usec_t) dbus_timeout_get_interval(timeout) * 1000);
|
||||
|
||||
ev = mainloop->time_new(mainloop, &tv, time_event_cb, timeout);
|
||||
|
||||
dbus_timeout_set_data(timeout, ev, NULL);
|
||||
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
/* Called by D-Bus when a D-Bus timer event is removed. */
|
||||
static void timeout_remove_cb(DBusTimeout *timeout, void *data) {
|
||||
struct server *s = data;
|
||||
pa_time_event *ev;
|
||||
|
||||
pa_assert(timeout);
|
||||
pa_assert(s);
|
||||
|
||||
if ((ev = dbus_timeout_get_data(timeout)))
|
||||
s->userdata->module->core->mainloop->time_free(ev);
|
||||
}
|
||||
|
||||
/* Called by D-Bus when a D-Bus timer event is toggled. */
|
||||
static void timeout_toggled_cb(DBusTimeout *timeout, void *data) {
|
||||
struct server *s = data;
|
||||
pa_mainloop_api *mainloop;
|
||||
pa_time_event *ev;
|
||||
|
||||
pa_assert(timeout);
|
||||
pa_assert(s);
|
||||
|
||||
mainloop = s->userdata->module->core->mainloop;
|
||||
|
||||
pa_assert_se(ev = dbus_timeout_get_data(timeout));
|
||||
|
||||
if (dbus_timeout_get_enabled(timeout)) {
|
||||
struct timeval tv;
|
||||
|
||||
pa_gettimeofday(&tv);
|
||||
pa_timeval_add(&tv, (pa_usec_t) dbus_timeout_get_interval(timeout) * 1000);
|
||||
|
||||
mainloop->time_restart(ev, &tv);
|
||||
} else
|
||||
mainloop->time_restart(ev, NULL);
|
||||
}
|
||||
|
||||
static void server_free(struct server *s) {
|
||||
pa_assert(s);
|
||||
|
||||
if (s->dbus_server) {
|
||||
dbus_server_disconnect(s->dbus_server);
|
||||
dbus_server_unref(s->dbus_server);
|
||||
}
|
||||
|
||||
pa_xfree(s);
|
||||
}
|
||||
|
||||
static struct server *start_server(struct userdata *u, const char *address, enum server_type type) {
|
||||
/* XXX: We assume that when we unref the DBusServer instance at module
|
||||
* shutdown, nobody else holds any references to it. If we stop assuming
|
||||
* that someday, dbus_server_set_new_connection_function,
|
||||
* dbus_server_set_watch_functions and dbus_server_set_timeout_functions
|
||||
* calls should probably register free callbacks, instead of providing NULL
|
||||
* as they do now. */
|
||||
|
||||
struct server *s = NULL;
|
||||
DBusError error;
|
||||
|
||||
pa_assert(u);
|
||||
pa_assert(address);
|
||||
|
||||
dbus_error_init(&error);
|
||||
|
||||
s = pa_xnew0(struct server, 1);
|
||||
s->userdata = u;
|
||||
s->dbus_server = dbus_server_listen(address, &error);
|
||||
|
||||
if (dbus_error_is_set(&error)) {
|
||||
pa_log("dbus_server_listen() failed: %s: %s", error.name, error.message);
|
||||
goto fail;
|
||||
}
|
||||
|
||||
dbus_server_set_new_connection_function(s->dbus_server, connection_new_cb, s, NULL);
|
||||
|
||||
if (!dbus_server_set_watch_functions(s->dbus_server, watch_add_cb, watch_remove_cb, watch_toggled_cb, s, NULL)) {
|
||||
pa_log("dbus_server_set_watch_functions() ran out of memory.");
|
||||
goto fail;
|
||||
}
|
||||
|
||||
if (!dbus_server_set_timeout_functions(s->dbus_server, timeout_add_cb, timeout_remove_cb, timeout_toggled_cb, s, NULL)) {
|
||||
pa_log("dbus_server_set_timeout_functions() ran out of memory.");
|
||||
goto fail;
|
||||
}
|
||||
|
||||
return s;
|
||||
|
||||
fail:
|
||||
if (s)
|
||||
server_free(s);
|
||||
|
||||
dbus_error_free(&error);
|
||||
|
||||
return NULL;
|
||||
}
|
||||
|
||||
static struct server *start_local_server(struct userdata *u) {
|
||||
struct server *s = NULL;
|
||||
char *address = NULL;
|
||||
|
||||
pa_assert(u);
|
||||
|
||||
address = pa_get_dbus_address_from_server_type(u->module->core->server_type);
|
||||
|
||||
s = start_server(u, address, SERVER_TYPE_LOCAL); /* May return NULL */
|
||||
|
||||
pa_xfree(address);
|
||||
|
||||
return s;
|
||||
}
|
||||
|
||||
static struct server *start_tcp_server(struct userdata *u) {
|
||||
struct server *s = NULL;
|
||||
char *address = NULL;
|
||||
|
||||
pa_assert(u);
|
||||
|
||||
address = pa_sprintf_malloc("tcp:host=127.0.0.1,port=%u", u->tcp_port);
|
||||
|
||||
s = start_server(u, address, SERVER_TYPE_TCP); /* May return NULL */
|
||||
|
||||
pa_xfree(address);
|
||||
|
||||
return s;
|
||||
}
|
||||
|
||||
static int get_access_arg(pa_modargs *ma, pa_bool_t *local_access, pa_bool_t *remote_access) {
|
||||
const char *value = NULL;
|
||||
|
||||
pa_assert(ma);
|
||||
pa_assert(local_access);
|
||||
pa_assert(remote_access);
|
||||
|
||||
if (!(value = pa_modargs_get_value(ma, "access", NULL)))
|
||||
return 0;
|
||||
|
||||
if (!strcmp(value, "local")) {
|
||||
*local_access = TRUE;
|
||||
*remote_access = FALSE;
|
||||
} else if (!strcmp(value, "remote")) {
|
||||
*local_access = FALSE;
|
||||
*remote_access = TRUE;
|
||||
} else if (!strcmp(value, "local,remote")) {
|
||||
*local_access = TRUE;
|
||||
*remote_access = TRUE;
|
||||
} else
|
||||
return -1;
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
/* Frees dead client connections. Called every CLEANUP_INTERVAL seconds. */
|
||||
static void cleanup_cb(pa_mainloop_api *a, pa_time_event *e, const struct timeval *tv, void *userdata) {
|
||||
struct userdata *u = userdata;
|
||||
struct connection *conn = NULL;
|
||||
uint32_t idx;
|
||||
struct timeval cleanup_timeval;
|
||||
unsigned free_count = 0;
|
||||
|
||||
for (conn = pa_idxset_first(u->connections, &idx); conn; conn = pa_idxset_next(u->connections, &idx)) {
|
||||
if (!dbus_connection_get_is_connected(pa_dbus_wrap_connection_get(conn->wrap_conn))) {
|
||||
connection_free(conn);
|
||||
++free_count;
|
||||
}
|
||||
}
|
||||
|
||||
if (free_count > 0)
|
||||
pa_log_debug("Freed %u dead D-Bus client connections.", free_count);
|
||||
|
||||
pa_gettimeofday(&cleanup_timeval);
|
||||
cleanup_timeval.tv_sec += CLEANUP_INTERVAL;
|
||||
u->module->core->mainloop->time_restart(e, &cleanup_timeval);
|
||||
}
|
||||
|
||||
int pa__init(pa_module *m) {
|
||||
struct userdata *u = NULL;
|
||||
pa_modargs *ma = NULL;
|
||||
struct timeval cleanup_timeval;
|
||||
|
||||
pa_assert(m);
|
||||
|
||||
if (!(ma = pa_modargs_new(m->argument, valid_modargs))) {
|
||||
pa_log("Failed to parse module arguments.");
|
||||
goto fail;
|
||||
}
|
||||
|
||||
m->userdata = u = pa_xnew0(struct userdata, 1);
|
||||
u->module = m;
|
||||
u->local_access = TRUE;
|
||||
u->remote_access = FALSE;
|
||||
u->tcp_port = PA_DBUS_DEFAULT_PORT;
|
||||
|
||||
if (get_access_arg(ma, &u->local_access, &u->remote_access) < 0) {
|
||||
pa_log("Invalid access argument: '%s'", pa_modargs_get_value(ma, "access", NULL));
|
||||
goto fail;
|
||||
}
|
||||
|
||||
if (pa_modargs_get_value_u32(ma, "tcp_port", &u->tcp_port) < 0 || u->tcp_port < 1 || u->tcp_port > 49150) {
|
||||
pa_log("Invalid tcp_port argument: '%s'", pa_modargs_get_value(ma, "tcp_port", NULL));
|
||||
goto fail;
|
||||
}
|
||||
|
||||
if (u->local_access && !(u->local_server = start_local_server(u))) {
|
||||
pa_log("Starting the local D-Bus server failed.");
|
||||
goto fail;
|
||||
}
|
||||
|
||||
if (u->remote_access && !(u->tcp_server = start_tcp_server(u))) {
|
||||
pa_log("Starting the D-Bus server for remote connections failed.");
|
||||
goto fail;
|
||||
}
|
||||
|
||||
u->connections = pa_idxset_new(pa_idxset_trivial_hash_func, pa_idxset_trivial_compare_func);
|
||||
|
||||
pa_gettimeofday(&cleanup_timeval);
|
||||
cleanup_timeval.tv_sec += CLEANUP_INTERVAL;
|
||||
u->cleanup_event = m->core->mainloop->time_new(m->core->mainloop, &cleanup_timeval, cleanup_cb, u);
|
||||
|
||||
u->dbus_protocol = pa_dbus_protocol_get(m->core);
|
||||
u->core_iface = pa_dbusiface_core_new(m->core);
|
||||
|
||||
return 0;
|
||||
|
||||
fail:
|
||||
if (ma)
|
||||
pa_modargs_free(ma);
|
||||
|
||||
pa__done(m);
|
||||
|
||||
return -1;
|
||||
}
|
||||
|
||||
/* Called by idxset when the connection set is freed. */
|
||||
static void connection_free_cb(void *p, void *userdata) {
|
||||
struct connection *conn = p;
|
||||
|
||||
pa_assert(conn);
|
||||
|
||||
connection_free(conn);
|
||||
}
|
||||
|
||||
void pa__done(pa_module *m) {
|
||||
struct userdata *u;
|
||||
|
||||
pa_assert(m);
|
||||
|
||||
if (!(u = m->userdata))
|
||||
return;
|
||||
|
||||
if (u->core_iface)
|
||||
pa_dbusiface_core_free(u->core_iface);
|
||||
|
||||
if (u->cleanup_event)
|
||||
m->core->mainloop->time_free(u->cleanup_event);
|
||||
|
||||
if (u->connections)
|
||||
pa_idxset_free(u->connections, connection_free_cb, NULL);
|
||||
|
||||
if (u->tcp_server)
|
||||
server_free(u->tcp_server);
|
||||
|
||||
if (u->local_server)
|
||||
server_free(u->local_server);
|
||||
|
||||
if (u->dbus_protocol)
|
||||
pa_dbus_protocol_unref(u->dbus_protocol);
|
||||
|
||||
pa_xfree(u);
|
||||
m->userdata = NULL;
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue