CatNiP prefinal
Sähköinen nuottikirja, HY-TKTKL-OHTUPROJ KESÄ11
/Users/awniemel/Notepad-SVN/svn/trunk/CatNiP/CatNiP/CatNiPErrorManager.m
Go to the documentation of this file.
00001 
00014 #import "CatNiPErrorManager.h"
00015 
00016 @implementation CatNiPErrorManager
00017 
00018 static CatNiPErrorManager *sharedErrorManager = nil;
00019 
00021 -(id)init {
00022     if((self = [super init])) {
00023         errorConsumers = [[NSMutableSet alloc] init];
00024     }
00025     return self;
00026 }
00028 -(void)dealloc {
00029     [errorConsumers removeAllObjects];
00030     [errorConsumers release];
00031     errorConsumers = nil;
00032     [super dealloc];
00033 }
00038 -(void)reportError:(NSError *)error {
00039     NSEnumerator *e = [errorConsumers objectEnumerator];
00040     id<CatNiPErrorConsumer> consumer;
00041     while((consumer = [e nextObject])) {
00042         [consumer processError:error];
00043     }
00044     return;
00045 }
00050 -(void)addErrorConsumer:(id <CatNiPErrorConsumer>)consumer {
00051     if([errorConsumers containsObject:consumer]) {
00052         return;
00053     }
00054     else {
00055         [errorConsumers addObject:consumer];
00056     }
00057 }
00062 -(void)removeErrorConsumer:(id <CatNiPErrorConsumer>)consumer {
00063     if([errorConsumers containsObject:consumer]) {
00064         [errorConsumers removeObject:consumer];
00065     }
00066 }
00067 
00068 
00069 #pragma mark - Singleton Pattern implementation
00070 
00075 +(CatNiPErrorManager *)sharedManager {
00076     @synchronized(self) {
00077         if(sharedErrorManager == nil) {
00078             [[self alloc] init]; // assignment done in allocWithZone
00079         }
00080     }
00081     return sharedErrorManager;
00082 }
00083 
00091 +(id)allocWithZone:(NSZone *)zone {
00092     @synchronized(self) {
00093         if(sharedErrorManager == nil) {
00094             // assign and return the manager when called for the first time
00095             sharedErrorManager = [super allocWithZone:zone];
00096             return sharedErrorManager;
00097         }
00098     }
00099     return nil; // when we already have a shared manager, return nil
00100 }
00101 
00107 -(id)copyWithZone:(NSZone *)zone {
00108     return self;
00109 }
00110 
00116 -(id)retain {
00117     return self;
00118 }
00119 
00125 -(NSUInteger)retainCount {
00126     return UINT_MAX; // denotes an object that cannot be released
00127 }
00128 
00129 
00133 -(void)release {
00134     return;
00135 }
00141 -(id)autorelease {
00142     return self;
00143 }
00144 @end
 All Classes Files Functions Variables Enumerations Enumerator Properties Defines