-
Notifications
You must be signed in to change notification settings - Fork 50
/
Copy pathPBDataLoggingService.h
275 lines (237 loc) · 10.7 KB
/
PBDataLoggingService.h
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
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
//
// PBDataLoggingService.h
// PebbleKit
//
// Created by Martijn The on 7/19/13.
// Copyright (c) 2013 Pebble Technology. All rights reserved.
//
#import <PebbleKit-Static/PBDefines.h>
NS_ASSUME_NONNULL_BEGIN
@class PBWatch;
/**
* Data logging datatypes.
*/
typedef NS_ENUM(uint8_t, PBDataLoggingType) {
//! Array of bytes
PBDataLoggingTypeByteArray = 0,
//! unsigned integer
PBDataLoggingTypeUInt = 2,
//! signed integer
PBDataLoggingTypeInt = 3,
};
/**
* The metadata of a data logging session. Used to identify a session.
*/
PB_EXTERN_CLASS @interface PBDataLoggingSessionMetadata : NSObject <NSSecureCoding, NSCopying>
/**
* A tag associated with the session.
*/
@property (nonatomic, readonly) uint32_t tag;
/**
* The timestamp of the moment the session was created by the watchapp.
*/
@property (nonatomic, readonly) uint32_t timestamp;
/**
* The type of data stored in this session.
*/
@property (nonatomic, readonly) PBDataLoggingType type;
/**
* The size of a data item.
*/
@property (nonatomic, readonly) uint16_t itemSize;
/**
* The serial number of the watch that created the sessions.
*/
@property (nonatomic, copy, readonly) NSString *serialNumber;
/**
* Creates a new data logging session metadata object, given all its property values.
* This method is provided to create a metadata object that can be used to
* compare it with a metadata object that is passed into one of the
* PBDataLoggingServiceDelegate methods.
* @param tag The tag associated with the session
* @param timestamp The timestamp of the creation of the session
* @param type The type of data stored in the session
* @param itemSize The size of a data item
* @param serialNumber The serial number of the watch that created the session
* @return A session metadata object with the specified information
*/
+ (instancetype)metadataWithTag:(uint32_t)tag
timestamp:(uint32_t)timestamp
type:(PBDataLoggingType)type
itemSize:(uint16_t)itemSize
serialNumber:(NSString *)serialNumber;
/**
* Tests the equality of the recipient and the given object.
*
* This method can be used to compare two sessions’ metadata objects to check
* whether they are referring to the same session or not.
*
* @param object The object to check against.
*
* @return `YES` if all the property values of the receiver are equal to the
* property values of the other object.
*/
- (BOOL)isEqual:(nullable id)object;
/**
* Tests the equality of two data logging sessions’ metadata objects.
*
* This method can be used to compare two sessions’ metadata objects to check
* whether they are referring to the same session or not.
*
* @note Equivalent to -[PBDataLoggingSessionMetadata isEqual:]
*
* @param sessionMetadata The session metadata to compare against.
*
* @return `YES` if all the property values of the receiver are equal to the
* property values of the given session.
*/
- (BOOL)isEqualToDataLoggingSessionMetadata:(PBDataLoggingSessionMetadata *)sessionMetadata;
@end
@class PBDataLoggingService;
/**
* Data logging delegate protocol. The object that implements this protocol
* is responsible for handling incoming data.
*/
@protocol PBDataLoggingServiceDelegate <NSObject>
@optional
/**
* Called by the service every time there is data available that has not been
* consumed yet.
* @param service The data logging service.
* @param bytes Pointer to the array of bytes.
* The array contains (numberOfItems * session.itemSize) bytes.
* @param numberOfItems The number of items that the array contains.
* @param session The metadata of the session.
* @return YES if the data was consumed and the service can discard the data.
* Return NO if the data was not be consumed after the method returned.
* If NO is returned, the next time this callback is invoked for the session, the
* data argument will (also) contain the data of the items of the previous
* invocation of the callback.
*/
- (BOOL)dataLoggingService:(PBDataLoggingService *)service hasByteArrays:(const uint8_t *const)bytes numberOfItems:(uint16_t)numberOfItems forDataLoggingSession:(PBDataLoggingSessionMetadata *)session;
/**
* Called by the service every time there is data available that has not been
* consumed yet.
* @param service The data logging service.
* @param data Pointer to the array of UInt8`s.
* @param numberOfItems The number of items that the array contains.
* @param session The metadata of the session.
* @return YES if the data was consumed and the service can discard the data.
* Return NO if the data was not be consumed after the method returned.
* If NO is returned, the next time this callback is invoked for the session, the
* data argument will (also) contain the data of the items of the previous
* invocation of the callback.
*/
- (BOOL)dataLoggingService:(PBDataLoggingService *)service hasUInt8s:(const uint8_t[])data numberOfItems:(uint16_t)numberOfItems forDataLoggingSession:(PBDataLoggingSessionMetadata *)session;
/**
* Called by the service every time there is data available that has not been
* consumed yet.
* @param service The data logging service.
* @param data Pointer to the array of UInt16`s.
* @param numberOfItems The number of items that the array contains.
* @param session The metadata of the session.
* @return YES if the data was consumed and the service can discard the data.
* Return NO if the data was not be consumed after the method returned.
* If NO is returned, the next time this callback is invoked for the session, the
* data argument will (also) contain the data of the items of the previous
* invocation of the callback.
*/
- (BOOL)dataLoggingService:(PBDataLoggingService *)service hasUInt16s:(const uint16_t[])data numberOfItems:(uint16_t)numberOfItems forDataLoggingSession:(PBDataLoggingSessionMetadata *)session;
/**
* Called by the service every time there is data available that has not been
* consumed yet.
* @param service The data logging service.
* @param data Pointer to the array of UInt32`s.
* @param numberOfItems The number of items that the array contains.
* @param session The metadata of the session.
* @return YES if the data was consumed and the service can discard the data.
* Return NO if the data was not be consumed after the method returned.
* If NO is returned, the next time this callback is invoked for the session, the
* data argument will (also) contain the data of the items of the previous
* invocation of the callback.
*/
- (BOOL)dataLoggingService:(PBDataLoggingService *)service hasUInt32s:(const uint32_t[])data numberOfItems:(uint16_t)numberOfItems forDataLoggingSession:(PBDataLoggingSessionMetadata *)session;
/**
* Called by the service every time there is data available that has not been
* consumed yet.
* @param service The data logging service.
* @param data Pointer to the array of SInt8`s.
* @param numberOfItems The number of items that the array contains.
* @param session The metadata of the session.
* @return YES if the data was consumed and the service can discard the data.
* Return NO if the data was not be consumed after the method returned.
* If NO is returned, the next time this callback is invoked for the session, the
* data argument will (also) contain the data of the items of the previous
* invocation of the callback.
*/
- (BOOL)dataLoggingService:(PBDataLoggingService *)service hasSInt8s:(const int8_t[])data numberOfItems:(uint16_t)numberOfItems forDataLoggingSession:(PBDataLoggingSessionMetadata *)session;
/**
* Called by the service every time there is data available that has not been
* consumed yet.
* @param service The data logging service.
* @param data Pointer to the array of SInt16`s.
* @param numberOfItems The number of items that the array contains.
* @param session The metadata of the session.
* @return YES if the data was consumed and the service can discard the data.
* Return NO if the data was not be consumed after the method returned.
* If NO is returned, the next time this callback is invoked for the session, the
* data argument will (also) contain the data of the items of the previous
* invocation of the callback.
*/
- (BOOL)dataLoggingService:(PBDataLoggingService *)service hasSInt16s:(const int16_t[])data numberOfItems:(uint16_t)numberOfItems forDataLoggingSession:(PBDataLoggingSessionMetadata *)session;
/**
* Called by the service every time there is data available that has not been
* consumed yet.
* @param service The data logging service.
* @param data Pointer to the array of SInt32`s.
* @param numberOfItems The number of items that the array contains.
* @param session The metadata of the session.
* @return YES if the data was consumed and the service can discard the data.
* Return NO if the data was not be consumed after the method returned.
* If NO is returned, the next time this callback is invoked for the session, the
* data argument will (also) contain the data of the items of the previous
* invocation of the callback.
*/
- (BOOL)dataLoggingService:(PBDataLoggingService *)service hasSInt32s:(const int32_t[])data numberOfItems:(uint16_t)numberOfItems forDataLoggingSession:(PBDataLoggingSessionMetadata *)session;
/**
* Called by the service every time a session is finished.
* This is guaranteed to be called only after all data has been received and
* consumed by the application.
* @param service The data logging service.
* @param session The metadata of the session.
*/
- (void)dataLoggingService:(PBDataLoggingService *)service sessionDidFinish:(PBDataLoggingSessionMetadata *)session;
@end
/**
* The data logging service. Assign a delegate object in order to receive
* data from your watchapp.
*/
PB_EXTERN_CLASS @interface PBDataLoggingService : NSObject
/**
* The delegate that has the responsility of handling callbacks from the
* data logging service.
*/
@property (atomic, readwrite, weak) id<PBDataLoggingServiceDelegate> delegate;
/**
* Sets the queue on which delegate methods will be executed.
* Callbacks are intended to be processed in the order as they come in, so it
* you must use a serial queue. If set to nil (default) the main queue is used.
* @param delegateQueue The queue on which the delegate methods will be executed.
*/
- (void)setDelegateQueue:(dispatch_queue_t)delegateQueue;
/**
* Query the latestConnectedWatch for data logging data.
*
* @deprecated Use pollForDataFromWatch:
*/
- (void)pollForData __attribute__((deprecated("Method deprecated. Use `pollForDataFromWatch:`")));
/**
* Query the watch for data logging data.
* @param watch The watch to query data from.
*/
- (void)pollForDataFromWatch:(PBWatch *)watch;
@end
@interface PBDataLoggingSessionMetadata (Unavailable)
- (instancetype)init NS_UNAVAILABLE;
@end
NS_ASSUME_NONNULL_END