forked from holoplot/go-avahi
-
Notifications
You must be signed in to change notification settings - Fork 0
/
host-name-resolver.go
51 lines (39 loc) · 1.2 KB
/
host-name-resolver.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
package avahi
import (
"fmt"
dbus "github.com/godbus/dbus/v5"
)
// A HostNameResolver can resolve host names
type HostNameResolver struct {
object dbus.BusObject
FoundChannel chan HostName
}
// HostNameResolverNew returns a new HostNameResolver
func HostNameResolverNew(conn *dbus.Conn, path dbus.ObjectPath) (*HostNameResolver, error) {
c := new(HostNameResolver)
c.object = conn.Object("org.freedesktop.Avahi.HostNameResolver", path)
c.FoundChannel = make(chan HostName, 10)
return c, nil
}
func (c *HostNameResolver) interfaceForMember(method string) string {
return fmt.Sprintf("%s.%s", "org.freedesktop.Avahi.HostNameResolver", method)
}
func (c *HostNameResolver) free() {
c.object.Call(c.interfaceForMember("Free"), 0)
}
func (c *HostNameResolver) getObjectPath() dbus.ObjectPath {
return c.object.Path()
}
func (c *HostNameResolver) dispatchSignal(signal *dbus.Signal) error {
if signal.Name == c.interfaceForMember("Found") {
var hostName HostName
err := dbus.Store(signal.Body, &hostName.Interface, &hostName.Protocol,
&hostName.Name, &hostName.Aprotocol, &hostName.Address,
&hostName.Flags)
if err != nil {
return err
}
c.FoundChannel <- hostName
}
return nil
}