veyron/lib/bluetooth: Fix build when -tags=veyronbluetooth is not specified
and/or building on non-linux.
Build for the veyron/services/proximity/lib package was failing with:
src/veyron/services/proximity/lib/bluetooth_scanner.go:30: s.device.StartScan undefined (type *bluetooth.Device has no field or method StartScan)
src/veyron/services/proximity/lib/bluetooth_scanner.go:51: s.device.StopScan undefined (type *bluetooth.Device has no field or method StopScan)
src/veyron/services/proximity/lib/bluetooth_scanner.go:52: s.device.Close undefined (type *bluetooth.Device has no field or method Close)
src/veyron/services/proximity/lib/bluetooth_scanner.go:60: s.device.StopScan undefined (type *bluetooth.Device has no field or method StopScan)
src/veyron/services/proximity/lib/bluetooth_scanner.go:61: s.device.Close undefined (type *bluetooth.Device has no field or method Close)
Since https://veyron-review.googlesource.com/#/c/3380/
Change-Id: I991de8fe2eb198ac794f0e37708e0bd792ed051b
diff --git a/lib/bluetooth/bluetooth_common.go b/lib/bluetooth/bluetooth_common.go
index 7d92524..81bd276 100644
--- a/lib/bluetooth/bluetooth_common.go
+++ b/lib/bluetooth/bluetooth_common.go
@@ -1,5 +1,25 @@
package bluetooth
+import (
+ "net"
+ "time"
+
+ "veyron/lib/unit"
+)
+
// Network string for net.Addr implementations used by the bluetooth
// package.
const Network = "bluetooth"
+
+// ScanReading holds a single reading of a Low-Energy scan on the Bluetooth device.
+type ScanReading struct {
+ // Name represents a local name of the remote device. It can also store
+ // arbitrary application-specific data.
+ Name string
+ // MAC is the hardware address of the remote device.
+ MAC net.HardwareAddr
+ // Distance represents the (power-estimated) distance to the remote device.
+ Distance unit.Distance
+ // Time is the time the advertisement packed was received/scanned.
+ Time time.Time
+}
diff --git a/lib/bluetooth/bluetooth_linux.go b/lib/bluetooth/bluetooth_linux.go
index 0ed6cab..4897e60 100644
--- a/lib/bluetooth/bluetooth_linux.go
+++ b/lib/bluetooth/bluetooth_linux.go
@@ -233,19 +233,6 @@
return nil
}
-// ScanReading holds a single reading of a Low-Energy scan on the Bluetooth device.
-type ScanReading struct {
- // Name represents a local name of the remote device. It can also store
- // arbitrary application-specific data.
- Name string
- // MAC is the hardware address of the remote device.
- MAC net.HardwareAddr
- // Distance represents the (power-estimated) distance to the remote device.
- Distance unit.Distance
- // Time is the time the advertisement packed was received/scanned.
- Time time.Time
-}
-
// StartScan initiates a Low-Energy scan on the Bluetooth device. The scan
// will proceed over many duration intervals; within each interval, scan will
// be ON only for a given duration window. All scan readings encountered
diff --git a/lib/bluetooth/bluetooth_other.go b/lib/bluetooth/bluetooth_other.go
index 5ec4815..48acfab 100644
--- a/lib/bluetooth/bluetooth_other.go
+++ b/lib/bluetooth/bluetooth_other.go
@@ -5,25 +5,40 @@
import (
"errors"
"net"
+ "time"
)
+var errNotSupported = errors.New("bluetooth is not supported on this platform")
+
// Device is a struct representing an opened Bluetooth device.
+//
+// However, bluetooth is not supported on this platform so all methods on a device
+// will fail.
type Device struct{}
+func (d *Device) StartScan(scanInterval, scanWindow time.Duration) (<-chan ScanReading, error) {
+ return nil, errNotSupported
+}
+func (d *Device) StopScan() error { return errNotSupported }
+func (d *Device) Close() error { return errNotSupported }
+func (d *Device) StartAdvertising(advInterval time.Duration) error { return errNotSupported }
+func (d *Device) SetAdvertisingPayload(payload string) error { return errNotSupported }
+func (d *Device) StopAdvertising() error { return errNotSupported }
+
// Dial always returns an error since bluetooth is not yet supported
// on this platform.
func Dial(remoteaddr string) (net.Conn, error) {
- return nil, errors.New("bluetooth is not supported on this platform")
+ return nil, errNotSupported
}
// Listen always returns an error since bluetooth is not yet supported
// on this platform.
func Listen(localaddr string) (net.Listener, error) {
- return nil, errors.New("bluetooth is not supported on this platform")
+ return nil, errNotSupported
}
// OpenFirstAvailableDevice always returns an error since bluetooth is
// not yet supported on this platform.
func OpenFirstAvailableDevice() (*Device, error) {
- return nil, errors.New("bluetooth is not supported on this platform")
+ return nil, errNotSupported
}