forked from overtake/telegram
-
Notifications
You must be signed in to change notification settings - Fork 6
/
ASActor.m
118 lines (92 loc) · 2.5 KB
/
ASActor.m
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
#import "ASActor.h"
static NSMutableDictionary *registeredRequestBuilders()
{
static NSMutableDictionary *dict = nil;
static dispatch_once_t onceToken;
dispatch_once(&onceToken, ^
{
dict = [[NSMutableDictionary alloc] init];
});
return dict;
}
@implementation ASActor
+ (void)registerActorClass:(Class)requestBuilderClass
{
NSString *genericPath = [requestBuilderClass genericPath];
if (genericPath == nil || genericPath.length == 0)
{
DLog(@"Error: ASActor::registerActorClass: genericPath is nil");
return;
}
[registeredRequestBuilders() setObject:requestBuilderClass forKey:genericPath];
}
+ (ASActor *)requestBuilderForGenericPath:(NSString *)genericPath path:(NSString *)path
{
Class builderClass = [registeredRequestBuilders() objectForKey:genericPath];
if (builderClass != nil)
{
ASActor *builderInstance = [[builderClass alloc] initWithPath:path];
return builderInstance;
}
return nil;
}
+ (NSString *)genericPath
{
DLog(@"Error: ASActor::genericPath: no default implementation provided");
return nil;
}
@synthesize path = _path;
@synthesize requestQueueName = _requestQueueName;
@synthesize storedOptions = _storedOptions;
@synthesize requiresAuthorization = _requiresAuthorization;
@synthesize cancelTimeout = _cancelTimeout;
@synthesize cancelToken = _cancelToken;
@synthesize cancelled = _cancelled;
/*#if TARGET_IPHONE_SIMULATOR
static int instanceCount = 0;
#endif*/
- (id)initWithPath:(NSString *)path
{
self = [super init];
if (self != nil)
{
_cancelTimeout = 0;
_path = path;
/*#if TARGET_IPHONE_SIMULATOR
instanceCount++;
DLog(@"%d actors (++)", instanceCount);
#endif*/
}
return self;
}
- (void)dealloc
{
/*#if TARGET_IPHONE_SIMULATOR
instanceCount--;
DLog(@"%d actors (--)", instanceCount);
#endif*/
}
- (void)prepare:(NSDictionary *)__unused options
{
}
- (void)execute:(NSDictionary *)__unused options
{
DLog(@"Error: ASActor::execute: no default implementation provided");
}
- (void)cancel
{
self.cancelled = true;
}
- (void)addCancelToken:(id)token
{
if (_multipleCancelTokens == nil)
_multipleCancelTokens = [[NSMutableArray alloc] init];
[_multipleCancelTokens addObject:token];
}
- (void)handleRequestProblem
{
}
- (void)watcherJoined:(ASHandle *)__unused watcherHandle options:(NSDictionary *)__unused options waitingInActorQueue:(bool)__unused waitingInActorQueue
{
}
@end