User Tools

Site Tools


Sidebar

Network and communication

k24:k24.9:k24.9.7:start

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-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!

24.9.7.1 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

  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:

B1
Figure 24.9.7.1.1: Output

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.

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

Download

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: 16.08.2022 (external edit)

Page Tools