3 // Part of ASIHTTPRequest -> http://allseeing-i.com/ASIHTTPRequest
5 // Created by Ben Copsey on 07/11/2008.
6 // Copyright 2008-2009 All-Seeing Interactive. All rights reserved.
9 #import <Foundation/Foundation.h>
10 #import "ASIHTTPRequestDelegate.h"
11 #import "ASIProgressDelegate.h"
13 @interface ASINetworkQueue : NSOperationQueue <ASIProgressDelegate, ASIHTTPRequestDelegate, NSCopying> {
15 // Delegate will get didFail + didFinish messages (if set)
18 // Will be called when a request starts with the request as the argument
19 SEL requestDidStartSelector;
21 // Will be called when a request receives response headers
22 // Should take the form request:didRecieveResponseHeaders:, where the first argument is the request, and the second the headers dictionary
23 SEL requestDidReceiveResponseHeadersSelector;
25 // Will be called when a request is about to redirect
26 // Should take the form request:willRedirectToURL:, where the first argument is the request, and the second the new url
27 SEL requestWillRedirectSelector;
29 // Will be called when a request completes with the request as the argument
30 SEL requestDidFinishSelector;
32 // Will be called when a request fails with the request as the argument
33 SEL requestDidFailSelector;
35 // Will be called when the queue finishes with the queue as the argument
36 SEL queueDidFinishSelector;
38 // Upload progress indicator, probably an NSProgressIndicator or UIProgressView
39 id uploadProgressDelegate;
41 // Total amount uploaded so far for all requests in this queue
42 unsigned long long bytesUploadedSoFar;
44 // Total amount to be uploaded for all requests in this queue - requests add to this figure as they work out how much data they have to transmit
45 unsigned long long totalBytesToUpload;
47 // Download progress indicator, probably an NSProgressIndicator or UIProgressView
48 id downloadProgressDelegate;
50 // Total amount downloaded so far for all requests in this queue
51 unsigned long long bytesDownloadedSoFar;
53 // Total amount to be downloaded for all requests in this queue - requests add to this figure as they receive Content-Length headers
54 unsigned long long totalBytesToDownload;
56 // When YES, the queue will cancel all requests when a request fails. Default is YES
57 BOOL shouldCancelAllRequestsOnFailure;
59 //Number of real requests (excludes HEAD requests created to manage showAccurateProgress)
62 // When NO, this request will only update the progress indicator when it completes
63 // When YES, this request will update the progress indicator according to how much data it has received so far
64 // When YES, the queue will first perform HEAD requests for all GET requests in the queue, so it can calculate the total download size before it starts
65 // NO means better performance, because it skips this step for GET requests, and it won't waste time updating the progress indicator until a request completes
66 // Set to YES if the size of a requests in the queue varies greatly for much more accurate results
67 // Default for requests in the queue is NO
68 BOOL showAccurateProgress;
70 // Storage container for additional queue information.
71 NSDictionary *userInfo;
75 // Convenience constructor
78 // Call this to reset a queue - it will cancel all operations, clear delegates, and suspend operation
81 // Used internally to manage HEAD requests when showAccurateProgress is YES, do not use!
82 - (void)addHEADOperation:(NSOperation *)operation;
84 // All ASINetworkQueues are paused when created so that total size can be calculated before the queue starts
85 // This method will start the queue
88 @property (assign, nonatomic, setter=setUploadProgressDelegate:) id uploadProgressDelegate;
89 @property (assign, nonatomic, setter=setDownloadProgressDelegate:) id downloadProgressDelegate;
91 @property (assign) SEL requestDidStartSelector;
92 @property (assign) SEL requestDidReceiveResponseHeadersSelector;
93 @property (assign) SEL requestWillRedirectSelector;
94 @property (assign) SEL requestDidFinishSelector;
95 @property (assign) SEL requestDidFailSelector;
96 @property (assign) SEL queueDidFinishSelector;
97 @property (assign) BOOL shouldCancelAllRequestsOnFailure;
98 @property (assign) id delegate;
99 @property (assign) BOOL showAccurateProgress;
100 @property (assign, readonly) int requestsCount;
101 @property (retain) NSDictionary *userInfo;
103 @property (assign) unsigned long long bytesUploadedSoFar;
104 @property (assign) unsigned long long totalBytesToUpload;
105 @property (assign) unsigned long long bytesDownloadedSoFar;
106 @property (assign) unsigned long long totalBytesToDownload;