object with multiple interfaces in ndesk-dbus (C#)?

Alp Toker alp at atoker.com
Wed Oct 17 08:17:55 PDT 2007

Enric Jaen wrote:
> Hi, is there any example of an object implementing
> mutiple interfaces in ndesk-dbus? I mean, that when
> introspecting the object the XML shows more than one
> <interface>. The spec says this is valid. 
> In python I think this is done by placing above each
> method definition an @ annotation indicating the
> interface name. Is this feature implemented in
> ndesk-dbus?

Multiple D-Bus interfaces can be provided simply by implementing them as 
multiple C# interfaces. They are automatically mapped back and forth 
both when implemented in managed code and when they are retrieved as a 


I've written up here a hypothetical application scenario "PhotoSpot" 
which is conceptually an application that can also be run as a 
screensaver. In particular, see how we deal with two methods that have 
the same name but exist on different interfaces. (Note that I haven't 
tried to compile this, should be fine though.)

[Interface ("org.ndesk.Application")]
public interface IApplication
	string GetVersion ();
	void Activate ();

[Interface ("org.ndesk.Screensaver")]
public interface IScreensaver
	void Activate ();

public class PhotoSpot : IApplication, IScreensaver
	public static void Main ()
		if (bus.RequestName ("org.ndesk.PhotoSpot") != 
			throw new Exception ("Failed to acquire bus name");

		Bus.Session.Register (new ObjectPath ("/apps/PhotoSpot", new PhotoSpot 

		//run your main loop here

	public string GetVersion ()
		return "1.0";

	public void Activate ()
		showMainUI ();

	void IScreensaver.Activate ()
		showScreenSaver ();

More information about the dbus mailing list