Skip to content

Commit 46c61fd

Browse files
authored
feat(gap): add GAPDevice as base interface (#429)
* feat(gap): add DeviceInterface as base interface All platforms implementation of Device must now satisfy the interface. This makes it easier to change the contract of a device accross platforms. * remove stub implementations I did not realize the implemention was on others files * add stub implementation for s113v7 * rename DeviceInterface to GAPDevice
1 parent 80414ef commit 46c61fd

8 files changed

Lines changed: 63 additions & 0 deletions

File tree

gap.go

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -130,6 +130,13 @@ func NewDuration(interval time.Duration) Duration {
130130
// Connection is a numeric identifier that indicates a connection handle.
131131
type Connection uint16
132132

133+
// GAPDevice is the shared interface that all platform-specific Device types must implement.
134+
type GAPDevice interface {
135+
DiscoverServices(uuids []UUID) ([]DeviceService, error)
136+
RequestConnectionParams(params ConnectionParams) error
137+
Disconnect() error
138+
}
139+
133140
// ScanResult contains information from when an advertisement packet was
134141
// received. It is passed as a parameter to the callback of the Scan method.
135142
type ScanResult struct {

gap_darwin.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -83,6 +83,8 @@ func (a *Adapter) StopScan() error {
8383
return nil
8484
}
8585

86+
var _ GAPDevice = Device{}
87+
8688
// Device is a connection to a remote peripheral.
8789
type Device struct {
8890
Address Address

gap_hci.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -267,6 +267,8 @@ type notificationRegistration struct {
267267
callback func([]byte)
268268
}
269269

270+
var _ GAPDevice = Device{}
271+
270272
// Device is a connection to a remote peripheral.
271273
type Device struct {
272274
Address Address

gap_linux.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -430,6 +430,8 @@ func makeScanResult(props map[string]dbus.Variant) ScanResult {
430430
}
431431
}
432432

433+
var _ GAPDevice = Device{}
434+
433435
// Device is a connection to a remote bluetooth device.
434436
type Device struct {
435437
Address Address // the MAC address of the device

gap_nrf51.go

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -108,3 +108,21 @@ func (a *Adapter) SetRandomAddress(mac MAC) error {
108108
}
109109
return nil
110110
}
111+
112+
// Disconnect from the BLE device.
113+
func (d Device) Disconnect() error {
114+
return errNotYetImplmented
115+
}
116+
117+
// DiscoverServices starts a service discovery procedure.
118+
func (d Device) DiscoverServices(uuids []UUID) ([]DeviceService, error) {
119+
return nil, errNotYetImplmented
120+
}
121+
122+
// RequestConnectionParams requests a different connection latency and timeout
123+
// of the given device connection.
124+
func (d Device) RequestConnectionParams(params ConnectionParams) error {
125+
return errNotYetImplmented
126+
}
127+
128+
type DeviceService struct{}

gap_s113v7.go

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
//go:build softdevice && s113v7
2+
3+
package bluetooth
4+
5+
/*
6+
// Add the correct SoftDevice include path to CFLAGS, so #include will work as
7+
// expected.
8+
#cgo CFLAGS: -Is113_nrf52_7.0.1/s113_nrf52_7.0.1_API/include
9+
*/
10+
import "C"
11+
12+
// Disconnect from the BLE device.
13+
func (d Device) Disconnect() error {
14+
return errNotYetImplmented
15+
}
16+
17+
// DiscoverServices starts a service discovery procedure.
18+
func (d Device) DiscoverServices(uuids []UUID) ([]DeviceService, error) {
19+
return nil, errNotYetImplmented
20+
}
21+
22+
// RequestConnectionParams requests a different connection latency and timeout
23+
// of the given device connection.
24+
func (d Device) RequestConnectionParams(params ConnectionParams) error {
25+
return errNotYetImplmented
26+
}
27+
28+
type DeviceService struct{}

gap_sd.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,8 @@ package bluetooth
77
*/
88
import "C"
99

10+
var _ GAPDevice = Device{}
11+
1012
// Device is a connection to a remote peripheral or central.
1113
type Device struct {
1214
Address Address

gap_windows.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -282,6 +282,8 @@ func (a *Adapter) StopScan() error {
282282
return a.watcher.Stop()
283283
}
284284

285+
var _ GAPDevice = Device{}
286+
285287
// Device is a connection to a remote peripheral.
286288
type Device struct {
287289
ctx context.Context

0 commit comments

Comments
 (0)