PageRenderTime 4ms CodeModel.GetById 1ms app.highlight 1ms RepoModel.GetById 1ms app.codeStats 0ms

/Foundation/CPInvocationOperation.j

http://github.com/cacaodev/cappuccino
Unknown | 104 lines | 91 code | 13 blank | 0 comment | 0 complexity | cc0ccbf8de589e14acb2e8965cd10b4a MD5 | raw file
  1/*
  2 * CPInvocationOperation.j
  3 *
  4 * Created by Johannes Fahrenkrug.
  5 * Copyright 2009, Springenwerk.
  6 *
  7 * This library is free software; you can redistribute it and/or
  8 * modify it under the terms of the GNU Lesser General Public
  9 * License as published by the Free Software Foundation; either
 10 * version 2.1 of the License, or (at your option) any later version.
 11 *
 12 * This library is distributed in the hope that it will be useful,
 13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
 15 * Lesser General Public License for more details.
 16 *
 17 * You should have received a copy of the GNU Lesser General Public
 18 * License along with this library; if not, write to the Free Software
 19 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
 20 */
 21
 22@import "CPInvocation.j"
 23@import "CPObject.j"
 24@import "CPOperation.j"
 25
 26/*!
 27    @class CPInvocationOperation
 28    @brief Represents an operation using an invocation that can be run in an CPOperationQueue
 29*/
 30@implementation CPInvocationOperation : CPOperation
 31{
 32    CPInvocation _invocation;
 33}
 34
 35
 36- (void)main
 37{
 38    if (_invocation)
 39    {
 40        [_invocation invoke];
 41    }
 42}
 43
 44- (id)init
 45{
 46    if (self = [super init])
 47    {
 48        _invocation = nil;
 49    }
 50    return self;
 51}
 52
 53/*!
 54    Returns a CPInvocationOperation object initialized with the specified invocation object.
 55    @param inv the invocation
 56*/
 57- (id)initWithInvocation:(CPInvocation)inv
 58{
 59    if (self = [self init])
 60    {
 61        _invocation = inv;
 62    }
 63
 64    return self;
 65}
 66
 67/*!
 68    Returns a CPInvocationOperation object initialized with the specified target and selector.
 69    @param target the target
 70    @param sel the selector that should be called on the target
 71    @param arg the arguments
 72*/
 73- (id)initWithTarget:(id)target selector:(SEL)sel object:(id)arg
 74{
 75    var inv = [[CPInvocation alloc] initWithMethodSignature:nil];
 76    [inv setTarget:target];
 77    [inv setSelector:sel];
 78    [inv setArgument:arg atIndex:2];
 79
 80    return [self initWithInvocation:inv];
 81}
 82
 83/*!
 84    Returns the receiver’s invocation object.
 85*/
 86- (CPInvocation)invocation
 87{
 88    return _invocation;
 89}
 90
 91/*!
 92    Returns the result of the invocation or method.
 93*/
 94- (id)result
 95{
 96    if ([self isFinished] && _invocation)
 97    {
 98        return [_invocation returnValue];
 99    }
100
101    return nil;
102}
103
104@end