cordova-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ste...@apache.org
Subject [1/2] js commit: updated ffos to use win8 style commandProxy
Date Tue, 12 Aug 2014 18:11:30 GMT
Repository: cordova-js
Updated Branches:
  refs/heads/3.2.x fc683fbb0 -> e9b7d2c88
  refs/heads/ffos 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/ffos
Commit: 1b208a619016a7aba8209d54ddc5efe42a8445dd
Parents: 579d990
Author: Steven Gill <stevengill97@gmail.com>
Authored: Fri Sep 13 17:37:40 2013 -0700
Committer: Steven Gill <stevengill97@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];
     }
 };


Mime
View raw message