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
= load_module_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 dbus_uint32_t
*default_channels
;
435 pa_channel_map_init(&new_channel_map
);
437 if (pa_dbus_get_fixed_array_set_property_arg(conn
, msg
, DBUS_TYPE_UINT32
, &default_channels
, &n_channels
) < 0)
440 if (n_channels
<= 0) {
441 pa_dbus_send_error(conn
, msg
, DBUS_ERROR_INVALID_ARGS
, "Empty channel array.");
445 if (n_channels
> PA_CHANNELS_MAX
) {
446 pa_dbus_send_error(conn
, msg
, DBUS_ERROR_INVALID_ARGS
, "Too many channels: %u. The maximum number of channels is %u.", n_channels
, PA_CHANNELS_MAX
);
450 new_channel_map
.channels
= n_channels
;
452 for (i
= 0; i
< new_channel_map
.channels
; ++i
) {
453 if (default_channels
[i
] >= PA_CHANNEL_POSITION_MAX
) {
454 pa_dbus_send_error(conn
, msg
, DBUS_ERROR_INVALID_ARGS
, "Invalid channel position: %u.", default_channels
[i
]);
458 new_channel_map
.map
[i
] = default_channels
[i
];
461 c
->core
->default_channel_map
= new_channel_map
;
462 c
->core
->default_sample_spec
.channels
= n_channels
;
464 pa_dbus_send_empty_reply(conn
, msg
);
467 static void handle_get_default_sample_format(DBusConnection
*conn
, DBusMessage
*msg
, void *userdata
) {
468 pa_dbusiface_core
*c
= userdata
;
469 dbus_uint32_t default_sample_format
;
475 default_sample_format
= c
->core
->default_sample_spec
.format
;
477 pa_dbus_send_basic_variant_reply(conn
, msg
, DBUS_TYPE_UINT32
, &default_sample_format
);
480 static void handle_set_default_sample_format(DBusConnection
*conn
, DBusMessage
*msg
, void *userdata
) {
481 pa_dbusiface_core
*c
= userdata
;
482 dbus_uint32_t default_sample_format
;
488 if (pa_dbus_get_basic_set_property_arg(conn
, msg
, DBUS_TYPE_UINT32
, &default_sample_format
) < 0)
491 if (default_sample_format
>= PA_SAMPLE_MAX
) {
492 pa_dbus_send_error(conn
, msg
, DBUS_ERROR_INVALID_ARGS
, "Invalid sample format.");
496 c
->core
->default_sample_spec
.format
= default_sample_format
;
498 pa_dbus_send_empty_reply(conn
, msg
);
501 static void handle_get_default_sample_rate(DBusConnection
*conn
, DBusMessage
*msg
, void *userdata
) {
502 pa_dbusiface_core
*c
= userdata
;
503 dbus_uint32_t default_sample_rate
;
509 default_sample_rate
= c
->core
->default_sample_spec
.rate
;
511 pa_dbus_send_basic_variant_reply(conn
, msg
, DBUS_TYPE_UINT32
, &default_sample_rate
);
514 static void handle_set_default_sample_rate(DBusConnection
*conn
, DBusMessage
*msg
, void *userdata
) {
515 pa_dbusiface_core
*c
= userdata
;
516 dbus_uint32_t default_sample_rate
;
522 if (pa_dbus_get_basic_set_property_arg(conn
, msg
, DBUS_TYPE_UINT32
, &default_sample_rate
) < 0)
525 if (default_sample_rate
<= 0 || default_sample_rate
> PA_RATE_MAX
) {
526 pa_dbus_send_error(conn
, msg
, DBUS_ERROR_INVALID_ARGS
, "Invalid sample rate.");
530 c
->core
->default_sample_spec
.rate
= default_sample_rate
;
532 pa_dbus_send_empty_reply(conn
, msg
);
535 /* The caller frees the array, but not the strings. */
536 static const char **get_cards(pa_dbusiface_core
*c
, unsigned *n
) {
540 pa_dbusiface_card
*card
;
545 *n
= pa_hashmap_size(c
->cards
);
550 cards
= pa_xnew(const char *, *n
);
552 for (i
= 0, card
= pa_hashmap_iterate(c
->cards
, &state
, NULL
); card
; ++i
, card
= pa_hashmap_iterate(c
->cards
, &state
, NULL
))
553 cards
[i
] = pa_dbusiface_card_get_path(card
);
560 static void handle_get_cards(DBusConnection
*conn
, DBusMessage
*msg
, void *userdata
) {
561 pa_dbusiface_core
*c
= userdata
;
569 cards
= get_cards(c
, &n
);
571 pa_dbus_send_basic_array_variant_reply(conn
, msg
, DBUS_TYPE_OBJECT_PATH
, cards
, n
);
576 /* The caller frees the array, but not the strings. */
577 static const char **get_sinks(pa_dbusiface_core
*c
, unsigned *n
) {
581 pa_dbusiface_device
*sink
;
586 *n
= pa_hashmap_size(c
->sinks_by_index
);
591 sinks
= pa_xnew(const char *, *n
);
593 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
))
594 sinks
[i
] = pa_dbusiface_device_get_path(sink
);
601 static void handle_get_sinks(DBusConnection
*conn
, DBusMessage
*msg
, void *userdata
) {
602 pa_dbusiface_core
*c
= userdata
;
610 sinks
= get_sinks(c
, &n
);
612 pa_dbus_send_basic_array_variant_reply(conn
, msg
, DBUS_TYPE_OBJECT_PATH
, sinks
, n
);
617 static void handle_get_fallback_sink(DBusConnection
*conn
, DBusMessage
*msg
, void *userdata
) {
618 pa_dbusiface_core
*c
= userdata
;
619 pa_dbusiface_device
*fallback_sink
;
620 const char *object_path
;
626 if (!c
->fallback_sink
) {
627 pa_dbus_send_error(conn
, msg
, PA_DBUS_ERROR_NO_SUCH_PROPERTY
, "There are no sinks, and therefore no fallback sink either.");
631 pa_assert_se((fallback_sink
= pa_hashmap_get(c
->sinks_by_index
, PA_UINT32_TO_PTR(c
->fallback_sink
->index
))));
632 object_path
= pa_dbusiface_device_get_path(fallback_sink
);
634 pa_dbus_send_basic_variant_reply(conn
, msg
, DBUS_TYPE_OBJECT_PATH
, &object_path
);
637 static void handle_set_fallback_sink(DBusConnection
*conn
, DBusMessage
*msg
, void *userdata
) {
638 pa_dbusiface_core
*c
= userdata
;
639 pa_dbusiface_device
*fallback_sink
;
640 const char *object_path
;
646 if (!c
->fallback_sink
) {
647 pa_dbus_send_error(conn
, msg
, PA_DBUS_ERROR_NO_SUCH_PROPERTY
, "There are no sinks, and therefore no fallback sink either.");
651 if (pa_dbus_get_basic_set_property_arg(conn
, msg
, DBUS_TYPE_OBJECT_PATH
, &object_path
) < 0)
654 if (!(fallback_sink
= pa_hashmap_get(c
->sinks_by_path
, object_path
))) {
655 pa_dbus_send_error(conn
, msg
, PA_DBUS_ERROR_NOT_FOUND
, "No such sink.");
659 pa_namereg_set_default_sink(c
->core
, pa_dbusiface_device_get_sink(fallback_sink
));
661 pa_dbus_send_empty_reply(conn
, msg
);
664 /* The caller frees the array, but not the strings. */
665 static const char **get_sources(pa_dbusiface_core
*c
, unsigned *n
) {
666 const char **sources
;
669 pa_dbusiface_device
*source
;
674 *n
= pa_hashmap_size(c
->sources_by_index
);
679 sources
= pa_xnew(const char *, *n
);
681 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
))
682 sources
[i
] = pa_dbusiface_device_get_path(source
);
689 static void handle_get_sources(DBusConnection
*conn
, DBusMessage
*msg
, void *userdata
) {
690 pa_dbusiface_core
*c
= userdata
;
691 const char **sources
;
698 sources
= get_sources(c
, &n
);
700 pa_dbus_send_basic_array_variant_reply(conn
, msg
, DBUS_TYPE_OBJECT_PATH
, sources
, n
);
705 static void handle_get_fallback_source(DBusConnection
*conn
, DBusMessage
*msg
, void *userdata
) {
706 pa_dbusiface_core
*c
= userdata
;
707 pa_dbusiface_device
*fallback_source
;
708 const char *object_path
;
714 if (!c
->fallback_source
) {
715 pa_dbus_send_error(conn
, msg
, PA_DBUS_ERROR_NO_SUCH_PROPERTY
, "There are no sources, and therefore no fallback source either.");
719 pa_assert_se((fallback_source
= pa_hashmap_get(c
->sources_by_index
, PA_UINT32_TO_PTR(c
->fallback_source
->index
))));
720 object_path
= pa_dbusiface_device_get_path(fallback_source
);
722 pa_dbus_send_basic_variant_reply(conn
, msg
, DBUS_TYPE_OBJECT_PATH
, &object_path
);
725 static void handle_set_fallback_source(DBusConnection
*conn
, DBusMessage
*msg
, void *userdata
) {
726 pa_dbusiface_core
*c
= userdata
;
727 pa_dbusiface_device
*fallback_source
;
728 const char *object_path
;
734 if (!c
->fallback_source
) {
735 pa_dbus_send_error(conn
, msg
, PA_DBUS_ERROR_NO_SUCH_PROPERTY
, "There are no sources, and therefore no fallback source either.");
739 if (pa_dbus_get_basic_set_property_arg(conn
, msg
, DBUS_TYPE_OBJECT_PATH
, &object_path
) < 0)
742 if (!(fallback_source
= pa_hashmap_get(c
->sources_by_path
, object_path
))) {
743 pa_dbus_send_error(conn
, msg
, PA_DBUS_ERROR_NOT_FOUND
, "No such source.");
747 pa_namereg_set_default_source(c
->core
, pa_dbusiface_device_get_source(fallback_source
));
749 pa_dbus_send_empty_reply(conn
, msg
);
752 /* The caller frees the array, but not the strings. */
753 static const char **get_playback_streams(pa_dbusiface_core
*c
, unsigned *n
) {
754 const char **streams
;
757 pa_dbusiface_stream
*stream
;
762 *n
= pa_hashmap_size(c
->playback_streams
);
767 streams
= pa_xnew(const char *, *n
);
769 for (i
= 0, stream
= pa_hashmap_iterate(c
->playback_streams
, &state
, NULL
); stream
; ++i
, stream
= pa_hashmap_iterate(c
->playback_streams
, &state
, NULL
))
770 streams
[i
] = pa_dbusiface_stream_get_path(stream
);
777 static void handle_get_playback_streams(DBusConnection
*conn
, DBusMessage
*msg
, void *userdata
) {
778 pa_dbusiface_core
*c
= userdata
;
779 const char **playback_streams
;
786 playback_streams
= get_playback_streams(c
, &n
);
788 pa_dbus_send_basic_array_variant_reply(conn
, msg
, DBUS_TYPE_OBJECT_PATH
, playback_streams
, n
);
790 pa_xfree(playback_streams
);
793 /* The caller frees the array, but not the strings. */
794 static const char **get_record_streams(pa_dbusiface_core
*c
, unsigned *n
) {
795 const char **streams
;
798 pa_dbusiface_stream
*stream
;
803 *n
= pa_hashmap_size(c
->record_streams
);
808 streams
= pa_xnew(const char *, *n
);
810 for (i
= 0, stream
= pa_hashmap_iterate(c
->record_streams
, &state
, NULL
); stream
; ++i
, stream
= pa_hashmap_iterate(c
->record_streams
, &state
, NULL
))
811 streams
[i
] = pa_dbusiface_stream_get_path(stream
);
818 static void handle_get_record_streams(DBusConnection
*conn
, DBusMessage
*msg
, void *userdata
) {
819 pa_dbusiface_core
*c
= userdata
;
820 const char **record_streams
;
827 record_streams
= get_record_streams(c
, &n
);
829 pa_dbus_send_basic_array_variant_reply(conn
, msg
, DBUS_TYPE_OBJECT_PATH
, record_streams
, n
);
831 pa_xfree(record_streams
);
834 /* The caller frees the array, but not the strings. */
835 static const char **get_samples(pa_dbusiface_core
*c
, unsigned *n
) {
836 const char **samples
;
839 pa_dbusiface_sample
*sample
;
844 *n
= pa_hashmap_size(c
->samples
);
849 samples
= pa_xnew(const char *, *n
);
851 for (i
= 0, sample
= pa_hashmap_iterate(c
->samples
, &state
, NULL
); sample
; ++i
, sample
= pa_hashmap_iterate(c
->samples
, &state
, NULL
))
852 samples
[i
] = pa_dbusiface_sample_get_path(sample
);
859 static void handle_get_samples(DBusConnection
*conn
, DBusMessage
*msg
, void *userdata
) {
860 pa_dbusiface_core
*c
= userdata
;
861 const char **samples
;
868 samples
= get_samples(c
, &n
);
870 pa_dbus_send_basic_array_variant_reply(conn
, msg
, DBUS_TYPE_OBJECT_PATH
, samples
, n
);
875 /* The caller frees the array, but not the strings. */
876 static const char **get_modules(pa_dbusiface_core
*c
, unsigned *n
) {
877 const char **modules
;
880 pa_dbusiface_module
*module
;
885 *n
= pa_hashmap_size(c
->modules
);
890 modules
= pa_xnew(const char *, *n
);
892 for (i
= 0, module
= pa_hashmap_iterate(c
->modules
, &state
, NULL
); module
; ++i
, module
= pa_hashmap_iterate(c
->modules
, &state
, NULL
))
893 modules
[i
] = pa_dbusiface_module_get_path(module
);
900 static void handle_get_modules(DBusConnection
*conn
, DBusMessage
*msg
, void *userdata
) {
901 pa_dbusiface_core
*c
= userdata
;
902 const char **modules
;
909 modules
= get_modules(c
, &n
);
911 pa_dbus_send_basic_array_variant_reply(conn
, msg
, DBUS_TYPE_OBJECT_PATH
, modules
, n
);
916 /* The caller frees the array, but not the strings. */
917 static const char **get_clients(pa_dbusiface_core
*c
, unsigned *n
) {
918 const char **clients
;
921 pa_dbusiface_client
*client
;
926 *n
= pa_hashmap_size(c
->clients
);
931 clients
= pa_xnew(const char *, *n
);
933 for (i
= 0, client
= pa_hashmap_iterate(c
->clients
, &state
, NULL
); client
; ++i
, client
= pa_hashmap_iterate(c
->clients
, &state
, NULL
))
934 clients
[i
] = pa_dbusiface_client_get_path(client
);
941 static void handle_get_clients(DBusConnection
*conn
, DBusMessage
*msg
, void *userdata
) {
942 pa_dbusiface_core
*c
= userdata
;
943 const char **clients
;
950 clients
= get_clients(c
, &n
);
952 pa_dbus_send_basic_array_variant_reply(conn
, msg
, DBUS_TYPE_OBJECT_PATH
, clients
, n
);
957 static const char *get_my_client(pa_dbusiface_core
*c
, DBusConnection
*conn
) {
958 pa_client
*my_client
;
963 pa_assert_se((my_client
= pa_dbus_protocol_get_client(c
->dbus_protocol
, conn
)));
965 return pa_dbusiface_client_get_path(pa_hashmap_get(c
->clients
, PA_UINT32_TO_PTR(my_client
->index
)));
968 static void handle_get_my_client(DBusConnection
*conn
, DBusMessage
*msg
, void *userdata
) {
969 pa_dbusiface_core
*c
= userdata
;
970 const char *my_client
;
976 my_client
= get_my_client(c
, conn
);
978 pa_dbus_send_basic_variant_reply(conn
, msg
, DBUS_TYPE_OBJECT_PATH
, &my_client
);
981 static void handle_get_extensions(DBusConnection
*conn
, DBusMessage
*msg
, void *userdata
) {
982 pa_dbusiface_core
*c
= userdata
;
983 const char **extensions
;
990 extensions
= pa_dbus_protocol_get_extensions(c
->dbus_protocol
, &n
);
992 pa_dbus_send_basic_array_variant_reply(conn
, msg
, DBUS_TYPE_STRING
, extensions
, n
);
994 pa_xfree(extensions
);
997 static void handle_get_all(DBusConnection
*conn
, DBusMessage
*msg
, void *userdata
) {
998 pa_dbusiface_core
*c
= userdata
;
999 DBusMessage
*reply
= NULL
;
1000 DBusMessageIter msg_iter
;
1001 DBusMessageIter dict_iter
;
1002 dbus_uint32_t interface_revision
;
1003 const char *server_name
;
1004 const char *version
;
1005 dbus_bool_t is_local
;
1008 dbus_uint32_t
*default_channels
;
1009 unsigned n_default_channels
;
1010 dbus_uint32_t default_sample_format
;
1011 dbus_uint32_t default_sample_rate
;
1016 const char *fallback_sink
;
1017 const char **sources
;
1019 const char *fallback_source
;
1020 const char **playback_streams
;
1021 unsigned n_playback_streams
;
1022 const char **record_streams
;
1023 unsigned n_record_streams
;
1024 const char **samples
;
1026 const char **modules
;
1028 const char **clients
;
1030 const char *my_client
;
1031 const char **extensions
;
1032 unsigned n_extensions
;
1038 interface_revision
= INTERFACE_REVISION
;
1039 server_name
= PACKAGE_NAME
;
1040 version
= PACKAGE_VERSION
;
1041 is_local
= get_is_local(conn
);
1042 username
= pa_get_user_name_malloc();
1043 hostname
= pa_get_host_name_malloc();
1044 default_channels
= get_default_channels(c
, &n_default_channels
);
1045 default_sample_format
= c
->core
->default_sample_spec
.format
;
1046 default_sample_rate
= c
->core
->default_sample_spec
.rate
;
1047 cards
= get_cards(c
, &n_cards
);
1048 sinks
= get_sinks(c
, &n_sinks
);
1049 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
;
1050 sources
= get_sources(c
, &n_sources
);
1051 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
;
1052 playback_streams
= get_playback_streams(c
, &n_playback_streams
);
1053 record_streams
= get_record_streams(c
, &n_record_streams
);
1054 samples
= get_samples(c
, &n_samples
);
1055 modules
= get_modules(c
, &n_modules
);
1056 clients
= get_clients(c
, &n_clients
);
1057 my_client
= get_my_client(c
, conn
);
1058 extensions
= pa_dbus_protocol_get_extensions(c
->dbus_protocol
, &n_extensions
);
1060 pa_assert_se((reply
= dbus_message_new_method_return(msg
)));
1062 dbus_message_iter_init_append(reply
, &msg_iter
);
1063 pa_assert_se(dbus_message_iter_open_container(&msg_iter
, DBUS_TYPE_ARRAY
, "{sv}", &dict_iter
));
1065 pa_dbus_append_basic_variant_dict_entry(&dict_iter
, property_handlers
[PROPERTY_HANDLER_INTERFACE_REVISION
].property_name
, DBUS_TYPE_UINT32
, &interface_revision
);
1066 pa_dbus_append_basic_variant_dict_entry(&dict_iter
, property_handlers
[PROPERTY_HANDLER_NAME
].property_name
, DBUS_TYPE_STRING
, &server_name
);
1067 pa_dbus_append_basic_variant_dict_entry(&dict_iter
, property_handlers
[PROPERTY_HANDLER_VERSION
].property_name
, DBUS_TYPE_STRING
, &version
);
1068 pa_dbus_append_basic_variant_dict_entry(&dict_iter
, property_handlers
[PROPERTY_HANDLER_IS_LOCAL
].property_name
, DBUS_TYPE_BOOLEAN
, &is_local
);
1069 pa_dbus_append_basic_variant_dict_entry(&dict_iter
, property_handlers
[PROPERTY_HANDLER_USERNAME
].property_name
, DBUS_TYPE_STRING
, &username
);
1070 pa_dbus_append_basic_variant_dict_entry(&dict_iter
, property_handlers
[PROPERTY_HANDLER_HOSTNAME
].property_name
, DBUS_TYPE_STRING
, &hostname
);
1071 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
);
1072 pa_dbus_append_basic_variant_dict_entry(&dict_iter
, property_handlers
[PROPERTY_HANDLER_DEFAULT_SAMPLE_FORMAT
].property_name
, DBUS_TYPE_UINT32
, &default_sample_format
);
1073 pa_dbus_append_basic_variant_dict_entry(&dict_iter
, property_handlers
[PROPERTY_HANDLER_DEFAULT_SAMPLE_RATE
].property_name
, DBUS_TYPE_UINT32
, &default_sample_rate
);
1074 pa_dbus_append_basic_array_variant_dict_entry(&dict_iter
, property_handlers
[PROPERTY_HANDLER_CARDS
].property_name
, DBUS_TYPE_OBJECT_PATH
, cards
, n_cards
);
1075 pa_dbus_append_basic_array_variant_dict_entry(&dict_iter
, property_handlers
[PROPERTY_HANDLER_SINKS
].property_name
, DBUS_TYPE_OBJECT_PATH
, sinks
, n_sinks
);
1078 pa_dbus_append_basic_variant_dict_entry(&dict_iter
, property_handlers
[PROPERTY_HANDLER_FALLBACK_SINK
].property_name
, DBUS_TYPE_OBJECT_PATH
, &fallback_sink
);
1080 pa_dbus_append_basic_array_variant_dict_entry(&dict_iter
, property_handlers
[PROPERTY_HANDLER_SOURCES
].property_name
, DBUS_TYPE_OBJECT_PATH
, sources
, n_sources
);
1082 if (fallback_source
)
1083 pa_dbus_append_basic_variant_dict_entry(&dict_iter
, property_handlers
[PROPERTY_HANDLER_FALLBACK_SOURCE
].property_name
, DBUS_TYPE_OBJECT_PATH
, &fallback_source
);
1085 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
);
1086 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
);
1087 pa_dbus_append_basic_array_variant_dict_entry(&dict_iter
, property_handlers
[PROPERTY_HANDLER_SAMPLES
].property_name
, DBUS_TYPE_OBJECT_PATH
, samples
, n_samples
);
1088 pa_dbus_append_basic_array_variant_dict_entry(&dict_iter
, property_handlers
[PROPERTY_HANDLER_MODULES
].property_name
, DBUS_TYPE_OBJECT_PATH
, modules
, n_modules
);
1089 pa_dbus_append_basic_array_variant_dict_entry(&dict_iter
, property_handlers
[PROPERTY_HANDLER_CLIENTS
].property_name
, DBUS_TYPE_OBJECT_PATH
, clients
, n_clients
);
1090 pa_dbus_append_basic_variant_dict_entry(&dict_iter
, property_handlers
[PROPERTY_HANDLER_MY_CLIENT
].property_name
, DBUS_TYPE_OBJECT_PATH
, &my_client
);
1091 pa_dbus_append_basic_array_variant_dict_entry(&dict_iter
, property_handlers
[PROPERTY_HANDLER_EXTENSIONS
].property_name
, DBUS_TYPE_STRING
, extensions
, n_extensions
);
1093 pa_assert_se(dbus_message_iter_close_container(&msg_iter
, &dict_iter
));
1095 pa_assert_se(dbus_connection_send(conn
, reply
, NULL
));
1097 dbus_message_unref(reply
);
1101 pa_xfree(default_channels
);
1105 pa_xfree(playback_streams
);
1106 pa_xfree(record_streams
);
1110 pa_xfree(extensions
);
1113 static void handle_get_card_by_name(DBusConnection
*conn
, DBusMessage
*msg
, void *userdata
) {
1114 pa_dbusiface_core
*c
= userdata
;
1117 pa_dbusiface_card
*dbus_card
;
1118 const char *object_path
;
1125 dbus_error_init(&error
);
1127 if (!dbus_message_get_args(msg
, &error
, DBUS_TYPE_STRING
, &card_name
, DBUS_TYPE_INVALID
)) {
1128 pa_dbus_send_error(conn
, msg
, DBUS_ERROR_INVALID_ARGS
, "%s", error
.message
);
1129 dbus_error_free(&error
);
1133 if (!(card
= pa_namereg_get(c
->core
, card_name
, PA_NAMEREG_CARD
))) {
1134 pa_dbus_send_error(conn
, msg
, PA_DBUS_ERROR_NOT_FOUND
, "No such card.");
1138 pa_assert_se((dbus_card
= pa_hashmap_get(c
->cards
, PA_UINT32_TO_PTR(card
->index
))));
1140 object_path
= pa_dbusiface_card_get_path(dbus_card
);
1142 pa_dbus_send_basic_value_reply(conn
, msg
, DBUS_TYPE_OBJECT_PATH
, &object_path
);
1145 static void handle_get_sink_by_name(DBusConnection
*conn
, DBusMessage
*msg
, void *userdata
) {
1146 pa_dbusiface_core
*c
= userdata
;
1149 pa_dbusiface_device
*dbus_sink
;
1150 const char *object_path
;
1157 dbus_error_init(&error
);
1159 if (!dbus_message_get_args(msg
, &error
, DBUS_TYPE_STRING
, &sink_name
, DBUS_TYPE_INVALID
)) {
1160 pa_dbus_send_error(conn
, msg
, DBUS_ERROR_INVALID_ARGS
, "%s", error
.message
);
1161 dbus_error_free(&error
);
1165 if (!(sink
= pa_namereg_get(c
->core
, sink_name
, PA_NAMEREG_SINK
))) {
1166 pa_dbus_send_error(conn
, msg
, PA_DBUS_ERROR_NOT_FOUND
, "No such sink.");
1170 pa_assert_se((dbus_sink
= pa_hashmap_get(c
->sinks_by_index
, PA_UINT32_TO_PTR(sink
->index
))));
1172 object_path
= pa_dbusiface_device_get_path(dbus_sink
);
1174 pa_dbus_send_basic_value_reply(conn
, msg
, DBUS_TYPE_OBJECT_PATH
, &object_path
);
1177 static void handle_get_source_by_name(DBusConnection
*conn
, DBusMessage
*msg
, void *userdata
) {
1178 pa_dbusiface_core
*c
= userdata
;
1181 pa_dbusiface_device
*dbus_source
;
1182 const char *object_path
;
1189 dbus_error_init(&error
);
1191 if (!dbus_message_get_args(msg
, &error
, DBUS_TYPE_STRING
, &source_name
, DBUS_TYPE_INVALID
)) {
1192 pa_dbus_send_error(conn
, msg
, DBUS_ERROR_INVALID_ARGS
, "%s", error
.message
);
1193 dbus_error_free(&error
);
1197 if (!(source
= pa_namereg_get(c
->core
, source_name
, PA_NAMEREG_SOURCE
))) {
1198 pa_dbus_send_error(conn
, msg
, PA_DBUS_ERROR_NOT_FOUND
, "No such source.");
1202 pa_assert_se((dbus_source
= pa_hashmap_get(c
->sources_by_index
, PA_UINT32_TO_PTR(source
->index
))));
1204 object_path
= pa_dbusiface_device_get_path(dbus_source
);
1206 pa_dbus_send_basic_value_reply(conn
, msg
, DBUS_TYPE_OBJECT_PATH
, &object_path
);
1209 static void handle_get_sample_by_name(DBusConnection
*conn
, DBusMessage
*msg
, void *userdata
) {
1210 pa_dbusiface_core
*c
= userdata
;
1212 pa_scache_entry
*sample
;
1213 pa_dbusiface_sample
*dbus_sample
;
1214 const char *object_path
;
1221 dbus_error_init(&error
);
1223 if (!dbus_message_get_args(msg
, &error
, DBUS_TYPE_STRING
, &sample_name
, DBUS_TYPE_INVALID
)) {
1224 pa_dbus_send_error(conn
, msg
, DBUS_ERROR_INVALID_ARGS
, "%s", error
.message
);
1225 dbus_error_free(&error
);
1229 if (!(sample
= pa_namereg_get(c
->core
, sample_name
, PA_NAMEREG_SAMPLE
))) {
1230 pa_dbus_send_error(conn
, msg
, PA_DBUS_ERROR_NOT_FOUND
, "No such sample.");
1234 pa_assert_se((dbus_sample
= pa_hashmap_get(c
->samples
, PA_UINT32_TO_PTR(sample
->index
))));
1236 object_path
= pa_dbusiface_sample_get_path(dbus_sample
);
1238 pa_dbus_send_basic_value_reply(conn
, msg
, DBUS_TYPE_OBJECT_PATH
, &object_path
);
1241 static void handle_upload_sample(DBusConnection
*conn
, DBusMessage
*msg
, void *userdata
) {
1242 pa_dbusiface_core
*c
= userdata
;
1243 DBusMessageIter msg_iter
;
1245 dbus_uint32_t sample_format
;
1246 dbus_uint32_t sample_rate
;
1247 const dbus_uint32_t
*channels
;
1248 unsigned n_channels
;
1249 const dbus_uint32_t
*default_volume
;
1250 unsigned n_volume_entries
;
1251 pa_proplist
*property_list
;
1252 const uint8_t *data
;
1253 unsigned data_length
;
1259 pa_dbusiface_sample
*dbus_sample
= NULL
;
1260 pa_scache_entry
*sample
= NULL
;
1261 const char *object_path
;
1267 chunk
.memblock
= NULL
;
1269 if (!dbus_message_iter_init(msg
, &msg_iter
)) {
1270 pa_dbus_send_error(conn
, msg
, DBUS_ERROR_INVALID_ARGS
, "Too few arguments.");
1274 if (pa_dbus_get_basic_arg(conn
, msg
, &msg_iter
, DBUS_TYPE_STRING
, &name
) < 0)
1277 if (pa_dbus_get_basic_arg(conn
, msg
, &msg_iter
, DBUS_TYPE_UINT32
, &sample_format
) < 0)
1280 if (pa_dbus_get_basic_arg(conn
, msg
, &msg_iter
, DBUS_TYPE_UINT32
, &sample_rate
) < 0)
1283 if (pa_dbus_get_fixed_array_arg(conn
, msg
, &msg_iter
, DBUS_TYPE_UINT32
, &channels
, &n_channels
) < 0)
1286 if (pa_dbus_get_fixed_array_arg(conn
, msg
, &msg_iter
, DBUS_TYPE_UINT32
, &default_volume
, &n_volume_entries
) < 0)
1289 if (!(property_list
= pa_dbus_get_proplist_arg(conn
, msg
, &msg_iter
)))
1292 if (pa_dbus_get_fixed_array_arg(conn
, msg
, &msg_iter
, DBUS_TYPE_BYTE
, &data
, &data_length
) < 0)
1295 if (sample_format
>= PA_SAMPLE_MAX
) {
1296 pa_dbus_send_error(conn
, msg
, DBUS_ERROR_INVALID_ARGS
, "Invalid sample format.");
1300 if (sample_rate
<= 0 || sample_rate
> PA_RATE_MAX
) {
1301 pa_dbus_send_error(conn
, msg
, DBUS_ERROR_INVALID_ARGS
, "Invalid sample rate.");
1305 if (n_channels
== 0) {
1306 pa_dbus_send_error(conn
, msg
, DBUS_ERROR_INVALID_ARGS
, "Empty channel map.");
1310 if (n_channels
> PA_CHANNELS_MAX
) {
1311 pa_dbus_send_error(conn
, msg
, DBUS_ERROR_INVALID_ARGS
, "Too many channels.");
1315 for (i
= 0; i
< n_channels
; ++i
) {
1316 if (channels
[i
] >= PA_CHANNEL_POSITION_MAX
) {
1317 pa_dbus_send_error(conn
, msg
, DBUS_ERROR_INVALID_ARGS
, "Invalid channel position.");
1322 if (n_volume_entries
!= 0 && n_volume_entries
!= n_channels
) {
1323 pa_dbus_send_error(conn
, msg
, DBUS_ERROR_INVALID_ARGS
, "The channels and default_volume arguments have different number of elements.");
1327 for (i
= 0; i
< n_volume_entries
; ++i
) {
1328 if (default_volume
[i
] > PA_VOLUME_MAX
) {
1329 pa_dbus_send_error(conn
, msg
, DBUS_ERROR_INVALID_ARGS
, "Invalid volume.");
1334 if (data_length
== 0) {
1335 pa_dbus_send_error(conn
, msg
, DBUS_ERROR_INVALID_ARGS
, "Empty data.");
1339 if (data_length
> PA_SCACHE_ENTRY_SIZE_MAX
) {
1340 pa_dbus_send_error(conn
, msg
, DBUS_ERROR_INVALID_ARGS
, "Too big sample.");
1344 ss
.format
= sample_format
;
1345 ss
.rate
= sample_rate
;
1346 ss
.channels
= n_channels
;
1348 if (!pa_frame_aligned(data_length
, &ss
)) {
1349 pa_dbus_send_error(conn
, msg
, DBUS_ERROR_INVALID_ARGS
, "The sample length in bytes doesn't align with the sample format and channels.");
1353 map
.channels
= n_channels
;
1354 for (i
= 0; i
< n_channels
; ++i
)
1355 map
.map
[i
] = channels
[i
];
1357 chunk
.memblock
= pa_memblock_new(c
->core
->mempool
, data_length
);
1359 chunk
.length
= data_length
;
1361 memcpy(pa_memblock_acquire(chunk
.memblock
), data
, data_length
);
1362 pa_memblock_release(chunk
.memblock
);
1364 if (pa_scache_add_item(c
->core
, name
, &ss
, &map
, &chunk
, property_list
, &idx
) < 0) {
1365 pa_dbus_send_error(conn
, msg
, DBUS_ERROR_FAILED
, "Adding the sample failed.");
1369 sample
= pa_idxset_get_by_index(c
->core
->scache
, idx
);
1371 if (n_volume_entries
> 0) {
1372 sample
->volume
.channels
= n_channels
;
1373 for (i
= 0; i
< n_volume_entries
; ++i
)
1374 sample
->volume
.values
[i
] = default_volume
[i
];
1375 sample
->volume_is_set
= TRUE
;
1377 sample
->volume_is_set
= FALSE
;
1380 dbus_sample
= pa_dbusiface_sample_new(sample
, OBJECT_PATH
);
1381 pa_hashmap_put(c
->samples
, PA_UINT32_TO_PTR(idx
), dbus_sample
);
1383 object_path
= pa_dbusiface_sample_get_path(dbus_sample
);
1385 pa_dbus_send_basic_value_reply(conn
, msg
, DBUS_TYPE_OBJECT_PATH
, &object_path
);
1389 pa_proplist_free(property_list
);
1392 pa_memblock_unref(chunk
.memblock
);
1395 static pa_bool_t
contains_space(const char *string
) {
1400 for (p
= string
; *p
; ++p
) {
1408 static void handle_load_module(DBusConnection
*conn
, DBusMessage
*msg
, void *userdata
) {
1409 pa_dbusiface_core
*c
= userdata
;
1410 DBusMessageIter msg_iter
;
1411 DBusMessageIter dict_iter
;
1412 DBusMessageIter dict_entry_iter
;
1416 char *escaped_value
;
1417 pa_strbuf
*arg_buffer
= NULL
;
1419 pa_dbusiface_module
*dbus_module
;
1420 const char *object_path
;
1427 if (c
->core
->disallow_module_loading
) {
1428 pa_dbus_send_error(conn
, msg
, DBUS_ERROR_ACCESS_DENIED
, "The server is configured to disallow module loading.");
1432 if (!dbus_message_iter_init(msg
, &msg_iter
)) {
1433 pa_dbus_send_error(conn
, msg
, DBUS_ERROR_INVALID_ARGS
, "Too few arguments.");
1437 if (pa_dbus_get_basic_arg(conn
, msg
, &msg_iter
, DBUS_TYPE_STRING
, &name
) < 0)
1440 arg_type
= dbus_message_iter_get_arg_type(&msg_iter
);
1441 if (arg_type
!= DBUS_TYPE_ARRAY
) {
1442 if (arg_type
== DBUS_TYPE_INVALID
)
1443 pa_dbus_send_error(conn
, msg
, DBUS_ERROR_INVALID_ARGS
, "Too few arguments. A dictionary from strings to strings was expected.");
1445 pa_dbus_send_error(conn
, msg
, DBUS_ERROR_INVALID_ARGS
, "Wrong argument type: '%c'. An dictionary from strings to strings was expected.", (char) arg_type
);
1449 arg_type
= dbus_message_iter_get_element_type(&msg_iter
);
1450 if (arg_type
!= DBUS_TYPE_DICT_ENTRY
) {
1451 pa_dbus_send_error(conn
, msg
, DBUS_ERROR_INVALID_ARGS
, "Wrong array element type: '%c'. A dict entry (string to string) was expected.", (char) arg_type
);
1455 arg_buffer
= pa_strbuf_new();
1457 dbus_message_iter_recurse(&msg_iter
, &dict_iter
);
1459 while (dbus_message_iter_get_arg_type(&dict_iter
) != DBUS_TYPE_INVALID
) {
1460 if (!pa_strbuf_isempty(arg_buffer
))
1461 pa_strbuf_putc(arg_buffer
, ' ');
1463 dbus_message_iter_recurse(&dict_iter
, &dict_entry_iter
);
1465 arg_type
= dbus_message_iter_get_arg_type(&dict_entry_iter
);
1466 if (arg_type
!= DBUS_TYPE_STRING
) {
1467 pa_dbus_send_error(conn
, msg
, DBUS_ERROR_INVALID_ARGS
, "Wrong dict key type: '%c'. A string was expected.", (char) arg_type
);
1471 dbus_message_iter_get_basic(&dict_entry_iter
, &key
);
1472 dbus_message_iter_next(&dict_entry_iter
);
1474 if (strlen(key
) <= 0 || !pa_ascii_valid(key
) || contains_space(key
)) {
1475 pa_dbus_send_error(conn
, msg
, DBUS_ERROR_INVALID_ARGS
, "Invalid module argument name: %s", key
);
1479 arg_type
= dbus_message_iter_get_arg_type(&dict_entry_iter
);
1480 if (arg_type
!= DBUS_TYPE_STRING
) {
1481 if (arg_type
== DBUS_TYPE_INVALID
)
1482 pa_dbus_send_error(conn
, msg
, DBUS_ERROR_INVALID_ARGS
, "Dict value missing.");
1484 pa_dbus_send_error(conn
, msg
, DBUS_ERROR_INVALID_ARGS
, "Wrong dict value type: '%c'. A string was expected.", (char) arg_type
);
1488 dbus_message_iter_get_basic(&dict_entry_iter
, &value
);
1490 dbus_message_iter_next(&dict_iter
);
1492 escaped_value
= pa_escape(value
, "\"");
1493 pa_strbuf_printf(arg_buffer
, "%s=\"%s\"", key
, escaped_value
);
1494 pa_xfree(escaped_value
);
1497 if (!(module
= pa_module_load(c
->core
, name
, pa_strbuf_tostring(arg_buffer
)))) {
1498 pa_dbus_send_error(conn
, msg
, DBUS_ERROR_FAILED
, "Failed to load module.");
1502 dbus_module
= pa_dbusiface_module_new(module
, OBJECT_PATH
);
1503 pa_hashmap_put(c
->modules
, PA_UINT32_TO_PTR(module
->index
), dbus_module
);
1505 object_path
= pa_dbusiface_module_get_path(dbus_module
);
1507 pa_dbus_send_basic_value_reply(conn
, msg
, DBUS_TYPE_OBJECT_PATH
, &object_path
);
1511 pa_strbuf_free(arg_buffer
);
1514 static void handle_exit(DBusConnection
*conn
, DBusMessage
*msg
, void *userdata
) {
1515 pa_dbusiface_core
*c
= userdata
;
1521 if (c
->core
->disallow_exit
) {
1522 pa_dbus_send_error(conn
, msg
, DBUS_ERROR_ACCESS_DENIED
, "The server is configured to disallow exiting.");
1526 pa_dbus_send_empty_reply(conn
, msg
);
1528 pa_core_exit(c
->core
, FALSE
, 0);
1531 static void handle_listen_for_signal(DBusConnection
*conn
, DBusMessage
*msg
, void *userdata
) {
1532 pa_dbusiface_core
*c
= userdata
;
1534 char **objects
= NULL
;
1542 dbus_error_init(&error
);
1544 if (!dbus_message_get_args(msg
, &error
, DBUS_TYPE_STRING
, &signal
, DBUS_TYPE_ARRAY
, DBUS_TYPE_OBJECT_PATH
, &objects
, &n_objects
, DBUS_TYPE_INVALID
)) {
1545 pa_dbus_send_error(conn
, msg
, DBUS_ERROR_INVALID_ARGS
, "%s", error
.message
);
1546 dbus_error_free(&error
);
1550 pa_dbus_protocol_add_signal_listener(c
->dbus_protocol
, conn
, *signal
? signal
: NULL
, objects
, n_objects
);
1552 pa_dbus_send_empty_reply(conn
, msg
);
1555 dbus_free_string_array(objects
);
1558 static void handle_stop_listening_for_signal(DBusConnection
*conn
, DBusMessage
*msg
, void *userdata
) {
1559 pa_dbusiface_core
*c
= userdata
;
1567 dbus_error_init(&error
);
1569 if (!dbus_message_get_args(msg
, &error
, DBUS_TYPE_STRING
, &signal
, DBUS_TYPE_INVALID
)) {
1570 pa_dbus_send_error(conn
, msg
, DBUS_ERROR_INVALID_ARGS
, "%s", error
.message
);
1571 dbus_error_free(&error
);
1575 pa_dbus_protocol_remove_signal_listener(c
->dbus_protocol
, conn
, *signal
? signal
: NULL
);
1577 pa_dbus_send_empty_reply(conn
, msg
);
1580 static void subscription_cb(pa_core
*core
, pa_subscription_event_type_t t
, uint32_t idx
, void *userdata
) {
1581 pa_dbusiface_core
*c
= userdata
;
1582 pa_dbusiface_card
*card
= NULL
;
1583 pa_dbusiface_device
*device
= NULL
;
1584 pa_dbusiface_stream
*stream
= NULL
;
1585 pa_dbusiface_sample
*sample
= NULL
;
1586 pa_dbusiface_module
*module
= NULL
;
1587 pa_dbusiface_client
*client
= NULL
;
1588 DBusMessage
*signal
= NULL
;
1589 const char *object_path
= NULL
;
1590 pa_sink
*new_fallback_sink
= NULL
;
1591 pa_source
*new_fallback_source
= NULL
;
1595 switch (t
& PA_SUBSCRIPTION_EVENT_FACILITY_MASK
) {
1596 case PA_SUBSCRIPTION_EVENT_SERVER
:
1597 new_fallback_sink
= pa_namereg_get_default_sink(core
);
1598 new_fallback_source
= pa_namereg_get_default_source(core
);
1600 if (c
->fallback_sink
!= new_fallback_sink
) {
1601 c
->fallback_sink
= new_fallback_sink
;
1603 if (new_fallback_sink
) {
1604 pa_assert_se((device
= pa_hashmap_get(c
->sinks_by_index
, PA_UINT32_TO_PTR(new_fallback_sink
->index
))));
1606 object_path
= pa_dbusiface_device_get_path(device
);
1608 pa_assert_se((signal
= dbus_message_new_signal(OBJECT_PATH
, INTERFACE_CORE
, signals
[SIGNAL_FALLBACK_SINK_UPDATED
].name
)));
1609 pa_assert_se(dbus_message_append_args(signal
, DBUS_TYPE_OBJECT_PATH
, &object_path
, DBUS_TYPE_INVALID
));
1610 pa_dbus_protocol_send_signal(c
->dbus_protocol
, signal
);
1611 dbus_message_unref(signal
);
1616 if (c
->fallback_source
!= new_fallback_source
) {
1617 c
->fallback_source
= new_fallback_source
;
1619 if (new_fallback_source
) {
1620 pa_assert_se((device
= pa_hashmap_get(c
->sources_by_index
, PA_UINT32_TO_PTR(new_fallback_source
->index
))));
1622 object_path
= pa_dbusiface_device_get_path(device
);
1624 pa_assert_se((signal
= dbus_message_new_signal(OBJECT_PATH
, INTERFACE_CORE
, signals
[SIGNAL_FALLBACK_SOURCE_UPDATED
].name
)));
1625 pa_assert_se(dbus_message_append_args(signal
, DBUS_TYPE_OBJECT_PATH
, &object_path
, DBUS_TYPE_INVALID
));
1626 pa_dbus_protocol_send_signal(c
->dbus_protocol
, signal
);
1627 dbus_message_unref(signal
);
1633 case PA_SUBSCRIPTION_EVENT_CARD
:
1634 if ((t
& PA_SUBSCRIPTION_EVENT_TYPE_MASK
) == PA_SUBSCRIPTION_EVENT_NEW
) {
1635 card
= pa_dbusiface_card_new(pa_idxset_get_by_index(core
->cards
, idx
), OBJECT_PATH
);
1636 pa_hashmap_put(c
->cards
, PA_UINT32_TO_PTR(idx
), card
);
1638 object_path
= pa_dbusiface_card_get_path(card
);
1640 pa_assert_se((signal
= dbus_message_new_signal(OBJECT_PATH
, INTERFACE_CORE
, signals
[SIGNAL_NEW_CARD
].name
)));
1641 pa_assert_se(dbus_message_append_args(signal
, DBUS_TYPE_OBJECT_PATH
, &object_path
, DBUS_TYPE_INVALID
));
1643 } else if ((t
& PA_SUBSCRIPTION_EVENT_TYPE_MASK
) == PA_SUBSCRIPTION_EVENT_REMOVE
) {
1644 pa_assert_se((card
= pa_hashmap_remove(c
->cards
, PA_UINT32_TO_PTR(idx
))));
1646 object_path
= pa_dbusiface_card_get_path(card
);
1648 pa_assert_se((signal
= dbus_message_new_signal(OBJECT_PATH
, INTERFACE_CORE
, signals
[SIGNAL_CARD_REMOVED
].name
)));
1649 pa_assert_se(dbus_message_append_args(signal
, DBUS_TYPE_OBJECT_PATH
, &object_path
, DBUS_TYPE_INVALID
));
1651 pa_dbusiface_card_free(card
);
1655 case PA_SUBSCRIPTION_EVENT_SINK
:
1656 if ((t
& PA_SUBSCRIPTION_EVENT_TYPE_MASK
) == PA_SUBSCRIPTION_EVENT_NEW
) {
1657 device
= pa_dbusiface_device_new_sink(pa_idxset_get_by_index(core
->sinks
, idx
), OBJECT_PATH
);
1658 object_path
= pa_dbusiface_device_get_path(device
);
1660 pa_hashmap_put(c
->sinks_by_index
, PA_UINT32_TO_PTR(idx
), device
);
1661 pa_hashmap_put(c
->sinks_by_path
, object_path
, device
);
1663 pa_assert_se((signal
= dbus_message_new_signal(OBJECT_PATH
, INTERFACE_CORE
, signals
[SIGNAL_NEW_SINK
].name
)));
1664 pa_assert_se(dbus_message_append_args(signal
, DBUS_TYPE_OBJECT_PATH
, &object_path
, DBUS_TYPE_INVALID
));
1666 } else if ((t
& PA_SUBSCRIPTION_EVENT_TYPE_MASK
) == PA_SUBSCRIPTION_EVENT_REMOVE
) {
1667 pa_assert_se((device
= pa_hashmap_remove(c
->sinks_by_index
, PA_UINT32_TO_PTR(idx
))));
1668 object_path
= pa_dbusiface_device_get_path(device
);
1669 pa_assert_se(pa_hashmap_remove(c
->sinks_by_path
, object_path
));
1671 pa_assert_se((signal
= dbus_message_new_signal(OBJECT_PATH
, INTERFACE_CORE
, signals
[SIGNAL_SINK_REMOVED
].name
)));
1672 pa_assert_se(dbus_message_append_args(signal
, DBUS_TYPE_OBJECT_PATH
, &object_path
, DBUS_TYPE_INVALID
));
1674 pa_dbusiface_device_free(device
);
1678 case PA_SUBSCRIPTION_EVENT_SOURCE
:
1679 if ((t
& PA_SUBSCRIPTION_EVENT_TYPE_MASK
) == PA_SUBSCRIPTION_EVENT_NEW
) {
1680 device
= pa_dbusiface_device_new_source(pa_idxset_get_by_index(core
->sources
, idx
), OBJECT_PATH
);
1681 object_path
= pa_dbusiface_device_get_path(device
);
1683 pa_hashmap_put(c
->sources_by_index
, PA_UINT32_TO_PTR(idx
), device
);
1684 pa_hashmap_put(c
->sources_by_path
, object_path
, device
);
1686 pa_assert_se((signal
= dbus_message_new_signal(OBJECT_PATH
, INTERFACE_CORE
, signals
[SIGNAL_NEW_SOURCE
].name
)));
1687 pa_assert_se(dbus_message_append_args(signal
, DBUS_TYPE_OBJECT_PATH
, &object_path
, DBUS_TYPE_INVALID
));
1689 } else if ((t
& PA_SUBSCRIPTION_EVENT_TYPE_MASK
) == PA_SUBSCRIPTION_EVENT_REMOVE
) {
1690 pa_assert_se((device
= pa_hashmap_remove(c
->sources_by_index
, PA_UINT32_TO_PTR(idx
))));
1691 object_path
= pa_dbusiface_device_get_path(device
);
1692 pa_assert_se(pa_hashmap_remove(c
->sources_by_path
, object_path
));
1694 pa_assert_se((signal
= dbus_message_new_signal(OBJECT_PATH
, INTERFACE_CORE
, signals
[SIGNAL_SOURCE_REMOVED
].name
)));
1695 pa_assert_se(dbus_message_append_args(signal
, DBUS_TYPE_OBJECT_PATH
, &object_path
, DBUS_TYPE_INVALID
));
1697 pa_dbusiface_device_free(device
);
1701 case PA_SUBSCRIPTION_EVENT_SINK_INPUT
:
1702 if ((t
& PA_SUBSCRIPTION_EVENT_TYPE_MASK
) == PA_SUBSCRIPTION_EVENT_NEW
) {
1703 stream
= pa_dbusiface_stream_new_playback(pa_idxset_get_by_index(core
->sink_inputs
, idx
), OBJECT_PATH
);
1704 pa_hashmap_put(c
->playback_streams
, PA_UINT32_TO_PTR(idx
), stream
);
1706 object_path
= pa_dbusiface_stream_get_path(stream
);
1708 pa_assert_se((signal
= dbus_message_new_signal(OBJECT_PATH
, INTERFACE_CORE
, signals
[SIGNAL_NEW_PLAYBACK_STREAM
].name
)));
1709 pa_assert_se(dbus_message_append_args(signal
, DBUS_TYPE_OBJECT_PATH
, &object_path
, DBUS_TYPE_INVALID
));
1711 } else if ((t
& PA_SUBSCRIPTION_EVENT_TYPE_MASK
) == PA_SUBSCRIPTION_EVENT_REMOVE
) {
1712 pa_assert_se((stream
= pa_hashmap_remove(c
->playback_streams
, PA_UINT32_TO_PTR(idx
))));
1714 object_path
= pa_dbusiface_stream_get_path(stream
);
1716 pa_assert_se((signal
= dbus_message_new_signal(OBJECT_PATH
, INTERFACE_CORE
, signals
[SIGNAL_PLAYBACK_STREAM_REMOVED
].name
)));
1717 pa_assert_se(dbus_message_append_args(signal
, DBUS_TYPE_OBJECT_PATH
, &object_path
, DBUS_TYPE_INVALID
));
1719 pa_dbusiface_stream_free(stream
);
1723 case PA_SUBSCRIPTION_EVENT_SOURCE_OUTPUT
:
1724 if ((t
& PA_SUBSCRIPTION_EVENT_TYPE_MASK
) == PA_SUBSCRIPTION_EVENT_NEW
) {
1725 stream
= pa_dbusiface_stream_new_record(pa_idxset_get_by_index(core
->source_outputs
, idx
), OBJECT_PATH
);
1726 pa_hashmap_put(c
->record_streams
, PA_UINT32_TO_PTR(idx
), stream
);
1728 object_path
= pa_dbusiface_stream_get_path(stream
);
1730 pa_assert_se((signal
= dbus_message_new_signal(OBJECT_PATH
, INTERFACE_CORE
, signals
[SIGNAL_NEW_RECORD_STREAM
].name
)));
1731 pa_assert_se(dbus_message_append_args(signal
, DBUS_TYPE_OBJECT_PATH
, &object_path
, DBUS_TYPE_INVALID
));
1733 } else if ((t
& PA_SUBSCRIPTION_EVENT_TYPE_MASK
) == PA_SUBSCRIPTION_EVENT_REMOVE
) {
1734 pa_assert_se((stream
= pa_hashmap_remove(c
->record_streams
, PA_UINT32_TO_PTR(idx
))));
1736 object_path
= pa_dbusiface_stream_get_path(stream
);
1738 pa_assert_se((signal
= dbus_message_new_signal(OBJECT_PATH
, INTERFACE_CORE
, signals
[SIGNAL_RECORD_STREAM_REMOVED
].name
)));
1739 pa_assert_se(dbus_message_append_args(signal
, DBUS_TYPE_OBJECT_PATH
, &object_path
, DBUS_TYPE_INVALID
));
1741 pa_dbusiface_stream_free(stream
);
1745 case PA_SUBSCRIPTION_EVENT_SAMPLE_CACHE
:
1746 if ((t
& PA_SUBSCRIPTION_EVENT_TYPE_MASK
) == PA_SUBSCRIPTION_EVENT_NEW
) {
1747 /* We may have created the pa_dbusiface_sample object already
1748 * in handle_upload_sample. */
1749 if (!(sample
= pa_hashmap_get(c
->samples
, PA_UINT32_TO_PTR(idx
)))) {
1750 sample
= pa_dbusiface_sample_new(pa_idxset_get_by_index(core
->scache
, idx
), OBJECT_PATH
);
1751 pa_hashmap_put(c
->samples
, PA_UINT32_TO_PTR(idx
), sample
);
1754 object_path
= pa_dbusiface_sample_get_path(sample
);
1756 pa_assert_se((signal
= dbus_message_new_signal(OBJECT_PATH
, INTERFACE_CORE
, signals
[SIGNAL_NEW_SAMPLE
].name
)));
1757 pa_assert_se(dbus_message_append_args(signal
, DBUS_TYPE_OBJECT_PATH
, &object_path
, DBUS_TYPE_INVALID
));
1759 } else if ((t
& PA_SUBSCRIPTION_EVENT_TYPE_MASK
) == PA_SUBSCRIPTION_EVENT_REMOVE
) {
1760 pa_assert_se((sample
= pa_hashmap_remove(c
->samples
, PA_UINT32_TO_PTR(idx
))));
1762 object_path
= pa_dbusiface_sample_get_path(sample
);
1764 pa_assert_se((signal
= dbus_message_new_signal(OBJECT_PATH
, INTERFACE_CORE
, signals
[SIGNAL_SAMPLE_REMOVED
].name
)));
1765 pa_assert_se(dbus_message_append_args(signal
, DBUS_TYPE_OBJECT_PATH
, &object_path
, DBUS_TYPE_INVALID
));
1767 pa_dbusiface_sample_free(sample
);
1771 case PA_SUBSCRIPTION_EVENT_MODULE
:
1772 if ((t
& PA_SUBSCRIPTION_EVENT_TYPE_MASK
) == PA_SUBSCRIPTION_EVENT_NEW
) {
1773 /* We may have created the pa_dbusiface_module object already
1774 * in handle_load_module. */
1775 if (!(module
= pa_hashmap_get(c
->modules
, PA_UINT32_TO_PTR(idx
)))) {
1776 module
= pa_dbusiface_module_new(pa_idxset_get_by_index(core
->modules
, idx
), OBJECT_PATH
);
1777 pa_hashmap_put(c
->modules
, PA_UINT32_TO_PTR(idx
), module
);
1780 object_path
= pa_dbusiface_module_get_path(module
);
1782 pa_assert_se((signal
= dbus_message_new_signal(OBJECT_PATH
, INTERFACE_CORE
, signals
[SIGNAL_NEW_MODULE
].name
)));
1783 pa_assert_se(dbus_message_append_args(signal
, DBUS_TYPE_OBJECT_PATH
, &object_path
, DBUS_TYPE_INVALID
));
1785 } else if ((t
& PA_SUBSCRIPTION_EVENT_TYPE_MASK
) == PA_SUBSCRIPTION_EVENT_REMOVE
) {
1786 pa_assert_se((module
= pa_hashmap_remove(c
->modules
, PA_UINT32_TO_PTR(idx
))));
1788 object_path
= pa_dbusiface_module_get_path(module
);
1790 pa_assert_se((signal
= dbus_message_new_signal(OBJECT_PATH
, INTERFACE_CORE
, signals
[SIGNAL_MODULE_REMOVED
].name
)));
1791 pa_assert_se(dbus_message_append_args(signal
, DBUS_TYPE_OBJECT_PATH
, &object_path
, DBUS_TYPE_INVALID
));
1793 pa_dbusiface_module_free(module
);
1797 case PA_SUBSCRIPTION_EVENT_CLIENT
:
1798 if ((t
& PA_SUBSCRIPTION_EVENT_TYPE_MASK
) == PA_SUBSCRIPTION_EVENT_NEW
) {
1799 client
= pa_dbusiface_client_new(pa_idxset_get_by_index(core
->clients
, idx
), OBJECT_PATH
);
1800 pa_hashmap_put(c
->clients
, PA_UINT32_TO_PTR(idx
), client
);
1802 object_path
= pa_dbusiface_client_get_path(client
);
1804 pa_assert_se((signal
= dbus_message_new_signal(OBJECT_PATH
, INTERFACE_CORE
, signals
[SIGNAL_NEW_CLIENT
].name
)));
1805 pa_assert_se(dbus_message_append_args(signal
, DBUS_TYPE_OBJECT_PATH
, &object_path
, DBUS_TYPE_INVALID
));
1807 } else if ((t
& PA_SUBSCRIPTION_EVENT_TYPE_MASK
) == PA_SUBSCRIPTION_EVENT_REMOVE
) {
1808 pa_assert_se((client
= pa_hashmap_remove(c
->clients
, PA_UINT32_TO_PTR(idx
))));
1810 object_path
= pa_dbusiface_client_get_path(client
);
1812 pa_assert_se((signal
= dbus_message_new_signal(OBJECT_PATH
, INTERFACE_CORE
, signals
[SIGNAL_CLIENT_REMOVED
].name
)));
1813 pa_assert_se(dbus_message_append_args(signal
, DBUS_TYPE_OBJECT_PATH
, &object_path
, DBUS_TYPE_INVALID
));
1815 pa_dbusiface_client_free(client
);
1821 pa_dbus_protocol_send_signal(c
->dbus_protocol
, signal
);
1822 dbus_message_unref(signal
);
1826 pa_dbusiface_core
*pa_dbusiface_core_new(pa_core
*core
) {
1827 pa_dbusiface_core
*c
;
1831 pa_dbusiface_device
*device
;
1832 pa_sink_input
*sink_input
;
1833 pa_source_output
*source_output
;
1834 pa_scache_entry
*sample
;
1841 c
= pa_xnew(pa_dbusiface_core
, 1);
1843 c
->subscription
= pa_subscription_new(core
, PA_SUBSCRIPTION_MASK_ALL
, subscription_cb
, c
);
1844 c
->dbus_protocol
= pa_dbus_protocol_get(core
);
1845 c
->cards
= pa_hashmap_new(pa_idxset_trivial_hash_func
, pa_idxset_trivial_compare_func
);
1846 c
->sinks_by_index
= pa_hashmap_new(pa_idxset_trivial_hash_func
, pa_idxset_trivial_compare_func
);
1847 c
->sinks_by_path
= pa_hashmap_new(pa_idxset_string_hash_func
, pa_idxset_string_compare_func
);
1848 c
->sources_by_index
= pa_hashmap_new(pa_idxset_trivial_hash_func
, pa_idxset_trivial_compare_func
);
1849 c
->sources_by_path
= pa_hashmap_new(pa_idxset_string_hash_func
, pa_idxset_string_compare_func
);
1850 c
->playback_streams
= pa_hashmap_new(pa_idxset_trivial_hash_func
, pa_idxset_trivial_compare_func
);
1851 c
->record_streams
= pa_hashmap_new(pa_idxset_trivial_hash_func
, pa_idxset_trivial_compare_func
);
1852 c
->samples
= pa_hashmap_new(pa_idxset_trivial_hash_func
, pa_idxset_trivial_compare_func
);
1853 c
->modules
= pa_hashmap_new(pa_idxset_trivial_hash_func
, pa_idxset_trivial_compare_func
);
1854 c
->clients
= pa_hashmap_new(pa_idxset_trivial_hash_func
, pa_idxset_trivial_compare_func
);
1855 c
->fallback_sink
= pa_namereg_get_default_sink(core
);
1856 c
->fallback_source
= pa_namereg_get_default_source(core
);
1858 for (card
= pa_idxset_first(core
->cards
, &idx
); card
; card
= pa_idxset_next(core
->cards
, &idx
))
1859 pa_hashmap_put(c
->cards
, PA_UINT32_TO_PTR(idx
), pa_dbusiface_card_new(card
, OBJECT_PATH
));
1861 for (sink
= pa_idxset_first(core
->sinks
, &idx
); sink
; sink
= pa_idxset_next(core
->sinks
, &idx
)) {
1862 device
= pa_dbusiface_device_new_sink(sink
, OBJECT_PATH
);
1863 pa_hashmap_put(c
->sinks_by_index
, PA_UINT32_TO_PTR(idx
), device
);
1864 pa_hashmap_put(c
->sinks_by_path
, pa_dbusiface_device_get_path(device
), device
);
1867 for (source
= pa_idxset_first(core
->sources
, &idx
); source
; source
= pa_idxset_next(core
->sources
, &idx
)) {
1868 device
= pa_dbusiface_device_new_source(source
, OBJECT_PATH
);
1869 pa_hashmap_put(c
->sources_by_index
, PA_UINT32_TO_PTR(idx
), device
);
1870 pa_hashmap_put(c
->sources_by_path
, pa_dbusiface_device_get_path(device
), device
);
1873 for (sink_input
= pa_idxset_first(core
->sink_inputs
, &idx
); sink_input
; sink_input
= pa_idxset_next(core
->sink_inputs
, &idx
))
1874 pa_hashmap_put(c
->playback_streams
, PA_UINT32_TO_PTR(idx
), pa_dbusiface_stream_new_playback(sink_input
, OBJECT_PATH
));
1876 for (source_output
= pa_idxset_first(core
->source_outputs
, &idx
); source_output
; source_output
= pa_idxset_next(core
->source_outputs
, &idx
))
1877 pa_hashmap_put(c
->record_streams
, PA_UINT32_TO_PTR(idx
), pa_dbusiface_stream_new_record(source_output
, OBJECT_PATH
));
1879 for (sample
= pa_idxset_first(core
->scache
, &idx
); sample
; sample
= pa_idxset_next(core
->scache
, &idx
))
1880 pa_hashmap_put(c
->samples
, PA_UINT32_TO_PTR(idx
), pa_dbusiface_sample_new(sample
, OBJECT_PATH
));
1882 for (module
= pa_idxset_first(core
->modules
, &idx
); module
; module
= pa_idxset_next(core
->modules
, &idx
))
1883 pa_hashmap_put(c
->modules
, PA_UINT32_TO_PTR(idx
), pa_dbusiface_module_new(module
, OBJECT_PATH
));
1885 for (client
= pa_idxset_first(core
->clients
, &idx
); client
; client
= pa_idxset_next(core
->clients
, &idx
))
1886 pa_hashmap_put(c
->clients
, PA_UINT32_TO_PTR(idx
), pa_dbusiface_client_new(client
, OBJECT_PATH
));
1888 pa_dbus_protocol_add_interface(c
->dbus_protocol
, OBJECT_PATH
, &core_interface_info
, c
);
1893 static void free_card_cb(void *p
, void *userdata
) {
1894 pa_dbusiface_card
*c
= p
;
1898 pa_dbusiface_card_free(c
);
1901 static void free_device_cb(void *p
, void *userdata
) {
1902 pa_dbusiface_device
*d
= p
;
1906 pa_dbusiface_device_free(d
);
1909 static void free_stream_cb(void *p
, void *userdata
) {
1910 pa_dbusiface_stream
*s
= p
;
1914 pa_dbusiface_stream_free(s
);
1917 static void free_sample_cb(void *p
, void *userdata
) {
1918 pa_dbusiface_sample
*s
= p
;
1922 pa_dbusiface_sample_free(s
);
1925 static void free_module_cb(void *p
, void *userdata
) {
1926 pa_dbusiface_module
*m
= p
;
1930 pa_dbusiface_module_free(m
);
1933 static void free_client_cb(void *p
, void *userdata
) {
1934 pa_dbusiface_client
*c
= p
;
1938 pa_dbusiface_client_free(c
);
1941 void pa_dbusiface_core_free(pa_dbusiface_core
*c
) {
1944 pa_dbus_protocol_remove_interface(c
->dbus_protocol
, OBJECT_PATH
, INTERFACE_CORE
);
1946 pa_subscription_free(c
->subscription
);
1947 pa_hashmap_free(c
->cards
, free_card_cb
, NULL
);
1948 pa_hashmap_free(c
->sinks_by_index
, free_device_cb
, NULL
);
1949 pa_hashmap_free(c
->sinks_by_path
, NULL
, NULL
);
1950 pa_hashmap_free(c
->sources_by_index
, free_device_cb
, NULL
);
1951 pa_hashmap_free(c
->sources_by_path
, NULL
, NULL
);
1952 pa_hashmap_free(c
->playback_streams
, free_stream_cb
, NULL
);
1953 pa_hashmap_free(c
->record_streams
, free_stream_cb
, NULL
);
1954 pa_hashmap_free(c
->samples
, free_sample_cb
, NULL
);
1955 pa_hashmap_free(c
->modules
, free_module_cb
, NULL
);
1956 pa_hashmap_free(c
->clients
, free_client_cb
, NULL
);
1958 pa_dbus_protocol_unref(c
->dbus_protocol
);