-
Notifications
You must be signed in to change notification settings - Fork 40
/
implementer_static.go
61 lines (50 loc) · 1.47 KB
/
implementer_static.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
// SPDX-FileCopyrightText: 2022 UnionTech Software Technology Co., Ltd.
//
// SPDX-License-Identifier: GPL-3.0-or-later
package dbusutil
import (
"errors"
"reflect"
"github.com/godbus/dbus/v5"
"github.com/godbus/dbus/v5/introspect"
)
func newImplementerStatic(impl Implementer, interfaceName string, structValue reflect.Value) *implementerStatic {
s := &implementerStatic{}
structType := structValue.Type()
s.props = getFieldPropStaticMap(structType, structValue)
// 对旧代码实现兼容
var methods []introspect.Method
if implExt, ok := impl.(ImplementerExt); ok {
methods = getMethods(implExt, implExt.GetExportedMethods())
} else {
methods = getMethodsOld(impl, getMethodDetailMap(structType))
}
s.introspectInterface = introspect.Interface{
Name: interfaceName,
Signals: getSignals(structType),
Properties: getPropsIntrospection(s.props),
Methods: methods,
}
return s
}
type implementerStatic struct {
props map[string]*fieldPropStatic
introspectInterface introspect.Interface
}
func (is *implementerStatic) checkProperty(propName string) error {
_, ok := is.props[propName]
if ok {
return nil
}
return errors.New("property not found")
}
func (is *implementerStatic) checkPropertyValue(propName string, value interface{}) error {
p := is.props[propName]
if p == nil {
return errors.New("property not found")
}
if p.signature != dbus.SignatureOf(value) {
return errors.New("property signature not equal")
}
return nil
}