...
1 package dbus
2
3 import (
4 "strconv"
5 "strings"
6 )
7
8
9
10
11 type MatchOption struct {
12 key string
13 value string
14 }
15
16 func formatMatchOptions(options []MatchOption) string {
17 items := make([]string, 0, len(options))
18 for _, option := range options {
19 items = append(items, option.key+"='"+option.value+"'")
20 }
21 return strings.Join(items, ",")
22 }
23
24
25 func WithMatchOption(key, value string) MatchOption {
26 return MatchOption{key, value}
27 }
28
29
30
31 func withMatchType(typ string) MatchOption {
32 return WithMatchOption("type", typ)
33 }
34
35
36 func WithMatchSender(sender string) MatchOption {
37 return WithMatchOption("sender", sender)
38 }
39
40
41 func WithMatchInterface(iface string) MatchOption {
42 return WithMatchOption("interface", iface)
43 }
44
45
46 func WithMatchMember(member string) MatchOption {
47 return WithMatchOption("member", member)
48 }
49
50
51 func WithMatchObjectPath(path ObjectPath) MatchOption {
52 return WithMatchOption("path", string(path))
53 }
54
55
56 func WithMatchPathNamespace(namespace ObjectPath) MatchOption {
57 return WithMatchOption("path_namespace", string(namespace))
58 }
59
60
61 func WithMatchDestination(destination string) MatchOption {
62 return WithMatchOption("destination", destination)
63 }
64
65
66 func WithMatchArg(argIdx int, value string) MatchOption {
67 if argIdx < 0 || argIdx > 63 {
68 panic("range of argument index is 0 to 63")
69 }
70 return WithMatchOption("arg"+strconv.Itoa(argIdx), value)
71 }
72
73
74 func WithMatchArgPath(argIdx int, path string) MatchOption {
75 if argIdx < 0 || argIdx > 63 {
76 panic("range of argument index is 0 to 63")
77 }
78 return WithMatchOption("arg"+strconv.Itoa(argIdx)+"path", path)
79 }
80
81
82 func WithMatchArg0Namespace(arg0Namespace string) MatchOption {
83 return WithMatchOption("arg0namespace", arg0Namespace)
84 }
85
86
87 func WithMatchEavesdrop(eavesdrop bool) MatchOption {
88 return WithMatchOption("eavesdrop", strconv.FormatBool(eavesdrop))
89 }
90
View as plain text