30
30
31
31
import CoreBluetooth
32
32
33
- public class CBMCentralManagerMock : NSObject , CBMCentralManager {
33
+ open class CBMCentralManagerMock : NSObject , CBMCentralManager {
34
34
/// Mock RSSI deviation.
35
35
///
36
36
/// Returned RSSI values will be in range
@@ -67,11 +67,11 @@ public class CBMCentralManagerMock: NSObject, CBMCentralManager {
67
67
}
68
68
}
69
69
70
- public weak var delegate : CBMCentralManagerDelegate ?
71
- public var state : CBMManagerState {
70
+ open weak var delegate : CBMCentralManagerDelegate ?
71
+ open var state : CBMManagerState {
72
72
return initialized ? CBMCentralManagerMock . managerState : . unknown
73
73
}
74
- public private( set) var isScanning : Bool
74
+ open private( set) var isScanning : Bool
75
75
private var scanFilter : [ CBMUUID ] ?
76
76
private var scanOptions : [ String : Any ] ?
77
77
@@ -438,7 +438,7 @@ public class CBMCentralManagerMock: NSObject, CBMCentralManager {
438
438
}
439
439
}
440
440
441
- public func scanForPeripherals( withServices serviceUUIDs: [ CBMUUID ] ? ,
441
+ open func scanForPeripherals( withServices serviceUUIDs: [ CBMUUID ] ? ,
442
442
options: [ String : Any ] ? ) {
443
443
// Central manager must be in powered on state.
444
444
guard ensurePoweredOn ( ) else { return }
@@ -479,15 +479,15 @@ public class CBMCentralManagerMock: NSObject, CBMCentralManager {
479
479
}
480
480
}
481
481
482
- public func stopScan( ) {
482
+ open func stopScan( ) {
483
483
// Central manager must be in powered on state.
484
484
guard ensurePoweredOn ( ) else { return }
485
485
isScanning = false
486
486
scanFilter = nil
487
487
scanOptions = nil
488
488
}
489
489
490
- public func connect( _ peripheral: CBMPeripheral ,
490
+ open func connect( _ peripheral: CBMPeripheral ,
491
491
options: [ String : Any ] ? ) {
492
492
// Central manager must be in powered on state.
493
493
guard ensurePoweredOn ( ) else { return }
@@ -516,7 +516,7 @@ public class CBMCentralManagerMock: NSObject, CBMCentralManager {
516
516
}
517
517
}
518
518
519
- public func cancelPeripheralConnection( _ peripheral: CBMPeripheral ) {
519
+ open func cancelPeripheralConnection( _ peripheral: CBMPeripheral ) {
520
520
// Central manager must be in powered on state.
521
521
guard ensurePoweredOn ( ) else { return }
522
522
// Ignore peripherals that are not mocks.
@@ -534,7 +534,7 @@ public class CBMCentralManagerMock: NSObject, CBMCentralManager {
534
534
}
535
535
}
536
536
537
- public func retrievePeripherals( withIdentifiers identifiers: [ UUID ] ) -> [ CBMPeripheral ] {
537
+ open func retrievePeripherals( withIdentifiers identifiers: [ UUID ] ) -> [ CBMPeripheral ] {
538
538
// Starting from iOS 13, this method returns peripherals only in ON state.
539
539
guard ensurePoweredOn ( ) else { return [ ] }
540
540
// Get the peripherals already known to this central manager.
@@ -564,7 +564,7 @@ public class CBMCentralManagerMock: NSObject, CBMCentralManager {
564
564
}
565
565
}
566
566
567
- public func retrieveConnectedPeripherals( withServices serviceUUIDs: [ CBMUUID ] ) -> [ CBMPeripheral ] {
567
+ open func retrieveConnectedPeripherals( withServices serviceUUIDs: [ CBMUUID ] ) -> [ CBMPeripheral ] {
568
568
// Starting from iOS 13, this method returns peripherals only in ON state.
569
569
guard ensurePoweredOn ( ) else { return [ ] }
570
570
// Get the connected peripherals with at least one of the given services
@@ -607,7 +607,7 @@ public class CBMCentralManagerMock: NSObject, CBMCentralManager {
607
607
}
608
608
609
609
@available ( iOS 13 . 0 , * )
610
- public func registerForConnectionEvents( options: [ CBMConnectionEventMatchingOption : Any ] ? ) {
610
+ open func registerForConnectionEvents( options: [ CBMConnectionEventMatchingOption : Any ] ? ) {
611
611
fatalError ( " Mock connection events are not implemented " )
612
612
}
613
613
@@ -623,7 +623,7 @@ public class CBMCentralManagerMock: NSObject, CBMCentralManager {
623
623
624
624
// MARK: - CBPeripheralMock implementation
625
625
626
- public class CBMPeripheralMock : CBMPeer , CBMPeripheral {
626
+ open class CBMPeripheralMock : CBMPeer , CBMPeripheral {
627
627
628
628
/// The parent central manager.
629
629
private let manager : CBMCentralManagerMock
@@ -652,12 +652,12 @@ public class CBMPeripheralMock: CBMPeer, CBMPeripheral {
652
652
/// and iOS had chance to read device name.
653
653
fileprivate var wasConnected : Bool = false
654
654
655
- public var delegate : CBMPeripheralDelegate ?
655
+ open var delegate : CBMPeripheralDelegate ?
656
656
657
- public override var identifier : UUID {
657
+ open override var identifier : UUID {
658
658
return mock. identifier
659
659
}
660
- public var name : String ? {
660
+ open var name : String ? {
661
661
// If the device wasn't connected and has just been scanned first time,
662
662
// return nil. When scanning continued, the Local Name from the
663
663
// advertisement data is returned. When the device was connected, the
@@ -669,12 +669,12 @@ public class CBMPeripheralMock: CBMPeer, CBMPeripheral {
669
669
nil
670
670
}
671
671
@available ( iOS 11 . 0 , tvOS 11 . 0 , watchOS 4 . 0 , * )
672
- public var canSendWriteWithoutResponse : Bool {
672
+ open var canSendWriteWithoutResponse : Bool {
673
673
return _canSendWriteWithoutResponse
674
674
}
675
- public private( set) var ancsAuthorized : Bool = false
676
- public private( set) var state : CBMPeripheralState = . disconnected
677
- public private( set) var services : [ CBMService ] ? = nil
675
+ open private( set) var ancsAuthorized : Bool = false
676
+ open private( set) var state : CBMPeripheralState = . disconnected
677
+ open private( set) var services : [ CBMService ] ? = nil
678
678
679
679
// MARK: Initializers
680
680
@@ -852,7 +852,7 @@ public class CBMPeripheralMock: CBMPeer, CBMPeripheral {
852
852
853
853
// MARK: Service discovery
854
854
855
- public func discoverServices( _ serviceUUIDs: [ CBMUUID ] ? ) {
855
+ open func discoverServices( _ serviceUUIDs: [ CBMUUID ] ? ) {
856
856
// Central manager must be in powered on state.
857
857
guard manager. ensurePoweredOn ( ) else { return }
858
858
guard state == . connected,
@@ -893,7 +893,7 @@ public class CBMPeripheralMock: CBMPeer, CBMPeripheral {
893
893
}
894
894
}
895
895
896
- public func discoverIncludedServices( _ includedServiceUUIDs: [ CBMUUID ] ? ,
896
+ open func discoverIncludedServices( _ includedServiceUUIDs: [ CBMUUID ] ? ,
897
897
for service: CBMService ) {
898
898
// Central manager must be in powered on state.
899
899
guard manager. ensurePoweredOn ( ) else { return }
@@ -951,7 +951,7 @@ public class CBMPeripheralMock: CBMPeer, CBMPeripheral {
951
951
952
952
}
953
953
954
- public func discoverCharacteristics( _ characteristicUUIDs: [ CBMUUID ] ? ,
954
+ open func discoverCharacteristics( _ characteristicUUIDs: [ CBMUUID ] ? ,
955
955
for service: CBMService ) {
956
956
// Central manager must be in powered on state.
957
957
guard manager. ensurePoweredOn ( ) else { return }
@@ -1008,7 +1008,7 @@ public class CBMPeripheralMock: CBMPeer, CBMPeripheral {
1008
1008
}
1009
1009
}
1010
1010
1011
- public func discoverDescriptors( for characteristic: CBMCharacteristic ) {
1011
+ open func discoverDescriptors( for characteristic: CBMCharacteristic ) {
1012
1012
// Central manager must be in powered on state.
1013
1013
guard manager. ensurePoweredOn ( ) else { return }
1014
1014
guard state == . connected,
@@ -1066,7 +1066,7 @@ public class CBMPeripheralMock: CBMPeer, CBMPeripheral {
1066
1066
1067
1067
// MARK: Read requests
1068
1068
1069
- public func readValue( for characteristic: CBMCharacteristic ) {
1069
+ open func readValue( for characteristic: CBMCharacteristic ) {
1070
1070
// Central manager must be in powered on state.
1071
1071
guard manager. ensurePoweredOn ( ) else { return }
1072
1072
guard state == . connected,
@@ -1100,7 +1100,7 @@ public class CBMPeripheralMock: CBMPeer, CBMPeripheral {
1100
1100
}
1101
1101
}
1102
1102
1103
- public func readValue( for descriptor: CBMDescriptor ) {
1103
+ open func readValue( for descriptor: CBMDescriptor ) {
1104
1104
// Central manager must be in powered on state.
1105
1105
guard manager. ensurePoweredOn ( ) else { return }
1106
1106
guard state == . connected,
@@ -1136,7 +1136,7 @@ public class CBMPeripheralMock: CBMPeer, CBMPeripheral {
1136
1136
1137
1137
// MARK: Write requests
1138
1138
1139
- public func writeValue( _ data: Data ,
1139
+ open func writeValue( _ data: Data ,
1140
1140
for characteristic: CBMCharacteristic ,
1141
1141
type: CBMCharacteristicWriteType ) {
1142
1142
// Central manager must be in powered on state.
@@ -1215,7 +1215,7 @@ public class CBMPeripheralMock: CBMPeer, CBMPeripheral {
1215
1215
}
1216
1216
}
1217
1217
1218
- public func writeValue( _ data: Data , for descriptor: CBMDescriptor ) {
1218
+ open func writeValue( _ data: Data , for descriptor: CBMDescriptor ) {
1219
1219
// Central manager must be in powered on state.
1220
1220
guard manager. ensurePoweredOn ( ) else { return }
1221
1221
guard state == . connected,
@@ -1251,7 +1251,7 @@ public class CBMPeripheralMock: CBMPeer, CBMPeripheral {
1251
1251
}
1252
1252
1253
1253
@available ( iOS 9 . 0 , * )
1254
- public func maximumWriteValueLength( for type: CBMCharacteristicWriteType ) -> Int {
1254
+ open func maximumWriteValueLength( for type: CBMCharacteristicWriteType ) -> Int {
1255
1255
// Central manager must be in powered on state.
1256
1256
guard manager. ensurePoweredOn ( ) else { return 0 }
1257
1257
guard state == . connected, let mtu = mock. mtu else {
@@ -1262,7 +1262,7 @@ public class CBMPeripheralMock: CBMPeer, CBMPeripheral {
1262
1262
1263
1263
// MARK: Enabling notifications and indications
1264
1264
1265
- public func setNotifyValue( _ enabled: Bool ,
1265
+ open func setNotifyValue( _ enabled: Bool ,
1266
1266
for characteristic: CBMCharacteristic ) {
1267
1267
// Central manager must be in powered on state.
1268
1268
guard manager. ensurePoweredOn ( ) else { return }
@@ -1304,7 +1304,7 @@ public class CBMPeripheralMock: CBMPeer, CBMPeripheral {
1304
1304
1305
1305
// MARK: Other
1306
1306
1307
- public func readRSSI( ) {
1307
+ open func readRSSI( ) {
1308
1308
// Central manager must be in powered on state.
1309
1309
guard manager. ensurePoweredOn ( ) else { return }
1310
1310
queue. async { [ weak self] in
@@ -1319,11 +1319,11 @@ public class CBMPeripheralMock: CBMPeer, CBMPeripheral {
1319
1319
}
1320
1320
1321
1321
@available ( iOS 11 . 0 , tvOS 11 . 0 , watchOS 4 . 0 , * )
1322
- public func openL2CAPChannel( _ PSM: CBML2CAPPSM ) {
1322
+ open func openL2CAPChannel( _ PSM: CBML2CAPPSM ) {
1323
1323
fatalError ( " L2CAP mock is not implemented " )
1324
1324
}
1325
1325
1326
- public override var hash : Int {
1326
+ open override var hash : Int {
1327
1327
return mock. identifier. hashValue
1328
1328
}
1329
1329
}
0 commit comments