Permalink
Browse files

This modification allows for gathering information on requests globally.

  • Loading branch information...
1 parent 221c80f commit 4750833ad68822f10e46cd78fb4246bdda25962f Chris Miller committed Mar 12, 2012
Showing with 23 additions and 23 deletions.
  1. +4 −10 FSURLOperation.h
  2. +19 −13 FSURLOperation.m
View
@@ -8,13 +8,8 @@
#import <Foundation/Foundation.h>
-#ifdef FSURLDEBUG
-enum FSURLDebugStatus {
- RequestBegan,
- RequestFinished
-} FSURLDebugStatus;
-typedef void(^FSURLDebugBlockCallback)(NSURLRequest *, enum FSURLDebugStatus, NSHTTPURLResponse *, NSData *, NSError *);
-#endif
+typedef void(^FSURLRequestStartedCallback)(NSURLRequest *, NSThread *);
+typedef void(^FSURLRequestFinishedCallback)(NSURLRequest *, NSThread *, NSHTTPURLResponse *, NSData *, NSError *);
@interface FSURLOperation : NSOperation
@@ -27,9 +22,8 @@ typedef void(^FSURLDebugBlockCallback)(NSURLRequest *, enum FSURLDebugStatus, NS
@property (weak) id delegate;
@property (assign) SEL callback;
-#ifdef FSURLDEBUG
-+ (NSMutableSet *)debugCallbacks; // use to get callbacks to all operations going in and out
-#endif
++ (NSMutableSet *)globalBlockCallbacks_requestStarted;
++ (NSMutableSet *)globalBlockCallbacks_requestFinished;
+ (FSURLOperation*)URLOperationWithRequest:(NSURLRequest*)req
completionBlock:(void(^)(NSHTTPURLResponse* resp, NSData* payload, NSError* error))completion;
View
@@ -65,17 +65,25 @@ + (FSURLOperation*)URLOperationWithRequest:(NSURLRequest*)req
return operation;
}
-#ifdef FSURLDEBUG
-+ (NSMutableSet *)debugCallbacks
++ (NSMutableSet *)globalBlockCallbacks_requestStarted
{
- static NSMutableSet * _debugCallbacks;
+ static NSMutableSet * callbacks;
static dispatch_once_t onceToken;
dispatch_once(&onceToken, ^{
- _debugCallbacks = [[NSMutableSet alloc] init];
+ callbacks = [[NSMutableSet alloc] init];
});
- return _debugCallbacks;
+ return callbacks;
+}
+
++ (NSMutableSet *)globalBlockCallbacks_requestFinished
+{
+ static NSMutableSet * callbacks;
+ static dispatch_once_t onceToken;
+ dispatch_once(&onceToken, ^{
+ callbacks = [[NSMutableSet alloc] init];
+ });
+ return callbacks;
}
-#endif
+ (void)networkRequestThreadEntryPoint:(id)__unused object
{
@@ -114,9 +122,9 @@ - (void)finish
{
[self willChangeValueForKey:@"isFinished"];
self.state = finished;
-#ifdef FSURLDEBUG
- for (FSURLDebugBlockCallback callback in [[self class] debugCallbacks]) callback(self.request, RequestFinished, self.response, self.payload, self.error);
-#endif
+
+ for (FSURLRequestFinishedCallback blockCallback in [[self class] globalBlockCallbacks_requestFinished]) blockCallback(self.request, [NSThread currentThread], self.response, self.payload, self.error);
+
if (self.onFinish) self.onFinish(self.response, self.payload, self.error);
if (self.delegate&&self.callback) {
NSInvocation* inv = [NSInvocation invocationWithMethodSignature:[self.delegate methodSignatureForSelector:self.callback]];
@@ -145,6 +153,8 @@ - (void)operationDidStart
[self.connection scheduleInRunLoop:runLoop forMode:runLoopMode];
}
+ for (FSURLRequestStartedCallback blockCallback in [[self class] globalBlockCallbacks_requestStarted]) blockCallback(self.request, [NSThread currentThread]);
+
[self.connection start];
}
@@ -157,10 +167,6 @@ - (void)start
self.state = executing;
-#ifdef FSURLDEBUG
- for (FSURLDebugBlockCallback callback in [[self class] debugCallbacks]) callback(self.request, RequestBegan, nil, nil, nil);
-#endif
-
[self performSelector:@selector(operationDidStart) onThread:self.targetThread withObject:nil waitUntilDone:YES modes:[self.runLoopModes allObjects]];
}

0 comments on commit 4750833

Please sign in to comment.