commit | author | age
|
2370e0
|
1 |
// |
H |
2 |
// MQTTTransport.h |
|
3 |
// MQTTClient |
|
4 |
// |
|
5 |
// Created by Christoph Krey on 06.12.15. |
|
6 |
// Copyright © 2015-2016 Christoph Krey. All rights reserved. |
|
7 |
// |
|
8 |
|
|
9 |
#import <Foundation/Foundation.h> |
|
10 |
|
|
11 |
@protocol MQTTTransportDelegate; |
|
12 |
|
|
13 |
/** MQTTTransport is a protocol abstracting the underlying transport level for MQTTClient |
|
14 |
* |
|
15 |
*/ |
|
16 |
@protocol MQTTTransport <NSObject> |
|
17 |
|
|
18 |
/** MQTTTransport state defines the possible state of an abstract transport |
|
19 |
* |
|
20 |
*/ |
|
21 |
typedef NS_ENUM(NSInteger, MQTTTransportState) { |
|
22 |
|
|
23 |
/** MQTTTransportCreated indicates an initialized transport */ |
|
24 |
MQTTTransportCreated = 0, |
|
25 |
|
|
26 |
/** MQTTTransportOpening indicates a transport in the process of opening a connection */ |
|
27 |
MQTTTransportOpening, |
|
28 |
|
|
29 |
/** MQTTTransportCreated indicates a transport opened ready for communication */ |
|
30 |
MQTTTransportOpen, |
|
31 |
|
|
32 |
/** MQTTTransportCreated indicates a transport in the process of closing */ |
|
33 |
MQTTTransportClosing, |
|
34 |
|
|
35 |
/** MQTTTransportCreated indicates a closed transport */ |
|
36 |
MQTTTransportClosed |
|
37 |
}; |
|
38 |
|
|
39 |
/** runLoop The runLoop where the streams are scheduled. If nil, defaults to [NSRunLoop currentRunLoop]. */ |
|
40 |
@property (strong, nonatomic) NSRunLoop * _Nonnull runLoop; |
|
41 |
|
|
42 |
/** runLoopMode The runLoopMode where the streams are scheduled. If nil, defaults to NSRunLoopCommonModes. */ |
|
43 |
@property (strong, nonatomic) NSString * _Nonnull runLoopMode; |
|
44 |
|
|
45 |
/** MQTTTransportDelegate needs to be set to a class implementing th MQTTTransportDelegate protocol |
|
46 |
* to receive delegate messages. |
|
47 |
*/ |
|
48 |
@property (strong, nonatomic) _Nullable id<MQTTTransportDelegate> delegate; |
|
49 |
|
|
50 |
/** state contains the current MQTTTransportState of the transport */ |
|
51 |
@property (nonatomic) MQTTTransportState state; |
|
52 |
|
|
53 |
/** open opens the transport and prepares it for communication |
|
54 |
* actual transports may require additional parameters to be set before opening |
|
55 |
*/ |
|
56 |
- (void)open; |
|
57 |
|
|
58 |
/** send transmits a data message |
|
59 |
* @param data data to be send, might be zero length |
|
60 |
* @result a boolean indicating if the data could be send or not |
|
61 |
*/ |
|
62 |
- (BOOL)send:(nonnull NSData *)data; |
|
63 |
|
|
64 |
/** close closes the transport */ |
|
65 |
- (void)close; |
|
66 |
|
|
67 |
@end |
|
68 |
|
|
69 |
/** MQTTTransportDelegate protocol |
|
70 |
* Note: the implementation of the didReceiveMessage method is mandatory, the others are optional |
|
71 |
*/ |
|
72 |
@protocol MQTTTransportDelegate <NSObject> |
|
73 |
|
|
74 |
/** didReceiveMessage gets called when a message was received |
|
75 |
* @param mqttTransport the transport on which the message was received |
|
76 |
* @param message the data received which may be zero length |
|
77 |
*/ |
|
78 |
- (void)mqttTransport:(nonnull id<MQTTTransport>)mqttTransport didReceiveMessage:(nonnull NSData *)message; |
|
79 |
|
|
80 |
@optional |
|
81 |
|
|
82 |
/** mqttTransportDidOpen gets called when a transport is successfully opened |
|
83 |
* @param mqttTransport the transport which was successfully opened |
|
84 |
*/ |
|
85 |
- (void)mqttTransportDidOpen:(_Nonnull id<MQTTTransport>)mqttTransport; |
|
86 |
|
|
87 |
/** didFailWithError gets called when an error was detected on the transport |
|
88 |
* @param mqttTransport the transport which detected the error |
|
89 |
* @param error available error information, might be nil |
|
90 |
*/ |
|
91 |
- (void)mqttTransport:(_Nonnull id<MQTTTransport>)mqttTransport didFailWithError:(nullable NSError *)error; |
|
92 |
|
|
93 |
/** mqttTransportDidClose gets called when the transport closed |
|
94 |
* @param mqttTransport the transport which was closed |
|
95 |
*/ |
|
96 |
- (void)mqttTransportDidClose:(_Nonnull id<MQTTTransport>)mqttTransport; |
|
97 |
|
|
98 |
@end |
|
99 |
|
|
100 |
@interface MQTTTransport : NSObject <MQTTTransport> |
|
101 |
@end |
|
102 |
|