Skip to content

Commit

Permalink
Extract image capture into a separate route
Browse files Browse the repository at this point in the history
Conflicts:

	Frank.xcodeproj/project.pbxproj
	example/Controls/Controls.xcodeproj/project.pbxproj
	lib/cocoahttpserver
  • Loading branch information
moredip committed Sep 22, 2012
1 parent 9ffb47f commit c40c4f7
Show file tree
Hide file tree
Showing 5 changed files with 92 additions and 32 deletions.
16 changes: 16 additions & 0 deletions Frank.xcodeproj/project.pbxproj
Expand Up @@ -49,6 +49,10 @@
ABA9E4C815C81E7A00112290 /* DDTTYLogger.m in Sources */ = {isa = PBXBuildFile; fileRef = ABA9E4C315C81E7A00112290 /* DDTTYLogger.m */; }; ABA9E4C815C81E7A00112290 /* DDTTYLogger.m in Sources */ = {isa = PBXBuildFile; fileRef = ABA9E4C315C81E7A00112290 /* DDTTYLogger.m */; };
ABA9E4CD15C81E8700112290 /* ContextFilterLogFormatter.m in Sources */ = {isa = PBXBuildFile; fileRef = ABA9E4CA15C81E8700112290 /* ContextFilterLogFormatter.m */; }; ABA9E4CD15C81E8700112290 /* ContextFilterLogFormatter.m in Sources */ = {isa = PBXBuildFile; fileRef = ABA9E4CA15C81E8700112290 /* ContextFilterLogFormatter.m */; };
ABA9E4CE15C81E8700112290 /* DispatchQueueLogFormatter.m in Sources */ = {isa = PBXBuildFile; fileRef = ABA9E4CC15C81E8700112290 /* DispatchQueueLogFormatter.m */; }; ABA9E4CE15C81E8700112290 /* DispatchQueueLogFormatter.m in Sources */ = {isa = PBXBuildFile; fileRef = ABA9E4CC15C81E8700112290 /* DispatchQueueLogFormatter.m */; };
C18A5EF0160D4AB400DC25F6 /* ImageCaptureRoute.h in Headers */ = {isa = PBXBuildFile; fileRef = C18A5EEE160D4AB400DC25F6 /* ImageCaptureRoute.h */; };
C18A5EF1160D4AB400DC25F6 /* ImageCaptureRoute.m in Sources */ = {isa = PBXBuildFile; fileRef = C18A5EEF160D4AB400DC25F6 /* ImageCaptureRoute.m */; };
C18A5EF5160D4AD300DC25F6 /* UIView+ImageCapture.h in Headers */ = {isa = PBXBuildFile; fileRef = C18A5EF3160D4AD300DC25F6 /* UIView+ImageCapture.h */; };
C18A5EF6160D4AD300DC25F6 /* UIView+ImageCapture.m in Sources */ = {isa = PBXBuildFile; fileRef = C18A5EF4160D4AD300DC25F6 /* UIView+ImageCapture.m */; };
C1AF90551569F10200AE06A1 /* KIFTestStep.h in Headers */ = {isa = PBXBuildFile; fileRef = C1AF90541569F10200AE06A1 /* KIFTestStep.h */; }; C1AF90551569F10200AE06A1 /* KIFTestStep.h in Headers */ = {isa = PBXBuildFile; fileRef = C1AF90541569F10200AE06A1 /* KIFTestStep.h */; };
C1C3CCC0156BCF3500AEE136 /* FEXTappableConfirmationButton.h in Headers */ = {isa = PBXBuildFile; fileRef = C1C3CCBE156BCF3500AEE136 /* FEXTappableConfirmationButton.h */; }; C1C3CCC0156BCF3500AEE136 /* FEXTappableConfirmationButton.h in Headers */ = {isa = PBXBuildFile; fileRef = C1C3CCBE156BCF3500AEE136 /* FEXTappableConfirmationButton.h */; };
C1C3CCC1156BCF3500AEE136 /* FEXTappableConfirmationButton.m in Sources */ = {isa = PBXBuildFile; fileRef = C1C3CCBF156BCF3500AEE136 /* FEXTappableConfirmationButton.m */; }; C1C3CCC1156BCF3500AEE136 /* FEXTappableConfirmationButton.m in Sources */ = {isa = PBXBuildFile; fileRef = C1C3CCBF156BCF3500AEE136 /* FEXTappableConfirmationButton.m */; };
Expand Down Expand Up @@ -272,6 +276,10 @@
ABA9E4CA15C81E8700112290 /* ContextFilterLogFormatter.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = ContextFilterLogFormatter.m; sourceTree = "<group>"; }; ABA9E4CA15C81E8700112290 /* ContextFilterLogFormatter.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = ContextFilterLogFormatter.m; sourceTree = "<group>"; };
ABA9E4CB15C81E8700112290 /* DispatchQueueLogFormatter.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = DispatchQueueLogFormatter.h; sourceTree = "<group>"; }; ABA9E4CB15C81E8700112290 /* DispatchQueueLogFormatter.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = DispatchQueueLogFormatter.h; sourceTree = "<group>"; };
ABA9E4CC15C81E8700112290 /* DispatchQueueLogFormatter.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = DispatchQueueLogFormatter.m; sourceTree = "<group>"; }; ABA9E4CC15C81E8700112290 /* DispatchQueueLogFormatter.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = DispatchQueueLogFormatter.m; sourceTree = "<group>"; };
C18A5EEE160D4AB400DC25F6 /* ImageCaptureRoute.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = ImageCaptureRoute.h; sourceTree = "<group>"; };
C18A5EEF160D4AB400DC25F6 /* ImageCaptureRoute.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = ImageCaptureRoute.m; sourceTree = "<group>"; };
C18A5EF3160D4AD300DC25F6 /* UIView+ImageCapture.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = "UIView+ImageCapture.h"; sourceTree = "<group>"; };
C18A5EF4160D4AD300DC25F6 /* UIView+ImageCapture.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = "UIView+ImageCapture.m"; sourceTree = "<group>"; };
C1AF90541569F10200AE06A1 /* KIFTestStep.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = KIFTestStep.h; sourceTree = "<group>"; }; C1AF90541569F10200AE06A1 /* KIFTestStep.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = KIFTestStep.h; sourceTree = "<group>"; };
C1C3CCBE156BCF3500AEE136 /* FEXTappableConfirmationButton.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = FEXTappableConfirmationButton.h; sourceTree = "<group>"; }; C1C3CCBE156BCF3500AEE136 /* FEXTappableConfirmationButton.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = FEXTappableConfirmationButton.h; sourceTree = "<group>"; };
C1C3CCBF156BCF3500AEE136 /* FEXTappableConfirmationButton.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = FEXTappableConfirmationButton.m; sourceTree = "<group>"; }; C1C3CCBF156BCF3500AEE136 /* FEXTappableConfirmationButton.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = FEXTappableConfirmationButton.m; sourceTree = "<group>"; };
Expand Down Expand Up @@ -614,6 +622,8 @@
children = ( children = (
D6D05CA311C883AA0081C5A5 /* FrankCommandRoute.h */, D6D05CA311C883AA0081C5A5 /* FrankCommandRoute.h */,
D6D05CA411C883AA0081C5A5 /* FrankCommandRoute.m */, D6D05CA411C883AA0081C5A5 /* FrankCommandRoute.m */,
C18A5EEE160D4AB400DC25F6 /* ImageCaptureRoute.h */,
C18A5EEF160D4AB400DC25F6 /* ImageCaptureRoute.m */,
D6D05CAB11C883AA0081C5A5 /* RequestRouter.h */, D6D05CAB11C883AA0081C5A5 /* RequestRouter.h */,
D6D05CAC11C883AA0081C5A5 /* RequestRouter.m */, D6D05CAC11C883AA0081C5A5 /* RequestRouter.m */,
D6D05CAD11C883AA0081C5A5 /* RoutingHTTPConnection.h */, D6D05CAD11C883AA0081C5A5 /* RoutingHTTPConnection.h */,
Expand Down Expand Up @@ -668,6 +678,8 @@
D6A1D27E15A8D05E00EC056C /* UIView+Frank.m */, D6A1D27E15A8D05E00EC056C /* UIView+Frank.m */,
C1C6D1EC1535522300EAA0CF /* UIView+FrankGestures.m */, C1C6D1EC1535522300EAA0CF /* UIView+FrankGestures.m */,
D6F0955A144A5F4600B78FEC /* UIView+KIFAdapter.m */, D6F0955A144A5F4600B78FEC /* UIView+KIFAdapter.m */,
C18A5EF3160D4AD300DC25F6 /* UIView+ImageCapture.h */,
C18A5EF4160D4AD300DC25F6 /* UIView+ImageCapture.m */,
C9605E661606BF8E00170F88 /* UIView+MapKitWorkaround.m */, C9605E661606BF8E00170F88 /* UIView+MapKitWorkaround.m */,
); );
name = Additions; name = Additions;
Expand Down Expand Up @@ -929,6 +941,8 @@
FC4EC7EC15ED1E0A00B1F119 /* NSString+Franks_SBJSON.h in Headers */, FC4EC7EC15ED1E0A00B1F119 /* NSString+Franks_SBJSON.h in Headers */,
C9605E641606BF2900170F88 /* KeyboardCommand.h in Headers */, C9605E641606BF2900170F88 /* KeyboardCommand.h in Headers */,
C9605E6A1606BFAE00170F88 /* UIImage+Frank.h in Headers */, C9605E6A1606BFAE00170F88 /* UIImage+Frank.h in Headers */,
C18A5EF0160D4AB400DC25F6 /* ImageCaptureRoute.h in Headers */,
C18A5EF5160D4AD300DC25F6 /* UIView+ImageCapture.h in Headers */,
); );
runOnlyForDeploymentPostprocessing = 0; runOnlyForDeploymentPostprocessing = 0;
}; };
Expand Down Expand Up @@ -1120,6 +1134,8 @@
C9605E651606BF2900170F88 /* KeyboardCommand.m in Sources */, C9605E651606BF2900170F88 /* KeyboardCommand.m in Sources */,
C9605E671606BF8E00170F88 /* UIView+MapKitWorkaround.m in Sources */, C9605E671606BF8E00170F88 /* UIView+MapKitWorkaround.m in Sources */,
C9605E6B1606BFAE00170F88 /* UIImage+Frank.m in Sources */, C9605E6B1606BFAE00170F88 /* UIImage+Frank.m in Sources */,
C18A5EF1160D4AB400DC25F6 /* ImageCaptureRoute.m in Sources */,
C18A5EF6160D4AD300DC25F6 /* UIView+ImageCapture.m in Sources */,
); );
runOnlyForDeploymentPostprocessing = 0; runOnlyForDeploymentPostprocessing = 0;
}; };
Expand Down
32 changes: 0 additions & 32 deletions src/FrankCommandRoute.m
Expand Up @@ -52,38 +52,6 @@ -(void) registerCommand: (id<FrankCommand>)command withName:(NSString *)commandN
NSLog( @"received request with path %@\nPOST DATA:\n%@", path, connection.postDataAsString ); NSLog( @"received request with path %@\nPOST DATA:\n%@", path, connection.postDataAsString );
} }


