Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

introspect: add Peer to introspection #389

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading