The DBus (gb.dbus) class manages an application's connection to the session bus or the system bus and inherits from the _DBus virtual class.
The DBus class has the following six properties:
Property | Data type | Description |
---|---|---|
Debug | Boolean | Is True if debugging messages are output after DBus.Debug = True or sets the Boolean value. |
Name | String | The name of the D-Bus application is set or returned. By default, the D-Bus name has the following syntax: org.gambas.<xxx>, where <xxx> is the value of the Application.Name property. Note: The D-Bus name is automatically normalised and adapted to the D-Bus specification. |
Zero | Object | A special object is returned that represents the D-Bus value ZERO. |
Session | DBusConnection | Identifies the connection between an application and the session bus of type DBusConnection. |
System | DBusConnection | Identifies the connection between an application and the system bus of type DBusConnection. |
Unique | Boolean | Is True if an application is registered on the D-Bus with a unique ID or sets the Unique property. Please refer to the following notes. |
Table 24.9.2.1.1 : Properties of the DBus class
Notes on the DBus.Unique property:
In case you set the DBus.Unique property to True.
sDBusApplicationName = org.gambas.projektname
However, for the alternative case DBus.Unique = False (which is the default value), it becomes.
sDBusApplicationName = org.gambas.projektname-PID ' PID = Process Identification Number
Since it is not necessarily known what the current value of DBus.Unique is for a D-Bus server to be used, for example, you can use the following function in the source code for a D-Bus client to determine the correct name of the server on the D-Bus:
Private Function GetDBusApplicationName(GBAppName As String) As String Dim aList As String[] Dim sElement As String aList = DBus.Session.Applications.Sort(gb.Natural) For Each sElement In aList If sElement Begins "org.gambas." & GBApp.Name Then Return sElement Endif Next End
The DBus class has four methods, which are specified and described in the following table:
Method | Description |
---|---|
IsRegistered ( Object As DBusObject ) | The boolean function returns True if the object passed as parameter is registered on the D-Bus. |
Register ( Object As DBusObject, Path As String [ , Interfaces As String[] ] ) | Exports a DBus object to the D-Bus. For the parameters: Object is the D-Bus object to be exported, Path is the D-Bus path for the D-Bus object and Interface (optional) allows you to specify the names of additional interfaces implemented for the D-Bus object used. Details can be found in the documentation under DBusConnection.Register(). |
Unregister ( Object As DBusObject ) | Deregisters the DBus object passed in the parameter from the D-Bus and is the equivalent of DBus.Session.Unregister(). |
Raise ( Object As DBusObject, Signal As String [ , Arguments As Variant[] ] ) |
Table 24.9.2.2.1 : Methods of the DBus class.
Notes:
To determine whether a particular application is currently registered on the D-Bus, you can use the following source code when customising the application name:
If DBus.Session.Applications.Exist($sDBusName) Then
If necessary, you can unregister the objects exported by your Gambas program from the D-Bus again:
Public Sub Form_Close() If DBus.IsRegistered($hDBusObject) Then DBus.Session.Unregister($hDBusObject) FMain.Close() End
The answer to the question 'What is exported to the D-Bus?' depends on whether you use the optional argument Interfaces As String[] in the register method or not.
Register without interfaces:
As soon as you export at least one object, your application will be registered on the D-Bus under the name org.gambas.<applicationname>. For <application name> you can always use the Application.Name property.
All methods and properties whose name starts with an interface name specified in the interface argument - where the dots are replaced by underscores and followed by an additional underscore - are exported under this interface.
Registration with at least one interface:
In chapters 24.9.8.1 and 24.9.8.2 you will find two (server) projects that export objects to the D-Bus.
The following four constants of the DBus class each represent a message type that can take one of the following integer values:
An object representing an application connected to the D-Bus is returned with DBus[…], because the class DBus is static and behaves like a (read-only) array:
Dim hDBusApplication As DBusApplication hDBusApplication = DBus [ Application As String ]
The default value for the Application argument prefix is “session://”.
Examples:
Dim hDBusApplication As DBusApplication Dim hConnection As DBusConnection hConnection = DBus.System hDBusApplication = DBus["system://org.freedesktop.ConsoleKit"]
Dim hDBusApplication As DBusApplication hDBusApplication = DBus["session://org.Cinnamon.LookingGlass"] oder hDBusApplication = DBus["org.Cinnamon.LookingGlass"] Standard-Parameter 'session:\\' intern gesetzt