Ben Copsey

Progress API cleanup

Use slightly stricter build config, fix 64bit issues
@@ -243,8 +243,8 @@ @@ -243,8 +243,8 @@
243 243
244 NSEnumerator *e = [[self postData] keyEnumerator]; 244 NSEnumerator *e = [[self postData] keyEnumerator];
245 NSString *key; 245 NSString *key;
246 - int i=0; 246 + NSUInteger i=0;
247 - int count = [[self postData] count]-1; 247 + NSUInteger count = [[self postData] count]-1;
248 while (key = [e nextObject]) { 248 while (key = [e nextObject]) {
249 NSString *data = [NSString stringWithFormat:@"%@=%@%@", [self encodeURL:key], [self encodeURL:[[self postData] objectForKey:key]],(i<count ? @"&" : @"")]; 249 NSString *data = [NSString stringWithFormat:@"%@=%@%@", [self encodeURL:key], [self encodeURL:[[self postData] objectForKey:key]],(i<count ? @"&" : @"")];
250 [self appendPostString:data]; 250 [self appendPostString:data];
@@ -245,6 +245,9 @@ extern unsigned long const ASIWWANBandwidthThrottleAmount; @@ -245,6 +245,9 @@ extern unsigned long const ASIWWANBandwidthThrottleAmount;
245 // Called on the delegate (if implemented) when the request starts. Default is requestStarted: 245 // Called on the delegate (if implemented) when the request starts. Default is requestStarted:
246 SEL didStartSelector; 246 SEL didStartSelector;
247 247
  248 + // Called on the delegate (if implemented) when the request receives response headers. Default is requestDidReceiveResponseHeaders:
  249 + SEL didReceiveResponseHeadersSelector;
  250 +
248 // Called on the delegate (if implemented) when the request completes successfully. Default is requestFinished: 251 // Called on the delegate (if implemented) when the request completes successfully. Default is requestFinished:
249 SEL didFinishSelector; 252 SEL didFinishSelector;
250 253
@@ -446,25 +449,37 @@ extern unsigned long const ASIWWANBandwidthThrottleAmount; @@ -446,25 +449,37 @@ extern unsigned long const ASIWWANBandwidthThrottleAmount;
446 449
447 #pragma mark upload/download progress 450 #pragma mark upload/download progress
448 451
  452 +// Called approximately every 0.25 seconds to update the progress delegates
449 - (void)updateProgressIndicators; 453 - (void)updateProgressIndicators;
  454 +
  455 +// Updates upload progress (notifies the queue and/or uploadProgressDelegate of this request)
450 - (void)updateUploadProgress; 456 - (void)updateUploadProgress;
  457 +
  458 +// Updates download progress (notifies the queue and/or uploadProgressDelegate of this request)
451 - (void)updateDownloadProgress; 459 - (void)updateDownloadProgress;
452 460
453 // Called when authorisation is needed, as we only find out we don't have permission to something when the upload is complete 461 // Called when authorisation is needed, as we only find out we don't have permission to something when the upload is complete
454 - (void)removeUploadProgressSoFar; 462 - (void)removeUploadProgressSoFar;
455 463
  464 +// Called when we get a content-length header and shouldResetProgressIndicators is true
  465 +- (void)incrementDownloadSizeBy:(long long)length;
  466 +
  467 +// Called when a request starts and shouldResetProgressIndicators is true
  468 +// Also called (with a negative length) to remove the size of the underlying buffer used for uploading
  469 +- (void)incrementUploadSizeBy:(long long)length;
  470 +
456 // Helper method for interacting with progress indicators to abstract the details of different APIS (NSProgressIndicator and UIProgressView) 471 // Helper method for interacting with progress indicators to abstract the details of different APIS (NSProgressIndicator and UIProgressView)
457 + (void)updateProgressIndicator:(id)indicator withProgress:(unsigned long long)progress ofTotal:(unsigned long long)total; 472 + (void)updateProgressIndicator:(id)indicator withProgress:(unsigned long long)progress ofTotal:(unsigned long long)total;
458 473
459 474
460 -- (void)resetDownloadProgressWithNewLength:(unsigned long long)length;  
461 -- (void)resetUploadProgressWithNewLength:(unsigned long long)value;  
462 -  
463 #pragma mark handling request complete / failure 475 #pragma mark handling request complete / failure
464 476
465 // Called when a request starts, lets the delegate know via didStartSelector 477 // Called when a request starts, lets the delegate know via didStartSelector
466 - (void)requestStarted; 478 - (void)requestStarted;
467 479
  480 +// Called when a request receives response headers, lets the delegate know via didReceiveResponseHeadersSelector
  481 +- (void)requestReceivedResponseHeaders;
  482 +
468 // Called when a request completes successfully, lets the delegate know via didFinishSelector 483 // Called when a request completes successfully, lets the delegate know via didFinishSelector
469 - (void)requestFinished; 484 - (void)requestFinished;
470 485
@@ -678,6 +693,7 @@ extern unsigned long const ASIWWANBandwidthThrottleAmount; @@ -678,6 +693,7 @@ extern unsigned long const ASIWWANBandwidthThrottleAmount;
678 @property (retain) NSString *downloadDestinationPath; 693 @property (retain) NSString *downloadDestinationPath;
679 @property (retain) NSString *temporaryFileDownloadPath; 694 @property (retain) NSString *temporaryFileDownloadPath;
680 @property (assign) SEL didStartSelector; 695 @property (assign) SEL didStartSelector;
  696 +@property (assign) SEL didReceiveResponseHeadersSelector;
681 @property (assign) SEL didFinishSelector; 697 @property (assign) SEL didFinishSelector;
682 @property (assign) SEL didFailSelector; 698 @property (assign) SEL didFailSelector;
683 @property (retain,readonly) NSString *authenticationRealm; 699 @property (retain,readonly) NSString *authenticationRealm;
@@ -728,7 +744,6 @@ extern unsigned long const ASIWWANBandwidthThrottleAmount; @@ -728,7 +744,6 @@ extern unsigned long const ASIWWANBandwidthThrottleAmount;
728 @property (assign, readonly) int proxyAuthenticationRetryCount; 744 @property (assign, readonly) int proxyAuthenticationRetryCount;
729 @property (assign) BOOL haveBuiltRequestHeaders; 745 @property (assign) BOOL haveBuiltRequestHeaders;
730 @property (assign, nonatomic) BOOL haveBuiltPostBody; 746 @property (assign, nonatomic) BOOL haveBuiltPostBody;
731 -  
732 @property (assign, readonly) BOOL isSynchronous; 747 @property (assign, readonly) BOOL isSynchronous;
733 @property (assign, readonly) BOOL inProgress; 748 @property (assign, readonly) BOOL inProgress;
734 @property (assign) int numberOfTimesToRetryOnTimeout; 749 @property (assign) int numberOfTimesToRetryOnTimeout;
This diff is collapsed. Click to expand it.
@@ -15,6 +15,7 @@ @@ -15,6 +15,7 @@
15 // These are the default delegate methods for request status 15 // These are the default delegate methods for request status
16 // You can use different ones by setting didStartSelector / didFinishSelector / didFailSelector 16 // You can use different ones by setting didStartSelector / didFinishSelector / didFailSelector
17 - (void)requestStarted:(ASIHTTPRequest *)request; 17 - (void)requestStarted:(ASIHTTPRequest *)request;
  18 +- (void)requestReceivedResponseHeaders:(ASIHTTPRequest *)request;
18 - (void)requestFinished:(ASIHTTPRequest *)request; 19 - (void)requestFinished:(ASIHTTPRequest *)request;
19 - (void)requestFailed:(ASIHTTPRequest *)request; 20 - (void)requestFailed:(ASIHTTPRequest *)request;
20 21
@@ -7,9 +7,10 @@ @@ -7,9 +7,10 @@
7 // 7 //
8 8
9 #import <Foundation/Foundation.h> 9 #import <Foundation/Foundation.h>
  10 +#import "ASIHTTPRequestDelegate.h"
10 #import "ASIProgressDelegate.h" 11 #import "ASIProgressDelegate.h"
11 12
12 -@interface ASINetworkQueue : NSOperationQueue <ASIProgressDelegate, NSCopying> { 13 +@interface ASINetworkQueue : NSOperationQueue <ASIProgressDelegate, ASIHTTPRequestDelegate, NSCopying> {
13 14
14 // Delegate will get didFail + didFinish messages (if set) 15 // Delegate will get didFail + didFinish messages (if set)
15 id delegate; 16 id delegate;
@@ -17,6 +18,9 @@ @@ -17,6 +18,9 @@
17 // Will be called when a request starts with the request as the argument 18 // Will be called when a request starts with the request as the argument
18 SEL requestDidStartSelector; 19 SEL requestDidStartSelector;
19 20
  21 + // Will be called when a request receives response headers with the request as the argument
  22 + SEL requestDidReceiveResponseHeadersSelector;
  23 +
20 // Will be called when a request completes with the request as the argument 24 // Will be called when a request completes with the request as the argument
21 SEL requestDidFinishSelector; 25 SEL requestDidFinishSelector;
22 26
@@ -88,6 +92,7 @@ @@ -88,6 +92,7 @@
88 @property (assign,setter=setDownloadProgressDelegate:) id downloadProgressDelegate; 92 @property (assign,setter=setDownloadProgressDelegate:) id downloadProgressDelegate;
89 93
90 @property (assign) SEL requestDidStartSelector; 94 @property (assign) SEL requestDidStartSelector;
  95 +@property (assign) SEL requestDidReceiveResponseHeadersSelector;
91 @property (assign) SEL requestDidFinishSelector; 96 @property (assign) SEL requestDidFinishSelector;
92 @property (assign) SEL requestDidFailSelector; 97 @property (assign) SEL requestDidFailSelector;
93 @property (assign) SEL queueDidFinishSelector; 98 @property (assign) SEL queueDidFinishSelector;
@@ -66,6 +66,7 @@ @@ -66,6 +66,7 @@
66 [self setDownloadProgressDelegate:nil]; 66 [self setDownloadProgressDelegate:nil];
67 [self setUploadProgressDelegate:nil]; 67 [self setUploadProgressDelegate:nil];
68 [self setRequestDidStartSelector:NULL]; 68 [self setRequestDidStartSelector:NULL];
  69 + [self setRequestDidReceiveResponseHeadersSelector:NULL];
69 [self setRequestDidFailSelector:NULL]; 70 [self setRequestDidFailSelector:NULL];
70 [self setRequestDidFinishSelector:NULL]; 71 [self setRequestDidFinishSelector:NULL];
71 [self setQueueDidFinishSelector:NULL]; 72 [self setQueueDidFinishSelector:NULL];
@@ -197,45 +198,54 @@ @@ -197,45 +198,54 @@
197 198
198 } 199 }
199 200
200 -- (void)requestDidStart:(ASIHTTPRequest *)request 201 +- (void)requestStarted:(ASIHTTPRequest *)request
201 { 202 {
202 if ([self requestDidStartSelector]) { 203 if ([self requestDidStartSelector]) {
203 [[self delegate] performSelector:[self requestDidStartSelector] withObject:request]; 204 [[self delegate] performSelector:[self requestDidStartSelector] withObject:request];
204 } 205 }
205 } 206 }
206 207
207 -- (void)requestDidFail:(ASIHTTPRequest *)request 208 +- (void)requestDidReceiveResponseHeaders:(ASIHTTPRequest *)request
  209 +{
  210 + if ([self requestDidReceiveResponseHeadersSelector]) {
  211 + [[self delegate] performSelector:[self requestDidReceiveResponseHeadersSelector] withObject:request];
  212 + }
  213 +}
  214 +
  215 +
  216 +- (void)requestFinished:(ASIHTTPRequest *)request
208 { 217 {
209 [self setRequestsCount:[self requestsCount]-1]; 218 [self setRequestsCount:[self requestsCount]-1];
210 [self updateNetworkActivityIndicator]; 219 [self updateNetworkActivityIndicator];
211 - if ([self requestDidFailSelector]) { 220 + if ([self requestDidFinishSelector]) {
212 - [[self delegate] performSelector:[self requestDidFailSelector] withObject:request]; 221 + [[self delegate] performSelector:[self requestDidFinishSelector] withObject:request];
213 } 222 }
214 if ([self requestsCount] == 0) { 223 if ([self requestsCount] == 0) {
215 if ([self queueDidFinishSelector]) { 224 if ([self queueDidFinishSelector]) {
216 [[self delegate] performSelector:[self queueDidFinishSelector] withObject:self]; 225 [[self delegate] performSelector:[self queueDidFinishSelector] withObject:self];
217 } 226 }
218 } 227 }
219 - if ([self shouldCancelAllRequestsOnFailure] && [self requestsCount] > 0) {  
220 - [self cancelAllOperations];  
221 - }  
222 -  
223 } 228 }
224 229
225 -- (void)requestDidFinish:(ASIHTTPRequest *)request 230 +- (void)requestFailed:(ASIHTTPRequest *)request
226 { 231 {
227 [self setRequestsCount:[self requestsCount]-1]; 232 [self setRequestsCount:[self requestsCount]-1];
228 [self updateNetworkActivityIndicator]; 233 [self updateNetworkActivityIndicator];
229 - if ([self requestDidFinishSelector]) { 234 + if ([self requestDidFailSelector]) {
230 - [[self delegate] performSelector:[self requestDidFinishSelector] withObject:request]; 235 + [[self delegate] performSelector:[self requestDidFailSelector] withObject:request];
231 } 236 }
232 if ([self requestsCount] == 0) { 237 if ([self requestsCount] == 0) {
233 if ([self queueDidFinishSelector]) { 238 if ([self queueDidFinishSelector]) {
234 [[self delegate] performSelector:[self queueDidFinishSelector] withObject:self]; 239 [[self delegate] performSelector:[self queueDidFinishSelector] withObject:self];
235 } 240 }
236 } 241 }
  242 + if ([self shouldCancelAllRequestsOnFailure] && [self requestsCount] > 0) {
  243 + [self cancelAllOperations];
  244 + }
  245 +
237 } 246 }
238 247
  248 +
239 - (void)request:(ASIHTTPRequest *)request didReceiveBytes:(long long)bytes 249 - (void)request:(ASIHTTPRequest *)request didReceiveBytes:(long long)bytes
240 { 250 {
241 [self setBytesDownloadedSoFar:[self bytesDownloadedSoFar]+bytes]; 251 [self setBytesDownloadedSoFar:[self bytesDownloadedSoFar]+bytes];
@@ -252,12 +262,12 @@ @@ -252,12 +262,12 @@
252 } 262 }
253 } 263 }
254 264
255 -- (void)request:(ASIHTTPRequest *)request resetDownloadContentLength:(long long)newLength 265 +- (void)request:(ASIHTTPRequest *)request incrementDownloadSizeBy:(long long)newLength
256 { 266 {
257 [self setTotalBytesToDownload:[self totalBytesToDownload]+newLength]; 267 [self setTotalBytesToDownload:[self totalBytesToDownload]+newLength];
258 } 268 }
259 269
260 -- (void)request:(ASIHTTPRequest *)request resetUploadContentLength:(long long)newLength 270 +- (void)request:(ASIHTTPRequest *)request incrementUploadSizeBy:(long long)newLength
261 { 271 {
262 [self setTotalBytesToUpload:[self totalBytesToUpload]+newLength]; 272 [self setTotalBytesToUpload:[self totalBytesToUpload]+newLength];
263 } 273 }
@@ -323,6 +333,7 @@ @@ -323,6 +333,7 @@
323 @synthesize uploadProgressDelegate; 333 @synthesize uploadProgressDelegate;
324 @synthesize downloadProgressDelegate; 334 @synthesize downloadProgressDelegate;
325 @synthesize requestDidStartSelector; 335 @synthesize requestDidStartSelector;
  336 +@synthesize requestDidReceiveResponseHeadersSelector;
