]> git.sesse.net Git - vlc/blobdiff - modules/gui/macosx/SPInvocationGrabbing.m
Useless #includes
[vlc] / modules / gui / macosx / SPInvocationGrabbing.m
index 2a16eefefaa131d3b2a70c697f4618369bb3fe8a..a79753bd34131602cf7996ff0d4dd344299c9cb6 100644 (file)
@@ -1,11 +1,11 @@
 /*
  Copyright (c) 2011, Joachim Bengtsson
  All rights reserved.
+
  Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met:
+
  * Neither the name of the organization nor the names of its contributors may be used to endorse or promote products derived from this software without specific prior written permission.
+
  THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  */
 
 @implementation SPInvocationGrabber
 - (id)initWithObject:(id)obj;
 {
-       return [self initWithObject:obj stacktraceSaving:YES];
+    return [self initWithObject:obj stacktraceSaving:YES];
 }
 
 -(id)initWithObject:(id)obj stacktraceSaving:(BOOL)saveStack;
 {
-       self.object = obj;
-
-       if(saveStack)
-               [self saveBacktrace];
+    self.object = obj;
+    if(saveStack)
+        [self saveBacktrace];
 
-       return self;
+    return self;
 }
+
 -(void)dealloc;
 {
-       free(frameStrings);
-       self.object = nil;
-       self.invocation = nil;
-       [super dealloc];
+    free(frameStrings);
+    self.object = nil;
+    self.invocation = nil;
+
+    [super dealloc];
 }
 @synthesize invocation = _invocation, object = _object;
 
 @synthesize backgroundAfterForward, onMainAfterForward, waitUntilDone;
 - (void)runInBackground;
 {
-       NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];
-       @try {
-               [self invoke];
-       }
-       @finally {
-               [pool drain];
-       }
+    NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];
+    @try {
+        [self invoke];
+    }
+    @finally {
+        [pool drain];
+    }
 }
 
 
 - (void)forwardInvocation:(NSInvocation *)anInvocation {
-       [anInvocation retainArguments];
-       anInvocation.target = _object;
-       self.invocation = anInvocation;
-       
-       if(backgroundAfterForward)
-               [NSThread detachNewThreadSelector:@selector(runInBackground) toTarget:self withObject:nil];
-       else if(onMainAfterForward)
+    [anInvocation retainArguments];
+    anInvocation.target = _object;
+    self.invocation = anInvocation;
+
+    if(backgroundAfterForward)
+        [NSThread detachNewThreadSelector:@selector(runInBackground) toTarget:self withObject:nil];
+    else if(onMainAfterForward)
         [self performSelectorOnMainThread:@selector(invoke) withObject:nil waitUntilDone:waitUntilDone];
 }
+
 - (NSMethodSignature *)methodSignatureForSelector:(SEL)inSelector {
-       NSMethodSignature *signature = [super methodSignatureForSelector:inSelector];
-       if (signature == NULL)
-               signature = [_object methodSignatureForSelector:inSelector];
-    
-       return signature;
+    NSMethodSignature *signature = [super methodSignatureForSelector:inSelector];
+    if (signature == NULL)
+        signature = [_object methodSignatureForSelector:inSelector];
+
+    return signature;
 }
 
 - (void)invoke;
 {
-
-       @try {
-               [_invocation invoke];
-       }
-       @catch (NSException * e) {
-               NSLog(@"SPInvocationGrabber's target raised %@:\n\t%@\nInvocation was originally scheduled at:", e.name, e);
-               [self printBacktrace];
-               printf("\n");
-               [e raise];
-       }
-
-       self.invocation = nil;
-       self.object = nil;
+    @try {
+        [_invocation invoke];
+    }
+
+    @catch (NSException * e) {
+        NSLog(@"SPInvocationGrabber's target raised %@:\n\t%@\nInvocation was originally scheduled at:", e.name, e);
+        [self printBacktrace];
+        printf("\n");
+        [e raise];
+    }
+
+    self.invocation = nil;
+    self.object = nil;
 }
 
 -(void)saveBacktrace;
 {
-  void *backtraceFrames[128];
-  frameCount = backtrace(&backtraceFrames[0], 128);
-  frameStrings = backtrace_symbols(&backtraceFrames[0], frameCount);
+    void *backtraceFrames[128];
+    frameCount = backtrace(&backtraceFrames[0], 128);
+    frameStrings = backtrace_symbols(&backtraceFrames[0], frameCount);
 }
+
 -(void)printBacktrace;
 {
-       for(int x = 3; x < frameCount; x++) {
-               if(frameStrings[x] == NULL) { break; }
-               printf("%s\n", frameStrings[x]);
-       }
+    for(int x = 3; x < frameCount; x++) {
+        if(frameStrings[x] == NULL) { break; }
+        printf("%s\n", frameStrings[x]);
+    }
 }
 @end
 
 @implementation NSObject (SPInvocationGrabbing)
 -(id)grab;
 {
-       return [[[SPInvocationGrabber alloc] initWithObject:self] autorelease];
+    return [[[SPInvocationGrabber alloc] initWithObject:self] autorelease];
 }
+
 -(id)invokeAfter:(NSTimeInterval)delta;
 {
-       id grabber = [self grab];
-       [NSTimer scheduledTimerWithTimeInterval:delta target:grabber selector:@selector(invoke) userInfo:nil repeats:NO];
-       return grabber;
+    id grabber = [self grab];
+    [NSTimer scheduledTimerWithTimeInterval:delta target:grabber selector:@selector(invoke) userInfo:nil repeats:NO];
+    return grabber;
 }
+
 - (id)nextRunloop;
 {
-       return [self invokeAfter:0];
+    return [self invokeAfter:0];
 }
+
 -(id)inBackground;
 {
     SPInvocationGrabber *grabber = [self grab];
-       grabber.backgroundAfterForward = YES;
-       return grabber;
+    grabber.backgroundAfterForward = YES;
+    return grabber;
 }
+
 -(id)onMainAsync:(BOOL)async;
 {
     SPInvocationGrabber *grabber = [self grab];
-       grabber.onMainAfterForward = YES;
+    grabber.onMainAfterForward = YES;
     grabber.waitUntilDone = !async;
-       return grabber;
+    return grabber;
 }
 
 @end