-
Notifications
You must be signed in to change notification settings - Fork 57
Expand file tree
/
Copy pathDirectAppExecCommand.m
More file actions
54 lines (43 loc) · 1.78 KB
/
DirectAppExecCommand.m
File metadata and controls
54 lines (43 loc) · 1.78 KB
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
//
// DirectAppExecCommand.m
// Frank
//
// Created by Martin Taylor on 4-Apr-14.
// Copyright (c) 2014 Texas Instruments, Inc. All rights reserved.
//
// NOTE: This code was copied directly from AppCommand.m. The only difference in this command is that the
// RequestRouter.m executes it on the HTTP thread rather than on the main UI thread.
//
#import <Foundation/Foundation.h>
#import "DirectAppExecCommand.h"
#import "Operation.h"
#import "ViewJSONSerializer.h"
#import "FranklyProtocolHelper.h"
#import "JSON.h"
@implementation DirectAppExecCommand
- (NSString *)handleCommandWithRequestBody:(NSString *)requestBody {
NSDictionary *requestCommand = FROM_JSON(requestBody);
NSDictionary *operationDict = [requestCommand objectForKey:@"operation"];
Operation *operation = [[[Operation alloc] initFromJsonRepresentation:operationDict] autorelease];
#if TARGET_OS_IPHONE
id <UIApplicationDelegate> appDelegate = [[UIApplication sharedApplication] delegate];
#else
id <NSApplicationDelegate> appDelegate = [[NSApplication sharedApplication] delegate];
#endif
if( ![operation appliesToObject:appDelegate] )
{
return [FranklyProtocolHelper generateErrorResponseWithReason:@"operation doesn't apply" andDetails:@"operation does not appear to be implemented in app delegate"];
}
id result;
@try {
result = [operation applyToObject:appDelegate];
}
@catch (NSException *e) {
NSLog( @"Exception while applying operation to app delegate:\n%@", e );
return [FranklyProtocolHelper generateErrorResponseWithReason:@"exception while executing operation" andDetails:[e reason]];
}
NSMutableArray *results = [NSMutableArray new];
[results addObject:[ViewJSONSerializer jsonify:result]];
return [FranklyProtocolHelper generateSuccessResponseWithResults: results];
}
@end