Skip to content

Commit

Permalink
[core] Remove unnecessary private property declarations from NIOperat…
Browse files Browse the repository at this point in the history
…ions.
  • Loading branch information
jverkoey committed Jun 11, 2012
1 parent e6c9a62 commit a9d7ca3
Show file tree
Hide file tree
Showing 2 changed files with 114 additions and 137 deletions.
31 changes: 2 additions & 29 deletions src/core/src/NIOperations.h
Expand Up @@ -43,30 +43,12 @@
*
* @ingroup Operations
*/
@interface NIOperation : NSOperation {
@private
id<NIOperationDelegate> _delegate;

NSInteger _tag;

NSError* _lastError;

#if NS_BLOCKS_AVAILABLE
// Performed on the main thread.
NIBasicBlock _didStartBlock;
NIBasicBlock _didFinishBlock;
NIErrorBlock _didFailWithErrorBlock;

// Performed in the operation's thread.
NIBasicBlock _willFinishBlock;
#endif // #if NS_BLOCKS_AVAILABLE
}
@interface NIOperation : NSOperation

@property (readwrite, assign) id<NIOperationDelegate> delegate;
@property (readonly, retain) NSError* lastError;
@property (readwrite, assign) NSInteger tag;


#if NS_BLOCKS_AVAILABLE

@property (readwrite, copy) NIBasicBlock didStartBlock;
Expand All @@ -92,16 +74,7 @@
*
* @ingroup Operations
*/
@interface NINetworkRequestOperation : NIOperation {
@private
// [in]
NSURL* _url;
NSTimeInterval _timeout;

// [out]
NSData* _data;
id _processedObject;
}
@interface NINetworkRequestOperation : NIOperation

// Designated initializer.
- (id)initWithURL:(NSURL *)url;
Expand Down
220 changes: 112 additions & 108 deletions src/core/src/NIOperations.m
Expand Up @@ -20,118 +20,11 @@
#import "NIPreprocessorMacros.h"
#import "NIOperations+Subclassing.h"

@interface NIOperation()

///////////////////////////////////////////////////////////////////////////////////////////////////
///////////////////////////////////////////////////////////////////////////////////////////////////
///////////////////////////////////////////////////////////////////////////////////////////////////
@implementation NINetworkRequestOperation

@synthesize url = _url;
@synthesize timeout = _timeout;
@synthesize cachePolicy = _cachePolicy;
@synthesize data = _data;
@synthesize processedObject = _processedObject;


///////////////////////////////////////////////////////////////////////////////////////////////////
- (void)dealloc {
NI_RELEASE_SAFELY(_url);
NI_RELEASE_SAFELY(_data);
NI_RELEASE_SAFELY(_processedObject);

[super dealloc];
}


///////////////////////////////////////////////////////////////////////////////////////////////////
- (id)initWithURL:(NSURL *)url {
if ((self = [super init])) {
self.url = url;
self.timeout = 60;
self.cachePolicy = NSURLRequestUseProtocolCachePolicy;
}
return self;
}


///////////////////////////////////////////////////////////////////////////////////////////////////
///////////////////////////////////////////////////////////////////////////////////////////////////
#pragma mark -
#pragma mark NSOperation


///////////////////////////////////////////////////////////////////////////////////////////////////
- (void)main {
NSAutoreleasePool* pool = [[NSAutoreleasePool alloc] init];

if ([self.url isFileURL]) {
// Special case: load the image from disk without hitting the network.

[self didStart];

NSError* dataReadError = nil;

// The meat of the load-from-disk operation.
NSString* filePath = [self.url path];
NSMutableData* data = [NSMutableData dataWithContentsOfFile:filePath
options:0
error:&dataReadError];

if (nil != dataReadError) {
// This generally happens when the file path points to a file that doesn't exist.
// dataReadError has the complete details.
[self didFailWithError:dataReadError];

} else {
self.data = data;

// Notifies the delegates of the request completion.
[self willFinish];
[self didFinish];
}

} else { // COV_NF_START
// Load the image from the network then.
[self didStart];

NSURLRequest* request = [NSURLRequest requestWithURL:self.url
cachePolicy:self.cachePolicy
timeoutInterval:self.timeout];

NSError* networkError = nil;
NSURLResponse* response = nil;
NSData* data = [NSURLConnection sendSynchronousRequest:request
returningResponse:&response
error:&networkError];

// If we get a 404 error then the request will not fail with an error, so only let successful
// responses pass.
if ([response isKindOfClass:[NSHTTPURLResponse class]]) {
NSHTTPURLResponse* httpResponse = (NSHTTPURLResponse *)response;
if (httpResponse.statusCode < 200 || httpResponse.statusCode >= 300) {
networkError = [NSError errorWithDomain:NSURLErrorDomain
code:NSURLErrorResourceUnavailable
userInfo:nil];
}
}

if (nil != networkError) {
[self didFailWithError:networkError];

} else {
self.data = data;

[self willFinish];
[self didFinish];
} // COV_NF_END
}

NI_RELEASE_SAFELY(pool);
}

