add command proxy for non-native platforms

Project: http://git-wip-us.apache.org/repos/asf/incubator-cordova-js/repo
Commit: 
http://git-wip-us.apache.org/repos/asf/incubator-cordova-js/commit/0d58bf4a
Tree: http://git-wip-us.apache.org/repos/asf/incubator-cordova-js/tree/0d58bf4a
Diff: http://git-wip-us.apache.org/repos/asf/incubator-cordova-js/diff/0d58bf4a

Branch: refs/heads/master
Commit: 0d58bf4ae1b662001e396c48a09f16dc3b1c099f
Parents: 602c064
Author: Jesse MacFadyen <purplecabb...@gmail.com>
Authored: Fri Oct 5 17:11:24 2012 -0700
Committer: Jesse MacFadyen <purplecabb...@gmail.com>
Committed: Fri Oct 5 17:11:24 2012 -0700

----------------------------------------------------------------------
 lib/common/commandProxy.js |   46 ++++++++++++++++++++++++++
 lib/windows8/exec.js       |   67 ++++----------------------------------
 lib/windows8/platform.js   |   22 +++++++++++++
 3 files changed, 75 insertions(+), 60 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-cordova-js/blob/0d58bf4a/lib/common/commandProxy.js
----------------------------------------------------------------------
diff --git a/lib/common/commandProxy.js b/lib/common/commandProxy.js
new file mode 100644
index 0000000..f6b2a04
--- /dev/null
+++ b/lib/common/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 );
+    }
+};

http://git-wip-us.apache.org/repos/asf/incubator-cordova-js/blob/0d58bf4a/lib/windows8/exec.js
----------------------------------------------------------------------
diff --git a/lib/windows8/exec.js b/lib/windows8/exec.js
index d563201..46343bd 100644
--- a/lib/windows8/exec.js
+++ b/lib/windows8/exec.js
@@ -20,13 +20,7 @@
 */
 
 var cordova = require('cordova');
-
-
- /* definition of named properties expected by the native side,
-    all arrays are stored in order of how they are received from common js 
code.
-    When other platforms evolve to using named args this will be removed.
- */
-
+var commandProxy = require('cordova/commandProxy');
 
 /**
  * Execute a cordova command.  It is up to the native side whether this action
@@ -42,70 +36,23 @@ var cordova = require('cordova');
  * @param {String} action       Action to be run in cordova
  * @param {String[]} [args]     Zero or more arguments to pass to the method
  */
-
-
-
-var CommandProxy;
-
-function getCP() {
-    if (!CommandProxy) {
-        CommandProxy = {
-          "Accelerometer": 
require('cordova/plugin/windows8/AccelerometerProxy'),
-          "Camera":require('cordova/plugin/windows8/CameraProxy'),
-          "Capture":require('cordova/plugin/windows8/CaptureProxy'),
-          "Compass":require('cordova/plugin/windows8/CompassProxy'),
-          "Device":require('cordova/plugin/windows8/DeviceProxy'),
-          "File":require('cordova/plugin/windows8/FileProxy'),
-          "FileTransfer":require('cordova/plugin/windows8/FileTransferProxy'),
-          "Media":require('cordova/plugin/windows8/MediaProxy'),
-          
"NetworkStatus":require('cordova/plugin/windows8/NetworkStatusProxy'),
-          "Notification":require('cordova/plugin/windows8/NotificationProxy')
-        };
-    }
-    return CommandProxy;
-}
-
 module.exports = function(success, fail, service, action, args) {
-    var CommandProxy = getCP();
-    if(CommandProxy[service] && CommandProxy[service][action]) {
 
+    var proxy = commandProxy.get(service,action);
+    if(proxy) {
         var callbackId = service + cordova.callbackId++;
-        console.log("EXEC:" + service + " : " + action);
-
+        // console.log("EXEC:" + service + " : " + action);
         if (typeof success == "function" || typeof fail == "function") {
             cordova.callbacks[callbackId] = {success:success, fail:fail};
         }
-        // pass it on to Notify
         try {
-            CommandProxy [service][action](success, fail, args);
+            proxy(success, fail, args);
         }
         catch(e) {
             console.log("Exception calling native with command :: " + service 
+ " :: " + action  + " ::exception=" + e);
         }
     }
-    else
-    {
-        if(fail) { fail("Missing Command Error"); }
+    else {
+        fail && fail("Missing Command Error");
     }
-
-};
-
-// cordova.exec.addCommandProxy("Accelerometer",{getCurrentAcceleration: 
function(successCallback, errorCallback, options) {...},...);
-module.exports.addCommandProxy = function(id,proxyObj) {
-    var CommandProxy = getCP();
-    CommandProxy[id] = proxyObj;
-};
-
-// cordova.exec.removeCommandProxy("Accelerometer");
-module.exports.removeCommandProxy = function(id) {
-    var CommandProxy = getCP();
-    var proxy = CommandProxy[id];
-    delete CommandProxy[id];
-    CommandProxy[id] = null;
-    return proxy;
 };
-
-
-
-
-

http://git-wip-us.apache.org/repos/asf/incubator-cordova-js/blob/0d58bf4a/lib/windows8/platform.js
----------------------------------------------------------------------
diff --git a/lib/windows8/platform.js b/lib/windows8/platform.js
index 28d0e07..948e9ab 100755
--- a/lib/windows8/platform.js
+++ b/lib/windows8/platform.js
@@ -23,12 +23,34 @@ var cordova = require('cordova'),
     exec = require('cordova/exec'),
     channel = cordova.require("cordova/channel");
 
+/*
+ * Define native implementations ( there is no native layer, so need to make 
sure the proxies are there )
+*/
+
+require('cordova/plugin/windows8/DeviceProxy');
+require('cordova/plugin/windows8/NetworkStatusProxy');
+require('cordova/plugin/windows8/AccelerometerProxy');
+require('cordova/plugin/windows8/CameraProxy');
+require('cordova/plugin/windows8/CaptureProxy');
+require('cordova/plugin/windows8/CompassProxy');
+require('cordova/plugin/windows8/FileProxy');
+require('cordova/plugin/windows8/MediaProxy');
+require('cordova/plugin/windows8/NotificationProxy');
+
 module.exports = {
     id: "windows8",
     initialize:function() {
 
     },
     objects: {
+        cordova: {
+            path: 'cordova',
+            children: {
+                commandProxy: {
+                    path: 'cordova/commandProxy'
+                }
+            }
+        },        
         navigator: {
             children: {
                 device: {

Reply via email to