Skip to content

Commit

Permalink
add pragma mark delimiters
Browse files Browse the repository at this point in the history
  • Loading branch information
jmesnil committed Feb 17, 2014
1 parent 26f1e01 commit 5477512
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 15 deletions.
14 changes: 11 additions & 3 deletions MQTTKit/MQTTKit.h
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,8 @@ typedef enum MQTTQualityOfService : NSUInteger {
ExactlyOnce
} MQTTQualityOfService;

#pragma mark - MQTT Message

@interface MQTTMessage : NSObject

@property (readonly, assign) unsigned short mid;
Expand All @@ -36,6 +38,8 @@ typedef enum MQTTQualityOfService : NSUInteger {
typedef void (^MQTTSubscriptionCompletionHandler)(NSArray *grantedQos);
typedef void (^MQTTMessageHandler)(MQTTMessage *message);

#pragma mark - MQTT Client

@class MQTTClient;

@interface MQTTClient : NSObject {
Expand All @@ -56,12 +60,14 @@ typedef void (^MQTTMessageHandler)(MQTTMessage *message);

- (MQTTClient*) initWithClientId: (NSString *)clientId;
- (void) setMessageRetry: (NSUInteger)seconds;

#pragma mark - Connection

- (void) connectWithCompletionHandler:(void (^)(MQTTConnectionReturnCode code))completionHandler;
- (void) connectToHost: (NSString*)host
completionHandler:(void (^)(MQTTConnectionReturnCode code))completionHandler;
- (void) disconnectWithCompletionHandler:(void (^)(NSUInteger code))completionHandler;
- (void) reconnect;

- (void)setWillData:(NSData *)payload
toTopic:(NSString *)willTopic
withQos:(MQTTQualityOfService)willQos
Expand All @@ -72,6 +78,8 @@ typedef void (^MQTTMessageHandler)(MQTTMessage *message);
retain:(BOOL)retain;
- (void)clearWill;

#pragma mark - Publish

- (void)publishData:(NSData *)payload
toTopic:(NSString *)topic
withQos:(MQTTQualityOfService)qos
Expand All @@ -83,13 +91,13 @@ typedef void (^MQTTMessageHandler)(MQTTMessage *message);
retain:(BOOL)retain
completionHandler:(void (^)(int mid))completionHandler;

#pragma mark - Subscribe

- (void)subscribe:(NSString *)topic
withCompletionHandler:(MQTTSubscriptionCompletionHandler)completionHandler;

- (void)subscribe:(NSString *)topic
withQos:(MQTTQualityOfService)qos
completionHandler:(MQTTSubscriptionCompletionHandler)completionHandler;

- (void)unsubscribe: (NSString *)topic
withCompletionHandler:(void (^)(void))completionHandler;

Expand Down
35 changes: 23 additions & 12 deletions MQTTKit/MQTTKit.m
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,8 @@

#endif

#pragma mark - MQTT Message

@interface MQTTMessage()

@property (readwrite, assign) unsigned short mid;
Expand Down Expand Up @@ -54,6 +56,8 @@ - (NSString *)payloadString {

@end

#pragma mark - MQTT Client

@interface MQTTClient()

@property (nonatomic, assign) BOOL connected;
Expand All @@ -71,6 +75,8 @@ @implementation MQTTClient
// dispatch queue to run the mosquitto_loop_forever.
dispatch_queue_t queue;

#pragma mark - mosquitto callback methods

static void on_connect(struct mosquitto *mosq, void *obj, int rc)
{
MQTTClient* client = (__bridge MQTTClient*)obj;
Expand Down Expand Up @@ -188,6 +194,19 @@ - (MQTTClient*) initWithClientId: (NSString*) clientId {
return self;
}

- (void) setMessageRetry: (NSUInteger)seconds
{
mosquitto_message_retry_set(mosq, (unsigned int)seconds);
}

- (void) dealloc {
if (mosq) {
mosquitto_destroy(mosq);
mosq = NULL;
}
}

#pragma mark - Connection

- (void) connectWithCompletionHandler:(void (^)(MQTTConnectionReturnCode code))completionHandler {
self.connectionCompletionHandler = completionHandler;
Expand Down Expand Up @@ -255,6 +274,8 @@ - (void)clearWill
mosquitto_will_clear(mosq);
}

#pragma mark - Publish

- (void)publishData:(NSData *)payload
toTopic:(NSString *)topic
withQos:(MQTTQualityOfService)qos
Expand Down Expand Up @@ -287,6 +308,8 @@ - (void)publishString:(NSString *)payload
completionHandler:completionHandler];
}

#pragma mark - Subscribe

- (void)subscribe: (NSString *)topic withCompletionHandler:(MQTTSubscriptionCompletionHandler)completionHandler {
[self subscribe:topic withQos:0 completionHandler:completionHandler];
}
Expand All @@ -311,16 +334,4 @@ - (void)unsubscribe: (NSString *)topic withCompletionHandler:(void (^)(void))com
}
}

- (void) setMessageRetry: (NSUInteger)seconds
{
mosquitto_message_retry_set(mosq, (unsigned int)seconds);
}

- (void) dealloc {
if (mosq) {
mosquitto_destroy(mosq);
mosq = NULL;
}
}

@end

0 comments on commit 5477512

Please sign in to comment.