forked from eczarny/xmlrpc
-
Notifications
You must be signed in to change notification settings - Fork 1
/
XMLRPCConnectionManager.m
109 lines (74 loc) · 2.24 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
#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];
NSString *identifier = [[[newConnection identifier] retain] autorelease];
[myConnections setObject: newConnection forKey: identifier];
[newConnection release];
return identifier;
}
#pragma mark -
- (NSArray *)activeConnectionIdentifiers {
return [myConnections allKeys];
}
- (int)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 -
- (void)finalize {
[self closeConnections];
[super finalize];
}
#pragma mark -
- (void)dealloc {
[self closeConnections];
[myConnections release];
[super dealloc];
}
@end