-
Notifications
You must be signed in to change notification settings - Fork 0
/
bluez_gatt_server_service.go
48 lines (43 loc) · 1.1 KB
/
bluez_gatt_server_service.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
package bluez
import (
"github.com/godbus/dbus"
"github.com/pkg/errors"
)
type BlueZGattService struct {
gattService *GattService
blueZGattCharacteristics []*BlueZGattCharacteristic
path dbus.ObjectPath
}
func (self *BlueZGattService) GetAll(iface string) (properties map[string]dbus.Variant, e *dbus.Error) {
names := []string{"UUID", "Primary"}
props := make(map[string]dbus.Variant, 0)
for _, name := range names {
if value, err := self.get(name); err == nil {
props[name] = dbus.MakeVariant(value)
} else {
e = dbus.MakeFailedError(err)
break
}
}
properties = props
return
}
func (self *BlueZGattService) Get(iface string, name string) (variant dbus.Variant, e *dbus.Error) {
if value, err := self.get(name); err == nil {
variant = dbus.MakeVariant(value)
} else {
e = dbus.MakeFailedError(err)
}
return
}
func (self *BlueZGattService) get(name string) (value interface{}, e error) {
switch name {
case "UUID":
value = self.gattService.UUID
case "Primary":
value = true
default:
e = errors.Errorf("Property '%s' not found", name)
}
return
}