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_alternate_sample_rate(DBusConnection
*conn
, DBusMessage
*msg
, void *userdata
);
66 static void handle_set_alternate_sample_rate(DBusConnection
*conn
, DBusMessage
*msg
, DBusMessageIter
*iter
, void *userdata
);
67 static void handle_get_cards(DBusConnection
*conn
, DBusMessage
*msg
, void *userdata
);
68 static void handle_get_sinks(DBusConnection
*conn
, DBusMessage
*msg
, void *userdata
);
69 static void handle_get_fallback_sink(DBusConnection
*conn
, DBusMessage
*msg
, void *userdata
);
70 static void handle_set_fallback_sink(DBusConnection
*conn
, DBusMessage
*msg
, DBusMessageIter
*iter
, void *userdata
);
71 static void handle_get_sources(DBusConnection
*conn
, DBusMessage
*msg
, void *userdata
);
72 static void handle_get_fallback_source(DBusConnection
*conn
, DBusMessage
*msg
, void *userdata
);
73 static void handle_set_fallback_source(DBusConnection
*conn
, DBusMessage
*msg
, DBusMessageIter
*iter
, void *userdata
);
74 static void handle_get_playback_streams(DBusConnection
*conn
, DBusMessage
*msg
, void *userdata
);
75 static void handle_get_record_streams(DBusConnection
*conn
, DBusMessage
*msg
, void *userdata
);
76 static void handle_get_samples(DBusConnection
*conn
, DBusMessage
*msg
, void *userdata
);
77 static void handle_get_modules(DBusConnection
*conn
, DBusMessage
*msg
, void *userdata
);
78 static void handle_get_clients(DBusConnection
*conn
, DBusMessage
*msg
, void *userdata
);
79 static void handle_get_my_client(DBusConnection
*conn
, DBusMessage
*msg
, void *userdata
);
80 static void handle_get_extensions(DBusConnection
*conn
, DBusMessage
*msg
, void *userdata
);
82 static void handle_get_all(DBusConnection
*conn
, DBusMessage
*msg
, void *userdata
);
84 static void handle_get_card_by_name(DBusConnection
*conn
, DBusMessage
*msg
, void *userdata
);
85 static void handle_get_sink_by_name(DBusConnection
*conn
, DBusMessage
*msg
, void *userdata
);
86 static void handle_get_source_by_name(DBusConnection
*conn
, DBusMessage
*msg
, void *userdata
);
87 static void handle_get_sample_by_name(DBusConnection
*conn
, DBusMessage
*msg
, void *userdata
);
88 static void handle_upload_sample(DBusConnection
*conn
, DBusMessage
*msg
, void *userdata
);
89 static void handle_load_module(DBusConnection
*conn
, DBusMessage
*msg
, void *userdata
);
90 static void handle_exit(DBusConnection
*conn
, DBusMessage
*msg
, void *userdata
);
91 static void handle_listen_for_signal(DBusConnection
*conn
, DBusMessage
*msg
, void *userdata
);
92 static void handle_stop_listening_for_signal(DBusConnection
*conn
, DBusMessage
*msg
, void *userdata
);
94 struct pa_dbusiface_core
{
96 pa_subscription
*subscription
;
98 pa_dbus_protocol
*dbus_protocol
;
101 pa_hashmap
*sinks_by_index
;
102 pa_hashmap
*sinks_by_path
;
103 pa_hashmap
*sources_by_index
;
104 pa_hashmap
*sources_by_path
;
105 pa_hashmap
*playback_streams
;
106 pa_hashmap
*record_streams
;
111 pa_sink
*fallback_sink
;
112 pa_source
*fallback_source
;
114 pa_hook_slot
*sink_put_slot
;
115 pa_hook_slot
*sink_unlink_slot
;
116 pa_hook_slot
*source_put_slot
;
117 pa_hook_slot
*source_unlink_slot
;
118 pa_hook_slot
*extension_registered_slot
;
119 pa_hook_slot
*extension_unregistered_slot
;
121 pa_dbusiface_memstats
*memstats
;
124 enum property_handler_index
{
125 PROPERTY_HANDLER_INTERFACE_REVISION
,
126 PROPERTY_HANDLER_NAME
,
127 PROPERTY_HANDLER_VERSION
,
128 PROPERTY_HANDLER_IS_LOCAL
,
129 PROPERTY_HANDLER_USERNAME
,
130 PROPERTY_HANDLER_HOSTNAME
,
131 PROPERTY_HANDLER_DEFAULT_CHANNELS
,
132 PROPERTY_HANDLER_DEFAULT_SAMPLE_FORMAT
,
133 PROPERTY_HANDLER_DEFAULT_SAMPLE_RATE
,
134 PROPERTY_HANDLER_ALTERNATE_SAMPLE_RATE
,
135 PROPERTY_HANDLER_CARDS
,
136 PROPERTY_HANDLER_SINKS
,
137 PROPERTY_HANDLER_FALLBACK_SINK
,
138 PROPERTY_HANDLER_SOURCES
,
139 PROPERTY_HANDLER_FALLBACK_SOURCE
,
140 PROPERTY_HANDLER_PLAYBACK_STREAMS
,
141 PROPERTY_HANDLER_RECORD_STREAMS
,
142 PROPERTY_HANDLER_SAMPLES
,
143 PROPERTY_HANDLER_MODULES
,
144 PROPERTY_HANDLER_CLIENTS
,
145 PROPERTY_HANDLER_MY_CLIENT
,
146 PROPERTY_HANDLER_EXTENSIONS
,
150 static pa_dbus_property_handler property_handlers
[PROPERTY_HANDLER_MAX
] = {
151 [PROPERTY_HANDLER_INTERFACE_REVISION
] = { .property_name
= "InterfaceRevision", .type
= "u", .get_cb
= handle_get_interface_revision
, .set_cb
= NULL
},
152 [PROPERTY_HANDLER_NAME
] = { .property_name
= "Name", .type
= "s", .get_cb
= handle_get_name
, .set_cb
= NULL
},
153 [PROPERTY_HANDLER_VERSION
] = { .property_name
= "Version", .type
= "s", .get_cb
= handle_get_version
, .set_cb
= NULL
},
154 [PROPERTY_HANDLER_IS_LOCAL
] = { .property_name
= "IsLocal", .type
= "b", .get_cb
= handle_get_is_local
, .set_cb
= NULL
},
155 [PROPERTY_HANDLER_USERNAME
] = { .property_name
= "Username", .type
= "s", .get_cb
= handle_get_username
, .set_cb
= NULL
},
156 [PROPERTY_HANDLER_HOSTNAME
] = { .property_name
= "Hostname", .type
= "s", .get_cb
= handle_get_hostname
, .set_cb
= NULL
},
157 [PROPERTY_HANDLER_DEFAULT_CHANNELS
] = { .property_name
= "DefaultChannels", .type
= "au", .get_cb
= handle_get_default_channels
, .set_cb
= handle_set_default_channels
},
158 [PROPERTY_HANDLER_DEFAULT_SAMPLE_FORMAT
] = { .property_name
= "DefaultSampleFormat", .type
= "u", .get_cb
= handle_get_default_sample_format
, .set_cb
= handle_set_default_sample_format
},
159 [PROPERTY_HANDLER_DEFAULT_SAMPLE_RATE
] = { .property_name
= "DefaultSampleRate", .type
= "u", .get_cb
= handle_get_default_sample_rate
, .set_cb
= handle_set_default_sample_rate
},
160 [PROPERTY_HANDLER_ALTERNATE_SAMPLE_RATE
] = { .property_name
= "AlternateSampleRate", .type
= "u", .get_cb
= handle_get_alternate_sample_rate
, .set_cb
= handle_set_alternate_sample_rate
},
161 [PROPERTY_HANDLER_CARDS
] = { .property_name
= "Cards", .type
= "ao", .get_cb
= handle_get_cards
, .set_cb
= NULL
},
162 [PROPERTY_HANDLER_SINKS
] = { .property_name
= "Sinks", .type
= "ao", .get_cb
= handle_get_sinks
, .set_cb
= NULL
},
163 [PROPERTY_HANDLER_FALLBACK_SINK
] = { .property_name
= "FallbackSink", .type
= "o", .get_cb
= handle_get_fallback_sink
, .set_cb
= handle_set_fallback_sink
},
164 [PROPERTY_HANDLER_SOURCES
] = { .property_name
= "Sources", .type
= "ao", .get_cb
= handle_get_sources
, .set_cb
= NULL
},
165 [PROPERTY_HANDLER_FALLBACK_SOURCE
] = { .property_name
= "FallbackSource", .type
= "o", .get_cb
= handle_get_fallback_source
, .set_cb
= handle_set_fallback_source
},
166 [PROPERTY_HANDLER_PLAYBACK_STREAMS
] = { .property_name
= "PlaybackStreams", .type
= "ao", .get_cb
= handle_get_playback_streams
, .set_cb
= NULL
},
167 [PROPERTY_HANDLER_RECORD_STREAMS
] = { .property_name
= "RecordStreams", .type
= "ao", .get_cb
= handle_get_record_streams
, .set_cb
= NULL
},
168 [PROPERTY_HANDLER_SAMPLES
] = { .property_name
= "Samples", .type
= "ao", .get_cb
= handle_get_samples
, .set_cb
= NULL
},
169 [PROPERTY_HANDLER_MODULES
] = { .property_name
= "Modules", .type
= "ao", .get_cb
= handle_get_modules
, .set_cb
= NULL
},
170 [PROPERTY_HANDLER_CLIENTS
] = { .property_name
= "Clients", .type
= "ao", .get_cb
= handle_get_clients
, .set_cb
= NULL
},
171 [PROPERTY_HANDLER_MY_CLIENT
] = { .property_name
= "MyClient", .type
= "o", .get_cb
= handle_get_my_client
, .set_cb
= NULL
},
172 [PROPERTY_HANDLER_EXTENSIONS
] = { .property_name
= "Extensions", .type
= "as", .get_cb
= handle_get_extensions
, .set_cb
= NULL
}
175 enum method_handler_index
{
176 METHOD_HANDLER_GET_CARD_BY_NAME
,
177 METHOD_HANDLER_GET_SINK_BY_NAME
,
178 METHOD_HANDLER_GET_SOURCE_BY_NAME
,
179 METHOD_HANDLER_GET_SAMPLE_BY_NAME
,
180 METHOD_HANDLER_UPLOAD_SAMPLE
,
181 METHOD_HANDLER_LOAD_MODULE
,
183 METHOD_HANDLER_LISTEN_FOR_SIGNAL
,
184 METHOD_HANDLER_STOP_LISTENING_FOR_SIGNAL
,
188 static pa_dbus_arg_info get_card_by_name_args
[] = { { "name", "s", "in" }, { "card", "o", "out" } };
189 static pa_dbus_arg_info get_sink_by_name_args
[] = { { "name", "s", "in" }, { "sink", "o", "out" } };
190 static pa_dbus_arg_info get_source_by_name_args
[] = { { "name", "s", "in" }, { "source", "o", "out" } };
191 static pa_dbus_arg_info get_sample_by_name_args
[] = { { "name", "s", "in" }, { "sample", "o", "out" } };
192 static pa_dbus_arg_info upload_sample_args
[] = { { "name", "s", "in" },
193 { "sample_format", "u", "in" },
194 { "sample_rate", "u", "in" },
195 { "channels", "au", "in" },
196 { "default_volume", "au", "in" },
197 { "property_list", "a{say}", "in" },
198 { "data", "ay", "in" },
199 { "sample", "o", "out" } };
200 static pa_dbus_arg_info load_module_args
[] = { { "name", "s", "in" }, { "arguments", "a{ss}", "in" }, { "module", "o", "out" } };
201 static pa_dbus_arg_info listen_for_signal_args
[] = { { "signal", "s", "in" }, { "objects", "ao", "in" } };
202 static pa_dbus_arg_info stop_listening_for_signal_args
[] = { { "signal", "s", "in" } };
204 static pa_dbus_method_handler method_handlers
[METHOD_HANDLER_MAX
] = {
205 [METHOD_HANDLER_GET_CARD_BY_NAME
] = {
206 .method_name
= "GetCardByName",
207 .arguments
= get_card_by_name_args
,
208 .n_arguments
= sizeof(get_card_by_name_args
) / sizeof(pa_dbus_arg_info
),
209 .receive_cb
= handle_get_card_by_name
},
210 [METHOD_HANDLER_GET_SINK_BY_NAME
] = {
211 .method_name
= "GetSinkByName",
212 .arguments
= get_sink_by_name_args
,
213 .n_arguments
= sizeof(get_sink_by_name_args
) / sizeof(pa_dbus_arg_info
),
214 .receive_cb
= handle_get_sink_by_name
},
215 [METHOD_HANDLER_GET_SOURCE_BY_NAME
] = {
216 .method_name
= "GetSourceByName",
217 .arguments
= get_source_by_name_args
,
218 .n_arguments
= sizeof(get_source_by_name_args
) / sizeof(pa_dbus_arg_info
),
219 .receive_cb
= handle_get_source_by_name
},
220 [METHOD_HANDLER_GET_SAMPLE_BY_NAME
] = {
221 .method_name
= "GetSampleByName",
222 .arguments
= get_sample_by_name_args
,
223 .n_arguments
= sizeof(get_sample_by_name_args
) / sizeof(pa_dbus_arg_info
),
224 .receive_cb
= handle_get_sample_by_name
},
225 [METHOD_HANDLER_UPLOAD_SAMPLE
] = {
226 .method_name
= "UploadSample",
227 .arguments
= upload_sample_args
,
228 .n_arguments
= sizeof(upload_sample_args
) / sizeof(pa_dbus_arg_info
),
229 .receive_cb
= handle_upload_sample
},
230 [METHOD_HANDLER_LOAD_MODULE
] = {
231 .method_name
= "LoadModule",
232 .arguments
= load_module_args
,
233 .n_arguments
= sizeof(load_module_args
) / sizeof(pa_dbus_arg_info
),
234 .receive_cb
= handle_load_module
},
235 [METHOD_HANDLER_EXIT
] = {
236 .method_name
= "Exit",
239 .receive_cb
= handle_exit
},
240 [METHOD_HANDLER_LISTEN_FOR_SIGNAL
] = {
241 .method_name
= "ListenForSignal",
242 .arguments
= listen_for_signal_args
,
243 .n_arguments
= sizeof(listen_for_signal_args
) / sizeof(pa_dbus_arg_info
),
244 .receive_cb
= handle_listen_for_signal
},
245 [METHOD_HANDLER_STOP_LISTENING_FOR_SIGNAL
] = {
246 .method_name
= "StopListeningForSignal",
247 .arguments
= stop_listening_for_signal_args
,
248 .n_arguments
= sizeof(stop_listening_for_signal_args
) / sizeof(pa_dbus_arg_info
),
249 .receive_cb
= handle_stop_listening_for_signal
}
257 SIGNAL_FALLBACK_SINK_UPDATED
,
258 SIGNAL_FALLBACK_SINK_UNSET
,
260 SIGNAL_SOURCE_REMOVED
,
261 SIGNAL_FALLBACK_SOURCE_UPDATED
,
262 SIGNAL_FALLBACK_SOURCE_UNSET
,
263 SIGNAL_NEW_PLAYBACK_STREAM
,
264 SIGNAL_PLAYBACK_STREAM_REMOVED
,
265 SIGNAL_NEW_RECORD_STREAM
,
266 SIGNAL_RECORD_STREAM_REMOVED
,
268 SIGNAL_SAMPLE_REMOVED
,
270 SIGNAL_MODULE_REMOVED
,
272 SIGNAL_CLIENT_REMOVED
,
273 SIGNAL_NEW_EXTENSION
,
274 SIGNAL_EXTENSION_REMOVED
,
278 static pa_dbus_arg_info new_card_args
[] = { { "card", "o", NULL
} };
279 static pa_dbus_arg_info card_removed_args
[] = { { "card", "o", NULL
} };
280 static pa_dbus_arg_info new_sink_args
[] = { { "sink", "o", NULL
} };
281 static pa_dbus_arg_info sink_removed_args
[] = { { "sink", "o", NULL
} };
282 static pa_dbus_arg_info fallback_sink_updated_args
[] = { { "sink", "o", NULL
} };
283 static pa_dbus_arg_info new_source_args
[] = { { "source", "o", NULL
} };
284 static pa_dbus_arg_info source_removed_args
[] = { { "source", "o", NULL
} };
285 static pa_dbus_arg_info fallback_source_updated_args
[] = { { "source", "o", NULL
} };
286 static pa_dbus_arg_info new_playback_stream_args
[] = { { "playback_stream", "o", NULL
} };
287 static pa_dbus_arg_info playback_stream_removed_args
[] = { { "playback_stream", "o", NULL
} };
288 static pa_dbus_arg_info new_record_stream_args
[] = { { "record_stream", "o", NULL
} };
289 static pa_dbus_arg_info record_stream_removed_args
[] = { { "record_stream", "o", NULL
} };
290 static pa_dbus_arg_info new_sample_args
[] = { { "sample", "o", NULL
} };
291 static pa_dbus_arg_info sample_removed_args
[] = { { "sample", "o", NULL
} };
292 static pa_dbus_arg_info new_module_args
[] = { { "module", "o", NULL
} };
293 static pa_dbus_arg_info module_removed_args
[] = { { "module", "o", NULL
} };
294 static pa_dbus_arg_info new_client_args
[] = { { "client", "o", NULL
} };
295 static pa_dbus_arg_info client_removed_args
[] = { { "client", "o", NULL
} };
296 static pa_dbus_arg_info new_extension_args
[] = { { "extension", "s", NULL
} };
297 static pa_dbus_arg_info extension_removed_args
[] = { { "extension", "s", NULL
} };
299 static pa_dbus_signal_info signals
[SIGNAL_MAX
] = {
300 [SIGNAL_NEW_CARD
] = { .name
= "NewCard", .arguments
= new_card_args
, .n_arguments
= 1 },
301 [SIGNAL_CARD_REMOVED
] = { .name
= "CardRemoved", .arguments
= card_removed_args
, .n_arguments
= 1 },
302 [SIGNAL_NEW_SINK
] = { .name
= "NewSink", .arguments
= new_sink_args
, .n_arguments
= 1 },
303 [SIGNAL_SINK_REMOVED
] = { .name
= "SinkRemoved", .arguments
= sink_removed_args
, .n_arguments
= 1 },
304 [SIGNAL_FALLBACK_SINK_UPDATED
] = { .name
= "FallbackSinkUpdated", .arguments
= fallback_sink_updated_args
, .n_arguments
= 1 },
305 [SIGNAL_FALLBACK_SINK_UNSET
] = { .name
= "FallbackSinkUnset", .arguments
= NULL
, .n_arguments
= 0 },
306 [SIGNAL_NEW_SOURCE
] = { .name
= "NewSource", .arguments
= new_source_args
, .n_arguments
= 1 },
307 [SIGNAL_SOURCE_REMOVED
] = { .name
= "SourceRemoved", .arguments
= source_removed_args
, .n_arguments
= 1 },
308 [SIGNAL_FALLBACK_SOURCE_UPDATED
] = { .name
= "FallbackSourceUpdated", .arguments
= fallback_source_updated_args
, .n_arguments
= 1 },
309 [SIGNAL_FALLBACK_SOURCE_UNSET
] = { .name
= "FallbackSourceUnset", .arguments
= NULL
, .n_arguments
= 0 },
310 [SIGNAL_NEW_PLAYBACK_STREAM
] = { .name
= "NewPlaybackStream", .arguments
= new_playback_stream_args
, .n_arguments
= 1 },
311 [SIGNAL_PLAYBACK_STREAM_REMOVED
] = { .name
= "PlaybackStreamRemoved", .arguments
= playback_stream_removed_args
, .n_arguments
= 1 },
312 [SIGNAL_NEW_RECORD_STREAM
] = { .name
= "NewRecordStream", .arguments
= new_record_stream_args
, .n_arguments
= 1 },
313 [SIGNAL_RECORD_STREAM_REMOVED
] = { .name
= "RecordStreamRemoved", .arguments
= record_stream_removed_args
, .n_arguments
= 1 },
314 [SIGNAL_NEW_SAMPLE
] = { .name
= "NewSample", .arguments
= new_sample_args
, .n_arguments
= 1 },
315 [SIGNAL_SAMPLE_REMOVED
] = { .name
= "SampleRemoved", .arguments
= sample_removed_args
, .n_arguments
= 1 },
316 [SIGNAL_NEW_MODULE
] = { .name
= "NewModule", .arguments
= new_module_args
, .n_arguments
= 1 },
317 [SIGNAL_MODULE_REMOVED
] = { .name
= "ModuleRemoved", .arguments
= module_removed_args
, .n_arguments
= 1 },
318 [SIGNAL_NEW_CLIENT
] = { .name
= "NewClient", .arguments
= new_client_args
, .n_arguments
= 1 },
319 [SIGNAL_CLIENT_REMOVED
] = { .name
= "ClientRemoved", .arguments
= client_removed_args
, .n_arguments
= 1 },
320 [SIGNAL_NEW_EXTENSION
] = { .name
= "NewExtension", .arguments
= new_extension_args
, .n_arguments
= 1 },
321 [SIGNAL_EXTENSION_REMOVED
] = { .name
= "ExtensionRemoved", .arguments
= extension_removed_args
, .n_arguments
= 1 }
324 static pa_dbus_interface_info core_interface_info
= {
325 .name
= PA_DBUS_CORE_INTERFACE
,
326 .method_handlers
= method_handlers
,
327 .n_method_handlers
= METHOD_HANDLER_MAX
,
328 .property_handlers
= property_handlers
,
329 .n_property_handlers
= PROPERTY_HANDLER_MAX
,
330 .get_all_properties_cb
= handle_get_all
,
332 .n_signals
= SIGNAL_MAX
335 static void handle_get_interface_revision(DBusConnection
*conn
, DBusMessage
*msg
, void *userdata
) {
336 dbus_uint32_t interface_revision
= INTERFACE_REVISION
;
341 pa_dbus_send_basic_variant_reply(conn
, msg
, DBUS_TYPE_UINT32
, &interface_revision
);
344 static void handle_get_name(DBusConnection
*conn
, DBusMessage
*msg
, void *userdata
) {
345 const char *server_name
= PACKAGE_NAME
;
350 pa_dbus_send_basic_variant_reply(conn
, msg
, DBUS_TYPE_STRING
, &server_name
);
353 static void handle_get_version(DBusConnection
*conn
, DBusMessage
*msg
, void *userdata
) {
354 const char *version
= PACKAGE_VERSION
;
359 pa_dbus_send_basic_variant_reply(conn
, msg
, DBUS_TYPE_STRING
, &version
);
362 static dbus_bool_t
get_is_local(DBusConnection
*conn
) {
367 if (!dbus_connection_get_socket(conn
, &conn_fd
))
370 return pa_socket_is_local(conn_fd
);
373 static void handle_get_is_local(DBusConnection
*conn
, DBusMessage
*msg
, void *userdata
) {
374 dbus_bool_t is_local
;
379 is_local
= get_is_local(conn
);
381 pa_dbus_send_basic_variant_reply(conn
, msg
, DBUS_TYPE_BOOLEAN
, &is_local
);
384 static void handle_get_username(DBusConnection
*conn
, DBusMessage
*msg
, void *userdata
) {
385 char *username
= NULL
;
390 username
= pa_get_user_name_malloc();
392 pa_dbus_send_basic_variant_reply(conn
, msg
, DBUS_TYPE_STRING
, &username
);
397 static void handle_get_hostname(DBusConnection
*conn
, DBusMessage
*msg
, void *userdata
) {
398 char *hostname
= NULL
;
403 hostname
= pa_get_host_name_malloc();
405 pa_dbus_send_basic_variant_reply(conn
, msg
, DBUS_TYPE_STRING
, &hostname
);
410 /* Caller frees the returned array. */
411 static dbus_uint32_t
*get_default_channels(pa_dbusiface_core
*c
, unsigned *n
) {
412 dbus_uint32_t
*default_channels
= NULL
;
418 *n
= c
->core
->default_channel_map
.channels
;
419 default_channels
= pa_xnew(dbus_uint32_t
, *n
);
421 for (i
= 0; i
< *n
; ++i
)
422 default_channels
[i
] = c
->core
->default_channel_map
.map
[i
];
424 return default_channels
;
427 static void handle_get_default_channels(DBusConnection
*conn
, DBusMessage
*msg
, void *userdata
) {
428 pa_dbusiface_core
*c
= userdata
;
429 dbus_uint32_t
*default_channels
= NULL
;
436 default_channels
= get_default_channels(c
, &n
);
438 pa_dbus_send_basic_array_variant_reply(conn
, msg
, DBUS_TYPE_UINT32
, default_channels
, n
);
440 pa_xfree(default_channels
);
443 static void handle_set_default_channels(DBusConnection
*conn
, DBusMessage
*msg
, DBusMessageIter
*iter
, void *userdata
) {
444 pa_dbusiface_core
*c
= userdata
;
445 DBusMessageIter array_iter
;
446 pa_channel_map new_channel_map
;
447 const dbus_uint32_t
*default_channels
;
456 pa_channel_map_init(&new_channel_map
);
458 dbus_message_iter_recurse(iter
, &array_iter
);
459 dbus_message_iter_get_fixed_array(&array_iter
, &default_channels
, &n_channels
);
461 if (n_channels
<= 0) {
462 pa_dbus_send_error(conn
, msg
, DBUS_ERROR_INVALID_ARGS
, "Empty channel array.");
466 if (n_channels
> (int) PA_CHANNELS_MAX
) {
467 pa_dbus_send_error(conn
, msg
, DBUS_ERROR_INVALID_ARGS
,
468 "Too many channels: %i. The maximum number of channels is %u.", n_channels
, PA_CHANNELS_MAX
);
472 new_channel_map
.channels
= n_channels
;
474 for (i
= 0; i
< new_channel_map
.channels
; ++i
) {
475 if (default_channels
[i
] >= PA_CHANNEL_POSITION_MAX
) {
476 pa_dbus_send_error(conn
, msg
, DBUS_ERROR_INVALID_ARGS
, "Invalid channel position: %u.", default_channels
[i
]);
480 new_channel_map
.map
[i
] = default_channels
[i
];
483 c
->core
->default_channel_map
= new_channel_map
;
484 c
->core
->default_sample_spec
.channels
= n_channels
;
486 pa_dbus_send_empty_reply(conn
, msg
);
489 static void handle_get_default_sample_format(DBusConnection
*conn
, DBusMessage
*msg
, void *userdata
) {
490 pa_dbusiface_core
*c
= userdata
;
491 dbus_uint32_t default_sample_format
;
497 default_sample_format
= c
->core
->default_sample_spec
.format
;
499 pa_dbus_send_basic_variant_reply(conn
, msg
, DBUS_TYPE_UINT32
, &default_sample_format
);
502 static void handle_set_default_sample_format(DBusConnection
*conn
, DBusMessage
*msg
, DBusMessageIter
*iter
, void *userdata
) {
503 pa_dbusiface_core
*c
= userdata
;
504 dbus_uint32_t default_sample_format
;
511 dbus_message_iter_get_basic(iter
, &default_sample_format
);
513 if (default_sample_format
>= PA_SAMPLE_MAX
) {
514 pa_dbus_send_error(conn
, msg
, DBUS_ERROR_INVALID_ARGS
, "Invalid sample format.");
518 c
->core
->default_sample_spec
.format
= default_sample_format
;
520 pa_dbus_send_empty_reply(conn
, msg
);
523 static void handle_get_default_sample_rate(DBusConnection
*conn
, DBusMessage
*msg
, void *userdata
) {
524 pa_dbusiface_core
*c
= userdata
;
525 dbus_uint32_t default_sample_rate
;
531 default_sample_rate
= c
->core
->default_sample_spec
.rate
;
533 pa_dbus_send_basic_variant_reply(conn
, msg
, DBUS_TYPE_UINT32
, &default_sample_rate
);
536 static void handle_set_default_sample_rate(DBusConnection
*conn
, DBusMessage
*msg
, DBusMessageIter
*iter
, void *userdata
) {
537 pa_dbusiface_core
*c
= userdata
;
538 dbus_uint32_t default_sample_rate
;
545 dbus_message_iter_get_basic(iter
, &default_sample_rate
);
547 if (default_sample_rate
<= 0 || default_sample_rate
> PA_RATE_MAX
||
548 !((default_sample_rate
% 4000 == 0) || (default_sample_rate
% 11025 == 0))) {
549 pa_dbus_send_error(conn
, msg
, DBUS_ERROR_INVALID_ARGS
, "Invalid sample rate.");
553 c
->core
->default_sample_spec
.rate
= default_sample_rate
;
555 pa_dbus_send_empty_reply(conn
, msg
);
558 static void handle_get_alternate_sample_rate(DBusConnection
*conn
, DBusMessage
*msg
, void *userdata
) {
559 pa_dbusiface_core
*c
= userdata
;
560 dbus_uint32_t alternate_sample_rate
;
566 alternate_sample_rate
= c
->core
->alternate_sample_rate
;
568 pa_dbus_send_basic_variant_reply(conn
, msg
, DBUS_TYPE_UINT32
, &alternate_sample_rate
);
571 static void handle_set_alternate_sample_rate(DBusConnection
*conn
, DBusMessage
*msg
, DBusMessageIter
*iter
, void *userdata
) {
572 pa_dbusiface_core
*c
= userdata
;
573 dbus_uint32_t alternate_sample_rate
;
580 dbus_message_iter_get_basic(iter
, &alternate_sample_rate
);
582 if (alternate_sample_rate
<= 0 || alternate_sample_rate
> PA_RATE_MAX
||
583 !((alternate_sample_rate
% 4000 == 0) || (alternate_sample_rate
% 11025 == 0))) {
584 pa_dbus_send_error(conn
, msg
, DBUS_ERROR_INVALID_ARGS
, "Invalid sample rate.");
588 c
->core
->alternate_sample_rate
= alternate_sample_rate
;
590 pa_dbus_send_empty_reply(conn
, msg
);
593 /* The caller frees the array, but not the strings. */
594 static const char **get_cards(pa_dbusiface_core
*c
, unsigned *n
) {
598 pa_dbusiface_card
*card
;
603 *n
= pa_hashmap_size(c
->cards
);
608 cards
= pa_xnew(const char *, *n
);
610 PA_HASHMAP_FOREACH(card
, c
->cards
, state
)
611 cards
[i
++] = pa_dbusiface_card_get_path(card
);
616 static void handle_get_cards(DBusConnection
*conn
, DBusMessage
*msg
, void *userdata
) {
617 pa_dbusiface_core
*c
= userdata
;
625 cards
= get_cards(c
, &n
);
627 pa_dbus_send_basic_array_variant_reply(conn
, msg
, DBUS_TYPE_OBJECT_PATH
, cards
, n
);
632 /* The caller frees the array, but not the strings. */
633 static const char **get_sinks(pa_dbusiface_core
*c
, unsigned *n
) {
637 pa_dbusiface_device
*sink
;
642 *n
= pa_hashmap_size(c
->sinks_by_index
);
647 sinks
= pa_xnew(const char *, *n
);
649 PA_HASHMAP_FOREACH(sink
, c
->sinks_by_index
, state
)
650 sinks
[i
++] = pa_dbusiface_device_get_path(sink
);
655 static void handle_get_sinks(DBusConnection
*conn
, DBusMessage
*msg
, void *userdata
) {
656 pa_dbusiface_core
*c
= userdata
;
664 sinks
= get_sinks(c
, &n
);
666 pa_dbus_send_basic_array_variant_reply(conn
, msg
, DBUS_TYPE_OBJECT_PATH
, sinks
, n
);
671 static void handle_get_fallback_sink(DBusConnection
*conn
, DBusMessage
*msg
, void *userdata
) {
672 pa_dbusiface_core
*c
= userdata
;
673 pa_dbusiface_device
*fallback_sink
;
674 const char *object_path
;
680 if (!c
->fallback_sink
) {
681 pa_dbus_send_error(conn
, msg
, PA_DBUS_ERROR_NO_SUCH_PROPERTY
,
682 "There are no sinks, and therefore no fallback sink either.");
686 pa_assert_se((fallback_sink
= pa_hashmap_get(c
->sinks_by_index
, PA_UINT32_TO_PTR(c
->fallback_sink
->index
))));
687 object_path
= pa_dbusiface_device_get_path(fallback_sink
);
689 pa_dbus_send_basic_variant_reply(conn
, msg
, DBUS_TYPE_OBJECT_PATH
, &object_path
);
692 static void handle_set_fallback_sink(DBusConnection
*conn
, DBusMessage
*msg
, DBusMessageIter
*iter
, void *userdata
) {
693 pa_dbusiface_core
*c
= userdata
;
694 pa_dbusiface_device
*fallback_sink
;
695 const char *object_path
;
702 if (!c
->fallback_sink
) {
703 pa_dbus_send_error(conn
, msg
, PA_DBUS_ERROR_NO_SUCH_PROPERTY
,
704 "There are no sinks, and therefore no fallback sink either.");
708 dbus_message_iter_get_basic(iter
, &object_path
);
710 if (!(fallback_sink
= pa_hashmap_get(c
->sinks_by_path
, object_path
))) {
711 pa_dbus_send_error(conn
, msg
, PA_DBUS_ERROR_NOT_FOUND
, "%s: No such sink.", object_path
);
715 pa_namereg_set_default_sink(c
->core
, pa_dbusiface_device_get_sink(fallback_sink
));
717 pa_dbus_send_empty_reply(conn
, msg
);
720 /* The caller frees the array, but not the strings. */
721 static const char **get_sources(pa_dbusiface_core
*c
, unsigned *n
) {
722 const char **sources
;
725 pa_dbusiface_device
*source
;
730 *n
= pa_hashmap_size(c
->sources_by_index
);
735 sources
= pa_xnew(const char *, *n
);
737 PA_HASHMAP_FOREACH(source
, c
->sources_by_index
, state
)
738 sources
[i
++] = pa_dbusiface_device_get_path(source
);
743 static void handle_get_sources(DBusConnection
*conn
, DBusMessage
*msg
, void *userdata
) {
744 pa_dbusiface_core
*c
= userdata
;
745 const char **sources
;
752 sources
= get_sources(c
, &n
);
754 pa_dbus_send_basic_array_variant_reply(conn
, msg
, DBUS_TYPE_OBJECT_PATH
, sources
, n
);
759 static void handle_get_fallback_source(DBusConnection
*conn
, DBusMessage
*msg
, void *userdata
) {
760 pa_dbusiface_core
*c
= userdata
;
761 pa_dbusiface_device
*fallback_source
;
762 const char *object_path
;
768 if (!c
->fallback_source
) {
769 pa_dbus_send_error(conn
, msg
, PA_DBUS_ERROR_NO_SUCH_PROPERTY
,
770 "There are no sources, and therefore no fallback source either.");
774 pa_assert_se((fallback_source
= pa_hashmap_get(c
->sources_by_index
, PA_UINT32_TO_PTR(c
->fallback_source
->index
))));
775 object_path
= pa_dbusiface_device_get_path(fallback_source
);
777 pa_dbus_send_basic_variant_reply(conn
, msg
, DBUS_TYPE_OBJECT_PATH
, &object_path
);
780 static void handle_set_fallback_source(DBusConnection
*conn
, DBusMessage
*msg
, DBusMessageIter
*iter
, void *userdata
) {
781 pa_dbusiface_core
*c
= userdata
;
782 pa_dbusiface_device
*fallback_source
;
783 const char *object_path
;
790 if (!c
->fallback_source
) {
791 pa_dbus_send_error(conn
, msg
, PA_DBUS_ERROR_NO_SUCH_PROPERTY
,
792 "There are no sources, and therefore no fallback source either.");
796 dbus_message_iter_get_basic(iter
, &object_path
);
798 if (!(fallback_source
= pa_hashmap_get(c
->sources_by_path
, object_path
))) {
799 pa_dbus_send_error(conn
, msg
, PA_DBUS_ERROR_NOT_FOUND
, "%s: No such source.", object_path
);
803 pa_namereg_set_default_source(c
->core
, pa_dbusiface_device_get_source(fallback_source
));
805 pa_dbus_send_empty_reply(conn
, msg
);
808 /* The caller frees the array, but not the strings. */
809 static const char **get_playback_streams(pa_dbusiface_core
*c
, unsigned *n
) {
810 const char **streams
;
813 pa_dbusiface_stream
*stream
;
818 *n
= pa_hashmap_size(c
->playback_streams
);
823 streams
= pa_xnew(const char *, *n
);
825 PA_HASHMAP_FOREACH(stream
, c
->playback_streams
, state
)
826 streams
[i
++] = pa_dbusiface_stream_get_path(stream
);
831 static void handle_get_playback_streams(DBusConnection
*conn
, DBusMessage
*msg
, void *userdata
) {
832 pa_dbusiface_core
*c
= userdata
;
833 const char **playback_streams
;
840 playback_streams
= get_playback_streams(c
, &n
);
842 pa_dbus_send_basic_array_variant_reply(conn
, msg
, DBUS_TYPE_OBJECT_PATH
, playback_streams
, n
);
844 pa_xfree(playback_streams
);
847 /* The caller frees the array, but not the strings. */
848 static const char **get_record_streams(pa_dbusiface_core
*c
, unsigned *n
) {
849 const char **streams
;
852 pa_dbusiface_stream
*stream
;
857 *n
= pa_hashmap_size(c
->record_streams
);
862 streams
= pa_xnew(const char *, *n
);
864 PA_HASHMAP_FOREACH(stream
, c
->record_streams
, state
)
865 streams
[i
++] = pa_dbusiface_stream_get_path(stream
);
870 static void handle_get_record_streams(DBusConnection
*conn
, DBusMessage
*msg
, void *userdata
) {
871 pa_dbusiface_core
*c
= userdata
;
872 const char **record_streams
;
879 record_streams
= get_record_streams(c
, &n
);
881 pa_dbus_send_basic_array_variant_reply(conn
, msg
, DBUS_TYPE_OBJECT_PATH
, record_streams
, n
);
883 pa_xfree(record_streams
);
886 /* The caller frees the array, but not the strings. */
887 static const char **get_samples(pa_dbusiface_core
*c
, unsigned *n
) {
888 const char **samples
;
891 pa_dbusiface_sample
*sample
;
896 *n
= pa_hashmap_size(c
->samples
);
901 samples
= pa_xnew(const char *, *n
);
903 PA_HASHMAP_FOREACH(sample
, c
->samples
, state
)
904 samples
[i
++] = pa_dbusiface_sample_get_path(sample
);
909 static void handle_get_samples(DBusConnection
*conn
, DBusMessage
*msg
, void *userdata
) {
910 pa_dbusiface_core
*c
= userdata
;
911 const char **samples
;
918 samples
= get_samples(c
, &n
);
920 pa_dbus_send_basic_array_variant_reply(conn
, msg
, DBUS_TYPE_OBJECT_PATH
, samples
, n
);
925 /* The caller frees the array, but not the strings. */
926 static const char **get_modules(pa_dbusiface_core
*c
, unsigned *n
) {
927 const char **modules
;
930 pa_dbusiface_module
*module
;
935 *n
= pa_hashmap_size(c
->modules
);
940 modules
= pa_xnew(const char *, *n
);
942 PA_HASHMAP_FOREACH(module
, c
->modules
, state
)
943 modules
[i
++] = pa_dbusiface_module_get_path(module
);
948 static void handle_get_modules(DBusConnection
*conn
, DBusMessage
*msg
, void *userdata
) {
949 pa_dbusiface_core
*c
= userdata
;
950 const char **modules
;
957 modules
= get_modules(c
, &n
);
959 pa_dbus_send_basic_array_variant_reply(conn
, msg
, DBUS_TYPE_OBJECT_PATH
, modules
, n
);
964 /* The caller frees the array, but not the strings. */
965 static const char **get_clients(pa_dbusiface_core
*c
, unsigned *n
) {
966 const char **clients
;
969 pa_dbusiface_client
*client
;
974 *n
= pa_hashmap_size(c
->clients
);
979 clients
= pa_xnew(const char *, *n
);
981 PA_HASHMAP_FOREACH(client
, c
->clients
, state
)
982 clients
[i
++] = pa_dbusiface_client_get_path(client
);
987 static void handle_get_clients(DBusConnection
*conn
, DBusMessage
*msg
, void *userdata
) {
988 pa_dbusiface_core
*c
= userdata
;
989 const char **clients
;
996 clients
= get_clients(c
, &n
);
998 pa_dbus_send_basic_array_variant_reply(conn
, msg
, DBUS_TYPE_OBJECT_PATH
, clients
, n
);
1003 static const char *get_my_client(pa_dbusiface_core
*c
, DBusConnection
*conn
) {
1004 pa_client
*my_client
;
1009 pa_assert_se((my_client
= pa_dbus_protocol_get_client(c
->dbus_protocol
, conn
)));
1011 return pa_dbusiface_client_get_path(pa_hashmap_get(c
->clients
, PA_UINT32_TO_PTR(my_client
->index
)));
1014 static void handle_get_my_client(DBusConnection
*conn
, DBusMessage
*msg
, void *userdata
) {
1015 pa_dbusiface_core
*c
= userdata
;
1016 const char *my_client
;
1022 my_client
= get_my_client(c
, conn
);
1024 pa_dbus_send_basic_variant_reply(conn
, msg
, DBUS_TYPE_OBJECT_PATH
, &my_client
);
1027 static void handle_get_extensions(DBusConnection
*conn
, DBusMessage
*msg
, void *userdata
) {
1028 pa_dbusiface_core
*c
= userdata
;
1029 const char **extensions
;
1036 extensions
= pa_dbus_protocol_get_extensions(c
->dbus_protocol
, &n
);
1038 pa_dbus_send_basic_array_variant_reply(conn
, msg
, DBUS_TYPE_STRING
, extensions
, n
);
1040 pa_xfree(extensions
);
1043 static void handle_get_all(DBusConnection
*conn
, DBusMessage
*msg
, void *userdata
) {
1044 pa_dbusiface_core
*c
= userdata
;
1045 DBusMessage
*reply
= NULL
;
1046 DBusMessageIter msg_iter
;
1047 DBusMessageIter dict_iter
;
1048 dbus_uint32_t interface_revision
;
1049 const char *server_name
;
1050 const char *version
;
1051 dbus_bool_t is_local
;
1054 dbus_uint32_t
*default_channels
;
1055 unsigned n_default_channels
;
1056 dbus_uint32_t default_sample_format
;
1057 dbus_uint32_t default_sample_rate
;
1058 dbus_uint32_t alternate_sample_rate
;
1063 const char *fallback_sink
;
1064 const char **sources
;
1066 const char *fallback_source
;
1067 const char **playback_streams
;
1068 unsigned n_playback_streams
;
1069 const char **record_streams
;
1070 unsigned n_record_streams
;
1071 const char **samples
;
1073 const char **modules
;
1075 const char **clients
;
1077 const char *my_client
;
1078 const char **extensions
;
1079 unsigned n_extensions
;
1085 interface_revision
= INTERFACE_REVISION
;
1086 server_name
= PACKAGE_NAME
;
1087 version
= PACKAGE_VERSION
;
1088 is_local
= get_is_local(conn
);
1089 username
= pa_get_user_name_malloc();
1090 hostname
= pa_get_host_name_malloc();
1091 default_channels
= get_default_channels(c
, &n_default_channels
);
1092 default_sample_format
= c
->core
->default_sample_spec
.format
;
1093 default_sample_rate
= c
->core
->default_sample_spec
.rate
;
1094 alternate_sample_rate
= c
->core
->alternate_sample_rate
;
1095 cards
= get_cards(c
, &n_cards
);
1096 sinks
= get_sinks(c
, &n_sinks
);
1097 fallback_sink
= c
->fallback_sink
1098 ? pa_dbusiface_device_get_path(pa_hashmap_get(c
->sinks_by_index
, PA_UINT32_TO_PTR(c
->fallback_sink
->index
)))
1100 sources
= get_sources(c
, &n_sources
);
1101 fallback_source
= c
->fallback_source
1102 ? pa_dbusiface_device_get_path(pa_hashmap_get(c
->sources_by_index
,
1103 PA_UINT32_TO_PTR(c
->fallback_source
->index
)))
1105 playback_streams
= get_playback_streams(c
, &n_playback_streams
);
1106 record_streams
= get_record_streams(c
, &n_record_streams
);
1107 samples
= get_samples(c
, &n_samples
);
1108 modules
= get_modules(c
, &n_modules
);
1109 clients
= get_clients(c
, &n_clients
);
1110 my_client
= get_my_client(c
, conn
);
1111 extensions
= pa_dbus_protocol_get_extensions(c
->dbus_protocol
, &n_extensions
);
1113 pa_assert_se((reply
= dbus_message_new_method_return(msg
)));
1115 dbus_message_iter_init_append(reply
, &msg_iter
);
1116 pa_assert_se(dbus_message_iter_open_container(&msg_iter
, DBUS_TYPE_ARRAY
, "{sv}", &dict_iter
));
1118 pa_dbus_append_basic_variant_dict_entry(&dict_iter
, property_handlers
[PROPERTY_HANDLER_INTERFACE_REVISION
].property_name
, DBUS_TYPE_UINT32
, &interface_revision
);
1119 pa_dbus_append_basic_variant_dict_entry(&dict_iter
, property_handlers
[PROPERTY_HANDLER_NAME
].property_name
, DBUS_TYPE_STRING
, &server_name
);
1120 pa_dbus_append_basic_variant_dict_entry(&dict_iter
, property_handlers
[PROPERTY_HANDLER_VERSION
].property_name
, DBUS_TYPE_STRING
, &version
);
1121 pa_dbus_append_basic_variant_dict_entry(&dict_iter
, property_handlers
[PROPERTY_HANDLER_IS_LOCAL
].property_name
, DBUS_TYPE_BOOLEAN
, &is_local
);
1122 pa_dbus_append_basic_variant_dict_entry(&dict_iter
, property_handlers
[PROPERTY_HANDLER_USERNAME
].property_name
, DBUS_TYPE_STRING
, &username
);
1123 pa_dbus_append_basic_variant_dict_entry(&dict_iter
, property_handlers
[PROPERTY_HANDLER_HOSTNAME
].property_name
, DBUS_TYPE_STRING
, &hostname
);
1124 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
);
1125 pa_dbus_append_basic_variant_dict_entry(&dict_iter
, property_handlers
[PROPERTY_HANDLER_DEFAULT_SAMPLE_FORMAT
].property_name
, DBUS_TYPE_UINT32
, &default_sample_format
);
1126 pa_dbus_append_basic_variant_dict_entry(&dict_iter
, property_handlers
[PROPERTY_HANDLER_DEFAULT_SAMPLE_RATE
].property_name
, DBUS_TYPE_UINT32
, &default_sample_rate
);
1127 pa_dbus_append_basic_variant_dict_entry(&dict_iter
, property_handlers
[PROPERTY_HANDLER_ALTERNATE_SAMPLE_RATE
].property_name
, DBUS_TYPE_UINT32
, &alternate_sample_rate
);
1128 pa_dbus_append_basic_array_variant_dict_entry(&dict_iter
, property_handlers
[PROPERTY_HANDLER_CARDS
].property_name
, DBUS_TYPE_OBJECT_PATH
, cards
, n_cards
);
1129 pa_dbus_append_basic_array_variant_dict_entry(&dict_iter
, property_handlers
[PROPERTY_HANDLER_SINKS
].property_name
, DBUS_TYPE_OBJECT_PATH
, sinks
, n_sinks
);
1132 pa_dbus_append_basic_variant_dict_entry(&dict_iter
, property_handlers
[PROPERTY_HANDLER_FALLBACK_SINK
].property_name
, DBUS_TYPE_OBJECT_PATH
, &fallback_sink
);
1134 pa_dbus_append_basic_array_variant_dict_entry(&dict_iter
, property_handlers
[PROPERTY_HANDLER_SOURCES
].property_name
, DBUS_TYPE_OBJECT_PATH
, sources
, n_sources
);
1136 if (fallback_source
)
1137 pa_dbus_append_basic_variant_dict_entry(&dict_iter
, property_handlers
[PROPERTY_HANDLER_FALLBACK_SOURCE
].property_name
, DBUS_TYPE_OBJECT_PATH
, &fallback_source
);
1139 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
);
1140 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
);
1141 pa_dbus_append_basic_array_variant_dict_entry(&dict_iter
, property_handlers
[PROPERTY_HANDLER_SAMPLES
].property_name
, DBUS_TYPE_OBJECT_PATH
, samples
, n_samples
);
1142 pa_dbus_append_basic_array_variant_dict_entry(&dict_iter
, property_handlers
[PROPERTY_HANDLER_MODULES
].property_name
, DBUS_TYPE_OBJECT_PATH
, modules
, n_modules
);
1143 pa_dbus_append_basic_array_variant_dict_entry(&dict_iter
, property_handlers
[PROPERTY_HANDLER_CLIENTS
].property_name
, DBUS_TYPE_OBJECT_PATH
, clients
, n_clients
);
1144 pa_dbus_append_basic_variant_dict_entry(&dict_iter
, property_handlers
[PROPERTY_HANDLER_MY_CLIENT
].property_name
, DBUS_TYPE_OBJECT_PATH
, &my_client
);
1145 pa_dbus_append_basic_array_variant_dict_entry(&dict_iter
, property_handlers
[PROPERTY_HANDLER_EXTENSIONS
].property_name
, DBUS_TYPE_STRING
, extensions
, n_extensions
);
1147 pa_assert_se(dbus_message_iter_close_container(&msg_iter
, &dict_iter
));
1149 pa_assert_se(dbus_connection_send(conn
, reply
, NULL
));
1151 dbus_message_unref(reply
);
1155 pa_xfree(default_channels
);
1159 pa_xfree(playback_streams
);
1160 pa_xfree(record_streams
);
1164 pa_xfree(extensions
);
1167 static void handle_get_card_by_name(DBusConnection
*conn
, DBusMessage
*msg
, void *userdata
) {
1168 pa_dbusiface_core
*c
= userdata
;
1171 pa_dbusiface_card
*dbus_card
;
1172 const char *object_path
;
1178 pa_assert_se(dbus_message_get_args(msg
, NULL
, DBUS_TYPE_STRING
, &card_name
, DBUS_TYPE_INVALID
));
1180 if (!(card
= pa_namereg_get(c
->core
, card_name
, PA_NAMEREG_CARD
))) {
1181 pa_dbus_send_error(conn
, msg
, PA_DBUS_ERROR_NOT_FOUND
, "No such card.");
1185 pa_assert_se((dbus_card
= pa_hashmap_get(c
->cards
, PA_UINT32_TO_PTR(card
->index
))));
1187 object_path
= pa_dbusiface_card_get_path(dbus_card
);
1189 pa_dbus_send_basic_value_reply(conn
, msg
, DBUS_TYPE_OBJECT_PATH
, &object_path
);
1192 static void handle_get_sink_by_name(DBusConnection
*conn
, DBusMessage
*msg
, void *userdata
) {
1193 pa_dbusiface_core
*c
= userdata
;
1196 pa_dbusiface_device
*dbus_sink
;
1197 const char *object_path
;
1203 pa_assert_se(dbus_message_get_args(msg
, NULL
, DBUS_TYPE_STRING
, &sink_name
, DBUS_TYPE_INVALID
));
1205 if (!(sink
= pa_namereg_get(c
->core
, sink_name
, PA_NAMEREG_SINK
))) {
1206 pa_dbus_send_error(conn
, msg
, PA_DBUS_ERROR_NOT_FOUND
, "%s: No such sink.", sink_name
);
1210 pa_assert_se((dbus_sink
= pa_hashmap_get(c
->sinks_by_index
, PA_UINT32_TO_PTR(sink
->index
))));
1212 object_path
= pa_dbusiface_device_get_path(dbus_sink
);
1214 pa_dbus_send_basic_value_reply(conn
, msg
, DBUS_TYPE_OBJECT_PATH
, &object_path
);
1217 static void handle_get_source_by_name(DBusConnection
*conn
, DBusMessage
*msg
, void *userdata
) {
1218 pa_dbusiface_core
*c
= userdata
;
1221 pa_dbusiface_device
*dbus_source
;
1222 const char *object_path
;
1228 pa_assert_se(dbus_message_get_args(msg
, NULL
, DBUS_TYPE_STRING
, &source_name
, DBUS_TYPE_INVALID
));
1230 if (!(source
= pa_namereg_get(c
->core
, source_name
, PA_NAMEREG_SOURCE
))) {
1231 pa_dbus_send_error(conn
, msg
, PA_DBUS_ERROR_NOT_FOUND
, "%s: No such source.", source_name
);
1235 pa_assert_se((dbus_source
= pa_hashmap_get(c
->sources_by_index
, PA_UINT32_TO_PTR(source
->index
))));
1237 object_path
= pa_dbusiface_device_get_path(dbus_source
);
1239 pa_dbus_send_basic_value_reply(conn
, msg
, DBUS_TYPE_OBJECT_PATH
, &object_path
);
1242 static void handle_get_sample_by_name(DBusConnection
*conn
, DBusMessage
*msg
, void *userdata
) {
1243 pa_dbusiface_core
*c
= userdata
;
1245 pa_scache_entry
*sample
;
1246 pa_dbusiface_sample
*dbus_sample
;
1247 const char *object_path
;
1253 pa_assert_se(dbus_message_get_args(msg
, NULL
, DBUS_TYPE_STRING
, &sample_name
, DBUS_TYPE_INVALID
));
1255 if (!(sample
= pa_namereg_get(c
->core
, sample_name
, PA_NAMEREG_SAMPLE
))) {
1256 pa_dbus_send_error(conn
, msg
, PA_DBUS_ERROR_NOT_FOUND
, "No such sample.");
1260 pa_assert_se((dbus_sample
= pa_hashmap_get(c
->samples
, PA_UINT32_TO_PTR(sample
->index
))));
1262 object_path
= pa_dbusiface_sample_get_path(dbus_sample
);
1264 pa_dbus_send_basic_value_reply(conn
, msg
, DBUS_TYPE_OBJECT_PATH
, &object_path
);
1267 static void handle_upload_sample(DBusConnection
*conn
, DBusMessage
*msg
, void *userdata
) {
1268 pa_dbusiface_core
*c
= userdata
;
1269 DBusMessageIter msg_iter
;
1270 DBusMessageIter array_iter
;
1272 dbus_uint32_t sample_format
;
1273 dbus_uint32_t sample_rate
;
1274 const dbus_uint32_t
*channels
;
1276 const dbus_uint32_t
*default_volume
;
1277 int n_volume_entries
;
1278 pa_proplist
*property_list
;
1279 const uint8_t *data
;
1286 pa_dbusiface_sample
*dbus_sample
= NULL
;
1287 pa_scache_entry
*sample
= NULL
;
1288 const char *object_path
;
1294 chunk
.memblock
= NULL
;
1296 pa_assert_se(dbus_message_iter_init(msg
, &msg_iter
));
1297 dbus_message_iter_get_basic(&msg_iter
, &name
);
1299 pa_assert_se(dbus_message_iter_next(&msg_iter
));
1300 dbus_message_iter_get_basic(&msg_iter
, &sample_format
);
1302 pa_assert_se(dbus_message_iter_next(&msg_iter
));
1303 dbus_message_iter_get_basic(&msg_iter
, &sample_rate
);
1305 pa_assert_se(dbus_message_iter_next(&msg_iter
));
1306 dbus_message_iter_recurse(&msg_iter
, &array_iter
);
1307 dbus_message_iter_get_fixed_array(&array_iter
, &channels
, &n_channels
);
1309 pa_assert_se(dbus_message_iter_next(&msg_iter
));
1310 dbus_message_iter_recurse(&msg_iter
, &array_iter
);
1311 dbus_message_iter_get_fixed_array(&array_iter
, &default_volume
, &n_volume_entries
);
1313 pa_assert_se(dbus_message_iter_next(&msg_iter
));
1314 if (!(property_list
= pa_dbus_get_proplist_arg(conn
, msg
, &msg_iter
)))
1317 dbus_message_iter_recurse(&msg_iter
, &array_iter
);
1318 dbus_message_iter_get_fixed_array(&array_iter
, &data
, &data_length
);
1320 if (sample_format
>= PA_SAMPLE_MAX
) {
1321 pa_dbus_send_error(conn
, msg
, DBUS_ERROR_INVALID_ARGS
, "Invalid sample format.");
1325 if (sample_rate
<= 0 || sample_rate
> PA_RATE_MAX
) {
1326 pa_dbus_send_error(conn
, msg
, DBUS_ERROR_INVALID_ARGS
, "Invalid sample rate.");
1330 if (n_channels
<= 0) {
1331 pa_dbus_send_error(conn
, msg
, DBUS_ERROR_INVALID_ARGS
, "Empty channel map.");
1335 if (n_channels
> (int) PA_CHANNELS_MAX
) {
1336 pa_dbus_send_error(conn
, msg
, DBUS_ERROR_INVALID_ARGS
,
1337 "Too many channels: %i. The maximum is %u.", n_channels
, PA_CHANNELS_MAX
);
1341 for (i
= 0; i
< n_channels
; ++i
) {
1342 if (channels
[i
] >= PA_CHANNEL_POSITION_MAX
) {
1343 pa_dbus_send_error(conn
, msg
, DBUS_ERROR_INVALID_ARGS
, "Invalid channel position.");
1348 if (n_volume_entries
!= 0 && n_volume_entries
!= n_channels
) {
1349 pa_dbus_send_error(conn
, msg
, DBUS_ERROR_INVALID_ARGS
,
1350 "The channels and default_volume arguments have different number of elements (%i and %i, resp).",
1351 n_channels
, n_volume_entries
);
1355 for (i
= 0; i
< n_volume_entries
; ++i
) {
1356 if (!PA_VOLUME_IS_VALID(default_volume
[i
])) {
1357 pa_dbus_send_error(conn
, msg
, DBUS_ERROR_INVALID_ARGS
, "Invalid volume: %u.", default_volume
[i
]);
1362 if (data_length
== 0) {
1363 pa_dbus_send_error(conn
, msg
, DBUS_ERROR_INVALID_ARGS
, "Empty data.");
1367 if (data_length
> PA_SCACHE_ENTRY_SIZE_MAX
) {
1368 pa_dbus_send_error(conn
, msg
, DBUS_ERROR_INVALID_ARGS
,
1369 "Too big sample: %i bytes. The maximum sample length is %u bytes.",
1370 data_length
, PA_SCACHE_ENTRY_SIZE_MAX
);
1374 ss
.format
= sample_format
;
1375 ss
.rate
= sample_rate
;
1376 ss
.channels
= n_channels
;
1378 pa_assert(pa_sample_spec_valid(&ss
));
1380 if (!pa_frame_aligned(data_length
, &ss
)) {
1381 char buf
[PA_SAMPLE_SPEC_SNPRINT_MAX
];
1382 pa_dbus_send_error(conn
, msg
, DBUS_ERROR_INVALID_ARGS
,
1383 "The sample length (%i bytes) doesn't align with the sample format and channels (%s).",
1384 data_length
, pa_sample_spec_snprint(buf
, sizeof(buf
), &ss
));
1388 map
.channels
= n_channels
;
1389 for (i
= 0; i
< n_channels
; ++i
)
1390 map
.map
[i
] = channels
[i
];
1392 chunk
.memblock
= pa_memblock_new(c
->core
->mempool
, data_length
);
1394 chunk
.length
= data_length
;
1396 memcpy(pa_memblock_acquire(chunk
.memblock
), data
, data_length
);
1397 pa_memblock_release(chunk
.memblock
);
1399 if (pa_scache_add_item(c
->core
, name
, &ss
, &map
, &chunk
, property_list
, &idx
) < 0) {
1400 pa_dbus_send_error(conn
, msg
, DBUS_ERROR_FAILED
, "Adding the sample failed.");
1404 pa_assert_se(sample
= pa_idxset_get_by_index(c
->core
->scache
, idx
));
1406 if (n_volume_entries
> 0) {
1407 sample
->volume
.channels
= n_channels
;
1408 for (i
= 0; i
< n_volume_entries
; ++i
)
1409 sample
->volume
.values
[i
] = default_volume
[i
];
1410 sample
->volume_is_set
= true;
1412 sample
->volume_is_set
= false;
1415 dbus_sample
= pa_dbusiface_sample_new(c
, sample
);
1416 pa_hashmap_put(c
->samples
, PA_UINT32_TO_PTR(idx
), dbus_sample
);
1418 object_path
= pa_dbusiface_sample_get_path(dbus_sample
);
1420 pa_dbus_send_basic_value_reply(conn
, msg
, DBUS_TYPE_OBJECT_PATH
, &object_path
);
1424 pa_proplist_free(property_list
);
1427 pa_memblock_unref(chunk
.memblock
);
1430 static bool contains_space(const char *string
) {
1435 for (p
= string
; *p
; ++p
) {
1443 static void handle_load_module(DBusConnection
*conn
, DBusMessage
*msg
, void *userdata
) {
1444 pa_dbusiface_core
*c
= userdata
;
1445 DBusMessageIter msg_iter
;
1446 DBusMessageIter dict_iter
;
1447 DBusMessageIter dict_entry_iter
;
1449 const char *key
= NULL
;
1450 const char *value
= NULL
;
1451 char *escaped_value
= NULL
;
1452 pa_strbuf
*arg_buffer
= NULL
;
1453 char *arg_string
= NULL
;
1454 pa_module
*module
= NULL
;
1455 pa_dbusiface_module
*dbus_module
= NULL
;
1456 const char *object_path
= NULL
;
1462 if (c
->core
->disallow_module_loading
) {
1463 pa_dbus_send_error(conn
, msg
, DBUS_ERROR_ACCESS_DENIED
, "The server is configured to disallow module loading.");
1467 pa_assert_se(dbus_message_iter_init(msg
, &msg_iter
));
1468 dbus_message_iter_get_basic(&msg_iter
, &name
);
1470 arg_buffer
= pa_strbuf_new();
1472 pa_assert_se(dbus_message_iter_next(&msg_iter
));
1473 dbus_message_iter_recurse(&msg_iter
, &dict_iter
);
1475 while (dbus_message_iter_get_arg_type(&dict_iter
) != DBUS_TYPE_INVALID
) {
1476 if (!pa_strbuf_isempty(arg_buffer
))
1477 pa_strbuf_putc(arg_buffer
, ' ');
1479 dbus_message_iter_recurse(&dict_iter
, &dict_entry_iter
);
1481 dbus_message_iter_get_basic(&dict_entry_iter
, &key
);
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 pa_assert_se(dbus_message_iter_next(&dict_entry_iter
));
1489 dbus_message_iter_get_basic(&dict_entry_iter
, &value
);
1491 escaped_value
= pa_escape(value
, "\"");
1492 pa_strbuf_printf(arg_buffer
, "%s=\"%s\"", key
, escaped_value
);
1493 pa_xfree(escaped_value
);
1495 dbus_message_iter_next(&dict_iter
);
1498 arg_string
= pa_strbuf_tostring(arg_buffer
);
1500 if (!(module
= pa_module_load(c
->core
, name
, arg_string
))) {
1501 pa_dbus_send_error(conn
, msg
, DBUS_ERROR_FAILED
, "Failed to load module.");
1505 dbus_module
= pa_dbusiface_module_new(module
);
1506 pa_hashmap_put(c
->modules
, PA_UINT32_TO_PTR(module
->index
), dbus_module
);
1508 object_path
= pa_dbusiface_module_get_path(dbus_module
);
1510 pa_dbus_send_basic_value_reply(conn
, msg
, DBUS_TYPE_OBJECT_PATH
, &object_path
);
1514 pa_strbuf_free(arg_buffer
);
1516 pa_xfree(arg_string
);
1519 static void handle_exit(DBusConnection
*conn
, DBusMessage
*msg
, void *userdata
) {
1520 pa_dbusiface_core
*c
= userdata
;
1526 if (c
->core
->disallow_exit
) {
1527 pa_dbus_send_error(conn
, msg
, DBUS_ERROR_ACCESS_DENIED
, "The server is configured to disallow exiting.");
1531 pa_dbus_send_empty_reply(conn
, msg
);
1533 pa_core_exit(c
->core
, false, 0);
1536 static void handle_listen_for_signal(DBusConnection
*conn
, DBusMessage
*msg
, void *userdata
) {
1537 pa_dbusiface_core
*c
= userdata
;
1538 const char *signal_str
;
1539 char **objects
= NULL
;
1546 pa_assert_se(dbus_message_get_args(msg
, NULL
,
1547 DBUS_TYPE_STRING
, &signal_str
,
1548 DBUS_TYPE_ARRAY
, DBUS_TYPE_OBJECT_PATH
, &objects
, &n_objects
,
1549 DBUS_TYPE_INVALID
));
1551 pa_dbus_protocol_add_signal_listener(c
->dbus_protocol
, conn
, *signal_str
? signal_str
: NULL
, objects
, n_objects
);
1553 pa_dbus_send_empty_reply(conn
, msg
);
1555 dbus_free_string_array(objects
);
1558 static void handle_stop_listening_for_signal(DBusConnection
*conn
, DBusMessage
*msg
, void *userdata
) {
1559 pa_dbusiface_core
*c
= userdata
;
1560 const char *signal_str
;
1566 pa_assert_se(dbus_message_get_args(msg
, NULL
, DBUS_TYPE_STRING
, &signal_str
, DBUS_TYPE_INVALID
));
1568 pa_dbus_protocol_remove_signal_listener(c
->dbus_protocol
, conn
, *signal_str
? signal_str
: NULL
);
1570 pa_dbus_send_empty_reply(conn
, msg
);
1573 static void subscription_cb(pa_core
*core
, pa_subscription_event_type_t t
, uint32_t idx
, void *userdata
) {
1574 pa_dbusiface_core
*c
= userdata
;
1575 pa_dbusiface_card
*card_iface
= NULL
;
1576 pa_dbusiface_device
*device_iface
= NULL
;
1577 pa_dbusiface_stream
*stream_iface
= NULL
;
1578 pa_dbusiface_sample
*sample_iface
= NULL
;
1579 pa_dbusiface_module
*module_iface
= NULL
;
1580 pa_dbusiface_client
*client_iface
= NULL
;
1581 DBusMessage
*signal_msg
= NULL
;
1582 const char *object_path
= NULL
;
1583 pa_sink
*new_fallback_sink
= NULL
;
1584 pa_source
*new_fallback_source
= NULL
;
1588 switch (t
& PA_SUBSCRIPTION_EVENT_FACILITY_MASK
) {
1589 case PA_SUBSCRIPTION_EVENT_SERVER
:
1590 new_fallback_sink
= pa_namereg_get_default_sink(core
);
1591 new_fallback_source
= pa_namereg_get_default_source(core
);
1593 if (c
->fallback_sink
!= new_fallback_sink
) {
1594 if (c
->fallback_sink
)
1595 pa_sink_unref(c
->fallback_sink
);
1596 c
->fallback_sink
= new_fallback_sink
? pa_sink_ref(new_fallback_sink
) : NULL
;
1598 if (c
->fallback_sink
) {
1599 pa_assert_se(device_iface
= pa_hashmap_get(c
->sinks_by_index
, PA_UINT32_TO_PTR(c
->fallback_sink
->index
)));
1600 object_path
= pa_dbusiface_device_get_path(device_iface
);
1602 pa_assert_se((signal_msg
= dbus_message_new_signal(PA_DBUS_CORE_OBJECT_PATH
,
1603 PA_DBUS_CORE_INTERFACE
,
1604 signals
[SIGNAL_FALLBACK_SINK_UPDATED
].name
)));
1605 pa_assert_se(dbus_message_append_args(signal_msg
, DBUS_TYPE_OBJECT_PATH
, &object_path
, DBUS_TYPE_INVALID
));
1606 pa_dbus_protocol_send_signal(c
->dbus_protocol
, signal_msg
);
1607 dbus_message_unref(signal_msg
);
1611 pa_assert_se((signal_msg
= dbus_message_new_signal(PA_DBUS_CORE_OBJECT_PATH
,
1612 PA_DBUS_CORE_INTERFACE
,
1613 signals
[SIGNAL_FALLBACK_SINK_UNSET
].name
)));
1614 pa_dbus_protocol_send_signal(c
->dbus_protocol
, signal_msg
);
1615 dbus_message_unref(signal_msg
);
1620 if (c
->fallback_source
!= new_fallback_source
) {
1621 if (c
->fallback_source
)
1622 pa_source_unref(c
->fallback_source
);
1623 c
->fallback_source
= new_fallback_source
? pa_source_ref(new_fallback_source
) : NULL
;
1625 if (c
->fallback_source
) {
1626 pa_assert_se(device_iface
= pa_hashmap_get(c
->sources_by_index
, PA_UINT32_TO_PTR(c
->fallback_source
->index
)));
1627 object_path
= pa_dbusiface_device_get_path(device_iface
);
1629 pa_assert_se((signal_msg
= dbus_message_new_signal(PA_DBUS_CORE_OBJECT_PATH
,
1630 PA_DBUS_CORE_INTERFACE
,
1631 signals
[SIGNAL_FALLBACK_SOURCE_UPDATED
].name
)));
1632 pa_assert_se(dbus_message_append_args(signal_msg
, DBUS_TYPE_OBJECT_PATH
, &object_path
, DBUS_TYPE_INVALID
));
1633 pa_dbus_protocol_send_signal(c
->dbus_protocol
, signal_msg
);
1634 dbus_message_unref(signal_msg
);
1638 pa_assert_se((signal_msg
= dbus_message_new_signal(PA_DBUS_CORE_OBJECT_PATH
,
1639 PA_DBUS_CORE_INTERFACE
,
1640 signals
[SIGNAL_FALLBACK_SOURCE_UNSET
].name
)));
1641 pa_dbus_protocol_send_signal(c
->dbus_protocol
, signal_msg
);
1642 dbus_message_unref(signal_msg
);
1648 case PA_SUBSCRIPTION_EVENT_CARD
:
1649 if ((t
& PA_SUBSCRIPTION_EVENT_TYPE_MASK
) == PA_SUBSCRIPTION_EVENT_NEW
) {
1650 if (!(card_iface
= pa_hashmap_get(c
->cards
, PA_UINT32_TO_PTR(idx
)))) {
1651 pa_card
*card
= NULL
;
1653 if (!(card
= pa_idxset_get_by_index(core
->cards
, idx
)))
1654 return; /* The card was removed immediately after creation. */
1656 card_iface
= pa_dbusiface_card_new(c
, card
);
1657 pa_hashmap_put(c
->cards
, PA_UINT32_TO_PTR(idx
), card_iface
);
1660 object_path
= pa_dbusiface_card_get_path(card_iface
);
1662 pa_assert_se((signal_msg
= dbus_message_new_signal(PA_DBUS_CORE_OBJECT_PATH
,
1663 PA_DBUS_CORE_INTERFACE
,
1664 signals
[SIGNAL_NEW_CARD
].name
)));
1665 pa_assert_se(dbus_message_append_args(signal_msg
, DBUS_TYPE_OBJECT_PATH
, &object_path
, DBUS_TYPE_INVALID
));
1667 } else if ((t
& PA_SUBSCRIPTION_EVENT_TYPE_MASK
) == PA_SUBSCRIPTION_EVENT_REMOVE
) {
1668 if (!(card_iface
= pa_hashmap_remove(c
->cards
, PA_UINT32_TO_PTR(idx
))))
1671 object_path
= pa_dbusiface_card_get_path(card_iface
);
1673 pa_assert_se((signal_msg
= dbus_message_new_signal(PA_DBUS_CORE_OBJECT_PATH
,
1674 PA_DBUS_CORE_INTERFACE
,
1675 signals
[SIGNAL_CARD_REMOVED
].name
)));
1676 pa_assert_se(dbus_message_append_args(signal_msg
, DBUS_TYPE_OBJECT_PATH
, &object_path
, DBUS_TYPE_INVALID
));
1678 pa_dbusiface_card_free(card_iface
);
1682 case PA_SUBSCRIPTION_EVENT_SINK_INPUT
:
1683 if ((t
& PA_SUBSCRIPTION_EVENT_TYPE_MASK
) == PA_SUBSCRIPTION_EVENT_NEW
) {
1684 pa_sink_input
*sink_input
= NULL
;
1686 if (!(sink_input
= pa_idxset_get_by_index(core
->sink_inputs
, idx
)))
1687 return; /* The sink input was removed immediately after creation. */
1689 if (!(stream_iface
= pa_hashmap_get(c
->playback_streams
, PA_UINT32_TO_PTR(idx
)))) {
1690 stream_iface
= pa_dbusiface_stream_new_playback(c
, sink_input
);
1691 pa_hashmap_put(c
->playback_streams
, PA_UINT32_TO_PTR(idx
), stream_iface
);
1694 object_path
= pa_dbusiface_stream_get_path(stream_iface
);
1696 pa_assert_se((signal_msg
= dbus_message_new_signal(PA_DBUS_CORE_OBJECT_PATH
,
1697 PA_DBUS_CORE_INTERFACE
,
1698 signals
[SIGNAL_NEW_PLAYBACK_STREAM
].name
)));
1699 pa_assert_se(dbus_message_append_args(signal_msg
, DBUS_TYPE_OBJECT_PATH
, &object_path
, DBUS_TYPE_INVALID
));
1701 } else if ((t
& PA_SUBSCRIPTION_EVENT_TYPE_MASK
) == PA_SUBSCRIPTION_EVENT_REMOVE
) {
1702 if (!(stream_iface
= pa_hashmap_remove(c
->playback_streams
, PA_UINT32_TO_PTR(idx
))))
1705 object_path
= pa_dbusiface_stream_get_path(stream_iface
);
1707 pa_assert_se((signal_msg
= dbus_message_new_signal(PA_DBUS_CORE_OBJECT_PATH
,
1708 PA_DBUS_CORE_INTERFACE
,
1709 signals
[SIGNAL_PLAYBACK_STREAM_REMOVED
].name
)));
1710 pa_assert_se(dbus_message_append_args(signal_msg
, DBUS_TYPE_OBJECT_PATH
, &object_path
, DBUS_TYPE_INVALID
));
1712 pa_dbusiface_stream_free(stream_iface
);
1716 case PA_SUBSCRIPTION_EVENT_SOURCE_OUTPUT
:
1717 if ((t
& PA_SUBSCRIPTION_EVENT_TYPE_MASK
) == PA_SUBSCRIPTION_EVENT_NEW
) {
1718 pa_source_output
*source_output
= NULL
;
1720 if (!(source_output
= pa_idxset_get_by_index(core
->source_outputs
, idx
)))
1721 return; /* The source output was removed immediately after creation. */
1723 if (!(stream_iface
= pa_hashmap_get(c
->record_streams
, PA_UINT32_TO_PTR(idx
)))) {
1724 stream_iface
= pa_dbusiface_stream_new_record(c
, source_output
);
1725 pa_hashmap_put(c
->record_streams
, PA_UINT32_TO_PTR(idx
), stream_iface
);
1728 object_path
= pa_dbusiface_stream_get_path(stream_iface
);
1730 pa_assert_se((signal_msg
= dbus_message_new_signal(PA_DBUS_CORE_OBJECT_PATH
,
1731 PA_DBUS_CORE_INTERFACE
,
1732 signals
[SIGNAL_NEW_RECORD_STREAM
].name
)));
1733 pa_assert_se(dbus_message_append_args(signal_msg
, DBUS_TYPE_OBJECT_PATH
, &object_path
, DBUS_TYPE_INVALID
));
1735 } else if ((t
& PA_SUBSCRIPTION_EVENT_TYPE_MASK
) == PA_SUBSCRIPTION_EVENT_REMOVE
) {
1736 if (!(stream_iface
= pa_hashmap_remove(c
->record_streams
, PA_UINT32_TO_PTR(idx
))))
1739 object_path
= pa_dbusiface_stream_get_path(stream_iface
);
1741 pa_assert_se((signal_msg
= dbus_message_new_signal(PA_DBUS_CORE_OBJECT_PATH
,
1742 PA_DBUS_CORE_INTERFACE
,
1743 signals
[SIGNAL_RECORD_STREAM_REMOVED
].name
)));
1744 pa_assert_se(dbus_message_append_args(signal_msg
, DBUS_TYPE_OBJECT_PATH
, &object_path
, DBUS_TYPE_INVALID
));
1746 pa_dbusiface_stream_free(stream_iface
);
1750 case PA_SUBSCRIPTION_EVENT_SAMPLE_CACHE
:
1751 if ((t
& PA_SUBSCRIPTION_EVENT_TYPE_MASK
) == PA_SUBSCRIPTION_EVENT_NEW
) {
1752 pa_scache_entry
*sample
= NULL
;
1754 if (!(sample
= pa_idxset_get_by_index(core
->scache
, idx
)))
1755 return; /* The sample was removed immediately after creation. */
1757 if (!(sample_iface
= pa_hashmap_get(c
->samples
, PA_UINT32_TO_PTR(idx
)))) {
1758 sample_iface
= pa_dbusiface_sample_new(c
, sample
);
1759 pa_hashmap_put(c
->samples
, PA_UINT32_TO_PTR(idx
), sample_iface
);
1762 object_path
= pa_dbusiface_sample_get_path(sample_iface
);
1764 pa_assert_se((signal_msg
= dbus_message_new_signal(PA_DBUS_CORE_OBJECT_PATH
,
1765 PA_DBUS_CORE_INTERFACE
,
1766 signals
[SIGNAL_NEW_SAMPLE
].name
)));
1767 pa_assert_se(dbus_message_append_args(signal_msg
, DBUS_TYPE_OBJECT_PATH
, &object_path
, DBUS_TYPE_INVALID
));
1769 } else if ((t
& PA_SUBSCRIPTION_EVENT_TYPE_MASK
) == PA_SUBSCRIPTION_EVENT_REMOVE
) {
1770 if (!(sample_iface
= pa_hashmap_remove(c
->samples
, PA_UINT32_TO_PTR(idx
))))
1773 object_path
= pa_dbusiface_sample_get_path(sample_iface
);
1775 pa_assert_se((signal_msg
= dbus_message_new_signal(PA_DBUS_CORE_OBJECT_PATH
,
1776 PA_DBUS_CORE_INTERFACE
,
1777 signals
[SIGNAL_SAMPLE_REMOVED
].name
)));
1778 pa_assert_se(dbus_message_append_args(signal_msg
, DBUS_TYPE_OBJECT_PATH
, &object_path
, DBUS_TYPE_INVALID
));
1780 pa_dbusiface_sample_free(sample_iface
);
1784 case PA_SUBSCRIPTION_EVENT_MODULE
:
1785 if ((t
& PA_SUBSCRIPTION_EVENT_TYPE_MASK
) == PA_SUBSCRIPTION_EVENT_NEW
) {
1786 pa_module
*module
= NULL
;
1788 if (!(module
= pa_idxset_get_by_index(core
->modules
, idx
)))
1789 return; /* The module was removed immediately after creation. */
1791 if (!(module_iface
= pa_hashmap_get(c
->modules
, PA_UINT32_TO_PTR(idx
)))) {
1792 module_iface
= pa_dbusiface_module_new(module
);
1793 pa_hashmap_put(c
->modules
, PA_UINT32_TO_PTR(idx
), module_iface
);
1796 object_path
= pa_dbusiface_module_get_path(module_iface
);
1798 pa_assert_se((signal_msg
= dbus_message_new_signal(PA_DBUS_CORE_OBJECT_PATH
,
1799 PA_DBUS_CORE_INTERFACE
,
1800 signals
[SIGNAL_NEW_MODULE
].name
)));
1801 pa_assert_se(dbus_message_append_args(signal_msg
, DBUS_TYPE_OBJECT_PATH
, &object_path
, DBUS_TYPE_INVALID
));
1803 } else if ((t
& PA_SUBSCRIPTION_EVENT_TYPE_MASK
) == PA_SUBSCRIPTION_EVENT_REMOVE
) {
1804 if (!(module_iface
= pa_hashmap_remove(c
->modules
, PA_UINT32_TO_PTR(idx
))))
1807 object_path
= pa_dbusiface_module_get_path(module_iface
);
1809 pa_assert_se((signal_msg
= dbus_message_new_signal(PA_DBUS_CORE_OBJECT_PATH
,
1810 PA_DBUS_CORE_INTERFACE
,
1811 signals
[SIGNAL_MODULE_REMOVED
].name
)));
1812 pa_assert_se(dbus_message_append_args(signal_msg
, DBUS_TYPE_OBJECT_PATH
, &object_path
, DBUS_TYPE_INVALID
));
1814 pa_dbusiface_module_free(module_iface
);
1818 case PA_SUBSCRIPTION_EVENT_CLIENT
:
1819 if ((t
& PA_SUBSCRIPTION_EVENT_TYPE_MASK
) == PA_SUBSCRIPTION_EVENT_NEW
) {
1820 pa_client
*client
= NULL
;
1822 if (!(client
= pa_idxset_get_by_index(core
->clients
, idx
)))
1823 return; /* The client was removed immediately after creation. */
1825 if (!(client_iface
= pa_hashmap_get(c
->clients
, PA_UINT32_TO_PTR(idx
)))) {
1826 client_iface
= pa_dbusiface_client_new(c
, client
);
1827 pa_hashmap_put(c
->clients
, PA_UINT32_TO_PTR(idx
), client_iface
);
1830 object_path
= pa_dbusiface_client_get_path(client_iface
);
1832 pa_assert_se((signal_msg
= dbus_message_new_signal(PA_DBUS_CORE_OBJECT_PATH
,
1833 PA_DBUS_CORE_INTERFACE
,
1834 signals
[SIGNAL_NEW_CLIENT
].name
)));
1835 pa_assert_se(dbus_message_append_args(signal_msg
, DBUS_TYPE_OBJECT_PATH
, &object_path
, DBUS_TYPE_INVALID
));
1837 } else if ((t
& PA_SUBSCRIPTION_EVENT_TYPE_MASK
) == PA_SUBSCRIPTION_EVENT_REMOVE
) {
1838 if (!(client_iface
= pa_hashmap_remove(c
->clients
, PA_UINT32_TO_PTR(idx
))))
1841 object_path
= pa_dbusiface_client_get_path(client_iface
);
1843 pa_assert_se((signal_msg
= dbus_message_new_signal(PA_DBUS_CORE_OBJECT_PATH
,
1844 PA_DBUS_CORE_INTERFACE
,
1845 signals
[SIGNAL_CLIENT_REMOVED
].name
)));
1846 pa_assert_se(dbus_message_append_args(signal_msg
, DBUS_TYPE_OBJECT_PATH
, &object_path
, DBUS_TYPE_INVALID
));
1848 pa_dbusiface_client_free(client_iface
);
1854 pa_dbus_protocol_send_signal(c
->dbus_protocol
, signal_msg
);
1855 dbus_message_unref(signal_msg
);
1859 static pa_hook_result_t
sink_put_cb(void *hook_data
, void *call_data
, void *slot_data
) {
1860 pa_dbusiface_core
*c
= slot_data
;
1861 pa_sink
*s
= call_data
;
1862 pa_dbusiface_device
*d
= NULL
;
1863 const char *object_path
= NULL
;
1864 DBusMessage
*signal_msg
= NULL
;
1869 d
= pa_dbusiface_device_new_sink(c
, s
);
1870 object_path
= pa_dbusiface_device_get_path(d
);
1872 pa_assert_se(pa_hashmap_put(c
->sinks_by_index
, PA_UINT32_TO_PTR(s
->index
), d
) >= 0);
1873 pa_assert_se(pa_hashmap_put(c
->sinks_by_path
, object_path
, d
) >= 0);
1875 pa_assert_se(signal_msg
= dbus_message_new_signal(PA_DBUS_CORE_OBJECT_PATH
,
1876 PA_DBUS_CORE_INTERFACE
,
1877 signals
[SIGNAL_NEW_SINK
].name
));
1878 pa_assert_se(dbus_message_append_args(signal_msg
, DBUS_TYPE_OBJECT_PATH
, &object_path
, DBUS_TYPE_INVALID
));
1880 pa_dbus_protocol_send_signal(c
->dbus_protocol
, signal_msg
);
1881 dbus_message_unref(signal_msg
);
1886 static pa_hook_result_t
sink_unlink_cb(void *hook_data
, void *call_data
, void *slot_data
) {
1887 pa_dbusiface_core
*c
= slot_data
;
1888 pa_sink
*s
= call_data
;
1889 pa_dbusiface_device
*d
= NULL
;
1890 const char *object_path
= NULL
;
1891 DBusMessage
*signal_msg
= NULL
;
1896 pa_assert_se(d
= pa_hashmap_remove(c
->sinks_by_index
, PA_UINT32_TO_PTR(s
->index
)));
1897 object_path
= pa_dbusiface_device_get_path(d
);
1898 pa_assert_se(pa_hashmap_remove(c
->sinks_by_path
, object_path
));
1900 pa_assert_se(signal_msg
= dbus_message_new_signal(PA_DBUS_CORE_OBJECT_PATH
,
1901 PA_DBUS_CORE_INTERFACE
,
1902 signals
[SIGNAL_SINK_REMOVED
].name
));
1903 pa_assert_se(dbus_message_append_args(signal_msg
, DBUS_TYPE_OBJECT_PATH
, &object_path
, DBUS_TYPE_INVALID
));
1905 pa_dbus_protocol_send_signal(c
->dbus_protocol
, signal_msg
);
1906 dbus_message_unref(signal_msg
);
1908 pa_dbusiface_device_free(d
);
1913 static pa_hook_result_t
source_put_cb(void *hook_data
, void *call_data
, void *slot_data
) {
1914 pa_dbusiface_core
*c
= slot_data
;
1915 pa_source
*s
= call_data
;
1916 pa_dbusiface_device
*d
= NULL
;
1917 const char *object_path
= NULL
;
1918 DBusMessage
*signal_msg
= NULL
;
1923 d
= pa_dbusiface_device_new_source(c
, s
);
1924 object_path
= pa_dbusiface_device_get_path(d
);
1926 pa_assert_se(pa_hashmap_put(c
->sources_by_index
, PA_UINT32_TO_PTR(s
->index
), d
) >= 0);
1927 pa_assert_se(pa_hashmap_put(c
->sources_by_path
, object_path
, d
) >= 0);
1929 pa_assert_se((signal_msg
= dbus_message_new_signal(PA_DBUS_CORE_OBJECT_PATH
,
1930 PA_DBUS_CORE_INTERFACE
,
1931 signals
[SIGNAL_NEW_SOURCE
].name
)));
1932 pa_assert_se(dbus_message_append_args(signal_msg
, DBUS_TYPE_OBJECT_PATH
, &object_path
, DBUS_TYPE_INVALID
));
1934 pa_dbus_protocol_send_signal(c
->dbus_protocol
, signal_msg
);
1935 dbus_message_unref(signal_msg
);
1940 static pa_hook_result_t
source_unlink_cb(void *hook_data
, void *call_data
, void *slot_data
) {
1941 pa_dbusiface_core
*c
= slot_data
;
1942 pa_source
*s
= call_data
;
1943 pa_dbusiface_device
*d
= NULL
;
1944 const char *object_path
= NULL
;
1945 DBusMessage
*signal_msg
= NULL
;
1950 pa_assert_se(d
= pa_hashmap_remove(c
->sources_by_index
, PA_UINT32_TO_PTR(s
->index
)));
1951 object_path
= pa_dbusiface_device_get_path(d
);
1952 pa_assert_se(pa_hashmap_remove(c
->sources_by_path
, object_path
));
1954 pa_assert_se(signal_msg
= dbus_message_new_signal(PA_DBUS_CORE_OBJECT_PATH
,
1955 PA_DBUS_CORE_INTERFACE
,
1956 signals
[SIGNAL_SOURCE_REMOVED
].name
));
1957 pa_assert_se(dbus_message_append_args(signal_msg
, DBUS_TYPE_OBJECT_PATH
, &object_path
, DBUS_TYPE_INVALID
));
1959 pa_dbus_protocol_send_signal(c
->dbus_protocol
, signal_msg
);
1960 dbus_message_unref(signal_msg
);
1962 pa_dbusiface_device_free(d
);
1967 static pa_hook_result_t
extension_registered_cb(void *hook_data
, void *call_data
, void *slot_data
) {
1968 pa_dbusiface_core
*c
= slot_data
;
1969 const char *ext_name
= call_data
;
1970 DBusMessage
*signal_msg
= NULL
;
1973 pa_assert(ext_name
);
1975 pa_assert_se((signal_msg
= dbus_message_new_signal(PA_DBUS_CORE_OBJECT_PATH
,
1976 PA_DBUS_CORE_INTERFACE
,
1977 signals
[SIGNAL_NEW_EXTENSION
].name
)));
1978 pa_assert_se(dbus_message_append_args(signal_msg
, DBUS_TYPE_STRING
, &ext_name
, DBUS_TYPE_INVALID
));
1980 pa_dbus_protocol_send_signal(c
->dbus_protocol
, signal_msg
);
1981 dbus_message_unref(signal_msg
);
1986 static pa_hook_result_t
extension_unregistered_cb(void *hook_data
, void *call_data
, void *slot_data
) {
1987 pa_dbusiface_core
*c
= slot_data
;
1988 const char *ext_name
= call_data
;
1989 DBusMessage
*signal_msg
= NULL
;
1992 pa_assert(ext_name
);
1994 pa_assert_se((signal_msg
= dbus_message_new_signal(PA_DBUS_CORE_OBJECT_PATH
,
1995 PA_DBUS_CORE_INTERFACE
,
1996 signals
[SIGNAL_EXTENSION_REMOVED
].name
)));
1997 pa_assert_se(dbus_message_append_args(signal_msg
, DBUS_TYPE_STRING
, &ext_name
, DBUS_TYPE_INVALID
));
1999 pa_dbus_protocol_send_signal(c
->dbus_protocol
, signal_msg
);
2000 dbus_message_unref(signal_msg
);
2005 pa_dbusiface_core
*pa_dbusiface_core_new(pa_core
*core
) {
2006 pa_dbusiface_core
*c
;
2010 pa_dbusiface_device
*device
;
2011 pa_sink_input
*sink_input
;
2012 pa_source_output
*source_output
;
2013 pa_scache_entry
*sample
;
2020 c
= pa_xnew(pa_dbusiface_core
, 1);
2022 c
->subscription
= pa_subscription_new(core
, PA_SUBSCRIPTION_MASK_ALL
, subscription_cb
, c
);
2023 c
->dbus_protocol
= pa_dbus_protocol_get(core
);
2024 c
->cards
= pa_hashmap_new(pa_idxset_trivial_hash_func
, pa_idxset_trivial_compare_func
);
2025 c
->sinks_by_index
= pa_hashmap_new(pa_idxset_trivial_hash_func
, pa_idxset_trivial_compare_func
);
2026 c
->sinks_by_path
= pa_hashmap_new(pa_idxset_string_hash_func
, pa_idxset_string_compare_func
);
2027 c
->sources_by_index
= pa_hashmap_new(pa_idxset_trivial_hash_func
, pa_idxset_trivial_compare_func
);
2028 c
->sources_by_path
= pa_hashmap_new(pa_idxset_string_hash_func
, pa_idxset_string_compare_func
);
2029 c
->playback_streams
= pa_hashmap_new(pa_idxset_trivial_hash_func
, pa_idxset_trivial_compare_func
);
2030 c
->record_streams
= pa_hashmap_new(pa_idxset_trivial_hash_func
, pa_idxset_trivial_compare_func
);
2031 c
->samples
= pa_hashmap_new(pa_idxset_trivial_hash_func
, pa_idxset_trivial_compare_func
);
2032 c
->modules
= pa_hashmap_new(pa_idxset_trivial_hash_func
, pa_idxset_trivial_compare_func
);
2033 c
->clients
= pa_hashmap_new(pa_idxset_trivial_hash_func
, pa_idxset_trivial_compare_func
);
2034 c
->fallback_sink
= pa_namereg_get_default_sink(core
);
2035 c
->fallback_source
= pa_namereg_get_default_source(core
);
2036 c
->sink_put_slot
= pa_hook_connect(&core
->hooks
[PA_CORE_HOOK_SINK_PUT
], PA_HOOK_NORMAL
, sink_put_cb
, c
);
2037 c
->sink_unlink_slot
= pa_hook_connect(&core
->hooks
[PA_CORE_HOOK_SINK_UNLINK
], PA_HOOK_NORMAL
, sink_unlink_cb
, c
);
2038 c
->source_put_slot
= pa_hook_connect(&core
->hooks
[PA_CORE_HOOK_SOURCE_PUT
], PA_HOOK_NORMAL
, source_put_cb
, c
);
2039 c
->source_unlink_slot
= pa_hook_connect(&core
->hooks
[PA_CORE_HOOK_SOURCE_UNLINK
], PA_HOOK_NORMAL
, source_unlink_cb
, c
);
2040 c
->extension_registered_slot
= pa_dbus_protocol_hook_connect(c
->dbus_protocol
,
2041 PA_DBUS_PROTOCOL_HOOK_EXTENSION_REGISTERED
,
2043 extension_registered_cb
,
2045 c
->extension_unregistered_slot
= pa_dbus_protocol_hook_connect(c
->dbus_protocol
,
2046 PA_DBUS_PROTOCOL_HOOK_EXTENSION_UNREGISTERED
,
2048 extension_unregistered_cb
,
2050 c
->memstats
= pa_dbusiface_memstats_new(c
, core
);
2052 if (c
->fallback_sink
)
2053 pa_sink_ref(c
->fallback_sink
);
2054 if (c
->fallback_source
)
2055 pa_source_ref(c
->fallback_source
);
2057 PA_IDXSET_FOREACH(card
, core
->cards
, idx
)
2058 pa_hashmap_put(c
->cards
, PA_UINT32_TO_PTR(idx
), pa_dbusiface_card_new(c
, card
));
2060 PA_IDXSET_FOREACH(sink
, core
->sinks
, idx
) {
2061 device
= pa_dbusiface_device_new_sink(c
, sink
);
2062 pa_hashmap_put(c
->sinks_by_index
, PA_UINT32_TO_PTR(idx
), device
);
2063 pa_hashmap_put(c
->sinks_by_path
, pa_dbusiface_device_get_path(device
), device
);
2066 PA_IDXSET_FOREACH(source
, core
->sources
, idx
) {
2067 device
= pa_dbusiface_device_new_source(c
, source
);
2068 pa_hashmap_put(c
->sources_by_index
, PA_UINT32_TO_PTR(idx
), device
);
2069 pa_hashmap_put(c
->sources_by_path
, pa_dbusiface_device_get_path(device
), device
);
2072 PA_IDXSET_FOREACH(sink_input
, core
->sink_inputs
, idx
)
2073 pa_hashmap_put(c
->playback_streams
, PA_UINT32_TO_PTR(idx
), pa_dbusiface_stream_new_playback(c
, sink_input
));
2075 PA_IDXSET_FOREACH(source_output
, core
->source_outputs
, idx
)
2076 pa_hashmap_put(c
->record_streams
, PA_UINT32_TO_PTR(idx
), pa_dbusiface_stream_new_record(c
, source_output
));
2078 PA_IDXSET_FOREACH(sample
, core
->scache
, idx
)
2079 pa_hashmap_put(c
->samples
, PA_UINT32_TO_PTR(idx
), pa_dbusiface_sample_new(c
, sample
));
2081 PA_IDXSET_FOREACH(module
, core
->modules
, idx
)
2082 pa_hashmap_put(c
->modules
, PA_UINT32_TO_PTR(idx
), pa_dbusiface_module_new(module
));
2084 PA_IDXSET_FOREACH(client
, core
->clients
, idx
)
2085 pa_hashmap_put(c
->clients
, PA_UINT32_TO_PTR(idx
), pa_dbusiface_client_new(c
, client
));
2087 pa_assert_se(pa_dbus_protocol_add_interface(c
->dbus_protocol
, PA_DBUS_CORE_OBJECT_PATH
, &core_interface_info
, c
) >= 0);
2092 void pa_dbusiface_core_free(pa_dbusiface_core
*c
) {
2095 pa_assert_se(pa_dbus_protocol_remove_interface(c
->dbus_protocol
, PA_DBUS_CORE_OBJECT_PATH
, core_interface_info
.name
) >= 0);
2097 /* Note that the order of freeing is important below.
2098 * Do not change it for the sake of tidiness without checking! */
2099 pa_subscription_free(c
->subscription
);
2100 pa_hashmap_free(c
->cards
, (pa_free_cb_t
) pa_dbusiface_card_free
);
2101 pa_hashmap_free(c
->sinks_by_path
, NULL
);
2102 pa_hashmap_free(c
->sinks_by_index
, (pa_free_cb_t
) pa_dbusiface_device_free
);
2103 pa_hashmap_free(c
->sources_by_path
, NULL
);
2104 pa_hashmap_free(c
->sources_by_index
, (pa_free_cb_t
) pa_dbusiface_device_free
);
2105 pa_hashmap_free(c
->playback_streams
, (pa_free_cb_t
) pa_dbusiface_stream_free
);
2106 pa_hashmap_free(c
->record_streams
, (pa_free_cb_t
) pa_dbusiface_stream_free
);
2107 pa_hashmap_free(c
->samples
, (pa_free_cb_t
) pa_dbusiface_sample_free
);
2108 pa_hashmap_free(c
->modules
, (pa_free_cb_t
) pa_dbusiface_module_free
);
2109 pa_hashmap_free(c
->clients
, (pa_free_cb_t
) pa_dbusiface_client_free
);
2110 pa_hook_slot_free(c
->sink_put_slot
);
2111 pa_hook_slot_free(c
->sink_unlink_slot
);
2112 pa_hook_slot_free(c
->source_put_slot
);
2113 pa_hook_slot_free(c
->source_unlink_slot
);
2114 pa_hook_slot_free(c
->extension_registered_slot
);
2115 pa_hook_slot_free(c
->extension_unregistered_slot
);
2116 pa_dbusiface_memstats_free(c
->memstats
);
2118 if (c
->fallback_sink
)
2119 pa_sink_unref(c
->fallback_sink
);
2120 if (c
->fallback_source
)
2121 pa_source_unref(c
->fallback_source
);
2123 pa_dbus_protocol_unref(c
->dbus_protocol
);
2128 const char *pa_dbusiface_core_get_card_path(pa_dbusiface_core
*c
, const pa_card
*card
) {
2132 return pa_dbusiface_card_get_path(pa_hashmap_get(c
->cards
, PA_UINT32_TO_PTR(card
->index
)));
2135 const char *pa_dbusiface_core_get_sink_path(pa_dbusiface_core
*c
, const pa_sink
*sink
) {
2139 return pa_dbusiface_device_get_path(pa_hashmap_get(c
->sinks_by_index
, PA_UINT32_TO_PTR(sink
->index
)));
2142 const char *pa_dbusiface_core_get_source_path(pa_dbusiface_core
*c
, const pa_source
*source
) {
2146 return pa_dbusiface_device_get_path(pa_hashmap_get(c
->sources_by_index
, PA_UINT32_TO_PTR(source
->index
)));
2149 const char *pa_dbusiface_core_get_playback_stream_path(pa_dbusiface_core
*c
, const pa_sink_input
*sink_input
) {
2151 pa_assert(sink_input
);
2153 return pa_dbusiface_stream_get_path(pa_hashmap_get(c
->playback_streams
, PA_UINT32_TO_PTR(sink_input
->index
)));
2156 const char *pa_dbusiface_core_get_record_stream_path(pa_dbusiface_core
*c
, const pa_source_output
*source_output
) {
2158 pa_assert(source_output
);
2160 return pa_dbusiface_stream_get_path(pa_hashmap_get(c
->record_streams
, PA_UINT32_TO_PTR(source_output
->index
)));
2163 const char *pa_dbusiface_core_get_module_path(pa_dbusiface_core
*c
, const pa_module
*module
) {
2167 return pa_dbusiface_module_get_path(pa_hashmap_get(c
->modules
, PA_UINT32_TO_PTR(module
->index
)));
2170 const char *pa_dbusiface_core_get_client_path(pa_dbusiface_core
*c
, const pa_client
*client
) {
2174 return pa_dbusiface_client_get_path(pa_hashmap_get(c
->clients
, PA_UINT32_TO_PTR(client
->index
)));
2177 pa_sink
*pa_dbusiface_core_get_sink(pa_dbusiface_core
*c
, const char *object_path
) {
2178 pa_dbusiface_device
*device
= NULL
;
2181 pa_assert(object_path
);
2183 device
= pa_hashmap_get(c
->sinks_by_path
, object_path
);
2186 return pa_dbusiface_device_get_sink(device
);
2191 pa_source
*pa_dbusiface_core_get_source(pa_dbusiface_core
*c
, const char *object_path
) {
2192 pa_dbusiface_device
*device
= NULL
;
2195 pa_assert(object_path
);
2197 device
= pa_hashmap_get(c
->sources_by_path
, object_path
);
2200 return pa_dbusiface_device_get_source(device
);