User Tools

Site Tools


Network and communication


24.9.7 DBusProxy

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-compatible application. This class can be created and has only the Children.

If you call a method or read or set a property, this only applies to the proxy object - not to the original. Note that the names of the methods or properties are case-sensitive. New DBusProxy (gb.dbus)

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:

  • Application is an application object of type DBusApplication.
  • ObjectPath is the absolute path of the DBUS object.
  • The optional parameter Interface identifies the object interface you want to use.
  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

  For i = 0 To aChildren.Max
    txaReport.Insert(sDBusObjectPath &/ aChildren[i] & gb.NewLine)

This output is generated with the penultimate line:


Figure Output

You can find the project DBusNMChildren as a 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 each method and all properties of the (exported) object. Otherwise, you can only access methods and properties of the specified interface. Examples

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.
' 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]


The website uses a temporary session cookie. This technically necessary cookie is deleted when the browser is closed. You can find information on cookies in our privacy policy.
k24/k24.9/k24.9.7/start.txt · Last modified: 02.07.2018 (external edit)

Page Tools