You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@cordova.apache.org by ag...@apache.org on 2012/10/09 21:50:41 UTC
[1/3] ios commit: Move CDVCommandDelegateImpl into Classes directory
(oops).
Updated Branches:
refs/heads/master f1ec68fe9 -> 994e23435
Move CDVCommandDelegateImpl into Classes directory (oops).
Project: http://git-wip-us.apache.org/repos/asf/incubator-cordova-ios/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-cordova-ios/commit/994e2343
Tree: http://git-wip-us.apache.org/repos/asf/incubator-cordova-ios/tree/994e2343
Diff: http://git-wip-us.apache.org/repos/asf/incubator-cordova-ios/diff/994e2343
Branch: refs/heads/master
Commit: 994e23435f1839f2f2cd49febbf5313501376815
Parents: e68e9d4
Author: Andrew Grieve <ag...@chromium.org>
Authored: Fri Oct 5 22:57:33 2012 -0400
Committer: Andrew Grieve <ag...@chromium.org>
Committed: Tue Oct 9 15:49:38 2012 -0400
----------------------------------------------------------------------
CordovaLib/CDVCommandDelegateImpl.h | 32 -----
CordovaLib/CDVCommandDelegateImpl.m | 117 ------------------
CordovaLib/Classes/CDVCommandDelegateImpl.h | 32 +++++
CordovaLib/Classes/CDVCommandDelegateImpl.m | 117 ++++++++++++++++++
CordovaLib/CordovaLib.xcodeproj/project.pbxproj | 4 +-
5 files changed, 151 insertions(+), 151 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/incubator-cordova-ios/blob/994e2343/CordovaLib/CDVCommandDelegateImpl.h
----------------------------------------------------------------------
diff --git a/CordovaLib/CDVCommandDelegateImpl.h b/CordovaLib/CDVCommandDelegateImpl.h
deleted file mode 100644
index f850dc6..0000000
--- a/CordovaLib/CDVCommandDelegateImpl.h
+++ /dev/null
@@ -1,32 +0,0 @@
-/*
- Licensed to the Apache Software Foundation (ASF) under one
- or more contributor license agreements. See the NOTICE file
- distributed with this work for additional information
- regarding copyright ownership. The ASF licenses this file
- to you under the Apache License, Version 2.0 (the
- "License"); you may not use this file except in compliance
- with the License. You may obtain a copy of the License at
-
- http://www.apache.org/licenses/LICENSE-2.0
-
- Unless required by applicable law or agreed to in writing,
- software distributed under the License is distributed on an
- "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
- KIND, either express or implied. See the License for the
- specific language governing permissions and limitations
- under the License.
- */
-
-#import <UIKit/UIKit.h>
-#import "CDVCommandDelegate.h"
-
-@class CDVViewController;
-@class CDVCommandQueue;
-
-@interface CDVCommandDelegateImpl : NSObject <CDVCommandDelegate>{
- @private
- __unsafe_unretained CDVViewController* _viewController;
- __unsafe_unretained CDVCommandQueue* _commandQueue;
-}
-- (id)initWithViewController:(CDVViewController*)viewController;
-@end
http://git-wip-us.apache.org/repos/asf/incubator-cordova-ios/blob/994e2343/CordovaLib/CDVCommandDelegateImpl.m
----------------------------------------------------------------------
diff --git a/CordovaLib/CDVCommandDelegateImpl.m b/CordovaLib/CDVCommandDelegateImpl.m
deleted file mode 100644
index f35705a..0000000
--- a/CordovaLib/CDVCommandDelegateImpl.m
+++ /dev/null
@@ -1,117 +0,0 @@
-/*
- Licensed to the Apache Software Foundation (ASF) under one
- or more contributor license agreements. See the NOTICE file
- distributed with this work for additional information
- regarding copyright ownership. The ASF licenses this file
- to you under the Apache License, Version 2.0 (the
- "License"); you may not use this file except in compliance
- with the License. You may obtain a copy of the License at
-
- http://www.apache.org/licenses/LICENSE-2.0
-
- Unless required by applicable law or agreed to in writing,
- software distributed under the License is distributed on an
- "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
- KIND, either express or implied. See the License for the
- specific language governing permissions and limitations
- under the License.
- */
-
-#import "CDVCommandDelegateImpl.h"
-
-#import "CDVCommandQueue.h"
-#import "CDVPluginResult.h"
-#import "CDVViewController.h"
-
-@implementation CDVCommandDelegateImpl
-
-- (id)initWithViewController:(CDVViewController*)viewController
-{
- self = [super init];
- if (self != nil) {
- _viewController = viewController;
- _commandQueue = _viewController.commandQueue;
- }
- return self;
-}
-
-- (NSString*)pathForResource:(NSString*)resourcepath
-{
- NSBundle* mainBundle = [NSBundle mainBundle];
- NSMutableArray* directoryParts = [NSMutableArray arrayWithArray:[resourcepath componentsSeparatedByString:@"/"]];
- NSString* filename = [directoryParts lastObject];
-
- [directoryParts removeLastObject];
-
- NSString* directoryPartsJoined = [directoryParts componentsJoinedByString:@"/"];
- NSString* directoryStr = _viewController.wwwFolderName;
-
- if ([directoryPartsJoined length] > 0) {
- directoryStr = [NSString stringWithFormat:@"%@/%@", _viewController.wwwFolderName, [directoryParts componentsJoinedByString:@"/"]];
- }
-
- return [mainBundle pathForResource:filename ofType:@"" inDirectory:directoryStr];
-}
-
-- (void)evalJsHelper:(NSString*)js
-{
- void (^doIt)() = ^{
- NSString* commandsJSON = [_viewController.webView stringByEvaluatingJavaScriptFromString:js];
- [_commandQueue enqueCommandBatch:commandsJSON];
- };
-
- // Cycle the run-loop before executing the JS.
- // This works around a bug where sometimes alerts() within callbacks can cause
- // dead-lock.
- // If the commandQueue is currently executing, then we know that it is safe to
- // execute the callback immediately.
- if (![NSThread isMainThread] || !_commandQueue.currentlyExecuting) {
- dispatch_async (dispatch_get_main_queue (), doIt);
- } else {
- doIt ();
- }
-}
-
-- (void)sendPluginResult:(CDVPluginResult*)result callbackId:(NSString*)callbackId
-{
- 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 cdvjk_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];
-
- [self evalJsHelper:js];
-}
-
-- (void)evalJs:(NSString*)js
-{
- js = [js stringByAppendingString:@";cordova.require('cordova/exec').nativeFetchMessages()"];
- [self evalJsHelper:js];
-}
-
-- (BOOL)execute:(CDVInvokedUrlCommand*)command
-{
- return [_commandQueue execute:command];
-}
-
-- (id)getCommandInstance:(NSString*)pluginName
-{
- return [_viewController getCommandInstance:pluginName];
-}
-
-- (void)registerPlugin:(CDVPlugin*)plugin withClassName:(NSString*)className
-{
- [_viewController registerPlugin:plugin withClassName:className];
-}
-
-- (void)runInBackground:(void (^) ())block {
- dispatch_async (dispatch_get_global_queue (DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), block);
-}
-
-@end
http://git-wip-us.apache.org/repos/asf/incubator-cordova-ios/blob/994e2343/CordovaLib/Classes/CDVCommandDelegateImpl.h
----------------------------------------------------------------------
diff --git a/CordovaLib/Classes/CDVCommandDelegateImpl.h b/CordovaLib/Classes/CDVCommandDelegateImpl.h
new file mode 100644
index 0000000..f850dc6
--- /dev/null
+++ b/CordovaLib/Classes/CDVCommandDelegateImpl.h
@@ -0,0 +1,32 @@
+/*
+ Licensed to the Apache Software Foundation (ASF) under one
+ or more contributor license agreements. See the NOTICE file
+ distributed with this work for additional information
+ regarding copyright ownership. The ASF licenses this file
+ to you under the Apache License, Version 2.0 (the
+ "License"); you may not use this file except in compliance
+ with the License. You may obtain a copy of the License at
+
+ http://www.apache.org/licenses/LICENSE-2.0
+
+ Unless required by applicable law or agreed to in writing,
+ software distributed under the License is distributed on an
+ "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ KIND, either express or implied. See the License for the
+ specific language governing permissions and limitations
+ under the License.
+ */
+
+#import <UIKit/UIKit.h>
+#import "CDVCommandDelegate.h"
+
+@class CDVViewController;
+@class CDVCommandQueue;
+
+@interface CDVCommandDelegateImpl : NSObject <CDVCommandDelegate>{
+ @private
+ __unsafe_unretained CDVViewController* _viewController;
+ __unsafe_unretained CDVCommandQueue* _commandQueue;
+}
+- (id)initWithViewController:(CDVViewController*)viewController;
+@end
http://git-wip-us.apache.org/repos/asf/incubator-cordova-ios/blob/994e2343/CordovaLib/Classes/CDVCommandDelegateImpl.m
----------------------------------------------------------------------
diff --git a/CordovaLib/Classes/CDVCommandDelegateImpl.m b/CordovaLib/Classes/CDVCommandDelegateImpl.m
new file mode 100644
index 0000000..f35705a
--- /dev/null
+++ b/CordovaLib/Classes/CDVCommandDelegateImpl.m
@@ -0,0 +1,117 @@
+/*
+ Licensed to the Apache Software Foundation (ASF) under one
+ or more contributor license agreements. See the NOTICE file
+ distributed with this work for additional information
+ regarding copyright ownership. The ASF licenses this file
+ to you under the Apache License, Version 2.0 (the
+ "License"); you may not use this file except in compliance
+ with the License. You may obtain a copy of the License at
+
+ http://www.apache.org/licenses/LICENSE-2.0
+
+ Unless required by applicable law or agreed to in writing,
+ software distributed under the License is distributed on an
+ "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ KIND, either express or implied. See the License for the
+ specific language governing permissions and limitations
+ under the License.
+ */
+
+#import "CDVCommandDelegateImpl.h"
+
+#import "CDVCommandQueue.h"
+#import "CDVPluginResult.h"
+#import "CDVViewController.h"
+
+@implementation CDVCommandDelegateImpl
+
+- (id)initWithViewController:(CDVViewController*)viewController
+{
+ self = [super init];
+ if (self != nil) {
+ _viewController = viewController;
+ _commandQueue = _viewController.commandQueue;
+ }
+ return self;
+}
+
+- (NSString*)pathForResource:(NSString*)resourcepath
+{
+ NSBundle* mainBundle = [NSBundle mainBundle];
+ NSMutableArray* directoryParts = [NSMutableArray arrayWithArray:[resourcepath componentsSeparatedByString:@"/"]];
+ NSString* filename = [directoryParts lastObject];
+
+ [directoryParts removeLastObject];
+
+ NSString* directoryPartsJoined = [directoryParts componentsJoinedByString:@"/"];
+ NSString* directoryStr = _viewController.wwwFolderName;
+
+ if ([directoryPartsJoined length] > 0) {
+ directoryStr = [NSString stringWithFormat:@"%@/%@", _viewController.wwwFolderName, [directoryParts componentsJoinedByString:@"/"]];
+ }
+
+ return [mainBundle pathForResource:filename ofType:@"" inDirectory:directoryStr];
+}
+
+- (void)evalJsHelper:(NSString*)js
+{
+ void (^doIt)() = ^{
+ NSString* commandsJSON = [_viewController.webView stringByEvaluatingJavaScriptFromString:js];
+ [_commandQueue enqueCommandBatch:commandsJSON];
+ };
+
+ // Cycle the run-loop before executing the JS.
+ // This works around a bug where sometimes alerts() within callbacks can cause
+ // dead-lock.
+ // If the commandQueue is currently executing, then we know that it is safe to
+ // execute the callback immediately.
+ if (![NSThread isMainThread] || !_commandQueue.currentlyExecuting) {
+ dispatch_async (dispatch_get_main_queue (), doIt);
+ } else {
+ doIt ();
+ }
+}
+
+- (void)sendPluginResult:(CDVPluginResult*)result callbackId:(NSString*)callbackId
+{
+ 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 cdvjk_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];
+
+ [self evalJsHelper:js];
+}
+
+- (void)evalJs:(NSString*)js
+{
+ js = [js stringByAppendingString:@";cordova.require('cordova/exec').nativeFetchMessages()"];
+ [self evalJsHelper:js];
+}
+
+- (BOOL)execute:(CDVInvokedUrlCommand*)command
+{
+ return [_commandQueue execute:command];
+}
+
+- (id)getCommandInstance:(NSString*)pluginName
+{
+ return [_viewController getCommandInstance:pluginName];
+}
+
+- (void)registerPlugin:(CDVPlugin*)plugin withClassName:(NSString*)className
+{
+ [_viewController registerPlugin:plugin withClassName:className];
+}
+
+- (void)runInBackground:(void (^) ())block {
+ dispatch_async (dispatch_get_global_queue (DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), block);
+}
+
+@end
http://git-wip-us.apache.org/repos/asf/incubator-cordova-ios/blob/994e2343/CordovaLib/CordovaLib.xcodeproj/project.pbxproj
----------------------------------------------------------------------
diff --git a/CordovaLib/CordovaLib.xcodeproj/project.pbxproj b/CordovaLib/CordovaLib.xcodeproj/project.pbxproj
index 8cd78a5..22bcf8b 100644
--- a/CordovaLib/CordovaLib.xcodeproj/project.pbxproj
+++ b/CordovaLib/CordovaLib.xcodeproj/project.pbxproj
@@ -162,8 +162,8 @@
C937A4551337599E002C4C79 /* CDVFileTransfer.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; name = CDVFileTransfer.m; path = Classes/CDVFileTransfer.m; sourceTree = "<group>"; };
EB3B3545161CB44D003DBE7D /* CDVCommandQueue.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = CDVCommandQueue.h; path = Classes/CDVCommandQueue.h; sourceTree = "<group>"; };
EB3B3546161CB44D003DBE7D /* CDVCommandQueue.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; name = CDVCommandQueue.m; path = Classes/CDVCommandQueue.m; sourceTree = "<group>"; };
- EB3B357A161F2A44003DBE7D /* CDVCommandDelegateImpl.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = CDVCommandDelegateImpl.h; sourceTree = "<group>"; };
- EB3B357B161F2A45003DBE7D /* CDVCommandDelegateImpl.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = CDVCommandDelegateImpl.m; sourceTree = "<group>"; };
+ EB3B357A161F2A44003DBE7D /* CDVCommandDelegateImpl.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = CDVCommandDelegateImpl.h; path = Classes/CDVCommandDelegateImpl.h; sourceTree = "<group>"; };
+ EB3B357B161F2A45003DBE7D /* CDVCommandDelegateImpl.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; name = CDVCommandDelegateImpl.m; path = Classes/CDVCommandDelegateImpl.m; sourceTree = "<group>"; };
EB80C2AA15DEA63D004D9E7B /* CDVEcho.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = CDVEcho.h; path = Classes/CDVEcho.h; sourceTree = "<group>"; };
EB80C2AB15DEA63D004D9E7B /* CDVEcho.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; name = CDVEcho.m; path = Classes/CDVEcho.m; sourceTree = "<group>"; };
EBA3557115ABD38C00F4DE24 /* NSArray+Comparisons.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = "NSArray+Comparisons.h"; path = "Classes/NSArray+Comparisons.h"; sourceTree = "<group>"; };