Skip to content
This repository
Browse code

Extract image capture into a separate route

Conflicts:

	Frank.xcodeproj/project.pbxproj
	example/Controls/Controls.xcodeproj/project.pbxproj
	lib/cocoahttpserver
  • Loading branch information...
commit c40c4f70d9f86be2c953fcf740b534b6a7bc2864 1 parent 9ffb47f
Pete Hodgson authored
16 Frank.xcodeproj/project.pbxproj
@@ -49,6 +49,10 @@
49 49 ABA9E4C815C81E7A00112290 /* DDTTYLogger.m in Sources */ = {isa = PBXBuildFile; fileRef = ABA9E4C315C81E7A00112290 /* DDTTYLogger.m */; };
50 50 ABA9E4CD15C81E8700112290 /* ContextFilterLogFormatter.m in Sources */ = {isa = PBXBuildFile; fileRef = ABA9E4CA15C81E8700112290 /* ContextFilterLogFormatter.m */; };
51 51 ABA9E4CE15C81E8700112290 /* DispatchQueueLogFormatter.m in Sources */ = {isa = PBXBuildFile; fileRef = ABA9E4CC15C81E8700112290 /* DispatchQueueLogFormatter.m */; };
  52 + C18A5EF0160D4AB400DC25F6 /* ImageCaptureRoute.h in Headers */ = {isa = PBXBuildFile; fileRef = C18A5EEE160D4AB400DC25F6 /* ImageCaptureRoute.h */; };
  53 + C18A5EF1160D4AB400DC25F6 /* ImageCaptureRoute.m in Sources */ = {isa = PBXBuildFile; fileRef = C18A5EEF160D4AB400DC25F6 /* ImageCaptureRoute.m */; };
  54 + C18A5EF5160D4AD300DC25F6 /* UIView+ImageCapture.h in Headers */ = {isa = PBXBuildFile; fileRef = C18A5EF3160D4AD300DC25F6 /* UIView+ImageCapture.h */; };
  55 + C18A5EF6160D4AD300DC25F6 /* UIView+ImageCapture.m in Sources */ = {isa = PBXBuildFile; fileRef = C18A5EF4160D4AD300DC25F6 /* UIView+ImageCapture.m */; };
52 56 C1AF90551569F10200AE06A1 /* KIFTestStep.h in Headers */ = {isa = PBXBuildFile; fileRef = C1AF90541569F10200AE06A1 /* KIFTestStep.h */; };
53 57 C1C3CCC0156BCF3500AEE136 /* FEXTappableConfirmationButton.h in Headers */ = {isa = PBXBuildFile; fileRef = C1C3CCBE156BCF3500AEE136 /* FEXTappableConfirmationButton.h */; };
54 58 C1C3CCC1156BCF3500AEE136 /* FEXTappableConfirmationButton.m in Sources */ = {isa = PBXBuildFile; fileRef = C1C3CCBF156BCF3500AEE136 /* FEXTappableConfirmationButton.m */; };
@@ -272,6 +276,10 @@
272 276 ABA9E4CA15C81E8700112290 /* ContextFilterLogFormatter.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = ContextFilterLogFormatter.m; sourceTree = "<group>"; };
273 277 ABA9E4CB15C81E8700112290 /* DispatchQueueLogFormatter.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = DispatchQueueLogFormatter.h; sourceTree = "<group>"; };
274 278 ABA9E4CC15C81E8700112290 /* DispatchQueueLogFormatter.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = DispatchQueueLogFormatter.m; sourceTree = "<group>"; };
  279 + C18A5EEE160D4AB400DC25F6 /* ImageCaptureRoute.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = ImageCaptureRoute.h; sourceTree = "<group>"; };
  280 + C18A5EEF160D4AB400DC25F6 /* ImageCaptureRoute.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = ImageCaptureRoute.m; sourceTree = "<group>"; };
  281 + C18A5EF3160D4AD300DC25F6 /* UIView+ImageCapture.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = "UIView+ImageCapture.h"; sourceTree = "<group>"; };
  282 + C18A5EF4160D4AD300DC25F6 /* UIView+ImageCapture.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = "UIView+ImageCapture.m"; sourceTree = "<group>"; };
275 283 C1AF90541569F10200AE06A1 /* KIFTestStep.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = KIFTestStep.h; sourceTree = "<group>"; };
276 284 C1C3CCBE156BCF3500AEE136 /* FEXTappableConfirmationButton.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = FEXTappableConfirmationButton.h; sourceTree = "<group>"; };
277 285 C1C3CCBF156BCF3500AEE136 /* FEXTappableConfirmationButton.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = FEXTappableConfirmationButton.m; sourceTree = "<group>"; };
@@ -614,6 +622,8 @@
614 622 children = (
615 623 D6D05CA311C883AA0081C5A5 /* FrankCommandRoute.h */,
616 624 D6D05CA411C883AA0081C5A5 /* FrankCommandRoute.m */,
  625 + C18A5EEE160D4AB400DC25F6 /* ImageCaptureRoute.h */,
  626 + C18A5EEF160D4AB400DC25F6 /* ImageCaptureRoute.m */,
