forked from JuulLabs-OSS/cbgo
-
Notifications
You must be signed in to change notification settings - Fork 2
/
mutableservice.go
52 lines (40 loc) · 1.36 KB
/
mutableservice.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
package cbgo
/*
// See cutil.go for C compiler flags.
#import "bt.h"
*/
import "C"
import "unsafe"
// MutableService: https://developer.apple.com/documentation/corebluetooth/cbmutableservice
type MutableService struct {
ptr unsafe.Pointer
}
func NewMutableService(uuid UUID, primary bool) MutableService {
cuuid := C.CString(uuid.String())
defer C.free(unsafe.Pointer(cuuid))
return MutableService{
ptr: unsafe.Pointer(C.cb_msvc_alloc(cuuid, C.bool(primary))),
}
}
// Service converts a MutableService into its underlying Service.
func (s MutableService) Service() Service {
return Service{s.ptr}
}
// SetCharacteristics: https://developer.apple.com/documentation/corebluetooth/cbmutableservice/1434317-characteristics
func (s MutableService) SetCharacteristics(mchrs []MutableCharacteristic) {
chrs := mallocObjArr(len(mchrs))
defer C.free(unsafe.Pointer(chrs.objs))
for i, mchr := range mchrs {
setObjArrElem(&chrs, i, mchr.ptr)
}
C.cb_msvc_set_characteristics(s.ptr, &chrs)
}
// SetIncludedServices: https://developer.apple.com/documentation/corebluetooth/cbmutableservice/1434320-includedservices
func (s MutableService) SetIncludedServices(msvcs []MutableService) {
svcs := mallocObjArr(len(msvcs))
defer C.free(unsafe.Pointer(svcs.objs))
for i, msvc := range msvcs {
setObjArrElem(&svcs, i, msvc.ptr)
}
C.cb_msvc_set_included_services(s.ptr, &svcs)
}