jens@0: // jens@0: // BLIPDispatcher.m jens@0: // MYNetwork jens@0: // jens@0: // Created by Jens Alfke on 5/15/08. jens@0: // Copyright 2008 Jens Alfke. All rights reserved. jens@0: // jens@0: jens@0: #import "BLIPDispatcher.h" jens@0: #import "Target.h" jens@0: #import "BLIPRequest.h" jens@0: #import "BLIPProperties.h" jens@1: #import "Logging.h" jens@1: #import "Test.h" jens@0: jens@0: jens@0: @implementation BLIPDispatcher jens@0: jens@0: jens@0: - (id) init jens@0: { jens@0: self = [super init]; jens@0: if (self != nil) { jens@0: _targets = [[NSMutableArray alloc] init]; jens@0: _predicates = [[NSMutableArray alloc] init]; jens@0: } jens@0: return self; jens@0: } jens@0: jens@0: - (void) dealloc jens@0: { jens@0: [_targets release]; jens@0: [_predicates release]; jens@0: [_parent release]; jens@0: [super dealloc]; jens@0: } jens@0: jens@0: jens@0: @synthesize parent=_parent; jens@0: jens@0: jens@0: - (void) addTarget: (MYTarget*)target forPredicate: (NSPredicate*)predicate jens@0: { jens@0: [_targets addObject: target]; jens@0: [_predicates addObject: predicate]; jens@0: } jens@0: jens@0: jens@0: - (void) removeTarget: (MYTarget*)target jens@0: { jens@0: NSUInteger i = [_targets indexOfObject: target]; jens@0: if( i != NSNotFound ) { jens@0: [_targets removeObjectAtIndex: i]; jens@0: [_predicates removeObjectAtIndex: i]; jens@0: } jens@0: } jens@0: jens@0: jens@0: - (void) addTarget: (MYTarget*)target forValueOfProperty: (NSString*)value forKey: (NSString*)key jens@0: { jens@0: [self addTarget: target jens@0: forPredicate: [NSComparisonPredicate predicateWithLeftExpression: [NSExpression expressionForKeyPath: key] jens@0: rightExpression: [NSExpression expressionForConstantValue: value] jens@0: modifier: NSDirectPredicateModifier jens@0: type: NSEqualToPredicateOperatorType jens@0: options: 0]]; jens@0: } jens@0: jens@0: jens@0: - (BOOL) dispatchMessage: (BLIPMessage*)message jens@0: { jens@0: NSDictionary *properties = message.properties.allProperties; jens@0: NSUInteger n = _predicates.count; jens@0: for( NSUInteger i=0; i. All rights reserved. jens@0: jens@0: Redistribution and use in source and binary forms, with or without modification, are permitted jens@0: provided that the following conditions are met: jens@0: jens@0: * Redistributions of source code must retain the above copyright notice, this list of conditions jens@0: and the following disclaimer. jens@0: * Redistributions in binary form must reproduce the above copyright notice, this list of conditions jens@0: and the following disclaimer in the documentation and/or other materials provided with the jens@0: distribution. jens@0: jens@0: THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR jens@0: IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND jens@0: FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRI- jens@0: BUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES jens@0: (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR jens@0: PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN jens@0: CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF jens@0: THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. jens@0: */