build-sys: Use ax_check_flag macros from autoconf archive
[pulseaudio-mirror.git] / src / modules / hal-util.c
blob2d59f51d7c687161acf6940dbee377ce3a99094a
1 /***
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
19 USA.
20 ***/
22 #ifdef HAVE_CONFIG_H
23 #include <config.h>
24 #endif
26 #include <pulsecore/log.h>
27 #include <pulsecore/dbus-shared.h>
29 #include <hal/libhal.h>
31 #include "hal-util.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;
36 DBusError error;
37 int r = -1;
38 char **udis = NULL, *t;
39 int n, i;
41 pa_assert(core);
42 pa_assert(p);
43 pa_assert(card >= 0);
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);
49 goto finish;
53 if (!(hal = libhal_ctx_new())) {
54 pa_log_error("libhal_ctx_new() finished");
55 goto finish;
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);
60 goto finish;
63 if (!libhal_ctx_init(hal, &error)) {
64 pa_log_error("Couldn't connect to hald: %s: %s", error.name, error.message);
65 goto finish;
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);
70 goto finish;
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);
79 continue;
82 if (this_card == card)
83 break;
87 if (i >= n)
88 goto finish;
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);
98 if (t) {
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);
106 if (t) {
107 pa_proplist_sets(p, "hal.card_id", t);
108 libhal_free_string(t);
111 r = 0;
113 finish:
115 if (udis)
116 libhal_free_string_array(udis);
118 dbus_error_free(&error);
120 if (hal) {
121 libhal_ctx_shutdown(hal, &error);
122 libhal_ctx_free(hal);
123 dbus_error_free(&error);
126 if (c)
127 pa_dbus_connection_unref(c);
129 return r;