Permalink
Browse files

Implemented core notification routines on AQAppStateMachine.

  • Loading branch information...
1 parent 70c15ef commit 82e973f30381ec24ae1422d30849afae06094fe1 Jim Dovey committed Jun 22, 2011
@@ -44,36 +44,58 @@ - (void) dealloc
dispatch_release(_syncQ);
}
-- (void) notifyForChangesToStateBitAtIndex: (NSUInteger) index usingBlock: (void (^)(void)) block
+- (void) _runNotificationBlocksForChangeInRange: (NSRange) range
{
- [self notifyForChangesToStateBitsInRange: NSMakeRange(index, 1) usingBlock: block];
+ for ( AQStateMatchingDescriptor * match in _matchDescriptors )
+ {
+ if ( [match matchesRange: range] == NO )
+ continue;
+
+ dispatch_block_t block = (dispatch_block_t)[_notifierLookup objectForKey: [match uniqueID]];
+ if ( block != nil )
+ block();
+ }
}
-- (void) notifyForChangesToStateBitsInRange: (NSRange) range usingBlock: (void (^)(void)) block
+- (void) _notifyForChangesToStatesMatchingDescriptor: (AQStateMatchingDescriptor *) desc
+ usingBlock: (void (^)(void)) block
{
- // create match descriptor and store it
- id desc = [[AQStateMatchingDescriptor alloc] initWithRange: range matchingMask: nil];
-
[_matchDescriptors addObject: desc];
[_notifierLookup setObject: block forKey: [desc uniqueID]];
- [_stateBits notifyModificationOfBitsInRange: range usingBlock: ^(NSRange range) {
+ NSRange notifyRange = desc.fullRange;
+ [_stateBits notifyModificationOfBitsInRange: notifyRange usingBlock: ^(NSRange range) {
// find and run any stored blocks
+ [self _runNotificationBlocksForChangeInRange: range];
}];
}
+- (void) notifyForChangesToStateBitAtIndex: (NSUInteger) index usingBlock: (void (^)(void)) block
+{
+ [self notifyForChangesToStateBitsInRange: NSMakeRange(index, 1) usingBlock: block];
+}
+
+- (void) notifyForChangesToStateBitsInRange: (NSRange) range usingBlock: (void (^)(void)) block
+{
+ // create match descriptor and store it
+ AQStateMatchingDescriptor * desc = [[AQStateMatchingDescriptor alloc] initWithRange: range matchingMask: nil];
+ [self _notifyForChangesToStatesMatchingDescriptor: desc usingBlock: block];
+}
+
- (void) notifyForChangesToStateBitsInRange: (NSRange) range
maskedWithInteger: (NSUInteger) mask
usingBlock: (void (^)(void)) block
{
-
+ AQStateMatchingDescriptor * desc = [[AQStateMatchingDescriptor alloc] initWith32BitMask: mask forRange: range];
+ [self _notifyForChangesToStatesMatchingDescriptor: desc usingBlock: block];
}
- (void) notifyForChangesToStateBitsInRange: (NSRange) range
maskedWithBits: (AQBitfield *) mask
usingBlock: (void (^)(void)) block
{
-
+ AQStateMatchingDescriptor * desc = [[AQStateMatchingDescriptor alloc] initWithRange: range matchingMask: mask];
+ [self _notifyForChangesToStatesMatchingDescriptor: desc usingBlock: block];
}
@end
@@ -17,9 +17,11 @@
}
// designated initializer
+// to specify 'no mask' in an array, use NSNull
- (id) initWithRanges: (NSIndexSet *) ranges matchingMasks: (NSArray *) masks;
@property (nonatomic, readonly) NSString * uniqueID;
+@property (nonatomic, readonly) NSRange fullRange;
- (BOOL) matchesRange: (NSRange) range;
@@ -58,6 +58,11 @@ - (id) initWithRanges: (NSIndexSet *) ranges matchingMasks: (NSArray *) masks
return ( self );
}
+- (NSRange) fullRange
+{
+ return ( NSMakeRange([_matchingIndices firstIndex], [_matchingIndices lastIndex] - [_matchingIndices firstIndex]) );
+}
+
- (BOOL) matchesRange: (NSRange) range
{
return ( [_matchingIndices intersectsIndexesInRange: range] );

0 comments on commit 82e973f

Please sign in to comment.