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