- Main Page
- Classes
- Files

- File List

# DDInvocationGrabber.h

    00001 /*
    00002  * Copyright (c) 2007-2008 Dave Dribin
    00003  *
    00004  * Permission is hereby granted, free of charge, to any person
    00005  * obtaining a copy of this software and associated documentation
    00006  * files (the "Software"), to deal in the Software without
    00007  * restriction, including without limitation the rights to use, copy,
    00008  * modify, merge, publish, distribute, sublicense, and/or sell copies
    00009  * of the Software, and to permit persons to whom the Software is
    00010  * furnished to do so, subject to the following conditions:
    00011  *
    00012  * The above copyright notice and this permission notice shall be
    00013  * included in all copies or substantial portions of the Software.
    00014  *
    00015  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
    00016  * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
    00017  * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
    00018  * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS
    00019  * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
    00020  * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
    00021  * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
    00022  * SOFTWARE.
    00023  */
    00024
    00025
    00026 /*
    00027  *  This class is based on CInvocationGrabber:
    00028  *
    00029  *  Copyright (c) 2007, Toxic Software
    00030  *  All rights reserved.
    00031  *  Redistribution and use in source and binary forms, with or without
    00032  *  modification, are permitted provided that the following conditions are
    00033  *  met:
    00034  *
    00035  *  * Redistributions of source code must retain the above copyright notice,
    00036  *  this list of conditions and the following disclaimer.
    00037  *
    00038  *  * Redistributions in binary form must reproduce the above copyright
    00039  *  notice, this list of conditions and the following disclaimer in the
    00040  *  documentation and/or other materials provided with the distribution.
    00041  *
    00042  *  * Neither the name of the Toxic Software nor the names of its
    00043  *  contributors may be used to endorse or promote products derived from
    00044  *  this software without specific prior written permission.
    00045  *
    00046  *  THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
    00047  *  ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
    00048  *  IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
    00049  *  PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE
    00050  *  LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
    00051  *  CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
    00052  *  SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
    00053  *  INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
    00054  *  CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
    00055  *  ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
    00056  *  THE POSSIBILITY OF SUCH DAMAGE.
    00057  *
    00058  */
    00059
    00060 #import <Foundation/Foundation.h>
    00061
    00062 /*
    00063  * @class DDInvocationGrabber
    00064  * @discussion DDInvocationGrabber is a helper object that makes it very easy to construct instances of NSInvocation for later use. The object is inspired by NSUndoManager's prepareWithInvocationTarget method. To use a DDInvocationGrabber object, you set its target to some object, then send it a message as if it were the target object (the DDInvocationGrabber object acts as a proxy), if the target message understands the message the DDInvocationGrabber object stores the message invocation.
    00065
    00066  DDInvocationGrabber *theGrabber = [DDInvocationGrabber invocationGrabber];
    00067  [theGrabber setTarget:someObject]
    00068  [theGrabber doSomethingWithParameter:someParameter]; // Send messages to 'theGrabber' as if it were 'someObject'
    00069  NSInvocation *theInvocation = [theGrabber invocation];
    00070
    00071  A slightly more concise version (using the covenience category) follows:
    00072
    00073  DDInvocationGrabber *theGrabber = [DDInvocationGrabber invocationGrabber];
    00074  [[theGrabber prepareWithInvocationTarget:someObject] doSomethingWithParameter:someParameter];
    00075  NSInvocation *theInvocation = [theGrabber invocation];
    00076
    00077  */
    00078 @interface DDInvocationGrabber : NSProxy
    00079 {
    00080         id _target;
    00081         NSInvocation * _invocation;
    00082     BOOL _forwardInvokesOnMainThread;
    00083     BOOL _waitUntilDone;
    00084 }
    00085
    00086 /*
    00087  * @method invocationGrabber
    00088  * @abstract Returns a newly allocated, inited, autoreleased DDInvocationGrabber object.
    00089  */
    00090 + (id)invocationGrabber;
    00091
    00092 - (id)target;
    00093 - (void)setTarget:(id)inTarget;
    00094
    00095 - (NSInvocation *)invocation;
    00096 - (void)setInvocation:(NSInvocation *)inInvocation;
    00097
    00098 - (BOOL)forwardInvokesOnMainThread;
    00099 - (void)setForwardInvokesOnMainThread:(BOOL)forwardInvokesOnMainThread;
    00100
    00101 - (BOOL)waitUntilDone;
    00102 - (void)setWaitUntilDone:(BOOL)waitUntilDone;
    00103
    00104 @end
    00105
    00106 @interface DDInvocationGrabber (DDInvocationGrabber_Conveniences)
    00107
    00108 /*
    00109  * @method prepareWithInvocationTarget:
    00110  * @abstract Sets the target object of the receiver and returns itself. The sender can then send a message to the
    00111  */
    00112 - (id)prepareWithInvocationTarget:(id)inTarget;
    00113
    00114 @end