Tuesday, August 12, 2008

HAL: fixed device locking

Some days ago I had a discussion with Matthias Kretz at the Akademy 2008 about HAL, the handling of audio devices in HAL and the needs/requirements from the perspective of phonon.

One aspect was that phonon needs to find out of some other tool already uses a audio device. The HAL device locking would be a solution to detect this. I took a look at the HAL code for device locking and while playing around with the interfaces I wondered why it didn't work as it should. The lock information (info.locked* keys) where never removed if the lock owner died or exited without unlock the interface again. The handling was also broken if someone requested more than one lock (e.g. two or more different devices).

I really wonder why there was only one bugreport about problems with device locking (if the lock owner dies). Did nobody ever used these interfaces?

I've wrote a quik patch to solve these problems. As first I changed the hashtable which contains the lock info from key={lockowner}/value={device} to key={lockowner}/value={list of devices} so that locking multiple devices is now possible. And the other part of this patch is to remove the lock based on the old_service_name (and not the new_service_name) on NameOwnerChanged events from DBus to solve the 'lock owner died' problem.
Tech Tags: