[Mono-devel-list] DBus and HAL

Adam Israel adam at battleaxe.net
Sun Jan 30 23:21:14 EST 2005

Hey all,

I'm trying to use Hal and DBus to detect the devices attached to the 
system.  I'm trying to call GetAllDevices but it's throwing this exception:

Unhandled Exception: DBus.DBusException: Disconnected prior to receiving 
a reply
in <0x0015a> DBus.Message:SendWithReplyAndBlock ()
in <0x0007c> HalManager.Proxy:GetAllDevices ()
in <0x00087> podlet:Main (string[])

I'm using DBus/dbus-sharp 0.23 under Ubuntu, and I do have a session bus 
running.  I'm not sure if I'm doing something wrong, or if the dbus 
bindings can't handle this yet.



For what it's worth, I used this snippet of python code to test that 
DBus is working (and it was):

import dbus

bus = dbus.Bus (dbus.Bus.TYPE_SYSTEM)
hal_service = bus.get_service ('org.freedesktop.Hal')
hal_manager = hal_service.get_object ('/org/freedesktop/Hal/Manager',

volume_udi_list = hal_manager.FindDeviceByCapability ('volume')
for udi in volume_udi_list:
    volume = hal_service.get_object (udi, 'org.freedesktop.Hal.Device')
    device_file = volume.GetProperty ('block.device')
    fstype = volume.GetProperty ('volume.fstype')
    storage_udi = volume.GetProperty ('block.storage_device')
    storage = hal_service.get_object (storage_udi, 
    drive_type = storage.GetProperty ('storage.drive_type')
    print 'udi=%s device_file=%s fstype=%s drive_type=%s'%(udi, 
device_file, fstype, drive_type)

-- snip --

public class HalManager
    public delegate void DeviceAddedHandler(string udi);
    public event DeviceAddedHandler DeviceAdded;

    public delegate void DeviceRemovedHandler(string udi);
    public event DeviceRemovedHandler DeviceRemoved;

    public delegate void NewCapabilityHandler(string udi, string 
    public event NewCapabilityHandler NewCapability;

    public virtual string[] GetAllDevices()
         return null;

    public virtual bool DeviceExists(string udi)
         return false;

    public virtual string[] FindDeviceStringMatch(string key, string value)
         return null;

    public virtual string[] FindDeviceByCapability(string capability)
         return null;

    public static void Main(string[] args)
        Connection connection;

        connection = Bus.GetSystemBus();
          Service service = Service.Get(connection, "org.freedesktop.Hal");
        HalManager manager = (HalManager)service.GetObject 
          foreach (string device in manager.GetAllDevices()) {

More information about the Mono-devel-list mailing list