2 * Copyright (c) 2007-2009 Dave Dribin
4 * Permission is hereby granted, free of charge, to any person
5 * obtaining a copy of this software and associated documentation
6 * files (the "Software"), to deal in the Software without
7 * restriction, including without limitation the rights to use, copy,
8 * modify, merge, publish, distribute, sublicense, and/or sell copies
9 * of the Software, and to permit persons to whom the Software is
10 * furnished to do so, subject to the following conditions:
12 * The above copyright notice and this permission notice shall be
13 * included in all copies or substantial portions of the Software.
15 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
16 * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
17 * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
18 * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS
19 * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
20 * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
21 * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
27 * This class is based on CInvocationGrabber:
29 * Copyright (c) 2007, Toxic Software
30 * All rights reserved.
31 * Redistribution and use in source and binary forms, with or without
32 * modification, are permitted provided that the following conditions are
35 * * Redistributions of source code must retain the above copyright notice,
36 * this list of conditions and the following disclaimer.
38 * * Redistributions in binary form must reproduce the above copyright
39 * notice, this list of conditions and the following disclaimer in the
40 * documentation and/or other materials provided with the distribution.
42 * * Neither the name of the Toxic Software nor the names of its
43 * contributors may be used to endorse or promote products derived from
44 * this software without specific prior written permission.
46 * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
47 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
48 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
49 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE
50 * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
51 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
52 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
53 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
54 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
55 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
56 * THE POSSIBILITY OF SUCH DAMAGE.
60 #import "DDInvocationGrabber.h"
63 @implementation DDInvocationGrabber
65 + (id)invocationGrabber
67 return([[[self alloc] init] autorelease]);
74 _forwardInvokesOnMainThread = NO;
82 [self setTarget:NULL];
83 [self setInvocation:NULL];
95 - (void)setTarget:(id)inTarget
97 if (_target != inTarget)
99 [_target autorelease];
100 _target = [inTarget retain];
104 - (NSInvocation *)invocation
109 - (void)setInvocation:(NSInvocation *)inInvocation
111 if (_invocation != inInvocation)
113 [_invocation autorelease];
114 _invocation = [inInvocation retain];
118 - (BOOL)forwardInvokesOnMainThread;
120 return _forwardInvokesOnMainThread;
123 - (void)setForwardInvokesOnMainThread:(BOOL)forwardInvokesOnMainThread;
125 _forwardInvokesOnMainThread = forwardInvokesOnMainThread;
128 - (BOOL)waitUntilDone;
130 return _waitUntilDone;
133 - (void)setWaitUntilDone:(BOOL)waitUntilDone;
135 _waitUntilDone = waitUntilDone;
140 - (NSMethodSignature *)methodSignatureForSelector:(SEL)selector
142 return [[self target] methodSignatureForSelector:selector];
145 - (void)forwardInvocation:(NSInvocation *)ioInvocation
147 [ioInvocation setTarget:[self target]];
148 [self setInvocation:ioInvocation];
149 if (_forwardInvokesOnMainThread)
152 [_invocation retainArguments];
153 [_invocation performSelectorOnMainThread:@selector(invoke)
155 waitUntilDone:_waitUntilDone];
163 @implementation DDInvocationGrabber (DDnvocationGrabber_Conveniences)
165 - (id)prepareWithInvocationTarget:(id)inTarget
167 [self setTarget:inTarget];