if( [@"screenshot" isEqualToString:[path objectAtIndex:0]] )
{
BOOL allWindows = [path count] > 1 && [[path objectAtIndex:0] isEqualToString:@"allwindows"];
UIImage *screenshot = [UIImage imageFromApplication:allWindows];

if ([path count] == 4)
{
NSString *stringRepresentation = [path objectAtIndex:3];
NSArray *parts = [stringRepresentation componentsSeparatedByString:@"."];
CGRect rect = CGRectZero;

rect.origin.x = [[parts objectAtIndex:0] integerValue];
rect.origin.y = [[parts objectAtIndex:1] integerValue];
rect.size.width = [[parts objectAtIndex:2] integerValue];
rect.size.height = [[parts objectAtIndex:3] integerValue];

//
// Crop image or mask out an area (IE: Timestamp)
//
if ([[path objectAtIndex:2] isEqualToString:@"frame"])
screenshot = [screenshot imageCropedToFrame:rect];
else if ([[path objectAtIndex:2] isEqualToString:@"mask"])
screenshot = [screenshot imageMaskedAtFrame:rect];
else
NSLog(@"Unknown Operation");
}

NSData *response = UIImagePNGRepresentation(screenshot);

return [[[HTTPDataResponse alloc] initWithData:response] autorelease];
}

