forked from moredip/Frank
/
FrankServer.m
77 lines (64 loc) · 2.28 KB
/
FrankServer.m
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
//
// FrankServer.m
// Frank
//
// Created by phodgson on 5/24/10.
// Copyright 2010 ThoughtWorks. See NOTICE file for details.
//
#import "FrankServer.h"
#import "HTTPServer.h"
#import "RoutingHTTPConnection.h"
#import "StaticResourcesRoute.h"
#import "FrankCommandRoute.h"
#import "DumpCommand.h"
#import "MapOperationCommand.h"
#import "OrientationCommand.h"
#import "AppCommand.h"
#import "AccessibilityCheckCommand.h"
static NSUInteger __defaultPort = FRANK_SERVER_PORT;
@implementation FrankServer
+ (void)setDefaultHttpPort:(NSUInteger)port
{
__defaultPort = port;
}
- (id) initWithDefaultBundle {
return [self initWithStaticFrankBundleNamed: @"frank_static_resources"];
}
- (id) initWithStaticFrankBundleNamed:(NSString *)bundleName
{
self = [super init];
if (self != nil) {
if( ![bundleName hasSuffix:@".bundle"] )
bundleName = [bundleName stringByAppendingString:@".bundle"];
FrankCommandRoute *frankCommandRoute = [[[FrankCommandRoute alloc] init] autorelease];
[frankCommandRoute registerCommand:[[[DumpCommand alloc]init]autorelease] withName:@"dump"];
[frankCommandRoute registerCommand:[[[MapOperationCommand alloc]init]autorelease] withName:@"map"];
[frankCommandRoute registerCommand:[[[OrientationCommand alloc]init]autorelease] withName:@"orientation"];
[frankCommandRoute registerCommand:[[[AccessibilityCheckCommand alloc] init]autorelease] withName:@"accessibility_check"];
[frankCommandRoute registerCommand:[[[AppCommand alloc] init]autorelease] withName:@"app_exec"];
[[RequestRouter singleton] registerRoute:frankCommandRoute];
StaticResourcesRoute *staticRoute = [[[StaticResourcesRoute alloc] initWithStaticResourceSubDir:bundleName] autorelease];
[[RequestRouter singleton] registerRoute:staticRoute];
_httpServer = [[[HTTPServer alloc]init] retain];
[_httpServer setName:@"Frank UISpec server"];
[_httpServer setType:@"_http._tcp."];
[_httpServer setConnectionClass:[RoutingHTTPConnection class]];
[_httpServer setPort:__defaultPort];
NSLog( @"Creating the server: %@", _httpServer );
}
return self;
}
- (BOOL) startServer{
NSError *error;
if( ![_httpServer start:&error] ) {
NSLog(@"Error starting HTTP Server:");// %@", error);
return NO;
}
return YES;
}
- (void) dealloc
{
[_httpServer release];
[super dealloc];
}
@end