[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.
Thanks,
Adam
For what it's worth, I used this snippet of python code to test that
DBus is working (and it was):
#!/usr/bin/python
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',
'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,
'org.freedesktop.Hal.Device')
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 --
[Interface("org.freedesktop.Hal.Manager")]
public class HalManager
{
public delegate void DeviceAddedHandler(string udi);
[Signal]
public event DeviceAddedHandler DeviceAdded;
public delegate void DeviceRemovedHandler(string udi);
[Signal]
public event DeviceRemovedHandler DeviceRemoved;
public delegate void NewCapabilityHandler(string udi, string
capability);
[Signal]
public event NewCapabilityHandler NewCapability;
[Method]
public virtual string[] GetAllDevices()
{
return null;
}
[Method]
public virtual bool DeviceExists(string udi)
{
return false;
}
[Method]
public virtual string[] FindDeviceStringMatch(string key, string value)
{
return null;
}
[Method]
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
(typeof(HalManager),
"org.freedesktop.Hal.Manager");
foreach (string device in manager.GetAllDevices()) {
System.Console.WriteLine(device);
}
}
More information about the Mono-devel-list
mailing list