2 This file is part of PulseAudio.
4 Copyright 2009 Tanu Kaskinen
6 PulseAudio is free software; you can redistribute it and/or modify
7 it under the terms of the GNU Lesser General Public License as published
8 by the Free Software Foundation; either version 2.1 of the License,
9 or (at your option) any later version.
11 PulseAudio is distributed in the hope that it will be useful, but
12 WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 General Public License for more details.
16 You should have received a copy of the GNU Lesser General Public License
17 along with PulseAudio; if not, write to the Free Software
18 Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
28 #include <dbus/dbus.h>
30 #include <pulse/utf8.h>
31 #include <pulse/xmalloc.h>
33 #include <pulsecore/core-util.h>
34 #include <pulsecore/dbus-util.h>
35 #include <pulsecore/macro.h>
36 #include <pulsecore/namereg.h>
37 #include <pulsecore/protocol-dbus.h>
38 #include <pulsecore/socket-util.h>
39 #include <pulsecore/strbuf.h>
41 #include "iface-card.h"
42 #include "iface-client.h"
43 #include "iface-device.h"
44 #include "iface-memstats.h"
45 #include "iface-module.h"
46 #include "iface-sample.h"
47 #include "iface-stream.h"
49 #include "iface-core.h"
51 #define INTERFACE_REVISION 0
53 static void handle_get_interface_revision(DBusConnection
*conn
, DBusMessage
*msg
, void *userdata
);
54 static void handle_get_name(DBusConnection
*conn
, DBusMessage
*msg
, void *userdata
);
55 static void handle_get_version(DBusConnection
*conn
, DBusMessage
*msg
, void *userdata
);
56 static void handle_get_is_local(DBusConnection
*conn
, DBusMessage
*msg
, void *userdata
);
57 static void handle_get_username(DBusConnection
*conn
, DBusMessage
*msg
, void *userdata
);
58 static void handle_get_hostname(DBusConnection
*conn
, DBusMessage
*msg
, void *userdata
);
59 static void handle_get_default_channels(DBusConnection
*conn
, DBusMessage
*msg
, void *userdata
);
60 static void handle_set_default_channels(DBusConnection
*conn
, DBusMessage
*msg
, DBusMessageIter
*iter
, void *userdata
);
61 static void handle_get_default_sample_format(DBusConnection
*conn
, DBusMessage
*msg
, void *userdata
);
62 static void handle_set_default_sample_format(DBusConnection
*conn
, DBusMessage
*msg
, DBusMessageIter
*iter
, void *userdata
);
63 static void handle_get_default_sample_rate(DBusConnection
*conn
, DBusMessage
*msg
, void *userdata
);
64 static void handle_set_default_sample_rate(DBusConnection
*conn
, DBusMessage
*msg
, DBusMessageIter
*iter
, void *userdata
);
65 static void handle_get_cards(DBusConnection
*conn
, DBusMessage
*msg
, void *userdata
);
66 static void handle_get_sinks(DBusConnection
*conn
, DBusMessage
*msg
, void *userdata
);
67 static void handle_get_fallback_sink(DBusConnection
*conn
, DBusMessage
*msg
, void *userdata
);
68 static void handle_set_fallback_sink(DBusConnection
*conn
, DBusMessage
*msg
, DBusMessageIter
*iter
, void *userdata
);
69 static void handle_get_sources(DBusConnection
*conn
, DBusMessage
*msg
, void *userdata
);
70 static void handle_get_fallback_source(DBusConnection
*conn
, DBusMessage
*msg
, void *userdata
);
71 static void handle_set_fallback_source(DBusConnection
*conn
, DBusMessage
*msg
, DBusMessageIter
*iter
, void *userdata
);
72 static void handle_get_playback_streams(DBusConnection
*conn
, DBusMessage
*msg
, void *userdata
);
73 static void handle_get_record_streams(DBusConnection
*conn
, DBusMessage
*msg
, void *userdata
);
74 static void handle_get_samples(DBusConnection
*conn
, DBusMessage
*msg
, void *userdata
);
75 static void handle_get_modules(DBusConnection
*conn
, DBusMessage
*msg
, void *userdata
);
76 static void handle_get_clients(DBusConnection
*conn
, DBusMessage
*msg
, void *userdata
);
77 static void handle_get_my_client(DBusConnection
*conn
, DBusMessage
*msg
, void *userdata
);
78 static void handle_get_extensions(DBusConnection
*conn
, DBusMessage
*msg
, void *userdata
);
80 static void handle_get_all(DBusConnection
*conn
, DBusMessage
*msg
, void *userdata
);
82 static void handle_get_card_by_name(DBusConnection
*conn
, DBusMessage
*msg
, void *userdata
);
83 static void handle_get_sink_by_name(DBusConnection
*conn
, DBusMessage
*msg
, void *userdata
);
84 static void handle_get_source_by_name(DBusConnection
*conn
, DBusMessage
*msg
, void *userdata
);
85 static void handle_get_sample_by_name(DBusConnection
*conn
, DBusMessage
*msg
, void *userdata
);
86 static void handle_upload_sample(DBusConnection
*conn
, DBusMessage
*msg
, void *userdata
);
87 static void handle_load_module(DBusConnection
*conn
, DBusMessage
*msg
, void *userdata
);
88 static void handle_exit(DBusConnection
*conn
, DBusMessage
*msg
, void *userdata
);
89 static void handle_listen_for_signal(DBusConnection
*conn
, DBusMessage
*msg
, void *userdata
);
90 static void handle_stop_listening_for_signal(DBusConnection
*conn
, DBusMessage
*msg
, void *userdata
);
92 struct pa_dbusiface_core
{
94 pa_subscription
*subscription
;
96 pa_dbus_protocol
*dbus_protocol
;
99 pa_hashmap
*sinks_by_index
;
100 pa_hashmap
*sinks_by_path
;
101 pa_hashmap
*sources_by_index
;
102 pa_hashmap
*sources_by_path
;
103 pa_hashmap
*playback_streams
;
104 pa_hashmap
*record_streams
;
109 pa_sink
*fallback_sink
;
110 pa_source
*fallback_source
;
112 pa_hook_slot
*sink_put_slot
;
113 pa_hook_slot
*sink_unlink_slot
;
114 pa_hook_slot
*source_put_slot
;
115 pa_hook_slot
*source_unlink_slot
;
116 pa_hook_slot
*extension_registered_slot
;
117 pa_hook_slot
*extension_unregistered_slot
;
119 pa_dbusiface_memstats
*memstats
;
122 enum property_handler_index
{
123 PROPERTY_HANDLER_INTERFACE_REVISION
,
124 PROPERTY_HANDLER_NAME
,
125 PROPERTY_HANDLER_VERSION
,
126 PROPERTY_HANDLER_IS_LOCAL
,
127 PROPERTY_HANDLER_USERNAME
,
128 PROPERTY_HANDLER_HOSTNAME
,
129 PROPERTY_HANDLER_DEFAULT_CHANNELS
,
130 PROPERTY_HANDLER_DEFAULT_SAMPLE_FORMAT
,
131 PROPERTY_HANDLER_DEFAULT_SAMPLE_RATE
,
132 PROPERTY_HANDLER_CARDS
,
133 PROPERTY_HANDLER_SINKS
,
134 PROPERTY_HANDLER_FALLBACK_SINK
,
135 PROPERTY_HANDLER_SOURCES
,
136 PROPERTY_HANDLER_FALLBACK_SOURCE
,
137 PROPERTY_HANDLER_PLAYBACK_STREAMS
,
138 PROPERTY_HANDLER_RECORD_STREAMS
,
139 PROPERTY_HANDLER_SAMPLES
,
140 PROPERTY_HANDLER_MODULES
,
141 PROPERTY_HANDLER_CLIENTS
,
142 PROPERTY_HANDLER_MY_CLIENT
,
143 PROPERTY_HANDLER_EXTENSIONS
,
147 static pa_dbus_property_handler property_handlers
[PROPERTY_HANDLER_MAX
] = {
148 [PROPERTY_HANDLER_INTERFACE_REVISION
] = { .property_name
= "InterfaceRevision", .type
= "u", .get_cb
= handle_get_interface_revision
, .set_cb
= NULL
},
149 [PROPERTY_HANDLER_NAME
] = { .property_name
= "Name", .type
= "s", .get_cb
= handle_get_name
, .set_cb
= NULL
},
150 [PROPERTY_HANDLER_VERSION
] = { .property_name
= "Version", .type
= "s", .get_cb
= handle_get_version
, .set_cb
= NULL
},
151 [PROPERTY_HANDLER_IS_LOCAL
] = { .property_name
= "IsLocal", .type
= "b", .get_cb
= handle_get_is_local
, .set_cb
= NULL
},
152 [PROPERTY_HANDLER_USERNAME
] = { .property_name
= "Username", .type
= "s", .get_cb
= handle_get_username
, .set_cb
= NULL
},
153 [PROPERTY_HANDLER_HOSTNAME
] = { .property_name
= "Hostname", .type
= "s", .get_cb
= handle_get_hostname
, .set_cb
= NULL
},
154 [PROPERTY_HANDLER_DEFAULT_CHANNELS
] = { .property_name
= "DefaultChannels", .type
= "au", .get_cb
= handle_get_default_channels
, .set_cb
= handle_set_default_channels
},
155 [PROPERTY_HANDLER_DEFAULT_SAMPLE_FORMAT
] = { .property_name
= "DefaultSampleFormat", .type
= "u", .get_cb
= handle_get_default_sample_format
, .set_cb
= handle_set_default_sample_format
},
156 [PROPERTY_HANDLER_DEFAULT_SAMPLE_RATE
] = { .property_name
= "DefaultSampleRate", .type
= "u", .get_cb
= handle_get_default_sample_rate
, .set_cb
= handle_set_default_sample_rate
},
157 [PROPERTY_HANDLER_CARDS
] = { .property_name
= "Cards", .type
= "ao", .get_cb
= handle_get_cards
, .set_cb
= NULL
},
158 [PROPERTY_HANDLER_SINKS
] = { .property_name
= "Sinks", .type
= "ao", .get_cb
= handle_get_sinks
, .set_cb
= NULL
},
159 [PROPERTY_HANDLER_FALLBACK_SINK
] = { .property_name
= "FallbackSink", .type
= "o", .get_cb
= handle_get_fallback_sink
, .set_cb
= handle_set_fallback_sink
},
160 [PROPERTY_HANDLER_SOURCES
] = { .property_name
= "Sources", .type
= "ao", .get_cb
= handle_get_sources
, .set_cb
= NULL
},
161 [PROPERTY_HANDLER_FALLBACK_SOURCE
] = { .property_name
= "FallbackSource", .type
= "o", .get_cb
= handle_get_fallback_source
, .set_cb
= handle_set_fallback_source
},
162 [PROPERTY_HANDLER_PLAYBACK_STREAMS
] = { .property_name
= "PlaybackStreams", .type
= "ao", .get_cb
= handle_get_playback_streams
, .set_cb
= NULL
},
163 [PROPERTY_HANDLER_RECORD_STREAMS
] = { .property_name
= "RecordStreams", .type
= "ao", .get_cb
= handle_get_record_streams
, .set_cb
= NULL
},
164 [PROPERTY_HANDLER_SAMPLES
] = { .property_name
= "Samples", .type
= "ao", .get_cb
= handle_get_samples
, .set_cb
= NULL
},
165 [PROPERTY_HANDLER_MODULES
] = { .property_name
= "Modules", .type
= "ao", .get_cb
= handle_get_modules
, .set_cb
= NULL
},
166 [PROPERTY_HANDLER_CLIENTS
] = { .property_name
= "Clients", .type
= "ao", .get_cb
= handle_get_clients
, .set_cb
= NULL
},
167 [PROPERTY_HANDLER_MY_CLIENT
] = { .property_name
= "MyClient", .type
= "o", .get_cb
= handle_get_my_client
, .set_cb
= NULL
},
168 [PROPERTY_HANDLER_EXTENSIONS
] = { .property_name
= "Extensions", .type
= "as", .get_cb
= handle_get_extensions
, .set_cb
= NULL
}
171 enum method_handler_index
{
172 METHOD_HANDLER_GET_CARD_BY_NAME
,
173 METHOD_HANDLER_GET_SINK_BY_NAME
,
174 METHOD_HANDLER_GET_SOURCE_BY_NAME
,
175 METHOD_HANDLER_GET_SAMPLE_BY_NAME
,
176 METHOD_HANDLER_UPLOAD_SAMPLE
,
177 METHOD_HANDLER_LOAD_MODULE
,
179 METHOD_HANDLER_LISTEN_FOR_SIGNAL
,
180 METHOD_HANDLER_STOP_LISTENING_FOR_SIGNAL
,
184 static pa_dbus_arg_info get_card_by_name_args
[] = { { "name", "s", "in" }, { "card", "o", "out" } };
185 static pa_dbus_arg_info get_sink_by_name_args
[] = { { "name", "s", "in" }, { "sink", "o", "out" } };
186 static pa_dbus_arg_info get_source_by_name_args
[] = { { "name", "s", "in" }, { "source", "o", "out" } };
187 static pa_dbus_arg_info get_sample_by_name_args
[] = { { "name", "s", "in" }, { "sample", "o", "out" } };
188 static pa_dbus_arg_info upload_sample_args
[] = { { "name", "s", "in" },
189 { "sample_format", "u", "in" },
190 { "sample_rate", "u", "in" },
191 { "channels", "au", "in" },
192 { "default_volume", "au", "in" },
193 { "property_list", "a{say}", "in" },
194 { "data", "ay", "in" },
195 { "sample", "o", "out" } };
196 static pa_dbus_arg_info load_module_args
[] = { { "name", "s", "in" }, { "arguments", "a{ss}", "in" }, { "module", "o", "out" } };
197 static pa_dbus_arg_info listen_for_signal_args
[] = { { "signal", "s", "in" }, { "objects", "ao", "in" } };
198 static pa_dbus_arg_info stop_listening_for_signal_args
[] = { { "signal", "s", "in" } };
200 static pa_dbus_method_handler method_handlers
[METHOD_HANDLER_MAX
] = {
201 [METHOD_HANDLER_GET_CARD_BY_NAME
] = {
202 .method_name
= "GetCardByName",
203 .arguments
= get_card_by_name_args
,
204 .n_arguments
= sizeof(get_card_by_name_args
) / sizeof(pa_dbus_arg_info
),
205 .receive_cb
= handle_get_card_by_name
},
206 [METHOD_HANDLER_GET_SINK_BY_NAME
] = {
207 .method_name
= "GetSinkByName",
208 .arguments
= get_sink_by_name_args
,
209 .n_arguments
= sizeof(get_sink_by_name_args
) / sizeof(pa_dbus_arg_info
),
210 .receive_cb
= handle_get_sink_by_name
},
211 [METHOD_HANDLER_GET_SOURCE_BY_NAME
] = {
212 .method_name
= "GetSourceByName",
213 .arguments
= get_source_by_name_args
,
214 .n_arguments
= sizeof(get_source_by_name_args
) / sizeof(pa_dbus_arg_info
),
215 .receive_cb
= handle_get_source_by_name
},
216 [METHOD_HANDLER_GET_SAMPLE_BY_NAME
] = {
217 .method_name
= "GetSampleByName",
218 .arguments
= get_sample_by_name_args
,
219 .n_arguments
= sizeof(get_sample_by_name_args
) / sizeof(pa_dbus_arg_info
),
220 .receive_cb
= handle_get_sample_by_name
},
221 [METHOD_HANDLER_UPLOAD_SAMPLE
] = {
222 .method_name
= "UploadSample",
223 .arguments
= upload_sample_args
,
224 .n_arguments
= sizeof(upload_sample_args
) / sizeof(pa_dbus_arg_info
),
225 .receive_cb
= handle_upload_sample
},
226 [METHOD_HANDLER_LOAD_MODULE
] = {
227 .method_name
= "LoadModule",
228 .arguments
= load_module_args
,
229 .n_arguments
= sizeof(load_module_args
) / sizeof(pa_dbus_arg_info
),
230 .receive_cb
= handle_load_module
},
231 [METHOD_HANDLER_EXIT
] = {
232 .method_name
= "Exit",
235 .receive_cb
= handle_exit
},
236 [METHOD_HANDLER_LISTEN_FOR_SIGNAL
] = {
237 .method_name
= "ListenForSignal",
238 .arguments
= listen_for_signal_args
,
239 .n_arguments
= sizeof(listen_for_signal_args
) / sizeof(pa_dbus_arg_info
),
240 .receive_cb
= handle_listen_for_signal
},
241 [METHOD_HANDLER_STOP_LISTENING_FOR_SIGNAL
] = {
242 .method_name
= "StopListeningForSignal",
243 .arguments
= stop_listening_for_signal_args
,
244 .n_arguments
= sizeof(stop_listening_for_signal_args
) / sizeof(pa_dbus_arg_info
),
245 .receive_cb
= handle_stop_listening_for_signal
}
253 SIGNAL_FALLBACK_SINK_UPDATED
,
254 SIGNAL_FALLBACK_SINK_UNSET
,
256 SIGNAL_SOURCE_REMOVED
,
257 SIGNAL_FALLBACK_SOURCE_UPDATED
,
258 SIGNAL_FALLBACK_SOURCE_UNSET
,
259 SIGNAL_NEW_PLAYBACK_STREAM
,
260 SIGNAL_PLAYBACK_STREAM_REMOVED
,
261 SIGNAL_NEW_RECORD_STREAM
,
262 SIGNAL_RECORD_STREAM_REMOVED
,
264 SIGNAL_SAMPLE_REMOVED
,
266 SIGNAL_MODULE_REMOVED
,
268 SIGNAL_CLIENT_REMOVED
,
269 SIGNAL_NEW_EXTENSION
,
270 SIGNAL_EXTENSION_REMOVED
,
274 static pa_dbus_arg_info new_card_args
[] = { { "card", "o", NULL
} };
275 static pa_dbus_arg_info card_removed_args
[] = { { "card", "o", NULL
} };
276 static pa_dbus_arg_info new_sink_args
[] = { { "sink", "o", NULL
} };
277 static pa_dbus_arg_info sink_removed_args
[] = { { "sink", "o", NULL
} };
278 static pa_dbus_arg_info fallback_sink_updated_args
[] = { { "sink", "o", NULL
} };
279 static pa_dbus_arg_info new_source_args
[] = { { "source", "o", NULL
} };
280 static pa_dbus_arg_info source_removed_args
[] = { { "source", "o", NULL
} };
281 static pa_dbus_arg_info fallback_source_updated_args
[] = { { "source", "o", NULL
} };
282 static pa_dbus_arg_info new_playback_stream_args
[] = { { "playback_stream", "o", NULL
} };
283 static pa_dbus_arg_info playback_stream_removed_args
[] = { { "playback_stream", "o", NULL
} };
284 static pa_dbus_arg_info new_record_stream_args
[] = { { "record_stream", "o", NULL
} };
285 static pa_dbus_arg_info record_stream_removed_args
[] = { { "record_stream", "o", NULL
} };
286 static pa_dbus_arg_info new_sample_args
[] = { { "sample", "o", NULL
} };
287 static pa_dbus_arg_info sample_removed_args
[] = { { "sample", "o", NULL
} };
288 static pa_dbus_arg_info new_module_args
[] = { { "module", "o", NULL
} };
289 static pa_dbus_arg_info module_removed_args
[] = { { "module", "o", NULL
} };
290 static pa_dbus_arg_info new_client_args
[] = { { "client", "o", NULL
} };
291 static pa_dbus_arg_info client_removed_args
[] = { { "client", "o", NULL
} };
292 static pa_dbus_arg_info new_extension_args
[] = { { "extension", "s", NULL
} };
293 static pa_dbus_arg_info extension_removed_args
[] = { { "extension", "s", NULL
} };
295 static pa_dbus_signal_info signals
[SIGNAL_MAX
] = {
296 [SIGNAL_NEW_CARD
] = { .name
= "NewCard", .arguments
= new_card_args
, .n_arguments
= 1 },
297 [SIGNAL_CARD_REMOVED
] = { .name
= "CardRemoved", .arguments
= card_removed_args
, .n_arguments
= 1 },
298 [SIGNAL_NEW_SINK
] = { .name
= "NewSink", .arguments
= new_sink_args
, .n_arguments
= 1 },
299 [SIGNAL_SINK_REMOVED
] = { .name
= "SinkRemoved", .arguments
= sink_removed_args
, .n_arguments
= 1 },
300 [SIGNAL_FALLBACK_SINK_UPDATED
] = { .name
= "FallbackSinkUpdated", .arguments
= fallback_sink_updated_args
, .n_arguments
= 1 },
301 [SIGNAL_FALLBACK_SINK_UNSET
] = { .name
= "FallbackSinkUnset", .arguments
= NULL
, .n_arguments
= 0 },
302 [SIGNAL_NEW_SOURCE
] = { .name
= "NewSource", .arguments
= new_source_args
, .n_arguments
= 1 },
303 [SIGNAL_SOURCE_REMOVED
] = { .name
= "SourceRemoved", .arguments
= source_removed_args
, .n_arguments
= 1 },
304 [SIGNAL_FALLBACK_SOURCE_UPDATED
] = { .name
= "FallbackSourceUpdated", .arguments
= fallback_source_updated_args
, .n_arguments
= 1 },
305 [SIGNAL_FALLBACK_SOURCE_UNSET
] = { .name
= "FallbackSourceUnset", .arguments
= NULL
, .n_arguments
= 0 },
306 [SIGNAL_NEW_PLAYBACK_STREAM
] = { .name
= "NewPlaybackStream", .arguments
= new_playback_stream_args
, .n_arguments
= 1 },
307 [SIGNAL_PLAYBACK_STREAM_REMOVED
] = { .name
= "PlaybackStreamRemoved", .arguments
= playback_stream_removed_args
, .n_arguments
= 1 },
308 [SIGNAL_NEW_RECORD_STREAM
] = { .name
= "NewRecordStream", .arguments
= new_record_stream_args
, .n_arguments
= 1 },
309 [SIGNAL_RECORD_STREAM_REMOVED
] = { .name
= "RecordStreamRemoved", .arguments
= record_stream_removed_args
, .n_arguments
= 1 },
310 [SIGNAL_NEW_SAMPLE
] = { .name
= "NewSample", .arguments
= new_sample_args
, .n_arguments
= 1 },
311 [SIGNAL_SAMPLE_REMOVED
] = { .name
= "SampleRemoved", .arguments
= sample_removed_args
, .n_arguments
= 1 },
312 [SIGNAL_NEW_MODULE
] = { .name
= "NewModule", .arguments
= new_module_args
, .n_arguments
= 1 },
313 [SIGNAL_MODULE_REMOVED
] = { .name
= "ModuleRemoved", .arguments
= module_removed_args
, .n_arguments
= 1 },
314 [SIGNAL_NEW_CLIENT
] = { .name
= "NewClient", .arguments
= new_client_args
, .n_arguments
= 1 },
315 [SIGNAL_CLIENT_REMOVED
] = { .name
= "ClientRemoved", .arguments
= client_removed_args
, .n_arguments
= 1 },
316 [SIGNAL_NEW_EXTENSION
] = { .name
= "NewExtension", .arguments
= new_extension_args
, .n_arguments
= 1 },
317 [SIGNAL_EXTENSION_REMOVED
] = { .name
= "ExtensionRemoved", .arguments
= extension_removed_args
, .n_arguments
= 1 }
320 static pa_dbus_interface_info core_interface_info
= {
321 .name
= PA_DBUS_CORE_INTERFACE
,
322 .method_handlers
= method_handlers
,
323 .n_method_handlers
= METHOD_HANDLER_MAX
,
324 .property_handlers
= property_handlers
,
325 .n_property_handlers
= PROPERTY_HANDLER_MAX
,
326 .get_all_properties_cb
= handle_get_all
,
328 .n_signals
= SIGNAL_MAX
331 static void handle_get_interface_revision(DBusConnection
*conn
, DBusMessage
*msg
, void *userdata
) {
332 dbus_uint32_t interface_revision
= INTERFACE_REVISION
;
337 pa_dbus_send_basic_variant_reply(conn
, msg
, DBUS_TYPE_UINT32
, &interface_revision
);
340 static void handle_get_name(DBusConnection
*conn
, DBusMessage
*msg
, void *userdata
) {
341 const char *server_name
= PACKAGE_NAME
;
346 pa_dbus_send_basic_variant_reply(conn
, msg
, DBUS_TYPE_STRING
, &server_name
);
349 static void handle_get_version(DBusConnection
*conn
, DBusMessage
*msg
, void *userdata
) {
350 const char *version
= PACKAGE_VERSION
;
355 pa_dbus_send_basic_variant_reply(conn
, msg
, DBUS_TYPE_STRING
, &version
);
358 static dbus_bool_t
get_is_local(DBusConnection
*conn
) {
363 if (!dbus_connection_get_socket(conn
, &conn_fd
))
366 return pa_socket_is_local(conn_fd
);
369 static void handle_get_is_local(DBusConnection
*conn
, DBusMessage
*msg
, void *userdata
) {
370 dbus_bool_t is_local
;
375 is_local
= get_is_local(conn
);
377 pa_dbus_send_basic_variant_reply(conn
, msg
, DBUS_TYPE_BOOLEAN
, &is_local
);
380 static void handle_get_username(DBusConnection
*conn
, DBusMessage
*msg
, void *userdata
) {
381 char *username
= NULL
;
386 username
= pa_get_user_name_malloc();
388 pa_dbus_send_basic_variant_reply(conn
, msg
, DBUS_TYPE_STRING
, &username
);
393 static void handle_get_hostname(DBusConnection
*conn
, DBusMessage
*msg
, void *userdata
) {
394 char *hostname
= NULL
;
399 hostname
= pa_get_host_name_malloc();
401 pa_dbus_send_basic_variant_reply(conn
, msg
, DBUS_TYPE_STRING
, &hostname
);
406 /* Caller frees the returned array. */
407 static dbus_uint32_t
*get_default_channels(pa_dbusiface_core
*c
, unsigned *n
) {
408 dbus_uint32_t
*default_channels
= NULL
;
414 *n
= c
->core
->default_channel_map
.channels
;
415 default_channels
= pa_xnew(dbus_uint32_t
, *n
);
417 for (i
= 0; i
< *n
; ++i
)
418 default_channels
[i
] = c
->core
->default_channel_map
.map
[i
];
420 return default_channels
;
423 static void handle_get_default_channels(DBusConnection
*conn
, DBusMessage
*msg
, void *userdata
) {
424 pa_dbusiface_core
*c
= userdata
;
425 dbus_uint32_t
*default_channels
= NULL
;
432 default_channels
= get_default_channels(c
, &n
);
434 pa_dbus_send_basic_array_variant_reply(conn
, msg
, DBUS_TYPE_UINT32
, default_channels
, n
);
436 pa_xfree(default_channels
);
439 static void handle_set_default_channels(DBusConnection
*conn
, DBusMessage
*msg
, DBusMessageIter
*iter
, void *userdata
) {
440 pa_dbusiface_core
*c
= userdata
;
441 DBusMessageIter array_iter
;
442 pa_channel_map new_channel_map
;
443 const dbus_uint32_t
*default_channels
;
452 pa_channel_map_init(&new_channel_map
);
454 dbus_message_iter_recurse(iter
, &array_iter
);
455 dbus_message_iter_get_fixed_array(&array_iter
, &default_channels
, &n_channels
);
457 if (n_channels
<= 0) {
458 pa_dbus_send_error(conn
, msg
, DBUS_ERROR_INVALID_ARGS
, "Empty channel array.");
462 if (n_channels
> (int) PA_CHANNELS_MAX
) {
463 pa_dbus_send_error(conn
, msg
, DBUS_ERROR_INVALID_ARGS
,
464 "Too many channels: %i. The maximum number of channels is %u.", n_channels
, PA_CHANNELS_MAX
);
468 new_channel_map
.channels
= n_channels
;
470 for (i
= 0; i
< new_channel_map
.channels
; ++i
) {
471 if (default_channels
[i
] >= PA_CHANNEL_POSITION_MAX
) {
472 pa_dbus_send_error(conn
, msg
, DBUS_ERROR_INVALID_ARGS
, "Invalid channel position: %u.", default_channels
[i
]);
476 new_channel_map
.map
[i
] = default_channels
[i
];
479 c
->core
->default_channel_map
= new_channel_map
;
480 c
->core
->default_sample_spec
.channels
= n_channels
;
482 pa_dbus_send_empty_reply(conn
, msg
);
485 static void handle_get_default_sample_format(DBusConnection
*conn
, DBusMessage
*msg
, void *userdata
) {
486 pa_dbusiface_core
*c
= userdata
;
487 dbus_uint32_t default_sample_format
;
493 default_sample_format
= c
->core
->default_sample_spec
.format
;
495 pa_dbus_send_basic_variant_reply(conn
, msg
, DBUS_TYPE_UINT32
, &default_sample_format
);
498 static void handle_set_default_sample_format(DBusConnection
*conn
, DBusMessage
*msg
, DBusMessageIter
*iter
, void *userdata
) {
499 pa_dbusiface_core
*c
= userdata
;
500 dbus_uint32_t default_sample_format
;
507 dbus_message_iter_get_basic(iter
, &default_sample_format
);
509 if (default_sample_format
>= PA_SAMPLE_MAX
) {
510 pa_dbus_send_error(conn
, msg
, DBUS_ERROR_INVALID_ARGS
, "Invalid sample format.");
514 c
->core
->default_sample_spec
.format
= default_sample_format
;
516 pa_dbus_send_empty_reply(conn
, msg
);
519 static void handle_get_default_sample_rate(DBusConnection
*conn
, DBusMessage
*msg
, void *userdata
) {
520 pa_dbusiface_core
*c
= userdata
;
521 dbus_uint32_t default_sample_rate
;
527 default_sample_rate
= c
->core
->default_sample_spec
.rate
;
529 pa_dbus_send_basic_variant_reply(conn
, msg
, DBUS_TYPE_UINT32
, &default_sample_rate
);
532 static void handle_set_default_sample_rate(DBusConnection
*conn
, DBusMessage
*msg
, DBusMessageIter
*iter
, void *userdata
) {
533 pa_dbusiface_core
*c
= userdata
;
534 dbus_uint32_t default_sample_rate
;
541 dbus_message_iter_get_basic(iter
, &default_sample_rate
);
543 if (default_sample_rate
<= 0 || default_sample_rate
> PA_RATE_MAX
) {
544 pa_dbus_send_error(conn
, msg
, DBUS_ERROR_INVALID_ARGS
, "Invalid sample rate.");
548 c
->core
->default_sample_spec
.rate
= default_sample_rate
;
550 pa_dbus_send_empty_reply(conn
, msg
);
553 /* The caller frees the array, but not the strings. */
554 static const char **get_cards(pa_dbusiface_core
*c
, unsigned *n
) {
558 pa_dbusiface_card
*card
;
563 *n
= pa_hashmap_size(c
->cards
);
568 cards
= pa_xnew(const char *, *n
);
570 PA_HASHMAP_FOREACH(card
, c
->cards
, state
)
571 cards
[i
++] = pa_dbusiface_card_get_path(card
);
576 static void handle_get_cards(DBusConnection
*conn
, DBusMessage
*msg
, void *userdata
) {
577 pa_dbusiface_core
*c
= userdata
;
585 cards
= get_cards(c
, &n
);
587 pa_dbus_send_basic_array_variant_reply(conn
, msg
, DBUS_TYPE_OBJECT_PATH
, cards
, n
);
592 /* The caller frees the array, but not the strings. */
593 static const char **get_sinks(pa_dbusiface_core
*c
, unsigned *n
) {
597 pa_dbusiface_device
*sink
;
602 *n
= pa_hashmap_size(c
->sinks_by_index
);
607 sinks
= pa_xnew(const char *, *n
);
609 PA_HASHMAP_FOREACH(sink
, c
->sinks_by_index
, state
)
610 sinks
[i
++] = pa_dbusiface_device_get_path(sink
);
615 static void handle_get_sinks(DBusConnection
*conn
, DBusMessage
*msg
, void *userdata
) {
616 pa_dbusiface_core
*c
= userdata
;
624 sinks
= get_sinks(c
, &n
);
626 pa_dbus_send_basic_array_variant_reply(conn
, msg
, DBUS_TYPE_OBJECT_PATH
, sinks
, n
);
631 static void handle_get_fallback_sink(DBusConnection
*conn
, DBusMessage
*msg
, void *userdata
) {
632 pa_dbusiface_core
*c
= userdata
;
633 pa_dbusiface_device
*fallback_sink
;
634 const char *object_path
;
640 if (!c
->fallback_sink
) {
641 pa_dbus_send_error(conn
, msg
, PA_DBUS_ERROR_NO_SUCH_PROPERTY
,
642 "There are no sinks, and therefore no fallback sink either.");
646 pa_assert_se((fallback_sink
= pa_hashmap_get(c
->sinks_by_index
, PA_UINT32_TO_PTR(c
->fallback_sink
->index
))));
647 object_path
= pa_dbusiface_device_get_path(fallback_sink
);
649 pa_dbus_send_basic_variant_reply(conn
, msg
, DBUS_TYPE_OBJECT_PATH
, &object_path
);
652 static void handle_set_fallback_sink(DBusConnection
*conn
, DBusMessage
*msg
, DBusMessageIter
*iter
, void *userdata
) {
653 pa_dbusiface_core
*c
= userdata
;
654 pa_dbusiface_device
*fallback_sink
;
655 const char *object_path
;
662 if (!c
->fallback_sink
) {
663 pa_dbus_send_error(conn
, msg
, PA_DBUS_ERROR_NO_SUCH_PROPERTY
,
664 "There are no sinks, and therefore no fallback sink either.");
668 dbus_message_iter_get_basic(iter
, &object_path
);
670 if (!(fallback_sink
= pa_hashmap_get(c
->sinks_by_path
, object_path
))) {
671 pa_dbus_send_error(conn
, msg
, PA_DBUS_ERROR_NOT_FOUND
, "%s: No such sink.", object_path
);
675 pa_namereg_set_default_sink(c
->core
, pa_dbusiface_device_get_sink(fallback_sink
));
677 pa_dbus_send_empty_reply(conn
, msg
);
680 /* The caller frees the array, but not the strings. */
681 static const char **get_sources(pa_dbusiface_core
*c
, unsigned *n
) {
682 const char **sources
;
685 pa_dbusiface_device
*source
;
690 *n
= pa_hashmap_size(c
->sources_by_index
);
695 sources
= pa_xnew(const char *, *n
);
697 PA_HASHMAP_FOREACH(source
, c
->sources_by_index
, state
)
698 sources
[i
++] = pa_dbusiface_device_get_path(source
);
703 static void handle_get_sources(DBusConnection
*conn
, DBusMessage
*msg
, void *userdata
) {
704 pa_dbusiface_core
*c
= userdata
;
705 const char **sources
;
712 sources
= get_sources(c
, &n
);
714 pa_dbus_send_basic_array_variant_reply(conn
, msg
, DBUS_TYPE_OBJECT_PATH
, sources
, n
);
719 static void handle_get_fallback_source(DBusConnection
*conn
, DBusMessage
*msg
, void *userdata
) {
720 pa_dbusiface_core
*c
= userdata
;
721 pa_dbusiface_device
*fallback_source
;
722 const char *object_path
;
728 if (!c
->fallback_source
) {
729 pa_dbus_send_error(conn
, msg
, PA_DBUS_ERROR_NO_SUCH_PROPERTY
,
730 "There are no sources, and therefore no fallback source either.");
734 pa_assert_se((fallback_source
= pa_hashmap_get(c
->sources_by_index
, PA_UINT32_TO_PTR(c
->fallback_source
->index
))));
735 object_path
= pa_dbusiface_device_get_path(fallback_source
);
737 pa_dbus_send_basic_variant_reply(conn
, msg
, DBUS_TYPE_OBJECT_PATH
, &object_path
);
740 static void handle_set_fallback_source(DBusConnection
*conn
, DBusMessage
*msg
, DBusMessageIter
*iter
, void *userdata
) {
741 pa_dbusiface_core
*c
= userdata
;
742 pa_dbusiface_device
*fallback_source
;
743 const char *object_path
;
750 if (!c
->fallback_source
) {
751 pa_dbus_send_error(conn
, msg
, PA_DBUS_ERROR_NO_SUCH_PROPERTY
,
752 "There are no sources, and therefore no fallback source either.");
756 dbus_message_iter_get_basic(iter
, &object_path
);
758 if (!(fallback_source
= pa_hashmap_get(c
->sources_by_path
, object_path
))) {
759 pa_dbus_send_error(conn
, msg
, PA_DBUS_ERROR_NOT_FOUND
, "%s: No such source.", object_path
);
763 pa_namereg_set_default_source(c
->core
, pa_dbusiface_device_get_source(fallback_source
));
765 pa_dbus_send_empty_reply(conn
, msg
);
768 /* The caller frees the array, but not the strings. */
769 static const char **get_playback_streams(pa_dbusiface_core
*c
, unsigned *n
) {
770 const char **streams
;
773 pa_dbusiface_stream
*stream
;
778 *n
= pa_hashmap_size(c
->playback_streams
);
783 streams
= pa_xnew(const char *, *n
);
785 PA_HASHMAP_FOREACH(stream
, c
->playback_streams
, state
)
786 streams
[i
++] = pa_dbusiface_stream_get_path(stream
);
791 static void handle_get_playback_streams(DBusConnection
*conn
, DBusMessage
*msg
, void *userdata
) {
792 pa_dbusiface_core
*c
= userdata
;
793 const char **playback_streams
;
800 playback_streams
= get_playback_streams(c
, &n
);
802 pa_dbus_send_basic_array_variant_reply(conn
, msg
, DBUS_TYPE_OBJECT_PATH
, playback_streams
, n
);
804 pa_xfree(playback_streams
);
807 /* The caller frees the array, but not the strings. */
808 static const char **get_record_streams(pa_dbusiface_core
*c
, unsigned *n
) {
809 const char **streams
;
812 pa_dbusiface_stream
*stream
;
817 *n
= pa_hashmap_size(c
->record_streams
);
822 streams
= pa_xnew(const char *, *n
);
824 PA_HASHMAP_FOREACH(stream
, c
->record_streams
, state
)
825 streams
[i
++] = pa_dbusiface_stream_get_path(stream
);
830 static void handle_get_record_streams(DBusConnection
*conn
, DBusMessage
*msg
, void *userdata
) {
831 pa_dbusiface_core
*c
= userdata
;
832 const char **record_streams
;
839 record_streams
= get_record_streams(c
, &n
);
841 pa_dbus_send_basic_array_variant_reply(conn
, msg
, DBUS_TYPE_OBJECT_PATH
, record_streams
, n
);
843 pa_xfree(record_streams
);
846 /* The caller frees the array, but not the strings. */
847 static const char **get_samples(pa_dbusiface_core
*c
, unsigned *n
) {
848 const char **samples
;
851 pa_dbusiface_sample
*sample
;
856 *n
= pa_hashmap_size(c
->samples
);
861 samples
= pa_xnew(const char *, *n
);
863 PA_HASHMAP_FOREACH(sample
, c
->samples
, state
)
864 samples
[i
++] = pa_dbusiface_sample_get_path(sample
);
869 static void handle_get_samples(DBusConnection
*conn
, DBusMessage
*msg
, void *userdata
) {
870 pa_dbusiface_core
*c
= userdata
;
871 const char **samples
;
878 samples
= get_samples(c
, &n
);
880 pa_dbus_send_basic_array_variant_reply(conn
, msg
, DBUS_TYPE_OBJECT_PATH
, samples
, n
);
885 /* The caller frees the array, but not the strings. */
886 static const char **get_modules(pa_dbusiface_core
*c
, unsigned *n
) {
887 const char **modules
;
890 pa_dbusiface_module
*module
;
895 *n
= pa_hashmap_size(c
->modules
);
900 modules
= pa_xnew(const char *, *n
);
902 PA_HASHMAP_FOREACH(module
, c
->modules
, state
)
903 modules
[i
++] = pa_dbusiface_module_get_path(module
);
908 static void handle_get_modules(DBusConnection
*conn
, DBusMessage
*msg
, void *userdata
) {
909 pa_dbusiface_core
*c
= userdata
;
910 const char **modules
;
917 modules
= get_modules(c
, &n
);
919 pa_dbus_send_basic_array_variant_reply(conn
, msg
, DBUS_TYPE_OBJECT_PATH
, modules
, n
);
924 /* The caller frees the array, but not the strings. */
925 static const char **get_clients(pa_dbusiface_core
*c
, unsigned *n
) {
926 const char **clients
;
929 pa_dbusiface_client
*client
;
934 *n
= pa_hashmap_size(c
->clients
);
939 clients
= pa_xnew(const char *, *n
);
941 PA_HASHMAP_FOREACH(client
, c
->clients
, state
)
942 clients
[i
++] = pa_dbusiface_client_get_path(client
);
947 static void handle_get_clients(DBusConnection
*conn
, DBusMessage
*msg
, void *userdata
) {
948 pa_dbusiface_core
*c
= userdata
;
949 const char **clients
;
956 clients
= get_clients(c
, &n
);
958 pa_dbus_send_basic_array_variant_reply(conn
, msg
, DBUS_TYPE_OBJECT_PATH
, clients
, n
);
963 static const char *get_my_client(pa_dbusiface_core
*c
, DBusConnection
*conn
) {
964 pa_client
*my_client
;
969 pa_assert_se((my_client
= pa_dbus_protocol_get_client(c
->dbus_protocol
, conn
)));
971 return pa_dbusiface_client_get_path(pa_hashmap_get(c
->clients
, PA_UINT32_TO_PTR(my_client
->index
)));
974 static void handle_get_my_client(DBusConnection
*conn
, DBusMessage
*msg
, void *userdata
) {
975 pa_dbusiface_core
*c
= userdata
;
976 const char *my_client
;
982 my_client
= get_my_client(c
, conn
);
984 pa_dbus_send_basic_variant_reply(conn
, msg
, DBUS_TYPE_OBJECT_PATH
, &my_client
);
987 static void handle_get_extensions(DBusConnection
*conn
, DBusMessage
*msg
, void *userdata
) {
988 pa_dbusiface_core
*c
= userdata
;
989 const char **extensions
;
996 extensions
= pa_dbus_protocol_get_extensions(c
->dbus_protocol
, &n
);
998 pa_dbus_send_basic_array_variant_reply(conn
, msg
, DBUS_TYPE_STRING
, extensions
, n
);
1000 pa_xfree(extensions
);
1003 static void handle_get_all(DBusConnection
*conn
, DBusMessage
*msg
, void *userdata
) {
1004 pa_dbusiface_core
*c
= userdata
;
1005 DBusMessage
*reply
= NULL
;
1006 DBusMessageIter msg_iter
;
1007 DBusMessageIter dict_iter
;
1008 dbus_uint32_t interface_revision
;
1009 const char *server_name
;
1010 const char *version
;
1011 dbus_bool_t is_local
;
1014 dbus_uint32_t
*default_channels
;
1015 unsigned n_default_channels
;
1016 dbus_uint32_t default_sample_format
;
1017 dbus_uint32_t default_sample_rate
;
1022 const char *fallback_sink
;
1023 const char **sources
;
1025 const char *fallback_source
;
1026 const char **playback_streams
;
1027 unsigned n_playback_streams
;
1028 const char **record_streams
;
1029 unsigned n_record_streams
;
1030 const char **samples
;
1032 const char **modules
;
1034 const char **clients
;
1036 const char *my_client
;
1037 const char **extensions
;
1038 unsigned n_extensions
;
1044 interface_revision
= INTERFACE_REVISION
;
1045 server_name
= PACKAGE_NAME
;
1046 version
= PACKAGE_VERSION
;
1047 is_local
= get_is_local(conn
);
1048 username
= pa_get_user_name_malloc();
1049 hostname
= pa_get_host_name_malloc();
1050 default_channels
= get_default_channels(c
, &n_default_channels
);
1051 default_sample_format
= c
->core
->default_sample_spec
.format
;
1052 default_sample_rate
= c
->core
->default_sample_spec
.rate
;
1053 cards
= get_cards(c
, &n_cards
);
1054 sinks
= get_sinks(c
, &n_sinks
);
1055 fallback_sink
= c
->fallback_sink
1056 ? pa_dbusiface_device_get_path(pa_hashmap_get(c
->sinks_by_index
, PA_UINT32_TO_PTR(c
->fallback_sink
->index
)))
1058 sources
= get_sources(c
, &n_sources
);
1059 fallback_source
= c
->fallback_source
1060 ? pa_dbusiface_device_get_path(pa_hashmap_get(c
->sources_by_index
,
1061 PA_UINT32_TO_PTR(c
->fallback_source
->index
)))
1063 playback_streams
= get_playback_streams(c
, &n_playback_streams
);
1064 record_streams
= get_record_streams(c
, &n_record_streams
);
1065 samples
= get_samples(c
, &n_samples
);
1066 modules
= get_modules(c
, &n_modules
);
1067 clients
= get_clients(c
, &n_clients
);
1068 my_client
= get_my_client(c
, conn
);
1069 extensions
= pa_dbus_protocol_get_extensions(c
->dbus_protocol
, &n_extensions
);
1071 pa_assert_se((reply
= dbus_message_new_method_return(msg
)));
1073 dbus_message_iter_init_append(reply
, &msg_iter
);
1074 pa_assert_se(dbus_message_iter_open_container(&msg_iter
, DBUS_TYPE_ARRAY
, "{sv}", &dict_iter
));
1076 pa_dbus_append_basic_variant_dict_entry(&dict_iter
, property_handlers
[PROPERTY_HANDLER_INTERFACE_REVISION
].property_name
, DBUS_TYPE_UINT32
, &interface_revision
);
1077 pa_dbus_append_basic_variant_dict_entry(&dict_iter
, property_handlers
[PROPERTY_HANDLER_NAME
].property_name
, DBUS_TYPE_STRING
, &server_name
);
1078 pa_dbus_append_basic_variant_dict_entry(&dict_iter
, property_handlers
[PROPERTY_HANDLER_VERSION
].property_name
, DBUS_TYPE_STRING
, &version
);
1079 pa_dbus_append_basic_variant_dict_entry(&dict_iter
, property_handlers
[PROPERTY_HANDLER_IS_LOCAL
].property_name
, DBUS_TYPE_BOOLEAN
, &is_local
);
1080 pa_dbus_append_basic_variant_dict_entry(&dict_iter
, property_handlers
[PROPERTY_HANDLER_USERNAME
].property_name
, DBUS_TYPE_STRING
, &username
);
1081 pa_dbus_append_basic_variant_dict_entry(&dict_iter
, property_handlers
[PROPERTY_HANDLER_HOSTNAME
].property_name
, DBUS_TYPE_STRING
, &hostname
);
1082 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
);
1083 pa_dbus_append_basic_variant_dict_entry(&dict_iter
, property_handlers
[PROPERTY_HANDLER_DEFAULT_SAMPLE_FORMAT
].property_name
, DBUS_TYPE_UINT32
, &default_sample_format
);
1084 pa_dbus_append_basic_variant_dict_entry(&dict_iter
, property_handlers
[PROPERTY_HANDLER_DEFAULT_SAMPLE_RATE
].property_name
, DBUS_TYPE_UINT32
, &default_sample_rate
);
1085 pa_dbus_append_basic_array_variant_dict_entry(&dict_iter
, property_handlers
[PROPERTY_HANDLER_CARDS
].property_name
, DBUS_TYPE_OBJECT_PATH
, cards
, n_cards
);
1086 pa_dbus_append_basic_array_variant_dict_entry(&dict_iter
, property_handlers
[PROPERTY_HANDLER_SINKS
].property_name
, DBUS_TYPE_OBJECT_PATH
, sinks
, n_sinks
);
1089 pa_dbus_append_basic_variant_dict_entry(&dict_iter
, property_handlers
[PROPERTY_HANDLER_FALLBACK_SINK
].property_name
, DBUS_TYPE_OBJECT_PATH
, &fallback_sink
);
1091 pa_dbus_append_basic_array_variant_dict_entry(&dict_iter
, property_handlers
[PROPERTY_HANDLER_SOURCES
].property_name
, DBUS_TYPE_OBJECT_PATH
, sources
, n_sources
);
1093 if (fallback_source
)
1094 pa_dbus_append_basic_variant_dict_entry(&dict_iter
, property_handlers
[PROPERTY_HANDLER_FALLBACK_SOURCE
].property_name
, DBUS_TYPE_OBJECT_PATH
, &fallback_source
);
1096 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
);
1097 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
);
1098 pa_dbus_append_basic_array_variant_dict_entry(&dict_iter
, property_handlers
[PROPERTY_HANDLER_SAMPLES
].property_name
, DBUS_TYPE_OBJECT_PATH
, samples
, n_samples
);
1099 pa_dbus_append_basic_array_variant_dict_entry(&dict_iter
, property_handlers
[PROPERTY_HANDLER_MODULES
].property_name
, DBUS_TYPE_OBJECT_PATH
, modules
, n_modules
);
1100 pa_dbus_append_basic_array_variant_dict_entry(&dict_iter
, property_handlers
[PROPERTY_HANDLER_CLIENTS
].property_name
, DBUS_TYPE_OBJECT_PATH
, clients
, n_clients
);
1101 pa_dbus_append_basic_variant_dict_entry(&dict_iter
, property_handlers
[PROPERTY_HANDLER_MY_CLIENT
].property_name
, DBUS_TYPE_OBJECT_PATH
, &my_client
);
1102 pa_dbus_append_basic_array_variant_dict_entry(&dict_iter
, property_handlers
[PROPERTY_HANDLER_EXTENSIONS
].property_name
, DBUS_TYPE_STRING
, extensions
, n_extensions
);
1104 pa_assert_se(dbus_message_iter_close_container(&msg_iter
, &dict_iter
));
1106 pa_assert_se(dbus_connection_send(conn
, reply
, NULL
));
1108 dbus_message_unref(reply
);
1112 pa_xfree(default_channels
);
1116 pa_xfree(playback_streams
);
1117 pa_xfree(record_streams
);
1121 pa_xfree(extensions
);
1124 static void handle_get_card_by_name(DBusConnection
*conn
, DBusMessage
*msg
, void *userdata
) {
1125 pa_dbusiface_core
*c
= userdata
;
1128 pa_dbusiface_card
*dbus_card
;
1129 const char *object_path
;
1135 pa_assert_se(dbus_message_get_args(msg
, NULL
, DBUS_TYPE_STRING
, &card_name
, DBUS_TYPE_INVALID
));
1137 if (!(card
= pa_namereg_get(c
->core
, card_name
, PA_NAMEREG_CARD
))) {
1138 pa_dbus_send_error(conn
, msg
, PA_DBUS_ERROR_NOT_FOUND
, "No such card.");
1142 pa_assert_se((dbus_card
= pa_hashmap_get(c
->cards
, PA_UINT32_TO_PTR(card
->index
))));
1144 object_path
= pa_dbusiface_card_get_path(dbus_card
);
1146 pa_dbus_send_basic_value_reply(conn
, msg
, DBUS_TYPE_OBJECT_PATH
, &object_path
);
1149 static void handle_get_sink_by_name(DBusConnection
*conn
, DBusMessage
*msg
, void *userdata
) {
1150 pa_dbusiface_core
*c
= userdata
;
1153 pa_dbusiface_device
*dbus_sink
;
1154 const char *object_path
;
1160 pa_assert_se(dbus_message_get_args(msg
, NULL
, DBUS_TYPE_STRING
, &sink_name
, DBUS_TYPE_INVALID
));
1162 if (!(sink
= pa_namereg_get(c
->core
, sink_name
, PA_NAMEREG_SINK
))) {
1163 pa_dbus_send_error(conn
, msg
, PA_DBUS_ERROR_NOT_FOUND
, "%s: No such sink.", sink_name
);
1167 pa_assert_se((dbus_sink
= pa_hashmap_get(c
->sinks_by_index
, PA_UINT32_TO_PTR(sink
->index
))));
1169 object_path
= pa_dbusiface_device_get_path(dbus_sink
);
1171 pa_dbus_send_basic_value_reply(conn
, msg
, DBUS_TYPE_OBJECT_PATH
, &object_path
);
1174 static void handle_get_source_by_name(DBusConnection
*conn
, DBusMessage
*msg
, void *userdata
) {
1175 pa_dbusiface_core
*c
= userdata
;
1178 pa_dbusiface_device
*dbus_source
;
1179 const char *object_path
;
1185 pa_assert_se(dbus_message_get_args(msg
, NULL
, DBUS_TYPE_STRING
, &source_name
, DBUS_TYPE_INVALID
));
1187 if (!(source
= pa_namereg_get(c
->core
, source_name
, PA_NAMEREG_SOURCE
))) {
1188 pa_dbus_send_error(conn
, msg
, PA_DBUS_ERROR_NOT_FOUND
, "%s: No such source.", source_name
);
1192 pa_assert_se((dbus_source
= pa_hashmap_get(c
->sources_by_index
, PA_UINT32_TO_PTR(source
->index
))));
1194 object_path
= pa_dbusiface_device_get_path(dbus_source
);
1196 pa_dbus_send_basic_value_reply(conn
, msg
, DBUS_TYPE_OBJECT_PATH
, &object_path
);
1199 static void handle_get_sample_by_name(DBusConnection
*conn
, DBusMessage
*msg
, void *userdata
) {
1200 pa_dbusiface_core
*c
= userdata
;
1202 pa_scache_entry
*sample
;
1203 pa_dbusiface_sample
*dbus_sample
;
1204 const char *object_path
;
1210 pa_assert_se(dbus_message_get_args(msg
, NULL
, DBUS_TYPE_STRING
, &sample_name
, DBUS_TYPE_INVALID
));
1212 if (!(sample
= pa_namereg_get(c
->core
, sample_name
, PA_NAMEREG_SAMPLE
))) {
1213 pa_dbus_send_error(conn
, msg
, PA_DBUS_ERROR_NOT_FOUND
, "No such sample.");
1217 pa_assert_se((dbus_sample
= pa_hashmap_get(c
->samples
, PA_UINT32_TO_PTR(sample
->index
))));
1219 object_path
= pa_dbusiface_sample_get_path(dbus_sample
);
1221 pa_dbus_send_basic_value_reply(conn
, msg
, DBUS_TYPE_OBJECT_PATH
, &object_path
);
1224 static void handle_upload_sample(DBusConnection
*conn
, DBusMessage
*msg
, void *userdata
) {
1225 pa_dbusiface_core
*c
= userdata
;
1226 DBusMessageIter msg_iter
;
1227 DBusMessageIter array_iter
;
1229 dbus_uint32_t sample_format
;
1230 dbus_uint32_t sample_rate
;
1231 const dbus_uint32_t
*channels
;
1233 const dbus_uint32_t
*default_volume
;
1234 int n_volume_entries
;
1235 pa_proplist
*property_list
;
1236 const uint8_t *data
;
1243 pa_dbusiface_sample
*dbus_sample
= NULL
;
1244 pa_scache_entry
*sample
= NULL
;
1245 const char *object_path
;
1251 chunk
.memblock
= NULL
;
1253 pa_assert_se(dbus_message_iter_init(msg
, &msg_iter
));
1254 dbus_message_iter_get_basic(&msg_iter
, &name
);
1256 pa_assert_se(dbus_message_iter_next(&msg_iter
));
1257 dbus_message_iter_get_basic(&msg_iter
, &sample_format
);
1259 pa_assert_se(dbus_message_iter_next(&msg_iter
));
1260 dbus_message_iter_get_basic(&msg_iter
, &sample_rate
);
1262 pa_assert_se(dbus_message_iter_next(&msg_iter
));
1263 dbus_message_iter_recurse(&msg_iter
, &array_iter
);
1264 dbus_message_iter_get_fixed_array(&array_iter
, &channels
, &n_channels
);
1266 pa_assert_se(dbus_message_iter_next(&msg_iter
));
1267 dbus_message_iter_recurse(&msg_iter
, &array_iter
);
1268 dbus_message_iter_get_fixed_array(&array_iter
, &default_volume
, &n_volume_entries
);
1270 pa_assert_se(dbus_message_iter_next(&msg_iter
));
1271 if (!(property_list
= pa_dbus_get_proplist_arg(conn
, msg
, &msg_iter
)))
1274 dbus_message_iter_recurse(&msg_iter
, &array_iter
);
1275 dbus_message_iter_get_fixed_array(&array_iter
, &data
, &data_length
);
1277 if (sample_format
>= PA_SAMPLE_MAX
) {
1278 pa_dbus_send_error(conn
, msg
, DBUS_ERROR_INVALID_ARGS
, "Invalid sample format.");
1282 if (sample_rate
<= 0 || sample_rate
> PA_RATE_MAX
) {
1283 pa_dbus_send_error(conn
, msg
, DBUS_ERROR_INVALID_ARGS
, "Invalid sample rate.");
1287 if (n_channels
<= 0) {
1288 pa_dbus_send_error(conn
, msg
, DBUS_ERROR_INVALID_ARGS
, "Empty channel map.");
1292 if (n_channels
> (int) PA_CHANNELS_MAX
) {
1293 pa_dbus_send_error(conn
, msg
, DBUS_ERROR_INVALID_ARGS
,
1294 "Too many channels: %i. The maximum is %u.", n_channels
, PA_CHANNELS_MAX
);
1298 for (i
= 0; i
< n_channels
; ++i
) {
1299 if (channels
[i
] >= PA_CHANNEL_POSITION_MAX
) {
1300 pa_dbus_send_error(conn
, msg
, DBUS_ERROR_INVALID_ARGS
, "Invalid channel position.");
1305 if (n_volume_entries
!= 0 && n_volume_entries
!= n_channels
) {
1306 pa_dbus_send_error(conn
, msg
, DBUS_ERROR_INVALID_ARGS
,
1307 "The channels and default_volume arguments have different number of elements (%i and %i, resp).",
1308 n_channels
, n_volume_entries
);
1312 for (i
= 0; i
< n_volume_entries
; ++i
) {
1313 if (!PA_VOLUME_IS_VALID(default_volume
[i
])) {
1314 pa_dbus_send_error(conn
, msg
, DBUS_ERROR_INVALID_ARGS
, "Invalid volume: %u.", default_volume
[i
]);
1319 if (data_length
== 0) {
1320 pa_dbus_send_error(conn
, msg
, DBUS_ERROR_INVALID_ARGS
, "Empty data.");
1324 if (data_length
> PA_SCACHE_ENTRY_SIZE_MAX
) {
1325 pa_dbus_send_error(conn
, msg
, DBUS_ERROR_INVALID_ARGS
,
1326 "Too big sample: %i bytes. The maximum sample length is %u bytes.",
1327 data_length
, PA_SCACHE_ENTRY_SIZE_MAX
);
1331 ss
.format
= sample_format
;
1332 ss
.rate
= sample_rate
;
1333 ss
.channels
= n_channels
;
1335 pa_assert(pa_sample_spec_valid(&ss
));
1337 if (!pa_frame_aligned(data_length
, &ss
)) {
1338 char buf
[PA_SAMPLE_SPEC_SNPRINT_MAX
];
1339 pa_dbus_send_error(conn
, msg
, DBUS_ERROR_INVALID_ARGS
,
1340 "The sample length (%i bytes) doesn't align with the sample format and channels (%s).",
1341 data_length
, pa_sample_spec_snprint(buf
, sizeof(buf
), &ss
));
1345 map
.channels
= n_channels
;
1346 for (i
= 0; i
< n_channels
; ++i
)
1347 map
.map
[i
] = channels
[i
];
1349 chunk
.memblock
= pa_memblock_new(c
->core
->mempool
, data_length
);
1351 chunk
.length
= data_length
;
1353 memcpy(pa_memblock_acquire(chunk
.memblock
), data
, data_length
);
1354 pa_memblock_release(chunk
.memblock
);
1356 if (pa_scache_add_item(c
->core
, name
, &ss
, &map
, &chunk
, property_list
, &idx
) < 0) {
1357 pa_dbus_send_error(conn
, msg
, DBUS_ERROR_FAILED
, "Adding the sample failed.");
1361 sample
= pa_idxset_get_by_index(c
->core
->scache
, idx
);
1363 if (n_volume_entries
> 0) {
1364 sample
->volume
.channels
= n_channels
;
1365 for (i
= 0; i
< n_volume_entries
; ++i
)
1366 sample
->volume
.values
[i
] = default_volume
[i
];
1367 sample
->volume_is_set
= TRUE
;
1369 sample
->volume_is_set
= FALSE
;
1372 dbus_sample
= pa_dbusiface_sample_new(c
, sample
);
1373 pa_hashmap_put(c
->samples
, PA_UINT32_TO_PTR(idx
), dbus_sample
);
1375 object_path
= pa_dbusiface_sample_get_path(dbus_sample
);
1377 pa_dbus_send_basic_value_reply(conn
, msg
, DBUS_TYPE_OBJECT_PATH
, &object_path
);
1381 pa_proplist_free(property_list
);
1384 pa_memblock_unref(chunk
.memblock
);
1387 static pa_bool_t
contains_space(const char *string
) {
1392 for (p
= string
; *p
; ++p
) {
1400 static void handle_load_module(DBusConnection
*conn
, DBusMessage
*msg
, void *userdata
) {
1401 pa_dbusiface_core
*c
= userdata
;
1402 DBusMessageIter msg_iter
;
1403 DBusMessageIter dict_iter
;
1404 DBusMessageIter dict_entry_iter
;
1406 const char *key
= NULL
;
1407 const char *value
= NULL
;
1408 char *escaped_value
= NULL
;
1409 pa_strbuf
*arg_buffer
= NULL
;
1410 char *arg_string
= NULL
;
1411 pa_module
*module
= NULL
;
1412 pa_dbusiface_module
*dbus_module
= NULL
;
1413 const char *object_path
= NULL
;
1419 if (c
->core
->disallow_module_loading
) {
1420 pa_dbus_send_error(conn
, msg
, DBUS_ERROR_ACCESS_DENIED
, "The server is configured to disallow module loading.");
1424 pa_assert_se(dbus_message_iter_init(msg
, &msg_iter
));
1425 dbus_message_iter_get_basic(&msg_iter
, &name
);
1427 arg_buffer
= pa_strbuf_new();
1429 pa_assert_se(dbus_message_iter_next(&msg_iter
));
1430 dbus_message_iter_recurse(&msg_iter
, &dict_iter
);
1432 while (dbus_message_iter_get_arg_type(&dict_iter
) != DBUS_TYPE_INVALID
) {
1433 if (!pa_strbuf_isempty(arg_buffer
))
1434 pa_strbuf_putc(arg_buffer
, ' ');
1436 dbus_message_iter_recurse(&dict_iter
, &dict_entry_iter
);
1438 dbus_message_iter_get_basic(&dict_entry_iter
, &key
);
1440 if (strlen(key
) <= 0 || !pa_ascii_valid(key
) || contains_space(key
)) {
1441 pa_dbus_send_error(conn
, msg
, DBUS_ERROR_INVALID_ARGS
, "Invalid module argument name: %s", key
);
1445 pa_assert_se(dbus_message_iter_next(&dict_entry_iter
));
1446 dbus_message_iter_get_basic(&dict_entry_iter
, &value
);
1448 escaped_value
= pa_escape(value
, "\"");
1449 pa_strbuf_printf(arg_buffer
, "%s=\"%s\"", key
, escaped_value
);
1450 pa_xfree(escaped_value
);
1452 dbus_message_iter_next(&dict_iter
);
1455 arg_string
= pa_strbuf_tostring(arg_buffer
);
1457 if (!(module
= pa_module_load(c
->core
, name
, arg_string
))) {
1458 pa_dbus_send_error(conn
, msg
, DBUS_ERROR_FAILED
, "Failed to load module.");
1462 dbus_module
= pa_dbusiface_module_new(module
);
1463 pa_hashmap_put(c
->modules
, PA_UINT32_TO_PTR(module
->index
), dbus_module
);
1465 object_path
= pa_dbusiface_module_get_path(dbus_module
);
1467 pa_dbus_send_basic_value_reply(conn
, msg
, DBUS_TYPE_OBJECT_PATH
, &object_path
);
1471 pa_strbuf_free(arg_buffer
);
1473 pa_xfree(arg_string
);
1476 static void handle_exit(DBusConnection
*conn
, DBusMessage
*msg
, void *userdata
) {
1477 pa_dbusiface_core
*c
= userdata
;
1483 if (c
->core
->disallow_exit
) {
1484 pa_dbus_send_error(conn
, msg
, DBUS_ERROR_ACCESS_DENIED
, "The server is configured to disallow exiting.");
1488 pa_dbus_send_empty_reply(conn
, msg
);
1490 pa_core_exit(c
->core
, FALSE
, 0);
1493 static void handle_listen_for_signal(DBusConnection
*conn
, DBusMessage
*msg
, void *userdata
) {
1494 pa_dbusiface_core
*c
= userdata
;
1495 const char *signal_str
;
1496 char **objects
= NULL
;
1503 pa_assert_se(dbus_message_get_args(msg
, NULL
,
1504 DBUS_TYPE_STRING
, &signal_str
,
1505 DBUS_TYPE_ARRAY
, DBUS_TYPE_OBJECT_PATH
, &objects
, &n_objects
,
1506 DBUS_TYPE_INVALID
));
1508 pa_dbus_protocol_add_signal_listener(c
->dbus_protocol
, conn
, *signal_str
? signal_str
: NULL
, objects
, n_objects
);
1510 pa_dbus_send_empty_reply(conn
, msg
);
1512 dbus_free_string_array(objects
);
1515 static void handle_stop_listening_for_signal(DBusConnection
*conn
, DBusMessage
*msg
, void *userdata
) {
1516 pa_dbusiface_core
*c
= userdata
;
1517 const char *signal_str
;
1523 pa_assert_se(dbus_message_get_args(msg
, NULL
, DBUS_TYPE_STRING
, &signal_str
, DBUS_TYPE_INVALID
));
1525 pa_dbus_protocol_remove_signal_listener(c
->dbus_protocol
, conn
, *signal_str
? signal_str
: NULL
);
1527 pa_dbus_send_empty_reply(conn
, msg
);
1530 static void subscription_cb(pa_core
*core
, pa_subscription_event_type_t t
, uint32_t idx
, void *userdata
) {
1531 pa_dbusiface_core
*c
= userdata
;
1532 pa_dbusiface_card
*card_iface
= NULL
;
1533 pa_dbusiface_device
*device_iface
= NULL
;
1534 pa_dbusiface_stream
*stream_iface
= NULL
;
1535 pa_dbusiface_sample
*sample_iface
= NULL
;
1536 pa_dbusiface_module
*module_iface
= NULL
;
1537 pa_dbusiface_client
*client_iface
= NULL
;
1538 DBusMessage
*signal_msg
= NULL
;
1539 const char *object_path
= NULL
;
1540 pa_sink
*new_fallback_sink
= NULL
;
1541 pa_source
*new_fallback_source
= NULL
;
1545 switch (t
& PA_SUBSCRIPTION_EVENT_FACILITY_MASK
) {
1546 case PA_SUBSCRIPTION_EVENT_SERVER
:
1547 new_fallback_sink
= pa_namereg_get_default_sink(core
);
1548 new_fallback_source
= pa_namereg_get_default_source(core
);
1550 if (c
->fallback_sink
!= new_fallback_sink
) {
1551 if (c
->fallback_sink
)
1552 pa_sink_unref(c
->fallback_sink
);
1553 c
->fallback_sink
= new_fallback_sink
? pa_sink_ref(new_fallback_sink
) : NULL
;
1555 if (c
->fallback_sink
) {
1556 pa_assert_se(device_iface
= pa_hashmap_get(c
->sinks_by_index
, PA_UINT32_TO_PTR(c
->fallback_sink
->index
)));
1557 object_path
= pa_dbusiface_device_get_path(device_iface
);
1559 pa_assert_se((signal_msg
= dbus_message_new_signal(PA_DBUS_CORE_OBJECT_PATH
,
1560 PA_DBUS_CORE_INTERFACE
,
1561 signals
[SIGNAL_FALLBACK_SINK_UPDATED
].name
)));
1562 pa_assert_se(dbus_message_append_args(signal_msg
, DBUS_TYPE_OBJECT_PATH
, &object_path
, DBUS_TYPE_INVALID
));
1563 pa_dbus_protocol_send_signal(c
->dbus_protocol
, signal_msg
);
1564 dbus_message_unref(signal_msg
);
1568 pa_assert_se((signal_msg
= dbus_message_new_signal(PA_DBUS_CORE_OBJECT_PATH
,
1569 PA_DBUS_CORE_INTERFACE
,
1570 signals
[SIGNAL_FALLBACK_SINK_UNSET
].name
)));
1571 pa_dbus_protocol_send_signal(c
->dbus_protocol
, signal_msg
);
1572 dbus_message_unref(signal_msg
);
1577 if (c
->fallback_source
!= new_fallback_source
) {
1578 if (c
->fallback_source
)
1579 pa_source_unref(c
->fallback_source
);
1580 c
->fallback_source
= new_fallback_source
? pa_source_ref(new_fallback_source
) : NULL
;
1582 if (c
->fallback_source
) {
1583 pa_assert_se(device_iface
= pa_hashmap_get(c
->sources_by_index
, PA_UINT32_TO_PTR(c
->fallback_source
->index
)));
1584 object_path
= pa_dbusiface_device_get_path(device_iface
);
1586 pa_assert_se((signal_msg
= dbus_message_new_signal(PA_DBUS_CORE_OBJECT_PATH
,
1587 PA_DBUS_CORE_INTERFACE
,
1588 signals
[SIGNAL_FALLBACK_SOURCE_UPDATED
].name
)));
1589 pa_assert_se(dbus_message_append_args(signal_msg
, DBUS_TYPE_OBJECT_PATH
, &object_path
, DBUS_TYPE_INVALID
));
1590 pa_dbus_protocol_send_signal(c
->dbus_protocol
, signal_msg
);
1591 dbus_message_unref(signal_msg
);
1595 pa_assert_se((signal_msg
= dbus_message_new_signal(PA_DBUS_CORE_OBJECT_PATH
,
1596 PA_DBUS_CORE_INTERFACE
,
1597 signals
[SIGNAL_FALLBACK_SOURCE_UNSET
].name
)));
1598 pa_dbus_protocol_send_signal(c
->dbus_protocol
, signal_msg
);
1599 dbus_message_unref(signal_msg
);
1605 case PA_SUBSCRIPTION_EVENT_CARD
:
1606 if ((t
& PA_SUBSCRIPTION_EVENT_TYPE_MASK
) == PA_SUBSCRIPTION_EVENT_NEW
) {
1607 if (!(card_iface
= pa_hashmap_get(c
->cards
, PA_UINT32_TO_PTR(idx
)))) {
1608 pa_card
*card
= NULL
;
1610 if (!(card
= pa_idxset_get_by_index(core
->cards
, idx
)))
1611 return; /* The card was removed immediately after creation. */
1613 card_iface
= pa_dbusiface_card_new(c
, card
);
1614 pa_hashmap_put(c
->cards
, PA_UINT32_TO_PTR(idx
), card_iface
);
1617 object_path
= pa_dbusiface_card_get_path(card_iface
);
1619 pa_assert_se((signal_msg
= dbus_message_new_signal(PA_DBUS_CORE_OBJECT_PATH
,
1620 PA_DBUS_CORE_INTERFACE
,
1621 signals
[SIGNAL_NEW_CARD
].name
)));
1622 pa_assert_se(dbus_message_append_args(signal_msg
, DBUS_TYPE_OBJECT_PATH
, &object_path
, DBUS_TYPE_INVALID
));
1624 } else if ((t
& PA_SUBSCRIPTION_EVENT_TYPE_MASK
) == PA_SUBSCRIPTION_EVENT_REMOVE
) {
1625 if (!(card_iface
= pa_hashmap_remove(c
->cards
, PA_UINT32_TO_PTR(idx
))))
1628 object_path
= pa_dbusiface_card_get_path(card_iface
);
1630 pa_assert_se((signal_msg
= dbus_message_new_signal(PA_DBUS_CORE_OBJECT_PATH
,
1631 PA_DBUS_CORE_INTERFACE
,
1632 signals
[SIGNAL_CARD_REMOVED
].name
)));
1633 pa_assert_se(dbus_message_append_args(signal_msg
, DBUS_TYPE_OBJECT_PATH
, &object_path
, DBUS_TYPE_INVALID
));
1635 pa_dbusiface_card_free(card_iface
);
1639 case PA_SUBSCRIPTION_EVENT_SINK_INPUT
:
1640 if ((t
& PA_SUBSCRIPTION_EVENT_TYPE_MASK
) == PA_SUBSCRIPTION_EVENT_NEW
) {
1641 pa_sink_input
*sink_input
= NULL
;
1643 if (!(sink_input
= pa_idxset_get_by_index(core
->sink_inputs
, idx
)))
1644 return; /* The sink input was removed immediately after creation. */
1646 if (!(stream_iface
= pa_hashmap_get(c
->playback_streams
, PA_UINT32_TO_PTR(idx
)))) {
1647 stream_iface
= pa_dbusiface_stream_new_playback(c
, sink_input
);
1648 pa_hashmap_put(c
->playback_streams
, PA_UINT32_TO_PTR(idx
), stream_iface
);
1651 object_path
= pa_dbusiface_stream_get_path(stream_iface
);
1653 pa_assert_se((signal_msg
= dbus_message_new_signal(PA_DBUS_CORE_OBJECT_PATH
,
1654 PA_DBUS_CORE_INTERFACE
,
1655 signals
[SIGNAL_NEW_PLAYBACK_STREAM
].name
)));
1656 pa_assert_se(dbus_message_append_args(signal_msg
, DBUS_TYPE_OBJECT_PATH
, &object_path
, DBUS_TYPE_INVALID
));
1658 } else if ((t
& PA_SUBSCRIPTION_EVENT_TYPE_MASK
) == PA_SUBSCRIPTION_EVENT_REMOVE
) {
1659 if (!(stream_iface
= pa_hashmap_remove(c
->playback_streams
, PA_UINT32_TO_PTR(idx
))))
1662 object_path
= pa_dbusiface_stream_get_path(stream_iface
);
1664 pa_assert_se((signal_msg
= dbus_message_new_signal(PA_DBUS_CORE_OBJECT_PATH
,
1665 PA_DBUS_CORE_INTERFACE
,
1666 signals
[SIGNAL_PLAYBACK_STREAM_REMOVED
].name
)));
1667 pa_assert_se(dbus_message_append_args(signal_msg
, DBUS_TYPE_OBJECT_PATH
, &object_path
, DBUS_TYPE_INVALID
));
1669 pa_dbusiface_stream_free(stream_iface
);
1673 case PA_SUBSCRIPTION_EVENT_SOURCE_OUTPUT
:
1674 if ((t
& PA_SUBSCRIPTION_EVENT_TYPE_MASK
) == PA_SUBSCRIPTION_EVENT_NEW
) {
1675 pa_source_output
*source_output
= NULL
;
1677 if (!(source_output
= pa_idxset_get_by_index(core
->source_outputs
, idx
)))
1678 return; /* The source output was removed immediately after creation. */
1680 if (!(stream_iface
= pa_hashmap_get(c
->record_streams
, PA_UINT32_TO_PTR(idx
)))) {
1681 stream_iface
= pa_dbusiface_stream_new_record(c
, source_output
);
1682 pa_hashmap_put(c
->record_streams
, PA_UINT32_TO_PTR(idx
), stream_iface
);
1685 object_path
= pa_dbusiface_stream_get_path(stream_iface
);
1687 pa_assert_se((signal_msg
= dbus_message_new_signal(PA_DBUS_CORE_OBJECT_PATH
,
1688 PA_DBUS_CORE_INTERFACE
,
1689 signals
[SIGNAL_NEW_RECORD_STREAM
].name
)));
1690 pa_assert_se(dbus_message_append_args(signal_msg
, DBUS_TYPE_OBJECT_PATH
, &object_path
, DBUS_TYPE_INVALID
));
1692 } else if ((t
& PA_SUBSCRIPTION_EVENT_TYPE_MASK
) == PA_SUBSCRIPTION_EVENT_REMOVE
) {
1693 if (!(stream_iface
= pa_hashmap_remove(c
->record_streams
, PA_UINT32_TO_PTR(idx
))))
1696 object_path
= pa_dbusiface_stream_get_path(stream_iface
);
1698 pa_assert_se((signal_msg
= dbus_message_new_signal(PA_DBUS_CORE_OBJECT_PATH
,
1699 PA_DBUS_CORE_INTERFACE
,
1700 signals
[SIGNAL_RECORD_STREAM_REMOVED
].name
)));
1701 pa_assert_se(dbus_message_append_args(signal_msg
, DBUS_TYPE_OBJECT_PATH
, &object_path
, DBUS_TYPE_INVALID
));
1703 pa_dbusiface_stream_free(stream_iface
);
1707 case PA_SUBSCRIPTION_EVENT_SAMPLE_CACHE
:
1708 if ((t
& PA_SUBSCRIPTION_EVENT_TYPE_MASK
) == PA_SUBSCRIPTION_EVENT_NEW
) {
1709 pa_scache_entry
*sample
= NULL
;
1711 if (!(sample
= pa_idxset_get_by_index(core
->scache
, idx
)))
1712 return; /* The sample was removed immediately after creation. */
1714 if (!(sample_iface
= pa_hashmap_get(c
->samples
, PA_UINT32_TO_PTR(idx
)))) {
1715 sample_iface
= pa_dbusiface_sample_new(c
, sample
);
1716 pa_hashmap_put(c
->samples
, PA_UINT32_TO_PTR(idx
), sample_iface
);
1719 object_path
= pa_dbusiface_sample_get_path(sample_iface
);
1721 pa_assert_se((signal_msg
= dbus_message_new_signal(PA_DBUS_CORE_OBJECT_PATH
,
1722 PA_DBUS_CORE_INTERFACE
,
1723 signals
[SIGNAL_NEW_SAMPLE
].name
)));
1724 pa_assert_se(dbus_message_append_args(signal_msg
, DBUS_TYPE_OBJECT_PATH
, &object_path
, DBUS_TYPE_INVALID
));
1726 } else if ((t
& PA_SUBSCRIPTION_EVENT_TYPE_MASK
) == PA_SUBSCRIPTION_EVENT_REMOVE
) {
1727 if (!(sample_iface
= pa_hashmap_remove(c
->samples
, PA_UINT32_TO_PTR(idx
))))
1730 object_path
= pa_dbusiface_sample_get_path(sample_iface
);
1732 pa_assert_se((signal_msg
= dbus_message_new_signal(PA_DBUS_CORE_OBJECT_PATH
,
1733 PA_DBUS_CORE_INTERFACE
,
1734 signals
[SIGNAL_SAMPLE_REMOVED
].name
)));
1735 pa_assert_se(dbus_message_append_args(signal_msg
, DBUS_TYPE_OBJECT_PATH
, &object_path
, DBUS_TYPE_INVALID
));
1737 pa_dbusiface_sample_free(sample_iface
);
1741 case PA_SUBSCRIPTION_EVENT_MODULE
:
1742 if ((t
& PA_SUBSCRIPTION_EVENT_TYPE_MASK
) == PA_SUBSCRIPTION_EVENT_NEW
) {
1743 pa_module
*module
= NULL
;
1745 if (!(module
= pa_idxset_get_by_index(core
->modules
, idx
)))
1746 return; /* The module was removed immediately after creation. */
1748 if (!(module_iface
= pa_hashmap_get(c
->modules
, PA_UINT32_TO_PTR(idx
)))) {
1749 module_iface
= pa_dbusiface_module_new(module
);
1750 pa_hashmap_put(c
->modules
, PA_UINT32_TO_PTR(idx
), module_iface
);
1753 object_path
= pa_dbusiface_module_get_path(module_iface
);
1755 pa_assert_se((signal_msg
= dbus_message_new_signal(PA_DBUS_CORE_OBJECT_PATH
,
1756 PA_DBUS_CORE_INTERFACE
,
1757 signals
[SIGNAL_NEW_MODULE
].name
)));
1758 pa_assert_se(dbus_message_append_args(signal_msg
, DBUS_TYPE_OBJECT_PATH
, &object_path
, DBUS_TYPE_INVALID
));
1760 } else if ((t
& PA_SUBSCRIPTION_EVENT_TYPE_MASK
) == PA_SUBSCRIPTION_EVENT_REMOVE
) {
1761 if (!(module_iface
= pa_hashmap_remove(c
->modules
, PA_UINT32_TO_PTR(idx
))))
1764 object_path
= pa_dbusiface_module_get_path(module_iface
);
1766 pa_assert_se((signal_msg
= dbus_message_new_signal(PA_DBUS_CORE_OBJECT_PATH
,
1767 PA_DBUS_CORE_INTERFACE
,
1768 signals
[SIGNAL_MODULE_REMOVED
].name
)));
1769 pa_assert_se(dbus_message_append_args(signal_msg
, DBUS_TYPE_OBJECT_PATH
, &object_path
, DBUS_TYPE_INVALID
));
1771 pa_dbusiface_module_free(module_iface
);
1775 case PA_SUBSCRIPTION_EVENT_CLIENT
:
1776 if ((t
& PA_SUBSCRIPTION_EVENT_TYPE_MASK
) == PA_SUBSCRIPTION_EVENT_NEW
) {
1777 pa_client
*client
= NULL
;
1779 if (!(client
= pa_idxset_get_by_index(core
->clients
, idx
)))
1780 return; /* The client was removed immediately after creation. */
1782 if (!(client_iface
= pa_hashmap_get(c
->clients
, PA_UINT32_TO_PTR(idx
)))) {
1783 client_iface
= pa_dbusiface_client_new(c
, client
);
1784 pa_hashmap_put(c
->clients
, PA_UINT32_TO_PTR(idx
), client_iface
);
1787 object_path
= pa_dbusiface_client_get_path(client_iface
);
1789 pa_assert_se((signal_msg
= dbus_message_new_signal(PA_DBUS_CORE_OBJECT_PATH
,
1790 PA_DBUS_CORE_INTERFACE
,
1791 signals
[SIGNAL_NEW_CLIENT
].name
)));
1792 pa_assert_se(dbus_message_append_args(signal_msg
, DBUS_TYPE_OBJECT_PATH
, &object_path
, DBUS_TYPE_INVALID
));
1794 } else if ((t
& PA_SUBSCRIPTION_EVENT_TYPE_MASK
) == PA_SUBSCRIPTION_EVENT_REMOVE
) {
1795 if (!(client_iface
= pa_hashmap_remove(c
->clients
, PA_UINT32_TO_PTR(idx
))))
1798 object_path
= pa_dbusiface_client_get_path(client_iface
);
1800 pa_assert_se((signal_msg
= dbus_message_new_signal(PA_DBUS_CORE_OBJECT_PATH
,
1801 PA_DBUS_CORE_INTERFACE
,
1802 signals
[SIGNAL_CLIENT_REMOVED
].name
)));
1803 pa_assert_se(dbus_message_append_args(signal_msg
, DBUS_TYPE_OBJECT_PATH
, &object_path
, DBUS_TYPE_INVALID
));
1805 pa_dbusiface_client_free(client_iface
);
1811 pa_dbus_protocol_send_signal(c
->dbus_protocol
, signal_msg
);
1812 dbus_message_unref(signal_msg
);
1816 static pa_hook_result_t
sink_put_cb(void *hook_data
, void *call_data
, void *slot_data
) {
1817 pa_dbusiface_core
*c
= slot_data
;
1818 pa_sink
*s
= call_data
;
1819 pa_dbusiface_device
*d
= NULL
;
1820 const char *object_path
= NULL
;
1821 DBusMessage
*signal_msg
= NULL
;
1826 d
= pa_dbusiface_device_new_sink(c
, s
);
1827 object_path
= pa_dbusiface_device_get_path(d
);
1829 pa_assert_se(pa_hashmap_put(c
->sinks_by_index
, PA_UINT32_TO_PTR(s
->index
), d
) >= 0);
1830 pa_assert_se(pa_hashmap_put(c
->sinks_by_path
, object_path
, d
) >= 0);
1832 pa_assert_se(signal_msg
= dbus_message_new_signal(PA_DBUS_CORE_OBJECT_PATH
,
1833 PA_DBUS_CORE_INTERFACE
,
1834 signals
[SIGNAL_NEW_SINK
].name
));
1835 pa_assert_se(dbus_message_append_args(signal_msg
, DBUS_TYPE_OBJECT_PATH
, &object_path
, DBUS_TYPE_INVALID
));
1837 pa_dbus_protocol_send_signal(c
->dbus_protocol
, signal_msg
);
1838 dbus_message_unref(signal_msg
);
1843 static pa_hook_result_t
sink_unlink_cb(void *hook_data
, void *call_data
, void *slot_data
) {
1844 pa_dbusiface_core
*c
= slot_data
;
1845 pa_sink
*s
= call_data
;
1846 pa_dbusiface_device
*d
= NULL
;
1847 const char *object_path
= NULL
;
1848 DBusMessage
*signal_msg
= NULL
;
1853 pa_assert_se(d
= pa_hashmap_remove(c
->sinks_by_index
, PA_UINT32_TO_PTR(s
->index
)));
1854 object_path
= pa_dbusiface_device_get_path(d
);
1855 pa_assert_se(pa_hashmap_remove(c
->sinks_by_path
, object_path
));
1857 pa_assert_se(signal_msg
= dbus_message_new_signal(PA_DBUS_CORE_OBJECT_PATH
,
1858 PA_DBUS_CORE_INTERFACE
,
1859 signals
[SIGNAL_SINK_REMOVED
].name
));
1860 pa_assert_se(dbus_message_append_args(signal_msg
, DBUS_TYPE_OBJECT_PATH
, &object_path
, DBUS_TYPE_INVALID
));
1862 pa_dbus_protocol_send_signal(c
->dbus_protocol
, signal_msg
);
1863 dbus_message_unref(signal_msg
);
1865 pa_dbusiface_device_free(d
);
1870 static pa_hook_result_t
source_put_cb(void *hook_data
, void *call_data
, void *slot_data
) {
1871 pa_dbusiface_core
*c
= slot_data
;
1872 pa_source
*s
= call_data
;
1873 pa_dbusiface_device
*d
= NULL
;
1874 const char *object_path
= NULL
;
1875 DBusMessage
*signal_msg
= NULL
;
1880 d
= pa_dbusiface_device_new_source(c
, s
);
1881 object_path
= pa_dbusiface_device_get_path(d
);
1883 pa_assert_se(pa_hashmap_put(c
->sources_by_index
, PA_UINT32_TO_PTR(s
->index
), d
) >= 0);
1884 pa_assert_se(pa_hashmap_put(c
->sources_by_path
, object_path
, d
) >= 0);
1886 pa_assert_se((signal_msg
= dbus_message_new_signal(PA_DBUS_CORE_OBJECT_PATH
,
1887 PA_DBUS_CORE_INTERFACE
,
1888 signals
[SIGNAL_NEW_SOURCE
].name
)));
1889 pa_assert_se(dbus_message_append_args(signal_msg
, DBUS_TYPE_OBJECT_PATH
, &object_path
, DBUS_TYPE_INVALID
));
1891 pa_dbus_protocol_send_signal(c
->dbus_protocol
, signal_msg
);
1892 dbus_message_unref(signal_msg
);
1897 static pa_hook_result_t
source_unlink_cb(void *hook_data
, void *call_data
, void *slot_data
) {
1898 pa_dbusiface_core
*c
= slot_data
;
1899 pa_source
*s
= call_data
;
1900 pa_dbusiface_device
*d
= NULL
;
1901 const char *object_path
= NULL
;
1902 DBusMessage
*signal_msg
= NULL
;
1907 pa_assert_se(d
= pa_hashmap_remove(c
->sources_by_index
, PA_UINT32_TO_PTR(s
->index
)));
1908 object_path
= pa_dbusiface_device_get_path(d
);
1909 pa_assert_se(pa_hashmap_remove(c
->sources_by_path
, object_path
));
1911 pa_assert_se(signal_msg
= dbus_message_new_signal(PA_DBUS_CORE_OBJECT_PATH
,
1912 PA_DBUS_CORE_INTERFACE
,
1913 signals
[SIGNAL_SOURCE_REMOVED
].name
));
1914 pa_assert_se(dbus_message_append_args(signal_msg
, DBUS_TYPE_OBJECT_PATH
, &object_path
, DBUS_TYPE_INVALID
));
1916 pa_dbus_protocol_send_signal(c
->dbus_protocol
, signal_msg
);
1917 dbus_message_unref(signal_msg
);
1919 pa_dbusiface_device_free(d
);
1924 static pa_hook_result_t
extension_registered_cb(void *hook_data
, void *call_data
, void *slot_data
) {
1925 pa_dbusiface_core
*c
= slot_data
;
1926 const char *ext_name
= call_data
;
1927 DBusMessage
*signal_msg
= NULL
;
1930 pa_assert(ext_name
);
1932 pa_assert_se((signal_msg
= dbus_message_new_signal(PA_DBUS_CORE_OBJECT_PATH
,
1933 PA_DBUS_CORE_INTERFACE
,
1934 signals
[SIGNAL_NEW_EXTENSION
].name
)));
1935 pa_assert_se(dbus_message_append_args(signal_msg
, DBUS_TYPE_STRING
, &ext_name
, DBUS_TYPE_INVALID
));
1937 pa_dbus_protocol_send_signal(c
->dbus_protocol
, signal_msg
);
1938 dbus_message_unref(signal_msg
);
1943 static pa_hook_result_t
extension_unregistered_cb(void *hook_data
, void *call_data
, void *slot_data
) {
1944 pa_dbusiface_core
*c
= slot_data
;
1945 const char *ext_name
= call_data
;
1946 DBusMessage
*signal_msg
= NULL
;
1949 pa_assert(ext_name
);
1951 pa_assert_se((signal_msg
= dbus_message_new_signal(PA_DBUS_CORE_OBJECT_PATH
,
1952 PA_DBUS_CORE_INTERFACE
,
1953 signals
[SIGNAL_EXTENSION_REMOVED
].name
)));
1954 pa_assert_se(dbus_message_append_args(signal_msg
, DBUS_TYPE_STRING
, &ext_name
, DBUS_TYPE_INVALID
));
1956 pa_dbus_protocol_send_signal(c
->dbus_protocol
, signal_msg
);
1957 dbus_message_unref(signal_msg
);
1962 pa_dbusiface_core
*pa_dbusiface_core_new(pa_core
*core
) {
1963 pa_dbusiface_core
*c
;
1967 pa_dbusiface_device
*device
;
1968 pa_sink_input
*sink_input
;
1969 pa_source_output
*source_output
;
1970 pa_scache_entry
*sample
;
1977 c
= pa_xnew(pa_dbusiface_core
, 1);
1978 c
->core
= pa_core_ref(core
);
1979 c
->subscription
= pa_subscription_new(core
, PA_SUBSCRIPTION_MASK_ALL
, subscription_cb
, c
);
1980 c
->dbus_protocol
= pa_dbus_protocol_get(core
);
1981 c
->cards
= pa_hashmap_new(pa_idxset_trivial_hash_func
, pa_idxset_trivial_compare_func
);
1982 c
->sinks_by_index
= pa_hashmap_new(pa_idxset_trivial_hash_func
, pa_idxset_trivial_compare_func
);
1983 c
->sinks_by_path
= pa_hashmap_new(pa_idxset_string_hash_func
, pa_idxset_string_compare_func
);
1984 c
->sources_by_index
= pa_hashmap_new(pa_idxset_trivial_hash_func
, pa_idxset_trivial_compare_func
);
1985 c
->sources_by_path
= pa_hashmap_new(pa_idxset_string_hash_func
, pa_idxset_string_compare_func
);
1986 c
->playback_streams
= pa_hashmap_new(pa_idxset_trivial_hash_func
, pa_idxset_trivial_compare_func
);
1987 c
->record_streams
= pa_hashmap_new(pa_idxset_trivial_hash_func
, pa_idxset_trivial_compare_func
);
1988 c
->samples
= pa_hashmap_new(pa_idxset_trivial_hash_func
, pa_idxset_trivial_compare_func
);
1989 c
->modules
= pa_hashmap_new(pa_idxset_trivial_hash_func
, pa_idxset_trivial_compare_func
);
1990 c
->clients
= pa_hashmap_new(pa_idxset_trivial_hash_func
, pa_idxset_trivial_compare_func
);
1991 c
->fallback_sink
= pa_namereg_get_default_sink(core
);
1992 c
->fallback_source
= pa_namereg_get_default_source(core
);
1993 c
->sink_put_slot
= pa_hook_connect(&core
->hooks
[PA_CORE_HOOK_SINK_PUT
], PA_HOOK_NORMAL
, sink_put_cb
, c
);
1994 c
->sink_unlink_slot
= pa_hook_connect(&core
->hooks
[PA_CORE_HOOK_SINK_UNLINK
], PA_HOOK_NORMAL
, sink_unlink_cb
, c
);
1995 c
->source_put_slot
= pa_hook_connect(&core
->hooks
[PA_CORE_HOOK_SOURCE_PUT
], PA_HOOK_NORMAL
, source_put_cb
, c
);
1996 c
->source_unlink_slot
= pa_hook_connect(&core
->hooks
[PA_CORE_HOOK_SOURCE_UNLINK
], PA_HOOK_NORMAL
, source_unlink_cb
, c
);
1997 c
->extension_registered_slot
= pa_dbus_protocol_hook_connect(c
->dbus_protocol
,
1998 PA_DBUS_PROTOCOL_HOOK_EXTENSION_REGISTERED
,
2000 extension_registered_cb
,
2002 c
->extension_unregistered_slot
= pa_dbus_protocol_hook_connect(c
->dbus_protocol
,
2003 PA_DBUS_PROTOCOL_HOOK_EXTENSION_UNREGISTERED
,
2005 extension_unregistered_cb
,
2007 c
->memstats
= pa_dbusiface_memstats_new(c
, core
);
2009 if (c
->fallback_sink
)
2010 pa_sink_ref(c
->fallback_sink
);
2011 if (c
->fallback_source
)
2012 pa_source_ref(c
->fallback_source
);
2014 PA_IDXSET_FOREACH(card
, core
->cards
, idx
)
2015 pa_hashmap_put(c
->cards
, PA_UINT32_TO_PTR(idx
), pa_dbusiface_card_new(c
, card
));
2017 PA_IDXSET_FOREACH(sink
, core
->sinks
, idx
) {
2018 device
= pa_dbusiface_device_new_sink(c
, sink
);
2019 pa_hashmap_put(c
->sinks_by_index
, PA_UINT32_TO_PTR(idx
), device
);
2020 pa_hashmap_put(c
->sinks_by_path
, pa_dbusiface_device_get_path(device
), device
);
2023 PA_IDXSET_FOREACH(source
, core
->sources
, idx
) {
2024 device
= pa_dbusiface_device_new_source(c
, source
);
2025 pa_hashmap_put(c
->sources_by_index
, PA_UINT32_TO_PTR(idx
), device
);
2026 pa_hashmap_put(c
->sources_by_path
, pa_dbusiface_device_get_path(device
), device
);
2029 PA_IDXSET_FOREACH(sink_input
, core
->sink_inputs
, idx
)
2030 pa_hashmap_put(c
->playback_streams
, PA_UINT32_TO_PTR(idx
), pa_dbusiface_stream_new_playback(c
, sink_input
));
2032 PA_IDXSET_FOREACH(source_output
, core
->source_outputs
, idx
)
2033 pa_hashmap_put(c
->record_streams
, PA_UINT32_TO_PTR(idx
), pa_dbusiface_stream_new_record(c
, source_output
));
2035 PA_IDXSET_FOREACH(sample
, core
->scache
, idx
)
2036 pa_hashmap_put(c
->samples
, PA_UINT32_TO_PTR(idx
), pa_dbusiface_sample_new(c
, sample
));
2038 PA_IDXSET_FOREACH(module
, core
->modules
, idx
)
2039 pa_hashmap_put(c
->modules
, PA_UINT32_TO_PTR(idx
), pa_dbusiface_module_new(module
));
2041 PA_IDXSET_FOREACH(client
, core
->clients
, idx
)
2042 pa_hashmap_put(c
->clients
, PA_UINT32_TO_PTR(idx
), pa_dbusiface_client_new(c
, client
));
2044 pa_assert_se(pa_dbus_protocol_add_interface(c
->dbus_protocol
, PA_DBUS_CORE_OBJECT_PATH
, &core_interface_info
, c
) >= 0);
2049 static void free_card_cb(void *p
, void *userdata
) {
2050 pa_dbusiface_card
*c
= p
;
2054 pa_dbusiface_card_free(c
);
2057 static void free_device_cb(void *p
, void *userdata
) {
2058 pa_dbusiface_device
*d
= p
;
2062 pa_dbusiface_device_free(d
);
2065 static void free_stream_cb(void *p
, void *userdata
) {
2066 pa_dbusiface_stream
*s
= p
;
2070 pa_dbusiface_stream_free(s
);
2073 static void free_sample_cb(void *p
, void *userdata
) {
2074 pa_dbusiface_sample
*s
= p
;
2078 pa_dbusiface_sample_free(s
);
2081 static void free_module_cb(void *p
, void *userdata
) {
2082 pa_dbusiface_module
*m
= p
;
2086 pa_dbusiface_module_free(m
);
2089 static void free_client_cb(void *p
, void *userdata
) {
2090 pa_dbusiface_client
*c
= p
;
2094 pa_dbusiface_client_free(c
);
2097 void pa_dbusiface_core_free(pa_dbusiface_core
*c
) {
2100 pa_assert_se(pa_dbus_protocol_remove_interface(c
->dbus_protocol
, PA_DBUS_CORE_OBJECT_PATH
, core_interface_info
.name
) >= 0);
2102 pa_subscription_free(c
->subscription
);
2103 pa_hashmap_free(c
->cards
, free_card_cb
, NULL
);
2104 pa_hashmap_free(c
->sinks_by_index
, free_device_cb
, NULL
);
2105 pa_hashmap_free(c
->sinks_by_path
, NULL
, NULL
);
2106 pa_hashmap_free(c
->sources_by_index
, free_device_cb
, NULL
);
2107 pa_hashmap_free(c
->sources_by_path
, NULL
, NULL
);
2108 pa_hashmap_free(c
->playback_streams
, free_stream_cb
, NULL
);
2109 pa_hashmap_free(c
->record_streams
, free_stream_cb
, NULL
);
2110 pa_hashmap_free(c
->samples
, free_sample_cb
, NULL
);
2111 pa_hashmap_free(c
->modules
, free_module_cb
, NULL
);
2112 pa_hashmap_free(c
->clients
, free_client_cb
, NULL
);
2113 pa_hook_slot_free(c
->sink_put_slot
);
2114 pa_hook_slot_free(c
->sink_unlink_slot
);
2115 pa_hook_slot_free(c
->source_put_slot
);
2116 pa_hook_slot_free(c
->source_unlink_slot
);
2117 pa_hook_slot_free(c
->extension_registered_slot
);
2118 pa_hook_slot_free(c
->extension_unregistered_slot
);
2119 pa_dbusiface_memstats_free(c
->memstats
);
2121 if (c
->fallback_sink
)
2122 pa_sink_unref(c
->fallback_sink
);
2123 if (c
->fallback_source
)
2124 pa_source_unref(c
->fallback_source
);
2126 pa_dbus_protocol_unref(c
->dbus_protocol
);
2127 pa_core_unref(c
->core
);
2132 const char *pa_dbusiface_core_get_card_path(pa_dbusiface_core
*c
, const pa_card
*card
) {
2136 return pa_dbusiface_card_get_path(pa_hashmap_get(c
->cards
, PA_UINT32_TO_PTR(card
->index
)));
2139 const char *pa_dbusiface_core_get_sink_path(pa_dbusiface_core
*c
, const pa_sink
*sink
) {
2143 return pa_dbusiface_device_get_path(pa_hashmap_get(c
->sinks_by_index
, PA_UINT32_TO_PTR(sink
->index
)));
2146 const char *pa_dbusiface_core_get_source_path(pa_dbusiface_core
*c
, const pa_source
*source
) {
2150 return pa_dbusiface_device_get_path(pa_hashmap_get(c
->sources_by_index
, PA_UINT32_TO_PTR(source
->index
)));
2153 const char *pa_dbusiface_core_get_playback_stream_path(pa_dbusiface_core
*c
, const pa_sink_input
*sink_input
) {
2155 pa_assert(sink_input
);
2157 return pa_dbusiface_stream_get_path(pa_hashmap_get(c
->playback_streams
, PA_UINT32_TO_PTR(sink_input
->index
)));
2160 const char *pa_dbusiface_core_get_record_stream_path(pa_dbusiface_core
*c
, const pa_source_output
*source_output
) {
2162 pa_assert(source_output
);
2164 return pa_dbusiface_stream_get_path(pa_hashmap_get(c
->record_streams
, PA_UINT32_TO_PTR(source_output
->index
)));
2167 const char *pa_dbusiface_core_get_module_path(pa_dbusiface_core
*c
, const pa_module
*module
) {
2171 return pa_dbusiface_module_get_path(pa_hashmap_get(c
->modules
, PA_UINT32_TO_PTR(module
->index
)));
2174 const char *pa_dbusiface_core_get_client_path(pa_dbusiface_core
*c
, const pa_client
*client
) {
2178 return pa_dbusiface_client_get_path(pa_hashmap_get(c
->clients
, PA_UINT32_TO_PTR(client
->index
)));
2181 pa_sink
*pa_dbusiface_core_get_sink(pa_dbusiface_core
*c
, const char *object_path
) {
2182 pa_dbusiface_device
*device
= NULL
;
2185 pa_assert(object_path
);
2187 device
= pa_hashmap_get(c
->sinks_by_path
, object_path
);
2190 return pa_dbusiface_device_get_sink(device
);
2195 pa_source
*pa_dbusiface_core_get_source(pa_dbusiface_core
*c
, const char *object_path
) {
2196 pa_dbusiface_device
*device
= NULL
;
2199 pa_assert(object_path
);
2201 device
= pa_hashmap_get(c
->sources_by_path
, object_path
);
2204 return pa_dbusiface_device_get_source(device
);