This repository has been archived by the owner on Apr 15, 2019. It is now read-only.
forked from eczarny/xmlrpc
-
Notifications
You must be signed in to change notification settings - Fork 29
/
XMLRPCConnectionManager.m
112 lines (78 loc) · 2.34 KB
/
XMLRPCConnectionManager.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
#import "XMLRPCConnectionManager.h"
#import "XMLRPCConnection.h"
#import "XMLRPCRequest.h"
@implementation XMLRPCConnectionManager
static XMLRPCConnectionManager *sharedInstance = nil;
- (id)init {
self = [super init];
if (self) {
myConnections = [[NSMutableDictionary alloc] init];
}
return self;
}
#pragma mark -
+ (id)allocWithZone: (NSZone *)zone {
@synchronized(self) {
if (!sharedInstance) {
sharedInstance = [super allocWithZone: zone];
return sharedInstance;
}
}
return nil;
}
#pragma mark -
+ (XMLRPCConnectionManager *)sharedManager {
@synchronized(self) {
if (!sharedInstance) {
sharedInstance = [[self alloc] init];
}
}
return sharedInstance;
}
#pragma mark -
- (NSString *)spawnConnectionWithXMLRPCRequest: (XMLRPCRequest *)request delegate: (id<XMLRPCConnectionDelegate>)delegate {
XMLRPCConnection *newConnection = [[XMLRPCConnection alloc] initWithXMLRPCRequest: request delegate: delegate manager: self];
#if ! __has_feature(objc_arc)
NSString *identifier = [[[newConnection identifier] retain] autorelease];
#else
NSString *identifier = [newConnection identifier];
#endif
[myConnections setObject: newConnection forKey: identifier];
#if ! __has_feature(objc_arc)
[newConnection release];
#endif
return identifier;
}
#pragma mark -
- (NSArray *)activeConnectionIdentifiers {
return [myConnections allKeys];
}
- (NSUInteger)numberOfActiveConnections {
return [myConnections count];
}
#pragma mark -
- (XMLRPCConnection *)connectionForIdentifier: (NSString *)identifier {
return [myConnections objectForKey: identifier];
}
#pragma mark -
- (void)closeConnectionForIdentifier: (NSString *)identifier {
XMLRPCConnection *selectedConnection = [self connectionForIdentifier: identifier];
if (selectedConnection) {
[selectedConnection cancel];
[myConnections removeObjectForKey: identifier];
}
}
- (void)closeConnections {
[[myConnections allValues] makeObjectsPerformSelector: @selector(cancel)];
[myConnections removeAllObjects];
}
#pragma mark -
#pragma mark -
- (void)dealloc {
[self closeConnections];
#if ! __has_feature(objc_arc)
[myConnections release];
[super dealloc];
#endif
}
@end