dbus: split dbus-util into dbus-shared

modules: fix dbus-util include
pulse: get dbus at context connection
This commit is contained in:
Marc-André Lureau 2009-03-19 01:35:02 +02:00
parent 3813034cef
commit eb93e2537a
13 changed files with 233 additions and 121 deletions

View file

@ -633,6 +633,12 @@ if OS_IS_WIN32
libpulsecommon_@PA_MAJORMINORMICRO@_la_SOURCES += pulsecore/dllmain.c libpulsecommon_@PA_MAJORMINORMICRO@_la_SOURCES += pulsecore/dllmain.c
endif endif
if HAVE_DBUS
libpulsecommon_@PA_MAJORMINORMICRO@_la_SOURCES += pulsecore/dbus-util.c pulsecore/dbus-util.h
libpulsecommon_@PA_MAJORMINORMICRO@_la_CFLAGS += $(DBUS_CFLAGS)
libpulsecommon_@PA_MAJORMINORMICRO@_la_LIBADD += $(DBUS_LIBS)
endif
################################### ###################################
# Client library # # Client library #
################################### ###################################
@ -713,7 +719,7 @@ libpulse_la_SOURCES = \
pulse/volume.c pulse/volume.h \ pulse/volume.c pulse/volume.h \
pulse/xmalloc.c pulse/xmalloc.h pulse/xmalloc.c pulse/xmalloc.h
libpulse_la_CFLAGS = $(AM_CFLAGS) libpulse_la_CFLAGS = $(AM_CFLAGS) $(DBUS_CFLAGS)
libpulse_la_LIBADD = $(AM_LIBADD) $(WINSOCK_LIBS) $(LTLIBICONV) libpulsecommon-@PA_MAJORMINORMICRO@.la libpulse_la_LIBADD = $(AM_LIBADD) $(WINSOCK_LIBS) $(LTLIBICONV) libpulsecommon-@PA_MAJORMINORMICRO@.la
libpulse_la_LDFLAGS = $(AM_LDFLAGS) $(VERSIONING_LDFLAGS) -version-info $(LIBPULSE_VERSION_INFO) libpulse_la_LDFLAGS = $(AM_LDFLAGS) $(VERSIONING_LDFLAGS) -version-info $(LIBPULSE_VERSION_INFO)
@ -813,6 +819,13 @@ libpulsecore_@PA_MAJORMINORMICRO@_la_CFLAGS += $(X11_CFLAGS)
libpulsecore_@PA_MAJORMINORMICRO@_la_LDFLAGS += $(X11_LIBS) libpulsecore_@PA_MAJORMINORMICRO@_la_LDFLAGS += $(X11_LIBS)
endif endif
if HAVE_DBUS
libpulsecore_@PA_MAJORMINORMICRO@_la_SOURCES += pulsecore/dbus-shared.c pulsecore/dbus-shared.h
libpulsecore_@PA_MAJORMINORMICRO@_la_CFLAGS += $(DBUS_CFLAGS)
libpulsecore_@PA_MAJORMINORMICRO@_la_LIBADD += $(DBUS_LIBS)
endif
# We split the foreign code off to not be annoyed by warnings we don't care about # We split the foreign code off to not be annoyed by warnings we don't care about
noinst_LTLIBRARIES = libpulsecore-foreign.la noinst_LTLIBRARIES = libpulsecore-foreign.la
@ -902,7 +915,6 @@ libavahi_wrap_la_LIBADD = $(AM_LIBADD) $(AVAHI_CFLAGS) libpulsecore-@PA_MAJORMIN
if HAVE_DBUS if HAVE_DBUS
# Serveral module (e.g. libalsa-util.la) # Serveral module (e.g. libalsa-util.la)
modlibexec_LTLIBRARIES += \ modlibexec_LTLIBRARIES += \
libdbus-util.la \
module-console-kit.la module-console-kit.la
endif endif
@ -1322,7 +1334,7 @@ endif
if HAVE_DBUS if HAVE_DBUS
libalsa_util_la_SOURCES += modules/reserve.h modules/reserve.c modules/reserve-wrap.c modules/reserve-wrap.h libalsa_util_la_SOURCES += modules/reserve.h modules/reserve.c modules/reserve-wrap.c modules/reserve-wrap.h
libalsa_util_la_LIBADD += $(DBUS_LIBS) libdbus-util.la libalsa_util_la_LIBADD += $(DBUS_LIBS)
libalsa_util_la_CFLAGS += $(DBUS_CFLAGS) libalsa_util_la_CFLAGS += $(DBUS_CFLAGS)
endif endif
@ -1476,20 +1488,14 @@ module_jack_source_la_LDFLAGS = $(MODULE_LDFLAGS)
module_jack_source_la_LIBADD = $(AM_LIBADD) libpulsecore-@PA_MAJORMINORMICRO@.la $(JACK_LIBS) libpulsecommon-@PA_MAJORMINORMICRO@.la libpulse.la module_jack_source_la_LIBADD = $(AM_LIBADD) libpulsecore-@PA_MAJORMINORMICRO@.la $(JACK_LIBS) libpulsecommon-@PA_MAJORMINORMICRO@.la libpulse.la
module_jack_source_la_CFLAGS = $(AM_CFLAGS) $(JACK_CFLAGS) module_jack_source_la_CFLAGS = $(AM_CFLAGS) $(JACK_CFLAGS)
# HAL/D-Bus
libdbus_util_la_SOURCES = modules/dbus-util.c modules/dbus-util.h
libdbus_util_la_LDFLAGS = -avoid-version
libdbus_util_la_LIBADD = $(AM_LIBADD) $(DBUS_LIBS) libpulsecore-@PA_MAJORMINORMICRO@.la libpulsecommon-@PA_MAJORMINORMICRO@.la libpulse.la
libdbus_util_la_CFLAGS = $(AM_CFLAGS) $(DBUS_CFLAGS)
module_hal_detect_la_SOURCES = modules/module-hal-detect.c module_hal_detect_la_SOURCES = modules/module-hal-detect.c
module_hal_detect_la_LDFLAGS = $(MODULE_LDFLAGS) module_hal_detect_la_LDFLAGS = $(MODULE_LDFLAGS)
module_hal_detect_la_LIBADD = $(AM_LIBADD) $(HAL_LIBS) libpulsecore-@PA_MAJORMINORMICRO@.la libdbus-util.la libpulsecommon-@PA_MAJORMINORMICRO@.la libpulse.la module_hal_detect_la_LIBADD = $(AM_LIBADD) $(HAL_LIBS) libpulsecore-@PA_MAJORMINORMICRO@.la libpulsecommon-@PA_MAJORMINORMICRO@.la libpulse.la
module_hal_detect_la_CFLAGS = $(AM_CFLAGS) $(HAL_CFLAGS) module_hal_detect_la_CFLAGS = $(AM_CFLAGS) $(HAL_CFLAGS)
module_console_kit_la_SOURCES = modules/module-console-kit.c module_console_kit_la_SOURCES = modules/module-console-kit.c
module_console_kit_la_LDFLAGS = $(MODULE_LDFLAGS) module_console_kit_la_LDFLAGS = $(MODULE_LDFLAGS)
module_console_kit_la_LIBADD = $(AM_LIBADD) $(DBUS_LIBS) libpulsecore-@PA_MAJORMINORMICRO@.la libdbus-util.la libpulsecommon-@PA_MAJORMINORMICRO@.la libpulse.la module_console_kit_la_LIBADD = $(AM_LIBADD) $(DBUS_LIBS) libpulsecore-@PA_MAJORMINORMICRO@.la libpulsecommon-@PA_MAJORMINORMICRO@.la libpulse.la
module_console_kit_la_CFLAGS = $(AM_CFLAGS) $(DBUS_CFLAGS) module_console_kit_la_CFLAGS = $(AM_CFLAGS) $(DBUS_CFLAGS)
# GConf support # GConf support
@ -1506,7 +1512,7 @@ gconf_helper_LDFLAGS = $(AM_LDFLAGS) $(BINLDFLAGS)
# Bluetooth proximity # Bluetooth proximity
module_bluetooth_proximity_la_SOURCES = modules/bluetooth/module-bluetooth-proximity.c module_bluetooth_proximity_la_SOURCES = modules/bluetooth/module-bluetooth-proximity.c
module_bluetooth_proximity_la_LDFLAGS = $(MODULE_LDFLAGS) module_bluetooth_proximity_la_LDFLAGS = $(MODULE_LDFLAGS)
module_bluetooth_proximity_la_LIBADD = $(AM_LIBADD) $(DBUS_LIBS) libpulsecore-@PA_MAJORMINORMICRO@.la libdbus-util.la libpulsecommon-@PA_MAJORMINORMICRO@.la libpulse.la module_bluetooth_proximity_la_LIBADD = $(AM_LIBADD) $(DBUS_LIBS) libpulsecore-@PA_MAJORMINORMICRO@.la libpulsecommon-@PA_MAJORMINORMICRO@.la libpulse.la
module_bluetooth_proximity_la_CFLAGS = $(AM_CFLAGS) $(DBUS_CFLAGS) -DPA_BT_PROXIMITY_HELPER=\"$(pulselibexecdir)/proximity-helper\" module_bluetooth_proximity_la_CFLAGS = $(AM_CFLAGS) $(DBUS_CFLAGS) -DPA_BT_PROXIMITY_HELPER=\"$(pulselibexecdir)/proximity-helper\"
proximity_helper_SOURCES = modules/bluetooth/proximity-helper.c proximity_helper_SOURCES = modules/bluetooth/proximity-helper.c
@ -1517,7 +1523,7 @@ proximity_helper_LDFLAGS = $(AM_LDFLAGS) $(BINLDFLAGS)
# Bluetooth sink / source # Bluetooth sink / source
module_bluetooth_discover_la_SOURCES = modules/bluetooth/module-bluetooth-discover.c module_bluetooth_discover_la_SOURCES = modules/bluetooth/module-bluetooth-discover.c
module_bluetooth_discover_la_LDFLAGS = $(MODULE_LDFLAGS) module_bluetooth_discover_la_LDFLAGS = $(MODULE_LDFLAGS)
module_bluetooth_discover_la_LIBADD = $(AM_LIBADD) $(DBUS_LIBS) libpulsecore-@PA_MAJORMINORMICRO@.la libdbus-util.la libbluetooth-util.la libpulsecommon-@PA_MAJORMINORMICRO@.la libpulse.la module_bluetooth_discover_la_LIBADD = $(AM_LIBADD) $(DBUS_LIBS) libpulsecore-@PA_MAJORMINORMICRO@.la libbluetooth-util.la libpulsecommon-@PA_MAJORMINORMICRO@.la libpulse.la
module_bluetooth_discover_la_CFLAGS = $(AM_CFLAGS) $(DBUS_CFLAGS) module_bluetooth_discover_la_CFLAGS = $(AM_CFLAGS) $(DBUS_CFLAGS)
libbluetooth_sbc_la_SOURCES = modules/bluetooth/sbc.c modules/bluetooth/sbc.h modules/bluetooth/sbc_tables.h modules/bluetooth/sbc_math.h modules/bluetooth/sbc_primitives.h modules/bluetooth/sbc_primitives.c modules/bluetooth/sbc_primitives_mmx.h modules/bluetooth/sbc_primitives_neon.h modules/bluetooth/sbc_primitives_mmx.c modules/bluetooth/sbc_primitives_neon.c libbluetooth_sbc_la_SOURCES = modules/bluetooth/sbc.c modules/bluetooth/sbc.h modules/bluetooth/sbc_tables.h modules/bluetooth/sbc_math.h modules/bluetooth/sbc_primitives.h modules/bluetooth/sbc_primitives.c modules/bluetooth/sbc_primitives_mmx.h modules/bluetooth/sbc_primitives_neon.h modules/bluetooth/sbc_primitives_mmx.c modules/bluetooth/sbc_primitives_neon.c
@ -1534,12 +1540,12 @@ BLUETOOTH_IPC_FILES = $(subst modules/bluetooth/,,$(libbluetooth_ipc_la_SOURCES)
libbluetooth_util_la_SOURCES = modules/bluetooth/bluetooth-util.c modules/bluetooth/bluetooth-util.h libbluetooth_util_la_SOURCES = modules/bluetooth/bluetooth-util.c modules/bluetooth/bluetooth-util.h
libbluetooth_util_la_LDFLAGS = -avoid-version libbluetooth_util_la_LDFLAGS = -avoid-version
libbluetooth_util_la_LIBADD = $(AM_LIBADD) $(DBUS_LIBS) libpulsecore-@PA_MAJORMINORMICRO@.la libpulsecommon-@PA_MAJORMINORMICRO@.la libpulse.la libdbus-util.la libbluetooth_util_la_LIBADD = $(AM_LIBADD) $(DBUS_LIBS) libpulsecore-@PA_MAJORMINORMICRO@.la libpulsecommon-@PA_MAJORMINORMICRO@.la libpulse.la
libbluetooth_util_la_CFLAGS = $(AM_CFLAGS) $(DBUS_CFLAGS) libbluetooth_util_la_CFLAGS = $(AM_CFLAGS) $(DBUS_CFLAGS)
module_bluetooth_device_la_SOURCES = modules/bluetooth/module-bluetooth-device.c modules/bluetooth/rtp.h module_bluetooth_device_la_SOURCES = modules/bluetooth/module-bluetooth-device.c modules/bluetooth/rtp.h
module_bluetooth_device_la_LDFLAGS = $(MODULE_LDFLAGS) module_bluetooth_device_la_LDFLAGS = $(MODULE_LDFLAGS)
module_bluetooth_device_la_LIBADD = $(AM_LIBADD) $(DBUS_LIBS) libpulsecore-@PA_MAJORMINORMICRO@.la libdbus-util.la libbluetooth-util.la libbluetooth-ipc.la libbluetooth-sbc.la libpulsecommon-@PA_MAJORMINORMICRO@.la libpulse.la module_bluetooth_device_la_LIBADD = $(AM_LIBADD) $(DBUS_LIBS) libpulsecore-@PA_MAJORMINORMICRO@.la libbluetooth-util.la libbluetooth-ipc.la libbluetooth-sbc.la libpulsecommon-@PA_MAJORMINORMICRO@.la libpulse.la
module_bluetooth_device_la_CFLAGS = $(AM_CFLAGS) $(DBUS_CFLAGS) module_bluetooth_device_la_CFLAGS = $(AM_CFLAGS) $(DBUS_CFLAGS)
# Apple Airtunes/RAOP # Apple Airtunes/RAOP

View file

@ -25,7 +25,7 @@
#include <pulsecore/core-util.h> #include <pulsecore/core-util.h>
#include <pulsecore/shared.h> #include <pulsecore/shared.h>
#include <modules/dbus-util.h> #include <pulsecore/dbus-shared.h>
#include "bluetooth-util.h" #include "bluetooth-util.h"

View file

@ -46,8 +46,7 @@
#include <pulsecore/time-smoother.h> #include <pulsecore/time-smoother.h>
#include <pulsecore/rtclock.h> #include <pulsecore/rtclock.h>
#include <pulsecore/namereg.h> #include <pulsecore/namereg.h>
#include <pulsecore/dbus-shared.h>
#include <modules/dbus-util.h>
#include "module-bluetooth-device-symdef.h" #include "module-bluetooth-device-symdef.h"
#include "ipc.h" #include "ipc.h"

View file

@ -34,7 +34,7 @@
#include <pulsecore/macro.h> #include <pulsecore/macro.h>
#include <pulsecore/llist.h> #include <pulsecore/llist.h>
#include <pulsecore/core-util.h> #include <pulsecore/core-util.h>
#include <modules/dbus-util.h> #include <pulsecore/dbus-shared.h>
#include "module-bluetooth-discover-symdef.h" #include "module-bluetooth-discover-symdef.h"
#include "bluetooth-util.h" #include "bluetooth-util.h"

View file

@ -42,8 +42,8 @@
#include <pulsecore/core-util.h> #include <pulsecore/core-util.h>
#include <pulsecore/core-error.h> #include <pulsecore/core-error.h>
#include <pulsecore/start-child.h> #include <pulsecore/start-child.h>
#include <pulsecore/dbus-shared.h>
#include "../dbus-util.h"
#include "module-bluetooth-proximity-symdef.h" #include "module-bluetooth-proximity-symdef.h"
PA_MODULE_AUTHOR("Lennart Poettering"); PA_MODULE_AUTHOR("Lennart Poettering");

View file

@ -24,10 +24,10 @@
#endif #endif
#include <pulsecore/log.h> #include <pulsecore/log.h>
#include <pulsecore/dbus-shared.h>
#include <hal/libhal.h> #include <hal/libhal.h>
#include "dbus-util.h"
#include "hal-util.h" #include "hal-util.h"
int pa_hal_get_info(pa_core *core, pa_proplist *p, int card) { int pa_hal_get_info(pa_core *core, pa_proplist *p, int card) {

View file

@ -44,8 +44,8 @@
#include <pulsecore/namereg.h> #include <pulsecore/namereg.h>
#include <pulsecore/core-scache.h> #include <pulsecore/core-scache.h>
#include <pulsecore/modargs.h> #include <pulsecore/modargs.h>
#include <pulsecore/dbus-shared.h>
#include "dbus-util.h"
#include "module-console-kit-symdef.h" #include "module-console-kit-symdef.h"
PA_MODULE_AUTHOR("Lennart Poettering"); PA_MODULE_AUTHOR("Lennart Poettering");

View file

@ -45,10 +45,10 @@
#include <pulsecore/namereg.h> #include <pulsecore/namereg.h>
#include <pulsecore/core-scache.h> #include <pulsecore/core-scache.h>
#include <pulsecore/modargs.h> #include <pulsecore/modargs.h>
#include <pulsecore/dbus-shared.h>
#include <hal/libhal.h> #include <hal/libhal.h>
#include "dbus-util.h"
#include "module-hal-detect-symdef.h" #include "module-hal-detect-symdef.h"
PA_MODULE_AUTHOR("Shahms King"); PA_MODULE_AUTHOR("Shahms King");

View file

@ -29,8 +29,7 @@
#include <pulsecore/core-error.h> #include <pulsecore/core-error.h>
#include <pulsecore/core-util.h> #include <pulsecore/core-util.h>
#include <pulsecore/shared.h> #include <pulsecore/shared.h>
#include <pulsecore/dbus-shared.h>
#include <modules/dbus-util.h>
#include "reserve.h" #include "reserve.h"
#include "reserve-wrap.h" #include "reserve-wrap.h"

111
src/pulsecore/dbus-shared.c Normal file
View file

@ -0,0 +1,111 @@
/***
This file is part of PulseAudio.
Copyright 2004-2006, 2009 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 <stdarg.h>
#include <pulse/xmalloc.h>
#include <pulse/timeval.h>
#include <pulsecore/log.h>
#include <pulsecore/shared.h>
#include "dbus-shared.h"
struct pa_dbus_connection {
PA_REFCNT_DECLARE;
pa_dbus_wrap_connection *connection;
pa_core *core;
const char *property_name;
};
static pa_dbus_connection* pa_dbus_connection_new(pa_core *c, pa_dbus_wrap_connection *conn, const char *name) {
pa_dbus_connection *pconn;
pconn = pa_xnew(pa_dbus_connection, 1);
PA_REFCNT_INIT(pconn);
pconn->core = c;
pconn->property_name = name;
pconn->connection = conn;
pa_shared_set(c, name, pconn);
return pconn;
}
pa_dbus_connection* pa_dbus_bus_get(pa_core *c, DBusBusType type, DBusError *error) {
static const char *const prop_name[] = {
[DBUS_BUS_SESSION] = "dbus-connection-session",
[DBUS_BUS_SYSTEM] = "dbus-connection-system",
[DBUS_BUS_STARTER] = "dbus-connection-starter"
};
pa_dbus_wrap_connection *conn;
pa_dbus_connection *pconn;
pa_assert(type == DBUS_BUS_SYSTEM || type == DBUS_BUS_SESSION || type == DBUS_BUS_STARTER);
if ((pconn = pa_shared_get(c, prop_name[type])))
return pa_dbus_connection_ref(pconn);
if (!(conn = pa_dbus_wrap_connection_new(c->mainloop, type, error)))
return NULL;
pconn = pa_dbus_connection_new(c, conn, prop_name[type]);
return pconn;
}
DBusConnection* pa_dbus_connection_get(pa_dbus_connection *c){
pa_assert(c);
pa_assert(PA_REFCNT_VALUE(c) > 0);
pa_assert(c->connection);
return pa_dbus_wrap_connection_get(c->connection);
}
void pa_dbus_connection_unref(pa_dbus_connection *c) {
pa_assert(c);
pa_assert(PA_REFCNT_VALUE(c) > 0);
if (PA_REFCNT_DEC(c) > 0)
return;
/* already disconnected, just free */
pa_shared_remove(c->core, c->property_name);
pa_xfree(c);
}
pa_dbus_connection* pa_dbus_connection_ref(pa_dbus_connection *c) {
pa_assert(c);
pa_assert(PA_REFCNT_VALUE(c) > 0);
PA_REFCNT_INC(c);
return c;
}

View file

@ -0,0 +1,42 @@
#ifndef foodbussharedhfoo
#define foodbussharedhfoo
/***
This file is part of PulseAudio.
Copyright 2004-2006, 2009 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.
***/
#include <dbus/dbus.h>
#include <pulsecore/core.h>
#include <pulsecore/dbus-util.h>
typedef struct pa_dbus_connection pa_dbus_connection;
/* return a pa_dbus_connection of the specified type for the given core,
* like dbus_bus_get(), but integrates the connection with the pa_core */
pa_dbus_connection* pa_dbus_bus_get(pa_core *c, DBusBusType type, DBusError *error);
DBusConnection* pa_dbus_connection_get(pa_dbus_connection *conn);
pa_dbus_connection* pa_dbus_connection_ref(pa_dbus_connection *conn);
void pa_dbus_connection_unref(pa_dbus_connection *conn);
#endif

View file

@ -29,16 +29,12 @@
#include <pulse/xmalloc.h> #include <pulse/xmalloc.h>
#include <pulse/timeval.h> #include <pulse/timeval.h>
#include <pulsecore/log.h> #include <pulsecore/log.h>
#include <pulsecore/shared.h>
#include "dbus-util.h" #include "dbus-util.h"
struct pa_dbus_connection { struct pa_dbus_wrap_connection {
PA_REFCNT_DECLARE; pa_mainloop_api *mainloop;
pa_core *core;
DBusConnection *connection; DBusConnection *connection;
const char *property_name;
pa_defer_event* dispatch_event; pa_defer_event* dispatch_event;
}; };
@ -53,20 +49,20 @@ static void dispatch_cb(pa_mainloop_api *ea, pa_defer_event *ev, void *userdata)
/* DBusDispatchStatusFunction callback for the pa mainloop */ /* DBusDispatchStatusFunction callback for the pa mainloop */
static void dispatch_status(DBusConnection *conn, DBusDispatchStatus status, void *userdata) { static void dispatch_status(DBusConnection *conn, DBusDispatchStatus status, void *userdata) {
pa_dbus_connection *c = userdata; pa_dbus_wrap_connection *c = userdata;
pa_assert(c); pa_assert(c);
switch(status) { switch(status) {
case DBUS_DISPATCH_COMPLETE: case DBUS_DISPATCH_COMPLETE:
c->core->mainloop->defer_enable(c->dispatch_event, 0); c->mainloop->defer_enable(c->dispatch_event, 0);
break; break;
case DBUS_DISPATCH_DATA_REMAINS: case DBUS_DISPATCH_DATA_REMAINS:
case DBUS_DISPATCH_NEED_MEMORY: case DBUS_DISPATCH_NEED_MEMORY:
default: default:
c->core->mainloop->defer_enable(c->dispatch_event, 1); c->mainloop->defer_enable(c->dispatch_event, 1);
break; break;
} }
} }
@ -135,7 +131,7 @@ static void handle_time_event(pa_mainloop_api *ea, pa_time_event* e, const struc
/* DBusAddWatchFunction callback for pa mainloop */ /* DBusAddWatchFunction callback for pa mainloop */
static dbus_bool_t add_watch(DBusWatch *watch, void *data) { static dbus_bool_t add_watch(DBusWatch *watch, void *data) {
pa_core *c = PA_CORE(data); pa_dbus_wrap_connection *c = data;
pa_io_event *ev; pa_io_event *ev;
pa_assert(watch); pa_assert(watch);
@ -157,7 +153,7 @@ static dbus_bool_t add_watch(DBusWatch *watch, void *data) {
/* DBusRemoveWatchFunction callback for pa mainloop */ /* DBusRemoveWatchFunction callback for pa mainloop */
static void remove_watch(DBusWatch *watch, void *data) { static void remove_watch(DBusWatch *watch, void *data) {
pa_core *c = PA_CORE(data); pa_dbus_wrap_connection *c = data;
pa_io_event *ev; pa_io_event *ev;
pa_assert(watch); pa_assert(watch);
@ -169,11 +165,11 @@ static void remove_watch(DBusWatch *watch, void *data) {
/* DBusWatchToggledFunction callback for pa mainloop */ /* DBusWatchToggledFunction callback for pa mainloop */
static void toggle_watch(DBusWatch *watch, void *data) { static void toggle_watch(DBusWatch *watch, void *data) {
pa_core *c = PA_CORE(data); pa_dbus_wrap_connection *c = data;
pa_io_event *ev; pa_io_event *ev;
pa_assert(watch); pa_assert(watch);
pa_core_assert_ref(c); pa_assert(c);
pa_assert_se(ev = dbus_watch_get_data(watch)); pa_assert_se(ev = dbus_watch_get_data(watch));
@ -183,7 +179,7 @@ static void toggle_watch(DBusWatch *watch, void *data) {
/* DBusAddTimeoutFunction callback for pa mainloop */ /* DBusAddTimeoutFunction callback for pa mainloop */
static dbus_bool_t add_timeout(DBusTimeout *timeout, void *data) { static dbus_bool_t add_timeout(DBusTimeout *timeout, void *data) {
pa_core *c = PA_CORE(data); pa_dbus_wrap_connection *c = data;
pa_time_event *ev; pa_time_event *ev;
struct timeval tv; struct timeval tv;
@ -205,7 +201,7 @@ static dbus_bool_t add_timeout(DBusTimeout *timeout, void *data) {
/* DBusRemoveTimeoutFunction callback for pa mainloop */ /* DBusRemoveTimeoutFunction callback for pa mainloop */
static void remove_timeout(DBusTimeout *timeout, void *data) { static void remove_timeout(DBusTimeout *timeout, void *data) {
pa_core *c = PA_CORE(data); pa_dbus_wrap_connection *c = data;
pa_time_event *ev; pa_time_event *ev;
pa_assert(timeout); pa_assert(timeout);
@ -217,7 +213,7 @@ static void remove_timeout(DBusTimeout *timeout, void *data) {
/* DBusTimeoutToggledFunction callback for pa mainloop */ /* DBusTimeoutToggledFunction callback for pa mainloop */
static void toggle_timeout(DBusTimeout *timeout, void *data) { static void toggle_timeout(DBusTimeout *timeout, void *data) {
pa_core *c = PA_CORE(data); pa_dbus_wrap_connection *c = data;
pa_time_event *ev; pa_time_event *ev;
pa_assert(timeout); pa_assert(timeout);
@ -237,97 +233,61 @@ static void toggle_timeout(DBusTimeout *timeout, void *data) {
} }
static void wakeup_main(void *userdata) { static void wakeup_main(void *userdata) {
pa_dbus_connection *c = userdata; pa_dbus_wrap_connection *c = userdata;
pa_assert(c); pa_assert(c);
/* this will wakeup the mainloop and dispatch events, although /* this will wakeup the mainloop and dispatch events, although
* it may not be the cleanest way of accomplishing it */ * it may not be the cleanest way of accomplishing it */
c->core->mainloop->defer_enable(c->dispatch_event, 1); c->mainloop->defer_enable(c->dispatch_event, 1);
} }
static pa_dbus_connection* pa_dbus_connection_new(pa_core* c, DBusConnection *conn, const char* name) { pa_dbus_wrap_connection* pa_dbus_wrap_connection_new(pa_mainloop_api *m, DBusBusType type, DBusError *error) {
pa_dbus_connection *pconn;
pconn = pa_xnew(pa_dbus_connection, 1);
PA_REFCNT_INIT(pconn);
pconn->core = c;
pconn->property_name = name;
pconn->connection = conn;
pconn->dispatch_event = c->mainloop->defer_new(c->mainloop, dispatch_cb, conn);
pa_shared_set(c, name, pconn);
return pconn;
}
DBusConnection* pa_dbus_connection_get(pa_dbus_connection *c){
pa_assert(c);
pa_assert(PA_REFCNT_VALUE(c) > 0);
pa_assert(c->connection);
return c->connection;
}
void pa_dbus_connection_unref(pa_dbus_connection *c) {
pa_assert(c);
pa_assert(PA_REFCNT_VALUE(c) > 0);
if (PA_REFCNT_DEC(c) > 0)
return;
if (dbus_connection_get_is_connected(c->connection)) {
dbus_connection_close(c->connection);
/* must process remaining messages, bit of a kludge to handle
* both unload and shutdown */
while (dbus_connection_read_write_dispatch(c->connection, -1));
}
/* already disconnected, just free */
pa_shared_remove(c->core, c->property_name);
c->core->mainloop->defer_free(c->dispatch_event);
dbus_connection_unref(c->connection);
pa_xfree(c);
}
pa_dbus_connection* pa_dbus_connection_ref(pa_dbus_connection *c) {
pa_assert(c);
pa_assert(PA_REFCNT_VALUE(c) > 0);
PA_REFCNT_INC(c);
return c;
}
pa_dbus_connection* pa_dbus_bus_get(pa_core *c, DBusBusType type, DBusError *error) {
static const char *const prop_name[] = {
[DBUS_BUS_SESSION] = "dbus-connection-session",
[DBUS_BUS_SYSTEM] = "dbus-connection-system",
[DBUS_BUS_STARTER] = "dbus-connection-starter"
};
DBusConnection *conn; DBusConnection *conn;
pa_dbus_connection *pconn; pa_dbus_wrap_connection *pconn = NULL;
pa_assert(type == DBUS_BUS_SYSTEM || type == DBUS_BUS_SESSION || type == DBUS_BUS_STARTER); pa_assert(type == DBUS_BUS_SYSTEM || type == DBUS_BUS_SESSION || type == DBUS_BUS_STARTER);
if ((pconn = pa_shared_get(c, prop_name[type])))
return pa_dbus_connection_ref(pconn);
if (!(conn = dbus_bus_get_private(type, error))) if (!(conn = dbus_bus_get_private(type, error)))
return NULL; return NULL;
pconn = pa_dbus_connection_new(c, conn, prop_name[type]); pconn = pa_xnew(pa_dbus_wrap_connection, 1);
pconn->mainloop = m;
pconn->connection = conn;
dbus_connection_set_exit_on_disconnect(conn, FALSE); dbus_connection_set_exit_on_disconnect(conn, FALSE);
dbus_connection_set_dispatch_status_function(conn, dispatch_status, pconn, NULL); dbus_connection_set_dispatch_status_function(conn, dispatch_status, pconn, NULL);
dbus_connection_set_watch_functions(conn, add_watch, remove_watch, toggle_watch, c, NULL); dbus_connection_set_watch_functions(conn, add_watch, remove_watch, toggle_watch, pconn, NULL);
dbus_connection_set_timeout_functions(conn, add_timeout, remove_timeout, toggle_timeout, c, NULL); dbus_connection_set_timeout_functions(conn, add_timeout, remove_timeout, toggle_timeout, pconn, NULL);
dbus_connection_set_wakeup_main_function(conn, wakeup_main, pconn, NULL); dbus_connection_set_wakeup_main_function(conn, wakeup_main, pconn, NULL);
pconn->dispatch_event = pconn->mainloop->defer_new(pconn->mainloop, dispatch_cb, conn);
return pconn; return pconn;
} }
void pa_dbus_wrap_connection_free(pa_dbus_wrap_connection* c) {
pa_assert(c);
if (dbus_connection_get_is_connected(c->connection)) {
dbus_connection_close(c->connection);
/* must process remaining messages, bit of a kludge to handle
* both unload and shutdown */
while (dbus_connection_read_write_dispatch(c->connection, -1));
}
c->mainloop->defer_free(c->dispatch_event);
dbus_connection_unref(c->connection);
pa_xfree(c);
}
DBusConnection* pa_dbus_wrap_connection_get(pa_dbus_wrap_connection *c) {
pa_assert(c);
pa_assert(c->connection);
return c->connection;
}
int pa_dbus_add_matches(DBusConnection *c, DBusError *error, ...) { int pa_dbus_add_matches(DBusConnection *c, DBusError *error, ...) {
const char *t; const char *t;
va_list ap; va_list ap;

View file

@ -24,27 +24,22 @@
#include <dbus/dbus.h> #include <dbus/dbus.h>
#include <pulsecore/core.h>
#include <pulsecore/llist.h> #include <pulsecore/llist.h>
#include <pulse/mainloop-api.h>
typedef struct pa_dbus_connection pa_dbus_connection; /* A wrap connection is not shared or refcounted, it is available in client side */
typedef struct pa_dbus_wrap_connection pa_dbus_wrap_connection;
/* return the DBusConnection of the specified type for the given core, pa_dbus_wrap_connection* pa_dbus_wrap_connection_new(pa_mainloop_api *mainloop, DBusBusType type, DBusError *error);
* like dbus_bus_get(), but integrates the connection with the pa_core */ void pa_dbus_wrap_connection_free(pa_dbus_wrap_connection* conn);
pa_dbus_connection* pa_dbus_bus_get(pa_core *c, DBusBusType type, DBusError *error);
DBusConnection* pa_dbus_connection_get(pa_dbus_connection *conn); DBusConnection* pa_dbus_wrap_connection_get(pa_dbus_wrap_connection *conn);
pa_dbus_connection* pa_dbus_connection_ref(pa_dbus_connection *conn);
void pa_dbus_connection_unref(pa_dbus_connection *conn);
int pa_dbus_add_matches(DBusConnection *c, DBusError *error, ...) PA_GCC_SENTINEL; int pa_dbus_add_matches(DBusConnection *c, DBusError *error, ...) PA_GCC_SENTINEL;
void pa_dbus_remove_matches(DBusConnection *c, ...) PA_GCC_SENTINEL; void pa_dbus_remove_matches(DBusConnection *c, ...) PA_GCC_SENTINEL;
typedef struct pa_dbus_pending pa_dbus_pending; typedef struct pa_dbus_pending pa_dbus_pending;
struct userdata; /* We leave the actual definition to the caller */
struct pa_dbus_pending { struct pa_dbus_pending {
DBusConnection *connection; DBusConnection *connection;
DBusMessage *message; DBusMessage *message;