2 This file is part of PulseAudio.
4 Copyright 2009 Tanu Kaskinen
6 PulseAudio is free software; you can redistribute it and/or modify
7 it under the terms of the GNU Lesser General Public License as published
8 by the Free Software Foundation; either version 2.1 of the License,
9 or (at your option) any later version.
11 PulseAudio is distributed in the hope that it will be useful, but
12 WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 General Public License for more details.
16 You should have received a copy of the GNU Lesser General Public License
17 along with PulseAudio; if not, write to the Free Software
18 Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
28 #include <dbus/dbus.h>
30 #include <pulse/utf8.h>
31 #include <pulse/xmalloc.h>
33 #include <pulsecore/core-util.h>
34 #include <pulsecore/dbus-util.h>
35 #include <pulsecore/macro.h>
36 #include <pulsecore/namereg.h>
37 #include <pulsecore/protocol-dbus.h>
38 #include <pulsecore/socket-util.h>
39 #include <pulsecore/strbuf.h>
41 #include "iface-card.h"
42 #include "iface-client.h"
43 #include "iface-device.h"
44 #include "iface-memstats.h"
45 #include "iface-module.h"
46 #include "iface-sample.h"
47 #include "iface-stream.h"
49 #include "iface-core.h"
51 #define INTERFACE_REVISION 0
53 static void handle_get_interface_revision(DBusConnection
*conn
, DBusMessage
*msg
, void *userdata
);
54 static void handle_get_name(DBusConnection
*conn
, DBusMessage
*msg
, void *userdata
);
55 static void handle_get_version(DBusConnection
*conn
, DBusMessage
*msg
, void *userdata
);
56 static void handle_get_is_local(DBusConnection
*conn
, DBusMessage
*msg
, void *userdata
);
57 static void handle_get_username(DBusConnection
*conn
, DBusMessage
*msg
, void *userdata
);
58 static void handle_get_hostname(DBusConnection
*conn
, DBusMessage
*msg
, void *userdata
);
59 static void handle_get_default_channels(DBusConnection
*conn
, DBusMessage
*msg
, void *userdata
);
60 static void handle_set_default_channels(DBusConnection
*conn
, DBusMessage
*msg
, DBusMessageIter
*iter
, void *userdata
);
61 static void handle_get_default_sample_format(DBusConnection
*conn
, DBusMessage
*msg
, void *userdata
);
62 static void handle_set_default_sample_format(DBusConnection
*conn
, DBusMessage
*msg
, DBusMessageIter
*iter
, void *userdata
);
63 static void handle_get_default_sample_rate(DBusConnection
*conn
, DBusMessage
*msg
, void *userdata
);
64 static void handle_set_default_sample_rate(DBusConnection
*conn
, DBusMessage
*msg
, DBusMessageIter
*iter
, void *userdata
);
65 static void handle_get_cards(DBusConnection
*conn
, DBusMessage
*msg
, void *userdata
);
66 static void handle_get_sinks(DBusConnection
*conn
, DBusMessage
*msg
, void *userdata
);
67 static void handle_get_fallback_sink(DBusConnection
*conn
, DBusMessage
*msg
, void *userdata
);
68 static void handle_set_fallback_sink(DBusConnection
*conn
, DBusMessage
*msg
, DBusMessageIter
*iter
, void *userdata
);
69 static void handle_get_sources(DBusConnection
*conn
, DBusMessage
*msg
, void *userdata
);
70 static void handle_get_fallback_source(DBusConnection
*conn
, DBusMessage
*msg
, void *userdata
);
71 static void handle_set_fallback_source(DBusConnection
*conn
, DBusMessage
*msg
, DBusMessageIter
*iter
, void *userdata
);
72 static void handle_get_playback_streams(DBusConnection
*conn
, DBusMessage
*msg
, void *userdata
);
73 static void handle_get_record_streams(DBusConnection
*conn
, DBusMessage
*msg
, void *userdata
);
74 static void handle_get_samples(DBusConnection
*conn
, DBusMessage
*msg
, void *userdata
);
75 static void handle_get_modules(DBusConnection
*conn
, DBusMessage
*msg
, void *userdata
);
76 static void handle_get_clients(DBusConnection
*conn
, DBusMessage
*msg
, void *userdata
);
77 static void handle_get_my_client(DBusConnection
*conn
, DBusMessage
*msg
, void *userdata
);
78 static void handle_get_extensions(DBusConnection
*conn
, DBusMessage
*msg
, void *userdata
);
80 static void handle_get_all(DBusConnection
*conn
, DBusMessage
*msg
, void *userdata
);
82 static void handle_get_card_by_name(DBusConnection
*conn
, DBusMessage
*msg
, void *userdata
);
83 static void handle_get_sink_by_name(DBusConnection
*conn
, DBusMessage
*msg
, void *userdata
);
84 static void handle_get_source_by_name(DBusConnection
*conn
, DBusMessage
*msg
, void *userdata
);
85 static void handle_get_sample_by_name(DBusConnection
*conn
, DBusMessage
*msg
, void *userdata
);
86 static void handle_upload_sample(DBusConnection
*conn
, DBusMessage
*msg
, void *userdata
);
87 static void handle_load_module(DBusConnection
*conn
, DBusMessage
*msg
, void *userdata
);
88 static void handle_exit(DBusConnection
*conn
, DBusMessage
*msg
, void *userdata
);
89 static void handle_listen_for_signal(DBusConnection
*conn
, DBusMessage
*msg
, void *userdata
);
90 static void handle_stop_listening_for_signal(DBusConnection
*conn
, DBusMessage
*msg
, void *userdata
);
92 struct pa_dbusiface_core
{
94 pa_subscription
*subscription
;
96 pa_dbus_protocol
*dbus_protocol
;
99 pa_hashmap
*sinks_by_index
;
100 pa_hashmap
*sinks_by_path
;
101 pa_hashmap
*sources_by_index
;
102 pa_hashmap
*sources_by_path
;
103 pa_hashmap
*playback_streams
;
104 pa_hashmap
*record_streams
;
109 pa_sink
*fallback_sink
;
110 pa_source
*fallback_source
;
112 pa_hook_slot
*extension_registered_slot
;
113 pa_hook_slot
*extension_unregistered_slot
;
115 pa_dbusiface_memstats
*memstats
;
118 enum property_handler_index
{
119 PROPERTY_HANDLER_INTERFACE_REVISION
,
120 PROPERTY_HANDLER_NAME
,
121 PROPERTY_HANDLER_VERSION
,
122 PROPERTY_HANDLER_IS_LOCAL
,
123 PROPERTY_HANDLER_USERNAME
,
124 PROPERTY_HANDLER_HOSTNAME
,
125 PROPERTY_HANDLER_DEFAULT_CHANNELS
,
126 PROPERTY_HANDLER_DEFAULT_SAMPLE_FORMAT
,
127 PROPERTY_HANDLER_DEFAULT_SAMPLE_RATE
,
128 PROPERTY_HANDLER_CARDS
,
129 PROPERTY_HANDLER_SINKS
,
130 PROPERTY_HANDLER_FALLBACK_SINK
,
131 PROPERTY_HANDLER_SOURCES
,
132 PROPERTY_HANDLER_FALLBACK_SOURCE
,
133 PROPERTY_HANDLER_PLAYBACK_STREAMS
,
134 PROPERTY_HANDLER_RECORD_STREAMS
,
135 PROPERTY_HANDLER_SAMPLES
,
136 PROPERTY_HANDLER_MODULES
,
137 PROPERTY_HANDLER_CLIENTS
,
138 PROPERTY_HANDLER_MY_CLIENT
,
139 PROPERTY_HANDLER_EXTENSIONS
,
143 static pa_dbus_property_handler property_handlers
[PROPERTY_HANDLER_MAX
] = {
144 [PROPERTY_HANDLER_INTERFACE_REVISION
] = { .property_name
= "InterfaceRevision", .type
= "u", .get_cb
= handle_get_interface_revision
, .set_cb
= NULL
},
145 [PROPERTY_HANDLER_NAME
] = { .property_name
= "Name", .type
= "s", .get_cb
= handle_get_name
, .set_cb
= NULL
},
146 [PROPERTY_HANDLER_VERSION
] = { .property_name
= "Version", .type
= "s", .get_cb
= handle_get_version
, .set_cb
= NULL
},
147 [PROPERTY_HANDLER_IS_LOCAL
] = { .property_name
= "IsLocal", .type
= "b", .get_cb
= handle_get_is_local
, .set_cb
= NULL
},
148 [PROPERTY_HANDLER_USERNAME
] = { .property_name
= "Username", .type
= "s", .get_cb
= handle_get_username
, .set_cb
= NULL
},
149 [PROPERTY_HANDLER_HOSTNAME
] = { .property_name
= "Hostname", .type
= "s", .get_cb
= handle_get_hostname
, .set_cb
= NULL
},
150 [PROPERTY_HANDLER_DEFAULT_CHANNELS
] = { .property_name
= "DefaultChannels", .type
= "au", .get_cb
= handle_get_default_channels
, .set_cb
= handle_set_default_channels
},
151 [PROPERTY_HANDLER_DEFAULT_SAMPLE_FORMAT
] = { .property_name
= "DefaultSampleFormat", .type
= "u", .get_cb
= handle_get_default_sample_format
, .set_cb
= handle_set_default_sample_format
},
152 [PROPERTY_HANDLER_DEFAULT_SAMPLE_RATE
] = { .property_name
= "DefaultSampleRate", .type
= "u", .get_cb
= handle_get_default_sample_rate
, .set_cb
= handle_set_default_sample_rate
},
153 [PROPERTY_HANDLER_CARDS
] = { .property_name
= "Cards", .type
= "ao", .get_cb
= handle_get_cards
, .set_cb
= NULL
},
154 [PROPERTY_HANDLER_SINKS
] = { .property_name
= "Sinks", .type
= "ao", .get_cb
= handle_get_sinks
, .set_cb
= NULL
},
155 [PROPERTY_HANDLER_FALLBACK_SINK
] = { .property_name
= "FallbackSink", .type
= "o", .get_cb
= handle_get_fallback_sink
, .set_cb
= handle_set_fallback_sink
},
156 [PROPERTY_HANDLER_SOURCES
] = { .property_name
= "Sources", .type
= "ao", .get_cb
= handle_get_sources
, .set_cb
= NULL
},
157 [PROPERTY_HANDLER_FALLBACK_SOURCE
] = { .property_name
= "FallbackSource", .type
= "o", .get_cb
= handle_get_fallback_source
, .set_cb
= handle_set_fallback_source
},
158 [PROPERTY_HANDLER_PLAYBACK_STREAMS
] = { .property_name
= "PlaybackStreams", .type
= "ao", .get_cb
= handle_get_playback_streams
, .set_cb
= NULL
},
159 [PROPERTY_HANDLER_RECORD_STREAMS
] = { .property_name
= "RecordStreams", .type
= "ao", .get_cb
= handle_get_record_streams
, .set_cb
= NULL
},
160 [PROPERTY_HANDLER_SAMPLES
] = { .property_name
= "Samples", .type
= "ao", .get_cb
= handle_get_samples
, .set_cb
= NULL
},
161 [PROPERTY_HANDLER_MODULES
] = { .property_name
= "Modules", .type
= "ao", .get_cb
= handle_get_modules
, .set_cb
= NULL
},
162 [PROPERTY_HANDLER_CLIENTS
] = { .property_name
= "Clients", .type
= "ao", .get_cb
= handle_get_clients
, .set_cb
= NULL
},
163 [PROPERTY_HANDLER_MY_CLIENT
] = { .property_name
= "MyClient", .type
= "o", .get_cb
= handle_get_my_client
, .set_cb
= NULL
},
164 [PROPERTY_HANDLER_EXTENSIONS
] = { .property_name
= "Extensions", .type
= "as", .get_cb
= handle_get_extensions
, .set_cb
= NULL
}
167 enum method_handler_index
{
168 METHOD_HANDLER_GET_CARD_BY_NAME
,
169 METHOD_HANDLER_GET_SINK_BY_NAME
,
170 METHOD_HANDLER_GET_SOURCE_BY_NAME
,
171 METHOD_HANDLER_GET_SAMPLE_BY_NAME
,
172 METHOD_HANDLER_UPLOAD_SAMPLE
,
173 METHOD_HANDLER_LOAD_MODULE
,
175 METHOD_HANDLER_LISTEN_FOR_SIGNAL
,
176 METHOD_HANDLER_STOP_LISTENING_FOR_SIGNAL
,
180 static pa_dbus_arg_info get_card_by_name_args
[] = { { "name", "s", "in" }, { "card", "o", "out" } };
181 static pa_dbus_arg_info get_sink_by_name_args
[] = { { "name", "s", "in" }, { "sink", "o", "out" } };
182 static pa_dbus_arg_info get_source_by_name_args
[] = { { "name", "s", "in" }, { "source", "o", "out" } };
183 static pa_dbus_arg_info get_sample_by_name_args
[] = { { "name", "s", "in" }, { "sample", "o", "out" } };
184 static pa_dbus_arg_info upload_sample_args
[] = { { "name", "s", "in" },
185 { "sample_format", "u", "in" },
186 { "sample_rate", "u", "in" },
187 { "channels", "au", "in" },
188 { "default_volume", "au", "in" },
189 { "property_list", "a{say}", "in" },
190 { "data", "ay", "in" },
191 { "sample", "o", "out" } };
192 static pa_dbus_arg_info load_module_args
[] = { { "name", "s", "in" }, { "arguments", "a{ss}", "in" }, { "module", "o", "out" } };
193 static pa_dbus_arg_info listen_for_signal_args
[] = { { "signal", "s", "in" }, { "objects", "ao", "in" } };
194 static pa_dbus_arg_info stop_listening_for_signal_args
[] = { { "signal", "s", "in" } };
196 static pa_dbus_method_handler method_handlers
[METHOD_HANDLER_MAX
] = {
197 [METHOD_HANDLER_GET_CARD_BY_NAME
] = {
198 .method_name
= "GetCardByName",
199 .arguments
= get_card_by_name_args
,
200 .n_arguments
= sizeof(get_card_by_name_args
) / sizeof(pa_dbus_arg_info
),
201 .receive_cb
= handle_get_card_by_name
},
202 [METHOD_HANDLER_GET_SINK_BY_NAME
] = {
203 .method_name
= "GetSinkByName",
204 .arguments
= get_sink_by_name_args
,
205 .n_arguments
= sizeof(get_sink_by_name_args
) / sizeof(pa_dbus_arg_info
),
206 .receive_cb
= handle_get_sink_by_name
},
207 [METHOD_HANDLER_GET_SOURCE_BY_NAME
] = {
208 .method_name
= "GetSourceByName",
209 .arguments
= get_source_by_name_args
,
210 .n_arguments
= sizeof(get_source_by_name_args
) / sizeof(pa_dbus_arg_info
),
211 .receive_cb
= handle_get_source_by_name
},
212 [METHOD_HANDLER_GET_SAMPLE_BY_NAME
] = {
213 .method_name
= "GetSampleByName",
214 .arguments
= get_sample_by_name_args
,
215 .n_arguments
= sizeof(get_sample_by_name_args
) / sizeof(pa_dbus_arg_info
),
216 .receive_cb
= handle_get_sample_by_name
},
217 [METHOD_HANDLER_UPLOAD_SAMPLE
] = {
218 .method_name
= "UploadSample",
219 .arguments
= upload_sample_args
,
220 .n_arguments
= sizeof(upload_sample_args
) / sizeof(pa_dbus_arg_info
),
221 .receive_cb
= handle_upload_sample
},
222 [METHOD_HANDLER_LOAD_MODULE
] = {
223 .method_name
= "LoadModule",
224 .arguments
= load_module_args
,
225 .n_arguments
= sizeof(load_module_args
) / sizeof(pa_dbus_arg_info
),
226 .receive_cb
= handle_load_module
},
227 [METHOD_HANDLER_EXIT
] = {
228 .method_name
= "Exit",
231 .receive_cb
= handle_exit
},
232 [METHOD_HANDLER_LISTEN_FOR_SIGNAL
] = {
233 .method_name
= "ListenForSignal",
234 .arguments
= listen_for_signal_args
,
235 .n_arguments
= sizeof(listen_for_signal_args
) / sizeof(pa_dbus_arg_info
),
236 .receive_cb
= handle_listen_for_signal
},
237 [METHOD_HANDLER_STOP_LISTENING_FOR_SIGNAL
] = {
238 .method_name
= "StopListeningForSignal",
239 .arguments
= stop_listening_for_signal_args
,
240 .n_arguments
= sizeof(stop_listening_for_signal_args
) / sizeof(pa_dbus_arg_info
),
241 .receive_cb
= handle_stop_listening_for_signal
}
249 SIGNAL_FALLBACK_SINK_UPDATED
,
250 SIGNAL_FALLBACK_SINK_UNSET
,
252 SIGNAL_SOURCE_REMOVED
,
253 SIGNAL_FALLBACK_SOURCE_UPDATED
,
254 SIGNAL_FALLBACK_SOURCE_UNSET
,
255 SIGNAL_NEW_PLAYBACK_STREAM
,
256 SIGNAL_PLAYBACK_STREAM_REMOVED
,
257 SIGNAL_NEW_RECORD_STREAM
,
258 SIGNAL_RECORD_STREAM_REMOVED
,
260 SIGNAL_SAMPLE_REMOVED
,
262 SIGNAL_MODULE_REMOVED
,
264 SIGNAL_CLIENT_REMOVED
,
265 SIGNAL_NEW_EXTENSION
,
266 SIGNAL_EXTENSION_REMOVED
,
270 static pa_dbus_arg_info new_card_args
[] = { { "card", "o", NULL
} };
271 static pa_dbus_arg_info card_removed_args
[] = { { "card", "o", NULL
} };
272 static pa_dbus_arg_info new_sink_args
[] = { { "sink", "o", NULL
} };
273 static pa_dbus_arg_info sink_removed_args
[] = { { "sink", "o", NULL
} };
274 static pa_dbus_arg_info fallback_sink_updated_args
[] = { { "sink", "o", NULL
} };
275 static pa_dbus_arg_info new_source_args
[] = { { "source", "o", NULL
} };
276 static pa_dbus_arg_info source_removed_args
[] = { { "source", "o", NULL
} };
277 static pa_dbus_arg_info fallback_source_updated_args
[] = { { "source", "o", NULL
} };
278 static pa_dbus_arg_info new_playback_stream_args
[] = { { "playback_stream", "o", NULL
} };
279 static pa_dbus_arg_info playback_stream_removed_args
[] = { { "playback_stream", "o", NULL
} };
280 static pa_dbus_arg_info new_record_stream_args
[] = { { "record_stream", "o", NULL
} };
281 static pa_dbus_arg_info record_stream_removed_args
[] = { { "record_stream", "o", NULL
} };
282 static pa_dbus_arg_info new_sample_args
[] = { { "sample", "o", NULL
} };
283 static pa_dbus_arg_info sample_removed_args
[] = { { "sample", "o", NULL
} };
284 static pa_dbus_arg_info new_module_args
[] = { { "module", "o", NULL
} };
285 static pa_dbus_arg_info module_removed_args
[] = { { "module", "o", NULL
} };
286 static pa_dbus_arg_info new_client_args
[] = { { "client", "o", NULL
} };
287 static pa_dbus_arg_info client_removed_args
[] = { { "client", "o", NULL
} };
288 static pa_dbus_arg_info new_extension_args
[] = { { "extension", "s", NULL
} };
289 static pa_dbus_arg_info extension_removed_args
[] = { { "extension", "s", NULL
} };
291 static pa_dbus_signal_info signals
[SIGNAL_MAX
] = {
292 [SIGNAL_NEW_CARD
] = { .name
= "NewCard", .arguments
= new_card_args
, .n_arguments
= 1 },
293 [SIGNAL_CARD_REMOVED
] = { .name
= "CardRemoved", .arguments
= card_removed_args
, .n_arguments
= 1 },
294 [SIGNAL_NEW_SINK
] = { .name
= "NewSink", .arguments
= new_sink_args
, .n_arguments
= 1 },
295 [SIGNAL_SINK_REMOVED
] = { .name
= "SinkRemoved", .arguments
= sink_removed_args
, .n_arguments
= 1 },
296 [SIGNAL_FALLBACK_SINK_UPDATED
] = { .name
= "FallbackSinkUpdated", .arguments
= fallback_sink_updated_args
, .n_arguments
= 1 },
297 [SIGNAL_FALLBACK_SINK_UNSET
] = { .name
= "FallbackSinkUnset", .arguments
= NULL
, .n_arguments
= 0 },
298 [SIGNAL_NEW_SOURCE
] = { .name
= "NewSource", .arguments
= new_source_args
, .n_arguments
= 1 },
299 [SIGNAL_SOURCE_REMOVED
] = { .name
= "SourceRemoved", .arguments
= source_removed_args
, .n_arguments
= 1 },
300 [SIGNAL_FALLBACK_SOURCE_UPDATED
] = { .name
= "FallbackSourceUpdated", .arguments
= fallback_source_updated_args
, .n_arguments
= 1 },
301 [SIGNAL_FALLBACK_SOURCE_UNSET
] = { .name
= "FallbackSourceUnset", .arguments
= NULL
, .n_arguments
= 0 },
302 [SIGNAL_NEW_PLAYBACK_STREAM
] = { .name
= "NewPlaybackStream", .arguments
= new_playback_stream_args
, .n_arguments
= 1 },
303 [SIGNAL_PLAYBACK_STREAM_REMOVED
] = { .name
= "PlaybackStreamRemoved", .arguments
= playback_stream_removed_args
, .n_arguments
= 1 },
304 [SIGNAL_NEW_RECORD_STREAM
] = { .name
= "NewRecordStream", .arguments
= new_record_stream_args
, .n_arguments
= 1 },
305 [SIGNAL_RECORD_STREAM_REMOVED
] = { .name
= "RecordStreamRemoved", .arguments
= record_stream_removed_args
, .n_arguments
= 1 },
306 [SIGNAL_NEW_SAMPLE
] = { .name
= "NewSample", .arguments
= new_sample_args
, .n_arguments
= 1 },
307 [SIGNAL_SAMPLE_REMOVED
] = { .name
= "SampleRemoved", .arguments
= sample_removed_args
, .n_arguments
= 1 },
308 [SIGNAL_NEW_MODULE
] = { .name
= "NewModule", .arguments
= new_module_args
, .n_arguments
= 1 },
309 [SIGNAL_MODULE_REMOVED
] = { .name
= "ModuleRemoved", .arguments
= module_removed_args
, .n_arguments
= 1 },
310 [SIGNAL_NEW_CLIENT
] = { .name
= "NewClient", .arguments
= new_client_args
, .n_arguments
= 1 },
311 [SIGNAL_CLIENT_REMOVED
] = { .name
= "ClientRemoved", .arguments
= client_removed_args
, .n_arguments
= 1 },
312 [SIGNAL_NEW_EXTENSION
] = { .name
= "NewExtension", .arguments
= new_extension_args
, .n_arguments
= 1 },
313 [SIGNAL_EXTENSION_REMOVED
] = { .name
= "ExtensionRemoved", .arguments
= extension_removed_args
, .n_arguments
= 1 }
316 static pa_dbus_interface_info core_interface_info
= {
317 .name
= PA_DBUS_CORE_INTERFACE
,
318 .method_handlers
= method_handlers
,
319 .n_method_handlers
= METHOD_HANDLER_MAX
,
320 .property_handlers
= property_handlers
,
321 .n_property_handlers
= PROPERTY_HANDLER_MAX
,
322 .get_all_properties_cb
= handle_get_all
,
324 .n_signals
= SIGNAL_MAX
327 static void handle_get_interface_revision(DBusConnection
*conn
, DBusMessage
*msg
, void *userdata
) {
328 dbus_uint32_t interface_revision
= INTERFACE_REVISION
;
333 pa_dbus_send_basic_variant_reply(conn
, msg
, DBUS_TYPE_UINT32
, &interface_revision
);
336 static void handle_get_name(DBusConnection
*conn
, DBusMessage
*msg
, void *userdata
) {
337 const char *server_name
= PACKAGE_NAME
;
342 pa_dbus_send_basic_variant_reply(conn
, msg
, DBUS_TYPE_STRING
, &server_name
);
345 static void handle_get_version(DBusConnection
*conn
, DBusMessage
*msg
, void *userdata
) {
346 const char *version
= PACKAGE_VERSION
;
351 pa_dbus_send_basic_variant_reply(conn
, msg
, DBUS_TYPE_STRING
, &version
);
354 static dbus_bool_t
get_is_local(DBusConnection
*conn
) {
359 if (!dbus_connection_get_socket(conn
, &conn_fd
))
362 return pa_socket_is_local(conn_fd
);
365 static void handle_get_is_local(DBusConnection
*conn
, DBusMessage
*msg
, void *userdata
) {
366 dbus_bool_t is_local
;
371 is_local
= get_is_local(conn
);
373 pa_dbus_send_basic_variant_reply(conn
, msg
, DBUS_TYPE_BOOLEAN
, &is_local
);
376 static void handle_get_username(DBusConnection
*conn
, DBusMessage
*msg
, void *userdata
) {
377 char *username
= NULL
;
382 username
= pa_get_user_name_malloc();
384 pa_dbus_send_basic_variant_reply(conn
, msg
, DBUS_TYPE_STRING
, &username
);
389 static void handle_get_hostname(DBusConnection
*conn
, DBusMessage
*msg
, void *userdata
) {
390 char *hostname
= NULL
;
395 hostname
= pa_get_host_name_malloc();
397 pa_dbus_send_basic_variant_reply(conn
, msg
, DBUS_TYPE_STRING
, &hostname
);
402 /* Caller frees the returned array. */
403 static dbus_uint32_t
*get_default_channels(pa_dbusiface_core
*c
, unsigned *n
) {
404 dbus_uint32_t
*default_channels
= NULL
;
410 *n
= c
->core
->default_channel_map
.channels
;
411 default_channels
= pa_xnew(dbus_uint32_t
, *n
);
413 for (i
= 0; i
< *n
; ++i
)
414 default_channels
[i
] = c
->core
->default_channel_map
.map
[i
];
416 return default_channels
;
419 static void handle_get_default_channels(DBusConnection
*conn
, DBusMessage
*msg
, void *userdata
) {
420 pa_dbusiface_core
*c
= userdata
;
421 dbus_uint32_t
*default_channels
= NULL
;
428 default_channels
= get_default_channels(c
, &n
);
430 pa_dbus_send_basic_array_variant_reply(conn
, msg
, DBUS_TYPE_UINT32
, default_channels
, n
);
432 pa_xfree(default_channels
);
435 static void handle_set_default_channels(DBusConnection
*conn
, DBusMessage
*msg
, DBusMessageIter
*iter
, void *userdata
) {
436 pa_dbusiface_core
*c
= userdata
;
437 DBusMessageIter array_iter
;
438 pa_channel_map new_channel_map
;
439 const dbus_uint32_t
*default_channels
;
448 pa_channel_map_init(&new_channel_map
);
450 dbus_message_iter_recurse(iter
, &array_iter
);
451 dbus_message_iter_get_fixed_array(&array_iter
, &default_channels
, &n_channels
);
453 if (n_channels
<= 0) {
454 pa_dbus_send_error(conn
, msg
, DBUS_ERROR_INVALID_ARGS
, "Empty channel array.");
458 if (n_channels
> (int) PA_CHANNELS_MAX
) {
459 pa_dbus_send_error(conn
, msg
, DBUS_ERROR_INVALID_ARGS
,
460 "Too many channels: %i. The maximum number of channels is %u.", n_channels
, PA_CHANNELS_MAX
);
464 new_channel_map
.channels
= n_channels
;
466 for (i
= 0; i
< new_channel_map
.channels
; ++i
) {
467 if (default_channels
[i
] >= PA_CHANNEL_POSITION_MAX
) {
468 pa_dbus_send_error(conn
, msg
, DBUS_ERROR_INVALID_ARGS
, "Invalid channel position: %u.", default_channels
[i
]);
472 new_channel_map
.map
[i
] = default_channels
[i
];
475 c
->core
->default_channel_map
= new_channel_map
;
476 c
->core
->default_sample_spec
.channels
= n_channels
;
478 pa_dbus_send_empty_reply(conn
, msg
);
481 static void handle_get_default_sample_format(DBusConnection
*conn
, DBusMessage
*msg
, void *userdata
) {
482 pa_dbusiface_core
*c
= userdata
;
483 dbus_uint32_t default_sample_format
;
489 default_sample_format
= c
->core
->default_sample_spec
.format
;
491 pa_dbus_send_basic_variant_reply(conn
, msg
, DBUS_TYPE_UINT32
, &default_sample_format
);
494 static void handle_set_default_sample_format(DBusConnection
*conn
, DBusMessage
*msg
, DBusMessageIter
*iter
, void *userdata
) {
495 pa_dbusiface_core
*c
= userdata
;
496 dbus_uint32_t default_sample_format
;
503 dbus_message_iter_get_basic(iter
, &default_sample_format
);
505 if (default_sample_format
>= PA_SAMPLE_MAX
) {
506 pa_dbus_send_error(conn
, msg
, DBUS_ERROR_INVALID_ARGS
, "Invalid sample format.");
510 c
->core
->default_sample_spec
.format
= default_sample_format
;
512 pa_dbus_send_empty_reply(conn
, msg
);
515 static void handle_get_default_sample_rate(DBusConnection
*conn
, DBusMessage
*msg
, void *userdata
) {
516 pa_dbusiface_core
*c
= userdata
;
517 dbus_uint32_t default_sample_rate
;
523 default_sample_rate
= c
->core
->default_sample_spec
.rate
;
525 pa_dbus_send_basic_variant_reply(conn
, msg
, DBUS_TYPE_UINT32
, &default_sample_rate
);
528 static void handle_set_default_sample_rate(DBusConnection
*conn
, DBusMessage
*msg
, DBusMessageIter
*iter
, void *userdata
) {
529 pa_dbusiface_core
*c
= userdata
;
530 dbus_uint32_t default_sample_rate
;
537 dbus_message_iter_get_basic(iter
, &default_sample_rate
);
539 if (default_sample_rate
<= 0 || default_sample_rate
> PA_RATE_MAX
) {
540 pa_dbus_send_error(conn
, msg
, DBUS_ERROR_INVALID_ARGS
, "Invalid sample rate.");
544 c
->core
->default_sample_spec
.rate
= default_sample_rate
;
546 pa_dbus_send_empty_reply(conn
, msg
);
549 /* The caller frees the array, but not the strings. */
550 static const char **get_cards(pa_dbusiface_core
*c
, unsigned *n
) {
554 pa_dbusiface_card
*card
;
559 *n
= pa_hashmap_size(c
->cards
);
564 cards
= pa_xnew(const char *, *n
);
566 PA_HASHMAP_FOREACH(card
, c
->cards
, state
)
567 cards
[i
++] = pa_dbusiface_card_get_path(card
);
572 static void handle_get_cards(DBusConnection
*conn
, DBusMessage
*msg
, void *userdata
) {
573 pa_dbusiface_core
*c
= userdata
;
581 cards
= get_cards(c
, &n
);
583 pa_dbus_send_basic_array_variant_reply(conn
, msg
, DBUS_TYPE_OBJECT_PATH
, cards
, n
);
588 /* The caller frees the array, but not the strings. */
589 static const char **get_sinks(pa_dbusiface_core
*c
, unsigned *n
) {
593 pa_dbusiface_device
*sink
;
598 *n
= pa_hashmap_size(c
->sinks_by_index
);
603 sinks
= pa_xnew(const char *, *n
);
605 PA_HASHMAP_FOREACH(sink
, c
->sinks_by_index
, state
)
606 sinks
[i
++] = pa_dbusiface_device_get_path(sink
);
611 static void handle_get_sinks(DBusConnection
*conn
, DBusMessage
*msg
, void *userdata
) {
612 pa_dbusiface_core
*c
= userdata
;
620 sinks
= get_sinks(c
, &n
);
622 pa_dbus_send_basic_array_variant_reply(conn
, msg
, DBUS_TYPE_OBJECT_PATH
, sinks
, n
);
627 static void handle_get_fallback_sink(DBusConnection
*conn
, DBusMessage
*msg
, void *userdata
) {
628 pa_dbusiface_core
*c
= userdata
;
629 pa_dbusiface_device
*fallback_sink
;
630 const char *object_path
;
636 if (!c
->fallback_sink
) {
637 pa_dbus_send_error(conn
, msg
, PA_DBUS_ERROR_NO_SUCH_PROPERTY
,
638 "There are no sinks, and therefore no fallback sink either.");
642 pa_assert_se((fallback_sink
= pa_hashmap_get(c
->sinks_by_index
, PA_UINT32_TO_PTR(c
->fallback_sink
->index
))));
643 object_path
= pa_dbusiface_device_get_path(fallback_sink
);
645 pa_dbus_send_basic_variant_reply(conn
, msg
, DBUS_TYPE_OBJECT_PATH
, &object_path
);
648 static void handle_set_fallback_sink(DBusConnection
*conn
, DBusMessage
*msg
, DBusMessageIter
*iter
, void *userdata
) {
649 pa_dbusiface_core
*c
= userdata
;
650 pa_dbusiface_device
*fallback_sink
;
651 const char *object_path
;
658 if (!c
->fallback_sink
) {
659 pa_dbus_send_error(conn
, msg
, PA_DBUS_ERROR_NO_SUCH_PROPERTY
,
660 "There are no sinks, and therefore no fallback sink either.");
664 dbus_message_iter_get_basic(iter
, &object_path
);
666 if (!(fallback_sink
= pa_hashmap_get(c
->sinks_by_path
, object_path
))) {
667 pa_dbus_send_error(conn
, msg
, PA_DBUS_ERROR_NOT_FOUND
, "%s: No such sink.", object_path
);
671 pa_namereg_set_default_sink(c
->core
, pa_dbusiface_device_get_sink(fallback_sink
));
673 pa_dbus_send_empty_reply(conn
, msg
);
676 /* The caller frees the array, but not the strings. */
677 static const char **get_sources(pa_dbusiface_core
*c
, unsigned *n
) {
678 const char **sources
;
681 pa_dbusiface_device
*source
;
686 *n
= pa_hashmap_size(c
->sources_by_index
);
691 sources
= pa_xnew(const char *, *n
);
693 PA_HASHMAP_FOREACH(source
, c
->sources_by_index
, state
)
694 sources
[i
++] = pa_dbusiface_device_get_path(source
);
699 static void handle_get_sources(DBusConnection
*conn
, DBusMessage
*msg
, void *userdata
) {
700 pa_dbusiface_core
*c
= userdata
;
701 const char **sources
;
708 sources
= get_sources(c
, &n
);
710 pa_dbus_send_basic_array_variant_reply(conn
, msg
, DBUS_TYPE_OBJECT_PATH
, sources
, n
);
715 static void handle_get_fallback_source(DBusConnection
*conn
, DBusMessage
*msg
, void *userdata
) {
716 pa_dbusiface_core
*c
= userdata
;
717 pa_dbusiface_device
*fallback_source
;
718 const char *object_path
;
724 if (!c
->fallback_source
) {
725 pa_dbus_send_error(conn
, msg
, PA_DBUS_ERROR_NO_SUCH_PROPERTY
,
726 "There are no sources, and therefore no fallback source either.");
730 pa_assert_se((fallback_source
= pa_hashmap_get(c
->sources_by_index
, PA_UINT32_TO_PTR(c
->fallback_source
->index
))));
731 object_path
= pa_dbusiface_device_get_path(fallback_source
);
733 pa_dbus_send_basic_variant_reply(conn
, msg
, DBUS_TYPE_OBJECT_PATH
, &object_path
);
736 static void handle_set_fallback_source(DBusConnection
*conn
, DBusMessage
*msg
, DBusMessageIter
*iter
, void *userdata
) {
737 pa_dbusiface_core
*c
= userdata
;
738 pa_dbusiface_device
*fallback_source
;
739 const char *object_path
;
746 if (!c
->fallback_source
) {
747 pa_dbus_send_error(conn
, msg
, PA_DBUS_ERROR_NO_SUCH_PROPERTY
,
748 "There are no sources, and therefore no fallback source either.");
752 dbus_message_iter_get_basic(iter
, &object_path
);
754 if (!(fallback_source
= pa_hashmap_get(c
->sources_by_path
, object_path
))) {
755 pa_dbus_send_error(conn
, msg
, PA_DBUS_ERROR_NOT_FOUND
, "%s: No such source.", object_path
);
759 pa_namereg_set_default_source(c
->core
, pa_dbusiface_device_get_source(fallback_source
));
761 pa_dbus_send_empty_reply(conn
, msg
);
764 /* The caller frees the array, but not the strings. */
765 static const char **get_playback_streams(pa_dbusiface_core
*c
, unsigned *n
) {
766 const char **streams
;
769 pa_dbusiface_stream
*stream
;
774 *n
= pa_hashmap_size(c
->playback_streams
);
779 streams
= pa_xnew(const char *, *n
);
781 PA_HASHMAP_FOREACH(stream
, c
->playback_streams
, state
)
782 streams
[i
++] = pa_dbusiface_stream_get_path(stream
);
787 static void handle_get_playback_streams(DBusConnection
*conn
, DBusMessage
*msg
, void *userdata
) {
788 pa_dbusiface_core
*c
= userdata
;
789 const char **playback_streams
;
796 playback_streams
= get_playback_streams(c
, &n
);
798 pa_dbus_send_basic_array_variant_reply(conn
, msg
, DBUS_TYPE_OBJECT_PATH
, playback_streams
, n
);
800 pa_xfree(playback_streams
);
803 /* The caller frees the array, but not the strings. */
804 static const char **get_record_streams(pa_dbusiface_core
*c
, unsigned *n
) {
805 const char **streams
;
808 pa_dbusiface_stream
*stream
;
813 *n
= pa_hashmap_size(c
->record_streams
);
818 streams
= pa_xnew(const char *, *n
);
820 PA_HASHMAP_FOREACH(stream
, c
->record_streams
, state
)
821 streams
[i
++] = pa_dbusiface_stream_get_path(stream
);
826 static void handle_get_record_streams(DBusConnection
*conn
, DBusMessage
*msg
, void *userdata
) {
827 pa_dbusiface_core
*c
= userdata
;
828 const char **record_streams
;
835 record_streams
= get_record_streams(c
, &n
);
837 pa_dbus_send_basic_array_variant_reply(conn
, msg
, DBUS_TYPE_OBJECT_PATH
, record_streams
, n
);
839 pa_xfree(record_streams
);
842 /* The caller frees the array, but not the strings. */
843 static const char **get_samples(pa_dbusiface_core
*c
, unsigned *n
) {
844 const char **samples
;
847 pa_dbusiface_sample
*sample
;
852 *n
= pa_hashmap_size(c
->samples
);
857 samples
= pa_xnew(const char *, *n
);
859 PA_HASHMAP_FOREACH(sample
, c
->samples
, state
)
860 samples
[i
++] = pa_dbusiface_sample_get_path(sample
);
865 static void handle_get_samples(DBusConnection
*conn
, DBusMessage
*msg
, void *userdata
) {
866 pa_dbusiface_core
*c
= userdata
;
867 const char **samples
;
874 samples
= get_samples(c
, &n
);
876 pa_dbus_send_basic_array_variant_reply(conn
, msg
, DBUS_TYPE_OBJECT_PATH
, samples
, n
);
881 /* The caller frees the array, but not the strings. */
882 static const char **get_modules(pa_dbusiface_core
*c
, unsigned *n
) {
883 const char **modules
;
886 pa_dbusiface_module
*module
;
891 *n
= pa_hashmap_size(c
->modules
);
896 modules
= pa_xnew(const char *, *n
);
898 PA_HASHMAP_FOREACH(module
, c
->modules
, state
)
899 modules
[i
++] = pa_dbusiface_module_get_path(module
);
904 static void handle_get_modules(DBusConnection
*conn
, DBusMessage
*msg
, void *userdata
) {
905 pa_dbusiface_core
*c
= userdata
;
906 const char **modules
;
913 modules
= get_modules(c
, &n
);
915 pa_dbus_send_basic_array_variant_reply(conn
, msg
, DBUS_TYPE_OBJECT_PATH
, modules
, n
);
920 /* The caller frees the array, but not the strings. */
921 static const char **get_clients(pa_dbusiface_core
*c
, unsigned *n
) {
922 const char **clients
;
925 pa_dbusiface_client
*client
;
930 *n
= pa_hashmap_size(c
->clients
);
935 clients
= pa_xnew(const char *, *n
);
937 PA_HASHMAP_FOREACH(client
, c
->clients
, state
)
938 clients
[i
++] = pa_dbusiface_client_get_path(client
);
943 static void handle_get_clients(DBusConnection
*conn
, DBusMessage
*msg
, void *userdata
) {
944 pa_dbusiface_core
*c
= userdata
;
945 const char **clients
;
952 clients
= get_clients(c
, &n
);
954 pa_dbus_send_basic_array_variant_reply(conn
, msg
, DBUS_TYPE_OBJECT_PATH
, clients
, n
);
959 static const char *get_my_client(pa_dbusiface_core
*c
, DBusConnection
*conn
) {
960 pa_client
*my_client
;
965 pa_assert_se((my_client
= pa_dbus_protocol_get_client(c
->dbus_protocol
, conn
)));
967 return pa_dbusiface_client_get_path(pa_hashmap_get(c
->clients
, PA_UINT32_TO_PTR(my_client
->index
)));
970 static void handle_get_my_client(DBusConnection
*conn
, DBusMessage
*msg
, void *userdata
) {
971 pa_dbusiface_core
*c
= userdata
;
972 const char *my_client
;
978 my_client
= get_my_client(c
, conn
);
980 pa_dbus_send_basic_variant_reply(conn
, msg
, DBUS_TYPE_OBJECT_PATH
, &my_client
);
983 static void handle_get_extensions(DBusConnection
*conn
, DBusMessage
*msg
, void *userdata
) {
984 pa_dbusiface_core
*c
= userdata
;
985 const char **extensions
;
992 extensions
= pa_dbus_protocol_get_extensions(c
->dbus_protocol
, &n
);
994 pa_dbus_send_basic_array_variant_reply(conn
, msg
, DBUS_TYPE_STRING
, extensions
, n
);
996 pa_xfree(extensions
);
999 static void handle_get_all(DBusConnection
*conn
, DBusMessage
*msg
, void *userdata
) {
1000 pa_dbusiface_core
*c
= userdata
;
1001 DBusMessage
*reply
= NULL
;
1002 DBusMessageIter msg_iter
;
1003 DBusMessageIter dict_iter
;
1004 dbus_uint32_t interface_revision
;
1005 const char *server_name
;
1006 const char *version
;
1007 dbus_bool_t is_local
;
1010 dbus_uint32_t
*default_channels
;
1011 unsigned n_default_channels
;
1012 dbus_uint32_t default_sample_format
;
1013 dbus_uint32_t default_sample_rate
;
1018 const char *fallback_sink
;
1019 const char **sources
;
1021 const char *fallback_source
;
1022 const char **playback_streams
;
1023 unsigned n_playback_streams
;
1024 const char **record_streams
;
1025 unsigned n_record_streams
;
1026 const char **samples
;
1028 const char **modules
;
1030 const char **clients
;
1032 const char *my_client
;
1033 const char **extensions
;
1034 unsigned n_extensions
;
1040 interface_revision
= INTERFACE_REVISION
;
1041 server_name
= PACKAGE_NAME
;
1042 version
= PACKAGE_VERSION
;
1043 is_local
= get_is_local(conn
);
1044 username
= pa_get_user_name_malloc();
1045 hostname
= pa_get_host_name_malloc();
1046 default_channels
= get_default_channels(c
, &n_default_channels
);
1047 default_sample_format
= c
->core
->default_sample_spec
.format
;
1048 default_sample_rate
= c
->core
->default_sample_spec
.rate
;
1049 cards
= get_cards(c
, &n_cards
);
1050 sinks
= get_sinks(c
, &n_sinks
);
1051 fallback_sink
= c
->fallback_sink
1052 ? pa_dbusiface_device_get_path(pa_hashmap_get(c
->sinks_by_index
, PA_UINT32_TO_PTR(c
->fallback_sink
->index
)))
1054 sources
= get_sources(c
, &n_sources
);
1055 fallback_source
= c
->fallback_source
1056 ? pa_dbusiface_device_get_path(pa_hashmap_get(c
->sources_by_index
,
1057 PA_UINT32_TO_PTR(c
->fallback_source
->index
)))
1059 playback_streams
= get_playback_streams(c
, &n_playback_streams
);
1060 record_streams
= get_record_streams(c
, &n_record_streams
);
1061 samples
= get_samples(c
, &n_samples
);
1062 modules
= get_modules(c
, &n_modules
);
1063 clients
= get_clients(c
, &n_clients
);
1064 my_client
= get_my_client(c
, conn
);
1065 extensions
= pa_dbus_protocol_get_extensions(c
->dbus_protocol
, &n_extensions
);
1067 pa_assert_se((reply
= dbus_message_new_method_return(msg
)));
1069 dbus_message_iter_init_append(reply
, &msg_iter
);
1070 pa_assert_se(dbus_message_iter_open_container(&msg_iter
, DBUS_TYPE_ARRAY
, "{sv}", &dict_iter
));
1072 pa_dbus_append_basic_variant_dict_entry(&dict_iter
, property_handlers
[PROPERTY_HANDLER_INTERFACE_REVISION
].property_name
, DBUS_TYPE_UINT32
, &interface_revision
);
1073 pa_dbus_append_basic_variant_dict_entry(&dict_iter
, property_handlers
[PROPERTY_HANDLER_NAME
].property_name
, DBUS_TYPE_STRING
, &server_name
);
1074 pa_dbus_append_basic_variant_dict_entry(&dict_iter
, property_handlers
[PROPERTY_HANDLER_VERSION
].property_name
, DBUS_TYPE_STRING
, &version
);
1075 pa_dbus_append_basic_variant_dict_entry(&dict_iter
, property_handlers
[PROPERTY_HANDLER_IS_LOCAL
].property_name
, DBUS_TYPE_BOOLEAN
, &is_local
);
1076 pa_dbus_append_basic_variant_dict_entry(&dict_iter
, property_handlers
[PROPERTY_HANDLER_USERNAME
].property_name
, DBUS_TYPE_STRING
, &username
);
1077 pa_dbus_append_basic_variant_dict_entry(&dict_iter
, property_handlers
[PROPERTY_HANDLER_HOSTNAME
].property_name
, DBUS_TYPE_STRING
, &hostname
);
1078 pa_dbus_append_basic_array_variant_dict_entry(&dict_iter
, property_handlers
[PROPERTY_HANDLER_DEFAULT_CHANNELS
].property_name
, DBUS_TYPE_UINT32
, default_channels
, n_default_channels
);
1079 pa_dbus_append_basic_variant_dict_entry(&dict_iter
, property_handlers
[PROPERTY_HANDLER_DEFAULT_SAMPLE_FORMAT
].property_name
, DBUS_TYPE_UINT32
, &default_sample_format
);
1080 pa_dbus_append_basic_variant_dict_entry(&dict_iter
, property_handlers
[PROPERTY_HANDLER_DEFAULT_SAMPLE_RATE
].property_name
, DBUS_TYPE_UINT32
, &default_sample_rate
);
1081 pa_dbus_append_basic_array_variant_dict_entry(&dict_iter
, property_handlers
[PROPERTY_HANDLER_CARDS
].property_name
, DBUS_TYPE_OBJECT_PATH
, cards
, n_cards
);
1082 pa_dbus_append_basic_array_variant_dict_entry(&dict_iter
, property_handlers
[PROPERTY_HANDLER_SINKS
].property_name
, DBUS_TYPE_OBJECT_PATH
, sinks
, n_sinks
);
1085 pa_dbus_append_basic_variant_dict_entry(&dict_iter
, property_handlers
[PROPERTY_HANDLER_FALLBACK_SINK
].property_name
, DBUS_TYPE_OBJECT_PATH
, &fallback_sink
);
1087 pa_dbus_append_basic_array_variant_dict_entry(&dict_iter
, property_handlers
[PROPERTY_HANDLER_SOURCES
].property_name
, DBUS_TYPE_OBJECT_PATH
, sources
, n_sources
);
1089 if (fallback_source
)
1090 pa_dbus_append_basic_variant_dict_entry(&dict_iter
, property_handlers
[PROPERTY_HANDLER_FALLBACK_SOURCE
].property_name
, DBUS_TYPE_OBJECT_PATH
, &fallback_source
);
1092 pa_dbus_append_basic_array_variant_dict_entry(&dict_iter
, property_handlers
[PROPERTY_HANDLER_PLAYBACK_STREAMS
].property_name
, DBUS_TYPE_OBJECT_PATH
, playback_streams
, n_playback_streams
);
1093 pa_dbus_append_basic_array_variant_dict_entry(&dict_iter
, property_handlers
[PROPERTY_HANDLER_RECORD_STREAMS
].property_name
, DBUS_TYPE_OBJECT_PATH
, record_streams
, n_record_streams
);
1094 pa_dbus_append_basic_array_variant_dict_entry(&dict_iter
, property_handlers
[PROPERTY_HANDLER_SAMPLES
].property_name
, DBUS_TYPE_OBJECT_PATH
, samples
, n_samples
);
1095 pa_dbus_append_basic_array_variant_dict_entry(&dict_iter
, property_handlers
[PROPERTY_HANDLER_MODULES
].property_name
, DBUS_TYPE_OBJECT_PATH
, modules
, n_modules
);
1096 pa_dbus_append_basic_array_variant_dict_entry(&dict_iter
, property_handlers
[PROPERTY_HANDLER_CLIENTS
].property_name
, DBUS_TYPE_OBJECT_PATH
, clients
, n_clients
);
1097 pa_dbus_append_basic_variant_dict_entry(&dict_iter
, property_handlers
[PROPERTY_HANDLER_MY_CLIENT
].property_name
, DBUS_TYPE_OBJECT_PATH
, &my_client
);
1098 pa_dbus_append_basic_array_variant_dict_entry(&dict_iter
, property_handlers
[PROPERTY_HANDLER_EXTENSIONS
].property_name
, DBUS_TYPE_STRING
, extensions
, n_extensions
);
1100 pa_assert_se(dbus_message_iter_close_container(&msg_iter
, &dict_iter
));
1102 pa_assert_se(dbus_connection_send(conn
, reply
, NULL
));
1104 dbus_message_unref(reply
);
1108 pa_xfree(default_channels
);
1112 pa_xfree(playback_streams
);
1113 pa_xfree(record_streams
);
1117 pa_xfree(extensions
);
1120 static void handle_get_card_by_name(DBusConnection
*conn
, DBusMessage
*msg
, void *userdata
) {
1121 pa_dbusiface_core
*c
= userdata
;
1124 pa_dbusiface_card
*dbus_card
;
1125 const char *object_path
;
1131 pa_assert_se(dbus_message_get_args(msg
, NULL
, DBUS_TYPE_STRING
, &card_name
, DBUS_TYPE_INVALID
));
1133 if (!(card
= pa_namereg_get(c
->core
, card_name
, PA_NAMEREG_CARD
))) {
1134 pa_dbus_send_error(conn
, msg
, PA_DBUS_ERROR_NOT_FOUND
, "No such card.");
1138 pa_assert_se((dbus_card
= pa_hashmap_get(c
->cards
, PA_UINT32_TO_PTR(card
->index
))));
1140 object_path
= pa_dbusiface_card_get_path(dbus_card
);
1142 pa_dbus_send_basic_value_reply(conn
, msg
, DBUS_TYPE_OBJECT_PATH
, &object_path
);
1145 static void handle_get_sink_by_name(DBusConnection
*conn
, DBusMessage
*msg
, void *userdata
) {
1146 pa_dbusiface_core
*c
= userdata
;
1149 pa_dbusiface_device
*dbus_sink
;
1150 const char *object_path
;
1156 pa_assert_se(dbus_message_get_args(msg
, NULL
, DBUS_TYPE_STRING
, &sink_name
, DBUS_TYPE_INVALID
));
1158 if (!(sink
= pa_namereg_get(c
->core
, sink_name
, PA_NAMEREG_SINK
))) {
1159 pa_dbus_send_error(conn
, msg
, PA_DBUS_ERROR_NOT_FOUND
, "%s: No such sink.", sink_name
);
1163 pa_assert_se((dbus_sink
= pa_hashmap_get(c
->sinks_by_index
, PA_UINT32_TO_PTR(sink
->index
))));
1165 object_path
= pa_dbusiface_device_get_path(dbus_sink
);
1167 pa_dbus_send_basic_value_reply(conn
, msg
, DBUS_TYPE_OBJECT_PATH
, &object_path
);
1170 static void handle_get_source_by_name(DBusConnection
*conn
, DBusMessage
*msg
, void *userdata
) {
1171 pa_dbusiface_core
*c
= userdata
;
1174 pa_dbusiface_device
*dbus_source
;
1175 const char *object_path
;
1181 pa_assert_se(dbus_message_get_args(msg
, NULL
, DBUS_TYPE_STRING
, &source_name
, DBUS_TYPE_INVALID
));
1183 if (!(source
= pa_namereg_get(c
->core
, source_name
, PA_NAMEREG_SOURCE
))) {
1184 pa_dbus_send_error(conn
, msg
, PA_DBUS_ERROR_NOT_FOUND
, "%s: No such source.", source_name
);
1188 pa_assert_se((dbus_source
= pa_hashmap_get(c
->sources_by_index
, PA_UINT32_TO_PTR(source
->index
))));
1190 object_path
= pa_dbusiface_device_get_path(dbus_source
);
1192 pa_dbus_send_basic_value_reply(conn
, msg
, DBUS_TYPE_OBJECT_PATH
, &object_path
);
1195 static void handle_get_sample_by_name(DBusConnection
*conn
, DBusMessage
*msg
, void *userdata
) {
1196 pa_dbusiface_core
*c
= userdata
;
1198 pa_scache_entry
*sample
;
1199 pa_dbusiface_sample
*dbus_sample
;
1200 const char *object_path
;
1206 pa_assert_se(dbus_message_get_args(msg
, NULL
, DBUS_TYPE_STRING
, &sample_name
, DBUS_TYPE_INVALID
));
1208 if (!(sample
= pa_namereg_get(c
->core
, sample_name
, PA_NAMEREG_SAMPLE
))) {
1209 pa_dbus_send_error(conn
, msg
, PA_DBUS_ERROR_NOT_FOUND
, "No such sample.");
1213 pa_assert_se((dbus_sample
= pa_hashmap_get(c
->samples
, PA_UINT32_TO_PTR(sample
->index
))));
1215 object_path
= pa_dbusiface_sample_get_path(dbus_sample
);
1217 pa_dbus_send_basic_value_reply(conn
, msg
, DBUS_TYPE_OBJECT_PATH
, &object_path
);
1220 static void handle_upload_sample(DBusConnection
*conn
, DBusMessage
*msg
, void *userdata
) {
1221 pa_dbusiface_core
*c
= userdata
;
1222 DBusMessageIter msg_iter
;
1223 DBusMessageIter array_iter
;
1225 dbus_uint32_t sample_format
;
1226 dbus_uint32_t sample_rate
;
1227 const dbus_uint32_t
*channels
;
1229 const dbus_uint32_t
*default_volume
;
1230 int n_volume_entries
;
1231 pa_proplist
*property_list
;
1232 const uint8_t *data
;
1239 pa_dbusiface_sample
*dbus_sample
= NULL
;
1240 pa_scache_entry
*sample
= NULL
;
1241 const char *object_path
;
1247 chunk
.memblock
= NULL
;
1249 pa_assert_se(dbus_message_iter_init(msg
, &msg_iter
));
1250 dbus_message_iter_get_basic(&msg_iter
, &name
);
1252 pa_assert_se(dbus_message_iter_next(&msg_iter
));
1253 dbus_message_iter_get_basic(&msg_iter
, &sample_format
);
1255 pa_assert_se(dbus_message_iter_next(&msg_iter
));
1256 dbus_message_iter_get_basic(&msg_iter
, &sample_rate
);
1258 pa_assert_se(dbus_message_iter_next(&msg_iter
));
1259 dbus_message_iter_recurse(&msg_iter
, &array_iter
);
1260 dbus_message_iter_get_fixed_array(&array_iter
, &channels
, &n_channels
);
1262 pa_assert_se(dbus_message_iter_next(&msg_iter
));
1263 dbus_message_iter_recurse(&msg_iter
, &array_iter
);
1264 dbus_message_iter_get_fixed_array(&array_iter
, &default_volume
, &n_volume_entries
);
1266 pa_assert_se(dbus_message_iter_next(&msg_iter
));
1267 if (!(property_list
= pa_dbus_get_proplist_arg(conn
, msg
, &msg_iter
)))
1270 dbus_message_iter_recurse(&msg_iter
, &array_iter
);
1271 dbus_message_iter_get_fixed_array(&array_iter
, &data
, &data_length
);
1273 if (sample_format
>= PA_SAMPLE_MAX
) {
1274 pa_dbus_send_error(conn
, msg
, DBUS_ERROR_INVALID_ARGS
, "Invalid sample format.");
1278 if (sample_rate
<= 0 || sample_rate
> PA_RATE_MAX
) {
1279 pa_dbus_send_error(conn
, msg
, DBUS_ERROR_INVALID_ARGS
, "Invalid sample rate.");
1283 if (n_channels
<= 0) {
1284 pa_dbus_send_error(conn
, msg
, DBUS_ERROR_INVALID_ARGS
, "Empty channel map.");
1288 if (n_channels
> (int) PA_CHANNELS_MAX
) {
1289 pa_dbus_send_error(conn
, msg
, DBUS_ERROR_INVALID_ARGS
,
1290 "Too many channels: %i. The maximum is %u.", n_channels
, PA_CHANNELS_MAX
);
1294 for (i
= 0; i
< n_channels
; ++i
) {
1295 if (channels
[i
] >= PA_CHANNEL_POSITION_MAX
) {
1296 pa_dbus_send_error(conn
, msg
, DBUS_ERROR_INVALID_ARGS
, "Invalid channel position.");
1301 if (n_volume_entries
!= 0 && n_volume_entries
!= n_channels
) {
1302 pa_dbus_send_error(conn
, msg
, DBUS_ERROR_INVALID_ARGS
,
1303 "The channels and default_volume arguments have different number of elements (%i and %i, resp).",
1304 n_channels
, n_volume_entries
);
1308 for (i
= 0; i
< n_volume_entries
; ++i
) {
1309 if (default_volume
[i
] > PA_VOLUME_MAX
) {
1310 pa_dbus_send_error(conn
, msg
, DBUS_ERROR_INVALID_ARGS
, "Invalid volume: %u.", default_volume
[i
]);
1315 if (data_length
== 0) {
1316 pa_dbus_send_error(conn
, msg
, DBUS_ERROR_INVALID_ARGS
, "Empty data.");
1320 if (data_length
> PA_SCACHE_ENTRY_SIZE_MAX
) {
1321 pa_dbus_send_error(conn
, msg
, DBUS_ERROR_INVALID_ARGS
,
1322 "Too big sample: %i bytes. The maximum sample length is %u bytes.",
1323 data_length
, PA_SCACHE_ENTRY_SIZE_MAX
);
1327 ss
.format
= sample_format
;
1328 ss
.rate
= sample_rate
;
1329 ss
.channels
= n_channels
;
1331 pa_assert(pa_sample_spec_valid(&ss
));
1333 if (!pa_frame_aligned(data_length
, &ss
)) {
1334 char buf
[PA_SAMPLE_SPEC_SNPRINT_MAX
];
1335 pa_dbus_send_error(conn
, msg
, DBUS_ERROR_INVALID_ARGS
,
1336 "The sample length (%i bytes) doesn't align with the sample format and channels (%s).",
1337 data_length
, pa_sample_spec_snprint(buf
, sizeof(buf
), &ss
));
1341 map
.channels
= n_channels
;
1342 for (i
= 0; i
< n_channels
; ++i
)
1343 map
.map
[i
] = channels
[i
];
1345 chunk
.memblock
= pa_memblock_new(c
->core
->mempool
, data_length
);
1347 chunk
.length
= data_length
;
1349 memcpy(pa_memblock_acquire(chunk
.memblock
), data
, data_length
);
1350 pa_memblock_release(chunk
.memblock
);
1352 if (pa_scache_add_item(c
->core
, name
, &ss
, &map
, &chunk
, property_list
, &idx
) < 0) {
1353 pa_dbus_send_error(conn
, msg
, DBUS_ERROR_FAILED
, "Adding the sample failed.");
1357 sample
= pa_idxset_get_by_index(c
->core
->scache
, idx
);
1359 if (n_volume_entries
> 0) {
1360 sample
->volume
.channels
= n_channels
;
1361 for (i
= 0; i
< n_volume_entries
; ++i
)
1362 sample
->volume
.values
[i
] = default_volume
[i
];
1363 sample
->volume_is_set
= TRUE
;
1365 sample
->volume_is_set
= FALSE
;
1368 dbus_sample
= pa_dbusiface_sample_new(c
, sample
);
1369 pa_hashmap_put(c
->samples
, PA_UINT32_TO_PTR(idx
), dbus_sample
);
1371 object_path
= pa_dbusiface_sample_get_path(dbus_sample
);
1373 pa_dbus_send_basic_value_reply(conn
, msg
, DBUS_TYPE_OBJECT_PATH
, &object_path
);
1377 pa_proplist_free(property_list
);
1380 pa_memblock_unref(chunk
.memblock
);
1383 static pa_bool_t
contains_space(const char *string
) {
1388 for (p
= string
; *p
; ++p
) {
1396 static void handle_load_module(DBusConnection
*conn
, DBusMessage
*msg
, void *userdata
) {
1397 pa_dbusiface_core
*c
= userdata
;
1398 DBusMessageIter msg_iter
;
1399 DBusMessageIter dict_iter
;
1400 DBusMessageIter dict_entry_iter
;
1402 const char *key
= NULL
;
1403 const char *value
= NULL
;
1404 char *escaped_value
= NULL
;
1405 pa_strbuf
*arg_buffer
= NULL
;
1406 char *arg_string
= NULL
;
1407 pa_module
*module
= NULL
;
1408 pa_dbusiface_module
*dbus_module
= NULL
;
1409 const char *object_path
= NULL
;
1415 if (c
->core
->disallow_module_loading
) {
1416 pa_dbus_send_error(conn
, msg
, DBUS_ERROR_ACCESS_DENIED
, "The server is configured to disallow module loading.");
1420 pa_assert_se(dbus_message_iter_init(msg
, &msg_iter
));
1421 dbus_message_iter_get_basic(&msg_iter
, &name
);
1423 arg_buffer
= pa_strbuf_new();
1425 pa_assert_se(dbus_message_iter_next(&msg_iter
));
1426 dbus_message_iter_recurse(&msg_iter
, &dict_iter
);
1428 while (dbus_message_iter_get_arg_type(&dict_iter
) != DBUS_TYPE_INVALID
) {
1429 if (!pa_strbuf_isempty(arg_buffer
))
1430 pa_strbuf_putc(arg_buffer
, ' ');
1432 dbus_message_iter_recurse(&dict_iter
, &dict_entry_iter
);
1434 dbus_message_iter_get_basic(&dict_entry_iter
, &key
);
1436 if (strlen(key
) <= 0 || !pa_ascii_valid(key
) || contains_space(key
)) {
1437 pa_dbus_send_error(conn
, msg
, DBUS_ERROR_INVALID_ARGS
, "Invalid module argument name: %s", key
);
1441 pa_assert_se(dbus_message_iter_next(&dict_entry_iter
));
1442 dbus_message_iter_get_basic(&dict_entry_iter
, &value
);
1444 escaped_value
= pa_escape(value
, "\"");
1445 pa_strbuf_printf(arg_buffer
, "%s=\"%s\"", key
, escaped_value
);
1446 pa_xfree(escaped_value
);
1448 dbus_message_iter_next(&dict_iter
);
1451 arg_string
= pa_strbuf_tostring(arg_buffer
);
1453 if (!(module
= pa_module_load(c
->core
, name
, arg_string
))) {
1454 pa_dbus_send_error(conn
, msg
, DBUS_ERROR_FAILED
, "Failed to load module.");
1458 dbus_module
= pa_dbusiface_module_new(module
);
1459 pa_hashmap_put(c
->modules
, PA_UINT32_TO_PTR(module
->index
), dbus_module
);
1461 object_path
= pa_dbusiface_module_get_path(dbus_module
);
1463 pa_dbus_send_basic_value_reply(conn
, msg
, DBUS_TYPE_OBJECT_PATH
, &object_path
);
1467 pa_strbuf_free(arg_buffer
);
1469 pa_xfree(arg_string
);
1472 static void handle_exit(DBusConnection
*conn
, DBusMessage
*msg
, void *userdata
) {
1473 pa_dbusiface_core
*c
= userdata
;
1479 if (c
->core
->disallow_exit
) {
1480 pa_dbus_send_error(conn
, msg
, DBUS_ERROR_ACCESS_DENIED
, "The server is configured to disallow exiting.");
1484 pa_dbus_send_empty_reply(conn
, msg
);
1486 pa_core_exit(c
->core
, FALSE
, 0);
1489 static void handle_listen_for_signal(DBusConnection
*conn
, DBusMessage
*msg
, void *userdata
) {
1490 pa_dbusiface_core
*c
= userdata
;
1491 const char *signal_str
;
1492 char **objects
= NULL
;
1499 pa_assert_se(dbus_message_get_args(msg
, NULL
,
1500 DBUS_TYPE_STRING
, &signal_str
,
1501 DBUS_TYPE_ARRAY
, DBUS_TYPE_OBJECT_PATH
, &objects
, &n_objects
,
1502 DBUS_TYPE_INVALID
));
1504 pa_dbus_protocol_add_signal_listener(c
->dbus_protocol
, conn
, *signal_str
? signal_str
: NULL
, objects
, n_objects
);
1506 pa_dbus_send_empty_reply(conn
, msg
);
1508 dbus_free_string_array(objects
);
1511 static void handle_stop_listening_for_signal(DBusConnection
*conn
, DBusMessage
*msg
, void *userdata
) {
1512 pa_dbusiface_core
*c
= userdata
;
1513 const char *signal_str
;
1519 pa_assert_se(dbus_message_get_args(msg
, NULL
, DBUS_TYPE_STRING
, &signal_str
, DBUS_TYPE_INVALID
));
1521 pa_dbus_protocol_remove_signal_listener(c
->dbus_protocol
, conn
, *signal_str
? signal_str
: NULL
);
1523 pa_dbus_send_empty_reply(conn
, msg
);
1526 static void subscription_cb(pa_core
*core
, pa_subscription_event_type_t t
, uint32_t idx
, void *userdata
) {
1527 pa_dbusiface_core
*c
= userdata
;
1528 pa_dbusiface_card
*card_iface
= NULL
;
1529 pa_dbusiface_device
*device_iface
= NULL
;
1530 pa_dbusiface_stream
*stream_iface
= NULL
;
1531 pa_dbusiface_sample
*sample_iface
= NULL
;
1532 pa_dbusiface_module
*module_iface
= NULL
;
1533 pa_dbusiface_client
*client_iface
= NULL
;
1534 DBusMessage
*signal_msg
= NULL
;
1535 const char *object_path
= NULL
;
1536 pa_sink
*new_fallback_sink
= NULL
;
1537 pa_source
*new_fallback_source
= NULL
;
1541 switch (t
& PA_SUBSCRIPTION_EVENT_FACILITY_MASK
) {
1542 case PA_SUBSCRIPTION_EVENT_SERVER
:
1543 new_fallback_sink
= pa_namereg_get_default_sink(core
);
1544 new_fallback_source
= pa_namereg_get_default_source(core
);
1546 if (c
->fallback_sink
!= new_fallback_sink
) {
1547 if (c
->fallback_sink
)
1548 pa_sink_unref(c
->fallback_sink
);
1549 c
->fallback_sink
= new_fallback_sink
? pa_sink_ref(new_fallback_sink
) : NULL
;
1551 if (new_fallback_sink
1552 && (device_iface
= pa_hashmap_get(c
->sinks_by_index
, PA_UINT32_TO_PTR(new_fallback_sink
->index
)))) {
1553 object_path
= pa_dbusiface_device_get_path(device_iface
);
1555 pa_assert_se((signal_msg
= dbus_message_new_signal(PA_DBUS_CORE_OBJECT_PATH
,
1556 PA_DBUS_CORE_INTERFACE
,
1557 signals
[SIGNAL_FALLBACK_SINK_UPDATED
].name
)));
1558 pa_assert_se(dbus_message_append_args(signal_msg
, DBUS_TYPE_OBJECT_PATH
, &object_path
, DBUS_TYPE_INVALID
));
1559 pa_dbus_protocol_send_signal(c
->dbus_protocol
, signal_msg
);
1560 dbus_message_unref(signal_msg
);
1563 } else if (!new_fallback_sink
) {
1564 pa_assert_se((signal_msg
= dbus_message_new_signal(PA_DBUS_CORE_OBJECT_PATH
,
1565 PA_DBUS_CORE_INTERFACE
,
1566 signals
[SIGNAL_FALLBACK_SINK_UNSET
].name
)));
1567 pa_dbus_protocol_send_signal(c
->dbus_protocol
, signal_msg
);
1568 dbus_message_unref(signal_msg
);
1573 if (c
->fallback_source
!= new_fallback_source
) {
1574 if (c
->fallback_source
)
1575 pa_source_unref(c
->fallback_source
);
1576 c
->fallback_source
= new_fallback_source
? pa_source_ref(new_fallback_source
) : NULL
;
1578 if (new_fallback_source
1579 && (device_iface
= pa_hashmap_get(c
->sources_by_index
, PA_UINT32_TO_PTR(new_fallback_source
->index
)))) {
1580 object_path
= pa_dbusiface_device_get_path(device_iface
);
1582 pa_assert_se((signal_msg
= dbus_message_new_signal(PA_DBUS_CORE_OBJECT_PATH
,
1583 PA_DBUS_CORE_INTERFACE
,
1584 signals
[SIGNAL_FALLBACK_SOURCE_UPDATED
].name
)));
1585 pa_assert_se(dbus_message_append_args(signal_msg
, DBUS_TYPE_OBJECT_PATH
, &object_path
, DBUS_TYPE_INVALID
));
1586 pa_dbus_protocol_send_signal(c
->dbus_protocol
, signal_msg
);
1587 dbus_message_unref(signal_msg
);
1590 } else if (!new_fallback_source
) {
1591 pa_assert_se((signal_msg
= dbus_message_new_signal(PA_DBUS_CORE_OBJECT_PATH
,
1592 PA_DBUS_CORE_INTERFACE
,
1593 signals
[SIGNAL_FALLBACK_SOURCE_UNSET
].name
)));
1594 pa_dbus_protocol_send_signal(c
->dbus_protocol
, signal_msg
);
1595 dbus_message_unref(signal_msg
);
1601 case PA_SUBSCRIPTION_EVENT_CARD
:
1602 if ((t
& PA_SUBSCRIPTION_EVENT_TYPE_MASK
) == PA_SUBSCRIPTION_EVENT_NEW
) {
1603 if (!(card_iface
= pa_hashmap_get(c
->cards
, PA_UINT32_TO_PTR(idx
)))) {
1604 pa_card
*card
= NULL
;
1606 if (!(card
= pa_idxset_get_by_index(core
->cards
, idx
)))
1607 return; /* The card was removed immediately after creation. */
1609 card_iface
= pa_dbusiface_card_new(c
, card
);
1610 pa_hashmap_put(c
->cards
, PA_UINT32_TO_PTR(idx
), card_iface
);
1613 object_path
= pa_dbusiface_card_get_path(card_iface
);
1615 pa_assert_se((signal_msg
= dbus_message_new_signal(PA_DBUS_CORE_OBJECT_PATH
,
1616 PA_DBUS_CORE_INTERFACE
,
1617 signals
[SIGNAL_NEW_CARD
].name
)));
1618 pa_assert_se(dbus_message_append_args(signal_msg
, DBUS_TYPE_OBJECT_PATH
, &object_path
, DBUS_TYPE_INVALID
));
1620 } else if ((t
& PA_SUBSCRIPTION_EVENT_TYPE_MASK
) == PA_SUBSCRIPTION_EVENT_REMOVE
) {
1621 if (!(card_iface
= pa_hashmap_remove(c
->cards
, PA_UINT32_TO_PTR(idx
))))
1624 object_path
= pa_dbusiface_card_get_path(card_iface
);
1626 pa_assert_se((signal_msg
= dbus_message_new_signal(PA_DBUS_CORE_OBJECT_PATH
,
1627 PA_DBUS_CORE_INTERFACE
,
1628 signals
[SIGNAL_CARD_REMOVED
].name
)));
1629 pa_assert_se(dbus_message_append_args(signal_msg
, DBUS_TYPE_OBJECT_PATH
, &object_path
, DBUS_TYPE_INVALID
));
1631 pa_dbusiface_card_free(card_iface
);
1635 case PA_SUBSCRIPTION_EVENT_SINK
:
1636 if ((t
& PA_SUBSCRIPTION_EVENT_TYPE_MASK
) == PA_SUBSCRIPTION_EVENT_NEW
) {
1637 pa_sink
*sink
= NULL
;
1639 if (!(sink
= pa_idxset_get_by_index(core
->sinks
, idx
)))
1640 return; /* The sink was removed immediately after creation. */
1642 if (!(device_iface
= pa_hashmap_get(c
->sinks_by_index
, PA_UINT32_TO_PTR(idx
)))) {
1643 device_iface
= pa_dbusiface_device_new_sink(c
, sink
);
1644 pa_hashmap_put(c
->sinks_by_index
, PA_UINT32_TO_PTR(idx
), device_iface
);
1645 pa_hashmap_put(c
->sinks_by_path
, pa_dbusiface_device_get_path(device_iface
), device_iface
);
1648 object_path
= pa_dbusiface_device_get_path(device_iface
);
1650 pa_assert_se((signal_msg
= dbus_message_new_signal(PA_DBUS_CORE_OBJECT_PATH
,
1651 PA_DBUS_CORE_INTERFACE
,
1652 signals
[SIGNAL_NEW_SINK
].name
)));
1653 pa_assert_se(dbus_message_append_args(signal_msg
, DBUS_TYPE_OBJECT_PATH
, &object_path
, DBUS_TYPE_INVALID
));
1655 pa_dbus_protocol_send_signal(c
->dbus_protocol
, signal_msg
);
1656 dbus_message_unref(signal_msg
);
1659 if (c
->fallback_sink
&& pa_streq(c
->fallback_sink
->name
, sink
->name
)) {
1660 /* We have got default sink change event, but at that point
1661 * the D-Bus sink object wasn't created yet. Now that the
1662 * object is created, let's send the fallback sink change
1664 pa_assert_se((signal_msg
= dbus_message_new_signal(PA_DBUS_CORE_OBJECT_PATH
,
1665 PA_DBUS_CORE_INTERFACE
,
1666 signals
[SIGNAL_FALLBACK_SINK_UPDATED
].name
)));
1667 pa_assert_se(dbus_message_append_args(signal_msg
, DBUS_TYPE_OBJECT_PATH
, &object_path
, DBUS_TYPE_INVALID
));
1669 pa_dbus_protocol_send_signal(c
->dbus_protocol
, signal_msg
);
1670 dbus_message_unref(signal_msg
);
1674 } else if ((t
& PA_SUBSCRIPTION_EVENT_TYPE_MASK
) == PA_SUBSCRIPTION_EVENT_REMOVE
) {
1675 if (!(device_iface
= pa_hashmap_remove(c
->sinks_by_index
, PA_UINT32_TO_PTR(idx
))))
1678 object_path
= pa_dbusiface_device_get_path(device_iface
);
1679 pa_assert_se(pa_hashmap_remove(c
->sinks_by_path
, object_path
));
1681 pa_assert_se((signal_msg
= dbus_message_new_signal(PA_DBUS_CORE_OBJECT_PATH
,
1682 PA_DBUS_CORE_INTERFACE
,
1683 signals
[SIGNAL_SINK_REMOVED
].name
)));
1684 pa_assert_se(dbus_message_append_args(signal_msg
, DBUS_TYPE_OBJECT_PATH
, &object_path
, DBUS_TYPE_INVALID
));
1686 pa_dbusiface_device_free(device_iface
);
1690 case PA_SUBSCRIPTION_EVENT_SOURCE
:
1691 if ((t
& PA_SUBSCRIPTION_EVENT_TYPE_MASK
) == PA_SUBSCRIPTION_EVENT_NEW
) {
1692 pa_source
*source
= pa_idxset_get_by_index(core
->sources
, idx
);
1694 if (!(source
= pa_idxset_get_by_index(core
->sources
, idx
)))
1695 return; /* The source was removed immediately after creation. */
1697 if (!(device_iface
= pa_hashmap_get(c
->sources_by_index
, PA_UINT32_TO_PTR(idx
)))) {
1698 device_iface
= pa_dbusiface_device_new_source(c
, source
);
1699 pa_hashmap_put(c
->sources_by_index
, PA_UINT32_TO_PTR(idx
), device_iface
);
1700 pa_hashmap_put(c
->sources_by_path
, pa_dbusiface_device_get_path(device_iface
), device_iface
);
1703 object_path
= pa_dbusiface_device_get_path(device_iface
);
1705 pa_assert_se((signal_msg
= dbus_message_new_signal(PA_DBUS_CORE_OBJECT_PATH
,
1706 PA_DBUS_CORE_INTERFACE
,
1707 signals
[SIGNAL_NEW_SOURCE
].name
)));
1708 pa_assert_se(dbus_message_append_args(signal_msg
, DBUS_TYPE_OBJECT_PATH
, &object_path
, DBUS_TYPE_INVALID
));
1710 pa_dbus_protocol_send_signal(c
->dbus_protocol
, signal_msg
);
1711 dbus_message_unref(signal_msg
);
1714 if (c
->fallback_source
&& pa_streq(c
->fallback_source
->name
, source
->name
)) {
1715 /* We have got default source change event, but at that
1716 * point the D-Bus source object wasn't created yet. Now
1717 * that the object is created, let's send the fallback
1718 * source change signal. */
1719 pa_assert_se((signal_msg
= dbus_message_new_signal(PA_DBUS_CORE_OBJECT_PATH
,
1720 PA_DBUS_CORE_INTERFACE
,
1721 signals
[SIGNAL_FALLBACK_SOURCE_UPDATED
].name
)));
1722 pa_assert_se(dbus_message_append_args(signal_msg
, DBUS_TYPE_OBJECT_PATH
, &object_path
, DBUS_TYPE_INVALID
));
1724 pa_dbus_protocol_send_signal(c
->dbus_protocol
, signal_msg
);
1725 dbus_message_unref(signal_msg
);
1729 } else if ((t
& PA_SUBSCRIPTION_EVENT_TYPE_MASK
) == PA_SUBSCRIPTION_EVENT_REMOVE
) {
1730 if (!(device_iface
= pa_hashmap_remove(c
->sources_by_index
, PA_UINT32_TO_PTR(idx
))))
1733 object_path
= pa_dbusiface_device_get_path(device_iface
);
1734 pa_assert_se(pa_hashmap_remove(c
->sources_by_path
, object_path
));
1736 pa_assert_se((signal_msg
= dbus_message_new_signal(PA_DBUS_CORE_OBJECT_PATH
,
1737 PA_DBUS_CORE_INTERFACE
,
1738 signals
[SIGNAL_SOURCE_REMOVED
].name
)));
1739 pa_assert_se(dbus_message_append_args(signal_msg
, DBUS_TYPE_OBJECT_PATH
, &object_path
, DBUS_TYPE_INVALID
));
1741 pa_dbusiface_device_free(device_iface
);
1745 case PA_SUBSCRIPTION_EVENT_SINK_INPUT
:
1746 if ((t
& PA_SUBSCRIPTION_EVENT_TYPE_MASK
) == PA_SUBSCRIPTION_EVENT_NEW
) {
1747 pa_sink_input
*sink_input
= NULL
;
1749 if (!(sink_input
= pa_idxset_get_by_index(core
->sink_inputs
, idx
)))
1750 return; /* The sink input was removed immediately after creation. */
1752 if (!(stream_iface
= pa_hashmap_get(c
->playback_streams
, PA_UINT32_TO_PTR(idx
)))) {
1753 stream_iface
= pa_dbusiface_stream_new_playback(c
, sink_input
);
1754 pa_hashmap_put(c
->playback_streams
, PA_UINT32_TO_PTR(idx
), stream_iface
);
1757 object_path
= pa_dbusiface_stream_get_path(stream_iface
);
1759 pa_assert_se((signal_msg
= dbus_message_new_signal(PA_DBUS_CORE_OBJECT_PATH
,
1760 PA_DBUS_CORE_INTERFACE
,
1761 signals
[SIGNAL_NEW_PLAYBACK_STREAM
].name
)));
1762 pa_assert_se(dbus_message_append_args(signal_msg
, DBUS_TYPE_OBJECT_PATH
, &object_path
, DBUS_TYPE_INVALID
));
1764 } else if ((t
& PA_SUBSCRIPTION_EVENT_TYPE_MASK
) == PA_SUBSCRIPTION_EVENT_REMOVE
) {
1765 if (!(stream_iface
= pa_hashmap_remove(c
->playback_streams
, PA_UINT32_TO_PTR(idx
))))
1768 object_path
= pa_dbusiface_stream_get_path(stream_iface
);
1770 pa_assert_se((signal_msg
= dbus_message_new_signal(PA_DBUS_CORE_OBJECT_PATH
,
1771 PA_DBUS_CORE_INTERFACE
,
1772 signals
[SIGNAL_PLAYBACK_STREAM_REMOVED
].name
)));
1773 pa_assert_se(dbus_message_append_args(signal_msg
, DBUS_TYPE_OBJECT_PATH
, &object_path
, DBUS_TYPE_INVALID
));
1775 pa_dbusiface_stream_free(stream_iface
);
1779 case PA_SUBSCRIPTION_EVENT_SOURCE_OUTPUT
:
1780 if ((t
& PA_SUBSCRIPTION_EVENT_TYPE_MASK
) == PA_SUBSCRIPTION_EVENT_NEW
) {
1781 pa_source_output
*source_output
= NULL
;
1783 if (!(source_output
= pa_idxset_get_by_index(core
->source_outputs
, idx
)))
1784 return; /* The source output was removed immediately after creation. */
1786 if (!(stream_iface
= pa_hashmap_get(c
->record_streams
, PA_UINT32_TO_PTR(idx
)))) {
1787 stream_iface
= pa_dbusiface_stream_new_record(c
, source_output
);
1788 pa_hashmap_put(c
->record_streams
, PA_UINT32_TO_PTR(idx
), stream_iface
);
1791 object_path
= pa_dbusiface_stream_get_path(stream_iface
);
1793 pa_assert_se((signal_msg
= dbus_message_new_signal(PA_DBUS_CORE_OBJECT_PATH
,
1794 PA_DBUS_CORE_INTERFACE
,
1795 signals
[SIGNAL_NEW_RECORD_STREAM
].name
)));
1796 pa_assert_se(dbus_message_append_args(signal_msg
, DBUS_TYPE_OBJECT_PATH
, &object_path
, DBUS_TYPE_INVALID
));
1798 } else if ((t
& PA_SUBSCRIPTION_EVENT_TYPE_MASK
) == PA_SUBSCRIPTION_EVENT_REMOVE
) {
1799 if (!(stream_iface
= pa_hashmap_remove(c
->record_streams
, PA_UINT32_TO_PTR(idx
))))
1802 object_path
= pa_dbusiface_stream_get_path(stream_iface
);
1804 pa_assert_se((signal_msg
= dbus_message_new_signal(PA_DBUS_CORE_OBJECT_PATH
,
1805 PA_DBUS_CORE_INTERFACE
,
1806 signals
[SIGNAL_RECORD_STREAM_REMOVED
].name
)));
1807 pa_assert_se(dbus_message_append_args(signal_msg
, DBUS_TYPE_OBJECT_PATH
, &object_path
, DBUS_TYPE_INVALID
));
1809 pa_dbusiface_stream_free(stream_iface
);
1813 case PA_SUBSCRIPTION_EVENT_SAMPLE_CACHE
:
1814 if ((t
& PA_SUBSCRIPTION_EVENT_TYPE_MASK
) == PA_SUBSCRIPTION_EVENT_NEW
) {
1815 pa_scache_entry
*sample
= NULL
;
1817 if (!(sample
= pa_idxset_get_by_index(core
->scache
, idx
)))
1818 return; /* The sample was removed immediately after creation. */
1820 if (!(sample_iface
= pa_hashmap_get(c
->samples
, PA_UINT32_TO_PTR(idx
)))) {
1821 sample_iface
= pa_dbusiface_sample_new(c
, sample
);
1822 pa_hashmap_put(c
->samples
, PA_UINT32_TO_PTR(idx
), sample_iface
);
1825 object_path
= pa_dbusiface_sample_get_path(sample_iface
);
1827 pa_assert_se((signal_msg
= dbus_message_new_signal(PA_DBUS_CORE_OBJECT_PATH
,
1828 PA_DBUS_CORE_INTERFACE
,
1829 signals
[SIGNAL_NEW_SAMPLE
].name
)));
1830 pa_assert_se(dbus_message_append_args(signal_msg
, DBUS_TYPE_OBJECT_PATH
, &object_path
, DBUS_TYPE_INVALID
));
1832 } else if ((t
& PA_SUBSCRIPTION_EVENT_TYPE_MASK
) == PA_SUBSCRIPTION_EVENT_REMOVE
) {
1833 if (!(sample_iface
= pa_hashmap_remove(c
->samples
, PA_UINT32_TO_PTR(idx
))))
1836 object_path
= pa_dbusiface_sample_get_path(sample_iface
);
1838 pa_assert_se((signal_msg
= dbus_message_new_signal(PA_DBUS_CORE_OBJECT_PATH
,
1839 PA_DBUS_CORE_INTERFACE
,
1840 signals
[SIGNAL_SAMPLE_REMOVED
].name
)));
1841 pa_assert_se(dbus_message_append_args(signal_msg
, DBUS_TYPE_OBJECT_PATH
, &object_path
, DBUS_TYPE_INVALID
));
1843 pa_dbusiface_sample_free(sample_iface
);
1847 case PA_SUBSCRIPTION_EVENT_MODULE
:
1848 if ((t
& PA_SUBSCRIPTION_EVENT_TYPE_MASK
) == PA_SUBSCRIPTION_EVENT_NEW
) {
1849 pa_module
*module
= NULL
;
1851 if (!(module
= pa_idxset_get_by_index(core
->modules
, idx
)))
1852 return; /* The module was removed immediately after creation. */
1854 if (!(module_iface
= pa_hashmap_get(c
->modules
, PA_UINT32_TO_PTR(idx
)))) {
1855 module_iface
= pa_dbusiface_module_new(module
);
1856 pa_hashmap_put(c
->modules
, PA_UINT32_TO_PTR(idx
), module_iface
);
1859 object_path
= pa_dbusiface_module_get_path(module_iface
);
1861 pa_assert_se((signal_msg
= dbus_message_new_signal(PA_DBUS_CORE_OBJECT_PATH
,
1862 PA_DBUS_CORE_INTERFACE
,
1863 signals
[SIGNAL_NEW_MODULE
].name
)));
1864 pa_assert_se(dbus_message_append_args(signal_msg
, DBUS_TYPE_OBJECT_PATH
, &object_path
, DBUS_TYPE_INVALID
));
1866 } else if ((t
& PA_SUBSCRIPTION_EVENT_TYPE_MASK
) == PA_SUBSCRIPTION_EVENT_REMOVE
) {
1867 if (!(module_iface
= pa_hashmap_remove(c
->modules
, PA_UINT32_TO_PTR(idx
))))
1870 object_path
= pa_dbusiface_module_get_path(module_iface
);
1872 pa_assert_se((signal_msg
= dbus_message_new_signal(PA_DBUS_CORE_OBJECT_PATH
,
1873 PA_DBUS_CORE_INTERFACE
,
1874 signals
[SIGNAL_MODULE_REMOVED
].name
)));
1875 pa_assert_se(dbus_message_append_args(signal_msg
, DBUS_TYPE_OBJECT_PATH
, &object_path
, DBUS_TYPE_INVALID
));
1877 pa_dbusiface_module_free(module_iface
);
1881 case PA_SUBSCRIPTION_EVENT_CLIENT
:
1882 if ((t
& PA_SUBSCRIPTION_EVENT_TYPE_MASK
) == PA_SUBSCRIPTION_EVENT_NEW
) {
1883 pa_client
*client
= NULL
;
1885 if (!(client
= pa_idxset_get_by_index(core
->clients
, idx
)))
1886 return; /* The client was removed immediately after creation. */
1888 if (!(client_iface
= pa_hashmap_get(c
->clients
, PA_UINT32_TO_PTR(idx
)))) {
1889 client_iface
= pa_dbusiface_client_new(c
, client
);
1890 pa_hashmap_put(c
->clients
, PA_UINT32_TO_PTR(idx
), client_iface
);
1893 object_path
= pa_dbusiface_client_get_path(client_iface
);
1895 pa_assert_se((signal_msg
= dbus_message_new_signal(PA_DBUS_CORE_OBJECT_PATH
,
1896 PA_DBUS_CORE_INTERFACE
,
1897 signals
[SIGNAL_NEW_CLIENT
].name
)));
1898 pa_assert_se(dbus_message_append_args(signal_msg
, DBUS_TYPE_OBJECT_PATH
, &object_path
, DBUS_TYPE_INVALID
));
1900 } else if ((t
& PA_SUBSCRIPTION_EVENT_TYPE_MASK
) == PA_SUBSCRIPTION_EVENT_REMOVE
) {
1901 if (!(client_iface
= pa_hashmap_remove(c
->clients
, PA_UINT32_TO_PTR(idx
))))
1904 object_path
= pa_dbusiface_client_get_path(client_iface
);
1906 pa_assert_se((signal_msg
= dbus_message_new_signal(PA_DBUS_CORE_OBJECT_PATH
,
1907 PA_DBUS_CORE_INTERFACE
,
1908 signals
[SIGNAL_CLIENT_REMOVED
].name
)));
1909 pa_assert_se(dbus_message_append_args(signal_msg
, DBUS_TYPE_OBJECT_PATH
, &object_path
, DBUS_TYPE_INVALID
));
1911 pa_dbusiface_client_free(client_iface
);
1917 pa_dbus_protocol_send_signal(c
->dbus_protocol
, signal_msg
);
1918 dbus_message_unref(signal_msg
);
1922 static pa_hook_result_t
extension_registered_cb(void *hook_data
, void *call_data
, void *slot_data
) {
1923 pa_dbusiface_core
*c
= slot_data
;
1924 const char *ext_name
= call_data
;
1925 DBusMessage
*signal_msg
= NULL
;
1928 pa_assert(ext_name
);
1930 pa_assert_se((signal_msg
= dbus_message_new_signal(PA_DBUS_CORE_OBJECT_PATH
,
1931 PA_DBUS_CORE_INTERFACE
,
1932 signals
[SIGNAL_NEW_EXTENSION
].name
)));
1933 pa_assert_se(dbus_message_append_args(signal_msg
, DBUS_TYPE_STRING
, &ext_name
, DBUS_TYPE_INVALID
));
1935 pa_dbus_protocol_send_signal(c
->dbus_protocol
, signal_msg
);
1936 dbus_message_unref(signal_msg
);
1941 static pa_hook_result_t
extension_unregistered_cb(void *hook_data
, void *call_data
, void *slot_data
) {
1942 pa_dbusiface_core
*c
= slot_data
;
1943 const char *ext_name
= call_data
;
1944 DBusMessage
*signal_msg
= NULL
;
1947 pa_assert(ext_name
);
1949 pa_assert_se((signal_msg
= dbus_message_new_signal(PA_DBUS_CORE_OBJECT_PATH
,
1950 PA_DBUS_CORE_INTERFACE
,
1951 signals
[SIGNAL_EXTENSION_REMOVED
].name
)));
1952 pa_assert_se(dbus_message_append_args(signal_msg
, DBUS_TYPE_STRING
, &ext_name
, DBUS_TYPE_INVALID
));
1954 pa_dbus_protocol_send_signal(c
->dbus_protocol
, signal_msg
);
1955 dbus_message_unref(signal_msg
);
1960 pa_dbusiface_core
*pa_dbusiface_core_new(pa_core
*core
) {
1961 pa_dbusiface_core
*c
;
1965 pa_dbusiface_device
*device
;
1966 pa_sink_input
*sink_input
;
1967 pa_source_output
*source_output
;
1968 pa_scache_entry
*sample
;
1975 c
= pa_xnew(pa_dbusiface_core
, 1);
1976 c
->core
= pa_core_ref(core
);
1977 c
->subscription
= pa_subscription_new(core
, PA_SUBSCRIPTION_MASK_ALL
, subscription_cb
, c
);
1978 c
->dbus_protocol
= pa_dbus_protocol_get(core
);
1979 c
->cards
= pa_hashmap_new(pa_idxset_trivial_hash_func
, pa_idxset_trivial_compare_func
);
1980 c
->sinks_by_index
= pa_hashmap_new(pa_idxset_trivial_hash_func
, pa_idxset_trivial_compare_func
);
1981 c
->sinks_by_path
= pa_hashmap_new(pa_idxset_string_hash_func
, pa_idxset_string_compare_func
);
1982 c
->sources_by_index
= pa_hashmap_new(pa_idxset_trivial_hash_func
, pa_idxset_trivial_compare_func
);
1983 c
->sources_by_path
= pa_hashmap_new(pa_idxset_string_hash_func
, pa_idxset_string_compare_func
);
1984 c
->playback_streams
= pa_hashmap_new(pa_idxset_trivial_hash_func
, pa_idxset_trivial_compare_func
);
1985 c
->record_streams
= pa_hashmap_new(pa_idxset_trivial_hash_func
, pa_idxset_trivial_compare_func
);
1986 c
->samples
= pa_hashmap_new(pa_idxset_trivial_hash_func
, pa_idxset_trivial_compare_func
);
1987 c
->modules
= pa_hashmap_new(pa_idxset_trivial_hash_func
, pa_idxset_trivial_compare_func
);
1988 c
->clients
= pa_hashmap_new(pa_idxset_trivial_hash_func
, pa_idxset_trivial_compare_func
);
1989 c
->fallback_sink
= pa_namereg_get_default_sink(core
);
1990 c
->fallback_source
= pa_namereg_get_default_source(core
);
1991 c
->extension_registered_slot
= pa_dbus_protocol_hook_connect(c
->dbus_protocol
,
1992 PA_DBUS_PROTOCOL_HOOK_EXTENSION_REGISTERED
,
1994 extension_registered_cb
,
1996 c
->extension_unregistered_slot
= pa_dbus_protocol_hook_connect(c
->dbus_protocol
,
1997 PA_DBUS_PROTOCOL_HOOK_EXTENSION_UNREGISTERED
,
1999 extension_unregistered_cb
,
2001 c
->memstats
= pa_dbusiface_memstats_new(c
, core
);
2003 if (c
->fallback_sink
)
2004 pa_sink_ref(c
->fallback_sink
);
2005 if (c
->fallback_source
)
2006 pa_source_ref(c
->fallback_source
);
2008 PA_IDXSET_FOREACH(card
, core
->cards
, idx
)
2009 pa_hashmap_put(c
->cards
, PA_UINT32_TO_PTR(idx
), pa_dbusiface_card_new(c
, card
));
2011 PA_IDXSET_FOREACH(sink
, core
->sinks
, idx
) {
2012 device
= pa_dbusiface_device_new_sink(c
, sink
);
2013 pa_hashmap_put(c
->sinks_by_index
, PA_UINT32_TO_PTR(idx
), device
);
2014 pa_hashmap_put(c
->sinks_by_path
, pa_dbusiface_device_get_path(device
), device
);
2017 PA_IDXSET_FOREACH(source
, core
->sources
, idx
) {
2018 device
= pa_dbusiface_device_new_source(c
, source
);
2019 pa_hashmap_put(c
->sources_by_index
, PA_UINT32_TO_PTR(idx
), device
);
2020 pa_hashmap_put(c
->sources_by_path
, pa_dbusiface_device_get_path(device
), device
);
2023 PA_IDXSET_FOREACH(sink_input
, core
->sink_inputs
, idx
)
2024 pa_hashmap_put(c
->playback_streams
, PA_UINT32_TO_PTR(idx
), pa_dbusiface_stream_new_playback(c
, sink_input
));
2026 PA_IDXSET_FOREACH(source_output
, core
->source_outputs
, idx
)
2027 pa_hashmap_put(c
->record_streams
, PA_UINT32_TO_PTR(idx
), pa_dbusiface_stream_new_record(c
, source_output
));
2029 PA_IDXSET_FOREACH(sample
, core
->scache
, idx
)
2030 pa_hashmap_put(c
->samples
, PA_UINT32_TO_PTR(idx
), pa_dbusiface_sample_new(c
, sample
));
2032 PA_IDXSET_FOREACH(module
, core
->modules
, idx
)
2033 pa_hashmap_put(c
->modules
, PA_UINT32_TO_PTR(idx
), pa_dbusiface_module_new(module
));
2035 PA_IDXSET_FOREACH(client
, core
->clients
, idx
)
2036 pa_hashmap_put(c
->clients
, PA_UINT32_TO_PTR(idx
), pa_dbusiface_client_new(c
, client
));
2038 pa_assert_se(pa_dbus_protocol_add_interface(c
->dbus_protocol
, PA_DBUS_CORE_OBJECT_PATH
, &core_interface_info
, c
) >= 0);
2043 static void free_card_cb(void *p
, void *userdata
) {
2044 pa_dbusiface_card
*c
= p
;
2048 pa_dbusiface_card_free(c
);
2051 static void free_device_cb(void *p
, void *userdata
) {
2052 pa_dbusiface_device
*d
= p
;
2056 pa_dbusiface_device_free(d
);
2059 static void free_stream_cb(void *p
, void *userdata
) {
2060 pa_dbusiface_stream
*s
= p
;
2064 pa_dbusiface_stream_free(s
);
2067 static void free_sample_cb(void *p
, void *userdata
) {
2068 pa_dbusiface_sample
*s
= p
;
2072 pa_dbusiface_sample_free(s
);
2075 static void free_module_cb(void *p
, void *userdata
) {
2076 pa_dbusiface_module
*m
= p
;
2080 pa_dbusiface_module_free(m
);
2083 static void free_client_cb(void *p
, void *userdata
) {
2084 pa_dbusiface_client
*c
= p
;
2088 pa_dbusiface_client_free(c
);
2091 void pa_dbusiface_core_free(pa_dbusiface_core
*c
) {
2094 pa_assert_se(pa_dbus_protocol_remove_interface(c
->dbus_protocol
, PA_DBUS_CORE_OBJECT_PATH
, core_interface_info
.name
) >= 0);
2096 pa_subscription_free(c
->subscription
);
2097 pa_hashmap_free(c
->cards
, free_card_cb
, NULL
);
2098 pa_hashmap_free(c
->sinks_by_index
, free_device_cb
, NULL
);
2099 pa_hashmap_free(c
->sinks_by_path
, NULL
, NULL
);
2100 pa_hashmap_free(c
->sources_by_index
, free_device_cb
, NULL
);
2101 pa_hashmap_free(c
->sources_by_path
, NULL
, NULL
);
2102 pa_hashmap_free(c
->playback_streams
, free_stream_cb
, NULL
);
2103 pa_hashmap_free(c
->record_streams
, free_stream_cb
, NULL
);
2104 pa_hashmap_free(c
->samples
, free_sample_cb
, NULL
);
2105 pa_hashmap_free(c
->modules
, free_module_cb
, NULL
);
2106 pa_hashmap_free(c
->clients
, free_client_cb
, NULL
);
2107 pa_hook_slot_free(c
->extension_registered_slot
);
2108 pa_hook_slot_free(c
->extension_unregistered_slot
);
2109 pa_dbusiface_memstats_free(c
->memstats
);
2111 if (c
->fallback_sink
)
2112 pa_sink_unref(c
->fallback_sink
);
2113 if (c
->fallback_source
)
2114 pa_source_unref(c
->fallback_source
);
2116 pa_dbus_protocol_unref(c
->dbus_protocol
);
2117 pa_core_unref(c
->core
);
2122 const char *pa_dbusiface_core_get_card_path(pa_dbusiface_core
*c
, const pa_card
*card
) {
2126 return pa_dbusiface_card_get_path(pa_hashmap_get(c
->cards
, PA_UINT32_TO_PTR(card
->index
)));
2129 const char *pa_dbusiface_core_get_sink_path(pa_dbusiface_core
*c
, const pa_sink
*sink
) {
2133 return pa_dbusiface_device_get_path(pa_hashmap_get(c
->sinks_by_index
, PA_UINT32_TO_PTR(sink
->index
)));
2136 const char *pa_dbusiface_core_get_source_path(pa_dbusiface_core
*c
, const pa_source
*source
) {
2140 return pa_dbusiface_device_get_path(pa_hashmap_get(c
->sources_by_index
, PA_UINT32_TO_PTR(source
->index
)));
2143 const char *pa_dbusiface_core_get_playback_stream_path(pa_dbusiface_core
*c
, const pa_sink_input
*sink_input
) {
2145 pa_assert(sink_input
);
2147 return pa_dbusiface_stream_get_path(pa_hashmap_get(c
->playback_streams
, PA_UINT32_TO_PTR(sink_input
->index
)));
2150 const char *pa_dbusiface_core_get_record_stream_path(pa_dbusiface_core
*c
, const pa_source_output
*source_output
) {
2152 pa_assert(source_output
);
2154 return pa_dbusiface_stream_get_path(pa_hashmap_get(c
->record_streams
, PA_UINT32_TO_PTR(source_output
->index
)));
2157 const char *pa_dbusiface_core_get_module_path(pa_dbusiface_core
*c
, const pa_module
*module
) {
2161 return pa_dbusiface_module_get_path(pa_hashmap_get(c
->modules
, PA_UINT32_TO_PTR(module
->index
)));
2164 const char *pa_dbusiface_core_get_client_path(pa_dbusiface_core
*c
, const pa_client
*client
) {
2168 return pa_dbusiface_client_get_path(pa_hashmap_get(c
->clients
, PA_UINT32_TO_PTR(client
->index
)));
2171 pa_sink
*pa_dbusiface_core_get_sink(pa_dbusiface_core
*c
, const char *object_path
) {
2172 pa_dbusiface_device
*device
= NULL
;
2175 pa_assert(object_path
);
2177 device
= pa_hashmap_get(c
->sinks_by_path
, object_path
);
2180 return pa_dbusiface_device_get_sink(device
);
2185 pa_source
*pa_dbusiface_core_get_source(pa_dbusiface_core
*c
, const char *object_path
) {
2186 pa_dbusiface_device
*device
= NULL
;
2189 pa_assert(object_path
);
2191 device
= pa_hashmap_get(c
->sources_by_path
, object_path
);
2194 return pa_dbusiface_device_get_source(device
);