incubator-callback-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From purplecabb...@apache.org
Subject [3/10] js commit: wrapping up the exec rewrite
Date Wed, 18 Jul 2012 21:05:45 GMT
wrapping up the exec rewrite


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/c3180d73
Tree: http://git-wip-us.apache.org/repos/asf/incubator-cordova-js/tree/c3180d73
Diff: http://git-wip-us.apache.org/repos/asf/incubator-cordova-js/diff/c3180d73

Branch: refs/heads/master
Commit: c3180d73e28bdbc3c0d730f965e3a07483452b55
Parents: f4a423d
Author: Jesse MacFadyen <purplecabbage@gmail.com>
Authored: Wed Jul 18 13:37:31 2012 -0700
Committer: Jesse MacFadyen <purplecabbage@gmail.com>
Committed: Wed Jul 18 13:37:31 2012 -0700

----------------------------------------------------------------------
 lib/wp7/exec.js                      |   85 +----------------------------
 lib/wp7/platform.js                  |    4 ++
 lib/wp7/plugin/wp7/DirectoryEntry.js |   50 +++++++++++++++++
 lib/wp7/plugin/wp7/FileTransfer.js   |   14 +++---
 4 files changed, 63 insertions(+), 90 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-cordova-js/blob/c3180d73/lib/wp7/exec.js
----------------------------------------------------------------------
diff --git a/lib/wp7/exec.js b/lib/wp7/exec.js
index 74421e9..3f59f5b 100644
--- a/lib/wp7/exec.js
+++ b/lib/wp7/exec.js
@@ -1,67 +1,5 @@
 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 NamedArgs =  {
-    File:{
-        getFileMetadata:["fullPath"],
-        getMetadata:["fullPath"],
-        getParent:["fullPath"],
-        readAsText:["fileName","encoding"],
-        readAsDataURL:["fileName"],
-        getDirectory:["fullPath","path","options"],
-        remove:["fullPath"],
-        removeRecursively:["fullPath"],
-        getFile:["fullPath","path","options"],
-        readEntries:["fullPath"],
-        write:["fileName","data","position"],
-        truncate:["fileName","size"],
-        copyTo:["fullPath","parent", "newName"],
-        moveTo:["fullPath","parent", "newName"],
-        requestFileSystem:["type","size"],
-        resolveLocalFileSystemURI:["uri"]
-    }
-    // ,
-    // FileTransfer:{
-    //     upload:["filePath", "server", "fileKey", "fileName", "mimeType", "params", "debug",
"chunkedMode"],
-    //     download:["url","filePath"]
-    // },
-
-};
-
-/*
-    Notification: {
-        alert:["message","title","buttonLabel"],
-        confirm:["message","title","buttonLabel"]
-    },
-    Camera:{
-        takePicture:["quality", "destinationType", "sourceType", "targetWidth", "targetHeight",
"encodingType",
-                     "mediaType", "allowEdit", "correctOrientation", "saveToPhotoAlbum" ]
-    },
-    Contacts:{
-        search:["fields","options"]
-    },
-    Capture:{
-        getFormatData:["fullPath","type"]
-    }
-    Media:{
-        create:["id","src"],
-        startPlayingAudio:["id","src","milliseconds"],
-        stopPlayingAudio:["id"],
-        seekToAudio:["id","milliseconds"],
-        pausePlayingAudio:["id"],
-        getCurrentPositionAudio:["id"],
-        startRecordingAudio:["id","src"],
-        stopRecordingAudio:["id"],
-        release:["id"],
-        setVolume:["id","volume"]
-    },
-*/
-
 /**
  * Execute a cordova command.  It is up to the native side whether this action
  * is synchronous or asynchronous.  The native side can return:
@@ -80,30 +18,11 @@ var NamedArgs =  {
 
 module.exports = function(success, fail, service, action, args) {
 
-
     var callbackId = service + cordova.callbackId++;
-    if (typeof success == "function" || typeof fail == "function")
-    {
+    if (typeof success == "function" || typeof fail == "function") {
         cordova.callbacks[callbackId] = {success:success, fail:fail};
     }
-
-    // generate a new command string, ex. DebugConsole/log/DebugConsole23/{"message":"wtf
dude?"}
-
-    if(NamedArgs[service] && NamedArgs[service][action]) {
-        var argNames = NamedArgs[service][action];
-        var newArgs = {};
-        var len = Math.min(args.length,argNames.length);
-
-        for(var n = 0; n < len; n++) {
-            newArgs[argNames[n]] = args[n];
-        }
-
-        args = newArgs;
-    }
-    // else if(args && args.length && args.length == 1) {
-    //     args = args[0];
-    // }
-
+    // generate a new command string, ex. DebugConsole/log/DebugConsole23/["wtf dude?"]
     var command = service + "/" + action + "/" + callbackId + "/" + JSON.stringify(args);
     // pass it on to Notify
     try {

http://git-wip-us.apache.org/repos/asf/incubator-cordova-js/blob/c3180d73/lib/wp7/platform.js
----------------------------------------------------------------------
diff --git a/lib/wp7/platform.js b/lib/wp7/platform.js
index 718830c..f482ce7 100644
--- a/lib/wp7/platform.js
+++ b/lib/wp7/platform.js
@@ -56,7 +56,11 @@ module.exports = {
         },
         FileTransfer: {
             path: 'cordova/plugin/wp7/FileTransfer'
+        },
+        DirectoryEntry: {
+            path: 'cordova/plugin/wp7/DirectoryEntry'
         }
+        
     },
     merges:{
         navigator: {

http://git-wip-us.apache.org/repos/asf/incubator-cordova-js/blob/c3180d73/lib/wp7/plugin/wp7/DirectoryEntry.js
----------------------------------------------------------------------
diff --git a/lib/wp7/plugin/wp7/DirectoryEntry.js b/lib/wp7/plugin/wp7/DirectoryEntry.js
new file mode 100644
index 0000000..4c1a4cb
--- /dev/null
+++ b/lib/wp7/plugin/wp7/DirectoryEntry.js
@@ -0,0 +1,50 @@
+
+var DirectoryEntry = require('cordova/plugin/DirectoryEntry'),
+    exec = require('cordova/exec'),
+    FileError = require('cordova/plugin/FileError');
+
+// Note, this is a special case, we need to overwrite the functions getDirectory + getFile.
+// Entry uses require at runtime, and will not find our patched version of the funks
+// so we have to overwrite the prototype manually -jm
+// In this case there is nothing to export.
+
+/**
+ * Creates or looks up a directory
+ *
+ * @param {DOMString} path either a relative or absolute path from this directory in which
to look up or create a directory
+ * @param {Flags} options to create or excluively create the directory
+ * @param {Function} successCallback is called with the new entry
+ * @param {Function} errorCallback is called with a FileError
+ */
+DirectoryEntry.prototype.getDirectory = function(path, options, successCallback, errorCallback)
{
+
+    var win = typeof successCallback !== 'function' ? null : function(result) {
+        var entry = new DirectoryEntry(result.name, result.fullPath);
+        successCallback(entry);
+    };
+    var fail = typeof errorCallback !== 'function' ? null : function(code) {
+        errorCallback(new FileError(code));
+    };
+    exec(win, fail, "File", "getDirectory", [this.fullPath, path, JSON.stringify(options)]);
+};
+
+/**
+ * Creates or looks up a file
+ *
+ * @param {DOMString} path either a relative or absolute path from this directory in which
to look up or create a file
+ * @param {Flags} options to create or excluively create the file
+ * @param {Function} successCallback is called with the new entry
+ * @param {Function} errorCallback is called with a FileError
+ */
+DirectoryEntry.prototype.getFile = function(path, options, successCallback, errorCallback)
{
+
+    var win = typeof successCallback !== 'function' ? null : function(result) {
+        var FileEntry = require('cordova/plugin/FileEntry');
+        var entry = new FileEntry(result.name, result.fullPath);
+        successCallback(entry);
+    };
+    var fail = typeof errorCallback !== 'function' ? null : function(code) {
+        errorCallback(new FileError(code));
+    };
+    exec(win, fail, "File", "getFile", [this.fullPath, path, JSON.stringify(options)]);
+};

