/* * $Id$ * MacPorts.Framework * * Authors: * George Armah * * Copyright (c) 2008 George Armah * All rights reserved. * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions * are met: * 1. Redistributions of source code must retain the above copyright * notice, this list of conditions and the following disclaimer. * 2. Redistributions in binary form must reproduce the above copyright * notice, this list of conditions and the following disclaimer in the * documentation and/or other materials provided with the distribution. * 3. Neither the name of the copyright owner nor the names of contributors * may be used to endorse or promote products derived from this software * without specific prior written permission. * * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE * POSSIBILITY OF SUCH DAMAGE. */ #import "MPNotifications.h" @implementation MPNotifications + (MPNotifications *)sharedListener { @synchronized(self) { if ([[[NSThread currentThread] threadDictionary] objectForKey:@"sharedMPListener"] == nil) { [[self alloc] init]; } } return [[[NSThread currentThread] threadDictionary] objectForKey:@"sharedMPListener"]; } + (id)allocWithZone:(NSZone *)zone { @synchronized(self) { if ([[[NSThread currentThread] threadDictionary] objectForKey:@"sharedMPListener"] == nil) { [[[NSThread currentThread] threadDictionary] setObject:[super allocWithZone:zone] forKey:@"sharedMPListener"]; return [[[NSThread currentThread] threadDictionary] objectForKey:@"sharedMPListener"]; } } return nil; } - (id)copyWithZone:(NSZone *)zone { return self; } - (id)retain { return self; } - (NSUInteger)retainCount { return NSUIntegerMax; //denotes an object that cannot be released } -(void) release { //do nothing } - (id) autorelease { return self; } - (id)init { if (self = [super init]) { performingTclCommand = @""; blockOptions = [[NSMutableDictionary alloc] initWithObjectsAndKeys: [NSNumber numberWithInt:0], MPMSG, [NSNumber numberWithInt:0], MPINFO, [NSNumber numberWithInt:0], MPWARN, [NSNumber numberWithInt:0], MPERROR, [NSNumber numberWithInt:0], MPDEBUG, [NSNumber numberWithInt:0], MPALL, nil]; //NSLog(@"Dictionary is %@ ", [blockOptions description]); } return self; } - (void)dealloc { [super dealloc]; } //Should I raise an exception for invalid blockOptions that are //passed to this method? -(BOOL)checkIfNotificationBlocked:(NSString *)option { if ( [[blockOptions objectForKey:option] intValue] == 1 ) { return YES; } return NO; } -(void)blockNotification:(NSString *)option { //Should do some checking first if ( ! [self checkIfNotificationBlocked:option] ){ [blockOptions setObject:[NSNumber numberWithInt:1] forKey:option]; } } -(void)unblockNotification:(NSString *)option { if ( [self checkIfNotificationBlocked:option] ) { [blockOptions setObject:[NSNumber numberWithInt:0] forKey:option]; } } #pragma mark - #pragma mark Private Methods -(BOOL) postNotificationOnMainThread:(NSString *) message { // [[NSNotificationCenter defaultCenter] postNotificationOnMainThreadWithName:MPINFO // object:nil // userInfo:[NSDictionary dictionaryWithObjectsAndKeys:message, MPMESSAGE, nil]]; [[NSNotificationCenter defaultCenter] postNotificationName:MPINFO object:nil userInfo:[NSDictionary dictionaryWithObjectsAndKeys:message, MPMESSAGE, nil]]; return YES; } - (void) setPerformingTclCommand:(NSString *)tclString { [[[NSThread currentThread] threadDictionary] setObject:tclString forKey:@"performingTclCommand"]; // if(performingTclCommand != tclString){ // [performingTclCommand release]; // performingTclCommand = [tclString copy]; // } } - (NSString *) performingTclCommand { // return performingTclCommand; id tclCmd = [[[NSThread currentThread] threadDictionary] objectForKey:@"performingTclCommand"]; if (tclCmd == nil) return @""; return tclCmd; } @end