Viewing file: soundcardBackendHal.py (6.07 KB) -rwxr-xr-x Select action/file-type: (+) | (+) | (+) | Code (+) | Session (+) | (+) | SDB (+) | (+) | (+) | (+) | (+) | (+) |
## soundcardBackendKudzu.py - Contains the backend code needed for system-config-soundcard ## Copyright (C) 2002, 2003 Red Hat, Inc. ## Copyright (C) 2002, 2003 Brent Fox <bfox@redhat.com> ## Copyright (C) 2004, 2005 Bastien Nocera <hadess@hadess.net>
## Based on code by Dan Williams <dcbw@redhat.com>
## This program is free software; you can redistribute it and/or modify ## it under the terms of the GNU General Public License as published by ## the Free Software Foundation; either version 2 of the License, or ## (at your option) any later version.
## This program 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 General Public License ## along with this program; if not, write to the Free Software ## Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
import string import os import sys import dbus
## ## I18N ## from rhpl.translate import _, N_ import rhpl.translate as translate translate.textdomain ("system-config-soundcard")
HAL_DEVICE_IFACE = "org.freedesktop.Hal.Device" ALLOWED_TYPE = "playback"
import soundcardBackendSoundCard
class soundcardBackendHal: def __init__(self): self.doDebug = True
self._dbusBus = dbus.SystemBus() self.halManagerObj = self._dbusBus.get_object("org.freedesktop.Hal", "/org/freedesktop/Hal/Manager") self.halManager = dbus.Interface(self.halManagerObj, "org.freedesktop.Hal.Manager") self.driverList = self.read_driver_list() self.cards = {}
def destroy(self, args): return
# ------------------------------------------------------------------------ # Probe routines - drivers # ------------------------------------------------------------------------ def read_driver_list(self): try: fd = open('/proc/asound/modules', 'r') list = fd.readlines() fd.close() except: return []
drivers = [] for line in list: tmp = line.split() drivers.append([int(tmp[0]), string.replace(tmp[1],'_','-')]) return drivers
def find_driver(self, list, position): for rec in list: if rec[0] == position: return rec[1]
return _("Unknown")
# ------------------------------------------------------------------------ # Probe routines - HAL # ------------------------------------------------------------------------
def getProperty(self, obj, prop): if not obj.PropertyExists(prop, dbus_interface=HAL_DEVICE_IFACE): return None return obj.GetProperty(prop, dbus_interface=HAL_DEVICE_IFACE)
def getVendor(self, udi): parentUdi = udi while parentUdi and len(parentUdi): obj = self._dbusBus.get_object("org.freedesktop.Hal", parentUdi) vendor = self.getProperty(obj, "info.vendor") if vendor != None: return vendor, self.getProperty(obj, "info.product") new_parentUdi = self.getProperty(obj, "info.parent") if new_parentUdi == None: break parentUdi = new_parentUdi def getBus(self, udi): parentUdi = udi while parentUdi and len(parentUdi): obj = self._dbusBus.get_object("org.freedesktop.Hal", parentUdi) bus = self.getProperty(obj, "info.bus") if bus != None: return bus new_parentUdi = self.getProperty(obj, "info.parent") if new_parentUdi == None: break parentUdi = new_parentUdi
def getDriver(self, udi): parentUdi = udi while parentUdi and len(parentUdi): obj = self._dbusBus.get_object("org.freedesktop.Hal", parentUdi) driver = self.getProperty(obj, "info.linux.driver") if driver != None: return driver new_parentUdi = self.getProperty(obj, "info.parent") if new_parentUdi == None: break parentUdi = new_parentUdi
def getDevices(self, udi): # Search for other devices #children = self.halManager.FindDeviceStringMatch("info.parent", udi) #for childUdi in children: # self.getChildDevices(childUdi) # Add ourselves if we're an alsa device obj = self._dbusBus.get_object("org.freedesktop.Hal", udi) category = self.getProperty(obj, "info.category") if category == "alsa" and self.getProperty(obj, "alsa.type") == ALLOWED_TYPE: index = self.getProperty(obj, "alsa.card") if index != None and not self.cards.has_key(index): card = soundcardBackendSoundCard.soundCard(index) card.active = True card.maker, card.model = self.getVendor(udi) card.type = string.split(card.maker)[0] card.bus = self.getBus(udi) card.driver = self.find_driver(self.driverList, card.index) #card.driver = self.getDriver(udi) card.device_list = card.loadCardDevices() self.cards[index] = card
# TODO? # Only add USB audio devices that have snd-usb-audio as the driver #if card.bus() == "usb" and card.driver() != "snd-usb-audio": # continue # Same with Mac sound devices #if card.bus() == "macio" and card.driver() != "snd-powermac": def probeCards(self, default_card, default_device, card_list, card_max):
udiList = self.halManager.FindDeviceByCapability("alsa") for udi in udiList: self.getDevices(udi) for index in self.cards: if index < card_max : card_list[index] = self.cards[index] card_list[default_card].default_device = default_device
return card_list
|