ASINetworkQueue.h 4.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108
  1. //
  2. // ASINetworkQueue.h
  3. // Part of ASIHTTPRequest -> http://allseeing-i.com/ASIHTTPRequest
  4. //
  5. // Created by Ben Copsey on 07/11/2008.
  6. // Copyright 2008-2009 All-Seeing Interactive. All rights reserved.
  7. //
  8. #import <Foundation/Foundation.h>
  9. #import "ASIHTTPRequestDelegate.h"
  10. #import "ASIProgressDelegate.h"
  11. @interface ASINetworkQueue : NSOperationQueue <ASIProgressDelegate, ASIHTTPRequestDelegate, NSCopying> {
  12. // Delegate will get didFail + didFinish messages (if set)
  13. id delegate;
  14. // Will be called when a request starts with the request as the argument
  15. SEL requestDidStartSelector;
  16. // Will be called when a request receives response headers
  17. // Should take the form request:didRecieveResponseHeaders:, where the first argument is the request, and the second the headers dictionary
  18. SEL requestDidReceiveResponseHeadersSelector;
  19. // Will be called when a request is about to redirect
  20. // Should take the form request:willRedirectToURL:, where the first argument is the request, and the second the new url
  21. SEL requestWillRedirectSelector;
  22. // Will be called when a request completes with the request as the argument
  23. SEL requestDidFinishSelector;
  24. // Will be called when a request fails with the request as the argument
  25. SEL requestDidFailSelector;
  26. // Will be called when the queue finishes with the queue as the argument
  27. SEL queueDidFinishSelector;
  28. // Upload progress indicator, probably an NSProgressIndicator or UIProgressView
  29. id uploadProgressDelegate;
  30. // Total amount uploaded so far for all requests in this queue
  31. unsigned long long bytesUploadedSoFar;
  32. // 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
  33. unsigned long long totalBytesToUpload;
  34. // Download progress indicator, probably an NSProgressIndicator or UIProgressView
  35. id downloadProgressDelegate;
  36. // Total amount downloaded so far for all requests in this queue
  37. unsigned long long bytesDownloadedSoFar;
  38. // Total amount to be downloaded for all requests in this queue - requests add to this figure as they receive Content-Length headers
  39. unsigned long long totalBytesToDownload;
  40. // When YES, the queue will cancel all requests when a request fails. Default is YES
  41. BOOL shouldCancelAllRequestsOnFailure;
  42. //Number of real requests (excludes HEAD requests created to manage showAccurateProgress)
  43. int requestsCount;
  44. // When NO, this request will only update the progress indicator when it completes
  45. // When YES, this request will update the progress indicator according to how much data it has received so far
  46. // 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
  47. // 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
  48. // Set to YES if the size of a requests in the queue varies greatly for much more accurate results
  49. // Default for requests in the queue is NO
  50. BOOL showAccurateProgress;
  51. // Storage container for additional queue information.
  52. NSDictionary *userInfo;
  53. }
  54. // Convenience constructor
  55. + (id)queue;
  56. // Call this to reset a queue - it will cancel all operations, clear delegates, and suspend operation
  57. - (void)reset;
  58. // Used internally to manage HEAD requests when showAccurateProgress is YES, do not use!
  59. - (void)addHEADOperation:(NSOperation *)operation;
  60. // All ASINetworkQueues are paused when created so that total size can be calculated before the queue starts
  61. // This method will start the queue
  62. - (void)go;
  63. @property (assign, nonatomic, setter=setUploadProgressDelegate:) id uploadProgressDelegate;
  64. @property (assign, nonatomic, setter=setDownloadProgressDelegate:) id downloadProgressDelegate;
  65. @property (assign, atomic) SEL requestDidStartSelector;
  66. @property (assign, atomic) SEL requestDidReceiveResponseHeadersSelector;
  67. @property (assign, atomic) SEL requestWillRedirectSelector;
  68. @property (assign, atomic) SEL requestDidFinishSelector;
  69. @property (assign, atomic) SEL requestDidFailSelector;
  70. @property (assign, atomic) SEL queueDidFinishSelector;
  71. @property (assign, atomic) BOOL shouldCancelAllRequestsOnFailure;
  72. @property (assign, atomic) id delegate;
  73. @property (assign, atomic) BOOL showAccurateProgress;
  74. @property (assign, atomic, readonly) int requestsCount;
  75. @property (retain, atomic) NSDictionary *userInfo;
  76. @property (assign, atomic) unsigned long long bytesUploadedSoFar;
  77. @property (assign, atomic) unsigned long long totalBytesToUpload;
  78. @property (assign, atomic) unsigned long long bytesDownloadedSoFar;
  79. @property (assign, atomic) unsigned long long totalBytesToDownload;
  80. @end