Permalink
Browse files

make command route a singleton for easy extensibility by plugins

  • Loading branch information...
1 parent e9a432d commit c9bad34f4058bd9823cbe8880fa846c475a85e20 @krukow krukow committed Nov 16, 2012
Showing with 22 additions and 1 deletion.
  1. +2 −0 src/FrankCommandRoute.h
  2. +19 −0 src/FrankCommandRoute.m
  3. +1 −1 src/FrankServer.m
View
@@ -21,6 +21,8 @@
NSMutableDictionary *_commandDict;
}
++ (FrankCommandRoute *) singleton;
+
-(void) registerCommand: (id<FrankCommand>)command withName:(NSString *)commandName;
@end
View
@@ -17,6 +17,25 @@
@implementation FrankCommandRoute
+
+#pragma mark singleton implementation
+
+static FrankCommandRoute *s_singleton;
+
++ (void)initialize
+{
+ static BOOL initialized = NO;
+ if(!initialized)
+ {
+ initialized = YES;
+ s_singleton = [[FrankCommandRoute alloc] init];
+ }
+}
+
++ (FrankCommandRoute *) singleton{
+ return s_singleton;
+}
+
- (id) init
{
self = [super init];
View
@@ -41,7 +41,7 @@ - (id) initWithStaticFrankBundleNamed:(NSString *)bundleName
if( ![bundleName hasSuffix:@".bundle"] )
bundleName = [bundleName stringByAppendingString:@".bundle"];
- FrankCommandRoute *frankCommandRoute = [[[FrankCommandRoute alloc] init] autorelease];
+ FrankCommandRoute *frankCommandRoute = [FrankCommandRoute singleton];
[frankCommandRoute registerCommand:[[[DumpCommand alloc]init]autorelease] withName:@"dump"];
[frankCommandRoute registerCommand:[[[MapOperationCommand alloc]init]autorelease] withName:@"map"];
[frankCommandRoute registerCommand:[[[OrientationCommand alloc]init]autorelease] withName:@"orientation"];

0 comments on commit c9bad34

Please sign in to comment.