Blame view

HDFwear/3rd/RTKOTASDK/RTKLEFoundation.framework/Headers/RTKLEProfile.h 5.79 KB
75d24c15   yangbin   123
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
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
  //
  //  RTKLEProfile.h
  //  RTKLEFoundation
  //
  //  Created by jerome_gu on 2019/4/10.
  //  Copyright © 2019 Realtek. All rights reserved.
  //
  
  #import <Foundation/Foundation.h>
  #import <CoreBluetooth/CoreBluetooth.h>
  
  #ifdef RTK_SDK_IS_STATIC_LIBRARY
  #import "RTKLEPeripheral.h"
  #else
  #import <RTKLEFoundation/RTKLEPeripheral.h>
  #endif
  
  
  NS_ASSUME_NONNULL_BEGIN
  
  @class RTKLEProfile;
  
  
  /**
   * The RTKLEProfileDelegate protocol defines methods that a delegate of a RTKLEProfile object must adopt.
   */
  @protocol RTKLEProfileDelegate <NSObject>
  @required
  /**
   * Invoked when the underlying central managers state is updated.
   * @discussion Commands should only be issued when the underlying central manager state is <code>CBCentralManagerStatePoweredOn</code>
   */
  - (void)profileManagerDidUpdateState:(RTKLEProfile *)profile;
  
  
  @optional
  
  /**
   * Invoked when the Profile discovers a peripheral while scanning.
   *
   * @discussion Depend on the concrete Profile class, only interested peripheral is discovered. The discovered peripheral is typically a subclass of RTKLEPeripheral, which may provide more methods to operate with peripheral.
   */
  - (void)profile:(RTKLEProfile *)profile didDiscoverPeripheral:(RTKLEPeripheral *)peripheral;
  
  
  /**
   * Invoked when a connection is successfully created with a peripheral.
   *
   * @discussion You typically implement this method to perform specific operation.
   */
  - (void)profile:(RTKLEProfile *)profile didConnectPeripheral:(RTKLEPeripheral *)peripheral;
  
  /**
   * Invoked when the central manager fails to create a connection with a peripheral.
   *
   * @discussion Unlike the CBCentralManager, this connect methods of RTKLEProfile will time out. When connection time out, the error parameter has a RTKErrorTimeout code.
   */
  - (void)profile:(RTKLEProfile *)profile didFailToConnectPeripheral:(RTKLEPeripheral *)peripheral error:(nullable NSError *)error;
  
  /**
   * Invoked when an existing connection with a peripheral is torn down.
   */
  - (void)profile:(RTKLEProfile *)profile didDisconnectPeripheral:(RTKLEPeripheral *)peripheral error:(nullable NSError *)error;
  
  @end
  
  
  
  /**
   * RTKLEProfile objects are used to manage scanning, connecting to peripherals.
   *
   * @discussion Before you call any methods, the underlying CBCentralManager should be in CBManagerStatePoweredOn state.
   */
  @interface RTKLEProfile : NSObject <CBCentralManagerDelegate> {
      @protected
      CBCentralManager *_centralManager;
  }
  
  - (instancetype)initWithDelegate:(nullable id <RTKLEProfileDelegate>)delegate;
  
  // Protected accessors
  @property (readonly) CBCentralManager *centralManager;
  
  
  /**
   * The delegate that will receive scaning or connection events.
   */
  @property (weak) id <RTKLEProfileDelegate> delegate;
  
  
  @property (nullable, readonly) NSMutableArray <RTKLEPeripheral*> *managedPeripherals;
  
  /**
   * The interested advertising services.
   * When in scaning, only peripheral which is advertising specified services is returned. This is template method, which means you should override it in subclass.
   */
  + (nullable NSArray<CBUUID *> *)advertiseServiceUUIDs;
  
  /**
   * The class used to create peripheral instance.
   * This class should be a subclass of RTKLEPeripheral.
   */
  + (Class)concretePeripheralClass;
  
  
  // Scan expected peripheral nearby.
  
  // protected
  @property (readonly) NSPointerArray *scanedPeripherals;
  
  /**
   *  Indicates whether is currently scanning.
   */
  @property (readonly) BOOL isScaning;
  
  /**
   * Scan for interested peripherals.
   * @discussion RTKLEProfile only report scaned peripherals which pass some rule. A common rule check if the peripheral is advertising service specified by return value of -advertiseServiceUUIDs method.
   */
  - (void)scanForPeripherals;
  
  /**
   * Similar to -scanForPeripherals, while will report a scaned peripheral event each time it receive an advertisement.
   */
  - (void)scanForPeripheralsWithDuplicateReport;
  
  /**
   * Stop scaning.
   */
  - (void)stopScan;
  
  
  /* Deprecated */
  /*
  - (void)addPeripheral:(RTKLEPeripheral *)peripheral;
  - (void)removePeripheral:(RTKLEPeripheral *)peripheral;
  - (void)removeAllPeripherals;
  
  - (void)touch:(RTKLEPeripheral *)peripheral;
  */
  
  /**
   * Return all known RTKLEPeripheral instances  whose underlying CBPeripheral is equal to the peripheral passed in.
   */
  - (NSArray <RTKLEPeripheral*> *)peripheralsUsingCBPeripheral:(CBPeripheral *)peripheral;
  
  /**
   * Instantiate a RTKLEPeripheral object which have a underlying CBPeripheral equal to the pass in peripheral.
   * @discussion The return peripheral object is managed by the RTKLEProfile.
   */
  - (nullable RTKLEPeripheral *)instantiatePeripheralWithCBPeripheral:(CBPeripheral *)peripheral;
  
  
  /**
   * Returns a list of the RTK peripherals connected to the system whose services match the profile.
   */
  - (NSArray <RTKLEPeripheral*> *)retrieveConnectedPeripherals;
  
  @end
  
  
  #define RTKDistantInterval 31536000.
  
  @interface RTKLEProfile (Connection)
  
  /**
   * Establishes a connection to a peripheral with 10s timeout interval.
   
   */
  - (void)connectTo:(RTKLEPeripheral *)peripheral;
  
  /**
   * Establishes a connection to a peripheral.
   * When connection estabilished successfully, its delegate -profile:didConnectPeripheral will be invoked. otherwise -profile:didFailToConnectPeripheral is invoked.
   */
  - (void)connectTo:(RTKLEPeripheral *)peripheral withTimeout:(NSTimeInterval)timeout;
  
  /**
   * Cancels an active or pending local connection to a peripheral.
   */
  - (void)cancelConnectionWith:(RTKLEPeripheral *)peripheral;
  
  /**
   * Cancels active or pending local connections to all peripheral.
   */
  - (void)cancelAllPeripheralConnections;
  
  
  /* Protected */
  - (void)_connectTo:(RTKLEPeripheral *)peripheral withTimeout:(NSTimeInterval)timeout completionHandler:(nullable RTKLECompletionBlock)handler;
  - (void)_cancelConnectionWith:(RTKLEPeripheral *)peripheral;
  
  - (void)validatePeripheralAndOpen:(RTKLEPeripheral *)peripheral withCompletion:(RTKLECompletionBlock)handler;
  
  @end
  
  NS_ASSUME_NONNULL_END