Here’s the story. I’m trying to hook into Hal to detect when a device (specifically an iPod) is attached. I can do this in C, Perl, and Python, but I can’t get the C# version to work.
The code should be fairly straightforward. I’m using the definition of HalManager from hal-sharp, which as far as I know is current to the latest Hal spec. DBus 0.23, which is working just fine. My next step is to do some debugging in dbus-sharp and see if I can identify what’s failing and why, but maybe someone has already run into this. I can’t be the only person trying to access the Hal Manager via C#.
The 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[])
The code:
[code]
// Compile with: mcs -target:exe -out:”podlet.exe” -pkg:gtk-sharp -pkg:dbus-sharp ./Main.cs ./AssemblyInfo.cs
using System;
using System.Collections;
using Gtk;
using DBus;
[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;
}
}
class podlet
{
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);
}
}
}
[/code]