The class DBusProxy (gb.dbus) implements a proxy for a D-Bus object that has already been registered on the D-Bus by a d-bus-enabled application. This class can be created and has only the Children property.
If you call a method or read a property or set it, this only applies to the proxy object - but not to the original. Note that the names of the methods or properties are case-sensitive!
For example, use the following source code to create a proxy for the existing DBus object with the absolute path: “/org/freedesktop/NetworkManager”. The Children property returns the names of all current object children in a string array. You get the absolute path of a child by concatenating the absolute path of the current object with the child name. The following applies:
Dim i As Integer Dim hDBusApplication As DBusApplication Dim hConnection As DBusConnection Dim hDBusProxy As DBusProxy Dim sDBusName, sDBusObjectPath, sDBusInterface As String Dim aChildren As New String[] sDBusName = "org.freedesktop.NetworkManager" hConnection = DBus.System hDBusApplication = New DBusApplication(hConnection, sDBusName) sDBusObjectPath = "/org/freedesktop/NetworkManager" sDBusInterface = "org.freedesktop.NetworkManager" hDBusProxy = New DBusProxy(hDBusApplication, sDBusObjectPath, sDBusInterface) aChildren = hDBusProxy.Children txaReport.Insert(gb.NewLine) For i = 0 To aChildren.Max txaReport.Insert(sDBusObjectPath &/ aChildren[i] & gb.NewLine) Next
This output is generated with the penultimate line:
The project DBusNMChildren can be found as project archive in the download area.
Note:Alternatively, use DBus[Application][ObjectPath] as the active proxy, because DBus[Application][ObjectPath] also creates a D-Bus proxy.
If the argument for the optional parameter Interface is not specified, you have access to every method and all properties of the (exported) object. Otherwise, you only have access to methods and properties of the specified interface.
The following proxy examples are taken from the Gambas documentation and consistently use the syntax DBus[Application][ObjectPath]:
' The lock() method call locks the screen. DBus["org.kde.krunner"]["/ScreenSaver"].lock() ' A method call is used to check whether compositing is active. If DBus["org.kde.kwin"]["/KWin"].compositingActive() Then Print "Compositing is active!" ' Get a password from KDE wallet Dim sLocalWallet As String = DBus["org.kde.kwalletd"]["/modules/kwalletd"].localWallet() Dim sWalletId As String=DBus["org.kde.kwalletd"]["/modules/kwalletd"].open(sLocalWallet, Application.Title) Dim sPassword As String = DBus["org.kde.kwalletd"]["/modules/kwalletd"].readPassword(Application.Name, sWalletId, "login", Application.Title) ' Sets the geometry property of the KMail window. DBus["org.kde.kmail"]["/kmail/kmail_mainwindow_1"].geometry = [0, 24, 1024, 768]