Return-Path: X-Original-To: apmail-cordova-commits-archive@www.apache.org Delivered-To: apmail-cordova-commits-archive@www.apache.org Received: from mail.apache.org (hermes.apache.org [140.211.11.3]) by minotaur.apache.org (Postfix) with SMTP id ACDCBEBC5 for ; Mon, 25 Feb 2013 18:33:31 +0000 (UTC) Received: (qmail 68368 invoked by uid 500); 25 Feb 2013 18:33:31 -0000 Delivered-To: apmail-cordova-commits-archive@cordova.apache.org Received: (qmail 68333 invoked by uid 500); 25 Feb 2013 18:33:31 -0000 Mailing-List: contact commits-help@cordova.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: callback-dev@cordova.apache.org Delivered-To: mailing list commits@cordova.apache.org Received: (qmail 68326 invoked by uid 99); 25 Feb 2013 18:33:31 -0000 Received: from tyr.zones.apache.org (HELO tyr.zones.apache.org) (140.211.11.114) by apache.org (qpsmtpd/0.29) with ESMTP; Mon, 25 Feb 2013 18:33:31 +0000 Received: by tyr.zones.apache.org (Postfix, from userid 65534) id 5BDB182FC29; Mon, 25 Feb 2013 18:33:31 +0000 (UTC) Content-Type: text/plain; charset="us-ascii" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit From: mmocny@apache.org To: commits@cordova.apache.org X-Mailer: ASF-Git Admin Mailer Subject: ios commit: CB-2530 and CB-2239 Multipart plugin result Message-Id: <20130225183331.5BDB182FC29@tyr.zones.apache.org> Date: Mon, 25 Feb 2013 18:33:31 +0000 (UTC) Updated Branches: refs/heads/master 909652709 -> 5bd349235 CB-2530 and CB-2239 Multipart plugin result * Support MultiPart plugin result * Update Echo to test MultiPart messages Project: http://git-wip-us.apache.org/repos/asf/cordova-ios/repo Commit: http://git-wip-us.apache.org/repos/asf/cordova-ios/commit/5bd34923 Tree: http://git-wip-us.apache.org/repos/asf/cordova-ios/tree/5bd34923 Diff: http://git-wip-us.apache.org/repos/asf/cordova-ios/diff/5bd34923 Branch: refs/heads/master Commit: 5bd349235caa61a907d3ce059b955b798225beba Parents: 9096527 Author: Michal Mocny Authored: Mon Feb 25 13:27:29 2013 -0500 Committer: Michal Mocny Committed: Mon Feb 25 13:27:29 2013 -0500 ---------------------------------------------------------------------- CordovaLib/Classes/CDVCommandDelegateImpl.m | 12 +---- CordovaLib/Classes/CDVEcho.m | 7 +++ CordovaLib/Classes/CDVPluginResult.h | 4 ++ CordovaLib/Classes/CDVPluginResult.m | 55 +++++++++++++++++++-- hooks/pre-commit | 1 + 5 files changed, 64 insertions(+), 15 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/cordova-ios/blob/5bd34923/CordovaLib/Classes/CDVCommandDelegateImpl.m ---------------------------------------------------------------------- diff --git a/CordovaLib/Classes/CDVCommandDelegateImpl.m b/CordovaLib/Classes/CDVCommandDelegateImpl.m index 7779880..5197cb5 100644 --- a/CordovaLib/Classes/CDVCommandDelegateImpl.m +++ b/CordovaLib/Classes/CDVCommandDelegateImpl.m @@ -89,15 +89,9 @@ } int status = [result.status intValue]; BOOL keepCallback = [result.keepCallback boolValue]; - id message = result.message == nil ? [NSNull null] : result.message; - - // Use an array to encode the message as JSON. - message = [NSArray arrayWithObject:message]; - NSString* encodedMessage = [message JSONString]; - // And then strip off the outer []s. - encodedMessage = [encodedMessage substringWithRange:NSMakeRange(1, [encodedMessage length] - 2)]; - NSString* js = [NSString stringWithFormat:@"cordova.require('cordova/exec').nativeCallback('%@',%d,%@,%d)", - callbackId, status, encodedMessage, keepCallback]; + NSString* argumentsAsJSON = [result argumentsAsJSON]; + + NSString* js = [NSString stringWithFormat:@"cordova.require('cordova/exec').nativeCallback('%@',%d,%@,%d)", callbackId, status, argumentsAsJSON, keepCallback]; [self evalJsHelper:js]; } http://git-wip-us.apache.org/repos/asf/cordova-ios/blob/5bd34923/CordovaLib/Classes/CDVEcho.m ---------------------------------------------------------------------- diff --git a/CordovaLib/Classes/CDVEcho.m b/CordovaLib/Classes/CDVEcho.m index 916e315..c74990d 100644 --- a/CordovaLib/Classes/CDVEcho.m +++ b/CordovaLib/Classes/CDVEcho.m @@ -51,4 +51,11 @@ [self.commandDelegate sendPluginResult:pluginResult callbackId:command.callbackId]; } +- (void)echoMultiPart:(CDVInvokedUrlCommand*)command +{ + CDVPluginResult* pluginResult = [CDVPluginResult resultWithStatus:CDVCommandStatus_OK messageAsMultipart:command.arguments]; + + [self.commandDelegate sendPluginResult:pluginResult callbackId:command.callbackId]; +} + @end http://git-wip-us.apache.org/repos/asf/cordova-ios/blob/5bd34923/CordovaLib/Classes/CDVPluginResult.h ---------------------------------------------------------------------- diff --git a/CordovaLib/Classes/CDVPluginResult.h b/CordovaLib/Classes/CDVPluginResult.h index 8683205..8393df2 100644 --- a/CordovaLib/Classes/CDVPluginResult.h +++ b/CordovaLib/Classes/CDVPluginResult.h @@ -47,6 +47,7 @@ typedef enum { + (CDVPluginResult*)resultWithStatus:(CDVCommandStatus)statusOrdinal messageAsBool:(BOOL)theMessage; + (CDVPluginResult*)resultWithStatus:(CDVCommandStatus)statusOrdinal messageAsDictionary:(NSDictionary*)theMessage; + (CDVPluginResult*)resultWithStatus:(CDVCommandStatus)statusOrdinal messageAsArrayBuffer:(NSData*)theMessage; ++ (CDVPluginResult*)resultWithStatus:(CDVCommandStatus)statusOrdinal messageAsMultipart:(NSArray*)theMessages; + (CDVPluginResult*)resultWithStatus:(CDVCommandStatus)statusOrdinal messageToErrorObject:(int)errorCode; + (void)setVerbose:(BOOL)verbose; @@ -54,6 +55,9 @@ typedef enum { - (void)setKeepCallbackAsBool:(BOOL)bKeepCallback; +- (NSString*)argumentsAsJSON; + +// These methods are used by the legacy plugin return result method - (NSString*)toJSONString; - (NSString*)toSuccessCallbackString:(NSString*)callbackId; - (NSString*)toErrorCallbackString:(NSString*)callbackId; http://git-wip-us.apache.org/repos/asf/cordova-ios/blob/5bd34923/CordovaLib/Classes/CDVPluginResult.m ---------------------------------------------------------------------- diff --git a/CordovaLib/Classes/CDVPluginResult.m b/CordovaLib/Classes/CDVPluginResult.m index d9ba08f..a03e005 100644 --- a/CordovaLib/Classes/CDVPluginResult.m +++ b/CordovaLib/Classes/CDVPluginResult.m @@ -33,6 +33,36 @@ static NSArray* org_apache_cordova_CommandStatusMsgs; +id messageFromArrayBuffer(NSData* data) +{ + return @{ + @"CDVType" : @"ArrayBuffer", + @"data" :[data base64EncodedString] + }; +} + +id massageMessage(id message) +{ + if ([message isKindOfClass:[NSData class]]) { + return messageFromArrayBuffer(message); + } + return message; +} + +id messageFromMultipart(NSArray* theMessages) +{ + NSMutableArray* messages = [NSMutableArray arrayWithArray:theMessages]; + + for (NSUInteger i = 0; i < messages.count; ++i) { + [messages replaceObjectAtIndex:i withObject:massageMessage([messages objectAtIndex:i])]; + } + + return @{ + @"CDVType" : @"MultiPart", + @"messages" : messages + }; +} + + (void)initialize { org_apache_cordova_CommandStatusMsgs = [[NSArray alloc] initWithObjects:@"No result", @@ -101,17 +131,17 @@ static NSArray* org_apache_cordova_CommandStatusMsgs; + (CDVPluginResult*)resultWithStatus:(CDVCommandStatus)statusOrdinal messageAsArrayBuffer:(NSData*)theMessage { - NSDictionary* arrDict = [NSDictionary dictionaryWithObjectsAndKeys: - @"ArrayBuffer", @"CDVType", - [theMessage base64EncodedString], @"data", - nil]; + return [[self alloc] initWithStatus:statusOrdinal message:messageFromArrayBuffer(theMessage)]; +} - return [[self alloc] initWithStatus:statusOrdinal message:arrDict]; ++ (CDVPluginResult*)resultWithStatus:(CDVCommandStatus)statusOrdinal messageAsMultipart:(NSArray*)theMessages +{ + return [[self alloc] initWithStatus:statusOrdinal message:messageFromMultipart(theMessages)]; } + (CDVPluginResult*)resultWithStatus:(CDVCommandStatus)statusOrdinal messageToErrorObject:(int)errorCode { - NSDictionary* errDict = [NSDictionary dictionaryWithObject:[NSNumber numberWithInt:errorCode] forKey:@"code"]; + NSDictionary* errDict = @{@"code": [NSNumber numberWithInt:errorCode]}; return [[self alloc] initWithStatus:statusOrdinal message:errDict]; } @@ -121,6 +151,19 @@ static NSArray* org_apache_cordova_CommandStatusMsgs; [self setKeepCallback:[NSNumber numberWithBool:bKeepCallback]]; } +- (NSString*)argumentsAsJSON +{ + id arguments = (self.message == nil ? [NSNull null] : self.message); + NSArray* argumentsWrappedInArray = [NSArray arrayWithObject:arguments]; + + NSString* argumentsJSON = [argumentsWrappedInArray JSONString]; + + argumentsJSON = [argumentsJSON substringWithRange:NSMakeRange(1, [argumentsJSON length] - 2)]; + + return argumentsJSON; +} + +// These methods are used by the legacy plugin return result method - (NSString*)toJSONString { NSDictionary* dict = [NSDictionary dictionaryWithObjectsAndKeys: http://git-wip-us.apache.org/repos/asf/cordova-ios/blob/5bd34923/hooks/pre-commit ---------------------------------------------------------------------- diff --git a/hooks/pre-commit b/hooks/pre-commit index 7a420c9..03ff08c 100755 --- a/hooks/pre-commit +++ b/hooks/pre-commit @@ -20,6 +20,7 @@ # Redirect output to stderr. exec 1>&2 +test $SKIP_UNCRUSTIFY && exit 0 RET=0 files=$(bin/uncrustify.sh --filter $(git diff --cached --name-only))