Ben Copsey

Progress API cleanup

Use slightly stricter build config, fix 64bit issues
... ... @@ -243,8 +243,8 @@
NSEnumerator *e = [[self postData] keyEnumerator];
NSString *key;
int i=0;
int count = [[self postData] count]-1;
NSUInteger i=0;
NSUInteger count = [[self postData] count]-1;
while (key = [e nextObject]) {
NSString *data = [NSString stringWithFormat:@"%@=%@%@", [self encodeURL:key], [self encodeURL:[[self postData] objectForKey:key]],(i<count ? @"&" : @"")];
[self appendPostString:data];
... ...
... ... @@ -245,6 +245,9 @@ extern unsigned long const ASIWWANBandwidthThrottleAmount;
// Called on the delegate (if implemented) when the request starts. Default is requestStarted:
SEL didStartSelector;
// Called on the delegate (if implemented) when the request receives response headers. Default is requestDidReceiveResponseHeaders:
SEL didReceiveResponseHeadersSelector;
// Called on the delegate (if implemented) when the request completes successfully. Default is requestFinished:
SEL didFinishSelector;
... ... @@ -446,25 +449,37 @@ extern unsigned long const ASIWWANBandwidthThrottleAmount;
#pragma mark upload/download progress
// Called approximately every 0.25 seconds to update the progress delegates
- (void)updateProgressIndicators;
// Updates upload progress (notifies the queue and/or uploadProgressDelegate of this request)
- (void)updateUploadProgress;
// Updates download progress (notifies the queue and/or uploadProgressDelegate of this request)
- (void)updateDownloadProgress;
// Called when authorisation is needed, as we only find out we don't have permission to something when the upload is complete
- (void)removeUploadProgressSoFar;
// Called when we get a content-length header and shouldResetProgressIndicators is true
- (void)incrementDownloadSizeBy:(long long)length;
// Called when a request starts and shouldResetProgressIndicators is true
// Also called (with a negative length) to remove the size of the underlying buffer used for uploading
- (void)incrementUploadSizeBy:(long long)length;
// Helper method for interacting with progress indicators to abstract the details of different APIS (NSProgressIndicator and UIProgressView)
+ (void)updateProgressIndicator:(id)indicator withProgress:(unsigned long long)progress ofTotal:(unsigned long long)total;
- (void)resetDownloadProgressWithNewLength:(unsigned long long)length;
- (void)resetUploadProgressWithNewLength:(unsigned long long)value;
#pragma mark handling request complete / failure
// Called when a request starts, lets the delegate know via didStartSelector
- (void)requestStarted;
// Called when a request receives response headers, lets the delegate know via didReceiveResponseHeadersSelector
- (void)requestReceivedResponseHeaders;
// Called when a request completes successfully, lets the delegate know via didFinishSelector
- (void)requestFinished;
... ... @@ -678,6 +693,7 @@ extern unsigned long const ASIWWANBandwidthThrottleAmount;
@property (retain) NSString *downloadDestinationPath;
@property (retain) NSString *temporaryFileDownloadPath;
@property (assign) SEL didStartSelector;
@property (assign) SEL didReceiveResponseHeadersSelector;
@property (assign) SEL didFinishSelector;
@property (assign) SEL didFailSelector;
@property (retain,readonly) NSString *authenticationRealm;
... ... @@ -728,7 +744,6 @@ extern unsigned long const ASIWWANBandwidthThrottleAmount;
@property (assign, readonly) int proxyAuthenticationRetryCount;
@property (assign) BOOL haveBuiltRequestHeaders;
@property (assign, nonatomic) BOOL haveBuiltPostBody;
@property (assign, readonly) BOOL isSynchronous;
@property (assign, readonly) BOOL inProgress;
@property (assign) int numberOfTimesToRetryOnTimeout;
... ...
This diff is collapsed. Click to expand it.
... ... @@ -15,6 +15,7 @@
// These are the default delegate methods for request status
// You can use different ones by setting didStartSelector / didFinishSelector / didFailSelector
- (void)requestStarted:(ASIHTTPRequest *)request;
- (void)requestReceivedResponseHeaders:(ASIHTTPRequest *)request;
- (void)requestFinished:(ASIHTTPRequest *)request;
- (void)requestFailed:(ASIHTTPRequest *)request;
... ...
... ... @@ -7,9 +7,10 @@
//
#import <Foundation/Foundation.h>
#import "ASIHTTPRequestDelegate.h"
#import "ASIProgressDelegate.h"
@interface ASINetworkQueue : NSOperationQueue <ASIProgressDelegate, NSCopying> {
@interface ASINetworkQueue : NSOperationQueue <ASIProgressDelegate, ASIHTTPRequestDelegate, NSCopying> {
// Delegate will get didFail + didFinish messages (if set)
id delegate;
... ... @@ -17,6 +18,9 @@
// Will be called when a request starts with the request as the argument
SEL requestDidStartSelector;
// Will be called when a request receives response headers with the request as the argument
SEL requestDidReceiveResponseHeadersSelector;
// Will be called when a request completes with the request as the argument
SEL requestDidFinishSelector;
... ... @@ -88,6 +92,7 @@
@property (assign,setter=setDownloadProgressDelegate:) id downloadProgressDelegate;
@property (assign) SEL requestDidStartSelector;
@property (assign) SEL requestDidReceiveResponseHeadersSelector;
@property (assign) SEL requestDidFinishSelector;
@property (assign) SEL requestDidFailSelector;
@property (assign) SEL queueDidFinishSelector;
... ...
... ... @@ -66,6 +66,7 @@
[self setDownloadProgressDelegate:nil];
[self setUploadProgressDelegate:nil];
[self setRequestDidStartSelector:NULL];
[self setRequestDidReceiveResponseHeadersSelector:NULL];
[self setRequestDidFailSelector:NULL];
[self setRequestDidFinishSelector:NULL];
[self setQueueDidFinishSelector:NULL];
... ... @@ -197,45 +198,54 @@
}
- (void)requestDidStart:(ASIHTTPRequest *)request
- (void)requestStarted:(ASIHTTPRequest *)request
{
if ([self requestDidStartSelector]) {
[[self delegate] performSelector:[self requestDidStartSelector] withObject:request];
}
}
- (void)requestDidFail:(ASIHTTPRequest *)request
- (void)requestDidReceiveResponseHeaders:(ASIHTTPRequest *)request
{
if ([self requestDidReceiveResponseHeadersSelector]) {
[[self delegate] performSelector:[self requestDidReceiveResponseHeadersSelector] withObject:request];
}
}
- (void)requestFinished:(ASIHTTPRequest *)request
{
[self setRequestsCount:[self requestsCount]-1];
[self updateNetworkActivityIndicator];
if ([self requestDidFailSelector]) {
[[self delegate] performSelector:[self requestDidFailSelector] withObject:request];
if ([self requestDidFinishSelector]) {
[[self delegate] performSelector:[self requestDidFinishSelector] withObject:request];
}
if ([self requestsCount] == 0) {
if ([self queueDidFinishSelector]) {
[[self delegate] performSelector:[self queueDidFinishSelector] withObject:self];
}
}
if ([self shouldCancelAllRequestsOnFailure] && [self requestsCount] > 0) {
[self cancelAllOperations];
}
}
- (void)requestDidFinish:(ASIHTTPRequest *)request
- (void)requestFailed:(ASIHTTPRequest *)request
{
[self setRequestsCount:[self requestsCount]-1];
[self updateNetworkActivityIndicator];
if ([self requestDidFinishSelector]) {
[[self delegate] performSelector:[self requestDidFinishSelector] withObject:request];
if ([self requestDidFailSelector]) {
[[self delegate] performSelector:[self requestDidFailSelector] withObject:request];
}
if ([self requestsCount] == 0) {
if ([self queueDidFinishSelector]) {
[[self delegate] performSelector:[self queueDidFinishSelector] withObject:self];
}
}
if ([self shouldCancelAllRequestsOnFailure] && [self requestsCount] > 0) {
[self cancelAllOperations];
}
}
- (void)request:(ASIHTTPRequest *)request didReceiveBytes:(long long)bytes
{
[self setBytesDownloadedSoFar:[self bytesDownloadedSoFar]+bytes];
... ... @@ -252,12 +262,12 @@
}
}
- (void)request:(ASIHTTPRequest *)request resetDownloadContentLength:(long long)newLength
- (void)request:(ASIHTTPRequest *)request incrementDownloadSizeBy:(long long)newLength
{
[self setTotalBytesToDownload:[self totalBytesToDownload]+newLength];
}
- (void)request:(ASIHTTPRequest *)request resetUploadContentLength:(long long)newLength
- (void)request:(ASIHTTPRequest *)request incrementUploadSizeBy:(long long)newLength
{
[self setTotalBytesToUpload:[self totalBytesToUpload]+newLength];
}
... ... @@ -323,6 +333,7 @@
@synthesize uploadProgressDelegate;
@synthesize downloadProgressDelegate;
@synthesize requestDidStartSelector;
@synthesize requestDidReceiveResponseHeadersSelector;
@synthesize requestDidFinishSelector;
@synthesize requestDidFailSelector;
@synthesize queueDidFinishSelector;
... ...
... ... @@ -30,8 +30,8 @@
- (void)request:(ASIHTTPRequest *)request didSendBytes:(long long)bytes;
// Called when a request needs to change the length of the content to download
- (void)request:(ASIHTTPRequest *)request resetDownloadContentLength:(long long)newLength;
- (void)request:(ASIHTTPRequest *)request incrementDownloadSizeBy:(long long)newLength;
// Called when a request needs to change the length of the content to upload
- (void)request:(ASIHTTPRequest *)request resetUploadContentLength:(long long)newLength;
- (void)request:(ASIHTTPRequest *)request incrementUploadSizeBy:(long long)newLength;
@end
... ...
... ... @@ -57,5 +57,16 @@
- (IBAction)throttleBandwidth:(id)sender;
- (void)updateBandwidthUsageIndicator;
- (void)URLFetchWithProgressComplete:(ASIHTTPRequest *)request;
- (void)URLFetchWithProgressFailed:(ASIHTTPRequest *)request;
- (void)imageFetch1Complete:(ASIHTTPRequest *)request;
- (void)imageFetch2Complete:(ASIHTTPRequest *)request;
- (void)imageFetch3Complete:(ASIHTTPRequest *)request;
- (void)topSecretFetchComplete:(ASIHTTPRequest *)request;
- (void)authSheetDidEnd:(NSWindow *)sheet returnCode:(int)returnCode contextInfo:(void *)contextInfo;
- (void)postFinished:(ASIHTTPRequest *)request;
- (void)postFailed:(ASIHTTPRequest *)request;
@property (retain, nonatomic) ASIHTTPRequest *bigFetchRequest;
@end
... ...
... ... @@ -16,8 +16,7 @@
{
[super init];
networkQueue = [[ASINetworkQueue alloc] init];
NSTimer *timer = [NSTimer scheduledTimerWithTimeInterval:1.0 target:self selector:@selector(updateBandwidthUsageIndicator) userInfo:nil repeats:YES];
timer = nil;
[NSTimer scheduledTimerWithTimeInterval:1.0 target:self selector:@selector(updateBandwidthUsageIndicator) userInfo:nil repeats:YES];
return self;
}
... ... @@ -206,7 +205,7 @@
}
- (IBAction)topSecretFetchComplete:(ASIHTTPRequest *)request
- (void)topSecretFetchComplete:(ASIHTTPRequest *)request
{
if (![request error]) {
[topSecretInfo setStringValue:[request responseString]];
... ... @@ -243,7 +242,8 @@
[[NSApplication sharedApplication] endSheet: loginWindow returnCode: [(NSControl*)sender tag]];
}
- (void)authSheetDidEnd:(NSWindow *)sheet returnCode:(int)returnCode contextInfo:(void *)contextInfo {
- (void)authSheetDidEnd:(NSWindow *)sheet returnCode:(int)returnCode contextInfo:(void *)contextInfo
{
ASIHTTPRequest *request = (ASIHTTPRequest *)contextInfo;
if (returnCode == NSOKButton) {
if ([request authenticationNeeded] == ASIProxyAuthenticationNeeded) {
... ...
This diff was suppressed by a .gitattributes entry.
... ... @@ -13,11 +13,11 @@ GCC_WARN_INITIALIZER_NOT_FULLY_BRACKETED = YES
GCC_WARN_ABOUT_RETURN_TYPE = YES
//GCC_WARN_MISSING_PARENTHESES = YES
GCC_WARN_ABOUT_MISSING_FIELD_INITIALIZERS = YES
//GCC_WARN_ABOUT_MISSING_NEWLINE = YES
GCC_WARN_ABOUT_MISSING_NEWLINE = YES
GCC_WARN_SIGN_COMPARE = YES
GCC_WARN_STRICT_SELECTOR_MATCH = missing value
GCC_WARN_TYPECHECK_CALLS_TO_PRINTF = YES
//GCC_WARN_UNDECLARED_SELECTOR = YES
GCC_WARN_UNDECLARED_SELECTOR = YES
GCC_WARN_UNUSED_FUNCTION = YES
GCC_WARN_UNUSED_LABEL = YES
GCC_WARN_UNUSED_VALUE = YES
... ...