Branch data Line data Source code
1 : : /***
2 : : This file is part of PulseAudio.
3 : :
4 : : Copyright 2004-2006, 2009 Lennart Poettering
5 : : Copyright 2006 Shams E. King
6 : :
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.
11 : :
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.
16 : :
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
20 : : USA.
21 : : ***/
22 : :
23 : : #ifdef HAVE_CONFIG_H
24 : : #include <config.h>
25 : : #endif
26 : :
27 : : #include <pulse/xmalloc.h>
28 : :
29 : : #include <pulsecore/shared.h>
30 : :
31 : : #include "dbus-shared.h"
32 : :
33 : : struct pa_dbus_connection {
34 : : PA_REFCNT_DECLARE;
35 : :
36 : : pa_dbus_wrap_connection *connection;
37 : : pa_core *core;
38 : : const char *property_name;
39 : : };
40 : :
41 : : static pa_dbus_connection* dbus_connection_new(pa_core *c, pa_dbus_wrap_connection *conn, const char *name) {
42 : : pa_dbus_connection *pconn;
43 : :
44 : 0 : pconn = pa_xnew(pa_dbus_connection, 1);
45 : 0 : PA_REFCNT_INIT(pconn);
46 : 0 : pconn->core = c;
47 : 0 : pconn->property_name = name;
48 : 0 : pconn->connection = conn;
49 : :
50 : 0 : pa_shared_set(c, name, pconn);
51 : :
52 : : return pconn;
53 : : }
54 : :
55 : 0 : pa_dbus_connection* pa_dbus_bus_get(pa_core *c, DBusBusType type, DBusError *error) {
56 : :
57 : : static const char *const prop_name[] = {
58 : : [DBUS_BUS_SESSION] = "dbus-connection-session",
59 : : [DBUS_BUS_SYSTEM] = "dbus-connection-system",
60 : : [DBUS_BUS_STARTER] = "dbus-connection-starter"
61 : : };
62 : : pa_dbus_wrap_connection *conn;
63 : : pa_dbus_connection *pconn;
64 : :
65 [ # # ]: 0 : pa_assert(type == DBUS_BUS_SYSTEM || type == DBUS_BUS_SESSION || type == DBUS_BUS_STARTER);
66 : :
67 [ # # ]: 0 : if ((pconn = pa_shared_get(c, prop_name[type])))
68 : 0 : return pa_dbus_connection_ref(pconn);
69 : :
70 [ # # ]: 0 : if (!(conn = pa_dbus_wrap_connection_new(c->mainloop, TRUE, type, error)))
71 : : return NULL;
72 : :
73 : 0 : return dbus_connection_new(c, conn, prop_name[type]);
74 : : }
75 : :
76 : 0 : DBusConnection* pa_dbus_connection_get(pa_dbus_connection *c){
77 [ # # ]: 0 : pa_assert(c);
78 [ # # ]: 0 : pa_assert(PA_REFCNT_VALUE(c) > 0);
79 [ # # ]: 0 : pa_assert(c->connection);
80 : :
81 : 0 : return pa_dbus_wrap_connection_get(c->connection);
82 : : }
83 : :
84 : 0 : void pa_dbus_connection_unref(pa_dbus_connection *c) {
85 [ # # ]: 0 : pa_assert(c);
86 [ # # ]: 0 : pa_assert(PA_REFCNT_VALUE(c) > 0);
87 : :
88 [ # # ]: 0 : if (PA_REFCNT_DEC(c) > 0)
89 : 0 : return;
90 : :
91 : 0 : pa_dbus_wrap_connection_free(c->connection);
92 : :
93 : 0 : pa_shared_remove(c->core, c->property_name);
94 : 0 : pa_xfree(c);
95 : : }
96 : :
97 : 0 : pa_dbus_connection* pa_dbus_connection_ref(pa_dbus_connection *c) {
98 [ # # ]: 0 : pa_assert(c);
99 [ # # ]: 0 : pa_assert(PA_REFCNT_VALUE(c) > 0);
100 : :
101 : 0 : PA_REFCNT_INC(c);
102 : :
103 : 0 : return c;
104 : : }
|