2018-11-17 01:07:55 -08:00
|
|
|
//
|
|
|
|
|
// MBIMUpdatePollOperation.m
|
|
|
|
|
// kordophoned
|
|
|
|
|
//
|
|
|
|
|
// Created by James Magahern on 11/16/18.
|
|
|
|
|
// Copyright © 2018 James Magahern. All rights reserved.
|
|
|
|
|
//
|
|
|
|
|
|
|
|
|
|
#import "MBIMUpdatePollOperation.h"
|
|
|
|
|
#import "MBIMUpdateQueue.h"
|
|
|
|
|
|
2018-11-20 19:57:35 -07:00
|
|
|
@implementation MBIMUpdatePollOperation {
|
|
|
|
|
__strong MBIMUpdateConsumer _updateConsumer;
|
|
|
|
|
}
|
2018-11-17 01:07:55 -08:00
|
|
|
|
|
|
|
|
+ (void)load { [super load]; }
|
|
|
|
|
|
|
|
|
|
+ (NSString *)endpointName
|
|
|
|
|
{
|
|
|
|
|
return @"pollUpdates";
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
- (void)main
|
|
|
|
|
{
|
2018-11-21 15:51:51 -07:00
|
|
|
NSInteger messageSeq = -1;
|
|
|
|
|
NSString *messageSeqString = [self valueForQueryItemWithName:@"seq"];
|
|
|
|
|
if (messageSeqString) {
|
|
|
|
|
messageSeq = [messageSeqString integerValue];
|
|
|
|
|
}
|
|
|
|
|
|
2018-11-20 19:57:35 -07:00
|
|
|
__weak __auto_type weakSelf = self;
|
2018-11-21 15:51:51 -07:00
|
|
|
_updateConsumer = ^(NSArray<MBIMUpdateItem *> *updates) {
|
|
|
|
|
NSMutableArray *encodedUpdates = [NSMutableArray array];
|
|
|
|
|
for (MBIMUpdateItem *item in updates) {
|
|
|
|
|
NSDictionary *updateDict = [item dictionaryRepresentation];
|
|
|
|
|
[encodedUpdates addObject:updateDict];
|
|
|
|
|
}
|
2018-11-17 01:07:55 -08:00
|
|
|
|
2018-11-21 15:51:51 -07:00
|
|
|
MBIMJSONDataResponse *response = [MBIMJSONDataResponse responseWithJSONObject:encodedUpdates];
|
2018-11-20 19:57:35 -07:00
|
|
|
weakSelf.serverCompletionBlock(response);
|
2018-11-17 01:07:55 -08:00
|
|
|
};
|
|
|
|
|
|
2018-11-21 15:51:51 -07:00
|
|
|
[[MBIMUpdateQueue sharedInstance] addConsumer:_updateConsumer withLastSyncedMessageSeq:messageSeq];
|
2018-11-20 19:57:35 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
- (void)cancel
|
|
|
|
|
{
|
|
|
|
|
[super cancel];
|
|
|
|
|
[[MBIMUpdateQueue sharedInstance] removeConsumer:_updateConsumer];
|
2018-11-17 01:07:55 -08:00
|
|
|
}
|
|
|
|
|
|
2018-11-20 19:57:35 -07:00
|
|
|
- (NSObject<HTTPResponse> *)cancelAndReturnTimeoutResponse
|
|
|
|
|
{
|
|
|
|
|
[self cancel];
|
|
|
|
|
return [[HTTPErrorResponse alloc] initWithErrorCode:205]; // 205 = nothing to report
|
|
|
|
|
}
|
2018-11-17 01:07:55 -08:00
|
|
|
|
|
|
|
|
@end
|