Skip to content

Commit 92e255c

Browse files
authored
Merge pull request #7 from skiptools/bridge
Enable bridging
2 parents e7fb5e5 + 981b6a6 commit 92e255c

15 files changed

+98
-70
lines changed

Sources/SkipBluetooth/CBATTRequest.swift

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ import Foundation
66
import android.bluetooth.BluetoothGattCharacteristic
77
import android.bluetooth.BluetoothDevice
88

9-
open class CBATTRequest : NSObject {
9+
open class CBATTRequest {
1010

1111
open private(set) var central: CBCentral
1212

@@ -17,10 +17,10 @@ open class CBATTRequest : NSObject {
1717
open var value: Data?
1818
}
1919

20-
internal extension CBATTRequest: Identifiable {
21-
var id: Int
20+
extension CBATTRequest: Identifiable {
21+
open var id: Int
2222

23-
init(device: BluetoothDevice,
23+
internal init(device: BluetoothDevice,
2424
characteristic: BluetoothGattCharacteristic,
2525
offset: Int,
2626
value: ByteArray?,

Sources/SkipBluetooth/CBAttribute.swift

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,14 +3,16 @@
33
import Foundation
44

55
#if SKIP
6-
open class CBAttribute: NSObject, Equatable {
6+
open class CBAttribute {
77
open var uuid: CBUUID
88

99
internal init(uuid: CBUUID) {
1010
self.uuid = uuid
1111
}
12+
}
1213

13-
static func == (lhs: CBAttribute, rhs: CBAttribute) -> Bool {
14+
extension CBAttribute: Equatable {
15+
public static func == (lhs: CBAttribute, rhs: CBAttribute) -> Bool {
1416
return lhs.uuid.uuidString == rhs.uuid.uuidString
1517
}
1618
}

Sources/SkipBluetooth/CBCentral.swift

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -18,13 +18,14 @@ extension CBCentral: Equatable {
1818
}
1919
}
2020

21-
internal extension CBCentral: KotlinConverting<BluetoothDevice> {
22-
init(platformValue: BluetoothDevice) {
21+
extension CBCentral: KotlinConverting<android.bluetooth.BluetoothDevice> {
22+
internal init(platformValue: BluetoothDevice) {
2323
super.init(macAddress: platformValue.address)
2424
self.device = platformValue
2525
}
2626

27-
override func kotlin(noCopy: Bool) -> BluetoothDevice {
27+
// SKIP @nooverride
28+
public override func kotlin(noCopy: Bool) -> android.bluetooth.BluetoothDevice {
2829
device
2930
}
3031
}

Sources/SkipBluetooth/CBCentralManager.swift

Lines changed: 12 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -244,6 +244,7 @@ public protocol CBCentralManagerDelegate {
244244

245245
@available(*, unavailable)
246246
func centralManager(_ central: CBCentralManager, willRestoreState dict: [String : Any])
247+
247248
func centralManager(_ central: CBCentralManager, didDiscover peripheral: CBPeripheral, advertisementData: [String : Any], rssi RSSI: NSNumber)
248249

249250
func centralManagerDidConnect(central: CBCentralManager, peripheral: CBPeripheral)
@@ -258,15 +259,17 @@ public protocol CBCentralManagerDelegate {
258259
func centralManagerDidUpdateANCSAuthorizationFor(central: CBCentralManager, peripheral: CBPeripheral)
259260
}
260261

261-
public extension CBCentralManagerDelegate {
262-
func centralManager(_ central: CBCentralManager, didDiscover peripheral: CBPeripheral, advertisementData: [String : Any], rssi RSSI: NSNumber) { return }
263-
func centralManager(_ central: CBCentralManager, willRestoreState dict: [String : Any]) {}
264-
func centralManager(_ central: CBCentralManager, didDisconnectPeripheral peripheral: CBPeripheral, timestamp: CFAbsoluteTime, isReconnecting: Bool, error: (any Error)?) { return }
265-
func centralManager(_ central: CBCentralManager, connectionEventDidOccur event: CBConnectionEvent, for peripheral: CBPeripheral) { return }
266-
func centralManagerDidConnect(central: CBCentralManager, peripheral: CBPeripheral) { return }
267-
func centralManager(_ central: CBCentralManager, didFailToConnect peripheral: CBPeripheral, error: (any Error)?) { return }
268-
func centralManagerDidUpdateANCSAuthorizationFor(central: CBCentralManager, peripheral: CBPeripheral) { return }
269-
func centralManagerDidDisconnectPeripheral(_ central: CBCentralManager, peripheral: CBPeripheral, error: (any Error)?) { }
262+
extension CBCentralManagerDelegate {
263+
public func centralManager(_ central: CBCentralManager, didDiscover peripheral: CBPeripheral, advertisementData: [String : Any], rssi RSSI: NSNumber) { return }
264+
@available(*, unavailable)
265+
public func centralManager(_ central: CBCentralManager, willRestoreState dict: [String : Any]) {}
266+
public func centralManager(_ central: CBCentralManager, didDisconnectPeripheral peripheral: CBPeripheral, timestamp: CFAbsoluteTime, isReconnecting: Bool, error: (any Error)?) { return }
267+
public func centralManager(_ central: CBCentralManager, connectionEventDidOccur event: CBConnectionEvent, for peripheral: CBPeripheral) { return }
268+
public func centralManagerDidConnect(central: CBCentralManager, peripheral: CBPeripheral) { return }
269+
public func centralManager(_ central: CBCentralManager, didFailToConnect peripheral: CBPeripheral, error: (any Error)?) { return }
270+
@available(*, unavailable)
271+
public func centralManagerDidUpdateANCSAuthorizationFor(central: CBCentralManager, peripheral: CBPeripheral) { return }
272+
public func centralManagerDidDisconnectPeripheral(_ central: CBCentralManager, peripheral: CBPeripheral, error: (any Error)?) { }
270273
}
271274

272275
#endif

Sources/SkipBluetooth/CBCharacteristic.swift

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -85,8 +85,9 @@ open class CBCharacteristic : CBAttribute {
8585
}
8686
}
8787

88-
public extension CBCharacteristic: KotlinConverting<BluetoothGattCharacteristic> {
89-
public override func kotlin(nocopy: Bool) -> BluetoothGattCharacteristic {
88+
extension CBCharacteristic: KotlinConverting<android.bluetooth.BluetoothGattCharacteristic> {
89+
// SKIP @nooverride
90+
public override func kotlin(nocopy: Bool) -> android.bluetooth.BluetoothGattCharacteristic {
9091
return characteristic
9192
}
9293
}
@@ -109,8 +110,8 @@ open class CBMutableCharacteristic: CBCharacteristic {
109110

110111
// The getter is handled by `CBCharacteristic`, the setter is unimplemented
111112
@available(*, unavailable)
112-
override var properties: CBCharacteristicProperties
113-
override var value: Data?
113+
open override var properties: CBCharacteristicProperties
114+
open override var value: Data?
114115

115116
/* Although `CBCharacteristic` handles setting this value,
116117
there is no logic here to set the underlying characteristic's descriptor value.

Sources/SkipBluetooth/CBDescriptor.swift

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,10 +9,18 @@ open class CBDescriptor: CBAttribute {
99

1010
@available(*, unavailable)
1111
open var value: Any? { fatalError() }
12+
13+
public init(type UUID: CBUUID, value: Any?) {
14+
super.init(UUID)
15+
}
16+
17+
public init(type UUID: CBUUID) {
18+
super.init(UUID)
19+
}
1220
}
1321

1422
open class CBMutableDescriptor: CBDescriptor {
15-
public init(type UUID: CBUUID, value: Any?) {
23+
public override init(type UUID: CBUUID, value: Any?) {
1624
super.init(UUID)
1725
}
1826
}

Sources/SkipBluetooth/CBError.swift

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ public struct CBError: CustomNSError, Hashable, Error {
1616
}
1717

1818
// NSError Initialization
19+
// SKIP @nobridge
1920
public init(_nsError: NSError) {
2021
self.code = Code(rawValue: _nsError.code) ?? Code.unknown
2122
}
@@ -75,6 +76,7 @@ public struct CBATTError: CustomNSError, Hashable, Error {
7576
}
7677

7778
// NSError Initialization
79+
// SKIP @nobridge
7880
public init(_nsError: NSError) {
7981
self.code = Code(rawValue: _nsError.code) ?? Code.success
8082
}

Sources/SkipBluetooth/CBL2CAPChannel.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
import Foundation
66
public typealias CBL2CAPPSM = UInt16
77

8-
open class CBL2CAPChannel : NSObject {
8+
open class CBL2CAPChannel {
99
@available(*, unavailable)
1010
open var peer: CBPeer! { fatalError() }
1111

Sources/SkipBluetooth/CBManager.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ import android.content.BroadcastReceiver
1111
import android.bluetooth.BluetoothManager
1212
import android.bluetooth.BluetoothAdapter
1313

14-
public class CBManager {
14+
open class CBManager {
1515
let context = ProcessInfo.processInfo.androidContext
1616
private let stateChangedReceiver: StateChangedReceiver
1717
internal var stateChangedHandler: (() -> Void)?

Sources/SkipBluetooth/CBPeer.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ import Foundation
44

55
#if SKIP
66

7-
open class CBPeer: NSObject {
7+
open class CBPeer {
88
open var identifier: UUID
99

1010
required internal init(macAddress: String) {

0 commit comments

Comments
 (0)