617 627 D6D05CAB11C883AA0081C5A5 /* RequestRouter.h */,
618 628 D6D05CAC11C883AA0081C5A5 /* RequestRouter.m */,
619 629 D6D05CAD11C883AA0081C5A5 /* RoutingHTTPConnection.h */,
@@ -668,6 +678,8 @@
668 678 D6A1D27E15A8D05E00EC056C /* UIView+Frank.m */,
669 679 C1C6D1EC1535522300EAA0CF /* UIView+FrankGestures.m */,
670 680 D6F0955A144A5F4600B78FEC /* UIView+KIFAdapter.m */,
  681 + C18A5EF3160D4AD300DC25F6 /* UIView+ImageCapture.h */,
  682 + C18A5EF4160D4AD300DC25F6 /* UIView+ImageCapture.m */,
671 683 C9605E661606BF8E00170F88 /* UIView+MapKitWorkaround.m */,
672 684 );
673 685 name = Additions;
@@ -929,6 +941,8 @@
929 941 FC4EC7EC15ED1E0A00B1F119 /* NSString+Franks_SBJSON.h in Headers */,
930 942 C9605E641606BF2900170F88 /* KeyboardCommand.h in Headers */,
931 943 C9605E6A1606BFAE00170F88 /* UIImage+Frank.h in Headers */,
  944 + C18A5EF0160D4AB400DC25F6 /* ImageCaptureRoute.h in Headers */,
  945 + C18A5EF5160D4AD300DC25F6 /* UIView+ImageCapture.h in Headers */,
932 946 );
933 947 runOnlyForDeploymentPostprocessing = 0;
934 948 };
@@ -1120,6 +1134,8 @@
1120 1134 C9605E651606BF2900170F88 /* KeyboardCommand.m in Sources */,
1121 1135 C9605E671606BF8E00170F88 /* UIView+MapKitWorkaround.m in Sources */,
1122 1136 C9605E6B1606BFAE00170F88 /* UIImage+Frank.m in Sources */,
  1137 + C18A5EF1160D4AB400DC25F6 /* ImageCaptureRoute.m in Sources */,
  1138 + C18A5EF6160D4AD300DC25F6 /* UIView+ImageCapture.m in Sources */,
1123 1139 );
1124 1140 runOnlyForDeploymentPostprocessing = 0;
1125 1141 };
32 src/FrankCommandRoute.m
@@ -52,38 +52,6 @@ -(void) registerCommand: (id<FrankCommand>)command withName:(NSString *)commandN
52 52 NSLog( @"received request with path %@\nPOST DATA:\n%@", path, connection.postDataAsString );
53 53 }
54 54
55   - if( [@"screenshot" isEqualToString:[path objectAtIndex:0]] )
56   - {
57   - BOOL allWindows = [path count] > 1 && [[path objectAtIndex:0] isEqualToString:@"allwindows"];
58   - UIImage *screenshot = [UIImage imageFromApplication:allWindows];
59   -
60   - if ([path count] == 4)
61   - {
62   - NSString *stringRepresentation = [path objectAtIndex:3];
63   - NSArray *parts = [stringRepresentation componentsSeparatedByString:@"."];
64   - CGRect rect = CGRectZero;
65   -
66   - rect.origin.x = [[parts objectAtIndex:0] integerValue];
67   - rect.origin.y = [[parts objectAtIndex:1] integerValue];
68   - rect.size.width = [[parts objectAtIndex:2] integerValue];
69   - rect.size.height = [[parts objectAtIndex:3] integerValue];
70   -
71   - //
72   - // Crop image or mask out an area (IE: Timestamp)
73   - //
74   - if ([[path objectAtIndex:2] isEqualToString:@"frame"])
75   - screenshot = [screenshot imageCropedToFrame:rect];
76   - else if ([[path objectAtIndex:2] isEqualToString:@"mask"])
77   - screenshot = [screenshot imageMaskedAtFrame:rect];
78   - else
79   - NSLog(@"Unknown Operation");
80   - }
81   -
82   - NSData *response = UIImagePNGRepresentation(screenshot);
83   -
84   - return [[[HTTPDataResponse alloc] initWithData:response] autorelease];
85   - }
86   -
87 55 id<FrankCommand> command = [self commandForPath:path];
88 56 if( nil == command )
89 57 return nil;
4 src/FrankServer.m
@@ -11,6 +11,7 @@
11 11 #import "HTTPServer.h"
12 12 #import "RoutingHTTPConnection.h"
13 13 #import "StaticResourcesRoute.h"
  14 +#import "ImageCaptureRoute.h"
