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-module.h"
45 #include "iface-sample.h"
46 #include "iface-stream.h"
48 #include "iface-core.h"
50 #define OBJECT_PATH "/org/pulseaudio/core1"
51 #define INTERFACE_CORE "org.PulseAudio.Core1"
53 #define INTERFACE_REVISION 0
57 static void handle_get_interface_revision(DBusConnection
*conn
, DBusMessage
*msg
, void *userdata
);
58 static void handle_get_name(DBusConnection
*conn
, DBusMessage
*msg
, void *userdata
);
59 static void handle_get_version(DBusConnection
*conn
, DBusMessage
*msg
, void *userdata
);
60 static void handle_get_is_local(DBusConnection
*conn
, DBusMessage
*msg
, void *userdata
);
61 static void handle_get_username(DBusConnection
*conn
, DBusMessage
*msg
, void *userdata
);
62 static void handle_get_hostname(DBusConnection
*conn
, DBusMessage
*msg
, void *userdata
);
63 static void handle_get_default_channels(DBusConnection
*conn
, DBusMessage
*msg
, void *userdata
);
64 static void handle_set_default_channels(DBusConnection
*conn
, DBusMessage
*msg
, void *userdata
);
65 static void handle_get_default_sample_format(DBusConnection
*conn
, DBusMessage
*msg
, void *userdata
);
66 static void handle_set_default_sample_format(DBusConnection
*conn
, DBusMessage
*msg
, void *userdata
);
67 static void handle_get_default_sample_rate(DBusConnection
*conn
, DBusMessage
*msg
, void *userdata
);
68 static void handle_set_default_sample_rate(DBusConnection
*conn
, DBusMessage
*msg
, void *userdata
);
69 static void handle_get_cards(DBusConnection
*conn
, DBusMessage
*msg
, void *userdata
);
70 static void handle_get_sinks(DBusConnection
*conn
, DBusMessage
*msg
, void *userdata
);
71 static void handle_get_fallback_sink(DBusConnection
*conn
, DBusMessage
*msg
, void *userdata
);
72 static void handle_set_fallback_sink(DBusConnection
*conn
, DBusMessage
*msg
, void *userdata
);
73 static void handle_get_sources(DBusConnection
*conn
, DBusMessage
*msg
, void *userdata
);
74 static void handle_get_fallback_source(DBusConnection
*conn
, DBusMessage
*msg
, void *userdata
);
75 static void handle_set_fallback_source(DBusConnection
*conn
, DBusMessage
*msg
, void *userdata
);
76 static void handle_get_playback_streams(DBusConnection
*conn
, DBusMessage
*msg
, void *userdata
);
77 static void handle_get_record_streams(DBusConnection
*conn
, DBusMessage
*msg
, void *userdata
);
78 static void handle_get_samples(DBusConnection
*conn
, DBusMessage
*msg
, void *userdata
);
79 static void handle_get_modules(DBusConnection
*conn
, DBusMessage
*msg
, void *userdata
);
80 static void handle_get_clients(DBusConnection
*conn
, DBusMessage
*msg
, void *userdata
);
81 static void handle_get_my_client(DBusConnection
*conn
, DBusMessage
*msg
, void *userdata
);
82 static void handle_get_extensions(DBusConnection
*conn
, DBusMessage
*msg
, void *userdata
);
84 static void handle_get_all(DBusConnection
*conn
, DBusMessage
*msg
, void *userdata
);
86 static void handle_get_card_by_name(DBusConnection
*conn
, DBusMessage
*msg
, void *userdata
);
87 static void handle_get_sink_by_name(DBusConnection
*conn
, DBusMessage
*msg
, void *userdata
);
88 static void handle_get_source_by_name(DBusConnection
*conn
, DBusMessage
*msg
, void *userdata
);
89 static void handle_get_sample_by_name(DBusConnection
*conn
, DBusMessage
*msg
, void *userdata
);
90 static void handle_upload_sample(DBusConnection
*conn
, DBusMessage
*msg
, void *userdata
);
91 static void handle_load_module(DBusConnection
*conn
, DBusMessage
*msg
, void *userdata
);
92 static void handle_exit(DBusConnection
*conn
, DBusMessage
*msg
, void *userdata
);
93 static void handle_listen_for_signal(DBusConnection
*conn
, DBusMessage
*msg
, void *userdata
);
94 static void handle_stop_listening_for_signal(DBusConnection
*conn
, DBusMessage
*msg
, void *userdata
);
96 struct pa_dbusiface_core
{
98 pa_subscription
*subscription
;
100 pa_dbus_protocol
*dbus_protocol
;
103 pa_hashmap
*sinks_by_index
;
104 pa_hashmap
*sinks_by_path
;
105 pa_hashmap
*sources_by_index
;
106 pa_hashmap
*sources_by_path
;
107 pa_hashmap
*playback_streams
;
108 pa_hashmap
*record_streams
;
113 pa_sink
*fallback_sink
;
114 pa_source
*fallback_source
;
117 enum property_handler_index
{
118 PROPERTY_HANDLER_INTERFACE_REVISION
,
119 PROPERTY_HANDLER_NAME
,
120 PROPERTY_HANDLER_VERSION
,
121 PROPERTY_HANDLER_IS_LOCAL
,
122 PROPERTY_HANDLER_USERNAME
,
123 PROPERTY_HANDLER_HOSTNAME
,
124 PROPERTY_HANDLER_DEFAULT_CHANNELS
,
125 PROPERTY_HANDLER_DEFAULT_SAMPLE_FORMAT
,
126 PROPERTY_HANDLER_DEFAULT_SAMPLE_RATE
,
127 PROPERTY_HANDLER_CARDS
,
128 PROPERTY_HANDLER_SINKS
,
129 PROPERTY_HANDLER_FALLBACK_SINK
,
130 PROPERTY_HANDLER_SOURCES
,
131 PROPERTY_HANDLER_FALLBACK_SOURCE
,
132 PROPERTY_HANDLER_PLAYBACK_STREAMS
,
133 PROPERTY_HANDLER_RECORD_STREAMS
,
134 PROPERTY_HANDLER_SAMPLES
,
135 PROPERTY_HANDLER_MODULES
,
136 PROPERTY_HANDLER_CLIENTS
,
137 PROPERTY_HANDLER_MY_CLIENT
,
138 PROPERTY_HANDLER_EXTENSIONS
,
142 static pa_dbus_property_handler property_handlers
[PROPERTY_HANDLER_MAX
] = {
143 [PROPERTY_HANDLER_INTERFACE_REVISION
] = { .property_name
= "InterfaceRevision", .type
= "u", .get_cb
= handle_get_interface_revision
, .set_cb
= NULL
},
144 [PROPERTY_HANDLER_NAME
] = { .property_name
= "Name", .type
= "s", .get_cb
= handle_get_name
, .set_cb
= NULL
},
145 [PROPERTY_HANDLER_VERSION
] = { .property_name
= "Version", .type
= "s", .get_cb
= handle_get_version
, .set_cb
= NULL
},
146 [PROPERTY_HANDLER_IS_LOCAL
] = { .property_name
= "IsLocal", .type
= "b", .get_cb
= handle_get_is_local
, .set_cb
= NULL
},
147 [PROPERTY_HANDLER_USERNAME
] = { .property_name
= "Username", .type
= "s", .get_cb
= handle_get_username
, .set_cb
= NULL
},
148 [PROPERTY_HANDLER_HOSTNAME
] = { .property_name
= "Hostname", .type
= "s", .get_cb
= handle_get_hostname
, .set_cb
= NULL
},
149 [PROPERTY_HANDLER_DEFAULT_CHANNELS
] = { .property_name
= "DefaultChannels", .type
= "au", .get_cb
= handle_get_default_channels
, .set_cb
= handle_set_default_channels
},
150 [PROPERTY_HANDLER_DEFAULT_SAMPLE_FORMAT
] = { .property_name
= "DefaultSampleFormat", .type
= "u", .get_cb
= handle_get_default_sample_format
, .set_cb
= handle_set_default_sample_format
},
151 [PROPERTY_HANDLER_DEFAULT_SAMPLE_RATE
] = { .property_name
= "DefaultSampleRate", .type
= "u", .get_cb
= handle_get_default_sample_rate
, .set_cb
= handle_set_default_sample_rate
},
152 [PROPERTY_HANDLER_CARDS
] = { .property_name
= "Cards", .type
= "ao", .get_cb
= handle_get_cards
, .set_cb
= NULL
},
153 [PROPERTY_HANDLER_SINKS
] = { .property_name
= "Sinks", .type
= "ao", .get_cb
= handle_get_sinks
, .set_cb
= NULL
},
154 [PROPERTY_HANDLER_FALLBACK_SINK
] = { .property_name
= "FallbackSink", .type
= "o", .get_cb
= handle_get_fallback_sink
, .set_cb
= handle_set_fallback_sink
},
155 [PROPERTY_HANDLER_SOURCES
] = { .property_name
= "Sources", .type
= "ao", .get_cb
= handle_get_sources
, .set_cb
= NULL
},
156 [PROPERTY_HANDLER_FALLBACK_SOURCE
] = { .property_name
= "FallbackSource", .type
= "o", .get_cb
= handle_get_fallback_source
, .set_cb
= handle_set_fallback_source
},
157 [PROPERTY_HANDLER_PLAYBACK_STREAMS
] = { .property_name
= "PlaybackStreams", .type
= "ao", .get_cb
= handle_get_playback_streams
, .set_cb
= NULL
},
158 [PROPERTY_HANDLER_RECORD_STREAMS
] = { .property_name
= "RecordStreams", .type
= "ao", .get_cb
= handle_get_record_streams
, .set_cb
= NULL
},
159 [PROPERTY_HANDLER_SAMPLES
] = { .property_name
= "Samples", .type
= "ao", .get_cb
= handle_get_samples
, .set_cb
= NULL
},
160 [PROPERTY_HANDLER_MODULES
] = { .property_name
= "Modules", .type
= "ao", .get_cb
= handle_get_modules
, .set_cb
= NULL
},
161 [PROPERTY_HANDLER_CLIENTS
] = { .property_name
= "Clients", .type
= "ao", .get_cb
= handle_get_clients
, .set_cb
= NULL
},
162 [PROPERTY_HANDLER_MY_CLIENT
] = { .property_name
= "MyClient", .type
= "o", .get_cb
= handle_get_my_client
, .set_cb
= NULL
},
163 [PROPERTY_HANDLER_EXTENSIONS
] = { .property_name
= "Extensions", .type
= "as", .get_cb
= handle_get_extensions
, .set_cb
= NULL
}
166 enum method_handler_index
{
167 METHOD_HANDLER_GET_CARD_BY_NAME
,
168 METHOD_HANDLER_GET_SINK_BY_NAME
,
169 METHOD_HANDLER_GET_SOURCE_BY_NAME
,
170 METHOD_HANDLER_GET_SAMPLE_BY_NAME
,
171 METHOD_HANDLER_UPLOAD_SAMPLE
,
172 METHOD_HANDLER_LOAD_MODULE
,
174 METHOD_HANDLER_LISTEN_FOR_SIGNAL
,
175 METHOD_HANDLER_STOP_LISTENING_FOR_SIGNAL
,
179 static pa_dbus_arg_info get_card_by_name_args
[] = { { "name", "s", "in" }, { "card", "o", "out" } };
180 static pa_dbus_arg_info get_sink_by_name_args
[] = { { "name", "s", "in" }, { "sink", "o", "out" } };
181 static pa_dbus_arg_info get_source_by_name_args
[] = { { "name", "s", "in" }, { "source", "o", "out" } };
182 static pa_dbus_arg_info get_sample_by_name_args
[] = { { "name", "s", "in" }, { "sample", "o", "out" } };
183 static pa_dbus_arg_info upload_sample_args
[] = { { "name", "s", "in" },
184 { "sample_format", "u", "in" },
185 { "sample_rate", "u", "in" },
186 { "channels", "au", "in" },
187 { "default_volume", "au", "in" },
188 { "property_list", "a{say}", "in" },
189 { "data", "ay", "in" },
190 { "sample", "o", "out" } };
191 static pa_dbus_arg_info load_module_args
[] = { { "name", "s", "in" }, { "arguments", "a{ss}", "in" }, { "module", "o", "out" } };
192 static pa_dbus_arg_info listen_for_signal_args
[] = { { "signal", "s", "in" }, { "objects", "ao", "in" } };
193 static pa_dbus_arg_info stop_listening_for_signal_args
[] = { { "signal", "s", "in" } };
195 static pa_dbus_method_handler method_handlers
[METHOD_HANDLER_MAX
] = {
196 [METHOD_HANDLER_GET_CARD_BY_NAME
] = {
197 .method_name
= "GetCardByName",
198 .arguments
= get_card_by_name_args
,
199 .n_arguments
= sizeof(get_card_by_name_args
) / sizeof(pa_dbus_arg_info
),
200 .receive_cb
= handle_get_card_by_name
},
201 [METHOD_HANDLER_GET_SINK_BY_NAME
] = {
202 .method_name
= "GetSinkByName",
203 .arguments
= get_sink_by_name_args
,
204 .n_arguments
= sizeof(get_sink_by_name_args
) / sizeof(pa_dbus_arg_info
),
205 .receive_cb
= handle_get_sink_by_name
},
206 [METHOD_HANDLER_GET_SOURCE_BY_NAME
] = {
207 .method_name
= "GetSourceByName",
208 .arguments
= get_source_by_name_args
,
209 .n_arguments
= sizeof(get_source_by_name_args
) / sizeof(pa_dbus_arg_info
),
210 .receive_cb
= handle_get_source_by_name
},
211 [METHOD_HANDLER_GET_SAMPLE_BY_NAME
] = {
212 .method_name
= "GetSampleByName",
213 .arguments
= get_sample_by_name_args
,
214 .n_arguments
= sizeof(get_sample_by_name_args
) / sizeof(pa_dbus_arg_info
),
215 .receive_cb
= handle_get_sample_by_name
},
216 [METHOD_HANDLER_UPLOAD_SAMPLE
] = {
217 .method_name
= "UploadSample",
218 .arguments
= upload_sample_args
,
219 .n_arguments
= sizeof(upload_sample_args
) / sizeof(pa_dbus_arg_info
),
220 .receive_cb
= handle_upload_sample
},
221 [METHOD_HANDLER_LOAD_MODULE
] = {
222 .method_name
= "LoadModule",
223 .arguments
= upload_sample_args
,
224 .n_arguments
= sizeof(load_module_args
) / sizeof(pa_dbus_arg_info
),
225 .receive_cb
= handle_load_module
},
226 [METHOD_HANDLER_EXIT
] = {
227 .method_name
= "Exit",
230 .receive_cb
= handle_exit
},
231 [METHOD_HANDLER_LISTEN_FOR_SIGNAL
] = {
232 .method_name
= "ListenForSignal",
233 .arguments
= listen_for_signal_args
,
234 .n_arguments
= sizeof(listen_for_signal_args
) / sizeof(pa_dbus_arg_info
),
235 .receive_cb
= handle_listen_for_signal
},
236 [METHOD_HANDLER_STOP_LISTENING_FOR_SIGNAL
] = {
237 .method_name
= "StopListeningForSignal",
238 .arguments
= stop_listening_for_signal_args
,
239 .n_arguments
= sizeof(stop_listening_for_signal_args
) / sizeof(pa_dbus_arg_info
),
240 .receive_cb
= handle_stop_listening_for_signal
}
248 SIGNAL_FALLBACK_SINK_UPDATED
,
250 SIGNAL_SOURCE_REMOVED
,
251 SIGNAL_FALLBACK_SOURCE_UPDATED
,
252 SIGNAL_NEW_PLAYBACK_STREAM
,
253 SIGNAL_PLAYBACK_STREAM_REMOVED
,
254 SIGNAL_NEW_RECORD_STREAM
,
255 SIGNAL_RECORD_STREAM_REMOVED
,
257 SIGNAL_SAMPLE_REMOVED
,
259 SIGNAL_MODULE_REMOVED
,
261 SIGNAL_CLIENT_REMOVED
,
265 static pa_dbus_arg_info new_card_args
[] = { { "card", "o", NULL
} };
266 static pa_dbus_arg_info card_removed_args
[] = { { "card", "o", NULL
} };
267 static pa_dbus_arg_info new_sink_args
[] = { { "sink", "o", NULL
} };
268 static pa_dbus_arg_info sink_removed_args
[] = { { "sink", "o", NULL
} };
269 static pa_dbus_arg_info fallback_sink_updated_args
[] = { { "sink", "o", NULL
} };
270 static pa_dbus_arg_info new_source_args
[] = { { "source", "o", NULL
} };
271 static pa_dbus_arg_info source_removed_args
[] = { { "source", "o", NULL
} };
272 static pa_dbus_arg_info fallback_source_updated_args
[] = { { "source", "o", NULL
} };
273 static pa_dbus_arg_info new_playback_stream_args
[] = { { "playback_stream", "o", NULL
} };
274 static pa_dbus_arg_info playback_stream_removed_args
[] = { { "playback_stream", "o", NULL
} };
275 static pa_dbus_arg_info new_record_stream_args
[] = { { "record_stream", "o", NULL
} };
276 static pa_dbus_arg_info record_stream_removed_args
[] = { { "record_stream", "o", NULL
} };
277 static pa_dbus_arg_info new_sample_args
[] = { { "sample", "o", NULL
} };
278 static pa_dbus_arg_info sample_removed_args
[] = { { "sample", "o", NULL
} };
279 static pa_dbus_arg_info new_module_args
[] = { { "module", "o", NULL
} };
280 static pa_dbus_arg_info module_removed_args
[] = { { "module", "o", NULL
} };
281 static pa_dbus_arg_info new_client_args
[] = { { "client", "o", NULL
} };
282 static pa_dbus_arg_info client_removed_args
[] = { { "client", "o", NULL
} };
284 static pa_dbus_signal_info signals
[SIGNAL_MAX
] = {
285 [SIGNAL_NEW_CARD
] = { .name
= "NewCard", .arguments
= new_card_args
, .n_arguments
= 1 },
286 [SIGNAL_CARD_REMOVED
] = { .name
= "CardRemoved", .arguments
= card_removed_args
, .n_arguments
= 1 },
287 [SIGNAL_NEW_SINK
] = { .name
= "NewSink", .arguments
= new_sink_args
, .n_arguments
= 1 },
288 [SIGNAL_SINK_REMOVED
] = { .name
= "SinkRemoved", .arguments
= sink_removed_args
, .n_arguments
= 1 },
289 [SIGNAL_FALLBACK_SINK_UPDATED
] = { .name
= "FallbackSinkUpdated", .arguments
= fallback_sink_updated_args
, .n_arguments
= 1 },
290 [SIGNAL_NEW_SOURCE
] = { .name
= "NewSource", .arguments
= new_source_args
, .n_arguments
= 1 },
291 [SIGNAL_SOURCE_REMOVED
] = { .name
= "SourceRemoved", .arguments
= source_removed_args
, .n_arguments
= 1 },
292 [SIGNAL_FALLBACK_SOURCE_UPDATED
] = { .name
= "FallbackSourceUpdated", .arguments
= fallback_source_updated_args
, .n_arguments
= 1 },
293 [SIGNAL_NEW_PLAYBACK_STREAM
] = { .name
= "NewPlaybackStream", .arguments
= new_playback_stream_args
, .n_arguments
= 1 },
294 [SIGNAL_PLAYBACK_STREAM_REMOVED
] = { .name
= "PlaybackStreamRemoved", .arguments
= playback_stream_removed_args
, .n_arguments
= 1 },
295 [SIGNAL_NEW_RECORD_STREAM
] = { .name
= "NewRecordStream", .arguments
= new_record_stream_args
, .n_arguments
= 1 },
296 [SIGNAL_RECORD_STREAM_REMOVED
] = { .name
= "RecordStreamRemoved", .arguments
= record_stream_removed_args
, .n_arguments
= 1 },
297 [SIGNAL_NEW_SAMPLE
] = { .name
= "NewSample", .arguments
= new_sample_args
, .n_arguments
= 1 },
298 [SIGNAL_SAMPLE_REMOVED
] = { .name
= "SampleRemoved", .arguments
= sample_removed_args
, .n_arguments
= 1 },
299 [SIGNAL_NEW_MODULE
] = { .name
= "NewModule", .arguments
= new_module_args
, .n_arguments
= 1 },
300 [SIGNAL_MODULE_REMOVED
] = { .name
= "ModuleRemoved", .arguments
= module_removed_args
, .n_arguments
= 1 },
301 [SIGNAL_NEW_CLIENT
] = { .name
= "NewClient", .arguments
= new_client_args
, .n_arguments
= 1 },
302 [SIGNAL_CLIENT_REMOVED
] = { .name
= "ClientRemoved", .arguments
= client_removed_args
, .n_arguments
= 1 },
305 static pa_dbus_interface_info core_interface_info
= {
306 .name
= INTERFACE_CORE
,
307 .method_handlers
= method_handlers
,
308 .n_method_handlers
= METHOD_HANDLER_MAX
,
309 .property_handlers
= property_handlers
,
310 .n_property_handlers
= PROPERTY_HANDLER_MAX
,
311 .get_all_properties_cb
= handle_get_all
,
313 .n_signals
= SIGNAL_MAX
316 static void handle_get_interface_revision(DBusConnection
*conn
, DBusMessage
*msg
, void *userdata
) {
317 dbus_uint32_t interface_revision
= INTERFACE_REVISION
;
322 pa_dbus_send_basic_variant_reply(conn
, msg
, DBUS_TYPE_UINT32
, &interface_revision
);
325 static void handle_get_name(DBusConnection
*conn
, DBusMessage
*msg
, void *userdata
) {
326 const char *server_name
= PACKAGE_NAME
;
331 pa_dbus_send_basic_variant_reply(conn
, msg
, DBUS_TYPE_STRING
, &server_name
);
334 static void handle_get_version(DBusConnection
*conn
, DBusMessage
*msg
, void *userdata
) {
335 const char *version
= PACKAGE_VERSION
;
340 pa_dbus_send_basic_variant_reply(conn
, msg
, DBUS_TYPE_STRING
, &version
);
343 static dbus_bool_t
get_is_local(DBusConnection
*conn
) {
348 if (!dbus_connection_get_socket(conn
, &conn_fd
))
351 return pa_socket_is_local(conn_fd
);
354 static void handle_get_is_local(DBusConnection
*conn
, DBusMessage
*msg
, void *userdata
) {
355 dbus_bool_t is_local
;
360 is_local
= get_is_local(conn
);
362 pa_dbus_send_basic_variant_reply(conn
, msg
, DBUS_TYPE_BOOLEAN
, &is_local
);
365 static void handle_get_username(DBusConnection
*conn
, DBusMessage
*msg
, void *userdata
) {
366 char *username
= NULL
;
371 username
= pa_get_user_name_malloc();
373 pa_dbus_send_basic_variant_reply(conn
, msg
, DBUS_TYPE_STRING
, &username
);
378 static void handle_get_hostname(DBusConnection
*conn
, DBusMessage
*msg
, void *userdata
) {
379 char *hostname
= NULL
;
384 hostname
= pa_get_host_name_malloc();
386 pa_dbus_send_basic_variant_reply(conn
, msg
, DBUS_TYPE_STRING
, &hostname
);
391 /* Caller frees the returned array. */
392 static dbus_uint32_t
*get_default_channels(pa_dbusiface_core
*c
, unsigned *n
) {
393 dbus_uint32_t
*default_channels
= NULL
;
399 *n
= c
->core
->default_channel_map
.channels
;
400 default_channels
= pa_xnew(dbus_uint32_t
, *n
);
402 for (i
= 0; i
< *n
; ++i
)
403 default_channels
[i
] = c
->core
->default_channel_map
.map
[i
];
405 return default_channels
;
408 static void handle_get_default_channels(DBusConnection
*conn
, DBusMessage
*msg
, void *userdata
) {
409 pa_dbusiface_core
*c
= userdata
;
410 dbus_uint32_t
*default_channels
= NULL
;
417 default_channels
= get_default_channels(c
, &n
);
419 pa_dbus_send_basic_array_variant_reply(conn
, msg
, DBUS_TYPE_UINT32
, default_channels
, n
);
421 pa_xfree(default_channels
);
424 static void handle_set_default_channels(DBusConnection
*conn
, DBusMessage
*msg
, void *userdata
) {
425 pa_dbusiface_core
*c
= userdata
;
426 pa_channel_map new_channel_map
;
427 DBusMessageIter msg_iter
;
428 DBusMessageIter variant_iter
;
429 DBusMessageIter array_iter
;
430 dbus_uint32_t
*default_channels
;
438 pa_channel_map_init(&new_channel_map
);
440 pa_assert_se(dbus_message_iter_init(msg
, &msg_iter
));
442 /* Skip the interface and property name arguments. */
443 if (!dbus_message_iter_next(&msg_iter
) || !dbus_message_iter_next(&msg_iter
)) {
444 pa_dbus_send_error(conn
, msg
, DBUS_ERROR_INVALID_ARGS
, "Too few arguments.");
448 if (dbus_message_iter_get_arg_type(&msg_iter
) != DBUS_TYPE_VARIANT
) {
449 pa_dbus_send_error(conn
, msg
, DBUS_ERROR_INVALID_ARGS
, "Message argument isn't a variant.");
453 dbus_message_iter_recurse(&msg_iter
, &variant_iter
);
455 if (dbus_message_iter_get_arg_type(&variant_iter
) != DBUS_TYPE_ARRAY
) {
456 pa_dbus_send_error(conn
, msg
, DBUS_ERROR_INVALID_ARGS
, "Variant doesn't contain an array.");
460 dbus_message_iter_recurse(&variant_iter
, &array_iter
);
462 if (dbus_message_iter_get_arg_type(&array_iter
) != DBUS_TYPE_UINT32
) {
463 pa_dbus_send_error(conn
, msg
, DBUS_ERROR_INVALID_ARGS
, "Array type is not uint32.");
467 dbus_message_iter_get_fixed_array(&array_iter
, &default_channels
, &n_channels
);
469 if (n_channels
<= 0) {
470 pa_dbus_send_error(conn
, msg
, DBUS_ERROR_INVALID_ARGS
, "Empty channel array.");
474 new_channel_map
.channels
= n_channels
;
476 for (i
= 0; i
< new_channel_map
.channels
; ++i
) {
477 if (default_channels
[i
] >= PA_CHANNEL_POSITION_MAX
) {
478 pa_dbus_send_error(conn
, msg
, DBUS_ERROR_INVALID_ARGS
, "Invalid channel position.");
482 new_channel_map
.map
[i
] = default_channels
[i
];
485 c
->core
->default_channel_map
= new_channel_map
;
486 c
->core
->default_sample_spec
.channels
= n_channels
;
488 pa_dbus_send_empty_reply(conn
, msg
);
491 static void handle_get_default_sample_format(DBusConnection
*conn
, DBusMessage
*msg
, void *userdata
) {
492 pa_dbusiface_core
*c
= userdata
;
493 dbus_uint32_t default_sample_format
;
499 default_sample_format
= c
->core
->default_sample_spec
.format
;
501 pa_dbus_send_basic_variant_reply(conn
, msg
, DBUS_TYPE_UINT32
, &default_sample_format
);
504 static void handle_set_default_sample_format(DBusConnection
*conn
, DBusMessage
*msg
, void *userdata
) {
505 pa_dbusiface_core
*c
= userdata
;
506 dbus_uint32_t default_sample_format
;
512 if (pa_dbus_get_basic_set_property_arg(conn
, msg
, DBUS_TYPE_UINT32
, &default_sample_format
) < 0)
515 if (default_sample_format
>= PA_SAMPLE_MAX
) {
516 pa_dbus_send_error(conn
, msg
, DBUS_ERROR_INVALID_ARGS
, "Invalid sample format.");
520 c
->core
->default_sample_spec
.format
= default_sample_format
;
522 pa_dbus_send_empty_reply(conn
, msg
);
525 static void handle_get_default_sample_rate(DBusConnection
*conn
, DBusMessage
*msg
, void *userdata
) {
526 pa_dbusiface_core
*c
= userdata
;
527 dbus_uint32_t default_sample_rate
;
533 default_sample_rate
= c
->core
->default_sample_spec
.rate
;
535 pa_dbus_send_basic_variant_reply(conn
, msg
, DBUS_TYPE_UINT32
, &default_sample_rate
);
538 static void handle_set_default_sample_rate(DBusConnection
*conn
, DBusMessage
*msg
, void *userdata
) {
539 pa_dbusiface_core
*c
= userdata
;
540 dbus_uint32_t default_sample_rate
;
546 if (pa_dbus_get_basic_set_property_arg(conn
, msg
, DBUS_TYPE_UINT32
, &default_sample_rate
) < 0)
549 if (default_sample_rate
<= 0 || default_sample_rate
> PA_RATE_MAX
) {
550 pa_dbus_send_error(conn
, msg
, DBUS_ERROR_INVALID_ARGS
, "Invalid sample format.");
554 c
->core
->default_sample_spec
.rate
= default_sample_rate
;
556 pa_dbus_send_empty_reply(conn
, msg
);
559 /* The caller frees the array, but not the strings. */
560 static const char **get_cards(pa_dbusiface_core
*c
, unsigned *n
) {
564 pa_dbusiface_card
*card
;
569 *n
= pa_hashmap_size(c
->cards
);
574 cards
= pa_xnew(const char *, *n
);
576 for (i
= 0, card
= pa_hashmap_iterate(c
->cards
, &state
, NULL
); card
; ++i
, card
= pa_hashmap_iterate(c
->cards
, &state
, NULL
))
577 cards
[i
] = pa_dbusiface_card_get_path(card
);
584 static void handle_get_cards(DBusConnection
*conn
, DBusMessage
*msg
, void *userdata
) {
585 pa_dbusiface_core
*c
= userdata
;
593 cards
= get_cards(c
, &n
);
595 pa_dbus_send_basic_array_variant_reply(conn
, msg
, DBUS_TYPE_OBJECT_PATH
, cards
, n
);
600 /* The caller frees the array, but not the strings. */
601 static const char **get_sinks(pa_dbusiface_core
*c
, unsigned *n
) {
605 pa_dbusiface_device
*sink
;
610 *n
= pa_hashmap_size(c
->sinks_by_index
);
615 sinks
= pa_xnew(const char *, *n
);
617 for (i
= 0, sink
= pa_hashmap_iterate(c
->sinks_by_index
, &state
, NULL
); sink
; ++i
, sink
= pa_hashmap_iterate(c
->sinks_by_index
, &state
, NULL
))
618 sinks
[i
] = pa_dbusiface_device_get_path(sink
);
625 static void handle_get_sinks(DBusConnection
*conn
, DBusMessage
*msg
, void *userdata
) {
626 pa_dbusiface_core
*c
= userdata
;
634 sinks
= get_sinks(c
, &n
);
636 pa_dbus_send_basic_array_variant_reply(conn
, msg
, DBUS_TYPE_OBJECT_PATH
, sinks
, n
);
641 static void handle_get_fallback_sink(DBusConnection
*conn
, DBusMessage
*msg
, void *userdata
) {
642 pa_dbusiface_core
*c
= userdata
;
643 pa_dbusiface_device
*fallback_sink
;
644 const char *object_path
;
650 if (!c
->fallback_sink
) {
651 pa_dbus_send_error(conn
, msg
, PA_DBUS_ERROR_NO_SUCH_PROPERTY
, "There are no sinks, and therefore no fallback sink either.");
655 pa_assert_se((fallback_sink
= pa_hashmap_get(c
->sinks_by_index
, PA_UINT32_TO_PTR(c
->fallback_sink
->index
))));
656 object_path
= pa_dbusiface_device_get_path(fallback_sink
);
658 pa_dbus_send_basic_variant_reply(conn
, msg
, DBUS_TYPE_OBJECT_PATH
, &object_path
);
661 static void handle_set_fallback_sink(DBusConnection
*conn
, DBusMessage
*msg
, void *userdata
) {
662 pa_dbusiface_core
*c
= userdata
;
663 pa_dbusiface_device
*fallback_sink
;
664 const char *object_path
;
670 if (!c
->fallback_sink
) {
671 pa_dbus_send_error(conn
, msg
, PA_DBUS_ERROR_NO_SUCH_PROPERTY
, "There are no sinks, and therefore no fallback sink either.");
675 if (pa_dbus_get_basic_set_property_arg(conn
, msg
, DBUS_TYPE_OBJECT_PATH
, &object_path
) < 0)
678 if (!(fallback_sink
= pa_hashmap_get(c
->sinks_by_path
, object_path
))) {
679 pa_dbus_send_error(conn
, msg
, PA_DBUS_ERROR_NOT_FOUND
, "No such sink.");
683 pa_namereg_set_default_sink(c
->core
, pa_dbusiface_device_get_sink(fallback_sink
));
685 pa_dbus_send_empty_reply(conn
, msg
);
688 /* The caller frees the array, but not the strings. */
689 static const char **get_sources(pa_dbusiface_core
*c
, unsigned *n
) {
690 const char **sources
;
693 pa_dbusiface_device
*source
;
698 *n
= pa_hashmap_size(c
->sources_by_index
);
703 sources
= pa_xnew(const char *, *n
);
705 for (i
= 0, source
= pa_hashmap_iterate(c
->sources_by_index
, &state
, NULL
); source
; ++i
, source
= pa_hashmap_iterate(c
->sources_by_index
, &state
, NULL
))
706 sources
[i
] = pa_dbusiface_device_get_path(source
);
713 static void handle_get_sources(DBusConnection
*conn
, DBusMessage
*msg
, void *userdata
) {
714 pa_dbusiface_core
*c
= userdata
;
715 const char **sources
;
722 sources
= get_sources(c
, &n
);
724 pa_dbus_send_basic_array_variant_reply(conn
, msg
, DBUS_TYPE_OBJECT_PATH
, sources
, n
);
729 static void handle_get_fallback_source(DBusConnection
*conn
, DBusMessage
*msg
, void *userdata
) {
730 pa_dbusiface_core
*c
= userdata
;
731 pa_dbusiface_device
*fallback_source
;
732 const char *object_path
;
738 if (!c
->fallback_source
) {
739 pa_dbus_send_error(conn
, msg
, PA_DBUS_ERROR_NO_SUCH_PROPERTY
, "There are no sources, and therefore no fallback source either.");
743 pa_assert_se((fallback_source
= pa_hashmap_get(c
->sources_by_index
, PA_UINT32_TO_PTR(c
->fallback_source
->index
))));
744 object_path
= pa_dbusiface_device_get_path(fallback_source
);
746 pa_dbus_send_basic_variant_reply(conn
, msg
, DBUS_TYPE_OBJECT_PATH
, &object_path
);
749 static void handle_set_fallback_source(DBusConnection
*conn
, DBusMessage
*msg
, void *userdata
) {
750 pa_dbusiface_core
*c
= userdata
;
751 pa_dbusiface_device
*fallback_source
;
752 const char *object_path
;
758 if (!c
->fallback_source
) {
759 pa_dbus_send_error(conn
, msg
, PA_DBUS_ERROR_NO_SUCH_PROPERTY
, "There are no sources, and therefore no fallback source either.");
763 if (pa_dbus_get_basic_set_property_arg(conn
, msg
, DBUS_TYPE_OBJECT_PATH
, &object_path
) < 0)
766 if (!(fallback_source
= pa_hashmap_get(c
->sources_by_path
, object_path
))) {
767 pa_dbus_send_error(conn
, msg
, PA_DBUS_ERROR_NOT_FOUND
, "No such source.");
771 pa_namereg_set_default_source(c
->core
, pa_dbusiface_device_get_source(fallback_source
));
773 pa_dbus_send_empty_reply(conn
, msg
);
776 /* The caller frees the array, but not the strings. */
777 static const char **get_playback_streams(pa_dbusiface_core
*c
, unsigned *n
) {
778 const char **streams
;
781 pa_dbusiface_stream
*stream
;
786 *n
= pa_hashmap_size(c
->playback_streams
);
791 streams
= pa_xnew(const char *, *n
);
793 for (i
= 0, stream
= pa_hashmap_iterate(c
->playback_streams
, &state
, NULL
); stream
; ++i
, stream
= pa_hashmap_iterate(c
->playback_streams
, &state
, NULL
))
794 streams
[i
] = pa_dbusiface_stream_get_path(stream
);
801 static void handle_get_playback_streams(DBusConnection
*conn
, DBusMessage
*msg
, void *userdata
) {
802 pa_dbusiface_core
*c
= userdata
;
803 const char **playback_streams
;
810 playback_streams
= get_playback_streams(c
, &n
);
812 pa_dbus_send_basic_array_variant_reply(conn
, msg
, DBUS_TYPE_OBJECT_PATH
, playback_streams
, n
);
814 pa_xfree(playback_streams
);
817 /* The caller frees the array, but not the strings. */
818 static const char **get_record_streams(pa_dbusiface_core
*c
, unsigned *n
) {
819 const char **streams
;
822 pa_dbusiface_stream
*stream
;
827 *n
= pa_hashmap_size(c
->record_streams
);
832 streams
= pa_xnew(const char *, *n
);
834 for (i
= 0, stream
= pa_hashmap_iterate(c
->record_streams
, &state
, NULL
); stream
; ++i
, stream
= pa_hashmap_iterate(c
->record_streams
, &state
, NULL
))
835 streams
[i
] = pa_dbusiface_stream_get_path(stream
);
842 static void handle_get_record_streams(DBusConnection
*conn
, DBusMessage
*msg
, void *userdata
) {
843 pa_dbusiface_core
*c
= userdata
;
844 const char **record_streams
;
851 record_streams
= get_record_streams(c
, &n
);
853 pa_dbus_send_basic_array_variant_reply(conn
, msg
, DBUS_TYPE_OBJECT_PATH
, record_streams
, n
);
855 pa_xfree(record_streams
);
858 /* The caller frees the array, but not the strings. */
859 static const char **get_samples(pa_dbusiface_core
*c
, unsigned *n
) {
860 const char **samples
;
863 pa_dbusiface_sample
*sample
;
868 *n
= pa_hashmap_size(c
->samples
);
873 samples
= pa_xnew(const char *, *n
);
875 for (i
= 0, sample
= pa_hashmap_iterate(c
->samples
, &state
, NULL
); sample
; ++i
, sample
= pa_hashmap_iterate(c
->samples
, &state
, NULL
))
876 samples
[i
] = pa_dbusiface_sample_get_path(sample
);
883 static void handle_get_samples(DBusConnection
*conn
, DBusMessage
*msg
, void *userdata
) {
884 pa_dbusiface_core
*c
= userdata
;
885 const char **samples
;
892 samples
= get_samples(c
, &n
);
894 pa_dbus_send_basic_array_variant_reply(conn
, msg
, DBUS_TYPE_OBJECT_PATH
, samples
, n
);
899 /* The caller frees the array, but not the strings. */
900 static const char **get_modules(pa_dbusiface_core
*c
, unsigned *n
) {
901 const char **modules
;
904 pa_dbusiface_module
*module
;
909 *n
= pa_hashmap_size(c
->modules
);
914 modules
= pa_xnew(const char *, *n
);
916 for (i
= 0, module
= pa_hashmap_iterate(c
->modules
, &state
, NULL
); module
; ++i
, module
= pa_hashmap_iterate(c
->modules
, &state
, NULL
))
917 modules
[i
] = pa_dbusiface_module_get_path(module
);
924 static void handle_get_modules(DBusConnection
*conn
, DBusMessage
*msg
, void *userdata
) {
925 pa_dbusiface_core
*c
= userdata
;
926 const char **modules
;
933 modules
= get_modules(c
, &n
);
935 pa_dbus_send_basic_array_variant_reply(conn
, msg
, DBUS_TYPE_OBJECT_PATH
, modules
, n
);
940 /* The caller frees the array, but not the strings. */
941 static const char **get_clients(pa_dbusiface_core
*c
, unsigned *n
) {
942 const char **clients
;
945 pa_dbusiface_client
*client
;
950 *n
= pa_hashmap_size(c
->clients
);
955 clients
= pa_xnew(const char *, *n
);
957 for (i
= 0, client
= pa_hashmap_iterate(c
->clients
, &state
, NULL
); client
; ++i
, client
= pa_hashmap_iterate(c
->clients
, &state
, NULL
))
958 clients
[i
] = pa_dbusiface_client_get_path(client
);
965 static void handle_get_clients(DBusConnection
*conn
, DBusMessage
*msg
, void *userdata
) {
966 pa_dbusiface_core
*c
= userdata
;
967 const char **clients
;
974 clients
= get_clients(c
, &n
);
976 pa_dbus_send_basic_array_variant_reply(conn
, msg
, DBUS_TYPE_OBJECT_PATH
, clients
, n
);
981 static const char *get_my_client(pa_dbusiface_core
*c
, DBusConnection
*conn
) {
982 pa_client
*my_client
;
987 pa_assert_se((my_client
= pa_dbus_protocol_get_client(c
->dbus_protocol
, conn
)));
989 return pa_dbusiface_client_get_path(pa_hashmap_get(c
->clients
, PA_UINT32_TO_PTR(my_client
->index
)));
992 static void handle_get_my_client(DBusConnection
*conn
, DBusMessage
*msg
, void *userdata
) {
993 pa_dbusiface_core
*c
= userdata
;
994 const char *my_client
;
1000 my_client
= get_my_client(c
, conn
);
1002 pa_dbus_send_basic_variant_reply(conn
, msg
, DBUS_TYPE_OBJECT_PATH
, &my_client
);
1005 static void handle_get_extensions(DBusConnection
*conn
, DBusMessage
*msg
, void *userdata
) {
1006 pa_dbusiface_core
*c
= userdata
;
1007 const char **extensions
;
1014 extensions
= pa_dbus_protocol_get_extensions(c
->dbus_protocol
, &n
);
1016 pa_dbus_send_basic_array_variant_reply(conn
, msg
, DBUS_TYPE_STRING
, extensions
, n
);
1018 pa_xfree(extensions
);
1021 static void handle_get_all(DBusConnection
*conn
, DBusMessage
*msg
, void *userdata
) {
1022 pa_dbusiface_core
*c
= userdata
;
1023 DBusMessage
*reply
= NULL
;
1024 DBusMessageIter msg_iter
;
1025 DBusMessageIter dict_iter
;
1026 dbus_uint32_t interface_revision
;
1027 const char *server_name
;
1028 const char *version
;
1029 dbus_bool_t is_local
;
1032 dbus_uint32_t
*default_channels
;
1033 unsigned n_default_channels
;
1034 dbus_uint32_t default_sample_format
;
1035 dbus_uint32_t default_sample_rate
;
1040 const char *fallback_sink
;
1041 const char **sources
;
1043 const char *fallback_source
;
1044 const char **playback_streams
;
1045 unsigned n_playback_streams
;
1046 const char **record_streams
;
1047 unsigned n_record_streams
;
1048 const char **samples
;
1050 const char **modules
;
1052 const char **clients
;
1054 const char *my_client
;
1055 const char **extensions
;
1056 unsigned n_extensions
;
1062 interface_revision
= INTERFACE_REVISION
;
1063 server_name
= PACKAGE_NAME
;
1064 version
= PACKAGE_VERSION
;
1065 is_local
= get_is_local(conn
);
1066 username
= pa_get_user_name_malloc();
1067 hostname
= pa_get_host_name_malloc();
1068 default_channels
= get_default_channels(c
, &n_default_channels
);
1069 default_sample_format
= c
->core
->default_sample_spec
.format
;
1070 default_sample_rate
= c
->core
->default_sample_spec
.rate
;
1071 cards
= get_cards(c
, &n_cards
);
1072 sinks
= get_sinks(c
, &n_sinks
);
1073 fallback_sink
= c
->fallback_sink
? pa_dbusiface_device_get_path(pa_hashmap_get(c
->sinks_by_index
, PA_UINT32_TO_PTR(c
->fallback_sink
->index
))) : NULL
;
1074 sources
= get_sources(c
, &n_sources
);
1075 fallback_source
= c
->fallback_source
? pa_dbusiface_device_get_path(pa_hashmap_get(c
->sources_by_index
, PA_UINT32_TO_PTR(c
->fallback_source
->index
))) : NULL
;
1076 playback_streams
= get_playback_streams(c
, &n_playback_streams
);
1077 record_streams
= get_record_streams(c
, &n_record_streams
);
1078 samples
= get_samples(c
, &n_samples
);
1079 modules
= get_modules(c
, &n_modules
);
1080 clients
= get_clients(c
, &n_clients
);
1081 my_client
= get_my_client(c
, conn
);
1082 extensions
= pa_dbus_protocol_get_extensions(c
->dbus_protocol
, &n_extensions
);
1084 pa_assert_se((reply
= dbus_message_new_method_return(msg
)));
1086 dbus_message_iter_init_append(reply
, &msg_iter
);
1087 pa_assert_se(dbus_message_iter_open_container(&msg_iter
, DBUS_TYPE_ARRAY
, "{sv}", &dict_iter
));
1089 pa_dbus_append_basic_variant_dict_entry(&dict_iter
, property_handlers
[PROPERTY_HANDLER_INTERFACE_REVISION
].property_name
, DBUS_TYPE_UINT32
, &interface_revision
);
1090 pa_dbus_append_basic_variant_dict_entry(&dict_iter
, property_handlers
[PROPERTY_HANDLER_NAME
].property_name
, DBUS_TYPE_STRING
, &server_name
);
1091 pa_dbus_append_basic_variant_dict_entry(&dict_iter
, property_handlers
[PROPERTY_HANDLER_VERSION
].property_name
, DBUS_TYPE_STRING
, &version
);
1092 pa_dbus_append_basic_variant_dict_entry(&dict_iter
, property_handlers
[PROPERTY_HANDLER_IS_LOCAL
].property_name
, DBUS_TYPE_BOOLEAN
, &is_local
);
1093 pa_dbus_append_basic_variant_dict_entry(&dict_iter
, property_handlers
[PROPERTY_HANDLER_USERNAME
].property_name
, DBUS_TYPE_STRING
, &username
);
1094 pa_dbus_append_basic_variant_dict_entry(&dict_iter
, property_handlers
[PROPERTY_HANDLER_HOSTNAME
].property_name
, DBUS_TYPE_STRING
, &hostname
);
1095 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
);
1096 pa_dbus_append_basic_variant_dict_entry(&dict_iter
, property_handlers
[PROPERTY_HANDLER_DEFAULT_SAMPLE_FORMAT
].property_name
, DBUS_TYPE_UINT32
, &default_sample_format
);
1097 pa_dbus_append_basic_variant_dict_entry(&dict_iter
, property_handlers
[PROPERTY_HANDLER_DEFAULT_SAMPLE_RATE
].property_name
, DBUS_TYPE_UINT32
, &default_sample_rate
);
1098 pa_dbus_append_basic_array_variant_dict_entry(&dict_iter
, property_handlers
[PROPERTY_HANDLER_CARDS
].property_name
, DBUS_TYPE_OBJECT_PATH
, cards
, n_cards
);
1099 pa_dbus_append_basic_array_variant_dict_entry(&dict_iter
, property_handlers
[PROPERTY_HANDLER_SINKS
].property_name
, DBUS_TYPE_OBJECT_PATH
, sinks
, n_sinks
);
1102 pa_dbus_append_basic_variant_dict_entry(&dict_iter
, property_handlers
[PROPERTY_HANDLER_FALLBACK_SINK
].property_name
, DBUS_TYPE_OBJECT_PATH
, &fallback_sink
);
1104 pa_dbus_append_basic_array_variant_dict_entry(&dict_iter
, property_handlers
[PROPERTY_HANDLER_SOURCES
].property_name
, DBUS_TYPE_OBJECT_PATH
, sources
, n_sources
);
1106 if (fallback_source
)
1107 pa_dbus_append_basic_variant_dict_entry(&dict_iter
, property_handlers
[PROPERTY_HANDLER_FALLBACK_SOURCE
].property_name
, DBUS_TYPE_OBJECT_PATH
, &fallback_source
);
1109 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
);
1110 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
);
1111 pa_dbus_append_basic_array_variant_dict_entry(&dict_iter
, property_handlers
[PROPERTY_HANDLER_SAMPLES
].property_name
, DBUS_TYPE_OBJECT_PATH
, samples
, n_samples
);
1112 pa_dbus_append_basic_array_variant_dict_entry(&dict_iter
, property_handlers
[PROPERTY_HANDLER_MODULES
].property_name
, DBUS_TYPE_OBJECT_PATH
, modules
, n_modules
);
1113 pa_dbus_append_basic_array_variant_dict_entry(&dict_iter
, property_handlers
[PROPERTY_HANDLER_CLIENTS
].property_name
, DBUS_TYPE_OBJECT_PATH
, clients
, n_clients
);
1114 pa_dbus_append_basic_variant_dict_entry(&dict_iter
, property_handlers
[PROPERTY_HANDLER_MY_CLIENT
].property_name
, DBUS_TYPE_OBJECT_PATH
, &my_client
);
1115 pa_dbus_append_basic_array_variant_dict_entry(&dict_iter
, property_handlers
[PROPERTY_HANDLER_EXTENSIONS
].property_name
, DBUS_TYPE_STRING
, extensions
, n_extensions
);
1117 pa_assert_se(dbus_message_iter_close_container(&msg_iter
, &dict_iter
));
1119 pa_assert_se(dbus_connection_send(conn
, reply
, NULL
));
1121 dbus_message_unref(reply
);
1125 pa_xfree(default_channels
);
1129 pa_xfree(playback_streams
);
1130 pa_xfree(record_streams
);
1134 pa_xfree(extensions
);
1137 static void handle_get_card_by_name(DBusConnection
*conn
, DBusMessage
*msg
, void *userdata
) {
1138 pa_dbusiface_core
*c
= userdata
;
1141 pa_dbusiface_card
*dbus_card
;
1142 const char *object_path
;
1149 dbus_error_init(&error
);
1151 if (!dbus_message_get_args(msg
, &error
, DBUS_TYPE_STRING
, &card_name
, DBUS_TYPE_INVALID
)) {
1152 pa_dbus_send_error(conn
, msg
, DBUS_ERROR_INVALID_ARGS
, error
.message
);
1153 dbus_error_free(&error
);
1157 if (!(card
= pa_namereg_get(c
->core
, card_name
, PA_NAMEREG_CARD
))) {
1158 pa_dbus_send_error(conn
, msg
, PA_DBUS_ERROR_NOT_FOUND
, "No such card.");
1162 pa_assert_se((dbus_card
= pa_hashmap_get(c
->cards
, PA_UINT32_TO_PTR(card
->index
))));
1164 object_path
= pa_dbusiface_card_get_path(dbus_card
);
1166 pa_dbus_send_basic_value_reply(conn
, msg
, DBUS_TYPE_OBJECT_PATH
, &object_path
);
1169 static void handle_get_sink_by_name(DBusConnection
*conn
, DBusMessage
*msg
, void *userdata
) {
1170 pa_dbusiface_core
*c
= userdata
;
1173 pa_dbusiface_device
*dbus_sink
;
1174 const char *object_path
;
1181 dbus_error_init(&error
);
1183 if (!dbus_message_get_args(msg
, &error
, DBUS_TYPE_STRING
, &sink_name
, DBUS_TYPE_INVALID
)) {
1184 pa_dbus_send_error(conn
, msg
, DBUS_ERROR_INVALID_ARGS
, error
.message
);
1185 dbus_error_free(&error
);
1189 if (!(sink
= pa_namereg_get(c
->core
, sink_name
, PA_NAMEREG_SINK
))) {
1190 pa_dbus_send_error(conn
, msg
, PA_DBUS_ERROR_NOT_FOUND
, "No such sink.");
1194 pa_assert_se((dbus_sink
= pa_hashmap_get(c
->sinks_by_index
, PA_UINT32_TO_PTR(sink
->index
))));
1196 object_path
= pa_dbusiface_device_get_path(dbus_sink
);
1198 pa_dbus_send_basic_value_reply(conn
, msg
, DBUS_TYPE_OBJECT_PATH
, &object_path
);
1201 static void handle_get_source_by_name(DBusConnection
*conn
, DBusMessage
*msg
, void *userdata
) {
1202 pa_dbusiface_core
*c
= userdata
;
1205 pa_dbusiface_device
*dbus_source
;
1206 const char *object_path
;
1213 dbus_error_init(&error
);
1215 if (!dbus_message_get_args(msg
, &error
, DBUS_TYPE_STRING
, &source_name
, DBUS_TYPE_INVALID
)) {
1216 pa_dbus_send_error(conn
, msg
, DBUS_ERROR_INVALID_ARGS
, error
.message
);
1217 dbus_error_free(&error
);
1221 if (!(source
= pa_namereg_get(c
->core
, source_name
, PA_NAMEREG_SOURCE
))) {
1222 pa_dbus_send_error(conn
, msg
, PA_DBUS_ERROR_NOT_FOUND
, "No such source.");
1226 pa_assert_se((dbus_source
= pa_hashmap_get(c
->sources_by_index
, PA_UINT32_TO_PTR(source
->index
))));
1228 object_path
= pa_dbusiface_device_get_path(dbus_source
);
1230 pa_dbus_send_basic_value_reply(conn
, msg
, DBUS_TYPE_OBJECT_PATH
, &object_path
);
1233 static void handle_get_sample_by_name(DBusConnection
*conn
, DBusMessage
*msg
, void *userdata
) {
1234 pa_dbusiface_core
*c
= userdata
;
1236 pa_scache_entry
*sample
;
1237 pa_dbusiface_sample
*dbus_sample
;
1238 const char *object_path
;
1245 dbus_error_init(&error
);
1247 if (!dbus_message_get_args(msg
, &error
, DBUS_TYPE_STRING
, &sample_name
, DBUS_TYPE_INVALID
)) {
1248 pa_dbus_send_error(conn
, msg
, DBUS_ERROR_INVALID_ARGS
, error
.message
);
1249 dbus_error_free(&error
);
1253 if (!(sample
= pa_namereg_get(c
->core
, sample_name
, PA_NAMEREG_SAMPLE
))) {
1254 pa_dbus_send_error(conn
, msg
, PA_DBUS_ERROR_NOT_FOUND
, "No such sample.");
1258 pa_assert_se((dbus_sample
= pa_hashmap_get(c
->samples
, PA_UINT32_TO_PTR(sample
->index
))));
1260 object_path
= pa_dbusiface_sample_get_path(dbus_sample
);
1262 pa_dbus_send_basic_value_reply(conn
, msg
, DBUS_TYPE_OBJECT_PATH
, &object_path
);
1265 static void handle_upload_sample(DBusConnection
*conn
, DBusMessage
*msg
, void *userdata
) {
1266 pa_dbusiface_core
*c
= userdata
;
1267 DBusMessageIter msg_iter
;
1269 dbus_uint32_t sample_format
;
1270 dbus_uint32_t sample_rate
;
1271 const dbus_uint32_t
*channels
;
1272 unsigned n_channels
;
1273 const dbus_uint32_t
*default_volume
;
1274 unsigned n_volume_entries
;
1275 pa_proplist
*property_list
;
1276 const uint8_t *data
;
1277 unsigned data_length
;
1283 pa_dbusiface_sample
*dbus_sample
= NULL
;
1284 pa_scache_entry
*sample
= NULL
;
1285 const char *object_path
;
1291 chunk
.memblock
= NULL
;
1293 if (!dbus_message_iter_init(msg
, &msg_iter
)) {
1294 pa_dbus_send_error(conn
, msg
, DBUS_ERROR_INVALID_ARGS
, "Too few arguments.");
1298 if (pa_dbus_get_basic_arg(conn
, msg
, &msg_iter
, DBUS_TYPE_STRING
, &name
) < 0)
1301 if (pa_dbus_get_basic_arg(conn
, msg
, &msg_iter
, DBUS_TYPE_UINT32
, &sample_format
) < 0)
1304 if (pa_dbus_get_basic_arg(conn
, msg
, &msg_iter
, DBUS_TYPE_UINT32
, &sample_rate
) < 0)
1307 if (pa_dbus_get_fixed_array_arg(conn
, msg
, &msg_iter
, DBUS_TYPE_UINT32
, &channels
, &n_channels
) < 0)
1310 if (pa_dbus_get_fixed_array_arg(conn
, msg
, &msg_iter
, DBUS_TYPE_UINT32
, &default_volume
, &n_volume_entries
) < 0)
1313 if (!(property_list
= pa_dbus_get_proplist_arg(conn
, msg
, &msg_iter
)))
1316 if (pa_dbus_get_fixed_array_arg(conn
, msg
, &msg_iter
, DBUS_TYPE_BYTE
, &data
, &data_length
) < 0)
1319 if (sample_format
>= PA_SAMPLE_MAX
) {
1320 pa_dbus_send_error(conn
, msg
, DBUS_ERROR_INVALID_ARGS
, "Invalid sample format.");
1324 if (sample_rate
<= 0 || sample_rate
> PA_RATE_MAX
) {
1325 pa_dbus_send_error(conn
, msg
, DBUS_ERROR_INVALID_ARGS
, "Invalid sample rate.");
1329 if (n_channels
== 0) {
1330 pa_dbus_send_error(conn
, msg
, DBUS_ERROR_INVALID_ARGS
, "Empty channel map.");
1334 if (n_channels
> PA_CHANNELS_MAX
) {
1335 pa_dbus_send_error(conn
, msg
, DBUS_ERROR_INVALID_ARGS
, "Too many channels.");
1339 for (i
= 0; i
< n_channels
; ++i
) {
1340 if (channels
[i
] >= PA_CHANNEL_POSITION_MAX
) {
1341 pa_dbus_send_error(conn
, msg
, DBUS_ERROR_INVALID_ARGS
, "Invalid channel position.");
1346 if (n_volume_entries
!= 0 && n_volume_entries
!= n_channels
) {
1347 pa_dbus_send_error(conn
, msg
, DBUS_ERROR_INVALID_ARGS
, "The channels and default_volume arguments have different number of elements.");
1351 for (i
= 0; i
< n_volume_entries
; ++i
) {
1352 if (default_volume
[i
] > PA_VOLUME_MAX
) {
1353 pa_dbus_send_error(conn
, msg
, DBUS_ERROR_INVALID_ARGS
, "Invalid volume.");
1358 if (data_length
== 0) {
1359 pa_dbus_send_error(conn
, msg
, DBUS_ERROR_INVALID_ARGS
, "Empty data.");
1363 if (data_length
> PA_SCACHE_ENTRY_SIZE_MAX
) {
1364 pa_dbus_send_error(conn
, msg
, DBUS_ERROR_INVALID_ARGS
, "Too big sample.");
1368 ss
.format
= sample_format
;
1369 ss
.rate
= sample_rate
;
1370 ss
.channels
= n_channels
;
1372 if (!pa_frame_aligned(data_length
, &ss
)) {
1373 pa_dbus_send_error(conn
, msg
, DBUS_ERROR_INVALID_ARGS
, "The sample length in bytes doesn't align with the sample format and channels.");
1377 map
.channels
= n_channels
;
1378 for (i
= 0; i
< n_channels
; ++i
)
1379 map
.map
[i
] = channels
[i
];
1381 chunk
.memblock
= pa_memblock_new(c
->core
->mempool
, data_length
);
1383 chunk
.length
= data_length
;
1385 memcpy(pa_memblock_acquire(chunk
.memblock
), data
, data_length
);
1386 pa_memblock_release(chunk
.memblock
);
1388 if (pa_scache_add_item(c
->core
, name
, &ss
, &map
, &chunk
, property_list
, &idx
) < 0) {
1389 pa_dbus_send_error(conn
, msg
, DBUS_ERROR_FAILED
, "Adding the sample failed.");
1393 sample
= pa_idxset_get_by_index(c
->core
->scache
, idx
);
1395 if (n_volume_entries
> 0) {
1396 sample
->volume
.channels
= n_channels
;
1397 for (i
= 0; i
< n_volume_entries
; ++i
)
1398 sample
->volume
.values
[i
] = default_volume
[i
];
1399 sample
->volume_is_set
= TRUE
;
1401 sample
->volume_is_set
= FALSE
;
1404 dbus_sample
= pa_dbusiface_sample_new(sample
, OBJECT_PATH
);
1405 pa_hashmap_put(c
->samples
, PA_UINT32_TO_PTR(idx
), dbus_sample
);
1407 object_path
= pa_dbusiface_sample_get_path(dbus_sample
);
1409 pa_dbus_send_basic_value_reply(conn
, msg
, DBUS_TYPE_OBJECT_PATH
, &object_path
);
1413 pa_proplist_free(property_list
);
1416 pa_memblock_unref(chunk
.memblock
);
1419 static pa_bool_t
contains_space(const char *string
) {
1424 for (p
= string
; *p
; ++p
) {
1432 static void handle_load_module(DBusConnection
*conn
, DBusMessage
*msg
, void *userdata
) {
1433 pa_dbusiface_core
*c
= userdata
;
1434 DBusMessageIter msg_iter
;
1435 DBusMessageIter dict_iter
;
1439 char *escaped_value
;
1440 pa_strbuf
*arg_buffer
= NULL
;
1442 pa_dbusiface_module
*dbus_module
;
1443 const char *object_path
;
1449 if (c
->core
->disallow_module_loading
) {
1450 pa_dbus_send_error(conn
, msg
, DBUS_ERROR_ACCESS_DENIED
, "The server is configured to disallow module loading.");
1454 if (!dbus_message_iter_init(msg
, &msg_iter
)) {
1455 pa_dbus_send_error(conn
, msg
, DBUS_ERROR_INVALID_ARGS
, "Too few arguments.");
1459 if (pa_dbus_get_basic_arg(conn
, msg
, &msg_iter
, DBUS_TYPE_STRING
, &name
) < 0)
1462 if (dbus_message_iter_get_arg_type(&msg_iter
) != DBUS_TYPE_ARRAY
) {
1463 pa_dbus_send_error(conn
, msg
, DBUS_ERROR_INVALID_ARGS
, "Wrong argument type or too few arguments. An array was expected.");
1467 if (dbus_message_iter_get_element_type(&msg_iter
) != DBUS_TYPE_DICT_ENTRY
) {
1468 pa_dbus_send_error(conn
, msg
, DBUS_ERROR_INVALID_ARGS
, "Wrong array element type. A dict entry was expected.");
1472 arg_buffer
= pa_strbuf_new();
1474 dbus_message_iter_recurse(&msg_iter
, &dict_iter
);
1476 while (dbus_message_iter_has_next(&dict_iter
)) {
1477 if (!pa_strbuf_isempty(arg_buffer
))
1478 pa_strbuf_putc(arg_buffer
, ' ');
1480 if (dbus_message_iter_get_arg_type(&dict_iter
) != DBUS_TYPE_STRING
) {
1481 pa_dbus_send_error(conn
, msg
, DBUS_ERROR_INVALID_ARGS
, "Wrong dict key type. A string was expected.");
1485 dbus_message_iter_get_basic(&dict_iter
, &key
);
1487 if (strlen(key
) <= 0 || !pa_ascii_valid(key
) || contains_space(key
)) {
1488 pa_dbus_send_error(conn
, msg
, DBUS_ERROR_INVALID_ARGS
, "Invalid module argument name.");
1492 if (dbus_message_iter_get_arg_type(&dict_iter
) != DBUS_TYPE_STRING
) {
1493 pa_dbus_send_error(conn
, msg
, DBUS_ERROR_INVALID_ARGS
, "Wrong dict value type. A string was expected.");
1497 dbus_message_iter_get_basic(&dict_iter
, &value
);
1499 escaped_value
= pa_escape(value
, "\"");
1500 pa_strbuf_printf(arg_buffer
, "%s=\"%s\"", key
, escaped_value
);
1501 pa_xfree(escaped_value
);
1504 if (!(module
= pa_module_load(c
->core
, name
, pa_strbuf_tostring(arg_buffer
)))) {
1505 pa_dbus_send_error(conn
, msg
, DBUS_ERROR_FAILED
, "Failed to load module.");
1509 dbus_module
= pa_dbusiface_module_new(module
, OBJECT_PATH
);
1510 pa_hashmap_put(c
->modules
, PA_UINT32_TO_PTR(module
->index
), dbus_module
);
1512 object_path
= pa_dbusiface_module_get_path(dbus_module
);
1514 pa_dbus_send_basic_value_reply(conn
, msg
, DBUS_TYPE_OBJECT_PATH
, &object_path
);
1518 pa_strbuf_free(arg_buffer
);
1521 static void handle_exit(DBusConnection
*conn
, DBusMessage
*msg
, void *userdata
) {
1522 pa_dbusiface_core
*c
= userdata
;
1528 if (c
->core
->disallow_exit
) {
1529 pa_dbus_send_error(conn
, msg
, DBUS_ERROR_ACCESS_DENIED
, "The server is configured to disallow exiting.");
1533 pa_dbus_send_empty_reply(conn
, msg
);
1535 pa_core_exit(c
->core
, FALSE
, 0);
1538 static void handle_listen_for_signal(DBusConnection
*conn
, DBusMessage
*msg
, void *userdata
) {
1539 pa_dbusiface_core
*c
= userdata
;
1541 char **objects
= NULL
;
1549 dbus_error_init(&error
);
1551 if (!dbus_message_get_args(msg
, &error
, DBUS_TYPE_STRING
, &signal
, DBUS_TYPE_ARRAY
, DBUS_TYPE_OBJECT_PATH
, &objects
, &n_objects
, DBUS_TYPE_INVALID
)) {
1552 pa_dbus_send_error(conn
, msg
, DBUS_ERROR_INVALID_ARGS
, error
.message
);
1553 dbus_error_free(&error
);
1557 pa_dbus_protocol_add_signal_listener(c
->dbus_protocol
, conn
, *signal
? signal
: NULL
, objects
, n_objects
);
1559 pa_dbus_send_empty_reply(conn
, msg
);
1562 dbus_free_string_array(objects
);
1565 static void handle_stop_listening_for_signal(DBusConnection
*conn
, DBusMessage
*msg
, void *userdata
) {
1566 pa_dbusiface_core
*c
= userdata
;
1574 dbus_error_init(&error
);
1576 if (!dbus_message_get_args(msg
, &error
, DBUS_TYPE_STRING
, &signal
, DBUS_TYPE_INVALID
)) {
1577 pa_dbus_send_error(conn
, msg
, DBUS_ERROR_INVALID_ARGS
, error
.message
);
1578 dbus_error_free(&error
);
1582 pa_dbus_protocol_remove_signal_listener(c
->dbus_protocol
, conn
, *signal
? signal
: NULL
);
1584 pa_dbus_send_empty_reply(conn
, msg
);
1587 static void subscription_cb(pa_core
*core
, pa_subscription_event_type_t t
, uint32_t idx
, void *userdata
) {
1588 pa_dbusiface_core
*c
= userdata
;
1589 pa_dbusiface_card
*card
= NULL
;
1590 pa_dbusiface_device
*device
= NULL
;
1591 pa_dbusiface_stream
*stream
= NULL
;
1592 pa_dbusiface_sample
*sample
= NULL
;
1593 pa_dbusiface_module
*module
= NULL
;
1594 pa_dbusiface_client
*client
= NULL
;
1595 DBusMessage
*signal
= NULL
;
1596 const char *object_path
= NULL
;
1597 pa_sink
*new_fallback_sink
= NULL
;
1598 pa_source
*new_fallback_source
= NULL
;
1602 switch (t
& PA_SUBSCRIPTION_EVENT_FACILITY_MASK
) {
1603 case PA_SUBSCRIPTION_EVENT_SERVER
:
1604 new_fallback_sink
= pa_namereg_get_default_sink(core
);
1605 new_fallback_source
= pa_namereg_get_default_source(core
);
1607 if (c
->fallback_sink
!= new_fallback_sink
) {
1608 c
->fallback_sink
= new_fallback_sink
;
1610 if (new_fallback_sink
) {
1611 pa_assert_se((device
= pa_hashmap_get(c
->sinks_by_index
, PA_UINT32_TO_PTR(new_fallback_sink
->index
))));
1613 object_path
= pa_dbusiface_device_get_path(device
);
1615 pa_assert_se((signal
= dbus_message_new_signal(OBJECT_PATH
, INTERFACE_CORE
, signals
[SIGNAL_FALLBACK_SINK_UPDATED
].name
)));
1616 pa_assert_se(dbus_message_append_args(signal
, DBUS_TYPE_OBJECT_PATH
, &object_path
, DBUS_TYPE_INVALID
));
1617 pa_dbus_protocol_send_signal(c
->dbus_protocol
, signal
);
1618 dbus_message_unref(signal
);
1623 if (c
->fallback_source
!= new_fallback_source
) {
1624 c
->fallback_source
= new_fallback_source
;
1626 if (new_fallback_source
) {
1627 pa_assert_se((device
= pa_hashmap_get(c
->sources_by_index
, PA_UINT32_TO_PTR(new_fallback_source
->index
))));
1629 object_path
= pa_dbusiface_device_get_path(device
);
1631 pa_assert_se((signal
= dbus_message_new_signal(OBJECT_PATH
, INTERFACE_CORE
, signals
[SIGNAL_FALLBACK_SOURCE_UPDATED
].name
)));
1632 pa_assert_se(dbus_message_append_args(signal
, DBUS_TYPE_OBJECT_PATH
, &object_path
, DBUS_TYPE_INVALID
));
1633 pa_dbus_protocol_send_signal(c
->dbus_protocol
, signal
);
1634 dbus_message_unref(signal
);
1640 case PA_SUBSCRIPTION_EVENT_CARD
:
1641 if ((t
& PA_SUBSCRIPTION_EVENT_TYPE_MASK
) == PA_SUBSCRIPTION_EVENT_NEW
) {
1642 card
= pa_dbusiface_card_new(pa_idxset_get_by_index(core
->cards
, idx
), OBJECT_PATH
);
1643 pa_hashmap_put(c
->cards
, PA_UINT32_TO_PTR(idx
), card
);
1645 object_path
= pa_dbusiface_card_get_path(card
);
1647 pa_assert_se((signal
= dbus_message_new_signal(OBJECT_PATH
, INTERFACE_CORE
, signals
[SIGNAL_NEW_CARD
].name
)));
1648 pa_assert_se(dbus_message_append_args(signal
, DBUS_TYPE_OBJECT_PATH
, &object_path
, DBUS_TYPE_INVALID
));
1650 } else if ((t
& PA_SUBSCRIPTION_EVENT_TYPE_MASK
) == PA_SUBSCRIPTION_EVENT_REMOVE
) {
1651 pa_assert_se((card
= pa_hashmap_remove(c
->cards
, PA_UINT32_TO_PTR(idx
))));
1653 object_path
= pa_dbusiface_card_get_path(card
);
1655 pa_assert_se((signal
= dbus_message_new_signal(OBJECT_PATH
, INTERFACE_CORE
, signals
[SIGNAL_CARD_REMOVED
].name
)));
1656 pa_assert_se(dbus_message_append_args(signal
, DBUS_TYPE_OBJECT_PATH
, &object_path
, DBUS_TYPE_INVALID
));
1658 pa_dbusiface_card_free(card
);
1662 case PA_SUBSCRIPTION_EVENT_SINK
:
1663 if ((t
& PA_SUBSCRIPTION_EVENT_TYPE_MASK
) == PA_SUBSCRIPTION_EVENT_NEW
) {
1664 device
= pa_dbusiface_device_new_sink(pa_idxset_get_by_index(core
->sinks
, idx
), OBJECT_PATH
);
1665 object_path
= pa_dbusiface_device_get_path(device
);
1667 pa_hashmap_put(c
->sinks_by_index
, PA_UINT32_TO_PTR(idx
), device
);
1668 pa_hashmap_put(c
->sinks_by_path
, object_path
, device
);
1670 pa_assert_se((signal
= dbus_message_new_signal(OBJECT_PATH
, INTERFACE_CORE
, signals
[SIGNAL_NEW_SINK
].name
)));
1671 pa_assert_se(dbus_message_append_args(signal
, DBUS_TYPE_OBJECT_PATH
, &object_path
, DBUS_TYPE_INVALID
));
1673 } else if ((t
& PA_SUBSCRIPTION_EVENT_TYPE_MASK
) == PA_SUBSCRIPTION_EVENT_REMOVE
) {
1674 pa_assert_se((device
= pa_hashmap_remove(c
->sinks_by_index
, PA_UINT32_TO_PTR(idx
))));
1675 object_path
= pa_dbusiface_device_get_path(device
);
1676 pa_assert_se(pa_hashmap_remove(c
->sinks_by_path
, object_path
));
1678 pa_assert_se((signal
= dbus_message_new_signal(OBJECT_PATH
, INTERFACE_CORE
, signals
[SIGNAL_SINK_REMOVED
].name
)));
1679 pa_assert_se(dbus_message_append_args(signal
, DBUS_TYPE_OBJECT_PATH
, &object_path
, DBUS_TYPE_INVALID
));
1681 pa_dbusiface_device_free(device
);
1685 case PA_SUBSCRIPTION_EVENT_SOURCE
:
1686 if ((t
& PA_SUBSCRIPTION_EVENT_TYPE_MASK
) == PA_SUBSCRIPTION_EVENT_NEW
) {
1687 device
= pa_dbusiface_device_new_source(pa_idxset_get_by_index(core
->sources
, idx
), OBJECT_PATH
);
1688 object_path
= pa_dbusiface_device_get_path(device
);
1690 pa_hashmap_put(c
->sources_by_index
, PA_UINT32_TO_PTR(idx
), device
);
1691 pa_hashmap_put(c
->sources_by_path
, object_path
, device
);
1693 pa_assert_se((signal
= dbus_message_new_signal(OBJECT_PATH
, INTERFACE_CORE
, signals
[SIGNAL_NEW_SOURCE
].name
)));
1694 pa_assert_se(dbus_message_append_args(signal
, DBUS_TYPE_OBJECT_PATH
, &object_path
, DBUS_TYPE_INVALID
));
1696 } else if ((t
& PA_SUBSCRIPTION_EVENT_TYPE_MASK
) == PA_SUBSCRIPTION_EVENT_REMOVE
) {
1697 pa_assert_se((device
= pa_hashmap_remove(c
->sources_by_index
, PA_UINT32_TO_PTR(idx
))));
1698 object_path
= pa_dbusiface_device_get_path(device
);
1699 pa_assert_se(pa_hashmap_remove(c
->sources_by_path
, object_path
));
1701 pa_assert_se((signal
= dbus_message_new_signal(OBJECT_PATH
, INTERFACE_CORE
, signals
[SIGNAL_SOURCE_REMOVED
].name
)));
1702 pa_assert_se(dbus_message_append_args(signal
, DBUS_TYPE_OBJECT_PATH
, &object_path
, DBUS_TYPE_INVALID
));
1704 pa_dbusiface_device_free(device
);
1708 case PA_SUBSCRIPTION_EVENT_SINK_INPUT
:
1709 if ((t
& PA_SUBSCRIPTION_EVENT_TYPE_MASK
) == PA_SUBSCRIPTION_EVENT_NEW
) {
1710 stream
= pa_dbusiface_stream_new_playback(pa_idxset_get_by_index(core
->sink_inputs
, idx
), OBJECT_PATH
);
1711 pa_hashmap_put(c
->playback_streams
, PA_UINT32_TO_PTR(idx
), stream
);
1713 object_path
= pa_dbusiface_stream_get_path(stream
);
1715 pa_assert_se((signal
= dbus_message_new_signal(OBJECT_PATH
, INTERFACE_CORE
, signals
[SIGNAL_NEW_PLAYBACK_STREAM
].name
)));
1716 pa_assert_se(dbus_message_append_args(signal
, DBUS_TYPE_OBJECT_PATH
, &object_path
, DBUS_TYPE_INVALID
));
1718 } else if ((t
& PA_SUBSCRIPTION_EVENT_TYPE_MASK
) == PA_SUBSCRIPTION_EVENT_REMOVE
) {
1719 pa_assert_se((stream
= pa_hashmap_remove(c
->playback_streams
, PA_UINT32_TO_PTR(idx
))));
1721 object_path
= pa_dbusiface_stream_get_path(stream
);
1723 pa_assert_se((signal
= dbus_message_new_signal(OBJECT_PATH
, INTERFACE_CORE
, signals
[SIGNAL_PLAYBACK_STREAM_REMOVED
].name
)));
1724 pa_assert_se(dbus_message_append_args(signal
, DBUS_TYPE_OBJECT_PATH
, &object_path
, DBUS_TYPE_INVALID
));
1726 pa_dbusiface_stream_free(stream
);
1730 case PA_SUBSCRIPTION_EVENT_SOURCE_OUTPUT
:
1731 if ((t
& PA_SUBSCRIPTION_EVENT_TYPE_MASK
) == PA_SUBSCRIPTION_EVENT_NEW
) {
1732 stream
= pa_dbusiface_stream_new_record(pa_idxset_get_by_index(core
->source_outputs
, idx
), OBJECT_PATH
);
1733 pa_hashmap_put(c
->record_streams
, PA_UINT32_TO_PTR(idx
), stream
);
1735 object_path
= pa_dbusiface_stream_get_path(stream
);
1737 pa_assert_se((signal
= dbus_message_new_signal(OBJECT_PATH
, INTERFACE_CORE
, signals
[SIGNAL_NEW_RECORD_STREAM
].name
)));
1738 pa_assert_se(dbus_message_append_args(signal
, DBUS_TYPE_OBJECT_PATH
, &object_path
, DBUS_TYPE_INVALID
));
1740 } else if ((t
& PA_SUBSCRIPTION_EVENT_TYPE_MASK
) == PA_SUBSCRIPTION_EVENT_REMOVE
) {
1741 pa_assert_se((stream
= pa_hashmap_remove(c
->record_streams
, PA_UINT32_TO_PTR(idx
))));
1743 object_path
= pa_dbusiface_stream_get_path(stream
);
1745 pa_assert_se((signal
= dbus_message_new_signal(OBJECT_PATH
, INTERFACE_CORE
, signals
[SIGNAL_RECORD_STREAM_REMOVED
].name
)));
1746 pa_assert_se(dbus_message_append_args(signal
, DBUS_TYPE_OBJECT_PATH
, &object_path
, DBUS_TYPE_INVALID
));
1748 pa_dbusiface_stream_free(stream
);
1752 case PA_SUBSCRIPTION_EVENT_SAMPLE_CACHE
:
1753 if ((t
& PA_SUBSCRIPTION_EVENT_TYPE_MASK
) == PA_SUBSCRIPTION_EVENT_NEW
) {
1754 /* We may have created the pa_dbusiface_sample object already
1755 * in handle_upload_sample. */
1756 if (!(sample
= pa_hashmap_get(c
->samples
, PA_UINT32_TO_PTR(idx
)))) {
1757 sample
= pa_dbusiface_sample_new(pa_idxset_get_by_index(core
->scache
, idx
), OBJECT_PATH
);
1758 pa_hashmap_put(c
->samples
, PA_UINT32_TO_PTR(idx
), sample
);
1761 object_path
= pa_dbusiface_sample_get_path(sample
);
1763 pa_assert_se((signal
= dbus_message_new_signal(OBJECT_PATH
, INTERFACE_CORE
, signals
[SIGNAL_NEW_SAMPLE
].name
)));
1764 pa_assert_se(dbus_message_append_args(signal
, DBUS_TYPE_OBJECT_PATH
, &object_path
, DBUS_TYPE_INVALID
));
1766 } else if ((t
& PA_SUBSCRIPTION_EVENT_TYPE_MASK
) == PA_SUBSCRIPTION_EVENT_REMOVE
) {
1767 pa_assert_se((sample
= pa_hashmap_remove(c
->samples
, PA_UINT32_TO_PTR(idx
))));
1769 object_path
= pa_dbusiface_sample_get_path(sample
);
1771 pa_assert_se((signal
= dbus_message_new_signal(OBJECT_PATH
, INTERFACE_CORE
, signals
[SIGNAL_SAMPLE_REMOVED
].name
)));
1772 pa_assert_se(dbus_message_append_args(signal
, DBUS_TYPE_OBJECT_PATH
, &object_path
, DBUS_TYPE_INVALID
));
1774 pa_dbusiface_sample_free(sample
);
1778 case PA_SUBSCRIPTION_EVENT_MODULE
:
1779 if ((t
& PA_SUBSCRIPTION_EVENT_TYPE_MASK
) == PA_SUBSCRIPTION_EVENT_NEW
) {
1780 /* We may have created the pa_dbusiface_module object already
1781 * in handle_load_module. */
1782 if (!(module
= pa_hashmap_get(c
->modules
, PA_UINT32_TO_PTR(idx
)))) {
1783 module
= pa_dbusiface_module_new(pa_idxset_get_by_index(core
->modules
, idx
), OBJECT_PATH
);
1784 pa_hashmap_put(c
->modules
, PA_UINT32_TO_PTR(idx
), module
);
1787 object_path
= pa_dbusiface_module_get_path(module
);
1789 pa_assert_se((signal
= dbus_message_new_signal(OBJECT_PATH
, INTERFACE_CORE
, signals
[SIGNAL_NEW_MODULE
].name
)));
1790 pa_assert_se(dbus_message_append_args(signal
, DBUS_TYPE_OBJECT_PATH
, &object_path
, DBUS_TYPE_INVALID
));
1792 } else if ((t
& PA_SUBSCRIPTION_EVENT_TYPE_MASK
) == PA_SUBSCRIPTION_EVENT_REMOVE
) {
1793 pa_assert_se((module
= pa_hashmap_remove(c
->modules
, PA_UINT32_TO_PTR(idx
))));
1795 object_path
= pa_dbusiface_module_get_path(module
);
1797 pa_assert_se((signal
= dbus_message_new_signal(OBJECT_PATH
, INTERFACE_CORE
, signals
[SIGNAL_MODULE_REMOVED
].name
)));
1798 pa_assert_se(dbus_message_append_args(signal
, DBUS_TYPE_OBJECT_PATH
, &object_path
, DBUS_TYPE_INVALID
));
1800 pa_dbusiface_module_free(module
);
1804 case PA_SUBSCRIPTION_EVENT_CLIENT
:
1805 if ((t
& PA_SUBSCRIPTION_EVENT_TYPE_MASK
) == PA_SUBSCRIPTION_EVENT_NEW
) {
1806 client
= pa_dbusiface_client_new(pa_idxset_get_by_index(core
->clients
, idx
), OBJECT_PATH
);
1807 pa_hashmap_put(c
->clients
, PA_UINT32_TO_PTR(idx
), client
);
1809 object_path
= pa_dbusiface_client_get_path(client
);
1811 pa_assert_se((signal
= dbus_message_new_signal(OBJECT_PATH
, INTERFACE_CORE
, signals
[SIGNAL_NEW_CLIENT
].name
)));
1812 pa_assert_se(dbus_message_append_args(signal
, DBUS_TYPE_OBJECT_PATH
, &object_path
, DBUS_TYPE_INVALID
));
1814 } else if ((t
& PA_SUBSCRIPTION_EVENT_TYPE_MASK
) == PA_SUBSCRIPTION_EVENT_REMOVE
) {
1815 pa_assert_se((client
= pa_hashmap_remove(c
->clients
, PA_UINT32_TO_PTR(idx
))));
1817 object_path
= pa_dbusiface_client_get_path(client
);
1819 pa_assert_se((signal
= dbus_message_new_signal(OBJECT_PATH
, INTERFACE_CORE
, signals
[SIGNAL_CLIENT_REMOVED
].name
)));
1820 pa_assert_se(dbus_message_append_args(signal
, DBUS_TYPE_OBJECT_PATH
, &object_path
, DBUS_TYPE_INVALID
));
1822 pa_dbusiface_client_free(client
);
1828 pa_dbus_protocol_send_signal(c
->dbus_protocol
, signal
);
1829 dbus_message_unref(signal
);
1833 pa_dbusiface_core
*pa_dbusiface_core_new(pa_core
*core
) {
1834 pa_dbusiface_core
*c
;
1838 pa_dbusiface_device
*device
;
1839 pa_sink_input
*sink_input
;
1840 pa_source_output
*source_output
;
1841 pa_scache_entry
*sample
;
1848 c
= pa_xnew(pa_dbusiface_core
, 1);
1850 c
->subscription
= pa_subscription_new(core
, PA_SUBSCRIPTION_MASK_ALL
, subscription_cb
, c
);
1851 c
->dbus_protocol
= pa_dbus_protocol_get(core
);
1852 c
->cards
= pa_hashmap_new(pa_idxset_trivial_hash_func
, pa_idxset_trivial_compare_func
);
1853 c
->sinks_by_index
= pa_hashmap_new(pa_idxset_trivial_hash_func
, pa_idxset_trivial_compare_func
);
1854 c
->sinks_by_path
= pa_hashmap_new(pa_idxset_string_hash_func
, pa_idxset_string_compare_func
);
1855 c
->sources_by_index
= pa_hashmap_new(pa_idxset_trivial_hash_func
, pa_idxset_trivial_compare_func
);
1856 c
->sources_by_path
= pa_hashmap_new(pa_idxset_string_hash_func
, pa_idxset_string_compare_func
);
1857 c
->playback_streams
= pa_hashmap_new(pa_idxset_trivial_hash_func
, pa_idxset_trivial_compare_func
);
1858 c
->record_streams
= pa_hashmap_new(pa_idxset_trivial_hash_func
, pa_idxset_trivial_compare_func
);
1859 c
->samples
= pa_hashmap_new(pa_idxset_trivial_hash_func
, pa_idxset_trivial_compare_func
);
1860 c
->modules
= pa_hashmap_new(pa_idxset_trivial_hash_func
, pa_idxset_trivial_compare_func
);
1861 c
->clients
= pa_hashmap_new(pa_idxset_trivial_hash_func
, pa_idxset_trivial_compare_func
);
1862 c
->fallback_sink
= pa_namereg_get_default_sink(core
);
1863 c
->fallback_source
= pa_namereg_get_default_source(core
);
1865 for (card
= pa_idxset_first(core
->cards
, &idx
); card
; card
= pa_idxset_next(core
->cards
, &idx
))
1866 pa_hashmap_put(c
->cards
, PA_UINT32_TO_PTR(idx
), pa_dbusiface_card_new(card
, OBJECT_PATH
));
1868 for (sink
= pa_idxset_first(core
->sinks
, &idx
); sink
; sink
= pa_idxset_next(core
->sinks
, &idx
)) {
1869 device
= pa_dbusiface_device_new_sink(sink
, OBJECT_PATH
);
1870 pa_hashmap_put(c
->sinks_by_index
, PA_UINT32_TO_PTR(idx
), device
);
1871 pa_hashmap_put(c
->sinks_by_path
, pa_dbusiface_device_get_path(device
), device
);
1874 for (source
= pa_idxset_first(core
->sources
, &idx
); source
; source
= pa_idxset_next(core
->sources
, &idx
)) {
1875 device
= pa_dbusiface_device_new_source(source
, OBJECT_PATH
);
1876 pa_hashmap_put(c
->sources_by_index
, PA_UINT32_TO_PTR(idx
), device
);
1877 pa_hashmap_put(c
->sources_by_path
, pa_dbusiface_device_get_path(device
), device
);
1880 for (sink_input
= pa_idxset_first(core
->sink_inputs
, &idx
); sink_input
; sink_input
= pa_idxset_next(core
->sink_inputs
, &idx
))
1881 pa_hashmap_put(c
->playback_streams
, PA_UINT32_TO_PTR(idx
), pa_dbusiface_stream_new_playback(sink_input
, OBJECT_PATH
));
1883 for (source_output
= pa_idxset_first(core
->source_outputs
, &idx
); source_output
; source_output
= pa_idxset_next(core
->source_outputs
, &idx
))
1884 pa_hashmap_put(c
->record_streams
, PA_UINT32_TO_PTR(idx
), pa_dbusiface_stream_new_record(source_output
, OBJECT_PATH
));
1886 for (sample
= pa_idxset_first(core
->scache
, &idx
); sample
; sample
= pa_idxset_next(core
->scache
, &idx
))
1887 pa_hashmap_put(c
->samples
, PA_UINT32_TO_PTR(idx
), pa_dbusiface_sample_new(sample
, OBJECT_PATH
));
1889 for (module
= pa_idxset_first(core
->modules
, &idx
); module
; module
= pa_idxset_next(core
->modules
, &idx
))
1890 pa_hashmap_put(c
->modules
, PA_UINT32_TO_PTR(idx
), pa_dbusiface_module_new(module
, OBJECT_PATH
));
1892 for (client
= pa_idxset_first(core
->clients
, &idx
); client
; client
= pa_idxset_next(core
->clients
, &idx
))
1893 pa_hashmap_put(c
->clients
, PA_UINT32_TO_PTR(idx
), pa_dbusiface_client_new(client
, OBJECT_PATH
));
1895 pa_dbus_protocol_add_interface(c
->dbus_protocol
, OBJECT_PATH
, &core_interface_info
, c
);
1900 static void free_card_cb(void *p
, void *userdata
) {
1901 pa_dbusiface_card
*c
= p
;
1905 pa_dbusiface_card_free(c
);
1908 static void free_device_cb(void *p
, void *userdata
) {
1909 pa_dbusiface_device
*d
= p
;
1913 pa_dbusiface_device_free(d
);
1916 static void free_stream_cb(void *p
, void *userdata
) {
1917 pa_dbusiface_stream
*s
= p
;
1921 pa_dbusiface_stream_free(s
);
1924 static void free_sample_cb(void *p
, void *userdata
) {
1925 pa_dbusiface_sample
*s
= p
;
1929 pa_dbusiface_sample_free(s
);
1932 static void free_module_cb(void *p
, void *userdata
) {
1933 pa_dbusiface_module
*m
= p
;
1937 pa_dbusiface_module_free(m
);
1940 static void free_client_cb(void *p
, void *userdata
) {
1941 pa_dbusiface_client
*c
= p
;
1945 pa_dbusiface_client_free(c
);
1948 void pa_dbusiface_core_free(pa_dbusiface_core
*c
) {
1951 pa_dbus_protocol_remove_interface(c
->dbus_protocol
, OBJECT_PATH
, INTERFACE_CORE
);
1953 pa_subscription_free(c
->subscription
);
1954 pa_hashmap_free(c
->cards
, free_card_cb
, NULL
);
1955 pa_hashmap_free(c
->sinks_by_index
, free_device_cb
, NULL
);
1956 pa_hashmap_free(c
->sinks_by_path
, NULL
, NULL
);
1957 pa_hashmap_free(c
->sources_by_index
, free_device_cb
, NULL
);
1958 pa_hashmap_free(c
->sources_by_path
, NULL
, NULL
);
1959 pa_hashmap_free(c
->playback_streams
, free_stream_cb
, NULL
);
1960 pa_hashmap_free(c
->record_streams
, free_stream_cb
, NULL
);
1961 pa_hashmap_free(c
->samples
, free_sample_cb
, NULL
);
1962 pa_hashmap_free(c
->modules
, free_module_cb
, NULL
);
1963 pa_hashmap_free(c
->clients
, free_client_cb
, NULL
);
1965 pa_dbus_protocol_unref(c
->dbus_protocol
);