You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@cordova.apache.org by pu...@apache.org on 2012/04/20 23:16:04 UTC

[3/5] git commit: merging exec with new NamedArgs method

merging exec with new NamedArgs method


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

Branch: refs/heads/master
Commit: 452126ae427d059e3ae34e13ad6c7b2618d36fcf
Parents: e034157 acb911a
Author: Jesse MacFadyen <pu...@gmail.com>
Authored: Fri Apr 20 13:02:41 2012 -0700
Committer: Jesse MacFadyen <pu...@gmail.com>
Committed: Fri Apr 20 13:02:41 2012 -0700

----------------------------------------------------------------------
 .jshintrc                                          |  141 ++++++
 Jakefile                                           |  102 ++++-
 README.md                                          |  103 ++---
 lib/android/exec.js                                |    3 +-
 lib/android/platform.js                            |    6 +-
 lib/android/plugin/android/app.js                  |    6 +-
 lib/android/plugin/android/callback.js             |    2 +-
 lib/android/plugin/android/device.js               |   14 +-
 lib/android/plugin/android/notification.js         |    2 +-
 lib/android/plugin/android/polling.js              |    2 +-
 lib/android/plugin/android/storage.js              |    4 +-
 lib/bada/exec.js                                   |   18 +
 lib/bada/platform.js                               |   18 +
 lib/bada/plugin/bada/Accelerometer.js              |   43 ++
 lib/bada/plugin/bada/NetworkStatus.js              |   31 ++
 lib/bada/plugin/bada/Notification.js               |   50 ++
 lib/bada/plugin/bada/device.js                     |   84 ++++
 lib/blackberry/exec.js                             |    2 +-
 lib/blackberry/platform.js                         |    2 +-
 lib/blackberry/plugin/blackberry/Contact.js        |   37 +-
 lib/blackberry/plugin/blackberry/ContactUtils.js   |   25 +-
 lib/blackberry/plugin/blackberry/DirectoryEntry.js |    2 +-
 lib/blackberry/plugin/blackberry/Entry.js          |    1 +
 lib/blackberry/plugin/blackberry/app.js            |    5 +-
 lib/blackberry/plugin/blackberry/contacts.js       |    4 +-
 lib/blackberry/plugin/blackberry/device.js         |    2 +-
 lib/blackberry/plugin/blackberry/manager.js        |    2 +-
 lib/blackberry/plugin/blackberry/notification.js   |    2 +-
 lib/common/builder.js                              |    2 +
 lib/common/channel.js                              |   12 +-
 lib/common/common.js                               |    2 +-
 lib/common/exec.js                                 |    2 +-
 lib/common/platform.js                             |    2 +-
 lib/common/plugin/Acceleration.js                  |    2 +-
 lib/common/plugin/Camera.js                        |   20 +-
 lib/common/plugin/CameraConstants.js               |    2 +-
 lib/common/plugin/CaptureAudioOptions.js           |   14 +-
 lib/common/plugin/CaptureError.js                  |    4 +-
 lib/common/plugin/CaptureImageOptions.js           |   10 +-
 lib/common/plugin/CaptureVideoOptions.js           |   14 +-
 lib/common/plugin/CompassError.js                  |    2 +-
 lib/common/plugin/CompassHeading.js                |    2 +-
 lib/common/plugin/ConfigurationData.js             |   12 +-
 lib/common/plugin/Connection.js                    |   16 +-
 lib/common/plugin/Contact.js                       |   14 +-
 lib/common/plugin/ContactAddress.js                |    2 +-
 lib/common/plugin/ContactError.js                  |    2 +-
 lib/common/plugin/ContactField.js                  |    2 +-
 lib/common/plugin/ContactFindOptions.js            |    2 +-
 lib/common/plugin/ContactName.js                   |    2 +-
 lib/common/plugin/ContactOrganization.js           |    2 +-
 lib/common/plugin/Coordinates.js                   |    2 +-
 lib/common/plugin/DirectoryEntry.js                |    1 +
 lib/common/plugin/DirectoryReader.js               |    7 +-
 lib/common/plugin/Entry.js                         |    2 +-
 lib/common/plugin/File.js                          |   12 +-
 lib/common/plugin/FileEntry.js                     |    2 +-
 lib/common/plugin/FileError.js                     |    2 +-
 lib/common/plugin/FileReader.js                    |    2 +-
 lib/common/plugin/FileSystem.js                    |    2 +-
 lib/common/plugin/FileTransfer.js                  |    6 +-
 lib/common/plugin/FileTransferError.js             |    2 +-
 lib/common/plugin/FileUploadOptions.js             |    2 +-
 lib/common/plugin/FileUploadResult.js              |    2 +-
 lib/common/plugin/FileWriter.js                    |    4 +-
 lib/common/plugin/Flags.js                         |    4 +-
 lib/common/plugin/LocalFileSystem.js               |    2 +-
 lib/common/plugin/Media.js                         |    4 +-
 lib/common/plugin/MediaError.js                    |    2 +-
 lib/common/plugin/MediaFile.js                     |   12 +-
 lib/common/plugin/MediaFileData.js                 |   12 +-
 lib/common/plugin/Metadata.js                      |    4 +-
 lib/common/plugin/Position.js                      |    6 +-
 lib/common/plugin/PositionError.js                 |    2 +-
 lib/common/plugin/ProgressEvent.js                 |    2 +-
 lib/common/plugin/accelerometer.js                 |    2 +-
 lib/common/plugin/battery.js                       |   44 +-
 lib/common/plugin/capture.js                       |    8 +-
 lib/common/plugin/compass.js                       |   46 +-
 lib/common/plugin/contacts.js                      |    2 +-
 lib/common/plugin/geolocation.js                   |    4 +-
 lib/common/plugin/network.js                       |    2 +-
 lib/common/plugin/notification.js                  |    2 +-
 lib/common/plugin/requestFileSystem.js             |    2 +-
 lib/common/plugin/resolveLocalFileSystemURI.js     |    1 +
 lib/common/utils.js                                |   16 +-
 lib/cordova.js                                     |   40 ++-
 lib/errgen/exec.js                                 |   76 ++--
 lib/errgen/platform.js                             |    4 +-
 lib/errgen/plugin/errgen/device.js                 |   24 +-
 lib/ios/exec.js                                    |   18 +-
 lib/ios/platform.js                                |   12 +-
 lib/ios/plugin/ios/Contact.js                      |   44 +-
 lib/ios/plugin/ios/Entry.js                        |    8 +-
 lib/ios/plugin/ios/FileReader.js                   |    4 +-
 lib/ios/plugin/ios/console.js                      |   32 +-
 lib/ios/plugin/ios/contacts.js                     |   48 +-
 lib/ios/plugin/ios/device.js                       |    2 +-
 lib/ios/plugin/ios/nativecomm.js                   |    2 +-
 lib/ios/plugin/ios/notification.js                 |    2 +-
 lib/playbook/exec.js                               |    2 +-
 lib/playbook/platform.js                           |    2 +-
 lib/playbook/plugin/playbook/device.js             |    2 +-
 lib/playbook/plugin/playbook/manager.js            |    4 +-
 lib/scripts/bootstrap-bada.js                      |    1 +
 lib/scripts/bootstrap-errgen.js                    |    2 +-
 lib/scripts/bootstrap-playbook.js                  |    2 +-
 lib/scripts/bootstrap.js                           |   20 +-
 lib/scripts/require.js                             |    2 +-
 lib/test/exec.js                                   |    2 +-
 lib/webworks/plugin/webworks/manager.js            |    2 +-
 lib/wp7/exec.js                                    |   16 +-
 lib/wp7/platform.js                                |   56 ++--
 lib/wp7/plugin/wp7/CordovaCommandResult.js         |   86 ++--
 lib/wp7/plugin/wp7/CordovaMediaonStatus.js         |    8 +-
 lib/wp7/plugin/wp7/DOMStorage.js                   |  125 ++----
 lib/wp7/plugin/wp7/XHRPatch.js                     |  350 +++++++--------
 lib/wp7/plugin/wp7/console.js                      |   21 +-
 lib/wp7/plugin/wp7/device.js                       |    2 +-
 lib/wp7/plugin/wp7/requestFileSystem.js            |    2 +-
 lib/wp7/plugin/wp7/resolveLocalFileSystemURI.js    |    5 +-
 package.json                                       |   10 +-
 122 files changed, 1278 insertions(+), 844 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-cordova-js/blob/452126ae/lib/common/plugin/capture.js
