User Tools

Site Tools


k24:k24.9:k24.9.1:start

24.9.1 DBusObject

The (static) class DBusObject (gb.dbus) is the parent class for all objects that you can export to the D-Bus.

  • By default, a (Gambas) D-Bus object is not automatically exported to the D-Bus.
  • To export it, the two methods DBusConnection.Register(…) and DBusApplication.Connection.Register(…) are used, among others.

24.9.1.1 Example

Any method you define in a Gambas D-Bus object inherits from the DBusObject class as shown in the source code of TService.class:

' Gambas class file

Inherits DBusObject
Create Static

Public Function GetTemperature(Trigger As String) As RValue
…
End

The source code in FMain.class, for example, declares a (Gambas) D-Bus object of type TService and registers it on the Session D-Bus. If the server is terminated, then the D-Bus object is unregistered from the D-Bus, which made the TService object available for use by all d-bus-enabled applications.

' Gambas class file

Public hDBusObject As TService

Public Sub Form_Open()

  FMain.Resizable = False
  FMain.Caption = ("The data server is activated")
  DBus.Unique = True
  hDBusObject = New TService

  Try DBus.Session.Register(hDBusObject, "/TService")
  If Error Then
     Message.Error("An instance of " & Application.Name & " already exists.")
     FMain.Close()
  Endif

End

Public Sub Form_Close()

  If DBus.IsRegistered(hDBusObject) Then DBus.Session.Unregister(hDBusObject)
  FMain.Close()

End

Two commented server projects can be found in chapters 24.9.8.1 Project1 and 24.9.8.2 Project2.

This website uses cookies. By using the website, you agree with storing cookies on your computer. Also you acknowledge that you have read and understand our Privacy Policy. If you do not agree leave the website.
k24/k24.9/k24.9.1/start.txt · Last modified: by 127.0.0.1