@end


///////////////////////////////////////////////////////////////////////////////////////////////////
///////////////////////////////////////////////////////////////////////////////////////////////////
///////////////////////////////////////////////////////////////////////////////////////////////////
Expand Down Expand Up @@ -268,3 +161,114 @@ - (void)onMainThreadOperationDidFailWithError:(NSError *)error {


@end


///////////////////////////////////////////////////////////////////////////////////////////////////
///////////////////////////////////////////////////////////////////////////////////////////////////
///////////////////////////////////////////////////////////////////////////////////////////////////
@implementation NINetworkRequestOperation

@synthesize url = _url;
@synthesize timeout = _timeout;
@synthesize cachePolicy = _cachePolicy;
@synthesize data = _data;
@synthesize processedObject = _processedObject;


///////////////////////////////////////////////////////////////////////////////////////////////////
- (void)dealloc {
NI_RELEASE_SAFELY(_url);
NI_RELEASE_SAFELY(_data);
NI_RELEASE_SAFELY(_processedObject);

[super dealloc];
}


///////////////////////////////////////////////////////////////////////////////////////////////////
- (id)initWithURL:(NSURL *)url {
if ((self = [super init])) {
self.url = url;
self.timeout = 60;
self.cachePolicy = NSURLRequestUseProtocolCachePolicy;
}
return self;
}


///////////////////////////////////////////////////////////////////////////////////////////////////
///////////////////////////////////////////////////////////////////////////////////////////////////
#pragma mark -
#pragma mark NSOperation


///////////////////////////////////////////////////////////////////////////////////////////////////
- (void)main {
NSAutoreleasePool* pool = [[NSAutoreleasePool alloc] init];

if ([self.url isFileURL]) {
// Special case: load the image from disk without hitting the network.

[self didStart];

NSError* dataReadError = nil;

// The meat of the load-from-disk operation.
NSString* filePath = [self.url path];
NSMutableData* data = [NSMutableData dataWithContentsOfFile:filePath
options:0
error:&dataReadError];

if (nil != dataReadError) {
// This generally happens when the file path points to a file that doesn't exist.
// dataReadError has the complete details.
[self didFailWithError:dataReadError];

} else {
self.data = data;

// Notifies the delegates of the request completion.
[self willFinish];
[self didFinish];
}

} else { // COV_NF_START
// Load the image from the network then.
[self didStart];

NSURLRequest* request = [NSURLRequest requestWithURL:self.url
cachePolicy:self.cachePolicy
timeoutInterval:self.timeout];

NSError* networkError = nil;
NSURLResponse* response = nil;
NSData* data = [NSURLConnection sendSynchronousRequest:request
returningResponse:&response
error:&networkError];

// If we get a 404 error then the request will not fail with an error, so only let successful
// responses pass.
if ([response isKindOfClass:[NSHTTPURLResponse class]]) {
NSHTTPURLResponse* httpResponse = (NSHTTPURLResponse *)response;
if (httpResponse.statusCode < 200 || httpResponse.statusCode >= 300) {
networkError = [NSError errorWithDomain:NSURLErrorDomain
code:NSURLErrorResourceUnavailable
userInfo:nil];
}
}

if (nil != networkError) {
[self didFailWithError:networkError];

} else {
self.data = data;

[self willFinish];
[self didFinish];
} // COV_NF_END
}

NI_RELEASE_SAFELY(pool);
}

@end

0 comments on commit a9d7ca3

Please sign in to comment.