14 15 #import "FrankCommandRoute.h"
15 16 #import "DumpCommand.h"
16 17 #import "MapOperationCommand.h"
@@ -52,6 +53,9 @@ - (id) initWithStaticFrankBundleNamed:(NSString *)bundleName
52 53
53 54 StaticResourcesRoute *staticRoute = [[[StaticResourcesRoute alloc] initWithStaticResourceSubDir:bundleName] autorelease];
54 55 [[RequestRouter singleton] registerRoute:staticRoute];
  56 +
  57 + ImageCaptureRoute *imageCaptureCommand = [[[ImageCaptureRoute alloc] init] autorelease];
  58 + [[RequestRouter singleton] registerRoute:imageCaptureCommand];
55 59
56 60 _httpServer = [[[HTTPServer alloc]init] retain];
57 61
18 src/ImageCaptureRoute.h
... ... @@ -0,0 +1,18 @@
  1 +//
  2 +// ImageCaptureRoute.h
  3 +// Frank
  4 +//
  5 +// Created by Pete Hodgson on 7/26/12.
  6 +// Copyright (c) 2012 Thoughtworks. All rights reserved.
  7 +//
  8 +
  9 +#import <Foundation/Foundation.h>
  10 +
  11 +#import "FrankCommandRoute.h"
  12 +
  13 +
  14 +@interface ImageCaptureRoute : NSObject<Route> {
  15 +}
  16 +
  17 +
  18 +@end
54 src/ImageCaptureRoute.m
... ... @@ -0,0 +1,54 @@
  1 +//
  2 +// ImageCaptureRoute.m
  3 +// Frank
  4 +//
  5 +// Created by Pete Hodgson on 7/26/12.
  6 +// Copyright (c) 2012 Thoughtworks. All rights reserved.
  7 +//
  8 +
  9 +#import "ImageCaptureRoute.h"
  10 +
  11 +#import "UIImage+Frank.h"
  12 +
  13 +@implementation ImageCaptureRoute
  14 +
  15 +- (NSObject<HTTPResponse> *) handleRequestForPath: (NSArray *)path withConnection:(RoutingHTTPConnection *)connection{
  16 +
  17 + if( ![@"screenshot" isEqualToString:[path objectAtIndex:0]] )
  18 + return nil;
  19 +
  20 + BOOL allWindows = [path count] > 1 && [[path objectAtIndex:1] isEqualToString:@"allwindows"];
  21 + UIImage *screenshot = [UIImage imageFromApplication:allWindows];
  22 +
  23 + if ([path count] == 4)
  24 + {
  25 + NSString *stringRepresentation = [path objectAtIndex:3];
  26 + NSArray *parts = [stringRepresentation componentsSeparatedByString:@"."];
  27 + CGRect rect = CGRectZero;
  28 +
  29 + rect.origin.x = [[parts objectAtIndex:0] integerValue];
  30 + rect.origin.y = [[parts objectAtIndex:1] integerValue];
  31 + rect.size.width = [[parts objectAtIndex:2] integerValue];
  32 + rect.size.height = [[parts objectAtIndex:3] integerValue];
  33 +
  34 + //
  35 + // Crop image or mask out an area (IE: Timestamp)
  36 + //
  37 + if ([[path objectAtIndex:2] isEqualToString:@"frame"])
  38 + screenshot = [screenshot imageCropedToFrame:rect];
  39 + else if ([[path objectAtIndex:2] isEqualToString:@"mask"])
  40 + screenshot = [screenshot imageMaskedAtFrame:rect];
  41 + else
  42 + NSLog(@"Unknown Operation");
  43 + }
  44 +
  45 + NSData *response = UIImagePNGRepresentation(screenshot);
  46 +
  47 + return [[[HTTPDataResponse alloc] initWithData:response] autorelease];
  48 +}
  49 +
  50 +- (BOOL) canHandlePostForPath: (NSArray *)path{
  51 + return NO;
  52 +}
  53 +
  54 +@end

0 comments on commit c40c4f7

Please sign in to comment.
Something went wrong with that request. Please try again.