326 @synthesize requestDidFinishSelector; 337 @synthesize requestDidFinishSelector;
327 @synthesize requestDidFailSelector; 338 @synthesize requestDidFailSelector;
328 @synthesize queueDidFinishSelector; 339 @synthesize queueDidFinishSelector;
@@ -30,8 +30,8 @@ @@ -30,8 +30,8 @@
30 - (void)request:(ASIHTTPRequest *)request didSendBytes:(long long)bytes; 30 - (void)request:(ASIHTTPRequest *)request didSendBytes:(long long)bytes;
31 31
32 // Called when a request needs to change the length of the content to download 32 // Called when a request needs to change the length of the content to download
33 -- (void)request:(ASIHTTPRequest *)request resetDownloadContentLength:(long long)newLength; 33 +- (void)request:(ASIHTTPRequest *)request incrementDownloadSizeBy:(long long)newLength;
34 34
35 // Called when a request needs to change the length of the content to upload 35 // Called when a request needs to change the length of the content to upload
36 -- (void)request:(ASIHTTPRequest *)request resetUploadContentLength:(long long)newLength; 36 +- (void)request:(ASIHTTPRequest *)request incrementUploadSizeBy:(long long)newLength;
37 @end 37 @end
@@ -57,5 +57,16 @@ @@ -57,5 +57,16 @@
57 57
58 - (IBAction)throttleBandwidth:(id)sender; 58 - (IBAction)throttleBandwidth:(id)sender;
59 59
  60 +- (void)updateBandwidthUsageIndicator;
  61 +- (void)URLFetchWithProgressComplete:(ASIHTTPRequest *)request;
  62 +- (void)URLFetchWithProgressFailed:(ASIHTTPRequest *)request;
  63 +- (void)imageFetch1Complete:(ASIHTTPRequest *)request;
  64 +- (void)imageFetch2Complete:(ASIHTTPRequest *)request;
  65 +- (void)imageFetch3Complete:(ASIHTTPRequest *)request;
  66 +- (void)topSecretFetchComplete:(ASIHTTPRequest *)request;
  67 +- (void)authSheetDidEnd:(NSWindow *)sheet returnCode:(int)returnCode contextInfo:(void *)contextInfo;
  68 +- (void)postFinished:(ASIHTTPRequest *)request;
  69 +- (void)postFailed:(ASIHTTPRequest *)request;
  70 +
