Skip to content

Commit

Permalink
introspect: add Peer to introspection
Browse files Browse the repository at this point in the history
without this, there's no Peer interface in the introspection data, even
though the interface is already internally handled by this package.
  • Loading branch information
mischief authored and guelfey committed Sep 21, 2024
1 parent 6bb5ed0 commit 5fd8576
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 3 deletions.
16 changes: 16 additions & 0 deletions introspect/introspect.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,22 @@ var IntrospectData = Interface{
},
}

// PeerData is the introspection data for the org.freedesktop.DBus.Peer interface.
var PeerData = Interface{
Name: "org.freedesktop.DBus.Peer",
Methods: []Method{
{
Name: "Ping",
},
{
Name: "GetMachineId",
Args: []Arg{
{"machine_uuid", "s", "out"},
},
},
},
}

// XML document type declaration of the introspection format version 1.0
const IntrospectDeclarationString = `
<!DOCTYPE node PUBLIC "-//freedesktop//DTD D-BUS Object Introspection 1.0//EN"
Expand Down
19 changes: 16 additions & 3 deletions introspect/introspectable.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,16 +19,29 @@ type Introspectable string
// data that corresponds to the given Node. If n.Interfaces doesn't contain the
// data for org.freedesktop.DBus.Introspectable, it is added automatically.
func NewIntrospectable(n *Node) Introspectable {
found := false
foundIntrospect := false
foundPeer := false

for _, v := range n.Interfaces {
if v.Name == "org.freedesktop.DBus.Introspectable" {
found = true
foundIntrospect = true
break
}

if v.Name == "org.freedesktop.DBus.Peer" {
foundPeer = true
break
}
}
if !found {

if !foundIntrospect {
n.Interfaces = append(n.Interfaces, IntrospectData)
}

if !foundPeer {
n.Interfaces = append(n.Interfaces, PeerData)
}

b, err := xml.Marshal(n)
if err != nil {
panic(err)
Expand Down

0 comments on commit 5fd8576

Please sign in to comment.