diff options
author | Lennart Poettering <lennart@poettering.net> | 2009-01-24 01:25:11 +0100 |
---|---|---|
committer | Lennart Poettering <lennart@poettering.net> | 2009-01-24 01:25:11 +0100 |
commit | a365c8212d24f80acbdadc927b696dd083507b53 (patch) | |
tree | 1e535e0670a2a121571e59ad343e2ce6dd9d0fc1 /src/modules/hal-util.c | |
parent | 54dad91f079a88f7f7dfb17692ff09af70d30e2e (diff) |
include a few HAL properties in our card/sink/source properties for ALSA devices
Diffstat (limited to 'src/modules/hal-util.c')
-rw-r--r-- | src/modules/hal-util.c | 127 |
1 files changed, 127 insertions, 0 deletions
diff --git a/src/modules/hal-util.c b/src/modules/hal-util.c new file mode 100644 index 00000000..82bbc57e --- /dev/null +++ b/src/modules/hal-util.c @@ -0,0 +1,127 @@ +/*** + This file is part of PulseAudio. + + Copyright 2009 Lennart Poettering + + PulseAudio is free software; you can redistribute it and/or modify + it under the terms of the GNU Lesser General Public License as + published by the Free Software Foundation; either version 2 of the + License, or (at your option) any later version. + + PulseAudio is distributed in the hope that it will be useful, but + WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + General Public License for more details. + + You should have received a copy of the GNU Lesser General Public + License along with PulseAudio; if not, write to the Free Software + Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 + USA. +***/ + +#ifdef HAVE_CONFIG_H +#include <config.h> +#endif + +#include <pulsecore/log.h> + +#include <hal/libhal.h> + +#include "dbus-util.h" +#include "hal-util.h" + +int pa_hal_get_info(pa_core *core, pa_proplist *p, int card) { + pa_dbus_connection *c = NULL; + LibHalContext *hal = NULL; + DBusError error; + int r = -1; + char **udis = NULL, *t; + int n, i; + + pa_assert(core); + pa_assert(p); + pa_assert(card >= 0); + + dbus_error_init(&error); + + if (!(c = pa_dbus_bus_get(core, DBUS_BUS_SYSTEM, &error)) || dbus_error_is_set(&error)) { + pa_log_error("Unable to contact DBUS system bus: %s: %s", error.name, error.message); + goto finish; + } + + + if (!(hal = libhal_ctx_new())) { + pa_log_error("libhal_ctx_new() finished"); + goto finish; + } + + if (!libhal_ctx_set_dbus_connection(hal, pa_dbus_connection_get(c))) { + pa_log_error("Error establishing DBUS connection: %s: %s", error.name, error.message); + goto finish; + } + + if (!libhal_ctx_init(hal, &error)) { + pa_log_error("Couldn't connect to hald: %s: %s", error.name, error.message); + goto finish; + } + + if (!(udis = libhal_find_device_by_capability(hal, "sound", &n, &error)) < 0) { + pa_log_error("Couldn't find devices: %s: %s", error.name, error.message); + goto finish; + } + + for (i = 0; i < n; i++) { + dbus_int32_t this_card; + + this_card = libhal_device_get_property_int(hal, udis[i], "sound.card", &error); + if (dbus_error_is_set(&error)) { + dbus_error_free(&error); + continue; + } + + if (this_card == card) + break; + + } + + if (i >= n) + goto finish; + + pa_proplist_sets(p, "hal.udi", udis[i]); + + t = libhal_device_get_property_string(hal, udis[i], "info.product", &error); + if (dbus_error_is_set(&error)) + dbus_error_free(&error); + if (t) { + pa_proplist_sets(p, "hal.product", t); + libhal_free_string(t); + } + + t = libhal_device_get_property_string(hal, udis[i], "sound.card_id", &error); + if (dbus_error_is_set(&error)) + dbus_error_free(&error); + if (t) { + pa_proplist_sets(p, "hal.card_id", t); + libhal_free_string(t); + } + + r = 0; + +finish: + + if (udis) + libhal_free_string_array(udis); + + dbus_error_free(&error); + + if (hal) { + libhal_ctx_shutdown(hal, &error); + libhal_ctx_free(hal); + dbus_error_free(&error); + } + + if (c) + pa_dbus_connection_unref(c); + + return r; +} |