id<FrankCommand> command = [self commandForPath:path]; id<FrankCommand> command = [self commandForPath:path];
if( nil == command ) if( nil == command )
return nil; return nil;
Expand Down
4 changes: 4 additions & 0 deletions src/FrankServer.m
Expand Up @@ -11,6 +11,7 @@
#import "HTTPServer.h" #import "HTTPServer.h"
#import "RoutingHTTPConnection.h" #import "RoutingHTTPConnection.h"
#import "StaticResourcesRoute.h" #import "StaticResourcesRoute.h"
#import "ImageCaptureRoute.h"
#import "FrankCommandRoute.h" #import "FrankCommandRoute.h"
#import "DumpCommand.h" #import "DumpCommand.h"
#import "MapOperationCommand.h" #import "MapOperationCommand.h"
Expand Down Expand Up @@ -52,6 +53,9 @@ - (id) initWithStaticFrankBundleNamed:(NSString *)bundleName


StaticResourcesRoute *staticRoute = [[[StaticResourcesRoute alloc] initWithStaticResourceSubDir:bundleName] autorelease]; StaticResourcesRoute *staticRoute = [[[StaticResourcesRoute alloc] initWithStaticResourceSubDir:bundleName] autorelease];
[[RequestRouter singleton] registerRoute:staticRoute]; [[RequestRouter singleton] registerRoute:staticRoute];

