You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@cordova.apache.org by Apache Wiki <wi...@apache.org> on 2012/04/07 07:13:35 UTC

[Cordova Wiki] Update of "PluginDesign" by FilMaj

Dear Wiki user,

You have subscribed to a wiki page or wiki category on "Cordova Wiki" for change notification.

The "PluginDesign" page has been changed by FilMaj:
http://wiki.apache.org/cordova/PluginDesign?action=diff&rev1=4&rev2=5

Comment:
Adding a suggestion for the native and JavaScript file structures

  
  == JavaScript files ==
  
- TBD
+  * Taking advantage of the plugin interfaces defined in the [[http://git-wip-us.apache.org/repos/asf?p=incubator-cordova-ios.git;a=summary|cordova-js]] project:
+   * Using the {{{exec}}} function that is referencerable by calling {{{cordova.require('cordova/exec')}}} regardless of platform.
+    * {{{exec}}} function has the signature {{{function(successCallback, errorCallback, service, action, args}}}, with the arguments:
+     * {{{successCallback}}} - function that native can invoke by calling their {{{success}} method and optionally pass in arguments
+     * {{{errorCallback}}} - function that native can invoke by calling their {{{error}}} method and optionally pass in arguments
+     * {{{service}}} - the native plugin label that maps to the desired native plugin. Each native platform has a different mapping mechanism - see the below Native Files section for more details
+     * {{{action}}} - the native plugin method label that maps to the desired native plugin method. Each native platform has a different mapping mechanism - see below under Native Files section for more details
+     * {{{args}}} - an Array of parameters to pass into the native plugin methods
+   * Recommended to use {{{cordova.define}}} as module definition wrapper that conforms with cordova.
  
  == Native Files ==
  
- TBD
+  * Taking advantage of the plugin interfaces defined for each platform:
+   * iOS: The [[http://git-wip-us.apache.org/repos/asf?p=incubator-cordova-ios.git;a=blob;f=CordovaLib/Classes/CDVPlugin.h;h=662d4e9de9a3369b0fd14ceb225a83f9f87b4e69;hb=HEAD|CDVPlugin interface]]. Also available is a [[http://git-wip-us.apache.org/repos/asf?p=incubator-cordova-ios.git;a=blob;f=guides/Cordova+Plugin+Upgrade+Guide.md;h=e0e4b3ca8f2e9369da7d6984823e41afcb9b367c;hb=HEAD|Cordova Plugin Upgrade guide]]. iOS has an explicit mapping of JavaScript {{{exec}}} function's {{{service}}} plugin labels to iOS class names in the [[http://git-wip-us.apache.org/repos/asf?p=incubator-cordova-ios.git;a=blob;f=Cordova-based+Application/Cordova.plist;h=eaf4824f3b5627637ed8715e9603b76b688d5883;hb=HEAD|Cordova.plist file]]. {{{exec}}}'s {{{service}}} parameter maps directly to methods implemented in the CDVPlugin.
+   * Android: The [[http://git-wip-us.apache.org/repos/asf?p=incubator-cordova-android.git;a=blob;f=framework/src/org/apache/cordova/api/Plugin.java;h=648e86d6c3eb9a0c62726cc9d238dcb4c19ccd54;hb=HEAD|Plugin]] interface. Android maps JavaScript {{{exec}}} {{{service}}} labels to Android Plugin classes using the [[http://git-wip-us.apache.org/repos/asf?p=incubator-cordova-android.git;a=blob;f=framework/res/xml/plugins.xml;h=ce978fb48b9b171283739e057b58226924ccf75b;hb=HEAD|plugins.xml file]]. The Plugin class' {{{execute}}} [[http://git-wip-us.apache.org/repos/asf?p=incubator-cordova-android.git;a=blob;f=framework/src/org/apache/cordova/api/Plugin.java;h=648e86d6c3eb9a0c62726cc9d238dcb4c19ccd54;hb=HEAD#l46|method]] picks up on the {{{service}}} label as a parameter.
+   * WP7: The [[https://github.com/apache/incubator-cordova-wp7/blob/master/framework/Cordova/Commands/BaseCommand.cs|BaseCommand]]. BaseCommands are created by reflecting on assemblies at runtime (thus lazily loaded) and mapping the {{{service}}} parameter directly to the class name. Similarly the {{{action}}} label maps directly to the method name.
+   * BlackBerry: Identical to Android's implementation. There is a [[https://github.com/apache/incubator-cordova-blackberry-webworks/blob/master/framework/ext/src/org/apache/cordova/api/Plugin.java|Plugin]] class. A [[https://github.com/apache/incubator-cordova-blackberry-webworks/blob/master/template/project/www/plugins.xml|plugins.xml]] file maps {{{service}}} labels to class names. The Plugin's {{{execute}}} function should parse the passed-in {{{action}}} label to determine what method to fire on the native plugin.
+   * Playbook: TBD
+   * Bada: TBD
  
  == Tooling ==