-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathagent.go
62 lines (51 loc) · 1.14 KB
/
agent.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
package connman
import (
"fmt"
"log"
"github.com/godbus/dbus"
)
type Agent struct {
Name string
Path dbus.ObjectPath
Interface string
Passphrase string
}
func NewAgent(psk string) *Agent {
agent := &Agent{
Name: "net.connman",
Path: "/test/agent",
Interface: "net.connman.Agent",
Passphrase: psk,
}
conn, err := dbus.SystemBus()
if err != nil {
fmt.Println(err)
return nil
}
conn.Export(agent, agent.Path, agent.Interface)
return agent
}
func (a *Agent) Destroy() error {
conn, err := dbus.SystemBus()
if err != nil {
return err
}
reply, err := conn.ReleaseName(a.Name)
if err != nil {
return err
}
if reply != dbus.ReleaseNameReplyReleased {
return fmt.Errorf("Could not release the name\n")
}
conn.Export(nil, a.Path, a.Interface)
return nil
}
func (a *Agent) RequestInput(service dbus.ObjectPath, rq map[string]dbus.Variant) (map[string]dbus.Variant, *dbus.Error) {
return map[string]dbus.Variant{
"Passphrase": dbus.MakeVariant(a.Passphrase),
}, nil
}
func (a *Agent) ReportError(service dbus.ObjectPath, err string) *dbus.Error {
log.Printf("%s: %s\n", service, err)
return nil
}