[Gambas-user] D-Bus method with a complex data type triggers an error
Hans Lehmann
hans at gambas-buch.de
Tue Mar 13 19:29:29 CET 2018
Am 13.03.2018 um 16:58 schrieb Benoît Minisini:
> Struct are not used by gb.dbus.
This is understandable at http://gambaswiki.org/wiki/doc/dbus#t10. I
didn't use such a structure on the D-Bus server either.
> Compound values are returned as an array of variants.
That's how I realized it with three classes.
I oriented myself on the source code of the component gb.dbus.trayicon.
FMain.class:
------------------
Public hDBusObject As TService
Public Sub Form_Open()
hDBusObject = New TService
FMain.Resizable = False
FMain.Caption = ("The data server is activated")
DBus.Unique = True
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
TService.class:
----------------------
Inherits DBusObject
Create Static
Public Function GetTemperature(Trigger As String) As RValue
Dim hItem As RValue
Dim s1, s2, s3, s4 As String
Dim i1, i2, i3, i4 As Integer
Dim f1 As Float
Dim aTime As Variant[]
Dim cTemperature As Collection
i1 = Day(Now())
s1 = Format(Now(), "mmmm")
i2 = Year(Now())
i3 = Hour(Now())
i4 = Minute(Now())
s2 = "UTC"
aTime = [i3, i4, s2]
' The temperature value is read out in real operation from an RS232-AD
converter
f1 = 22.4 '
Select Case Trigger
Case "C"
s3 = "°"
s4 = "C"
Case "K"
f1 = f1 + 273.15
s3 = ""
s4 = "K"
Case "F"
f1 = (9 / 5) * f1 + 32
s3 = "°"
s4 = "F"
End Select
cTemperature["T"] = f1 ' Temperature
cTemperature["L"] = s3 ' Label
cTemperature["S"] = s4 ' Scale
hItem = New RValue
hItem.Value = [i1, s1, i2, aTime, cTemperature] ' <<-- Compound
values are returned as an array of variants.
Return hItem
End
RValue.class:
-------------------
' This class RValue (stands for ReturnValue) is needed to define the
complex return type with the signature' isiava{sv}:
Export
Inherits DBusVariant
Public Const Signature As String = "isiava{sv}"
---
The error occurs at the client in dbusc.class:
Public hDBusProxy As DBusProxy
Public Struct StructVariant
String1 As String
Integer1 As String
String2 As String
Array As Variant[]
Collection As Collection
End Struct
Public structS As New StructVariant
Public Sub Form_Open()
Dim sMessage As String
DBus.Debug = True
FMain.Resizable = False
If Not DBus.Session.Applications.Exist("org.gambas.dbuss") 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)
FMain.Close()
Else
hDBusProxy = DBus["org.gambas.dbuss"]["/TService"]
GetData()
Endif
End
Private Sub GetData()
structS = hDBusProxy.GetTemperature(tboxScale.Text) --> ERROR:
org.freedesktop.DBus.Error.Failed: Zero object?
End
Public Sub btnGetData_Click()
GetData()
End
Public Sub Form_Close()
FMain.Close()
End
The question remains as to why this error occurs?
With kind regards
Hans
More information about the User
mailing list