Revision cb6abe72 pithos-macos/PithosActivityFacility.m

b/pithos-macos/PithosActivityFacility.m
39 39
#import "PithosAccount.h"
40 40
#import "pithos_macosAppDelegate.h"
41 41

  
42
static PithosActivityFacility *defaultPithosActivityFacility = nil;
42
//static PithosActivityFacility *defaultPithosActivityFacility = nil;
43 43

  
44 44
@implementation PithosActivityFacility
45 45
@synthesize delegate;
46 46

  
47
#pragma mark -
48 47
#pragma mark - Singleton
49 48

  
50 49
+ (id)defaultPithosActivityFacility {
51
	@synchronized(self) {
52
		if (!defaultPithosActivityFacility)
53
			[[self alloc] init]; // Assignment not done here
54
	}
55
	return defaultPithosActivityFacility;
56
}
57

  
58
+ (id)allocWithZone:(NSZone *)zone {
59
    @synchronized(self) {
60
        if (!defaultPithosActivityFacility) {
61
            defaultPithosActivityFacility = [super allocWithZone:zone];
62
            return defaultPithosActivityFacility;
63
        }
64
    }
65
    return nil;
66
}
67

  
68
- (id)copyWithZone:(NSZone *)zone {
69
    return self;
70
}
71

  
72
- (id)retain {
73
    return self;
50
    static dispatch_once_t pred = 0;
51
    __strong static id _sharedObject = nil;
52
    dispatch_once(&pred, ^{
53
        _sharedObject = [[self alloc] init];
54
    });
55
    return _sharedObject;
74 56
}
75 57

  
76
- (NSUInteger)retainCount {
77
    return UINT_MAX; // Can not be released
78
}
79

  
80
- (void)release {
81
    // Do nothing
82
}
83

  
84
- (id)autorelease {
85
    return self;
86
}
58
//+ (id)allocWithZone:(NSZone *)zone {
59
//    @synchronized(self) {
60
//        if (!defaultPithosActivityFacility) {
61
//            defaultPithosActivityFacility = [super allocWithZone:zone];
62
//            return defaultPithosActivityFacility;
63
//        }
64
//    }
65
//    return nil;
66
//}
67
//
68
//- (id)copyWithZone:(NSZone *)zone {
69
//    return self;
70
//}
71
//
72
//- (id)retain {
73
//    return self;
74
//}
75
//
76
//- (NSUInteger)retainCount {
77
//    return UINT_MAX; // Can not be released
78
//}
79
//
80
//- (void)release {
81
//    // Do nothing
82
//}
83
//
84
//- (id)autorelease {
85
//    return self;
86
//}
87 87

  
88
#pragma mark -
89
#pragma mark Object Lifecycle
88
#pragma mark - Object Lifecycle
90 89

  
91 90
- (id)init {
92 91
    if ((self = [super init])) {
......
97 96

  
98 97
- (void)dealloc {
99 98
    [timer invalidate];
100
    [timer release];
101
    [runningActivities release];
102
    [endingActivities release];
103
    [super dealloc];
104 99
}
105 100

  
106 101
- (void)reset {
107 102
    @synchronized(self) {
108 103
        [timer invalidate];
109
        [timer release];
110 104
        
111
        [runningActivities release];
112 105
        runningActivities = [[NSMutableArray alloc] init];
113
        [endingActivities release];
114 106
        endingActivities = [[NSMutableArray alloc] init];
115 107
        totalUploadBytes = 0;
116 108
        currentUploadBytes = 0;
......
119 111
        
120 112
        pickedRunning = NO;
121 113
        
122
        timer = [[NSTimer scheduledTimerWithTimeInterval:[(pithos_macosAppDelegate *)[[NSApplication sharedApplication] delegate] activityFacilityTimeInterval] 
114
        timer = [NSTimer scheduledTimerWithTimeInterval:[(pithos_macosAppDelegate *)[[NSApplication sharedApplication] delegate] activityFacilityTimeInterval] 
123 115
                                                  target:self 
124 116
                                                selector:@selector(update:) 
125 117
                                                userInfo:nil 
126
                                                 repeats:YES] retain];
118
                                                 repeats:YES];
127 119
    }
128 120
}
129 121

  
......
160 152
                if (activity.message)
161 153
                    break;
162 154
            }
163
            [activity retain];
164 155
            [endingActivities removeObjectsInRange:NSMakeRange(0, (index + 1))];
165 156
            pickedRunning = NO;
166 157
        } else if (runningActivitiesCount) {
167 158
            NSUInteger count;
168 159
            for (count = 0 ; count < runningActivitiesCount; count++) {
169
                activity = [[runningActivities objectAtIndex:0] retain];
160
                activity = [runningActivities objectAtIndex:0];
170 161
                [runningActivities removeObjectAtIndex:0];
171 162
                [runningActivities addObject:activity];
172 163
                if (activity.message) {
173 164
                    break;
174 165
                } else {
175
                    [activity release];
176 166
                    activity = nil;
177 167
                }
178 168
            }
......
190 180
        [info setObject:[NSNumber numberWithUnsignedInteger:currentUploadBytes] forKey:@"currentUploadBytes"];
191 181
        [info setObject:[NSNumber numberWithUnsignedInteger:totalDownloadBytes] forKey:@"totalDownloadBytes"];
192 182
        [info setObject:[NSNumber numberWithUnsignedInteger:currentDownloadBytes] forKey:@"currentDownloadBytes"];
193
        [activity release];
194 183
    }
195 184
    if (delegate) {
196 185
        [delegate activityUpdate:info];
......
205 194
                               totalBytes:(NSUInteger)totalBytes 
206 195
                             currentBytes:(NSUInteger)currentBytes 
207 196
                            pithosAccount:(PithosAccount *)pithosAccount {
208
    PithosActivity *activity = [[[PithosActivity alloc] initWithType:type pithosAccount:pithosAccount] autorelease];
197
    PithosActivity *activity = [[PithosActivity alloc] initWithType:type pithosAccount:pithosAccount];
209 198
    activity.message = message;
210 199
    activity.totalBytes = totalBytes;
211 200
    activity.currentBytes = currentBytes;
......
257 246
- (PithosActivity *)startAndEndActivityWithType:(PithosActivityType)type 
258 247
                                        message:(NSString *)message 
259 248
                                  pithosAccount:(PithosAccount *)pithosAccount {
260
    PithosActivity *activity = [[[PithosActivity alloc] initWithType:type pithosAccount:pithosAccount] autorelease];
249
    PithosActivity *activity = [[PithosActivity alloc] initWithType:type pithosAccount:pithosAccount];
261 250
    activity.message = message;
262 251
    activity.totalBytes = 0;
263 252
    activity.currentBytes = 0;

Also available in: Unified diff