-
Notifications
You must be signed in to change notification settings - Fork 40
/
introspectable.go
93 lines (78 loc) · 1.88 KB
/
introspectable.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
// SPDX-FileCopyrightText: 2022 UnionTech Software Technology Co., Ltd.
//
// SPDX-License-Identifier: GPL-3.0-or-later
package dbusutil
import (
"strings"
"github.com/godbus/dbus/v5"
"github.com/godbus/dbus/v5/introspect"
"github.com/godbus/dbus/v5/prop"
"github.com/linuxdeepin/go-lib/strv"
)
var peerIntrospectData = introspect.Interface{
Name: orgFreedesktopDBus + ".Peer",
Methods: []introspect.Method{
{
Name: "Ping",
},
{
Name: "GetMachineId",
Args: []introspect.Arg{
{
Name: "machine_uuid",
Type: "s",
Direction: "out",
},
},
},
},
}
func (so *ServerObject) getChildren() (children strv.Strv) {
var target string
if so.path == "/" {
target = "/"
} else {
target = string(so.path) + "/"
}
for objPath := range so.service.objMap {
if objPath == so.path {
continue
}
if strings.HasPrefix(string(objPath), target) {
tail := string(objPath[len(target):])
idx := strings.Index(tail, "/")
var child string
if idx == -1 {
child = tail
} else {
child = tail[:idx]
}
if child == "" {
continue
} else {
children, _ = children.Add(child)
}
}
}
return
}
func (so *ServerObject) introspectableIntrospect() (string, *dbus.Error) {
so.service.DelayAutoQuit()
node := &introspect.Node{
Interfaces: so.getInterfaces(),
}
for _, child := range so.getChildren() {
node.Children = append(node.Children, introspect.Node{Name: child})
}
// marshal xml
return string(introspect.NewIntrospectable(node)), nil
}
func (so *ServerObject) getInterfaces() []introspect.Interface {
var interfaces []introspect.Interface
for _, impl := range so.implementers {
implStatic := impl.getStatic(so.service)
interfaces = append(interfaces, implStatic.introspectInterface)
}
interfaces = append(interfaces, introspect.IntrospectData, prop.IntrospectData, peerIntrospectData)
return interfaces
}