ImageCaptureRoute *imageCaptureCommand = [[[ImageCaptureRoute alloc] init] autorelease];
[[RequestRouter singleton] registerRoute:imageCaptureCommand];


_httpServer = [[[HTTPServer alloc]init] retain]; _httpServer = [[[HTTPServer alloc]init] retain];


Expand Down
18 changes: 18 additions & 0 deletions src/ImageCaptureRoute.h
@@ -0,0 +1,18 @@
//
// ImageCaptureRoute.h
// Frank
//
// Created by Pete Hodgson on 7/26/12.
// Copyright (c) 2012 Thoughtworks. All rights reserved.
//

#import <Foundation/Foundation.h>

#import "FrankCommandRoute.h"


@interface ImageCaptureRoute : NSObject<Route> {
}


@end
54 changes: 54 additions & 0 deletions src/ImageCaptureRoute.m
@@ -0,0 +1,54 @@
//
// ImageCaptureRoute.m
// Frank
//
// Created by Pete Hodgson on 7/26/12.
// Copyright (c) 2012 Thoughtworks. All rights reserved.
//

#import "ImageCaptureRoute.h"

#import "UIImage+Frank.h"

@implementation ImageCaptureRoute

- (NSObject<HTTPResponse> *) handleRequestForPath: (NSArray *)path withConnection:(RoutingHTTPConnection *)connection{

if( ![@"screenshot" isEqualToString:[path objectAtIndex:0]] )
return nil;

BOOL allWindows = [path count] > 1 && [[path objectAtIndex:1] isEqualToString:@"allwindows"];
UIImage *screenshot = [UIImage imageFromApplication:allWindows];

if ([path count] == 4)
{
NSString *stringRepresentation = [path objectAtIndex:3];
NSArray *parts = [stringRepresentation componentsSeparatedByString:@"."];
CGRect rect = CGRectZero;

rect.origin.x = [[parts objectAtIndex:0] integerValue];
rect.origin.y = [[parts objectAtIndex:1] integerValue];
rect.size.width = [[parts objectAtIndex:2] integerValue];
rect.size.height = [[parts objectAtIndex:3] integerValue];

//
// Crop image or mask out an area (IE: Timestamp)
//
if ([[path objectAtIndex:2] isEqualToString:@"frame"])
screenshot = [screenshot imageCropedToFrame:rect];
else if ([[path objectAtIndex:2] isEqualToString:@"mask"])
screenshot = [screenshot imageMaskedAtFrame:rect];
else
NSLog(@"Unknown Operation");
}

NSData *response = UIImagePNGRepresentation(screenshot);

return [[[HTTPDataResponse alloc] initWithData:response] autorelease];
}

- (BOOL) canHandlePostForPath: (NSArray *)path{
return NO;
}

@end

0 comments on commit c40c4f7

Please sign in to comment.