In contrast to the first two projects, in which signals selected by a Gambas client from other d-bus-compatible applications were only intercepted on the D-Bus and some of the content in the variant array argument was also evaluated, two projects are presented here with which you can send a self-defined signal (server) or intercept and evaluate (client) on the one hand:
Figure 18.104.22.168.1: Signal transmitter
The source code for a project with which D-Bus signals are also to be transmitted always includes the preparation of the signal to be transmitted in a special class file - whose name you can freely define - and the actual signal transmitter in the start class, for example in the FMain.class.
The signal to be transmitted is processed in the class file SGBVersion.class. The prefix S stands for signal definition and GBVersion for the signal name, which is also called member. You can define the signal name yourself:
 ' Gambas class file   Inherits DBusObject  Create Static   ' (Pseudo-) signature of the list of arguments: "s" => String   Event org_gambas_SignalTX_SGBVersion_GBVersion(Version As String)
The signal to be transmitted can be processed quickly. The class SGBVersion.class inherits in line 3 from the class DBusObject. Therefore, each instance of SGBVersion.class is of the data type DBusObject. The signal is defined in line 8. A D-Bus signal is defined as an event in Gambas. For the syntax of the signals to be sent, refer to chapter 22.214.171.124.4 Sending Signals. Since the signature of the signal is “s” - only one string is sent - the list of arguments consists of only one element: Version with the data type String. The native Gambas data type'String' is automatically converted to the appropriate D-Bus data type during transmission.
Before you can send a signal, you must export the DBus object in which the signal was defined (SGBVersion.class) with the method DBus.Raise(…) or DBus[AppName].Raise(…) to the Session D-Bus, so that d-bus-enabled programs can observe the defined signals.
Source text sender:
 ' Gambas class file   Private $sDBusName As String  Private $hDBusObject As SGBVersion  Private $sDBusObjectPath As String   Public Sub Form_Open()   FMain.Resizable = False  DBus.Unique = True  ' For tests only: DBus.Debug = True   $hDBusObject = New SGBVersion  $sDBusObjectPath = "/SGBVersion"   DBus.Session.Register($hDBusObject, $sDBusObjectPath)   End   Public Sub btnSendSignal_Click()   lblCaption.Foreground = Color.Red  SendSignal()  Wait 0.1  lblCaption.Foreground = Color.Black   End   Private Sub SendSignal()   Dim aArguments As New Variant   aArguments.Add(System.FullVersion)   DBus.Raise($hDBusObject, "org.gambas.SignalTX.SGBVersion.GBVersion", aArguments)  ' $sDBusName = DBus.Name  ' DBus[$sDBusName].Raise($hDBusObject, "org.gambas.SignalTX.SGBVersion.GBVersion", aArguments)   End   Public Sub Form_Close()   If DBus.IsRegistered($hDBusObject) Then DBus.Session.Unregister($hDBusObject)  FMain.Close()   End
The client SignalRX observes the signal with the name'GBVersion' and the D-Bus object path '/SGBVersion' of the application with the D-Bus name org.gambas.SignalTX on the Session-D-Bus. When the signal arrives, the content - the current Gambas version on the system - is read out and displayed in a text area together with the preceding date and the current time:
Figure 126.96.36.199.2: Signal receiver
The complete source code for the client is specified and then commented:
 ' Gambas class file   Private $hDBusSignal As DBusSignal  Private $sDBusInterface As String  Private $sDBusSignalName As String   Public Sub Form_Open()   Dim sMessage As String   If Not DBus.Session.Applications.Exist("org.gambas.SignalTX") Then  sMessage = ("There is no suitable data server on the session bus!")  sMessage &= "<center><font color='red'>"  sMessage &= ("The program is terminated.")  sMessage &= "</font></center>"  Message.Warning(sMessage)  Quit  Endif   FMain.Resizable = False  lblCaption.Text = ("WATCHING SPECIAL SIGNAL")  ' For tests only: DBus.Debug = True   $sDBusInterface = "org.gambas.SignalTX.SGBVersion"  $sDBusSignalName = "GBVersion" ' The signal name is called 'Member'   $hDBusSignal = New DBusSignal(DBus.Session, $sDBusInterface, True) As "ObservedSignal"   End   Public Sub ObservedSignal_Signal(Signal As String, Arguments As Variant)   If Signal = $sDBusSignalName Then  TextArea1.Insert("Zeit: " & Format(Now(), "dd.mm.yyyy hh:nn:ss") & " Signal-Name: " & Signal & " -> " & Arguments & gb.NewLine)  TextArea1.Pos = TextArea1.Length  Endif   End   Public Sub Form_Close()   If $hDBusSignal Then $hDBusSignal.Enabled = False  FMain.Close()   End
Figure 188.8.131.52.3: Wrong start…