call.go 585 B

12345678910111213141516171819202122232425262728
  1. package introspect
  2. import (
  3. "encoding/xml"
  4. "strings"
  5. "github.com/godbus/dbus/v5"
  6. )
  7. // Call calls org.freedesktop.Introspectable.Introspect on a remote object
  8. // and returns the introspection data.
  9. func Call(o dbus.BusObject) (*Node, error) {
  10. var xmldata string
  11. var node Node
  12. err := o.Call("org.freedesktop.DBus.Introspectable.Introspect", 0).Store(&xmldata)
  13. if err != nil {
  14. return nil, err
  15. }
  16. err = xml.NewDecoder(strings.NewReader(xmldata)).Decode(&node)
  17. if err != nil {
  18. return nil, err
  19. }
  20. if node.Name == "" {
  21. node.Name = string(o.Path())
  22. }
  23. return &node, nil
  24. }