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