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
, 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
, 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
, 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
, 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
, 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
,
251 SIGNAL_SOURCE_REMOVED
,
252 SIGNAL_FALLBACK_SOURCE_UPDATED
,
253 SIGNAL_NEW_PLAYBACK_STREAM
,
254 SIGNAL_PLAYBACK_STREAM_REMOVED
,
255 SIGNAL_NEW_RECORD_STREAM
,
256 SIGNAL_RECORD_STREAM_REMOVED
,
258 SIGNAL_SAMPLE_REMOVED
,
260 SIGNAL_MODULE_REMOVED
,
262 SIGNAL_CLIENT_REMOVED
,
263 SIGNAL_NEW_EXTENSION
,
264 SIGNAL_EXTENSION_REMOVED
,
268 static pa_dbus_arg_info new_card_args
[] = { { "card", "o", NULL
} };
269 static pa_dbus_arg_info card_removed_args
[] = { { "card", "o", NULL
} };
270 static pa_dbus_arg_info new_sink_args
[] = { { "sink", "o", NULL
} };
271 static pa_dbus_arg_info sink_removed_args
[] = { { "sink", "o", NULL
} };
272 static pa_dbus_arg_info fallback_sink_updated_args
[] = { { "sink", "o", NULL
} };
273 static pa_dbus_arg_info new_source_args
[] = { { "source", "o", NULL
} };
274 static pa_dbus_arg_info source_removed_args
[] = { { "source", "o", NULL
} };
275 static pa_dbus_arg_info fallback_source_updated_args
[] = { { "source", "o", NULL
} };
276 static pa_dbus_arg_info new_playback_stream_args
[] = { { "playback_stream", "o", NULL
} };
277 static pa_dbus_arg_info playback_stream_removed_args
[] = { { "playback_stream", "o", NULL
} };
278 static pa_dbus_arg_info new_record_stream_args
[] = { { "record_stream", "o", NULL
} };
279 static pa_dbus_arg_info record_stream_removed_args
[] = { { "record_stream", "o", NULL
} };
280 static pa_dbus_arg_info new_sample_args
[] = { { "sample", "o", NULL
} };
281 static pa_dbus_arg_info sample_removed_args
[] = { { "sample", "o", NULL
} };
282 static pa_dbus_arg_info new_module_args
[] = { { "module", "o", NULL
} };
283 static pa_dbus_arg_info module_removed_args
[] = { { "module", "o", NULL
} };
284 static pa_dbus_arg_info new_client_args
[] = { { "client", "o", NULL
} };
285 static pa_dbus_arg_info client_removed_args
[] = { { "client", "o", NULL
} };
286 static pa_dbus_arg_info new_extension_args
[] = { { "extension", "s", NULL
} };
287 static pa_dbus_arg_info extension_removed_args
[] = { { "extension", "s", NULL
} };
289 static pa_dbus_signal_info signals
[SIGNAL_MAX
] = {
290 [SIGNAL_NEW_CARD
] = { .name
= "NewCard", .arguments
= new_card_args
, .n_arguments
= 1 },
291 [SIGNAL_CARD_REMOVED
] = { .name
= "CardRemoved", .arguments
= card_removed_args
, .n_arguments
= 1 },
292 [SIGNAL_NEW_SINK
] = { .name
= "NewSink", .arguments
= new_sink_args
, .n_arguments
= 1 },
293 [SIGNAL_SINK_REMOVED
] = { .name
= "SinkRemoved", .arguments
= sink_removed_args
, .n_arguments
= 1 },
294 [SIGNAL_FALLBACK_SINK_UPDATED
] = { .name
= "FallbackSinkUpdated", .arguments
= fallback_sink_updated_args
, .n_arguments
= 1 },
295 [SIGNAL_NEW_SOURCE
] = { .name
= "NewSource", .arguments
= new_source_args
, .n_arguments
= 1 },
296 [SIGNAL_SOURCE_REMOVED
] = { .name
= "SourceRemoved", .arguments
= source_removed_args
, .n_arguments
= 1 },
297 [SIGNAL_FALLBACK_SOURCE_UPDATED
] = { .name
= "FallbackSourceUpdated", .arguments
= fallback_source_updated_args
, .n_arguments
= 1 },
298 [SIGNAL_NEW_PLAYBACK_STREAM
] = { .name
= "NewPlaybackStream", .arguments
= new_playback_stream_args
, .n_arguments
= 1 },
299 [SIGNAL_PLAYBACK_STREAM_REMOVED
] = { .name
= "PlaybackStreamRemoved", .arguments
= playback_stream_removed_args
, .n_arguments
= 1 },
300 [SIGNAL_NEW_RECORD_STREAM
] = { .name
= "NewRecordStream", .arguments
= new_record_stream_args
, .n_arguments
= 1 },
301 [SIGNAL_RECORD_STREAM_REMOVED
] = { .name
= "RecordStreamRemoved", .arguments
= record_stream_removed_args
, .n_arguments
= 1 },
302 [SIGNAL_NEW_SAMPLE
] = { .name
= "NewSample", .arguments
= new_sample_args
, .n_arguments
= 1 },
303 [SIGNAL_SAMPLE_REMOVED
] = { .name
= "SampleRemoved", .arguments
= sample_removed_args
, .n_arguments
= 1 },
304 [SIGNAL_NEW_MODULE
] = { .name
= "NewModule", .arguments
= new_module_args
, .n_arguments
= 1 },
305 [SIGNAL_MODULE_REMOVED
] = { .name
= "ModuleRemoved", .arguments
= module_removed_args
, .n_arguments
= 1 },
306 [SIGNAL_NEW_CLIENT
] = { .name
= "NewClient", .arguments
= new_client_args
, .n_arguments
= 1 },
307 [SIGNAL_CLIENT_REMOVED
] = { .name
= "ClientRemoved", .arguments
= client_removed_args
, .n_arguments
= 1 },
308 [SIGNAL_NEW_EXTENSION
] = { .name
= "NewExtension", .arguments
= new_extension_args
, .n_arguments
= 1 },
309 [SIGNAL_EXTENSION_REMOVED
] = { .name
= "ExtensionRemoved", .arguments
= extension_removed_args
, .n_arguments
= 1 }
312 static pa_dbus_interface_info core_interface_info
= {
313 .name
= PA_DBUS_CORE_INTERFACE
,
314 .method_handlers
= method_handlers
,
315 .n_method_handlers
= METHOD_HANDLER_MAX
,
316 .property_handlers
= property_handlers
,
317 .n_property_handlers
= PROPERTY_HANDLER_MAX
,
318 .get_all_properties_cb
= handle_get_all
,
320 .n_signals
= SIGNAL_MAX
323 static void handle_get_interface_revision(DBusConnection
*conn
, DBusMessage
*msg
, void *userdata
) {
324 dbus_uint32_t interface_revision
= INTERFACE_REVISION
;
329 pa_dbus_send_basic_variant_reply(conn
, msg
, DBUS_TYPE_UINT32
, &interface_revision
);
332 static void handle_get_name(DBusConnection
*conn
, DBusMessage
*msg
, void *userdata
) {
333 const char *server_name
= PACKAGE_NAME
;
338 pa_dbus_send_basic_variant_reply(conn
, msg
, DBUS_TYPE_STRING
, &server_name
);
341 static void handle_get_version(DBusConnection
*conn
, DBusMessage
*msg
, void *userdata
) {
342 const char *version
= PACKAGE_VERSION
;
347 pa_dbus_send_basic_variant_reply(conn
, msg
, DBUS_TYPE_STRING
, &version
);
350 static dbus_bool_t
get_is_local(DBusConnection
*conn
) {
355 if (!dbus_connection_get_socket(conn
, &conn_fd
))
358 return pa_socket_is_local(conn_fd
);
361 static void handle_get_is_local(DBusConnection
*conn
, DBusMessage
*msg
, void *userdata
) {
362 dbus_bool_t is_local
;
367 is_local
= get_is_local(conn
);
369 pa_dbus_send_basic_variant_reply(conn
, msg
, DBUS_TYPE_BOOLEAN
, &is_local
);
372 static void handle_get_username(DBusConnection
*conn
, DBusMessage
*msg
, void *userdata
) {
373 char *username
= NULL
;
378 username
= pa_get_user_name_malloc();
380 pa_dbus_send_basic_variant_reply(conn
, msg
, DBUS_TYPE_STRING
, &username
);
385 static void handle_get_hostname(DBusConnection
*conn
, DBusMessage
*msg
, void *userdata
) {
386 char *hostname
= NULL
;
391 hostname
= pa_get_host_name_malloc();
393 pa_dbus_send_basic_variant_reply(conn
, msg
, DBUS_TYPE_STRING
, &hostname
);
398 /* Caller frees the returned array. */
399 static dbus_uint32_t
*get_default_channels(pa_dbusiface_core
*c
, unsigned *n
) {
400 dbus_uint32_t
*default_channels
= NULL
;
406 *n
= c
->core
->default_channel_map
.channels
;
407 default_channels
= pa_xnew(dbus_uint32_t
, *n
);
409 for (i
= 0; i
< *n
; ++i
)
410 default_channels
[i
] = c
->core
->default_channel_map
.map
[i
];
412 return default_channels
;
415 static void handle_get_default_channels(DBusConnection
*conn
, DBusMessage
*msg
, void *userdata
) {
416 pa_dbusiface_core
*c
= userdata
;
417 dbus_uint32_t
*default_channels
= NULL
;
424 default_channels
= get_default_channels(c
, &n
);
426 pa_dbus_send_basic_array_variant_reply(conn
, msg
, DBUS_TYPE_UINT32
, default_channels
, n
);
428 pa_xfree(default_channels
);
431 static void handle_set_default_channels(DBusConnection
*conn
, DBusMessage
*msg
, void *userdata
) {
432 pa_dbusiface_core
*c
= userdata
;
433 pa_channel_map new_channel_map
;
434 dbus_uint32_t
*default_channels
;
442 pa_channel_map_init(&new_channel_map
);
444 if (pa_dbus_get_fixed_array_set_property_arg(conn
, msg
, DBUS_TYPE_UINT32
, &default_channels
, &n_channels
) < 0)
447 if (n_channels
<= 0) {
448 pa_dbus_send_error(conn
, msg
, DBUS_ERROR_INVALID_ARGS
, "Empty channel array.");
452 if (n_channels
> PA_CHANNELS_MAX
) {
453 pa_dbus_send_error(conn
, msg
, DBUS_ERROR_INVALID_ARGS
,
454 "Too many channels: %u. The maximum number of channels is %u.", n_channels
, PA_CHANNELS_MAX
);
458 new_channel_map
.channels
= n_channels
;
460 for (i
= 0; i
< new_channel_map
.channels
; ++i
) {
461 if (default_channels
[i
] >= PA_CHANNEL_POSITION_MAX
) {
462 pa_dbus_send_error(conn
, msg
, DBUS_ERROR_INVALID_ARGS
, "Invalid channel position: %u.", default_channels
[i
]);
466 new_channel_map
.map
[i
] = default_channels
[i
];
469 c
->core
->default_channel_map
= new_channel_map
;
470 c
->core
->default_sample_spec
.channels
= n_channels
;
472 pa_dbus_send_empty_reply(conn
, msg
);
475 static void handle_get_default_sample_format(DBusConnection
*conn
, DBusMessage
*msg
, void *userdata
) {
476 pa_dbusiface_core
*c
= userdata
;
477 dbus_uint32_t default_sample_format
;
483 default_sample_format
= c
->core
->default_sample_spec
.format
;
485 pa_dbus_send_basic_variant_reply(conn
, msg
, DBUS_TYPE_UINT32
, &default_sample_format
);
488 static void handle_set_default_sample_format(DBusConnection
*conn
, DBusMessage
*msg
, void *userdata
) {
489 pa_dbusiface_core
*c
= userdata
;
490 dbus_uint32_t default_sample_format
;
496 if (pa_dbus_get_basic_set_property_arg(conn
, msg
, DBUS_TYPE_UINT32
, &default_sample_format
) < 0)
499 if (default_sample_format
>= PA_SAMPLE_MAX
) {
500 pa_dbus_send_error(conn
, msg
, DBUS_ERROR_INVALID_ARGS
, "Invalid sample format.");
504 c
->core
->default_sample_spec
.format
= default_sample_format
;
506 pa_dbus_send_empty_reply(conn
, msg
);
509 static void handle_get_default_sample_rate(DBusConnection
*conn
, DBusMessage
*msg
, void *userdata
) {
510 pa_dbusiface_core
*c
= userdata
;
511 dbus_uint32_t default_sample_rate
;
517 default_sample_rate
= c
->core
->default_sample_spec
.rate
;
519 pa_dbus_send_basic_variant_reply(conn
, msg
, DBUS_TYPE_UINT32
, &default_sample_rate
);
522 static void handle_set_default_sample_rate(DBusConnection
*conn
, DBusMessage
*msg
, void *userdata
) {
523 pa_dbusiface_core
*c
= userdata
;
524 dbus_uint32_t default_sample_rate
;
530 if (pa_dbus_get_basic_set_property_arg(conn
, msg
, DBUS_TYPE_UINT32
, &default_sample_rate
) < 0)
533 if (default_sample_rate
<= 0 || default_sample_rate
> PA_RATE_MAX
) {
534 pa_dbus_send_error(conn
, msg
, DBUS_ERROR_INVALID_ARGS
, "Invalid sample rate.");
538 c
->core
->default_sample_spec
.rate
= default_sample_rate
;
540 pa_dbus_send_empty_reply(conn
, msg
);
543 /* The caller frees the array, but not the strings. */
544 static const char **get_cards(pa_dbusiface_core
*c
, unsigned *n
) {
548 pa_dbusiface_card
*card
;
553 *n
= pa_hashmap_size(c
->cards
);
558 cards
= pa_xnew(const char *, *n
);
560 PA_HASHMAP_FOREACH(card
, c
->cards
, state
)
561 cards
[i
++] = pa_dbusiface_card_get_path(card
);
566 static void handle_get_cards(DBusConnection
*conn
, DBusMessage
*msg
, void *userdata
) {
567 pa_dbusiface_core
*c
= userdata
;
575 cards
= get_cards(c
, &n
);
577 pa_dbus_send_basic_array_variant_reply(conn
, msg
, DBUS_TYPE_OBJECT_PATH
, cards
, n
);
582 /* The caller frees the array, but not the strings. */
583 static const char **get_sinks(pa_dbusiface_core
*c
, unsigned *n
) {
587 pa_dbusiface_device
*sink
;
592 *n
= pa_hashmap_size(c
->sinks_by_index
);
597 sinks
= pa_xnew(const char *, *n
);
599 PA_HASHMAP_FOREACH(sink
, c
->sinks_by_index
, state
)
600 sinks
[i
++] = pa_dbusiface_device_get_path(sink
);
605 static void handle_get_sinks(DBusConnection
*conn
, DBusMessage
*msg
, void *userdata
) {
606 pa_dbusiface_core
*c
= userdata
;
614 sinks
= get_sinks(c
, &n
);
616 pa_dbus_send_basic_array_variant_reply(conn
, msg
, DBUS_TYPE_OBJECT_PATH
, sinks
, n
);
621 static void handle_get_fallback_sink(DBusConnection
*conn
, DBusMessage
*msg
, void *userdata
) {
622 pa_dbusiface_core
*c
= userdata
;
623 pa_dbusiface_device
*fallback_sink
;
624 const char *object_path
;
630 if (!c
->fallback_sink
) {
631 pa_dbus_send_error(conn
, msg
, PA_DBUS_ERROR_NO_SUCH_PROPERTY
,
632 "There are no sinks, and therefore no fallback sink either.");
636 pa_assert_se((fallback_sink
= pa_hashmap_get(c
->sinks_by_index
, PA_UINT32_TO_PTR(c
->fallback_sink
->index
))));
637 object_path
= pa_dbusiface_device_get_path(fallback_sink
);
639 pa_dbus_send_basic_variant_reply(conn
, msg
, DBUS_TYPE_OBJECT_PATH
, &object_path
);
642 static void handle_set_fallback_sink(DBusConnection
*conn
, DBusMessage
*msg
, void *userdata
) {
643 pa_dbusiface_core
*c
= userdata
;
644 pa_dbusiface_device
*fallback_sink
;
645 const char *object_path
;
651 if (!c
->fallback_sink
) {
652 pa_dbus_send_error(conn
, msg
, PA_DBUS_ERROR_NO_SUCH_PROPERTY
,
653 "There are no sinks, and therefore no fallback sink either.");
657 if (pa_dbus_get_basic_set_property_arg(conn
, msg
, DBUS_TYPE_OBJECT_PATH
, &object_path
) < 0)
660 if (!(fallback_sink
= pa_hashmap_get(c
->sinks_by_path
, object_path
))) {
661 pa_dbus_send_error(conn
, msg
, PA_DBUS_ERROR_NOT_FOUND
, "%s: No such sink.", object_path
);
665 pa_namereg_set_default_sink(c
->core
, pa_dbusiface_device_get_sink(fallback_sink
));
667 pa_dbus_send_empty_reply(conn
, msg
);
670 /* The caller frees the array, but not the strings. */
671 static const char **get_sources(pa_dbusiface_core
*c
, unsigned *n
) {
672 const char **sources
;
675 pa_dbusiface_device
*source
;
680 *n
= pa_hashmap_size(c
->sources_by_index
);
685 sources
= pa_xnew(const char *, *n
);
687 PA_HASHMAP_FOREACH(source
, c
->sources_by_index
, state
)
688 sources
[i
++] = pa_dbusiface_device_get_path(source
);
693 static void handle_get_sources(DBusConnection
*conn
, DBusMessage
*msg
, void *userdata
) {
694 pa_dbusiface_core
*c
= userdata
;
695 const char **sources
;
702 sources
= get_sources(c
, &n
);
704 pa_dbus_send_basic_array_variant_reply(conn
, msg
, DBUS_TYPE_OBJECT_PATH
, sources
, n
);
709 static void handle_get_fallback_source(DBusConnection
*conn
, DBusMessage
*msg
, void *userdata
) {
710 pa_dbusiface_core
*c
= userdata
;
711 pa_dbusiface_device
*fallback_source
;
712 const char *object_path
;
718 if (!c
->fallback_source
) {
719 pa_dbus_send_error(conn
, msg
, PA_DBUS_ERROR_NO_SUCH_PROPERTY
,
720 "There are no sources, and therefore no fallback source either.");
724 pa_assert_se((fallback_source
= pa_hashmap_get(c
->sources_by_index
, PA_UINT32_TO_PTR(c
->fallback_source
->index
))));
725 object_path
= pa_dbusiface_device_get_path(fallback_source
);
727 pa_dbus_send_basic_variant_reply(conn
, msg
, DBUS_TYPE_OBJECT_PATH
, &object_path
);
730 static void handle_set_fallback_source(DBusConnection
*conn
, DBusMessage
*msg
, void *userdata
) {
731 pa_dbusiface_core
*c
= userdata
;
732 pa_dbusiface_device
*fallback_source
;
733 const char *object_path
;
739 if (!c
->fallback_source
) {
740 pa_dbus_send_error(conn
, msg
, PA_DBUS_ERROR_NO_SUCH_PROPERTY
,
741 "There are no sources, and therefore no fallback source either.");
745 if (pa_dbus_get_basic_set_property_arg(conn
, msg
, DBUS_TYPE_OBJECT_PATH
, &object_path
) < 0)
748 if (!(fallback_source
= pa_hashmap_get(c
->sources_by_path
, object_path
))) {
749 pa_dbus_send_error(conn
, msg
, PA_DBUS_ERROR_NOT_FOUND
, "%s: No such source.", object_path
);
753 pa_namereg_set_default_source(c
->core
, pa_dbusiface_device_get_source(fallback_source
));
755 pa_dbus_send_empty_reply(conn
, msg
);
758 /* The caller frees the array, but not the strings. */
759 static const char **get_playback_streams(pa_dbusiface_core
*c
, unsigned *n
) {
760 const char **streams
;
763 pa_dbusiface_stream
*stream
;
768 *n
= pa_hashmap_size(c
->playback_streams
);
773 streams
= pa_xnew(const char *, *n
);
775 PA_HASHMAP_FOREACH(stream
, c
->playback_streams
, state
)
776 streams
[i
++] = pa_dbusiface_stream_get_path(stream
);
781 static void handle_get_playback_streams(DBusConnection
*conn
, DBusMessage
*msg
, void *userdata
) {
782 pa_dbusiface_core
*c
= userdata
;
783 const char **playback_streams
;
790 playback_streams
= get_playback_streams(c
, &n
);
792 pa_dbus_send_basic_array_variant_reply(conn
, msg
, DBUS_TYPE_OBJECT_PATH
, playback_streams
, n
);
794 pa_xfree(playback_streams
);
797 /* The caller frees the array, but not the strings. */
798 static const char **get_record_streams(pa_dbusiface_core
*c
, unsigned *n
) {
799 const char **streams
;
802 pa_dbusiface_stream
*stream
;
807 *n
= pa_hashmap_size(c
->record_streams
);
812 streams
= pa_xnew(const char *, *n
);
814 PA_HASHMAP_FOREACH(stream
, c
->record_streams
, state
)
815 streams
[i
++] = pa_dbusiface_stream_get_path(stream
);
820 static void handle_get_record_streams(DBusConnection
*conn
, DBusMessage
*msg
, void *userdata
) {
821 pa_dbusiface_core
*c
= userdata
;
822 const char **record_streams
;
829 record_streams
= get_record_streams(c
, &n
);
831 pa_dbus_send_basic_array_variant_reply(conn
, msg
, DBUS_TYPE_OBJECT_PATH
, record_streams
, n
);
833 pa_xfree(record_streams
);
836 /* The caller frees the array, but not the strings. */
837 static const char **get_samples(pa_dbusiface_core
*c
, unsigned *n
) {
838 const char **samples
;
841 pa_dbusiface_sample
*sample
;
846 *n
= pa_hashmap_size(c
->samples
);
851 samples
= pa_xnew(const char *, *n
);
853 PA_HASHMAP_FOREACH(sample
, c
->samples
, state
)
854 samples
[i
++] = pa_dbusiface_sample_get_path(sample
);
859 static void handle_get_samples(DBusConnection
*conn
, DBusMessage
*msg
, void *userdata
) {
860 pa_dbusiface_core
*c
= userdata
;
861 const char **samples
;
868 samples
= get_samples(c
, &n
);
870 pa_dbus_send_basic_array_variant_reply(conn
, msg
, DBUS_TYPE_OBJECT_PATH
, samples
, n
);
875 /* The caller frees the array, but not the strings. */
876 static const char **get_modules(pa_dbusiface_core
*c
, unsigned *n
) {
877 const char **modules
;
880 pa_dbusiface_module
*module
;
885 *n
= pa_hashmap_size(c
->modules
);
890 modules
= pa_xnew(const char *, *n
);
892 PA_HASHMAP_FOREACH(module
, c
->modules
, state
)
893 modules
[i
++] = pa_dbusiface_module_get_path(module
);
898 static void handle_get_modules(DBusConnection
*conn
, DBusMessage
*msg
, void *userdata
) {
899 pa_dbusiface_core
*c
= userdata
;
900 const char **modules
;
907 modules
= get_modules(c
, &n
);
909 pa_dbus_send_basic_array_variant_reply(conn
, msg
, DBUS_TYPE_OBJECT_PATH
, modules
, n
);
914 /* The caller frees the array, but not the strings. */
915 static const char **get_clients(pa_dbusiface_core
*c
, unsigned *n
) {
916 const char **clients
;
919 pa_dbusiface_client
*client
;
924 *n
= pa_hashmap_size(c
->clients
);
929 clients
= pa_xnew(const char *, *n
);
931 PA_HASHMAP_FOREACH(client
, c
->clients
, state
)
932 clients
[i
++] = pa_dbusiface_client_get_path(client
);
937 static void handle_get_clients(DBusConnection
*conn
, DBusMessage
*msg
, void *userdata
) {
938 pa_dbusiface_core
*c
= userdata
;
939 const char **clients
;
946 clients
= get_clients(c
, &n
);
948 pa_dbus_send_basic_array_variant_reply(conn
, msg
, DBUS_TYPE_OBJECT_PATH
, clients
, n
);
953 static const char *get_my_client(pa_dbusiface_core
*c
, DBusConnection
*conn
) {
954 pa_client
*my_client
;
959 pa_assert_se((my_client
= pa_dbus_protocol_get_client(c
->dbus_protocol
, conn
)));
961 return pa_dbusiface_client_get_path(pa_hashmap_get(c
->clients
, PA_UINT32_TO_PTR(my_client
->index
)));
964 static void handle_get_my_client(DBusConnection
*conn
, DBusMessage
*msg
, void *userdata
) {
965 pa_dbusiface_core
*c
= userdata
;
966 const char *my_client
;
972 my_client
= get_my_client(c
, conn
);
974 pa_dbus_send_basic_variant_reply(conn
, msg
, DBUS_TYPE_OBJECT_PATH
, &my_client
);
977 static void handle_get_extensions(DBusConnection
*conn
, DBusMessage
*msg
, void *userdata
) {
978 pa_dbusiface_core
*c
= userdata
;
979 const char **extensions
;
986 extensions
= pa_dbus_protocol_get_extensions(c
->dbus_protocol
, &n
);
988 pa_dbus_send_basic_array_variant_reply(conn
, msg
, DBUS_TYPE_STRING
, extensions
, n
);
990 pa_xfree(extensions
);
993 static void handle_get_all(DBusConnection
*conn
, DBusMessage
*msg
, void *userdata
) {
994 pa_dbusiface_core
*c
= userdata
;
995 DBusMessage
*reply
= NULL
;
996 DBusMessageIter msg_iter
;
997 DBusMessageIter dict_iter
;
998 dbus_uint32_t interface_revision
;
999 const char *server_name
;
1000 const char *version
;
1001 dbus_bool_t is_local
;
1004 dbus_uint32_t
*default_channels
;
1005 unsigned n_default_channels
;
1006 dbus_uint32_t default_sample_format
;
1007 dbus_uint32_t default_sample_rate
;
1012 const char *fallback_sink
;
1013 const char **sources
;
1015 const char *fallback_source
;
1016 const char **playback_streams
;
1017 unsigned n_playback_streams
;
1018 const char **record_streams
;
1019 unsigned n_record_streams
;
1020 const char **samples
;
1022 const char **modules
;
1024 const char **clients
;
1026 const char *my_client
;
1027 const char **extensions
;
1028 unsigned n_extensions
;
1034 interface_revision
= INTERFACE_REVISION
;
1035 server_name
= PACKAGE_NAME
;
1036 version
= PACKAGE_VERSION
;
1037 is_local
= get_is_local(conn
);
1038 username
= pa_get_user_name_malloc();
1039 hostname
= pa_get_host_name_malloc();
1040 default_channels
= get_default_channels(c
, &n_default_channels
);
1041 default_sample_format
= c
->core
->default_sample_spec
.format
;
1042 default_sample_rate
= c
->core
->default_sample_spec
.rate
;
1043 cards
= get_cards(c
, &n_cards
);
1044 sinks
= get_sinks(c
, &n_sinks
);
1045 fallback_sink
= c
->fallback_sink
1046 ? pa_dbusiface_device_get_path(pa_hashmap_get(c
->sinks_by_index
, PA_UINT32_TO_PTR(c
->fallback_sink
->index
)))
1048 sources
= get_sources(c
, &n_sources
);
1049 fallback_source
= c
->fallback_source
1050 ? pa_dbusiface_device_get_path(pa_hashmap_get(c
->sources_by_index
,
1051 PA_UINT32_TO_PTR(c
->fallback_source
->index
)))
1053 playback_streams
= get_playback_streams(c
, &n_playback_streams
);
1054 record_streams
= get_record_streams(c
, &n_record_streams
);
1055 samples
= get_samples(c
, &n_samples
);
1056 modules
= get_modules(c
, &n_modules
);
1057 clients
= get_clients(c
, &n_clients
);
1058 my_client
= get_my_client(c
, conn
);
1059 extensions
= pa_dbus_protocol_get_extensions(c
->dbus_protocol
, &n_extensions
);
1061 pa_assert_se((reply
= dbus_message_new_method_return(msg
)));
1063 dbus_message_iter_init_append(reply
, &msg_iter
);
1064 pa_assert_se(dbus_message_iter_open_container(&msg_iter
, DBUS_TYPE_ARRAY
, "{sv}", &dict_iter
));
1066 pa_dbus_append_basic_variant_dict_entry(&dict_iter
, property_handlers
[PROPERTY_HANDLER_INTERFACE_REVISION
].property_name
, DBUS_TYPE_UINT32
, &interface_revision
);
1067 pa_dbus_append_basic_variant_dict_entry(&dict_iter
, property_handlers
[PROPERTY_HANDLER_NAME
].property_name
, DBUS_TYPE_STRING
, &server_name
);
1068 pa_dbus_append_basic_variant_dict_entry(&dict_iter
, property_handlers
[PROPERTY_HANDLER_VERSION
].property_name
, DBUS_TYPE_STRING
, &version
);
1069 pa_dbus_append_basic_variant_dict_entry(&dict_iter
, property_handlers
[PROPERTY_HANDLER_IS_LOCAL
].property_name
, DBUS_TYPE_BOOLEAN
, &is_local
);
1070 pa_dbus_append_basic_variant_dict_entry(&dict_iter
, property_handlers
[PROPERTY_HANDLER_USERNAME
].property_name
, DBUS_TYPE_STRING
, &username
);
1071 pa_dbus_append_basic_variant_dict_entry(&dict_iter
, property_handlers
[PROPERTY_HANDLER_HOSTNAME
].property_name
, DBUS_TYPE_STRING
, &hostname
);
1072 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
);
1073 pa_dbus_append_basic_variant_dict_entry(&dict_iter
, property_handlers
[PROPERTY_HANDLER_DEFAULT_SAMPLE_FORMAT
].property_name
, DBUS_TYPE_UINT32
, &default_sample_format
);
1074 pa_dbus_append_basic_variant_dict_entry(&dict_iter
, property_handlers
[PROPERTY_HANDLER_DEFAULT_SAMPLE_RATE
].property_name
, DBUS_TYPE_UINT32
, &default_sample_rate
);
1075 pa_dbus_append_basic_array_variant_dict_entry(&dict_iter
, property_handlers
[PROPERTY_HANDLER_CARDS
].property_name
, DBUS_TYPE_OBJECT_PATH
, cards
, n_cards
);
1076 pa_dbus_append_basic_array_variant_dict_entry(&dict_iter
, property_handlers
[PROPERTY_HANDLER_SINKS
].property_name
, DBUS_TYPE_OBJECT_PATH
, sinks
, n_sinks
);
1079 pa_dbus_append_basic_variant_dict_entry(&dict_iter
, property_handlers
[PROPERTY_HANDLER_FALLBACK_SINK
].property_name
, DBUS_TYPE_OBJECT_PATH
, &fallback_sink
);
1081 pa_dbus_append_basic_array_variant_dict_entry(&dict_iter
, property_handlers
[PROPERTY_HANDLER_SOURCES
].property_name
, DBUS_TYPE_OBJECT_PATH
, sources
, n_sources
);
1083 if (fallback_source
)
1084 pa_dbus_append_basic_variant_dict_entry(&dict_iter
, property_handlers
[PROPERTY_HANDLER_FALLBACK_SOURCE
].property_name
, DBUS_TYPE_OBJECT_PATH
, &fallback_source
);
1086 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
);
1087 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
);
1088 pa_dbus_append_basic_array_variant_dict_entry(&dict_iter
, property_handlers
[PROPERTY_HANDLER_SAMPLES
].property_name
, DBUS_TYPE_OBJECT_PATH
, samples
, n_samples
);
1089 pa_dbus_append_basic_array_variant_dict_entry(&dict_iter
, property_handlers
[PROPERTY_HANDLER_MODULES
].property_name
, DBUS_TYPE_OBJECT_PATH
, modules
, n_modules
);
1090 pa_dbus_append_basic_array_variant_dict_entry(&dict_iter
, property_handlers
[PROPERTY_HANDLER_CLIENTS
].property_name
, DBUS_TYPE_OBJECT_PATH
, clients
, n_clients
);
1091 pa_dbus_append_basic_variant_dict_entry(&dict_iter
, property_handlers
[PROPERTY_HANDLER_MY_CLIENT
].property_name
, DBUS_TYPE_OBJECT_PATH
, &my_client
);
1092 pa_dbus_append_basic_array_variant_dict_entry(&dict_iter
, property_handlers
[PROPERTY_HANDLER_EXTENSIONS
].property_name
, DBUS_TYPE_STRING
, extensions
, n_extensions
);
1094 pa_assert_se(dbus_message_iter_close_container(&msg_iter
, &dict_iter
));
1096 pa_assert_se(dbus_connection_send(conn
, reply
, NULL
));
1098 dbus_message_unref(reply
);
1102 pa_xfree(default_channels
);
1106 pa_xfree(playback_streams
);
1107 pa_xfree(record_streams
);
1111 pa_xfree(extensions
);
1114 static void handle_get_card_by_name(DBusConnection
*conn
, DBusMessage
*msg
, void *userdata
) {
1115 pa_dbusiface_core
*c
= userdata
;
1118 pa_dbusiface_card
*dbus_card
;
1119 const char *object_path
;
1126 dbus_error_init(&error
);
1128 if (!dbus_message_get_args(msg
, &error
, DBUS_TYPE_STRING
, &card_name
, DBUS_TYPE_INVALID
)) {
1129 pa_dbus_send_error(conn
, msg
, DBUS_ERROR_INVALID_ARGS
, "%s", error
.message
);
1130 dbus_error_free(&error
);
1134 if (!(card
= pa_namereg_get(c
->core
, card_name
, PA_NAMEREG_CARD
))) {
1135 pa_dbus_send_error(conn
, msg
, PA_DBUS_ERROR_NOT_FOUND
, "No such card.");
1139 pa_assert_se((dbus_card
= pa_hashmap_get(c
->cards
, PA_UINT32_TO_PTR(card
->index
))));
1141 object_path
= pa_dbusiface_card_get_path(dbus_card
);
1143 pa_dbus_send_basic_value_reply(conn
, msg
, DBUS_TYPE_OBJECT_PATH
, &object_path
);
1146 static void handle_get_sink_by_name(DBusConnection
*conn
, DBusMessage
*msg
, void *userdata
) {
1147 pa_dbusiface_core
*c
= userdata
;
1150 pa_dbusiface_device
*dbus_sink
;
1151 const char *object_path
;
1158 dbus_error_init(&error
);
1160 if (!dbus_message_get_args(msg
, &error
, DBUS_TYPE_STRING
, &sink_name
, DBUS_TYPE_INVALID
)) {
1161 pa_dbus_send_error(conn
, msg
, DBUS_ERROR_INVALID_ARGS
, "%s", error
.message
);
1162 dbus_error_free(&error
);
1166 if (!(sink
= pa_namereg_get(c
->core
, sink_name
, PA_NAMEREG_SINK
))) {
1167 pa_dbus_send_error(conn
, msg
, PA_DBUS_ERROR_NOT_FOUND
, "%s: No such sink.", sink_name
);
1171 pa_assert_se((dbus_sink
= pa_hashmap_get(c
->sinks_by_index
, PA_UINT32_TO_PTR(sink
->index
))));
1173 object_path
= pa_dbusiface_device_get_path(dbus_sink
);
1175 pa_dbus_send_basic_value_reply(conn
, msg
, DBUS_TYPE_OBJECT_PATH
, &object_path
);
1178 static void handle_get_source_by_name(DBusConnection
*conn
, DBusMessage
*msg
, void *userdata
) {
1179 pa_dbusiface_core
*c
= userdata
;
1182 pa_dbusiface_device
*dbus_source
;
1183 const char *object_path
;
1190 dbus_error_init(&error
);
1192 if (!dbus_message_get_args(msg
, &error
, DBUS_TYPE_STRING
, &source_name
, DBUS_TYPE_INVALID
)) {
1193 pa_dbus_send_error(conn
, msg
, DBUS_ERROR_INVALID_ARGS
, "%s", error
.message
);
1194 dbus_error_free(&error
);
1198 if (!(source
= pa_namereg_get(c
->core
, source_name
, PA_NAMEREG_SOURCE
))) {
1199 pa_dbus_send_error(conn
, msg
, PA_DBUS_ERROR_NOT_FOUND
, "%s: No such source.", source_name
);
1203 pa_assert_se((dbus_source
= pa_hashmap_get(c
->sources_by_index
, PA_UINT32_TO_PTR(source
->index
))));
1205 object_path
= pa_dbusiface_device_get_path(dbus_source
);
1207 pa_dbus_send_basic_value_reply(conn
, msg
, DBUS_TYPE_OBJECT_PATH
, &object_path
);
1210 static void handle_get_sample_by_name(DBusConnection
*conn
, DBusMessage
*msg
, void *userdata
) {
1211 pa_dbusiface_core
*c
= userdata
;
1213 pa_scache_entry
*sample
;
1214 pa_dbusiface_sample
*dbus_sample
;
1215 const char *object_path
;
1222 dbus_error_init(&error
);
1224 if (!dbus_message_get_args(msg
, &error
, DBUS_TYPE_STRING
, &sample_name
, DBUS_TYPE_INVALID
)) {
1225 pa_dbus_send_error(conn
, msg
, DBUS_ERROR_INVALID_ARGS
, "%s", error
.message
);
1226 dbus_error_free(&error
);
1230 if (!(sample
= pa_namereg_get(c
->core
, sample_name
, PA_NAMEREG_SAMPLE
))) {
1231 pa_dbus_send_error(conn
, msg
, PA_DBUS_ERROR_NOT_FOUND
, "No such sample.");
1235 pa_assert_se((dbus_sample
= pa_hashmap_get(c
->samples
, PA_UINT32_TO_PTR(sample
->index
))));
1237 object_path
= pa_dbusiface_sample_get_path(dbus_sample
);
1239 pa_dbus_send_basic_value_reply(conn
, msg
, DBUS_TYPE_OBJECT_PATH
, &object_path
);
1242 static void handle_upload_sample(DBusConnection
*conn
, DBusMessage
*msg
, void *userdata
) {
1243 pa_dbusiface_core
*c
= userdata
;
1244 DBusMessageIter msg_iter
;
1246 dbus_uint32_t sample_format
;
1247 dbus_uint32_t sample_rate
;
1248 const dbus_uint32_t
*channels
;
1249 unsigned n_channels
;
1250 const dbus_uint32_t
*default_volume
;
1251 unsigned n_volume_entries
;
1252 pa_proplist
*property_list
;
1253 const uint8_t *data
;
1254 unsigned data_length
;
1260 pa_dbusiface_sample
*dbus_sample
= NULL
;
1261 pa_scache_entry
*sample
= NULL
;
1262 const char *object_path
;
1268 chunk
.memblock
= NULL
;
1270 if (!dbus_message_iter_init(msg
, &msg_iter
)) {
1271 pa_dbus_send_error(conn
, msg
, DBUS_ERROR_INVALID_ARGS
, "Too few arguments.");
1275 if (pa_dbus_get_basic_arg(conn
, msg
, &msg_iter
, DBUS_TYPE_STRING
, &name
) < 0)
1278 if (pa_dbus_get_basic_arg(conn
, msg
, &msg_iter
, DBUS_TYPE_UINT32
, &sample_format
) < 0)
1281 if (pa_dbus_get_basic_arg(conn
, msg
, &msg_iter
, DBUS_TYPE_UINT32
, &sample_rate
) < 0)
1284 if (pa_dbus_get_fixed_array_arg(conn
, msg
, &msg_iter
, DBUS_TYPE_UINT32
, &channels
, &n_channels
) < 0)
1287 if (pa_dbus_get_fixed_array_arg(conn
, msg
, &msg_iter
, DBUS_TYPE_UINT32
, &default_volume
, &n_volume_entries
) < 0)
1290 if (!(property_list
= pa_dbus_get_proplist_arg(conn
, msg
, &msg_iter
)))
1293 if (pa_dbus_get_fixed_array_arg(conn
, msg
, &msg_iter
, DBUS_TYPE_BYTE
, &data
, &data_length
) < 0)
1296 if (sample_format
>= PA_SAMPLE_MAX
) {
1297 pa_dbus_send_error(conn
, msg
, DBUS_ERROR_INVALID_ARGS
, "Invalid sample format.");
1301 if (sample_rate
<= 0 || sample_rate
> PA_RATE_MAX
) {
1302 pa_dbus_send_error(conn
, msg
, DBUS_ERROR_INVALID_ARGS
, "Invalid sample rate.");
1306 if (n_channels
== 0) {
1307 pa_dbus_send_error(conn
, msg
, DBUS_ERROR_INVALID_ARGS
, "Empty channel map.");
1311 if (n_channels
> PA_CHANNELS_MAX
) {
1312 pa_dbus_send_error(conn
, msg
, DBUS_ERROR_INVALID_ARGS
,
1313 "Too many channels: %u. The maximum is %u.", n_channels
, PA_CHANNELS_MAX
);
1317 for (i
= 0; i
< n_channels
; ++i
) {
1318 if (channels
[i
] >= PA_CHANNEL_POSITION_MAX
) {
1319 pa_dbus_send_error(conn
, msg
, DBUS_ERROR_INVALID_ARGS
, "Invalid channel position.");
1324 if (n_volume_entries
!= 0 && n_volume_entries
!= n_channels
) {
1325 pa_dbus_send_error(conn
, msg
, DBUS_ERROR_INVALID_ARGS
,
1326 "The channels and default_volume arguments have different number of elements.");
1330 for (i
= 0; i
< n_volume_entries
; ++i
) {
1331 if (default_volume
[i
] > PA_VOLUME_MAX
) {
1332 pa_dbus_send_error(conn
, msg
, DBUS_ERROR_INVALID_ARGS
, "Invalid volume.");
1337 if (data_length
== 0) {
1338 pa_dbus_send_error(conn
, msg
, DBUS_ERROR_INVALID_ARGS
, "Empty data.");
1342 if (data_length
> PA_SCACHE_ENTRY_SIZE_MAX
) {
1343 pa_dbus_send_error(conn
, msg
, DBUS_ERROR_INVALID_ARGS
, "Too big sample.");
1347 ss
.format
= sample_format
;
1348 ss
.rate
= sample_rate
;
1349 ss
.channels
= n_channels
;
1351 if (!pa_frame_aligned(data_length
, &ss
)) {
1352 pa_dbus_send_error(conn
, msg
, DBUS_ERROR_INVALID_ARGS
,
1353 "The sample length in bytes doesn't align with the sample format and channels.");
1357 map
.channels
= n_channels
;
1358 for (i
= 0; i
< n_channels
; ++i
)
1359 map
.map
[i
] = channels
[i
];
1361 chunk
.memblock
= pa_memblock_new(c
->core
->mempool
, data_length
);
1363 chunk
.length
= data_length
;
1365 memcpy(pa_memblock_acquire(chunk
.memblock
), data
, data_length
);
1366 pa_memblock_release(chunk
.memblock
);
1368 if (pa_scache_add_item(c
->core
, name
, &ss
, &map
, &chunk
, property_list
, &idx
) < 0) {
1369 pa_dbus_send_error(conn
, msg
, DBUS_ERROR_FAILED
, "Adding the sample failed.");
1373 sample
= pa_idxset_get_by_index(c
->core
->scache
, idx
);
1375 if (n_volume_entries
> 0) {
1376 sample
->volume
.channels
= n_channels
;
1377 for (i
= 0; i
< n_volume_entries
; ++i
)
1378 sample
->volume
.values
[i
] = default_volume
[i
];
1379 sample
->volume_is_set
= TRUE
;
1381 sample
->volume_is_set
= FALSE
;
1384 dbus_sample
= pa_dbusiface_sample_new(c
, sample
);
1385 pa_hashmap_put(c
->samples
, PA_UINT32_TO_PTR(idx
), dbus_sample
);
1387 object_path
= pa_dbusiface_sample_get_path(dbus_sample
);
1389 pa_dbus_send_basic_value_reply(conn
, msg
, DBUS_TYPE_OBJECT_PATH
, &object_path
);
1393 pa_proplist_free(property_list
);
1396 pa_memblock_unref(chunk
.memblock
);
1399 static pa_bool_t
contains_space(const char *string
) {
1404 for (p
= string
; *p
; ++p
) {
1412 static void handle_load_module(DBusConnection
*conn
, DBusMessage
*msg
, void *userdata
) {
1413 pa_dbusiface_core
*c
= userdata
;
1414 DBusMessageIter msg_iter
;
1415 DBusMessageIter dict_iter
;
1416 DBusMessageIter dict_entry_iter
;
1420 char *escaped_value
;
1421 pa_strbuf
*arg_buffer
= NULL
;
1423 pa_dbusiface_module
*dbus_module
;
1424 const char *object_path
;
1431 if (c
->core
->disallow_module_loading
) {
1432 pa_dbus_send_error(conn
, msg
, DBUS_ERROR_ACCESS_DENIED
, "The server is configured to disallow module loading.");
1436 if (!dbus_message_iter_init(msg
, &msg_iter
)) {
1437 pa_dbus_send_error(conn
, msg
, DBUS_ERROR_INVALID_ARGS
, "Too few arguments.");
1441 if (pa_dbus_get_basic_arg(conn
, msg
, &msg_iter
, DBUS_TYPE_STRING
, &name
) < 0)
1444 arg_type
= dbus_message_iter_get_arg_type(&msg_iter
);
1445 if (arg_type
!= DBUS_TYPE_ARRAY
) {
1446 if (arg_type
== DBUS_TYPE_INVALID
)
1447 pa_dbus_send_error(conn
, msg
, DBUS_ERROR_INVALID_ARGS
,
1448 "Too few arguments. A dictionary from strings to strings was expected.");
1450 pa_dbus_send_error(conn
, msg
, DBUS_ERROR_INVALID_ARGS
,
1451 "Wrong argument type: '%c'. An dictionary from strings to strings was expected.",
1456 arg_type
= dbus_message_iter_get_element_type(&msg_iter
);
1457 if (arg_type
!= DBUS_TYPE_DICT_ENTRY
) {
1458 pa_dbus_send_error(conn
, msg
, DBUS_ERROR_INVALID_ARGS
,
1459 "Wrong array element type: '%c'. A dict entry (string to string) was expected.", (char) arg_type
);
1463 arg_buffer
= pa_strbuf_new();
1465 dbus_message_iter_recurse(&msg_iter
, &dict_iter
);
1467 while (dbus_message_iter_get_arg_type(&dict_iter
) != DBUS_TYPE_INVALID
) {
1468 if (!pa_strbuf_isempty(arg_buffer
))
1469 pa_strbuf_putc(arg_buffer
, ' ');
1471 dbus_message_iter_recurse(&dict_iter
, &dict_entry_iter
);
1473 arg_type
= dbus_message_iter_get_arg_type(&dict_entry_iter
);
1474 if (arg_type
!= DBUS_TYPE_STRING
) {
1475 pa_dbus_send_error(conn
, msg
, DBUS_ERROR_INVALID_ARGS
,
1476 "Wrong dict key type: '%c'. A string was expected.", (char) arg_type
);
1480 dbus_message_iter_get_basic(&dict_entry_iter
, &key
);
1481 dbus_message_iter_next(&dict_entry_iter
);
1483 if (strlen(key
) <= 0 || !pa_ascii_valid(key
) || contains_space(key
)) {
1484 pa_dbus_send_error(conn
, msg
, DBUS_ERROR_INVALID_ARGS
, "Invalid module argument name: %s", key
);
1488 arg_type
= dbus_message_iter_get_arg_type(&dict_entry_iter
);
1489 if (arg_type
!= DBUS_TYPE_STRING
) {
1490 if (arg_type
== DBUS_TYPE_INVALID
)
1491 pa_dbus_send_error(conn
, msg
, DBUS_ERROR_INVALID_ARGS
, "Dict value missing.");
1493 pa_dbus_send_error(conn
, msg
, DBUS_ERROR_INVALID_ARGS
,
1494 "Wrong dict value type: '%c'. A string was expected.", (char) arg_type
);
1498 dbus_message_iter_get_basic(&dict_entry_iter
, &value
);
1500 dbus_message_iter_next(&dict_iter
);
1502 escaped_value
= pa_escape(value
, "\"");
1503 pa_strbuf_printf(arg_buffer
, "%s=\"%s\"", key
, escaped_value
);
1504 pa_xfree(escaped_value
);
1507 if (!(module
= pa_module_load(c
->core
, name
, pa_strbuf_tostring(arg_buffer
)))) {
1508 pa_dbus_send_error(conn
, msg
, DBUS_ERROR_FAILED
, "Failed to load module.");
1512 dbus_module
= pa_dbusiface_module_new(c
, module
);
1513 pa_hashmap_put(c
->modules
, PA_UINT32_TO_PTR(module
->index
), dbus_module
);
1515 object_path
= pa_dbusiface_module_get_path(dbus_module
);
1517 pa_dbus_send_basic_value_reply(conn
, msg
, DBUS_TYPE_OBJECT_PATH
, &object_path
);
1521 pa_strbuf_free(arg_buffer
);
1524 static void handle_exit(DBusConnection
*conn
, DBusMessage
*msg
, void *userdata
) {
1525 pa_dbusiface_core
*c
= userdata
;
1531 if (c
->core
->disallow_exit
) {
1532 pa_dbus_send_error(conn
, msg
, DBUS_ERROR_ACCESS_DENIED
, "The server is configured to disallow exiting.");
1536 pa_dbus_send_empty_reply(conn
, msg
);
1538 pa_core_exit(c
->core
, FALSE
, 0);
1541 static void handle_listen_for_signal(DBusConnection
*conn
, DBusMessage
*msg
, void *userdata
) {
1542 pa_dbusiface_core
*c
= userdata
;
1544 char **objects
= NULL
;
1552 dbus_error_init(&error
);
1554 if (!dbus_message_get_args(msg
, &error
,
1555 DBUS_TYPE_STRING
, &signal
,
1556 DBUS_TYPE_ARRAY
, DBUS_TYPE_OBJECT_PATH
, &objects
, &n_objects
,
1557 DBUS_TYPE_INVALID
)) {
1558 pa_dbus_send_error(conn
, msg
, DBUS_ERROR_INVALID_ARGS
, "%s", error
.message
);
1559 dbus_error_free(&error
);
1563 pa_dbus_protocol_add_signal_listener(c
->dbus_protocol
, conn
, *signal
? signal
: NULL
, objects
, n_objects
);
1565 pa_dbus_send_empty_reply(conn
, msg
);
1568 dbus_free_string_array(objects
);
1571 static void handle_stop_listening_for_signal(DBusConnection
*conn
, DBusMessage
*msg
, void *userdata
) {
1572 pa_dbusiface_core
*c
= userdata
;
1580 dbus_error_init(&error
);
1582 if (!dbus_message_get_args(msg
, &error
, DBUS_TYPE_STRING
, &signal
, DBUS_TYPE_INVALID
)) {
1583 pa_dbus_send_error(conn
, msg
, DBUS_ERROR_INVALID_ARGS
, "%s", error
.message
);
1584 dbus_error_free(&error
);
1588 pa_dbus_protocol_remove_signal_listener(c
->dbus_protocol
, conn
, *signal
? signal
: NULL
);
1590 pa_dbus_send_empty_reply(conn
, msg
);
1593 static void subscription_cb(pa_core
*core
, pa_subscription_event_type_t t
, uint32_t idx
, void *userdata
) {
1594 pa_dbusiface_core
*c
= userdata
;
1595 pa_dbusiface_card
*card
= NULL
;
1596 pa_dbusiface_device
*device
= NULL
;
1597 pa_dbusiface_stream
*stream
= NULL
;
1598 pa_dbusiface_sample
*sample
= NULL
;
1599 pa_dbusiface_module
*module
= NULL
;
1600 pa_dbusiface_client
*client
= NULL
;
1601 DBusMessage
*signal
= NULL
;
1602 const char *object_path
= NULL
;
1603 pa_sink
*new_fallback_sink
= NULL
;
1604 pa_source
*new_fallback_source
= NULL
;
1608 switch (t
& PA_SUBSCRIPTION_EVENT_FACILITY_MASK
) {
1609 case PA_SUBSCRIPTION_EVENT_SERVER
:
1610 new_fallback_sink
= pa_namereg_get_default_sink(core
);
1611 new_fallback_source
= pa_namereg_get_default_source(core
);
1613 if (c
->fallback_sink
!= new_fallback_sink
) {
1614 c
->fallback_sink
= new_fallback_sink
;
1616 if (new_fallback_sink
1617 && (device
= pa_hashmap_get(c
->sinks_by_index
, PA_UINT32_TO_PTR(new_fallback_sink
->index
)))) {
1618 object_path
= pa_dbusiface_device_get_path(device
);
1620 pa_assert_se((signal
= dbus_message_new_signal(PA_DBUS_CORE_OBJECT_PATH
,
1621 PA_DBUS_CORE_INTERFACE
,
1622 signals
[SIGNAL_FALLBACK_SINK_UPDATED
].name
)));
1623 pa_assert_se(dbus_message_append_args(signal
, DBUS_TYPE_OBJECT_PATH
, &object_path
, DBUS_TYPE_INVALID
));
1624 pa_dbus_protocol_send_signal(c
->dbus_protocol
, signal
);
1625 dbus_message_unref(signal
);
1630 if (c
->fallback_source
!= new_fallback_source
) {
1631 c
->fallback_source
= new_fallback_source
;
1633 if (new_fallback_source
1634 && (device
= pa_hashmap_get(c
->sources_by_index
, PA_UINT32_TO_PTR(new_fallback_source
->index
)))) {
1635 object_path
= pa_dbusiface_device_get_path(device
);
1637 pa_assert_se((signal
= dbus_message_new_signal(PA_DBUS_CORE_OBJECT_PATH
,
1638 PA_DBUS_CORE_INTERFACE
,
1639 signals
[SIGNAL_FALLBACK_SOURCE_UPDATED
].name
)));
1640 pa_assert_se(dbus_message_append_args(signal
, DBUS_TYPE_OBJECT_PATH
, &object_path
, DBUS_TYPE_INVALID
));
1641 pa_dbus_protocol_send_signal(c
->dbus_protocol
, signal
);
1642 dbus_message_unref(signal
);
1648 case PA_SUBSCRIPTION_EVENT_CARD
:
1649 if ((t
& PA_SUBSCRIPTION_EVENT_TYPE_MASK
) == PA_SUBSCRIPTION_EVENT_NEW
) {
1650 if (!(card
= pa_hashmap_get(c
->cards
, PA_UINT32_TO_PTR(idx
)))) {
1651 card
= pa_dbusiface_card_new(c
, pa_idxset_get_by_index(core
->cards
, idx
));
1652 pa_hashmap_put(c
->cards
, PA_UINT32_TO_PTR(idx
), card
);
1655 object_path
= pa_dbusiface_card_get_path(card
);
1657 pa_assert_se((signal
= dbus_message_new_signal(PA_DBUS_CORE_OBJECT_PATH
,
1658 PA_DBUS_CORE_INTERFACE
,
1659 signals
[SIGNAL_NEW_CARD
].name
)));
1660 pa_assert_se(dbus_message_append_args(signal
, DBUS_TYPE_OBJECT_PATH
, &object_path
, DBUS_TYPE_INVALID
));
1662 } else if ((t
& PA_SUBSCRIPTION_EVENT_TYPE_MASK
) == PA_SUBSCRIPTION_EVENT_REMOVE
) {
1663 pa_assert_se((card
= pa_hashmap_remove(c
->cards
, PA_UINT32_TO_PTR(idx
))));
1665 object_path
= pa_dbusiface_card_get_path(card
);
1667 pa_assert_se((signal
= dbus_message_new_signal(PA_DBUS_CORE_OBJECT_PATH
,
1668 PA_DBUS_CORE_INTERFACE
,
1669 signals
[SIGNAL_CARD_REMOVED
].name
)));
1670 pa_assert_se(dbus_message_append_args(signal
, DBUS_TYPE_OBJECT_PATH
, &object_path
, DBUS_TYPE_INVALID
));
1672 pa_dbusiface_card_free(card
);
1676 case PA_SUBSCRIPTION_EVENT_SINK
:
1677 if ((t
& PA_SUBSCRIPTION_EVENT_TYPE_MASK
) == PA_SUBSCRIPTION_EVENT_NEW
) {
1678 pa_sink
*sink
= pa_idxset_get_by_index(core
->sinks
, idx
);
1680 if (!(device
= pa_hashmap_get(c
->sinks_by_index
, PA_UINT32_TO_PTR(idx
)))) {
1681 device
= pa_dbusiface_device_new_sink(c
, sink
);
1682 pa_hashmap_put(c
->sinks_by_index
, PA_UINT32_TO_PTR(idx
), device
);
1683 pa_hashmap_put(c
->sinks_by_path
, pa_dbusiface_device_get_path(device
), device
);
1686 object_path
= pa_dbusiface_device_get_path(device
);
1688 pa_assert_se((signal
= dbus_message_new_signal(PA_DBUS_CORE_OBJECT_PATH
,
1689 PA_DBUS_CORE_INTERFACE
,
1690 signals
[SIGNAL_NEW_SINK
].name
)));
1691 pa_assert_se(dbus_message_append_args(signal
, DBUS_TYPE_OBJECT_PATH
, &object_path
, DBUS_TYPE_INVALID
));
1693 pa_dbus_protocol_send_signal(c
->dbus_protocol
, signal
);
1694 dbus_message_unref(signal
);
1697 if (c
->fallback_sink
&& pa_streq(c
->fallback_sink
->name
, sink
->name
)) {
1698 /* We have got default sink change event, but at that point
1699 * the D-Bus sink object wasn't created yet. Now that the
1700 * object is created, let's send the fallback sink change
1702 pa_assert_se((signal
= dbus_message_new_signal(PA_DBUS_CORE_OBJECT_PATH
,
1703 PA_DBUS_CORE_INTERFACE
,
1704 signals
[SIGNAL_FALLBACK_SINK_UPDATED
].name
)));
1705 pa_assert_se(dbus_message_append_args(signal
, DBUS_TYPE_OBJECT_PATH
, &object_path
, DBUS_TYPE_INVALID
));
1707 pa_dbus_protocol_send_signal(c
->dbus_protocol
, signal
);
1708 dbus_message_unref(signal
);
1712 } else if ((t
& PA_SUBSCRIPTION_EVENT_TYPE_MASK
) == PA_SUBSCRIPTION_EVENT_REMOVE
) {
1713 pa_assert_se((device
= pa_hashmap_remove(c
->sinks_by_index
, PA_UINT32_TO_PTR(idx
))));
1714 object_path
= pa_dbusiface_device_get_path(device
);
1715 pa_assert_se(pa_hashmap_remove(c
->sinks_by_path
, object_path
));
1717 pa_assert_se((signal
= dbus_message_new_signal(PA_DBUS_CORE_OBJECT_PATH
,
1718 PA_DBUS_CORE_INTERFACE
,
1719 signals
[SIGNAL_SINK_REMOVED
].name
)));
1720 pa_assert_se(dbus_message_append_args(signal
, DBUS_TYPE_OBJECT_PATH
, &object_path
, DBUS_TYPE_INVALID
));
1722 pa_dbusiface_device_free(device
);
1726 case PA_SUBSCRIPTION_EVENT_SOURCE
:
1727 if ((t
& PA_SUBSCRIPTION_EVENT_TYPE_MASK
) == PA_SUBSCRIPTION_EVENT_NEW
) {
1728 pa_source
*source
= pa_idxset_get_by_index(core
->sources
, idx
);
1730 if (!(device
= pa_hashmap_get(c
->sources_by_index
, PA_UINT32_TO_PTR(idx
)))) {
1731 device
= pa_dbusiface_device_new_source(c
, source
);
1732 pa_hashmap_put(c
->sources_by_index
, PA_UINT32_TO_PTR(idx
), device
);
1733 pa_hashmap_put(c
->sources_by_path
, pa_dbusiface_device_get_path(device
), device
);
1736 object_path
= pa_dbusiface_device_get_path(device
);
1738 pa_assert_se((signal
= dbus_message_new_signal(PA_DBUS_CORE_OBJECT_PATH
,
1739 PA_DBUS_CORE_INTERFACE
,
1740 signals
[SIGNAL_NEW_SOURCE
].name
)));
1741 pa_assert_se(dbus_message_append_args(signal
, DBUS_TYPE_OBJECT_PATH
, &object_path
, DBUS_TYPE_INVALID
));
1743 pa_dbus_protocol_send_signal(c
->dbus_protocol
, signal
);
1744 dbus_message_unref(signal
);
1747 if (c
->fallback_source
&& pa_streq(c
->fallback_source
->name
, source
->name
)) {
1748 /* We have got default source change event, but at that
1749 * point the D-Bus source object wasn't created yet. Now
1750 * that the object is created, let's send the fallback
1751 * source change signal. */
1752 pa_assert_se((signal
= dbus_message_new_signal(PA_DBUS_CORE_OBJECT_PATH
,
1753 PA_DBUS_CORE_INTERFACE
,
1754 signals
[SIGNAL_FALLBACK_SOURCE_UPDATED
].name
)));
1755 pa_assert_se(dbus_message_append_args(signal
, DBUS_TYPE_OBJECT_PATH
, &object_path
, DBUS_TYPE_INVALID
));
1757 pa_dbus_protocol_send_signal(c
->dbus_protocol
, signal
);
1758 dbus_message_unref(signal
);
1762 } else if ((t
& PA_SUBSCRIPTION_EVENT_TYPE_MASK
) == PA_SUBSCRIPTION_EVENT_REMOVE
) {
1763 pa_assert_se((device
= pa_hashmap_remove(c
->sources_by_index
, PA_UINT32_TO_PTR(idx
))));
1764 object_path
= pa_dbusiface_device_get_path(device
);
1765 pa_assert_se(pa_hashmap_remove(c
->sources_by_path
, object_path
));
1767 pa_assert_se((signal
= dbus_message_new_signal(PA_DBUS_CORE_OBJECT_PATH
,
1768 PA_DBUS_CORE_INTERFACE
,
1769 signals
[SIGNAL_SOURCE_REMOVED
].name
)));
1770 pa_assert_se(dbus_message_append_args(signal
, DBUS_TYPE_OBJECT_PATH
, &object_path
, DBUS_TYPE_INVALID
));
1772 pa_dbusiface_device_free(device
);
1776 case PA_SUBSCRIPTION_EVENT_SINK_INPUT
:
1777 if ((t
& PA_SUBSCRIPTION_EVENT_TYPE_MASK
) == PA_SUBSCRIPTION_EVENT_NEW
) {
1778 if (!(stream
= pa_hashmap_get(c
->playback_streams
, PA_UINT32_TO_PTR(idx
)))) {
1779 stream
= pa_dbusiface_stream_new_playback(c
, pa_idxset_get_by_index(core
->sink_inputs
, idx
));
1780 pa_hashmap_put(c
->playback_streams
, PA_UINT32_TO_PTR(idx
), stream
);
1783 object_path
= pa_dbusiface_stream_get_path(stream
);
1785 pa_assert_se((signal
= dbus_message_new_signal(PA_DBUS_CORE_OBJECT_PATH
,
1786 PA_DBUS_CORE_INTERFACE
,
1787 signals
[SIGNAL_NEW_PLAYBACK_STREAM
].name
)));
1788 pa_assert_se(dbus_message_append_args(signal
, DBUS_TYPE_OBJECT_PATH
, &object_path
, DBUS_TYPE_INVALID
));
1790 } else if ((t
& PA_SUBSCRIPTION_EVENT_TYPE_MASK
) == PA_SUBSCRIPTION_EVENT_REMOVE
) {
1791 pa_assert_se((stream
= pa_hashmap_remove(c
->playback_streams
, PA_UINT32_TO_PTR(idx
))));
1793 object_path
= pa_dbusiface_stream_get_path(stream
);
1795 pa_assert_se((signal
= dbus_message_new_signal(PA_DBUS_CORE_OBJECT_PATH
,
1796 PA_DBUS_CORE_INTERFACE
,
1797 signals
[SIGNAL_PLAYBACK_STREAM_REMOVED
].name
)));
1798 pa_assert_se(dbus_message_append_args(signal
, DBUS_TYPE_OBJECT_PATH
, &object_path
, DBUS_TYPE_INVALID
));
1800 pa_dbusiface_stream_free(stream
);
1804 case PA_SUBSCRIPTION_EVENT_SOURCE_OUTPUT
:
1805 if ((t
& PA_SUBSCRIPTION_EVENT_TYPE_MASK
) == PA_SUBSCRIPTION_EVENT_NEW
) {
1806 if (!(stream
= pa_hashmap_get(c
->record_streams
, PA_UINT32_TO_PTR(idx
)))) {
1807 stream
= pa_dbusiface_stream_new_record(c
, pa_idxset_get_by_index(core
->source_outputs
, idx
));
1808 pa_hashmap_put(c
->record_streams
, PA_UINT32_TO_PTR(idx
), stream
);
1811 object_path
= pa_dbusiface_stream_get_path(stream
);
1813 pa_assert_se((signal
= dbus_message_new_signal(PA_DBUS_CORE_OBJECT_PATH
,
1814 PA_DBUS_CORE_INTERFACE
,
1815 signals
[SIGNAL_NEW_RECORD_STREAM
].name
)));
1816 pa_assert_se(dbus_message_append_args(signal
, DBUS_TYPE_OBJECT_PATH
, &object_path
, DBUS_TYPE_INVALID
));
1818 } else if ((t
& PA_SUBSCRIPTION_EVENT_TYPE_MASK
) == PA_SUBSCRIPTION_EVENT_REMOVE
) {
1819 pa_assert_se((stream
= pa_hashmap_remove(c
->record_streams
, PA_UINT32_TO_PTR(idx
))));
1821 object_path
= pa_dbusiface_stream_get_path(stream
);
1823 pa_assert_se((signal
= dbus_message_new_signal(PA_DBUS_CORE_OBJECT_PATH
,
1824 PA_DBUS_CORE_INTERFACE
,
1825 signals
[SIGNAL_RECORD_STREAM_REMOVED
].name
)));
1826 pa_assert_se(dbus_message_append_args(signal
, DBUS_TYPE_OBJECT_PATH
, &object_path
, DBUS_TYPE_INVALID
));
1828 pa_dbusiface_stream_free(stream
);
1832 case PA_SUBSCRIPTION_EVENT_SAMPLE_CACHE
:
1833 if ((t
& PA_SUBSCRIPTION_EVENT_TYPE_MASK
) == PA_SUBSCRIPTION_EVENT_NEW
) {
1834 if (!(sample
= pa_hashmap_get(c
->samples
, PA_UINT32_TO_PTR(idx
)))) {
1835 sample
= pa_dbusiface_sample_new(c
, pa_idxset_get_by_index(core
->scache
, idx
));
1836 pa_hashmap_put(c
->samples
, PA_UINT32_TO_PTR(idx
), sample
);
1839 object_path
= pa_dbusiface_sample_get_path(sample
);
1841 pa_assert_se((signal
= dbus_message_new_signal(PA_DBUS_CORE_OBJECT_PATH
,
1842 PA_DBUS_CORE_INTERFACE
,
1843 signals
[SIGNAL_NEW_SAMPLE
].name
)));
1844 pa_assert_se(dbus_message_append_args(signal
, DBUS_TYPE_OBJECT_PATH
, &object_path
, DBUS_TYPE_INVALID
));
1846 } else if ((t
& PA_SUBSCRIPTION_EVENT_TYPE_MASK
) == PA_SUBSCRIPTION_EVENT_REMOVE
) {
1847 pa_assert_se((sample
= pa_hashmap_remove(c
->samples
, PA_UINT32_TO_PTR(idx
))));
1849 object_path
= pa_dbusiface_sample_get_path(sample
);
1851 pa_assert_se((signal
= dbus_message_new_signal(PA_DBUS_CORE_OBJECT_PATH
,
1852 PA_DBUS_CORE_INTERFACE
,
1853 signals
[SIGNAL_SAMPLE_REMOVED
].name
)));
1854 pa_assert_se(dbus_message_append_args(signal
, DBUS_TYPE_OBJECT_PATH
, &object_path
, DBUS_TYPE_INVALID
));
1856 pa_dbusiface_sample_free(sample
);
1860 case PA_SUBSCRIPTION_EVENT_MODULE
:
1861 if ((t
& PA_SUBSCRIPTION_EVENT_TYPE_MASK
) == PA_SUBSCRIPTION_EVENT_NEW
) {
1862 if (!(module
= pa_hashmap_get(c
->modules
, PA_UINT32_TO_PTR(idx
)))) {
1863 module
= pa_dbusiface_module_new(c
, pa_idxset_get_by_index(core
->modules
, idx
));
1864 pa_hashmap_put(c
->modules
, PA_UINT32_TO_PTR(idx
), module
);
1867 object_path
= pa_dbusiface_module_get_path(module
);
1869 pa_assert_se((signal
= dbus_message_new_signal(PA_DBUS_CORE_OBJECT_PATH
,
1870 PA_DBUS_CORE_INTERFACE
,
1871 signals
[SIGNAL_NEW_MODULE
].name
)));
1872 pa_assert_se(dbus_message_append_args(signal
, DBUS_TYPE_OBJECT_PATH
, &object_path
, DBUS_TYPE_INVALID
));
1874 } else if ((t
& PA_SUBSCRIPTION_EVENT_TYPE_MASK
) == PA_SUBSCRIPTION_EVENT_REMOVE
) {
1875 pa_assert_se((module
= pa_hashmap_remove(c
->modules
, PA_UINT32_TO_PTR(idx
))));
1877 object_path
= pa_dbusiface_module_get_path(module
);
1879 pa_assert_se((signal
= dbus_message_new_signal(PA_DBUS_CORE_OBJECT_PATH
,
1880 PA_DBUS_CORE_INTERFACE
,
1881 signals
[SIGNAL_MODULE_REMOVED
].name
)));
1882 pa_assert_se(dbus_message_append_args(signal
, DBUS_TYPE_OBJECT_PATH
, &object_path
, DBUS_TYPE_INVALID
));
1884 pa_dbusiface_module_free(module
);
1888 case PA_SUBSCRIPTION_EVENT_CLIENT
:
1889 if ((t
& PA_SUBSCRIPTION_EVENT_TYPE_MASK
) == PA_SUBSCRIPTION_EVENT_NEW
) {
1890 if (!(client
= pa_hashmap_get(c
->clients
, PA_UINT32_TO_PTR(idx
)))) {
1891 client
= pa_dbusiface_client_new(c
, pa_idxset_get_by_index(core
->clients
, idx
));
1892 pa_hashmap_put(c
->clients
, PA_UINT32_TO_PTR(idx
), client
);
1895 object_path
= pa_dbusiface_client_get_path(client
);
1897 pa_assert_se((signal
= dbus_message_new_signal(PA_DBUS_CORE_OBJECT_PATH
,
1898 PA_DBUS_CORE_INTERFACE
,
1899 signals
[SIGNAL_NEW_CLIENT
].name
)));
1900 pa_assert_se(dbus_message_append_args(signal
, DBUS_TYPE_OBJECT_PATH
, &object_path
, DBUS_TYPE_INVALID
));
1902 } else if ((t
& PA_SUBSCRIPTION_EVENT_TYPE_MASK
) == PA_SUBSCRIPTION_EVENT_REMOVE
) {
1903 pa_assert_se((client
= pa_hashmap_remove(c
->clients
, PA_UINT32_TO_PTR(idx
))));
1905 object_path
= pa_dbusiface_client_get_path(client
);
1907 pa_assert_se((signal
= dbus_message_new_signal(PA_DBUS_CORE_OBJECT_PATH
,
1908 PA_DBUS_CORE_INTERFACE
,
1909 signals
[SIGNAL_CLIENT_REMOVED
].name
)));
1910 pa_assert_se(dbus_message_append_args(signal
, DBUS_TYPE_OBJECT_PATH
, &object_path
, DBUS_TYPE_INVALID
));
1912 pa_dbusiface_client_free(client
);
1918 pa_dbus_protocol_send_signal(c
->dbus_protocol
, signal
);
1919 dbus_message_unref(signal
);
1923 static pa_hook_result_t
extension_registered_cb(void *hook_data
, void *call_data
, void *slot_data
) {
1924 pa_dbusiface_core
*c
= slot_data
;
1925 const char *ext_name
= call_data
;
1926 DBusMessage
*signal
= NULL
;
1929 pa_assert(ext_name
);
1931 pa_assert_se((signal
= dbus_message_new_signal(PA_DBUS_CORE_OBJECT_PATH
,
1932 PA_DBUS_CORE_INTERFACE
,
1933 signals
[SIGNAL_NEW_EXTENSION
].name
)));
1934 pa_assert_se(dbus_message_append_args(signal
, DBUS_TYPE_STRING
, &ext_name
, DBUS_TYPE_INVALID
));
1936 pa_dbus_protocol_send_signal(c
->dbus_protocol
, signal
);
1937 dbus_message_unref(signal
);
1942 static pa_hook_result_t
extension_unregistered_cb(void *hook_data
, void *call_data
, void *slot_data
) {
1943 pa_dbusiface_core
*c
= slot_data
;
1944 const char *ext_name
= call_data
;
1945 DBusMessage
*signal
= NULL
;
1948 pa_assert(ext_name
);
1950 pa_assert_se((signal
= dbus_message_new_signal(PA_DBUS_CORE_OBJECT_PATH
,
1951 PA_DBUS_CORE_INTERFACE
,
1952 signals
[SIGNAL_EXTENSION_REMOVED
].name
)));
1953 pa_assert_se(dbus_message_append_args(signal
, DBUS_TYPE_STRING
, &ext_name
, DBUS_TYPE_INVALID
));
1955 pa_dbus_protocol_send_signal(c
->dbus_protocol
, signal
);
1956 dbus_message_unref(signal
);
1961 pa_dbusiface_core
*pa_dbusiface_core_new(pa_core
*core
) {
1962 pa_dbusiface_core
*c
;
1966 pa_dbusiface_device
*device
;
1967 pa_sink_input
*sink_input
;
1968 pa_source_output
*source_output
;
1969 pa_scache_entry
*sample
;
1976 c
= pa_xnew(pa_dbusiface_core
, 1);
1977 c
->core
= pa_core_ref(core
);
1978 c
->subscription
= pa_subscription_new(core
, PA_SUBSCRIPTION_MASK_ALL
, subscription_cb
, c
);
1979 c
->dbus_protocol
= pa_dbus_protocol_get(core
);
1980 c
->cards
= pa_hashmap_new(pa_idxset_trivial_hash_func
, pa_idxset_trivial_compare_func
);
1981 c
->sinks_by_index
= pa_hashmap_new(pa_idxset_trivial_hash_func
, pa_idxset_trivial_compare_func
);
1982 c
->sinks_by_path
= pa_hashmap_new(pa_idxset_string_hash_func
, pa_idxset_string_compare_func
);
1983 c
->sources_by_index
= pa_hashmap_new(pa_idxset_trivial_hash_func
, pa_idxset_trivial_compare_func
);
1984 c
->sources_by_path
= pa_hashmap_new(pa_idxset_string_hash_func
, pa_idxset_string_compare_func
);
1985 c
->playback_streams
= pa_hashmap_new(pa_idxset_trivial_hash_func
, pa_idxset_trivial_compare_func
);
1986 c
->record_streams
= pa_hashmap_new(pa_idxset_trivial_hash_func
, pa_idxset_trivial_compare_func
);
1987 c
->samples
= pa_hashmap_new(pa_idxset_trivial_hash_func
, pa_idxset_trivial_compare_func
);
1988 c
->modules
= pa_hashmap_new(pa_idxset_trivial_hash_func
, pa_idxset_trivial_compare_func
);
1989 c
->clients
= pa_hashmap_new(pa_idxset_trivial_hash_func
, pa_idxset_trivial_compare_func
);
1990 c
->fallback_sink
= pa_namereg_get_default_sink(core
);
1991 c
->fallback_source
= pa_namereg_get_default_source(core
);
1992 c
->extension_registered_slot
= pa_dbus_protocol_hook_connect(c
->dbus_protocol
,
1993 PA_DBUS_PROTOCOL_HOOK_EXTENSION_REGISTERED
,
1995 extension_registered_cb
,
1997 c
->extension_unregistered_slot
= pa_dbus_protocol_hook_connect(c
->dbus_protocol
,
1998 PA_DBUS_PROTOCOL_HOOK_EXTENSION_UNREGISTERED
,
2000 extension_unregistered_cb
,
2002 c
->memstats
= pa_dbusiface_memstats_new(c
, core
);
2004 PA_IDXSET_FOREACH(card
, core
->cards
, idx
)
2005 pa_hashmap_put(c
->cards
, PA_UINT32_TO_PTR(idx
), pa_dbusiface_card_new(c
, card
));
2007 PA_IDXSET_FOREACH(sink
, core
->sinks
, idx
) {
2008 device
= pa_dbusiface_device_new_sink(c
, sink
);
2009 pa_hashmap_put(c
->sinks_by_index
, PA_UINT32_TO_PTR(idx
), device
);
2010 pa_hashmap_put(c
->sinks_by_path
, pa_dbusiface_device_get_path(device
), device
);
2013 PA_IDXSET_FOREACH(source
, core
->sources
, idx
) {
2014 device
= pa_dbusiface_device_new_source(c
, source
);
2015 pa_hashmap_put(c
->sources_by_index
, PA_UINT32_TO_PTR(idx
), device
);
2016 pa_hashmap_put(c
->sources_by_path
, pa_dbusiface_device_get_path(device
), device
);
2019 PA_IDXSET_FOREACH(sink_input
, core
->sink_inputs
, idx
)
2020 pa_hashmap_put(c
->playback_streams
, PA_UINT32_TO_PTR(idx
), pa_dbusiface_stream_new_playback(c
, sink_input
));
2022 PA_IDXSET_FOREACH(source_output
, core
->source_outputs
, idx
)
2023 pa_hashmap_put(c
->record_streams
, PA_UINT32_TO_PTR(idx
), pa_dbusiface_stream_new_record(c
, source_output
));
2025 PA_IDXSET_FOREACH(sample
, core
->scache
, idx
)
2026 pa_hashmap_put(c
->samples
, PA_UINT32_TO_PTR(idx
), pa_dbusiface_sample_new(c
, sample
));
2028 PA_IDXSET_FOREACH(module
, core
->modules
, idx
)
2029 pa_hashmap_put(c
->modules
, PA_UINT32_TO_PTR(idx
), pa_dbusiface_module_new(c
, module
));
2031 PA_IDXSET_FOREACH(client
, core
->clients
, idx
)
2032 pa_hashmap_put(c
->clients
, PA_UINT32_TO_PTR(idx
), pa_dbusiface_client_new(c
, client
));
2034 pa_assert_se(pa_dbus_protocol_add_interface(c
->dbus_protocol
, PA_DBUS_CORE_OBJECT_PATH
, &core_interface_info
, c
) >= 0);
2039 static void free_card_cb(void *p
, void *userdata
) {
2040 pa_dbusiface_card
*c
= p
;
2044 pa_dbusiface_card_free(c
);
2047 static void free_device_cb(void *p
, void *userdata
) {
2048 pa_dbusiface_device
*d
= p
;
2052 pa_dbusiface_device_free(d
);
2055 static void free_stream_cb(void *p
, void *userdata
) {
2056 pa_dbusiface_stream
*s
= p
;
2060 pa_dbusiface_stream_free(s
);
2063 static void free_sample_cb(void *p
, void *userdata
) {
2064 pa_dbusiface_sample
*s
= p
;
2068 pa_dbusiface_sample_free(s
);
2071 static void free_module_cb(void *p
, void *userdata
) {
2072 pa_dbusiface_module
*m
= p
;
2076 pa_dbusiface_module_free(m
);
2079 static void free_client_cb(void *p
, void *userdata
) {
2080 pa_dbusiface_client
*c
= p
;
2084 pa_dbusiface_client_free(c
);
2087 void pa_dbusiface_core_free(pa_dbusiface_core
*c
) {
2090 pa_assert_se(pa_dbus_protocol_remove_interface(c
->dbus_protocol
, PA_DBUS_CORE_OBJECT_PATH
, core_interface_info
.name
) >= 0);
2092 pa_subscription_free(c
->subscription
);
2093 pa_hashmap_free(c
->cards
, free_card_cb
, NULL
);
2094 pa_hashmap_free(c
->sinks_by_index
, free_device_cb
, NULL
);
2095 pa_hashmap_free(c
->sinks_by_path
, NULL
, NULL
);
2096 pa_hashmap_free(c
->sources_by_index
, free_device_cb
, NULL
);
2097 pa_hashmap_free(c
->sources_by_path
, NULL
, NULL
);
2098 pa_hashmap_free(c
->playback_streams
, free_stream_cb
, NULL
);
2099 pa_hashmap_free(c
->record_streams
, free_stream_cb
, NULL
);
2100 pa_hashmap_free(c
->samples
, free_sample_cb
, NULL
);
2101 pa_hashmap_free(c
->modules
, free_module_cb
, NULL
);
2102 pa_hashmap_free(c
->clients
, free_client_cb
, NULL
);
2103 pa_hook_slot_free(c
->extension_registered_slot
);
2104 pa_hook_slot_free(c
->extension_unregistered_slot
);
2105 pa_dbusiface_memstats_free(c
->memstats
);
2107 pa_dbus_protocol_unref(c
->dbus_protocol
);
2108 pa_core_unref(c
->core
);
2113 const char *pa_dbusiface_core_get_card_path(pa_dbusiface_core
*c
, const pa_card
*card
) {
2117 return pa_dbusiface_card_get_path(pa_hashmap_get(c
->cards
, PA_UINT32_TO_PTR(card
->index
)));
2120 const char *pa_dbusiface_core_get_sink_path(pa_dbusiface_core
*c
, const pa_sink
*sink
) {
2124 return pa_dbusiface_device_get_path(pa_hashmap_get(c
->sinks_by_index
, PA_UINT32_TO_PTR(sink
->index
)));
2127 const char *pa_dbusiface_core_get_source_path(pa_dbusiface_core
*c
, const pa_source
*source
) {
2131 return pa_dbusiface_device_get_path(pa_hashmap_get(c
->sources_by_index
, PA_UINT32_TO_PTR(source
->index
)));
2134 const char *pa_dbusiface_core_get_playback_stream_path(pa_dbusiface_core
*c
, const pa_sink_input
*sink_input
) {
2136 pa_assert(sink_input
);
2138 return pa_dbusiface_stream_get_path(pa_hashmap_get(c
->playback_streams
, PA_UINT32_TO_PTR(sink_input
->index
)));
2141 const char *pa_dbusiface_core_get_record_stream_path(pa_dbusiface_core
*c
, const pa_source_output
*source_output
) {
2143 pa_assert(source_output
);
2145 return pa_dbusiface_stream_get_path(pa_hashmap_get(c
->record_streams
, PA_UINT32_TO_PTR(source_output
->index
)));
2148 const char *pa_dbusiface_core_get_module_path(pa_dbusiface_core
*c
, const pa_module
*module
) {
2152 return pa_dbusiface_module_get_path(pa_hashmap_get(c
->modules
, PA_UINT32_TO_PTR(module
->index
)));
2155 const char *pa_dbusiface_core_get_client_path(pa_dbusiface_core
*c
, const pa_client
*client
) {
2159 return pa_dbusiface_client_get_path(pa_hashmap_get(c
->clients
, PA_UINT32_TO_PTR(client
->index
)));
2162 pa_sink
*pa_dbusiface_core_get_sink(pa_dbusiface_core
*c
, const char *object_path
) {
2163 pa_dbusiface_device
*device
= NULL
;
2166 pa_assert(object_path
);
2168 device
= pa_hashmap_get(c
->sinks_by_path
, object_path
);
2171 return pa_dbusiface_device_get_sink(device
);
2176 pa_source
*pa_dbusiface_core_get_source(pa_dbusiface_core
*c
, const char *object_path
) {
2177 pa_dbusiface_device
*device
= NULL
;
2180 pa_assert(object_path
);
2182 device
= pa_hashmap_get(c
->sources_by_path
, object_path
);
2185 return pa_dbusiface_device_get_source(device
);