Browse files

Stubbed core of state machine, minus tthe, you know, *actual* state m…

…achine.
  • Loading branch information...
1 parent 97a6007 commit 328af8bd81c1c61b2a5a979932df0fcaf28a381c Jim Dovey committed Jun 16, 2011
View
10 AQAppStateMachine.xcodeproj/project.pbxproj
@@ -23,6 +23,9 @@
3866938B13AA805500268560 /* AQRange.m in Sources */ = {isa = PBXBuildFile; fileRef = 3866938913AA805500268560 /* AQRange.m */; };
3866938E13AA82C400268560 /* AQNotifyingBitfield.h in Headers */ = {isa = PBXBuildFile; fileRef = 3866938C13AA82C400268560 /* AQNotifyingBitfield.h */; };
3866938F13AA82C400268560 /* AQNotifyingBitfield.m in Sources */ = {isa = PBXBuildFile; fileRef = 3866938D13AA82C400268560 /* AQNotifyingBitfield.m */; };
+ 3866939513AAA0C600268560 /* AQAppStateMachine.h in Headers */ = {isa = PBXBuildFile; fileRef = 3866939313AAA0C600268560 /* AQAppStateMachine.h */; };
+ 3866939613AAA0C600268560 /* AQAppStateMachine.m in Sources */ = {isa = PBXBuildFile; fileRef = 3866939413AAA0C600268560 /* AQAppStateMachine.m */; };
+ 3866939713AAA0C600268560 /* AQAppStateMachine.m in Sources */ = {isa = PBXBuildFile; fileRef = 3866939413AAA0C600268560 /* AQAppStateMachine.m */; };
38AC30BC13AA3D5C00AB071C /* AQBitfieldPredicates.h in Headers */ = {isa = PBXBuildFile; fileRef = 38AC30BA13AA3D5C00AB071C /* AQBitfieldPredicates.h */; };
38AC30BD13AA3D5C00AB071C /* AQBitfieldPredicates.m in Sources */ = {isa = PBXBuildFile; fileRef = 38AC30BB13AA3D5C00AB071C /* AQBitfieldPredicates.m */; };
38AC30BE13AA3D5C00AB071C /* AQBitfieldPredicates.m in Sources */ = {isa = PBXBuildFile; fileRef = 38AC30BB13AA3D5C00AB071C /* AQBitfieldPredicates.m */; };
@@ -55,6 +58,8 @@
3866938913AA805500268560 /* AQRange.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = AQRange.m; sourceTree = "<group>"; };
3866938C13AA82C400268560 /* AQNotifyingBitfield.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = AQNotifyingBitfield.h; sourceTree = "<group>"; };
3866938D13AA82C400268560 /* AQNotifyingBitfield.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = AQNotifyingBitfield.m; sourceTree = "<group>"; };
+ 3866939313AAA0C600268560 /* AQAppStateMachine.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = AQAppStateMachine.h; sourceTree = "<group>"; };
+ 3866939413AAA0C600268560 /* AQAppStateMachine.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = AQAppStateMachine.m; sourceTree = "<group>"; };
38AC30BA13AA3D5C00AB071C /* AQBitfieldPredicates.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = AQBitfieldPredicates.h; sourceTree = "<group>"; };
38AC30BB13AA3D5C00AB071C /* AQBitfieldPredicates.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = AQBitfieldPredicates.m; sourceTree = "<group>"; };
/* End PBXFileReference section */
@@ -123,6 +128,8 @@
3866938913AA805500268560 /* AQRange.m */,
3866938C13AA82C400268560 /* AQNotifyingBitfield.h */,
3866938D13AA82C400268560 /* AQNotifyingBitfield.m */,
+ 3866939313AAA0C600268560 /* AQAppStateMachine.h */,
+ 3866939413AAA0C600268560 /* AQAppStateMachine.m */,
38431B5A13A7C26800178A7E /* Supporting Files */,
);
path = AQAppStateMachine;
@@ -166,6 +173,7 @@
38AC30BC13AA3D5C00AB071C /* AQBitfieldPredicates.h in Headers */,
3866938A13AA805500268560 /* AQRange.h in Headers */,
3866938E13AA82C400268560 /* AQNotifyingBitfield.h in Headers */,
+ 3866939513AAA0C600268560 /* AQAppStateMachine.h in Headers */,
);
runOnlyForDeploymentPostprocessing = 0;
};
@@ -271,6 +279,7 @@
38AC30BD13AA3D5C00AB071C /* AQBitfieldPredicates.m in Sources */,
3866938B13AA805500268560 /* AQRange.m in Sources */,
3866938F13AA82C400268560 /* AQNotifyingBitfield.m in Sources */,
+ 3866939613AAA0C600268560 /* AQAppStateMachine.m in Sources */,
);
runOnlyForDeploymentPostprocessing = 0;
};
@@ -281,6 +290,7 @@
38431B7513A7C26900178A7E /* AQAppStateMachineTests.m in Sources */,
38431B8213A7C63B00178A7E /* AQBitfield.m in Sources */,
38AC30BE13AA3D5C00AB071C /* AQBitfieldPredicates.m in Sources */,
+ 3866939713AAA0C600268560 /* AQAppStateMachine.m in Sources */,
);
runOnlyForDeploymentPostprocessing = 0;
};
View
32 AQAppStateMachine/AQAppStateMachine.h
@@ -0,0 +1,32 @@
+//
+// AQAppStateMachine.h
+// AQAppStateMachine
+//
+// Created by Jim Dovey on 11-06-16.
+// Copyright 2011 Jim Dovey. All rights reserved.
+//
+
+#import <Foundation/Foundation.h>
+#import "AQBitfield.h"
+
+/*!
+ This is intended to be a singleton class.
+ */
+@interface AQAppStateMachine : NSObject
+{
+ AQBitfield * _stateBits;
+}
+
+/*!
+ Obtain/create the singleton state machine instance.
+ */
++ (AQAppStateMachine *) appStateMachine;
+
+- (void) notifyForChangesToStateBitAtIndex: (NSUInteger) index usingBlock: (void (^)(void)) block;
+- (void) notifyForChangesToStateBitsInRange: (NSRange) range usingBlock: (void (^)(void)) block;
+- (void) notifyForChangesToStateBitsInRange: (NSRange) range maskedWithInteger: (NSUInteger) mask
+ usingBlock: (void (^)(void)) block;
+- (void) notifyForChangesToStateBitsInRange: (NSRange) range maskedWithBits: (AQBitfield *) mask
+ usingBlock: (void (^)(void)) block;
+
+@end
View
57 AQAppStateMachine/AQAppStateMachine.m
@@ -0,0 +1,57 @@
+//
+// AQAppStateMachine.m
+// AQAppStateMachine
+//
+// Created by Jim Dovey on 11-06-16.
+// Copyright 2011 Jim Dovey. All rights reserved.
+//
+
+#import "AQAppStateMachine.h"
+#import <dispatch/dispatch.h>
+
+@implementation AQAppStateMachine
+
++ (AQAppStateMachine *) appStateMachine
+{
+ static AQAppStateMachine * __singleton = nil;
+ static dispatch_once_t onceToken;
+ dispatch_once(&onceToken, ^{__singleton = [[self alloc] init];});
+
+ return ( __singleton );
+}
+
+- (id) init
+{
+ self = [super init];
+ if ( self == nil )
+ return ( nil );
+
+ // start out with 128 bits
+ _stateBits = [[AQBitfield alloc] initWithSize: 128];
+
+ return ( self );
+}
+
+- (void) notifyForChangesToStateBitAtIndex: (NSUInteger) index usingBlock: (void (^)(void)) block
+{
+
+}
+
+- (void) notifyForChangesToStateBitsInRange: (NSRange) range usingBlock: (void (^)(void)) block
+{
+
+}
+
+- (void) notifyForChangesToStateBitsInRange: (NSRange) range maskedWithInteger: (NSUInteger) mask
+ usingBlock: (void (^)(void)) block
+{
+
+}
+
+- (void) notifyForChangesToStateBitsInRange: (NSRange) range maskedWithBits: (AQBitfield *) mask
+ usingBlock: (void (^)(void)) block
+{
+
+}
+
+@end
View
4 AQAppStateMachine/AQNotifyingBitfield.h
@@ -9,9 +9,11 @@
#import <Foundation/Foundation.h>
#import "AQBitfield.h"
+typedef void (^AQRangeNotification)(NSRange range);
+
@interface AQNotifyingBitfield : AQBitfield
-- (void) notifyModificationOfBitsInRange: (NSRange) range usingBlock: (void (^)(void)) block;
+- (void) notifyModificationOfBitsInRange: (NSRange) range usingBlock: (AQRangeNotification) block;
- (void) removeNotifierForBitsInRange: (NSRange) range; // exact range match
- (void) removeAllNotifiersWithinRange: (NSRange) range; // any wholly-contained ranges
View
8 AQAppStateMachine/AQNotifyingBitfield.m
@@ -35,7 +35,7 @@ - (void) dealloc
dispatch_release(_syncQ);
}
-- (void) notifyModificationOfBitsInRange: (NSRange) range usingBlock: (void (^)(void)) block
+- (void) notifyModificationOfBitsInRange: (NSRange) range usingBlock: (AQRangeNotification) block
{
dispatch_async(_syncQ, ^{
AQRange * rangeObject = [[AQRange alloc] initWithRange: range];
@@ -83,7 +83,11 @@ - (void) removeAllNotifiersWithinRange: (NSRange) range
- (void) _scheduleNotificationForRange: (AQRange *) range
{
- dispatch_async(dispatch_get_global_queue(0, 0), [_lookup objectForKey: range]);
+ dispatch_async(dispatch_get_global_queue(0, 0), ^{
+ AQRangeNotification block = (AQRangeNotification)[_lookup objectForKey: range];
+ if ( block != nil )
+ block(range.range);
+ });
}
- (void) flipBitAtIndex: (NSUInteger) index

0 comments on commit 328af8b

Please sign in to comment.