You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@cordova.apache.org by st...@apache.org on 2013/09/14 02:38:19 UTC
js commit: updated ffos to use win8 style commandProxy
Updated Branches:
refs/heads/master 579d990af -> 1b208a619
updated ffos to use win8 style commandProxy
Project: http://git-wip-us.apache.org/repos/asf/cordova-js/repo
Commit: http://git-wip-us.apache.org/repos/asf/cordova-js/commit/1b208a61
Tree: http://git-wip-us.apache.org/repos/asf/cordova-js/tree/1b208a61
Diff: http://git-wip-us.apache.org/repos/asf/cordova-js/diff/1b208a61
Branch: refs/heads/master
Commit: 1b208a619016a7aba8209d54ddc5efe42a8445dd
Parents: 579d990
Author: Steven Gill <st...@gmail.com>
Authored: Fri Sep 13 17:37:40 2013 -0700
Committer: Steven Gill <st...@gmail.com>
Committed: Fri Sep 13 17:37:40 2013 -0700
----------------------------------------------------------------------
lib/firefoxos/exec.js | 27 ++++++++++++----
lib/firefoxos/firefoxos/commandProxy.js | 46 ++++++++++++++++++++++++++++
lib/firefoxos/platform.js | 12 +-------
3 files changed, 68 insertions(+), 17 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/cordova-js/blob/1b208a61/lib/firefoxos/exec.js
----------------------------------------------------------------------
diff --git a/lib/firefoxos/exec.js b/lib/firefoxos/exec.js
index a41d5df..bcf25d0 100644
--- a/lib/firefoxos/exec.js
+++ b/lib/firefoxos/exec.js
@@ -19,11 +19,26 @@
*
*/
-var firefoxos = require('cordova/platform');
+//var firefoxos = require('cordova/platform');
+var cordova = require('cordova');
+var commandProxy = require('cordova/firefoxos/commandProxy');
-module.exports = function(success, fail, service, action, actionArgs) {
- var plugin = firefoxos.getPlugin(service);
- actionArgs.unshift(fail);
- actionArgs.unshift(success);
- plugin[action].apply(plugin, actionArgs);
+module.exports = function(success, fail, service, action, args) {
+ var proxy = commandProxy.get(service,action);
+ if(proxy) {
+ var callbackId = service + cordova.callbackId++;
+ console.log("EXEC:" + service + " : " + action);
+ if (typeof success == "function" || typeof fail == "function") {
+ cordova.callbacks[callbackId] = {success:success, fail:fail};
+ }
+ try {
+ proxy(success, fail, args);
+ }
+ catch(e) {
+ console.log("Exception calling native with command :: " + service + " :: " + action + " ::exception=" + e);
+ }
+ }
+ else {
+ fail && fail("Missing Command Error");
+ }
};
http://git-wip-us.apache.org/repos/asf/cordova-js/blob/1b208a61/lib/firefoxos/firefoxos/commandProxy.js
----------------------------------------------------------------------
diff --git a/lib/firefoxos/firefoxos/commandProxy.js b/lib/firefoxos/firefoxos/commandProxy.js
new file mode 100644
index 0000000..e640003
--- /dev/null
+++ b/lib/firefoxos/firefoxos/commandProxy.js
@@ -0,0 +1,46 @@
+/*
+ *
+ * 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.
+ *
+*/
+
+
+// internal map of proxy function
+var CommandProxyMap = {};
+
+module.exports = {
+
+ // example: cordova.commandProxy.add("Accelerometer",{getCurrentAcceleration: function(successCallback, errorCallback, options) {...},...);
+ add:function(id,proxyObj) {
+ console.log("adding proxy for " + id);
+ CommandProxyMap[id] = proxyObj;
+ return proxyObj;
+ },
+
+ // cordova.commandProxy.remove("Accelerometer");
+ remove:function(id) {
+ var proxy = CommandProxyMap[id];
+ delete CommandProxyMap[id];
+ CommandProxyMap[id] = null;
+ return proxy;
+ },
+
+ get:function(service,action) {
+ return ( CommandProxyMap[service] ? CommandProxyMap[service][action] : null );
+ }
+};
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/cordova-js/blob/1b208a61/lib/firefoxos/platform.js
----------------------------------------------------------------------
diff --git a/lib/firefoxos/platform.js b/lib/firefoxos/platform.js
index b7158d8..07ba3b1 100644
--- a/lib/firefoxos/platform.js
+++ b/lib/firefoxos/platform.js
@@ -19,22 +19,12 @@
*
*/
-var plugins = {};
-
module.exports = {
id: 'firefoxos',
cordovaVersion: '3.0.0',
bootstrap: function() {
+ require('cordova/modulemapper').clobbers('cordova/firefoxos/commandProxy', 'cordova.commandProxy');
require('cordova/channel').onNativeReady.fire();
- },
-
- registerPlugin: function(name, plugin) {
- plugins[name] = plugin;
- console.log('registered ' + name);
- },
-
- getPlugin: function(name) {
- return plugins[name];
}
};