----------------------------------------------------------------------

http://git-wip-us.apache.org/repos/asf/incubator-cordova-js/blob/452126ae/lib/wp7/exec.js
----------------------------------------------------------------------
diff --cc lib/wp7/exec.js
index 44effb0,ed52ecb..6fae6f4
--- a/lib/wp7/exec.js
+++ b/lib/wp7/exec.js
@@@ -1,50 -1,5 +1,51 @@@
  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"],
 +		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"]
- 	},		 
++    },
 +	FileTransfer:{
 +		upload:["filePath", "server", "fileKey", "fileName", "mimeType", "params", "debug", "chunkedMode"]
 +	},
 +	Contacts:{
 +		search:["fields","options"]
 +	},
 +	Media:{
 +		create:["id","src"],
 +		startPlayingAudio:["id","src","milliseconds"],
 +		//stopPlayingAudio
 +		seekToAudio:["id","milliseconds"],
 +		//pausePlayingAudio
 +		//getCurrentPositionAudio
 +		startRecordingAudio:["id","src"],
 +		stopRecordingAudio:["id"],
 +		release:["id"],
 +		setVolume:["id","volume"]
 +	},
 +	Notification: {
 +		alert:["message","title","buttonLabel"],
 +		confirm:["message","title","buttonLabel"]
 +	},
 +	Camera:{
 +		takePicture:["quality", "destinationType", "sourceType", "targetWidth", "targetHeight", "encodingType"]
 +	}
 +};
 +
  /**
   * Execute a cordova command.  It is up to the native side whether this action
   * is synchronous or asynchronous.  The native side can return:
@@@ -61,42 -16,204 +62,43 @@@
  
   */
  
 - /* this will become a programmatic way to gen the named args ... TODO: -jm
 -var NamedArgs =
 -{
 -    File:{
 -        getFileMetadata:["fullPath"],
 -        readAsText:["fileName","encoding"],
 -        readAsDataURL:["fileName"],
 -        getDirectory:["fullPath","path","options"],
 -        removeRecursively:["fullPath"],
 -        getFile:["fullPath","path","options"],
 -        readEntries:["fullPath"],
 -        write:["fileName","data","position"],
 -        truncate:["fileName","size"]
 -    }
 -}
 -*/
 -
 -var MonkeyPatch =
 -{
 -    File:
 -    {
 -        "getFileMetadata":function(arg)
 -        {
 -            return  {fullPath:arg[0]};
 -        },
 -        "readAsText":function(arg)
 -        { //[this.fileName, enc]
 -            return {fileName:arg[0],encoding:arg[1]};
 -        },
 -        "readAsDataURL":function(arg)
 -        {
 -            return {fileName:arg[0]};
 -        },
 -        "getDirectory":function(arg)
 -        {
 -            return {fullPath:arg[0],path:arg[1],options:arg[2]};
 -        },
 -        "removeRecursively":function(arg)
 -        {
 -            return {fullPath:arg[0]};
 -        },
 -        "getFile":function(arg)
 -        {
 -            return {fullPath:arg[0],path:arg[1],options:arg[2]};
 -        },
 -        "readEntries":function(arg)
 -        {
 -            return {fullPath:arg[0]};
 -        },
 -        "write":function(arg)
 -        {
 -            return {fileName:arg[0],data:arg[1],position:arg[2]};
 -        },
 -        "truncate":function(arg)
 -        {
 -            return {fileName:arg[0],size:arg[1]};
 -        }
 -
 -    },
 -    FileTransfer:
 -    {
 -        // [filePath, server, fileKey, fileName, mimeType, params, debug, chunkedMode]
 -        "upload":function(arg)
 -        {
 -            // note, chuncked mode is not supported in WP7 currently
 -            return {filePath:arg[0],server:arg[1],fileKey:arg[2],fileName:arg[3],mimeType:arg[4],params:arg[5],debug:arg[6]};
 -        }
 -    },
 -    Contacts:
 -    {
 -        "remove":function(arg) // actually caught by our other case inside exec
 -        {
 -            return arg[0];
 -        },
 -        "save":function(arg) // actually caught by our other case inside exec
 -        {
 -            return arg[0];
 -        },
 -        "search":function(arg)
 -        {
 -            return {fields:arg[0],options:arg[1]};
 -        }
 -    },
 -    Capture:
 -    {
 -        captureAudio:function(arg)// actually caught by our other case inside exec
 -        {
 -            return arg[0];
 -        },
 -        captureVideo:function(arg)// actually caught by our other case inside exec
 -        {
 -            return arg[0];
 -        },
 -        captureImage:function(arg)// actually caught by our other case inside exec
 -        {
 -            return arg[0];
 -        }
 -    },
 -    Media:
 -    {
 -        create:function(arg)
 -        {
 -            return {id:arg[0],src:arg[1]};
 -        },
 -        startPlayingAudio:function(arg)
 -        {
 -            return {id:arg[0],src:arg[1],milliseconds:arg[2]};
 -        },
 -        stopPlayingAudio:function(arg)
 -        {
 -            return {id:arg[0]};
 -        },
 -        seekToAudio:function(arg)
 -        {
 -            return {id:arg[0],milliseconds:arg[1]};
 -        },
 -        pausePlayingAudio:function(arg)
 -        {
 -            return {id:arg[0]};
 -        },
 -        getCurrentPositionAudio:function(arg)
 -        {
 -            return {id:arg[0]};
 -        },
 -        startRecordingAudio:function(arg)
 -        {
 -            return {id:arg[0],src:arg[1]};
 -        },
 -        stopRecordingAudio:function(arg)
 -        {
 -            return {id:arg[0]};
 -        },
 -        release:function(arg)
 -        {
 -            return {id:arg[0]};
 -        },
 -        setVolume:function(arg)
 -        {
 -            return {id:arg[0],volume:arg[1]};
 -        }
 -    },
 -    Notification:
 -    {
 -        "alert":function(arg)
 -        {
 -            return {message:arg[0],title:arg[1],buttonLabel:arg[2]};
 -        },
 -        "confirm":function(arg)
 -        {
 -            return {message:arg[0],title:arg[1],buttonLabel:arg[2]};
 -        }
 -    },
 -    Camera:
 -    {
 -        "takePicture":function(arg)
 -        {
 -            //"takePicture", [quality, destinationType, sourceType, targetWidth, targetHeight, encodingType]);
 -            return {quality:arg[0],destinationType:arg[1],sourceType:arg[2],targetWidth:arg[3],targetHeight:arg[4],encodingType:arg[5]};
 -        }
 -    }
 -
 -};
 -
 -module.exports = function(success, fail, service, action, args)
 -{
 +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(MonkeyPatch[service] && MonkeyPatch[service][action])
 -     {
 -        //console.log("MonkeyPatching " + service + "." + action);
 -        args =  MonkeyPatch[service][action](args);
 -     }
 -     else if(args && args.length && args.length == 1)
 -     {
 -         args = args[0];
 -     }
 +	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]; 
++		args = args[0];
 +	}
 +	
 +	var command = service + "/" + action + "/" + callbackId + "/" + JSON.stringify(args);
 +	// pass it on to Notify
 +	try {
 +		if(window.external) {
 +			window.external.Notify(command);
 +		}
 +		else {
- 			console.log("window.external not available :: command=" + command);  
++			console.log("window.external not available :: command=" + command);
 +		}
 +	}
 +	catch(e) {
- 		console.log("Exception calling native with command :: " + command + " :: exception=" + e); 
++		console.log("Exception calling native with command :: " + command + " :: exception=" + e);
 +	}
 +};
  
- 
 -     var command = service + "/" + action + "/" + callbackId + "/" + JSON.stringify(args);
 -     // pass it on to Notify
 -     try
 -     {
 -         if(window.external)
 -         {
 -             window.external.Notify(command);
 -         }
 -         else
 -         {
 -            console.log("window.external not available :: command=" + command);
 -         }
 -     }
 -     catch(e)
 -     {
 -         console.log("Exception calling native with command :: " + command + " :: exception=" + e);
 -     }
 -};