http://git-wip-us.apache.org/repos/asf/incubator-cordova-js/blob/c3180d73/lib/wp7/plugin/wp7/FileTransfer.js
----------------------------------------------------------------------
diff --git a/lib/wp7/plugin/wp7/FileTransfer.js b/lib/wp7/plugin/wp7/FileTransfer.js
index c4baef7..a1393e5 100644
--- a/lib/wp7/plugin/wp7/FileTransfer.js
+++ b/lib/wp7/plugin/wp7/FileTransfer.js
@@ -54,13 +54,13 @@ FileTransfer.prototype.upload = function(filePath, server, successCallback,
erro
         var error = new FileTransferError(e.code, e.source, e.target, e.http_status);
         errorCallback(error);
     };
-    exec(successCallback, fail, 'FileTransfer', 'upload', [{"filePath":filePath, 
-                                                              "server":server, 
-                                                              "fileKey":fileKey, 
-                                                              "fileName":fileName, 
-                                                              "mimeType":mimeType, 
-                                                              "params":params, 
-                                                              "trustAllHosts":trustAllHosts,

+    exec(successCallback, fail, 'FileTransfer', 'upload', [{"filePath":filePath,
+                                                              "server":server,
+                                                              "fileKey":fileKey,
+                                                              "fileName":fileName,
+                                                              "mimeType":mimeType,
+                                                              "params":params,
+                                                              "trustAllHosts":trustAllHosts,
                                                               "chunkedMode":chunkedMode}]);
 };
 


Mime
View raw message