forked from papamitra/go-dbus
-
Notifications
You must be signed in to change notification settings - Fork 9
/
Copy pathmatchrule.go
43 lines (37 loc) · 995 Bytes
/
matchrule.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
package dbus
import "reflect"
import "fmt"
import "strings"
// Matches all messages with equal type, interface, member, or path.
// Any missing/invalid fields are not matched against.
type MatchRule struct {
Type MessageType
Interface string
Member string
Path string
}
// A string representation af the MatchRule (D-Bus variant map).
func (p *MatchRule) String() string {
strslice := []string{}
v := reflect.Indirect(reflect.ValueOf(p))
t := v.Type()
for i := 0; i < v.NumField(); i++ {
strslice = append(strslice, (fmt.Sprintf("%s='%v'", strings.ToLower(t.Field(i).Name), v.Field(i).Interface())))
}
return strings.Join(strslice, ",")
}
func (p *MatchRule) _Match(msg *Message) bool {
if p.Type != TypeInvalid && p.Type != msg.Type {
return false
}
if p.Interface != "" && p.Interface != msg.Iface {
return false
}
if p.Member != "" && p.Member != msg.Member {
return false
}
if p.Path != "" && p.Path != msg.Path {
return false
}
return true
}