Add 'server/' from commit '800090542d91beae40bc81fc41b67ba61c47da77'
git-subtree-dir: server git-subtree-mainline:6a4054c15agit-subtree-split:800090542d
This commit is contained in:
@@ -0,0 +1,58 @@
|
||||
//
|
||||
// MBIMUpdatePollOperation.m
|
||||
// kordophoned
|
||||
//
|
||||
// Created by James Magahern on 11/16/18.
|
||||
// Copyright © 2018 James Magahern. All rights reserved.
|
||||
//
|
||||
|
||||
#import "MBIMUpdatePollOperation.h"
|
||||
#import "MBIMUpdateQueue.h"
|
||||
|
||||
@implementation MBIMUpdatePollOperation {
|
||||
__strong MBIMUpdateConsumer _updateConsumer;
|
||||
}
|
||||
|
||||
+ (void)load { [super load]; }
|
||||
|
||||
+ (NSString *)endpointName
|
||||
{
|
||||
return @"pollUpdates";
|
||||
}
|
||||
|
||||
- (void)main
|
||||
{
|
||||
NSInteger messageSeq = -1;
|
||||
NSString *messageSeqString = [self valueForQueryItemWithName:@"seq"];
|
||||
if (messageSeqString) {
|
||||
messageSeq = [messageSeqString integerValue];
|
||||
}
|
||||
|
||||
__weak __auto_type weakSelf = self;
|
||||
_updateConsumer = ^(NSArray<MBIMUpdateItem *> *updates) {
|
||||
NSMutableArray *encodedUpdates = [NSMutableArray array];
|
||||
for (MBIMUpdateItem *item in updates) {
|
||||
NSDictionary *updateDict = [item dictionaryRepresentation];
|
||||
[encodedUpdates addObject:updateDict];
|
||||
}
|
||||
|
||||
MBIMJSONDataResponse *response = [MBIMJSONDataResponse responseWithJSONObject:encodedUpdates];
|
||||
weakSelf.serverCompletionBlock(response);
|
||||
};
|
||||
|
||||
[[MBIMUpdateQueue sharedInstance] addPollingConsumer:_updateConsumer withLastSyncedMessageSeq:messageSeq];
|
||||
}
|
||||
|
||||
- (void)cancel
|
||||
{
|
||||
[super cancel];
|
||||
[[MBIMUpdateQueue sharedInstance] removePollingConsumer:_updateConsumer];
|
||||
}
|
||||
|
||||
- (NSObject<HTTPResponse> *)cancelAndReturnTimeoutResponse
|
||||
{
|
||||
[self cancel];
|
||||
return [[HTTPErrorResponse alloc] initWithErrorCode:205]; // 205 = nothing to report
|
||||
}
|
||||
|
||||
@end
|
||||
Reference in New Issue
Block a user