Permalink
Browse files

Merge commit '24911b4a16f3d8fc1ec5a51b1a2cd72b5b0010c1'

  • Loading branch information...
Chris Miller
Chris Miller committed Mar 9, 2012
2 parents fad3ae8 + 24911b4 commit 221c80fd2ef0369f986117be78c7c41a0d64e4ca
Showing with 31 additions and 0 deletions.
  1. +12 −0 FSURLOperation.h
  2. +19 −0 FSURLOperation.m
View
@@ -8,6 +8,14 @@
#import <Foundation/Foundation.h>
+#ifdef FSURLDEBUG
+enum FSURLDebugStatus {
+ RequestBegan,
+ RequestFinished
+} FSURLDebugStatus;
+typedef void(^FSURLDebugBlockCallback)(NSURLRequest *, enum FSURLDebugStatus, NSHTTPURLResponse *, NSData *, NSError *);
+#endif
+
@interface FSURLOperation : NSOperation
@property (strong) NSURLRequest* request; // changing this after the request has started produces undefined behavior.
@@ -19,6 +27,10 @@
@property (weak) id delegate;
@property (assign) SEL callback;
+#ifdef FSURLDEBUG
++ (NSMutableSet *)debugCallbacks; // use to get callbacks to all operations going in and out
+#endif
+
+ (FSURLOperation*)URLOperationWithRequest:(NSURLRequest*)req
completionBlock:(void(^)(NSHTTPURLResponse* resp, NSData* payload, NSError* error))completion;
+ (FSURLOperation*)URLOperationWithRequest:(NSURLRequest*)req
View
@@ -65,6 +65,18 @@ + (FSURLOperation*)URLOperationWithRequest:(NSURLRequest*)req
return operation;
}
+#ifdef FSURLDEBUG
++ (NSMutableSet *)debugCallbacks
+{
+ static NSMutableSet * _debugCallbacks;
+ static dispatch_once_t onceToken;
+ dispatch_once(&onceToken, ^{
+ _debugCallbacks = [[NSMutableSet alloc] init];
+ });
+ return _debugCallbacks;
+}
+#endif
+
+ (void)networkRequestThreadEntryPoint:(id)__unused object
{
do {
@@ -102,6 +114,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
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]];
@@ -142,6 +157,10 @@ - (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 221c80f

Please sign in to comment.