ConcurrentOperation.m
author Jens Alfke <jens@mooseyard.com>
Wed Sep 02 08:41:25 2009 -0700 (2009-09-02)
changeset 35 5cab3034d3a1
parent 14 1af6415650bf
permissions -rw-r--r--
10.6 compatibility: Fix some new compiler warnings, and work around apparent regressions in NSTask and -stringByStandardizingPath.
jens@0
     1
//
jens@0
     2
//  ConcurrentOperation.m
jens@0
     3
//  MYUtilities
jens@0
     4
//
jens@0
     5
//  Created by Jens Alfke on 2/5/08.
jens@0
     6
//  Copyright 2008 Jens Alfke. All rights reserved.
jens@0
     7
//
jens@0
     8
jens@0
     9
#import "ConcurrentOperation.h"
jens@26
    10
#import "Test.h"
jens@0
    11
jens@14
    12
// See file:///Developer/Documentation/DocSets/com.apple.ADC_Reference_Library.CoreReference.docset/Contents/Resources/Documents/documentation/Cocoa/Reference/NSOperation_class/Reference/Reference.html
jens@0
    13
jens@0
    14
jens@0
    15
@implementation ConcurrentOperation
jens@0
    16
jens@0
    17
jens@0
    18
- (BOOL) isConcurrent {return YES;}
jens@0
    19
jens@0
    20
- (void) main
jens@0
    21
{
jens@0
    22
    Assert(NO,@"Shouldn't call -main method of ConcurrentOperation");
jens@0
    23
}
jens@0
    24
jens@0
    25
- (BOOL) isExecuting
jens@0
    26
{
jens@0
    27
    return _isExecuting;
jens@0
    28
}
jens@0
    29
jens@0
    30
- (BOOL) isFinished
jens@0
    31
{
jens@0
    32
    return _isFinished;
jens@0
    33
}
jens@0
    34
jens@0
    35
- (void) start
jens@0
    36
{
jens@0
    37
    // don't call super!
jens@0
    38
    Log(@"Starting %@",self);
jens@0
    39
    [self willChangeValueForKey: @"isExecuting"];
jens@0
    40
    _isExecuting = YES;
jens@0
    41
    [self didChangeValueForKey: @"isExecuting"];
jens@0
    42
}
jens@0
    43
jens@0
    44
- (void) finish
jens@0
    45
{
jens@0
    46
    Log(@"Finished %@",self);
jens@0
    47
    [self willChangeValueForKey: @"isExecuting"];
jens@0
    48
    [self willChangeValueForKey: @"isFinished"];
jens@0
    49
    _isExecuting = NO;
jens@0
    50
    _isFinished = YES;
jens@0
    51
    [self didChangeValueForKey: @"isFinished"];
jens@0
    52
    [self didChangeValueForKey: @"isExecuting"];
jens@0
    53
}
jens@0
    54
jens@0
    55
jens@0
    56
- (void) cancel
jens@0
    57
{
jens@0
    58
    Log(@"Canceling %@",self);
jens@0
    59
    [super cancel];
jens@0
    60
    if( _isExecuting ) {
jens@0
    61
        [self willChangeValueForKey: @"isExecuting"];
jens@0
    62
        _isExecuting = NO;
jens@0
    63
        [self didChangeValueForKey: @"isExecuting"];
jens@0
    64
    }
jens@0
    65
}
jens@0
    66
jens@0
    67
jens@0
    68
@end
jens@11
    69
jens@11
    70
jens@11
    71
/*
jens@11
    72
 Copyright (c) 2008, Jens Alfke <jens@mooseyard.com>. All rights reserved.
jens@11
    73
 
jens@11
    74
 Redistribution and use in source and binary forms, with or without modification, are permitted
jens@11
    75
 provided that the following conditions are met:
jens@11
    76
 
jens@11
    77
 * Redistributions of source code must retain the above copyright notice, this list of conditions
jens@11
    78
 and the following disclaimer.
jens@11
    79
 * Redistributions in binary form must reproduce the above copyright notice, this list of conditions
jens@11
    80
 and the following disclaimer in the documentation and/or other materials provided with the
jens@11
    81
 distribution.
jens@11
    82
 
jens@11
    83
 THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR
jens@11
    84
 IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND 
jens@11
    85
 FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRI-
jens@11
    86
 BUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
jens@11
    87
 (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR 
jens@11
    88
  PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 
jens@11
    89
 CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF 
jens@11
    90
 THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
jens@11
    91
 */