2 This file is part of PulseAudio.
4 Copyright 2009 Lennart Poettering
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
8 published by the Free Software Foundation; either version 2.1 of the
9 License, 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
17 License along with PulseAudio; if not, write to the Free Software
18 Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
26 #include <pulsecore/log.h>
27 #include <pulsecore/dbus-shared.h>
29 #include <hal/libhal.h>
33 int pa_hal_get_info(pa_core
*core
, pa_proplist
*p
, int card
) {
34 pa_dbus_connection
*c
= NULL
;
35 LibHalContext
*hal
= NULL
;
38 char **udis
= NULL
, *t
;
45 dbus_error_init(&error
);
47 if (!(c
= pa_dbus_bus_get(core
, DBUS_BUS_SYSTEM
, &error
)) || dbus_error_is_set(&error
)) {
48 pa_log_error("Unable to contact DBUS system bus: %s: %s", error
.name
, error
.message
);
53 if (!(hal
= libhal_ctx_new())) {
54 pa_log_error("libhal_ctx_new() finished");
58 if (!libhal_ctx_set_dbus_connection(hal
, pa_dbus_connection_get(c
))) {
59 pa_log_error("Error establishing DBUS connection: %s: %s", error
.name
, error
.message
);
63 if (!libhal_ctx_init(hal
, &error
)) {
64 pa_log_error("Couldn't connect to hald: %s: %s", error
.name
, error
.message
);
68 if (!(udis
= libhal_find_device_by_capability(hal
, "sound", &n
, &error
))) {
69 pa_log_error("Couldn't find devices: %s: %s", error
.name
, error
.message
);
73 for (i
= 0; i
< n
; i
++) {
74 dbus_int32_t this_card
;
76 this_card
= libhal_device_get_property_int(hal
, udis
[i
], "sound.card", &error
);
77 if (dbus_error_is_set(&error
)) {
78 dbus_error_free(&error
);
82 if (this_card
== card
)
90 pa_proplist_sets(p
, "hal.udi", udis
[i
]);
92 /* The data HAL stores in info.product is not actually a product
93 * string but simply the ALSA card name. We will hence not write
94 * it to PA_PROP_DEVICE_PRODUCT_NAME */
95 t
= libhal_device_get_property_string(hal
, udis
[i
], "info.product", &error
);
96 if (dbus_error_is_set(&error
))
97 dbus_error_free(&error
);
99 pa_proplist_sets(p
, "hal.product", t
);
100 libhal_free_string(t
);
103 t
= libhal_device_get_property_string(hal
, udis
[i
], "sound.card_id", &error
);
104 if (dbus_error_is_set(&error
))
105 dbus_error_free(&error
);
107 pa_proplist_sets(p
, "hal.card_id", t
);
108 libhal_free_string(t
);
116 libhal_free_string_array(udis
);
118 dbus_error_free(&error
);
121 libhal_ctx_shutdown(hal
, &error
);
122 libhal_ctx_free(hal
);
123 dbus_error_free(&error
);
127 pa_dbus_connection_unref(c
);