]> code.delx.au - pulseaudio/blob - src/modules/dbus/iface-card.c
dbus: Use correct idxset when getting sources
[pulseaudio] / src / modules / dbus / iface-card.c
1 /***
2 This file is part of PulseAudio.
3
4 Copyright 2009 Tanu Kaskinen
5
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.
10
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.
15
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
19 USA.
20 ***/
21
22 #ifdef HAVE_CONFIG_H
23 #include <config.h>
24 #endif
25
26 #include <dbus/dbus.h>
27
28 #include <pulsecore/core-util.h>
29 #include <pulsecore/dbus-util.h>
30 #include <pulsecore/protocol-dbus.h>
31
32 #include "iface-card-profile.h"
33
34 #include "iface-card.h"
35
36 #define OBJECT_NAME "card"
37
38 static void handle_get_index(DBusConnection *conn, DBusMessage *msg, void *userdata);
39 static void handle_get_name(DBusConnection *conn, DBusMessage *msg, void *userdata);
40 static void handle_get_driver(DBusConnection *conn, DBusMessage *msg, void *userdata);
41 static void handle_get_owner_module(DBusConnection *conn, DBusMessage *msg, void *userdata);
42 static void handle_get_sinks(DBusConnection *conn, DBusMessage *msg, void *userdata);
43 static void handle_get_sources(DBusConnection *conn, DBusMessage *msg, void *userdata);
44 static void handle_get_profiles(DBusConnection *conn, DBusMessage *msg, void *userdata);
45 static void handle_get_active_profile(DBusConnection *conn, DBusMessage *msg, void *userdata);
46 static void handle_set_active_profile(DBusConnection *conn, DBusMessage *msg, DBusMessageIter *iter, void *userdata);
47 static void handle_get_property_list(DBusConnection *conn, DBusMessage *msg, void *userdata);
48
49 static void handle_get_all(DBusConnection *conn, DBusMessage *msg, void *userdata);
50
51 static void handle_get_profile_by_name(DBusConnection *conn, DBusMessage *msg, void *userdata);
52
53 struct pa_dbusiface_card {
54 pa_dbusiface_core *core;
55
56 pa_card *card;
57 char *path;
58 pa_hashmap *profiles;
59 uint32_t next_profile_index;
60 pa_card_profile *active_profile;
61 pa_proplist *proplist;
62
63 pa_hook_slot *card_profile_added_slot;
64
65 pa_dbus_protocol *dbus_protocol;
66 pa_subscription *subscription;
67 };
68
69 enum property_handler_index {
70 PROPERTY_HANDLER_INDEX,
71 PROPERTY_HANDLER_NAME,
72 PROPERTY_HANDLER_DRIVER,
73 PROPERTY_HANDLER_OWNER_MODULE,
74 PROPERTY_HANDLER_SINKS,
75 PROPERTY_HANDLER_SOURCES,
76 PROPERTY_HANDLER_PROFILES,
77 PROPERTY_HANDLER_ACTIVE_PROFILE,
78 PROPERTY_HANDLER_PROPERTY_LIST,
79 PROPERTY_HANDLER_MAX
80 };
81
82 static pa_dbus_property_handler property_handlers[PROPERTY_HANDLER_MAX] = {
83 [PROPERTY_HANDLER_INDEX] = { .property_name = "Index", .type = "u", .get_cb = handle_get_index, .set_cb = NULL },
84 [PROPERTY_HANDLER_NAME] = { .property_name = "Name", .type = "s", .get_cb = handle_get_name, .set_cb = NULL },
85 [PROPERTY_HANDLER_DRIVER] = { .property_name = "Driver", .type = "s", .get_cb = handle_get_driver, .set_cb = NULL },
86 [PROPERTY_HANDLER_OWNER_MODULE] = { .property_name = "OwnerModule", .type = "o", .get_cb = handle_get_owner_module, .set_cb = NULL },
87 [PROPERTY_HANDLER_SINKS] = { .property_name = "Sinks", .type = "ao", .get_cb = handle_get_sinks, .set_cb = NULL },
88 [PROPERTY_HANDLER_SOURCES] = { .property_name = "Sources", .type = "ao", .get_cb = handle_get_sources, .set_cb = NULL },
89 [PROPERTY_HANDLER_PROFILES] = { .property_name = "Profiles", .type = "ao", .get_cb = handle_get_profiles, .set_cb = NULL },
90 [PROPERTY_HANDLER_ACTIVE_PROFILE] = { .property_name = "ActiveProfile", .type = "o", .get_cb = handle_get_active_profile, .set_cb = handle_set_active_profile },
91 [PROPERTY_HANDLER_PROPERTY_LIST] = { .property_name = "PropertyList", .type = "a{say}", .get_cb = handle_get_property_list, .set_cb = NULL }
92 };
93
94 enum method_handler_index {
95 METHOD_HANDLER_GET_PROFILE_BY_NAME,
96 METHOD_HANDLER_MAX
97 };
98
99 static pa_dbus_arg_info get_profile_by_name_args[] = { { "name", "s", "in" }, { "profile", "o", "out" } };
100
101 static pa_dbus_method_handler method_handlers[METHOD_HANDLER_MAX] = {
102 [METHOD_HANDLER_GET_PROFILE_BY_NAME] = {
103 .method_name = "GetProfileByName",
104 .arguments = get_profile_by_name_args,
105 .n_arguments = sizeof(get_profile_by_name_args) / sizeof(pa_dbus_arg_info),
106 .receive_cb = handle_get_profile_by_name }
107 };
108
109 enum signal_index {
110 SIGNAL_ACTIVE_PROFILE_UPDATED,
111 SIGNAL_NEW_PROFILE,
112 SIGNAL_PROPERTY_LIST_UPDATED,
113 SIGNAL_MAX
114 };
115
116 static pa_dbus_arg_info active_profile_updated_args[] = { { "profile", "o", NULL } };
117 static pa_dbus_arg_info new_profile_args[] = { { "profile", "o", NULL } };
118 static pa_dbus_arg_info property_list_updated_args[] = { { "property_list", "a{say}", NULL } };
119
120 static pa_dbus_signal_info signals[SIGNAL_MAX] = {
121 [SIGNAL_ACTIVE_PROFILE_UPDATED] = { .name = "ActiveProfileUpdated", .arguments = active_profile_updated_args, .n_arguments = 1 },
122 [SIGNAL_NEW_PROFILE] = { .name = "NewProfile", .arguments = new_profile_args, .n_arguments = 1 },
123 [SIGNAL_PROPERTY_LIST_UPDATED] = { .name = "PropertyListUpdated", .arguments = property_list_updated_args, .n_arguments = 1 }
124 };
125
126 static pa_dbus_interface_info card_interface_info = {
127 .name = PA_DBUSIFACE_CARD_INTERFACE,
128 .method_handlers = method_handlers,
129 .n_method_handlers = METHOD_HANDLER_MAX,
130 .property_handlers = property_handlers,
131 .n_property_handlers = PROPERTY_HANDLER_MAX,
132 .get_all_properties_cb = handle_get_all,
133 .signals = signals,
134 .n_signals = SIGNAL_MAX
135 };
136
137 static void handle_get_index(DBusConnection *conn, DBusMessage *msg, void *userdata) {
138 pa_dbusiface_card *c = userdata;
139 dbus_uint32_t idx;
140
141 pa_assert(conn);
142 pa_assert(msg);
143 pa_assert(c);
144
145 idx = c->card->index;
146
147 pa_dbus_send_basic_variant_reply(conn, msg, DBUS_TYPE_UINT32, &idx);
148 }
149
150 static void handle_get_name(DBusConnection *conn, DBusMessage *msg, void *userdata) {
151 pa_dbusiface_card *c = userdata;
152
153 pa_assert(conn);
154 pa_assert(msg);
155 pa_assert(c);
156
157 pa_dbus_send_basic_variant_reply(conn, msg, DBUS_TYPE_STRING, &c->card->name);
158 }
159
160 static void handle_get_driver(DBusConnection *conn, DBusMessage *msg, void *userdata) {
161 pa_dbusiface_card *c = userdata;
162
163 pa_assert(conn);
164 pa_assert(msg);
165 pa_assert(c);
166
167 pa_dbus_send_basic_variant_reply(conn, msg, DBUS_TYPE_STRING, &c->card->driver);
168 }
169
170 static void handle_get_owner_module(DBusConnection *conn, DBusMessage *msg, void *userdata) {
171 pa_dbusiface_card *c = userdata;
172 const char *owner_module;
173
174 pa_assert(conn);
175 pa_assert(msg);
176 pa_assert(c);
177
178 if (!c->card->module) {
179 pa_dbus_send_error(conn, msg, PA_DBUS_ERROR_NO_SUCH_PROPERTY, "Card %s doesn't have an owner module.", c->card->name);
180 return;
181 }
182
183 owner_module = pa_dbusiface_core_get_module_path(c->core, c->card->module);
184
185 pa_dbus_send_basic_variant_reply(conn, msg, DBUS_TYPE_OBJECT_PATH, &owner_module);
186 }
187
188 /* The caller frees the array, but not the strings. */
189 static const char **get_sinks(pa_dbusiface_card *c, unsigned *n) {
190 const char **sinks = NULL;
191 unsigned i = 0;
192 uint32_t idx = 0;
193 pa_sink *sink = NULL;
194
195 pa_assert(c);
196 pa_assert(n);
197
198 *n = pa_idxset_size(c->card->sinks);
199
200 if (*n == 0)
201 return NULL;
202
203 sinks = pa_xnew(const char *, *n);
204
205 PA_IDXSET_FOREACH(sink, c->card->sinks, idx) {
206 sinks[i] = pa_dbusiface_core_get_sink_path(c->core, sink);
207 ++i;
208 }
209
210 return sinks;
211 }
212
213 static void handle_get_sinks(DBusConnection *conn, DBusMessage *msg, void *userdata) {
214 pa_dbusiface_card *c = userdata;
215 const char **sinks;
216 unsigned n_sinks;
217
218 pa_assert(conn);
219 pa_assert(msg);
220 pa_assert(c);
221
222 sinks = get_sinks(c, &n_sinks);
223
224 pa_dbus_send_basic_array_variant_reply(conn, msg, DBUS_TYPE_OBJECT_PATH, sinks, n_sinks);
225
226 pa_xfree(sinks);
227 }
228
229 /* The caller frees the array, but not the strings. */
230 static const char **get_sources(pa_dbusiface_card *c, unsigned *n) {
231 const char **sources = NULL;
232 unsigned i = 0;
233 uint32_t idx = 0;
234 pa_source *source = NULL;
235
236 pa_assert(c);
237 pa_assert(n);
238
239 *n = pa_idxset_size(c->card->sources);
240
241 if (*n == 0)
242 return NULL;
243
244 sources = pa_xnew(const char *, *n);
245
246 PA_IDXSET_FOREACH(source, c->card->sources, idx) {
247 sources[i] = pa_dbusiface_core_get_source_path(c->core, source);
248 ++i;
249 }
250
251 return sources;
252 }
253
254 static void handle_get_sources(DBusConnection *conn, DBusMessage *msg, void *userdata) {
255 pa_dbusiface_card *c = userdata;
256 const char **sources;
257 unsigned n_sources;
258
259 pa_assert(conn);
260 pa_assert(msg);
261 pa_assert(c);
262
263 sources = get_sources(c, &n_sources);
264
265 pa_dbus_send_basic_array_variant_reply(conn, msg, DBUS_TYPE_OBJECT_PATH, sources, n_sources);
266
267 pa_xfree(sources);
268 }
269
270 /* The caller frees the array, but not the strings. */
271 static const char **get_profiles(pa_dbusiface_card *c, unsigned *n) {
272 const char **profiles;
273 unsigned i = 0;
274 void *state = NULL;
275 pa_dbusiface_card_profile *profile;
276
277 pa_assert(c);
278 pa_assert(n);
279
280 *n = pa_hashmap_size(c->profiles);
281
282 if (*n == 0)
283 return NULL;
284
285 profiles = pa_xnew(const char *, *n);
286
287 PA_HASHMAP_FOREACH(profile, c->profiles, state)
288 profiles[i++] = pa_dbusiface_card_profile_get_path(profile);
289
290 return profiles;
291 }
292
293 static void handle_get_profiles(DBusConnection *conn, DBusMessage *msg, void *userdata) {
294 pa_dbusiface_card *c = userdata;
295 const char **profiles;
296 unsigned n_profiles;
297
298 pa_assert(conn);
299 pa_assert(msg);
300 pa_assert(c);
301
302 profiles = get_profiles(c, &n_profiles);
303
304 pa_dbus_send_basic_array_variant_reply(conn, msg, DBUS_TYPE_OBJECT_PATH, profiles, n_profiles);
305
306 pa_xfree(profiles);
307 }
308
309 static void handle_get_active_profile(DBusConnection *conn, DBusMessage *msg, void *userdata) {
310 pa_dbusiface_card *c = userdata;
311 const char *active_profile;
312
313 pa_assert(conn);
314 pa_assert(msg);
315 pa_assert(c);
316
317 active_profile = pa_dbusiface_card_profile_get_path(pa_hashmap_get(c->profiles, c->active_profile->name));
318 pa_dbus_send_basic_variant_reply(conn, msg, DBUS_TYPE_OBJECT_PATH, &active_profile);
319 }
320
321 static void handle_set_active_profile(DBusConnection *conn, DBusMessage *msg, DBusMessageIter *iter, void *userdata) {
322 pa_dbusiface_card *c = userdata;
323 const char *new_active_path;
324 pa_dbusiface_card_profile *new_active;
325 int r;
326
327 pa_assert(conn);
328 pa_assert(msg);
329 pa_assert(iter);
330 pa_assert(c);
331
332 dbus_message_iter_get_basic(iter, &new_active_path);
333
334 if (!(new_active = pa_hashmap_get(c->profiles, new_active_path))) {
335 pa_dbus_send_error(conn, msg, PA_DBUS_ERROR_NOT_FOUND, "%s: No such profile.", new_active_path);
336 return;
337 }
338
339 if ((r = pa_card_set_profile(c->card, pa_dbusiface_card_profile_get_profile(new_active), true)) < 0) {
340 pa_dbus_send_error(conn, msg, DBUS_ERROR_FAILED,
341 "Internal error in PulseAudio: pa_card_set_profile() failed with error code %i.", r);
342 return;
343 }
344
345 pa_dbus_send_empty_reply(conn, msg);
346 }
347
348 static void handle_get_property_list(DBusConnection *conn, DBusMessage *msg, void *userdata) {
349 pa_dbusiface_card *c = userdata;
350
351 pa_assert(conn);
352 pa_assert(msg);
353 pa_assert(c);
354
355 pa_dbus_send_proplist_variant_reply(conn, msg, c->proplist);
356 }
357
358 static void handle_get_all(DBusConnection *conn, DBusMessage *msg, void *userdata) {
359 pa_dbusiface_card *c = userdata;
360 DBusMessage *reply = NULL;
361 DBusMessageIter msg_iter;
362 DBusMessageIter dict_iter;
363 dbus_uint32_t idx;
364 const char *owner_module = NULL;
365 const char **sinks = NULL;
366 unsigned n_sinks = 0;
367 const char **sources = NULL;
368 unsigned n_sources = 0;
369 const char **profiles = NULL;
370 unsigned n_profiles = 0;
371 const char *active_profile = NULL;
372
373 pa_assert(conn);
374 pa_assert(msg);
375 pa_assert(c);
376
377 idx = c->card->index;
378 if (c->card->module)
379 owner_module = pa_dbusiface_core_get_module_path(c->core, c->card->module);
380 sinks = get_sinks(c, &n_sinks);
381 sources = get_sources(c, &n_sources);
382 profiles = get_profiles(c, &n_profiles);
383 active_profile = pa_dbusiface_card_profile_get_path(pa_hashmap_get(c->profiles, c->active_profile->name));
384
385 pa_assert_se((reply = dbus_message_new_method_return(msg)));
386
387 dbus_message_iter_init_append(reply, &msg_iter);
388 pa_assert_se(dbus_message_iter_open_container(&msg_iter, DBUS_TYPE_ARRAY, "{sv}", &dict_iter));
389
390 pa_dbus_append_basic_variant_dict_entry(&dict_iter, property_handlers[PROPERTY_HANDLER_INDEX].property_name, DBUS_TYPE_UINT32, &idx);
391 pa_dbus_append_basic_variant_dict_entry(&dict_iter, property_handlers[PROPERTY_HANDLER_NAME].property_name, DBUS_TYPE_STRING, &c->card->name);
392 pa_dbus_append_basic_variant_dict_entry(&dict_iter, property_handlers[PROPERTY_HANDLER_DRIVER].property_name, DBUS_TYPE_STRING, &c->card->driver);
393
394 if (owner_module)
395 pa_dbus_append_basic_variant_dict_entry(&dict_iter, property_handlers[PROPERTY_HANDLER_OWNER_MODULE].property_name, DBUS_TYPE_OBJECT_PATH, &owner_module);
396
397 pa_dbus_append_basic_array_variant_dict_entry(&dict_iter, property_handlers[PROPERTY_HANDLER_SINKS].property_name, DBUS_TYPE_OBJECT_PATH, sinks, n_sinks);
398 pa_dbus_append_basic_array_variant_dict_entry(&dict_iter, property_handlers[PROPERTY_HANDLER_SOURCES].property_name, DBUS_TYPE_OBJECT_PATH, sources, n_sources);
399 pa_dbus_append_basic_array_variant_dict_entry(&dict_iter, property_handlers[PROPERTY_HANDLER_PROFILES].property_name, DBUS_TYPE_OBJECT_PATH, profiles, n_profiles);
400 pa_dbus_append_basic_variant_dict_entry(&dict_iter, property_handlers[PROPERTY_HANDLER_ACTIVE_PROFILE].property_name, DBUS_TYPE_OBJECT_PATH, &active_profile);
401
402 pa_dbus_append_proplist_variant_dict_entry(&dict_iter, property_handlers[PROPERTY_HANDLER_PROPERTY_LIST].property_name, c->proplist);
403
404 pa_assert_se(dbus_message_iter_close_container(&msg_iter, &dict_iter));
405
406 pa_assert_se(dbus_connection_send(conn, reply, NULL));
407
408 dbus_message_unref(reply);
409
410 pa_xfree(sinks);
411 pa_xfree(sources);
412 pa_xfree(profiles);
413 }
414
415 static void handle_get_profile_by_name(DBusConnection *conn, DBusMessage *msg, void *userdata) {
416 pa_dbusiface_card *c = userdata;
417 const char *profile_name = NULL;
418 pa_dbusiface_card_profile *profile = NULL;
419 const char *profile_path = NULL;
420
421 pa_assert(conn);
422 pa_assert(msg);
423 pa_assert(c);
424
425 pa_assert_se(dbus_message_get_args(msg, NULL, DBUS_TYPE_STRING, &profile_name, DBUS_TYPE_INVALID));
426
427 if (!(profile = pa_hashmap_get(c->profiles, profile_name))) {
428 pa_dbus_send_error(conn, msg, PA_DBUS_ERROR_NOT_FOUND, "%s: No such profile on card %s.", profile_name, c->card->name);
429 return;
430 }
431
432 profile_path = pa_dbusiface_card_profile_get_path(profile);
433
434 pa_dbus_send_basic_value_reply(conn, msg, DBUS_TYPE_OBJECT_PATH, &profile_path);
435 }
436
437 static void subscription_cb(pa_core *core, pa_subscription_event_type_t t, uint32_t idx, void *userdata) {
438 pa_dbusiface_card *c = userdata;
439 DBusMessage *signal_msg = NULL;
440
441 pa_assert(core);
442 pa_assert((t & PA_SUBSCRIPTION_EVENT_FACILITY_MASK) == PA_SUBSCRIPTION_EVENT_CARD);
443 pa_assert(c);
444
445 /* We can't use idx != c->card->index, because the c->card pointer may
446 * be stale at this point. */
447 if (pa_idxset_get_by_index(core->cards, idx) != c->card)
448 return;
449
450 if ((t & PA_SUBSCRIPTION_EVENT_TYPE_MASK) != PA_SUBSCRIPTION_EVENT_CHANGE)
451 return;
452
453 if (c->active_profile != c->card->active_profile) {
454 const char *object_path;
455
456 c->active_profile = c->card->active_profile;
457 object_path = pa_dbusiface_card_profile_get_path(pa_hashmap_get(c->profiles, c->active_profile->name));
458
459 pa_assert_se(signal_msg = dbus_message_new_signal(c->path,
460 PA_DBUSIFACE_CARD_INTERFACE,
461 signals[SIGNAL_ACTIVE_PROFILE_UPDATED].name));
462 pa_assert_se(dbus_message_append_args(signal_msg, DBUS_TYPE_OBJECT_PATH, &object_path, DBUS_TYPE_INVALID));
463
464 pa_dbus_protocol_send_signal(c->dbus_protocol, signal_msg);
465 dbus_message_unref(signal_msg);
466 signal_msg = NULL;
467 }
468
469 if (!pa_proplist_equal(c->proplist, c->card->proplist)) {
470 DBusMessageIter msg_iter;
471
472 pa_proplist_update(c->proplist, PA_UPDATE_SET, c->card->proplist);
473
474 pa_assert_se(signal_msg = dbus_message_new_signal(c->path,
475 PA_DBUSIFACE_CARD_INTERFACE,
476 signals[SIGNAL_PROPERTY_LIST_UPDATED].name));
477 dbus_message_iter_init_append(signal_msg, &msg_iter);
478 pa_dbus_append_proplist(&msg_iter, c->proplist);
479
480 pa_dbus_protocol_send_signal(c->dbus_protocol, signal_msg);
481 dbus_message_unref(signal_msg);
482 signal_msg = NULL;
483 }
484 }
485
486 static pa_hook_result_t card_profile_added_cb(void *hook_data, void *call_data, void *slot_data) {
487 pa_core *core = hook_data;
488 pa_dbusiface_card *c = slot_data;
489 pa_card_profile *profile = call_data;
490 pa_dbusiface_card_profile *p;
491 const char *object_path;
492 DBusMessage *signal_msg;
493
494 if (profile->card != c->card)
495 return PA_HOOK_OK;
496
497 p = pa_dbusiface_card_profile_new(c, core, profile, c->next_profile_index++);
498 pa_assert_se(pa_hashmap_put(c->profiles, (char *) pa_dbusiface_card_profile_get_name(p), p) >= 0);
499
500 /* Send D-Bus signal */
501 object_path = pa_dbusiface_card_profile_get_path(p);
502
503 pa_assert_se(signal_msg = dbus_message_new_signal(c->path,
504 PA_DBUSIFACE_CARD_INTERFACE,
505 signals[SIGNAL_NEW_PROFILE].name));
506 pa_assert_se(dbus_message_append_args(signal_msg, DBUS_TYPE_OBJECT_PATH, &object_path, DBUS_TYPE_INVALID));
507
508 pa_dbus_protocol_send_signal(c->dbus_protocol, signal_msg);
509 dbus_message_unref(signal_msg);
510
511 return PA_HOOK_OK;
512 }
513
514 pa_dbusiface_card *pa_dbusiface_card_new(pa_dbusiface_core *core, pa_card *card) {
515 pa_dbusiface_card *c = NULL;
516 pa_card_profile *profile;
517 void *state;
518
519 pa_assert(core);
520 pa_assert(card);
521
522 c = pa_xnew0(pa_dbusiface_card, 1);
523 c->core = core;
524 c->card = card;
525 c->path = pa_sprintf_malloc("%s/%s%u", PA_DBUS_CORE_OBJECT_PATH, OBJECT_NAME, card->index);
526 c->profiles = pa_hashmap_new_full(pa_idxset_string_hash_func, pa_idxset_string_compare_func, NULL,
527 (pa_free_cb_t) pa_dbusiface_card_profile_free);
528 c->next_profile_index = 0;
529 c->active_profile = card->active_profile;
530 c->proplist = pa_proplist_copy(card->proplist);
531 c->dbus_protocol = pa_dbus_protocol_get(card->core);
532 c->subscription = pa_subscription_new(card->core, PA_SUBSCRIPTION_MASK_CARD, subscription_cb, c);
533
534 PA_HASHMAP_FOREACH(profile, card->profiles, state) {
535 pa_dbusiface_card_profile *p = pa_dbusiface_card_profile_new(c, card->core, profile, c->next_profile_index++);
536 pa_hashmap_put(c->profiles, (char *) pa_dbusiface_card_profile_get_name(p), p);
537 }
538
539 pa_assert_se(pa_dbus_protocol_add_interface(c->dbus_protocol, c->path, &card_interface_info, c) >= 0);
540
541 c->card_profile_added_slot = pa_hook_connect(&card->core->hooks[PA_CORE_HOOK_CARD_PROFILE_ADDED], PA_HOOK_NORMAL,
542 card_profile_added_cb, c);
543
544 return c;
545 }
546
547 void pa_dbusiface_card_free(pa_dbusiface_card *c) {
548 pa_assert(c);
549
550 pa_assert_se(pa_dbus_protocol_remove_interface(c->dbus_protocol, c->path, card_interface_info.name) >= 0);
551
552 pa_hook_slot_free(c->card_profile_added_slot);
553
554 pa_hashmap_free(c->profiles);
555 pa_proplist_free(c->proplist);
556 pa_dbus_protocol_unref(c->dbus_protocol);
557 pa_subscription_free(c->subscription);
558
559 pa_xfree(c->path);
560 pa_xfree(c);
561 }
562
563 const char *pa_dbusiface_card_get_path(pa_dbusiface_card *c) {
564 pa_assert(c);
565
566 return c->path;
567 }