Skip to content

Commit

Permalink
Merge pull request #389 from mischief/peer
Browse files Browse the repository at this point in the history
introspect: add Peer to introspection
  • Loading branch information
guelfey authored Nov 9, 2024
2 parents a817f3c + fd6e54d commit f6c9fa2
Show file tree
Hide file tree
Showing 2 changed files with 37 additions and 5 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
26 changes: 21 additions & 5 deletions introspect/introspectable.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,19 +16,35 @@ import (
type Introspectable string

// NewIntrospectable returns an Introspectable that returns the introspection
// data that corresponds to the given Node. If n.Interfaces doesn't contain the
// data for org.freedesktop.DBus.Introspectable, it is added automatically.
// data that corresponds to the given Node.
//
// If n.Interfaces doesn't contain the data for
// org.freedesktop.DBus.Introspectable or org.freedesktop.DBus.Peer, they are
// 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 f6c9fa2

Please sign in to comment.