2 This file is part of PulseAudio.
4 Copyright 2004-2006, 2009 Lennart Poettering
5 Copyright 2006 Shams E. King
7 PulseAudio is free software; you can redistribute it and/or modify
8 it under the terms of the GNU Lesser General Public License as published
9 by the Free Software Foundation; either version 2.1 of the License,
10 or (at your option) any later version.
12 PulseAudio is distributed in the hope that it will be useful, but
13 WITHOUT ANY WARRANTY; without even the implied warranty of
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15 General Public License for more details.
17 You should have received a copy of the GNU Lesser General Public License
18 along with PulseAudio; if not, write to the Free Software
19 Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
29 #include <pulse/xmalloc.h>
30 #include <pulse/timeval.h>
31 #include <pulsecore/log.h>
32 #include <pulsecore/shared.h>
34 #include "dbus-shared.h"
36 struct pa_dbus_connection {
39 pa_dbus_wrap_connection *connection;
41 const char *property_name;
44 static pa_dbus_connection* dbus_connection_new(pa_core *c, pa_dbus_wrap_connection *conn, const char *name) {
45 pa_dbus_connection *pconn;
47 pconn = pa_xnew(pa_dbus_connection, 1);
48 PA_REFCNT_INIT(pconn);
50 pconn->property_name = name;
51 pconn->connection = conn;
53 pa_shared_set(c, name, pconn);
58 pa_dbus_connection* pa_dbus_bus_get(pa_core *c, DBusBusType type, DBusError *error) {
60 static const char *const prop_name[] = {
61 [DBUS_BUS_SESSION] = "dbus-connection-session",
62 [DBUS_BUS_SYSTEM] = "dbus-connection-system",
63 [DBUS_BUS_STARTER] = "dbus-connection-starter"
65 pa_dbus_wrap_connection *conn;
66 pa_dbus_connection *pconn;
68 pa_assert(type == DBUS_BUS_SYSTEM || type == DBUS_BUS_SESSION || type == DBUS_BUS_STARTER);
70 if ((pconn = pa_shared_get(c, prop_name[type])))
71 return pa_dbus_connection_ref(pconn);
73 if (!(conn = pa_dbus_wrap_connection_new(c->mainloop, TRUE, type, error)))
76 return dbus_connection_new(c, conn, prop_name[type]);
79 DBusConnection* pa_dbus_connection_get(pa_dbus_connection *c){
81 pa_assert(PA_REFCNT_VALUE(c) > 0);
82 pa_assert(c->connection);
84 return pa_dbus_wrap_connection_get(c->connection);
87 void pa_dbus_connection_unref(pa_dbus_connection *c) {
89 pa_assert(PA_REFCNT_VALUE(c) > 0);
91 if (PA_REFCNT_DEC(c) > 0)
94 pa_dbus_wrap_connection_free(c->connection);
96 pa_shared_remove(c->core, c->property_name);
100 pa_dbus_connection* pa_dbus_connection_ref(pa_dbus_connection *c) {
102 pa_assert(PA_REFCNT_VALUE(c) > 0);