60 @property (retain, nonatomic) ASIHTTPRequest *bigFetchRequest; 71 @property (retain, nonatomic) ASIHTTPRequest *bigFetchRequest;
61 @end 72 @end
@@ -16,8 +16,7 @@ @@ -16,8 +16,7 @@
16 { 16 {
17 [super init]; 17 [super init];
18 networkQueue = [[ASINetworkQueue alloc] init]; 18 networkQueue = [[ASINetworkQueue alloc] init];
19 - NSTimer *timer = [NSTimer scheduledTimerWithTimeInterval:1.0 target:self selector:@selector(updateBandwidthUsageIndicator) userInfo:nil repeats:YES]; 19 + [NSTimer scheduledTimerWithTimeInterval:1.0 target:self selector:@selector(updateBandwidthUsageIndicator) userInfo:nil repeats:YES];
20 - timer = nil;  
21 return self; 20 return self;
22 } 21 }
23 22
@@ -206,7 +205,7 @@ @@ -206,7 +205,7 @@
206 205
207 } 206 }
208 207
209 -- (IBAction)topSecretFetchComplete:(ASIHTTPRequest *)request 208 +- (void)topSecretFetchComplete:(ASIHTTPRequest *)request
210 { 209 {
211 if (![request error]) { 210 if (![request error]) {
212 [topSecretInfo setStringValue:[request responseString]]; 211 [topSecretInfo setStringValue:[request responseString]];
@@ -243,7 +242,8 @@ @@ -243,7 +242,8 @@
243 [[NSApplication sharedApplication] endSheet: loginWindow returnCode: [(NSControl*)sender tag]]; 242 [[NSApplication sharedApplication] endSheet: loginWindow returnCode: [(NSControl*)sender tag]];
244 } 243 }
245 244
246 -- (void)authSheetDidEnd:(NSWindow *)sheet returnCode:(int)returnCode contextInfo:(void *)contextInfo { 245 +- (void)authSheetDidEnd:(NSWindow *)sheet returnCode:(int)returnCode contextInfo:(void *)contextInfo
  246 +{
247 ASIHTTPRequest *request = (ASIHTTPRequest *)contextInfo; 247 ASIHTTPRequest *request = (ASIHTTPRequest *)contextInfo;
248 if (returnCode == NSOKButton) { 248 if (returnCode == NSOKButton) {
249 if ([request authenticationNeeded] == ASIProxyAuthenticationNeeded) { 249 if ([request authenticationNeeded] == ASIProxyAuthenticationNeeded) {
This diff was suppressed by a .gitattributes entry.
@@ -13,11 +13,11 @@ GCC_WARN_INITIALIZER_NOT_FULLY_BRACKETED = YES @@ -13,11 +13,11 @@ GCC_WARN_INITIALIZER_NOT_FULLY_BRACKETED = YES
13 GCC_WARN_ABOUT_RETURN_TYPE = YES 13 GCC_WARN_ABOUT_RETURN_TYPE = YES
14 //GCC_WARN_MISSING_PARENTHESES = YES 14 //GCC_WARN_MISSING_PARENTHESES = YES
15 GCC_WARN_ABOUT_MISSING_FIELD_INITIALIZERS = YES 15 GCC_WARN_ABOUT_MISSING_FIELD_INITIALIZERS = YES
16 -//GCC_WARN_ABOUT_MISSING_NEWLINE = YES 16 +GCC_WARN_ABOUT_MISSING_NEWLINE = YES
17 GCC_WARN_SIGN_COMPARE = YES 17 GCC_WARN_SIGN_COMPARE = YES
18 GCC_WARN_STRICT_SELECTOR_MATCH = missing value 18 GCC_WARN_STRICT_SELECTOR_MATCH = missing value
19 GCC_WARN_TYPECHECK_CALLS_TO_PRINTF = YES 19 GCC_WARN_TYPECHECK_CALLS_TO_PRINTF = YES
20 -//GCC_WARN_UNDECLARED_SELECTOR = YES 20 +GCC_WARN_UNDECLARED_SELECTOR = YES
21 GCC_WARN_UNUSED_FUNCTION = YES 21 GCC_WARN_UNUSED_FUNCTION = YES
22 GCC_WARN_UNUSED_LABEL = YES 22 GCC_WARN_UNUSED_LABEL = YES
23 GCC_WARN_UNUSED_VALUE = YES 23 GCC_WARN_UNUSED_VALUE = YES