Skip to content

Commit fd6e54d

Browse files
committed
introspect: add Peer to introspection
without this, there's no Peer interface in the introspection data, even though the interface is already internally handled by this package.
1 parent a817f3c commit fd6e54d

File tree

2 files changed

+37
-5
lines changed

2 files changed

+37
-5
lines changed

introspect/introspect.go

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,22 @@ var IntrospectData = Interface{
1717
},
1818
}
1919

20+
// PeerData is the introspection data for the org.freedesktop.DBus.Peer interface.
21+
var PeerData = Interface{
22+
Name: "org.freedesktop.DBus.Peer",
23+
Methods: []Method{
24+
{
25+
Name: "Ping",
26+
},
27+
{
28+
Name: "GetMachineId",
29+
Args: []Arg{
30+
{"machine_uuid", "s", "out"},
31+
},
32+
},
33+
},
34+
}
35+
2036
// XML document type declaration of the introspection format version 1.0
2137
const IntrospectDeclarationString = `
2238
<!DOCTYPE node PUBLIC "-//freedesktop//DTD D-BUS Object Introspection 1.0//EN"

introspect/introspectable.go

Lines changed: 21 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -16,19 +16,35 @@ import (
1616
type Introspectable string
1717

1818
// NewIntrospectable returns an Introspectable that returns the introspection
19-
// data that corresponds to the given Node. If n.Interfaces doesn't contain the
20-
// data for org.freedesktop.DBus.Introspectable, it is added automatically.
19+
// data that corresponds to the given Node.
20+
//
21+
// If n.Interfaces doesn't contain the data for
22+
// org.freedesktop.DBus.Introspectable or org.freedesktop.DBus.Peer, they are
23+
// added automatically.
2124
func NewIntrospectable(n *Node) Introspectable {
22-
found := false
25+
foundIntrospect := false
26+
foundPeer := false
27+
2328
for _, v := range n.Interfaces {
2429
if v.Name == "org.freedesktop.DBus.Introspectable" {
25-
found = true
30+
foundIntrospect = true
31+
break
32+
}
33+
34+
if v.Name == "org.freedesktop.DBus.Peer" {
35+
foundPeer = true
2636
break
2737
}
2838
}
29-
if !found {
39+
40+
if !foundIntrospect {
3041
n.Interfaces = append(n.Interfaces, IntrospectData)
3142
}
43+
44+
if !foundPeer {
45+
n.Interfaces = append(n.Interfaces, PeerData)
46+
}
47+
3248
b, err := xml.Marshal(n)
3349
if err != nil {
3450
panic(err)

0 commit comments

Comments
 (0)