Organize everything into operations
This commit is contained in:
58
kordophone/Bridge/Operations/MBIMBridgeOperation.m
Normal file
58
kordophone/Bridge/Operations/MBIMBridgeOperation.m
Normal file
@@ -0,0 +1,58 @@
|
||||
//
|
||||
// MBIMBridgeOperation.m
|
||||
// kordophoned
|
||||
//
|
||||
// Created by James Magahern on 11/13/18.
|
||||
// Copyright © 2018 James Magahern. All rights reserved.
|
||||
//
|
||||
|
||||
#import "MBIMBridgeOperation.h"
|
||||
|
||||
@interface MBIMBridgeOperation (/*INTERNAL*/)
|
||||
@property (nonatomic, copy) GCDWebServerCompletionBlock serverCompletionBlock;
|
||||
@property (nonatomic, strong) GCDWebServerRequest *request;
|
||||
@end
|
||||
|
||||
@implementation MBIMBridgeOperation
|
||||
|
||||
+ (NSString *)endpointName
|
||||
{
|
||||
// To be inplemented by subclasses
|
||||
return @"__unimplemented__";
|
||||
}
|
||||
|
||||
+ (NSMutableDictionary *)_operationClassMapping
|
||||
{
|
||||
static dispatch_once_t onceToken;
|
||||
static NSMutableDictionary *operationClassMapping = nil;
|
||||
dispatch_once(&onceToken, ^{
|
||||
operationClassMapping = [[NSMutableDictionary alloc] init];
|
||||
});
|
||||
|
||||
return operationClassMapping;
|
||||
}
|
||||
|
||||
+ (void)load
|
||||
{
|
||||
if ([self class] != [MBIMBridgeOperation class]) {
|
||||
[[self _operationClassMapping] setObject:[self class] forKey:[self endpointName]];
|
||||
}
|
||||
}
|
||||
|
||||
+ (nullable Class)operationClassForEndpointName:(NSString *)endpointName
|
||||
{
|
||||
return [[self _operationClassMapping] objectForKey:endpointName];
|
||||
}
|
||||
|
||||
- (instancetype)initWithRequest:(GCDWebServerRequest *)request completion:(GCDWebServerCompletionBlock)completionBlock
|
||||
{
|
||||
self = [super init];
|
||||
if (self) {
|
||||
self.request = request;
|
||||
self.serverCompletionBlock = completionBlock;
|
||||
}
|
||||
|
||||
return self;
|
||||
}
|
||||
|
||||
@end
|
||||
Reference in New Issue
Block a user