commit | author | age
|
ea8e18
|
1 |
// |
L |
2 |
// MQTTPersistence.h |
|
3 |
// MQTTClient |
|
4 |
// |
|
5 |
// Created by Christoph Krey on 22.03.15. |
|
6 |
// Copyright © 2015-2016 Christoph Krey. All rights reserved. |
|
7 |
// |
|
8 |
|
|
9 |
#import <Foundation/Foundation.h> |
|
10 |
#import "MQTTMessage.h" |
|
11 |
|
|
12 |
static BOOL const MQTT_PERSISTENT = NO; |
|
13 |
static NSInteger const MQTT_MAX_SIZE = 64 * 1024 * 1024; |
|
14 |
static NSInteger const MQTT_MAX_WINDOW_SIZE = 16; |
|
15 |
static NSInteger const MQTT_MAX_MESSAGES = 1024; |
|
16 |
|
|
17 |
/** MQTTFlow is an abstraction of the entity to be stored for persistence */ |
|
18 |
|
|
19 |
@protocol MQTTFlow |
|
20 |
/** The clientID of the flow element */ |
|
21 |
@property (strong, nonatomic) NSString *clientId; |
|
22 |
|
|
23 |
/** The flag indicating incoming or outgoing flow element */ |
|
24 |
@property (strong, nonatomic) NSNumber *incomingFlag; |
|
25 |
|
|
26 |
/** The flag indicating if the flow element is retained*/ |
|
27 |
@property (strong, nonatomic) NSNumber *retainedFlag; |
|
28 |
|
|
29 |
/** The MQTTCommandType of the flow element, might be MQTT_None for offline queueing */ |
|
30 |
@property (strong, nonatomic) NSNumber *commandType; |
|
31 |
|
|
32 |
/** The MQTTQosLevel of the flow element */ |
|
33 |
@property (strong, nonatomic) NSNumber *qosLevel; |
|
34 |
|
|
35 |
/** The messageId of the flow element */ |
|
36 |
@property (strong, nonatomic) NSNumber *messageId; |
|
37 |
|
|
38 |
/** The topic of the flow element */ |
|
39 |
@property (strong, nonatomic) NSString *topic; |
|
40 |
|
|
41 |
/** The data of the flow element */ |
|
42 |
@property (strong, nonatomic) NSData *data; |
|
43 |
|
|
44 |
/** The deadline of the flow elelment before (re)trying transmission */ |
|
45 |
@property (strong, nonatomic) NSDate *deadline; |
|
46 |
|
|
47 |
@end |
|
48 |
|
|
49 |
/** The MQTTPersistence protocol is an abstraction of persistence classes for MQTTSession */ |
|
50 |
|
|
51 |
@protocol MQTTPersistence |
|
52 |
|
|
53 |
/** The maximum Window Size for outgoing inflight messages per clientID. Defaults to 16 */ |
|
54 |
@property (nonatomic) NSUInteger maxWindowSize; |
|
55 |
|
|
56 |
/** The maximum number of messages kept per clientID and direction. Defaults to 1024 */ |
|
57 |
@property (nonatomic) NSUInteger maxMessages; |
|
58 |
|
|
59 |
/** Indicates if the persistence implementation should make the information permannent. Defaults to NO */ |
|
60 |
@property (nonatomic) BOOL persistent; |
|
61 |
|
|
62 |
/** The maximum size of the storage used for persistence in total in bytes. Defaults to 1024*1024 bytes */ |
|
63 |
@property (nonatomic) NSUInteger maxSize; |
|
64 |
|
|
65 |
/** The current Window Size for outgoing inflight messages per clientID. |
|
66 |
* @param clientId |
|
67 |
* @return the current size of the outgoing inflight window |
|
68 |
*/ |
|
69 |
- (NSUInteger)windowSize:(NSString *)clientId; |
|
70 |
|
|
71 |
/** Stores one new message |
|
72 |
* @param clientId |
|
73 |
* @param topic |
|
74 |
* @param data |
|
75 |
* @param retainFlag |
|
76 |
* @param qos |
|
77 |
* @param msgId |
|
78 |
* @param incomingFlag |
|
79 |
* @param commandType |
|
80 |
* @param deadline |
|
81 |
* @return the created MQTTFlow element or nil if the maxWindowSize has been exceeded |
|
82 |
*/ |
|
83 |
- (id<MQTTFlow>)storeMessageForClientId:(NSString *)clientId |
|
84 |
topic:(NSString *)topic |
|
85 |
data:(NSData *)data |
|
86 |
retainFlag:(BOOL)retainFlag |
|
87 |
qos:(MQTTQosLevel)qos |
|
88 |
msgId:(UInt16)msgId |
|
89 |
incomingFlag:(BOOL)incomingFlag |
|
90 |
commandType:(UInt8)commandType |
|
91 |
deadline:(NSDate *)deadline; |
|
92 |
|
|
93 |
/** Deletes an MQTTFlow element |
|
94 |
* @param flow |
|
95 |
*/ |
|
96 |
- (void)deleteFlow:(id<MQTTFlow>)flow; |
|
97 |
|
|
98 |
/** Deletes all MQTTFlow elements of a clientId |
|
99 |
* @param clientId |
|
100 |
*/ |
|
101 |
- (void)deleteAllFlowsForClientId:(NSString *)clientId; |
|
102 |
|
|
103 |
/** Retrieves all MQTTFlow elements of a clientId and direction |
|
104 |
* @param clientId |
|
105 |
* @param incomingFlag |
|
106 |
* @return an NSArray of the retrieved MQTTFlow elements |
|
107 |
*/ |
|
108 |
- (NSArray *)allFlowsforClientId:(NSString *)clientId |
|
109 |
incomingFlag:(BOOL)incomingFlag; |
|
110 |
|
|
111 |
/** Retrieves an MQTTFlow element |
|
112 |
* @param clientId |
|
113 |
* @param incomingFlag |
|
114 |
* @param messageId |
|
115 |
* @return the retrieved MQTTFlow element or nil if the elememt was not found |
|
116 |
*/ |
|
117 |
- (id<MQTTFlow>)flowforClientId:(NSString *)clientId |
|
118 |
incomingFlag:(BOOL)incomingFlag |
|
119 |
messageId:(UInt16)messageId; |
|
120 |
|
|
121 |
/** sync is called to allow the MQTTPersistence implemetation to save data permanently */ |
|
122 |
- (void)sync; |
|
123 |
|
|
124 |
@end |