[Gambas-user] DBus - How are signal data converted to Gambas data?

T Lee Davidson t.lee.davidson at gmail.com
Sat Jan 27 20:46:57 CET 2018


I couldn't fine the book, 'D-Bus with gb.dbus', you referred to, but the output of 'dbus-monitor' (whatever that is exactly)
indicates that Arguments[2] is of type 'struct'. Have you considered using a Structure?

PUBLIC STRUCT theVariant

  String1 AS String
  String2 AS String
  String3 AS String
  String4 AS String
  String5 AS String
  String6 AS String
  Boolean1 AS Boolean
  Boolean2 AS Boolean
  String7 AS String
  String8 AS String
  Collection1 AS Collection
  String9 AS String
  Collection2 AS Collection

END STRUCT

See: http://gambaswiki.org/wiki/lang/structdecl


-- 
Lee


On 01/26/2018 10:26 AM, Hans Lehmann wrote:
> Hello,
> 
> in a project for the Gambas book on 'D-Bus with gb.dbus' I have the problem to read the arguments of a particular signal. In the
> text of the XML document (Inspection) I found the number of expected arguments, their names and the signatures. Through the
> output of the console program, I knew all the values of the three arguments.
> 
> Cutout Introspection-XML-Document:
> ----------------------------------------------------
> 
> ...
> <signal name="VolumeAdded">
>    <arg type="s" name="dbus_name"/>
>    <arg type="s" name="id"/>
>    <arg type="(ssssssbbssa{ss}sa{sv})" name="volume"/>
> </signal>
> ...
> 
> Output of 'dbus-monitor' after inserting the USB stick with label '2_GB_P':
> ------------------------------------------------------------------------------------------------------
> 
> ...
> signal sender=:1.10 -> dest=(null destination) serial=173 path=/org/gtk/Private/RemoteVolumeMonitor;
> interface=org.gtk.Private.RemoteVolumeMonitor; member=VolumeAdded
>    string "org.gtk.Private.UDisks2VolumeMonitor"
>    string "0x1449bd0"
>    struct {
>       string "0x1449bd0"
>       string "2_GB_P"
>       string ". GThemedIcon drive-removable-media-usb drive-removable-media drive-removable drive"
>       string ". GThemedIcon drive-removable-media-usb-symbolic ... drive-symbolic drive-removable-media-usb
> drive-removable-media drive-removable drive"
>       string ""
>       string ""
>       boolean true
>       boolean true
>       string "0x14af500"
>       string ""
>       array [
>          dict entry(
>             string "class"
>             string "device"
>          )
>          dict entry(
>             string "unix-device"
>             string "/dev/sdd1"
>          )
>          dict entry(
>             string "label"
>             string "2_GB_P"
>          )
>          dict entry(
>             string "uuid"
>             string "38ea6e0b-a161-401d-a673-11c06cf1229e"
>          )
>       ]
>       string "gvfs.time_detected_usec.1516884992931147"
>       array [
>       ]
>    }
> ...
> 
> With the following source code I can read the arguments 0 and 1, since they have simple data types. From argument 2, I can only
> read the values with simple data types.
> 
> *Therefore, my question: Which way do I have to go - certainly about the class DBusValues, whose documentation I do not
> understand - in order to read out the values of all arguments safely and to map them to Gambas types?*
> 
> Gambas-Code-Cutout
> ------------------
> 
> Public Sub theDBusSignal_Signal(Signal As String, Arguments As Variant[])
> 
>   Dim vElement As Variant
>   Dim i As Integer
>   Dim aDBusArray As New BusValue
> 
>   If Signal = "VolumeAdded" Or Signal = "VolumeRemoved" Then
> 
>      txaResults.Insert("Number of Arguments from 'Arguments' = " & Arguments.Count & gb.NewLine)
>      txaResults.Insert("Arguments[0] = " & Arguments[0] & gb.NewLine)
>      txaResults.Insert("Arguments[1] = " & Arguments[1] & gb.NewLine)
> txaResults.Insert("~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~" & gb.NewLine)
> 
>      For i = 0 To Arguments[2].Max
>      '   txaResults.Insert("[2][" & Str(i) & "]" & " -> " & Arguments[2][i] & gb.NewLine)
>          txaResults.Insert(TypeOf(Arguments[2][i]) & gb.NewLine)
>      Next
> 
>      Print "Number of Arguments from 'Arguments' = "; Arguments.Count
> 
>      Print "Argument[0] = "; Arguments[0]
>      Print "Arguments[1] = "; Arguments[1]; " | Typ = "; TypeOf(Arguments[1])
>      Print "Arguments[2] = "; Arguments[2]; " | Typ = "; TypeOf(Arguments[2])
> 
>      For Each vElement In Arguments
>        Print vElement
>      Next
> 
>      For i = 0 To Arguments[2].Max
>        Print "[2]["; i; "]"; " -> "; Arguments[2][i]
>      Next
> 
>   Endif
> 
> End
> 
> Cutout Console:
> ---------------------
> 
> Number of Arguments from 'Arguments' = 3
> ---------------------------------------------------------
> Argument[0] = org.gtk.Private.UDisks2VolumeMonitor
> Arguments[1] = 0x1449bd0 | Typ = 9
> Arguments[2] = (Variant[] 0x16ac228) | Typ = 16
> ---------------------------------------------------------
> org.gtk.Private.UDisks2VolumeMonitor
> 0x1449bd0
> (Variant[] 0x16ac228)
> ---------------------------------------------------------
> [2][0] -> 0x1449bd0
> [2][1] -> 2_GB_P
> [2][2] -> . GThemedIcon drive-removable-media-usb ... drive-removable drive
> [2][3] -> . GThemedIcon drive-removable-media-usb-symbolic ...drive-removable-media-usb
> [2][4] ->
> [2][5] ->
> [2][6] -> True
> [2][7] -> True
> [2][8] ->
> [2][9] ->
> [2][10] -> (Collection 0x16ac048)
> [2][11] -> gvfs.time_detected_usec.1516884992931147
> [2][12] -> (Collection 0x16ac188)
> 
> With kind regards
> 
> Hans
> 
> --------------------------------------------------
> 
> This is the Gambas Mailing List
> https://lists.gambas-basic.org/listinfo/user
> 
> Hosted by https://www.hostsharing.net


More information about the User mailing list