Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Add accelerometer demo app.

  • Loading branch information...
commit 1f04d5930b49a4304edfd2e89581dca1255bca38 1 parent a3a7de6
Brian Moore authored
Showing with 4,182 additions and 0 deletions.
  1. +28 −0 accel/Rakefile
  2. +9 −0 accel/app/Accel/accel.erb
  3. +7 −0 accel/app/Accel/accel.rb
  4. +1 −0  accel/app/Accel/accel2.erb
  5. +41 −0 accel/app/Accel/accel_controller.rb
  6. +172 −0 accel/app/Accel/anim.erb
  7. +75 −0 accel/app/Settings/controller.rb
  8. +17 −0 accel/app/Settings/home.bb.erb
  9. +23 −0 accel/app/Settings/home.erb
  10. +32 −0 accel/app/Settings/index.bb.erb
  11. +46 −0 accel/app/Settings/index.erb
  12. +35 −0 accel/app/Settings/login.bb.erb
  13. +31 −0 accel/app/Settings/login.erb
  14. +15 −0 accel/app/Settings/reset.bb.erb
  15. +18 −0 accel/app/Settings/reset.erb
  16. +3 −0  accel/app/Settings/wait.bb.erb
  17. +5 −0 accel/app/Settings/wait.erb
  18. +14 −0 accel/app/application.rb
  19. +108 −0 accel/app/helpers/application_helper.rb
  20. +18 −0 accel/app/helpers/browser_helper.rb
  21. +26 −0 accel/app/index.bb.erb
  22. +31 −0 accel/app/index.erb
  23. +48 −0 accel/app/layout.erb
  24. +11 −0 accel/app/loading.html
  25. +7 −0 accel/app/test/accel_spec.rb
  26. +16 −0 accel/build.yml
  27. 0  accel/extensions/accelerometer/accelerometer.rb
  28. +2 −0  accel/extensions/accelerometer/ext.yml
  29. +9 −0 accel/extensions/accelerometer/ext/Accel.h
  30. +36 −0 accel/extensions/accelerometer/ext/Accel.m
  31. +116 −0 accel/extensions/accelerometer/ext/Rakefile
  32. +7 −0 accel/extensions/accelerometer/ext/accelerometer.i
  33. +1,880 −0 accel/extensions/accelerometer/ext/accelerometer_wrap.c
  34. +3 −0  accel/extensions/accelerometer/ext/build
  35. +1 −0  accel/extensions/accelerometer/ext/build.bat
  36. BIN  accel/icon/icon.ico
  37. BIN  accel/icon/icon.png
  38. +296 −0 accel/public/css/android.css
  39. +115 −0 accel/public/css/blackberry.css
  40. +382 −0 accel/public/css/iphone.css
  41. +41 −0 accel/public/css/webkit.css
  42. +212 −0 accel/public/css/windows_mobile.css
  43. +21 −0 accel/public/images/IUI_LICENSE.txt
  44. BIN  accel/public/images/android/btn_check_off.png
  45. BIN  accel/public/images/android/btn_check_on.png
  46. BIN  accel/public/images/android/btn_radio_off.png
  47. BIN  accel/public/images/android/btn_radio_on.png
  48. BIN  accel/public/images/android/disclosure.png
  49. BIN  accel/public/images/android/ic_menu_more.png
  50. BIN  accel/public/images/backButton.png
  51. BIN  accel/public/images/blueButton.png
  52. BIN  accel/public/images/cancel.png
  53. BIN  accel/public/images/grayButton.png
  54. BIN  accel/public/images/iphone/disclosure.png
  55. BIN  accel/public/images/iphone/disclosure_detail.png
  56. BIN  accel/public/images/iphone/radiobutton.png
  57. BIN  accel/public/images/iphone/select.png
  58. BIN  accel/public/images/iphone/switch.png
  59. BIN  accel/public/images/iui-logo-touch-icon.png
  60. BIN  accel/public/images/listArrow.png
  61. BIN  accel/public/images/listArrowDown.png
  62. BIN  accel/public/images/listArrowSel.png
  63. BIN  accel/public/images/listGroup.png
  64. BIN  accel/public/images/loading.gif
  65. BIN  accel/public/images/pinstripes.png
  66. BIN  accel/public/images/right_button.png
  67. BIN  accel/public/images/selection.png
  68. BIN  accel/public/images/thumb.png
  69. BIN  accel/public/images/toggle.png
  70. BIN  accel/public/images/toggleOn.png
  71. BIN  accel/public/images/toolButton.png
  72. BIN  accel/public/images/toolButton_new.png
  73. BIN  accel/public/images/toolbar.png
  74. BIN  accel/public/images/whiteButton.png
  75. +1 −0  accel/public/js/application.js
  76. +1 −0  accel/public/js/processing.init.js
  77. +122 −0 accel/public/js/processing.js
  78. +4 −0 accel/public/js/rho.js
  79. +59 −0 accel/public/js/rhogeolocation-wm.js
  80. +11 −0 accel/public/js/rhogeolocation.js
  81. +26 −0 accel/rhoconfig.txt
View
28 accel/Rakefile
@@ -0,0 +1,28 @@
+require 'yaml'
+
+unless File.exists? "build.yml"
+ puts "Cannot find build.yml"
+ exit 1
+end
+
+
+$app_config = YAML::load_file("build.yml")
+$app_path = File.expand_path(File.dirname(__FILE__))
+
+if ENV["RHO_HOME"].nil?
+ rakefilepath = "#{$app_config["sdk"]}/Rakefile"
+else
+ rakefilepath = "#{ENV["RHO_HOME"]}/Rakefile"
+end
+
+unless File.exists? rakefilepath
+ puts "\nCannot find your Rhodes gem or source path."
+ puts "\nIf you have the sdk on your path or have installed the gem this"
+ puts "can be resolved by running 'set-rhodes-sdk'"
+ puts "\nYou can also set this manually by modifying your build.yml or"
+ puts "setting the environment variable RHO_HOME"
+ exit 1
+end
+
+load rakefilepath
+
View
9 accel/app/Accel/accel.erb
@@ -0,0 +1,9 @@
+<li>
+ <span class="title">X: <%= @readings[0] %></span>
+</li>
+<li>
+ <span class="title">Y: <%= @readings[1] %></span>
+</li>
+<li>
+ <span class="title">Z: <%= @readings[2] %></span>
+</li>
View
7 accel/app/Accel/accel.rb
@@ -0,0 +1,7 @@
+# The model has already been created by the framework, and extends Rhom::RhomObject
+# You can add more methods here
+class Accel
+ include Rhom::PropertyBag
+
+ #add model specifc code here
+end
View
1  accel/app/Accel/accel2.erb
@@ -0,0 +1 @@
+<%= Math.atan2 @readings[0],@readings[1] %>,<%= Math.atan2 @readings[0],@readings[2] %>,<%= Math.atan2 @readings[1],@readings[2] %>
View
41 accel/app/Accel/accel_controller.rb
@@ -0,0 +1,41 @@
+require 'rho/rhocontroller'
+require 'helpers/browser_helper'
+
+class AccelController < Rho::RhoController
+ include BrowserHelper
+
+ def accel
+ @readings = Accelerometer.get_readings
+ end
+
+ def accel2
+ @readings = Accelerometer.get_readings
+
+ $rollx = ($rollx + @readings[0]) / 2
+ $rolly = ($rolly + @readings[1]) / 2
+ $rollz = ($rollz + @readings[2]) / 2
+
+ @readings[0] = $rollx
+ @readings[1] = $rolly
+ @readings[2] = $rollz
+
+ @readings[0] = -1.0 if @readings[0] < -1.0
+ @readings[1] = -1.0 if @readings[1] < -1.0
+ @readings[2] = -1.0 if @readings[2] < -1.0
+
+ @readings[0] = 1.0 if @readings[0] > 1.0
+ @readings[1] = 1.0 if @readings[1] > 1.0
+ @readings[2] = 1.0 if @readings[2] > 1.0
+
+ render :layout => false
+ end
+
+ def anim
+ $filter = 0.1;
+ $rollx = 0.0;
+ $rolly = 0.0;
+ $rollz = 0.0;
+ render :layout => false
+ end
+
+end
View
172 accel/app/Accel/anim.erb
@@ -0,0 +1,172 @@
+<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
+ "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
+<html xmlns="http://www.w3.org/1999/xhtml">
+ <head>
+ <title>Accel</title>
+<meta name="viewport" content="width=device-width; initial-scale=1.0; maximum-scale=1.0; user-scalable=0;"/>
+
+ <script language="javascript" src="/public/js/processing.init.js"></script>
+ <script language="javascript" src="/public/js/processing.js"></script>
+
+ </head>
+ <body style="margin: 0px; padding: 0px; border:0px; overflow-x:hidden; overflow-y:hidden;">
+<script type="application/processing">
+
+float getx(v) {
+ return midx + (v[0] * zscale / (v[2] + zscale));
+}
+
+float gety(v) {
+ return midx + (v[1] * zscale / (v[2] + zscale));
+}
+
+function rotz(v,theta) {
+ vt = [0,0,0];
+ vt[0] = (v[0] * Math.cos(theta)) + (v[1] * -1 * Math.sin(theta));
+ vt[1] = (v[0] * Math.sin(theta)) + (v[1] * Math.cos(theta));
+ vt[2] = v[2];
+ return vt
+}
+
+function roty(v,theta) {
+ vt = [0,0,0];
+ vt[0] = (v[0] * Math.cos(theta)) + (v[2] * Math.sin(theta));
+ vt[1] = v[1];
+ vt[2] = (v[0] * -1 * Math.sin(theta)) + (v[2] * Math.cos(theta));
+ return vt
+}
+
+function rotx(v,theta) {
+ vt = [0,0,0];
+ vt[0] = v[0];
+ vt[1] = (v[1] * Math.cos(theta)) + (v[2] * -1 * Math.sin(theta));
+ vt[2] = (v[1] * Math.sin(theta)) + (v[2] * Math.cos(theta));
+ return vt
+}
+
+
+// Global variables
+float radius = 50.0;
+int X, Y;
+int nX, nY;
+int delay = 16;
+int zscale = 500;
+int width = 320;
+int height = 420;
+int midx = width/2;
+int midy = height/2;
+float rx, ry, rz;
+float z = 0;
+
+ov1 = rotx([-50,-50,-10],-1.57079633);
+ov2 = rotx([-50,50,-10],-1.57079633);
+ov3 = rotx([50,50,-10],-1.57079633);
+ov4 = rotx([50,-50,-10],-1.57079633);
+ov5 = rotx([-50,-50,10],-1.57079633);
+ov6 = rotx([-50,50,10],-1.57079633);
+ov7 = rotx([50,50,10],-1.57079633);
+ov8 = rotx([50,-50,10],-1.57079633);
+
+v1 = ov1;
+v2 = ov2;
+v3 = ov3;
+v4 = ov4;
+v5 = ov5;
+v6 = ov6;
+v7 = ov7;
+v8 = ov8;
+
+//gets accel data
+function getRotation(url)
+{
+ if (window.XMLHttpRequest)
+ {// code for IE7+, Firefox, Chrome, Opera, Safari
+ xmlhttp=new XMLHttpRequest();
+
+ xmlhttp.open("GET",url,false);
+ xmlhttp.send(null);
+ if (xmlhttp.responseText != null)
+ {
+ points_ary = xmlhttp.responseText.split(',');
+ rz = points_ary[0] * -1;
+ ry = points_ary[1];
+ rx = points_ary[2] * -1;
+ }
+ }
+}
+// Setup the Processing Canvas
+void setup(){
+ size( width, height );
+ strokeWeight( 2 );
+ frameRate( 15 );
+ X = width / 2;
+ Y = width / 2;
+ nX = X;
+ nY = Y;
+ rx = 0.0;
+ ry = 0.0;
+ rz = 0.0;
+ setInterval(function() {getRotation('accel2');},50);
+}
+
+
+
+// Main draw loop
+void draw(){
+ zv1 = rotz(ov1,rz);
+ zv2 = rotz(ov2,rz);
+ zv3 = rotz(ov3,rz);
+ zv4 = rotz(ov4,rz);
+ zv5 = rotz(ov5,rz);
+ zv6 = rotz(ov6,rz);
+ zv7 = rotz(ov7,rz);
+ zv8 = rotz(ov8,rz);
+
+ xv1 = rotx(zv1,rx);
+ xv2 = rotx(zv2,rx);
+ xv3 = rotx(zv3,rx);
+ xv4 = rotx(zv4,rx);
+ xv5 = rotx(zv5,rx);
+ xv6 = rotx(zv6,rx);
+ xv7 = rotx(zv7,rx);
+ xv8 = rotx(zv8,rx);
+
+ v1 = roty(xv1,ry);
+ v2 = roty(xv2,ry);
+ v3 = roty(xv3,ry);
+ v4 = roty(xv4,ry);
+ v5 = roty(xv5,ry);
+ v6 = roty(xv6,ry);
+ v7 = roty(xv7,ry);
+ v8 = roty(xv8,ry);
+
+ // Fill canvas grey
+ background( 100 );
+
+ // Set stroke-color white
+
+ stroke(255);
+ line (getx(v4),gety(v4),getx(v8),gety(v8));
+ line (getx(v5),gety(v5),getx(v8),gety(v8));
+ line (getx(v5),gety(v5),getx(v6),gety(v6));
+ line (getx(v6),gety(v6),getx(v7),gety(v7));
+ line (getx(v7),gety(v7),getx(v8),gety(v8));
+ line (getx(v3),gety(v3),getx(v7),gety(v7));
+ line (getx(v1),gety(v1),getx(v5),gety(v5));
+ line (getx(v2),gety(v2),getx(v6),gety(v6));
+
+ stroke(255,0,0);
+
+ line (getx(v1),gety(v1),getx(v2),gety(v2));
+ line (getx(v1),gety(v1),getx(v4),gety(v4));
+ line (getx(v2),gety(v2),getx(v3),gety(v3));
+ line (getx(v3),gety(v3),getx(v4),gety(v4));
+}
+// Set circle's next destination
+void mouseMoved(){
+ nX = mouseX;
+ nY = mouseY;
+}
+</script><canvas width="240px" height="400px" style="margin: 0px; padding: 0px; border:0px;"></canvas>
+ </body>
+</html>
View
75 accel/app/Settings/controller.rb
@@ -0,0 +1,75 @@
+require 'rho'
+require 'rho/rhocontroller'
+require 'rho/rhoerror'
+require 'helpers/browser_helper'
+
+class SettingsController < Rho::RhoController
+ include BrowserHelper
+
+ def index
+ @msg = @params['msg']
+ render
+ end
+
+ def login
+ @msg = @params['msg']
+ render :action => :login, :back => '/app'
+ end
+
+ def login_callback
+ errCode = @params['error_code'].to_i
+ if errCode == 0
+ # run sync if we were successful
+ WebView.navigate Rho::RhoConfig.options_path
+ SyncEngine.dosync
+ else
+ if errCode == Rho::RhoError::ERR_CUSTOMSYNCSERVER
+ @msg = @params['error_message']
+ end
+
+ if !@msg || @msg.length == 0
+ @msg = Rho::RhoError.new(errCode).message
+ end
+
+ WebView.navigate ( url_for :action => :login, :query => {:msg => @msg} )
+ end
+ end
+
+ def do_login
+ if @params['login'] and @params['password']
+ begin
+ SyncEngine.login(@params['login'], @params['password'], (url_for :action => :login_callback) )
+ render :action => :wait
+ rescue Rho::RhoError => e
+ @msg = e.message
+ render :action => :login
+ end
+ else
+ @msg = Rho::RhoError.err_message(Rho::RhoError::ERR_UNATHORIZED) unless @msg && @msg.length > 0
+ render :action => :login
+ end
+ end
+
+ def logout
+ SyncEngine.logout
+ @msg = "You have been logged out."
+ render :action => :login
+ end
+
+ def reset
+ render :action => :reset
+ end
+
+ def do_reset
+ Rhom::Rhom.database_full_reset
+ SyncEngine.dosync
+ @msg = "Database has been reset."
+ redirect :action => :index, :query => {:msg => @msg}
+ end
+
+ def do_sync
+ SyncEngine.dosync
+ @msg = "Sync has been triggered."
+ redirect :action => :index, :query => {:msg => @msg}
+ end
+end
View
17 accel/app/Settings/home.bb.erb
@@ -0,0 +1,17 @@
+<div id="pageTitle">
+ <h1>Home</h1>
+</div>
+
+<div id="toolbar">
+ <% if SyncEngine::logged_in > 0 %>
+ <%= link_to "Logout", :action => :logout %>
+ <% else %>
+ <%= link_to "Login", :action => :login %>
+ <% end %>
+</div>
+
+<div id="content">
+ <ul>
+ <li>Add links here...</li>
+ </ul>
+</div>
View
23 accel/app/Settings/home.erb
@@ -0,0 +1,23 @@
+<div id="pageTitle">>
+ <h1>Home</h1>
+</div>
+
+<div id="toolbar">
+ <div id="leftItem" class="blueButton"><%%= link_to "Sync", :action => :do_sync %></div>
+ <%% if SyncEngine::logged_in > 0 %>
+ <div id="rightItem" class="regularButton"><%%= link_to "Logout", :action => :logout %></div>
+ <%% else %>
+ <div id="rightItem" class="regularButton"><%%= link_to "Login", :action => :login %></div>
+ <%% end %>
+</div>
+
+<div id="content">
+ <ul>
+ <li>
+ <a href="#">
+ <span class="title">Add Links Here...</span>
+ <span class="disclosure_indicator"></span>
+ </a>
+ </li>
+ </ul>
+</div>
View
32 accel/app/Settings/index.bb.erb
@@ -0,0 +1,32 @@
+<div id="pageTitle">
+ <h1>Settings</h1>
+</div>
+
+<div id="content">
+ <% if @msg %>
+ <div class="alert" align="center"><%= @msg %></div>
+ <% end %>
+
+ <ul>
+ <li>
+ <p>Client ID: <span class="cid"><%= Rhom::Rhom::client_id %></span></p>
+ </li>
+ <li>
+ <%= link_to "Reset Database", :action => :reset %>
+ </li>
+ <li>
+ <%= link_to "Sync", :action => :do_sync %>
+ </li>
+
+ <% if SyncEngine::logged_in > 0 %>
+ <li>
+ <%= link_to "Logout", :action => :logout %>
+ </li>
+ <% else %>
+ <li>
+ <%= link_to "Login", :action => :login %>
+ </li>
+ <% end %>
+ </ul>
+
+</div>
View
46 accel/app/Settings/index.erb
@@ -0,0 +1,46 @@
+<div id="pageTitle">
+ <h1>Settings</h1>
+</div>
+
+<div id="toolbar"></div>
+
+<div id="content">
+ <ul id="settings">
+ <% if @msg %>
+ <li class="alertMessage">
+ <span class="message"><%= @msg %></span>
+ </li>
+ <% end %>
+ <li>
+ <div class="itemLabel">
+ <span class="title">Client ID:</span>
+ </div>
+ <div class="itemValue">
+ <span class="clientID"><%= Rhom::Rhom::client_id %></span>
+ </div>
+ </li>
+ <li>
+ <a href="<%= url_for :action => :reset %>">
+ <span class="title">Reset Database</span>
+ </a>
+ </li>
+ <li>
+ <a href="<%= url_for :action => :do_sync %>">
+ <span class="title">Perform Sync</span>
+ </a>
+ </li>
+ <% if SyncEngine::logged_in > 0 %>
+ <li>
+ <a href="<%= url_for :action => :logout %>">
+ <span class="title">Logout</span>
+ </a>
+ </li>
+ <% else %>
+ <li>
+ <a href="<%= url_for :action => :login %>">
+ <span class="title">Login</span>
+ </a>
+ </li>
+ <% end %>
+ </ul>
+</div>
View
35 accel/app/Settings/login.bb.erb
@@ -0,0 +1,35 @@
+<div id="pageTitle">
+ <h1>Login</h1>
+</div>
+
+<div id="toolbar">
+ <%= link_to "Back", :action => :index %>
+</div>
+
+<div id="content">
+ <form method="POST" action="<%= url_for :action => :do_login %>">
+
+ <% if @msg %>
+ <div class="alert" align="center"><%= @msg %></div>
+ <% end %>
+
+ <table>
+
+ <tr>
+ <td width="125" class="fieldLabel">Login</td>
+ <td><input type="text" maxlength="100" name="login"/></td>
+ </tr>
+
+ <tr>
+ <td width="125" class="fieldLabel">Password</td>
+ <td><input type="password" maxlength="100" name="password"/></td>
+ </tr>
+ </table>
+
+ <input type="submit" class="standardButton" value="Login" />
+ </form>
+</div>
+
+
+
+
View
31 accel/app/Settings/login.erb
@@ -0,0 +1,31 @@
+<div id="pageTitle">
+ <h1>Login</h1>
+</div>
+
+
+<div id="toolbar">
+ <div id="leftItem" class="regularButton"><%= link_to "Cancel", :action => :index %></div>
+</div>
+
+
+
+<div id="content">
+ <form method="POST" action="<%= url_for :action => :do_login %>">
+
+ <% if @msg %>
+ <p style="color:#ff0000"><%= @msg %></p>
+ <% end %>
+ <ul>
+ <li>
+ <label for="login" class="fieldLabel">Login</label>
+ <input type="text" name="login" <%= placeholder( "Login" ) %> />
+ </li>
+
+ <li>
+ <label for="password" class="fieldLabel">Password</label>
+ <input type="password" name="password" <%= placeholder( "Password" ) %> />
+ </li>
+ </ul>
+ <input type="submit" class="standardButton" value="Login" />
+ </form>
+</div>
View
15 accel/app/Settings/reset.bb.erb
@@ -0,0 +1,15 @@
+<div id="pageTitle">
+ <h1>Reset Database</h1>
+</div>
+
+<div id="toolbar">
+ <%= link_to "Confirm", :action => :do_reset %>
+ <%= link_to "Cancel", Rho::RhoConfig.options_path %>
+</div>
+
+<div id="content">
+ <div class="warning">
+ <h2>Are you sure?</h2>
+ <p> Resetting removes all objects from your device.</p>
+ </div>
+</div>
View
18 accel/app/Settings/reset.erb
@@ -0,0 +1,18 @@
+<div id="pageTitle">
+ <h1>Reset Database</h1>
+</div>
+
+
+
+<div id="toolbar">
+ <div id="leftItem" class="regularButton"><%= link_to "Cancel", :action => :index %></div>
+ <div id="rightItem" class="blueButton"><%= link_to "Confirm", :action => :do_reset %></div>
+</div>
+
+
+<div id="content">
+ <div id="reset">
+ <h4>Are you sure?<br/>
+ Resetting removes all objects from your device.</h4>
+ </div>
+</div>
View
3  accel/app/Settings/wait.bb.erb
@@ -0,0 +1,3 @@
+<div id="pageTitle">
+ <h1>Wait</h1>
+</div>
View
5 accel/app/Settings/wait.erb
@@ -0,0 +1,5 @@
+<div id="pageTitle">
+ <h1>Wait</h1>
+</div>
+
+<div id="toolbar"></div>
View
14 accel/app/application.rb
@@ -0,0 +1,14 @@
+require 'rho/rhoapplication'
+
+class AppApplication < Rho::RhoApplication
+ def initialize
+ # Tab items are loaded left->right, @tabs[0] is leftmost tab in the tab-bar
+ @tabs = nil
+
+ @@tabbar = nil
+ # Important to call super _after_ you define @tabs!
+
+ Accelerometer.start
+ super
+ end
+end
View
108 accel/app/helpers/application_helper.rb
@@ -0,0 +1,108 @@
+module ApplicationHelper
+ def strip_braces(str=nil)
+ str ? str.gsub(/\{/,"").gsub(/\}/,"") : nil
+ end
+
+ def strike_if(str, condition=true)
+ condition ? "<s>#{str}</s>" : str
+ end
+
+ def display_blanks(value)
+ if blank?(value)
+ "---"
+ else
+ value
+ end
+ end
+
+ def blank?(value)
+ value.nil? || value == "" || value.length==0
+ end
+
+ def display_blankstr(value)
+ if blank?(value)
+ " "
+ else
+ value
+ end
+ end
+
+ def display_newline()
+ "<br>"
+ end
+
+ def display_space()
+ " "
+ end
+
+ def display_dollars(value)
+ if blank?(value)
+ " "
+ else
+ number = "$" + sprintf("%.2f", value)
+
+ # use a commify algorithm -- http://snippets.dzone.com/tag/commify
+ number.reverse!
+ number.gsub!(/(\d\d\d)(?=\d)(?!\d*\.)/, '\1,')
+ number.reverse!
+ end
+ end
+
+ def display_number(value)
+ if blank?(value)
+ " "
+ else
+ sprintf("%.2f", value)
+ end
+ end
+
+ def both_items_present?(value1, value2)
+ !blank?(value1) && !blank?(value2)
+ end
+
+ def replace_newlines(value)
+ if blank?(value)
+ " "
+ else
+ value.gsub('\n', ' ')
+ end
+ end
+
+ def format_address_for_mapping(street, city, state, zip, tagforurl)
+ # handle case where fields could be nil
+ mystreet = !street.nil? ? street : ""
+ mycity = !city.nil? ? city : ""
+ mystate = !state.nil? ? state : ""
+ myzip = !zip.nil? ? zip : ""
+
+ result = ""
+ if !tagforurl
+ # build up address string
+ result += (mystreet + ", ") if mystreet.length > 0
+ result += (mycity + ", ") if mycity.length > 0
+ result += (mystate + " ") if mystate.length > 0
+ result += myzip if myzip.length > 0
+ else
+ # need to URL encode data too
+ result += ("&street=" + Rho::RhoSupport.url_encode(mystreet)) if mystreet.length > 0
+ result += ("&city=" + Rho::RhoSupport.url_encode(mycity)) if mycity.length > 0
+ result += ("&state=" + Rho::RhoSupport.url_encode(mystate)) if mystate.length > 0
+ result += ("&zip=" + Rho::RhoSupport.url_encode(myzip)) if myzip.length > 0
+ end
+ # remove any extraneous characters that could interfere with proper address matching
+ result = replace_newlines(result)
+ end
+
+ def has_valid_mapping_address(street, city, state, zip)
+ # at a minimum, an address must have a state or a zip
+ (!state.nil? && state.length > 0) || (!zip.nil? && zip.length > 0)
+ end
+
+ def format_latlon_for_mapping(latitude, longitude)
+ result = ""
+ result += ("&latitude=" + Rho::RhoSupport.url_encode(latitude)) if latitude.length > 0
+ result += ("&longitude=" + Rho::RhoSupport.url_encode(longitude)) if longitude.length > 0
+ result
+ end
+
+end
View
18 accel/app/helpers/browser_helper.rb
@@ -0,0 +1,18 @@
+module BrowserHelper
+
+ def placeholder(label=nil)
+ "placeholder='#{label}'" if platform == 'apple'
+ end
+
+ def platform
+ System::get_property('platform').downcase
+ end
+
+ def selected(option_value,object_value)
+ "selected=\"yes\"" if option_value == object_value
+ end
+
+ def checked(option_value,object_value)
+ "checked=\"yes\"" if option_value == object_value
+ end
+end
View
26 accel/app/index.bb.erb
@@ -0,0 +1,26 @@
+<div id="pageTitle">
+ <h1>Accel</h1>
+</div>
+
+<div id="toolbar">
+ <%= link_to "Sync", :controller => :Settings, :action => :do_sync %>
+ <% if SyncEngine::logged_in > 0 %>
+ <%= link_to "Logout", :controller => :Settings, :action => :logout %>
+ <% else %>
+ <%= link_to "Login", :controller => :Settings, :action => :login %>
+ <% end %>
+</div>
+
+
+<div id="content">
+ <table>
+ <tr>
+ <td class="recordLabel">Add links here...</td>
+ </tr>
+ </table>
+</div>
+
+
+
+
+
View
31 accel/app/index.erb
@@ -0,0 +1,31 @@
+<div id="pageTitle">
+ <h1>Accel</h1>
+</div>
+
+<div id="toolbar">
+ <div id="leftItem" class="blueButton"><%= link_to "Sync", :controller => :Settings, :action => :do_sync %></div>
+ <% if SyncEngine::logged_in > 0 %>
+ <div id="rightItem" class="regularButton"><%= link_to "Logout", :controller => :Settings, :action => :logout %></div>
+ <% else %>
+ <div id="rightItem" class="regularButton"><%= link_to "Login", :controller => :Settings, :action => :login %></div>
+ <% end %>
+</div>
+
+<div id="content">
+ <ul>
+ <li>
+ <div onclick="setInterval(function(){loadXMLDoc('<%= url_for :controller => :Accel , :action => :accel %>','readings');},250);">
+ <span class="title">Go</span>
+ <span class="disclosure_indicator"></span>
+ </div>
+ </li>
+ <li>
+ <a href="<%= url_for :controller => :Accel , :action => :anim %>">
+ <span class="title">Draw</span>
+ <span class="disclosure_indicator"></span>
+ </a>
+ </li>
+ <div id="readings">
+ </div>
+ </ul>
+</div>
View
48 accel/app/layout.erb
@@ -0,0 +1,48 @@
+<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
+ "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
+<html xmlns="http://www.w3.org/1999/xhtml">
+ <head>
+ <title>Accel</title>
+
+ <% if System::get_property('platform') == 'APPLE' %>
+ <meta name="viewport" content="width=device-width; initial-scale=1.0; maximum-scale=1.0; user-scalable=0;"/>
+ <link href="/public/css/webkit.css" type="text/css" rel="stylesheet"/>
+ <link href="/public/css/iphone.css" type="text/css" rel="stylesheet"/>
+ <% elsif System::get_property('platform') == 'Blackberry' %>
+ <link href="/public/css/blackberry.css" type="text/css" rel="stylesheet"/>
+ <% elsif System::get_property('platform') == 'ANDROID' %>
+ <link href="/public/css/webkit.css" type="text/css" rel="stylesheet"/>
+ <link href="/public/css/android.css" type="text/css" rel="stylesheet"/>
+ <% else %>
+ <link href="/public/css/windows_mobile.css" type="text/css" rel="stylesheet"/>
+ <% end %>
+
+
+ <script type="text/javascript">
+
+ function loadXMLDoc(url,id)
+ {
+ if (window.XMLHttpRequest)
+ {// code for IE7+, Firefox, Chrome, Opera, Safari
+ xmlhttp=new XMLHttpRequest();
+
+ xmlhttp.open("GET",url,false);
+ xmlhttp.send(null);
+ if (xmlhttp.responseText != null)
+ {
+ element = document.getElementById(id);
+ if (element != null)
+ {
+ element.innerHTML=xmlhttp.responseText;
+ }
+ }
+ }
+ }
+ </script>
+ <script language="javascript" src="/public/js/processing.init.js"></script>
+ <script language="javascript" src="/public/js/processing.js"></script>
+ </head>
+ <body>
+ <%= @content %>
+ </body>
+</html>
View
11 accel/app/loading.html
@@ -0,0 +1,11 @@
+<html>
+ <head>
+ <title>Home</title>
+ <meta name="viewport" content="initial-scale=1.0, width=device-width"/>
+ </head>
+ <body>
+ <div align="center">
+ <h3>Loading...</h3>
+ </div>
+ </body>
+</html>
View
7 accel/app/test/accel_spec.rb
@@ -0,0 +1,7 @@
+describe "Accel" do
+ #this test always fails, you really should have tests!
+
+ it "should have tests" do
+ true.should == false
+ end
+end
View
16 accel/build.yml
@@ -0,0 +1,16 @@
+sdk: "/Library/Ruby/Gems/1.8/gems/rhodes-2.0.0"
+sdkversion: 2.0.0
+name: accel
+version: 1.0
+vendor: rhomobile
+build: debug
+bbver: 4.6
+wmsdk: "Windows Mobile 6 Professional SDK (ARMV4I)"
+applog: rholog.txt
+iphone:
+ configuration: Debug
+ sdk: iphonesimulator4.0
+ provisionprofile:
+ codesignidentity:
+ entitlements:
+extensions: ["accelerometer"]
View
0  accel/extensions/accelerometer/accelerometer.rb
No changes.
View
2  accel/extensions/accelerometer/ext.yml
@@ -0,0 +1,2 @@
+entry: Init_Accelerometer
+libraries: [ "accelerometer" ]
View
9 accel/extensions/accelerometer/ext/Accel.h
@@ -0,0 +1,9 @@
+#import <UIKit/UIKit.h>
+
+@interface Accel : UIViewController<UIAccelerometerDelegate>
+{
+}
+
+- (void)start;
+
+@end
View
36 accel/extensions/accelerometer/ext/Accel.m
@@ -0,0 +1,36 @@
+#import "accel.h"
+
+double gx,gy,gz;
+Accel *accel;
+@implementation Accel
+
+-(void)start
+{
+ gx = gy = gz = 0;
+ [[UIAccelerometer sharedAccelerometer] setUpdateInterval:0.025];
+ [[UIAccelerometer sharedAccelerometer] setDelegate:self];
+}
+
+-(void)accelerometer:(UIAccelerometer *)accelerometer didAccelerate:(UIAcceleration *)acceleration
+{
+ gx = acceleration.x;
+ gy = acceleration.y;
+ gz = acceleration.z;
+}
+
+@end
+
+void start(void) {
+ static bool started = false;
+ if(!started) {
+ accel = [[Accel alloc] init];
+ [accel start];
+ started = true;
+ }
+}
+
+void get_readings(double *x, double *y, double *z) {
+ *x = gx;
+ *y = gy;
+ *z = gz;
+}
View
116 accel/extensions/accelerometer/ext/Rakefile
@@ -0,0 +1,116 @@
+require 'fileutils'
+
+def build_extension(name, arch)
+ objects = []
+ mkdir_p $tempdir unless File.exists? $tempdir
+
+ Dir.glob("*.o").each { |f| rm_rf f }
+ Dir.glob("*.a").each { |f| rm_rf f }
+ rm_rf "accelerometer_wrap.c"
+
+ #swig
+ Dir.glob("*.i").each do |f|
+ puts "swig -ruby #{f}"
+ puts `swig -ruby #{f}`
+ end
+
+ Dir.glob("*.c").each do |f|
+ objname = File.join( $tempdir, File.basename( f.gsub(/\.c$/, '.o') ) )
+ objects << objname
+
+ args = []
+ args << "-I."
+ args << "-I#{$rootdir}/platform/shared/ruby/include"
+ args << "-I#{$rootdir}/platform/shared"
+
+ if ENV['RHO_PLATFORM'] == 'android'
+ elsif ENV['RHO_PLATFORM'] == 'iphone'
+ args << "-I#{$rootdir}/platform/shared/ruby/iphone"
+ args << "-D_XOPEN_SOURCE"
+ args << "-D_DARWIN_C_SOURCE"
+ args << "-isysroot #{$sdkroot}"
+ args << "-fno-common"
+ args << "-arch #{arch}"
+ args << "-O2"
+ args << "-o #{objname}"
+ args << "-c"
+ args << f
+ cmdline = $gccbin + ' ' + args.join(' ')
+ puts cmdline
+ puts `#{cmdline}`
+ exit unless $? == 0
+ end
+ end
+
+ #compile M files if iphone
+ if ENV['RHO_PLATFORM'] == 'iphone'
+ Dir.glob("*.m").each do |f|
+ objname = File.join( $tempdir, File.basename( f.gsub(/\.m$/, '.o') ) )
+ objects << objname
+
+ args = []
+ args << "-x objective-c"
+ args << "-arch #{arch}"
+ args << "-pipe -std=c99 -Wno-trigraphs -fpascal-strings -O0 -Wreturn-type -Wunused-variable"
+ args << "-isysroot #{$sdkroot}"
+ args << "-D__IPHONE_OS_VERSION_MIN_REQUIRED=30200 "
+ args << "-fvisibility=hidden -mmacosx-version-min=10.6 -gdwarf-2 -fobjc-abi-version=2 -fobjc-legacy-dispatch"
+ args << "-I."
+ args << "-o #{objname}"
+ args << "-c"
+ args << f
+ cmdline = $gccbin + ' ' + args.join(' ')
+ puts cmdline
+ puts `#{cmdline}`
+ exit unless $? == 0
+ end
+ end
+
+ mkdir_p $targetdir unless File.exist? $targetdir
+
+ if ENV['RHO_PLATFORM'] == 'android'
+ elsif ENV['RHO_PLATFORM'] == 'iphone'
+ args = []
+ args << 'rcs'
+ args << File.join( $targetdir, 'lib' + name + '.a' )
+ args += objects
+ cmdline = $arbin + ' ' + args.join(' ')
+ puts cmdline
+ puts `#{cmdline}`
+ exit unless $? == 0
+
+ elsif ENV['RHO_PLATFORM'] == 'wm'
+ end
+
+end
+
+namespace "build" do
+ task :config do
+ $targetdir = ENV['TARGET_TEMP_DIR']
+ raise "TARGET_TEMP_DIR is not set" if $targetdir.nil?
+ $tempdir = ENV['TEMP_FILES_DIR']
+ raise "TEMP_FILES_DIR is not set" if $tempdir.nil?
+ $rootdir = ENV['RHO_ROOT']
+ raise "RHO_ROOT is not set" if $rootdir.nil?
+
+ if ENV['RHO_PLATFORM'] == 'android'
+ elsif ENV['RHO_PLATFORM'] == 'wm'
+ elsif ENV['RHO_PLATFORM'] == 'iphone'
+ $bindir = ENV['PLATFORM_DEVELOPER_BIN_DIR']
+ raise "PLATFORM_DEVELOPER_BIN_DIR is not set" if $bindir.nil?
+ $sdkroot = ENV['SDKROOT']
+ raise "SDKROOT is not set" if $sdkroot.nil?
+ $arch = ENV['ARCHS']
+ raise "ARCHS is not set" if $arch.nil?
+ $gccbin = $bindir + '/gcc-4.2'
+ $arbin = $bindir + '/ar'
+ end
+
+ end
+
+ task :all => :config do
+ build_extension('accelerometer', $arch)
+ end
+end
+
+task :default => "build:all"
View
7 accel/extensions/accelerometer/ext/accelerometer.i
@@ -0,0 +1,7 @@
+%module Accelerometer
+%{
+extern void get_readings(double *x, double *y, double *z);
+extern void start(void);
+%}
+extern void start(void);
+extern void get_readings(double *OUTPUT, double *OUTPUT, double *OUTPUT);
View
1,880 accel/extensions/accelerometer/ext/accelerometer_wrap.c
@@ -0,0 +1,1880 @@
+/* ----------------------------------------------------------------------------
+ * This file was automatically generated by SWIG (http://www.swig.org).
+ * Version 1.3.31
+ *
+ * This file is not intended to be easily readable and contains a number of
+ * coding conventions designed to improve portability and efficiency. Do not make
+ * changes to this file unless you know what you are doing--modify the SWIG
+ * interface file instead.
+ * ----------------------------------------------------------------------------- */
+
+#define SWIGRUBY
+/* -----------------------------------------------------------------------------
+ * This section contains generic SWIG labels for method/variable
+ * declarations/attributes, and other compiler dependent labels.
+ * ----------------------------------------------------------------------------- */
+
+/* template workaround for compilers that cannot correctly implement the C++ standard */
+#ifndef SWIGTEMPLATEDISAMBIGUATOR
+# if defined(__SUNPRO_CC)
+# if (__SUNPRO_CC <= 0x560)
+# define SWIGTEMPLATEDISAMBIGUATOR template
+# else
+# define SWIGTEMPLATEDISAMBIGUATOR
+# endif
+# else
+# define SWIGTEMPLATEDISAMBIGUATOR
+# endif
+#endif
+
+/* inline attribute */
+#ifndef SWIGINLINE
+# if defined(__cplusplus) || (defined(__GNUC__) && !defined(__STRICT_ANSI__))
+# define SWIGINLINE inline
+# else
+# define SWIGINLINE
+# endif
+#endif
+
+/* attribute recognised by some compilers to avoid 'unused' warnings */
+#ifndef SWIGUNUSED
+# if defined(__GNUC__)
+# if !(defined(__cplusplus)) || (__GNUC__ > 3 || (__GNUC__ == 3 && __GNUC_MINOR__ >= 4))
+# define SWIGUNUSED __attribute__ ((__unused__))
+# else
+# define SWIGUNUSED
+# endif
+# elif defined(__ICC)
+# define SWIGUNUSED __attribute__ ((__unused__))
+# else
+# define SWIGUNUSED
+# endif
+#endif
+
+#ifndef SWIGUNUSEDPARM
+# ifdef __cplusplus
+# define SWIGUNUSEDPARM(p)
+# else
+# define SWIGUNUSEDPARM(p) p SWIGUNUSED
+# endif
+#endif
+
+/* internal SWIG method */
+#ifndef SWIGINTERN
+# define SWIGINTERN static SWIGUNUSED
+#endif
+
+/* internal inline SWIG method */
+#ifndef SWIGINTERNINLINE
+# define SWIGINTERNINLINE SWIGINTERN SWIGINLINE
+#endif
+
+/* exporting methods */
+#if (__GNUC__ >= 4) || (__GNUC__ == 3 && __GNUC_MINOR__ >= 4)
+# ifndef GCC_HASCLASSVISIBILITY
+# define GCC_HASCLASSVISIBILITY
+# endif
+#endif
+
+#ifndef SWIGEXPORT
+# if defined(_WIN32) || defined(__WIN32__) || defined(__CYGWIN__)
+# if defined(STATIC_LINKED)
+# define SWIGEXPORT
+# else
+# define SWIGEXPORT __declspec(dllexport)
+# endif
+# else
+# if defined(__GNUC__) && defined(GCC_HASCLASSVISIBILITY)
+# define SWIGEXPORT __attribute__ ((visibility("default")))
+# else
+# define SWIGEXPORT
+# endif
+# endif
+#endif
+
+/* calling conventions for Windows */
+#ifndef SWIGSTDCALL
+# if defined(_WIN32) || defined(__WIN32__) || defined(__CYGWIN__)
+# define SWIGSTDCALL __stdcall
+# else
+# define SWIGSTDCALL
+# endif
+#endif
+
+/* Deal with Microsoft's attempt at deprecating C standard runtime functions */
+#if !defined(SWIG_NO_CRT_SECURE_NO_DEPRECATE) && defined(_MSC_VER) && !defined(_CRT_SECURE_NO_DEPRECATE)
+# define _CRT_SECURE_NO_DEPRECATE
+#endif
+
+/* -----------------------------------------------------------------------------
+ * This section contains generic SWIG labels for method/variable
+ * declarations/attributes, and other compiler dependent labels.
+ * ----------------------------------------------------------------------------- */
+
+/* template workaround for compilers that cannot correctly implement the C++ standard */
+#ifndef SWIGTEMPLATEDISAMBIGUATOR
+# if defined(__SUNPRO_CC)
+# if (__SUNPRO_CC <= 0x560)
+# define SWIGTEMPLATEDISAMBIGUATOR template
+# else
+# define SWIGTEMPLATEDISAMBIGUATOR
+# endif
+# else
+# define SWIGTEMPLATEDISAMBIGUATOR
+# endif
+#endif
+
+/* inline attribute */
+#ifndef SWIGINLINE
+# if defined(__cplusplus) || (defined(__GNUC__) && !defined(__STRICT_ANSI__))
+# define SWIGINLINE inline
+# else
+# define SWIGINLINE
+# endif
+#endif
+
+/* attribute recognised by some compilers to avoid 'unused' warnings */
+#ifndef SWIGUNUSED
+# if defined(__GNUC__)
+# if !(defined(__cplusplus)) || (__GNUC__ > 3 || (__GNUC__ == 3 && __GNUC_MINOR__ >= 4))
+# define SWIGUNUSED __attribute__ ((__unused__))
+# else
+# define SWIGUNUSED
+# endif
+# elif defined(__ICC)
+# define SWIGUNUSED __attribute__ ((__unused__))
+# else
+# define SWIGUNUSED
+# endif
+#endif
+
+#ifndef SWIGUNUSEDPARM
+# ifdef __cplusplus
+# define SWIGUNUSEDPARM(p)
+# else
+# define SWIGUNUSEDPARM(p) p SWIGUNUSED
+# endif
+#endif
+
+/* internal SWIG method */
+#ifndef SWIGINTERN
+# define SWIGINTERN static SWIGUNUSED
+#endif
+
+/* internal inline SWIG method */
+#ifndef SWIGINTERNINLINE
+# define SWIGINTERNINLINE SWIGINTERN SWIGINLINE
+#endif
+
+/* exporting methods */
+#if (__GNUC__ >= 4) || (__GNUC__ == 3 && __GNUC_MINOR__ >= 4)
+# ifndef GCC_HASCLASSVISIBILITY
+# define GCC_HASCLASSVISIBILITY
+# endif
+#endif
+
+#ifndef SWIGEXPORT
+# if defined(_WIN32) || defined(__WIN32__) || defined(__CYGWIN__)
+# if defined(STATIC_LINKED)
+# define SWIGEXPORT
+# else
+# define SWIGEXPORT __declspec(dllexport)
+# endif
+# else
+# if defined(__GNUC__) && defined(GCC_HASCLASSVISIBILITY)
+# define SWIGEXPORT __attribute__ ((visibility("default")))
+# else
+# define SWIGEXPORT
+# endif
+# endif
+#endif
+
+/* calling conventions for Windows */
+#ifndef SWIGSTDCALL
+# if defined(_WIN32) || defined(__WIN32__) || defined(__CYGWIN__)
+# define SWIGSTDCALL __stdcall
+# else
+# define SWIGSTDCALL
+# endif
+#endif
+
+/* Deal with Microsoft's attempt at deprecating C standard runtime functions */
+#if !defined(SWIG_NO_CRT_SECURE_NO_DEPRECATE) && defined(_MSC_VER) && !defined(_CRT_SECURE_NO_DEPRECATE)
+# define _CRT_SECURE_NO_DEPRECATE
+#endif
+
+/* -----------------------------------------------------------------------------
+ * swigrun.swg
+ *
+ * This file contains generic CAPI SWIG runtime support for pointer
+ * type checking.
+ * ----------------------------------------------------------------------------- */
+
+/* This should only be incremented when either the layout of swig_type_info changes,
+ or for whatever reason, the runtime changes incompatibly */
+#define SWIG_RUNTIME_VERSION "3"
+
+/* define SWIG_TYPE_TABLE_NAME as "SWIG_TYPE_TABLE" */
+#ifdef SWIG_TYPE_TABLE
+# define SWIG_QUOTE_STRING(x) #x
+# define SWIG_EXPAND_AND_QUOTE_STRING(x) SWIG_QUOTE_STRING(x)
+# define SWIG_TYPE_TABLE_NAME SWIG_EXPAND_AND_QUOTE_STRING(SWIG_TYPE_TABLE)
+#else
+# define SWIG_TYPE_TABLE_NAME
+#endif
+
+/*
+ You can use the SWIGRUNTIME and SWIGRUNTIMEINLINE macros for
+ creating a static or dynamic library from the swig runtime code.
+ In 99.9% of the cases, swig just needs to declare them as 'static'.
+
+ But only do this if is strictly necessary, ie, if you have problems
+ with your compiler or so.
+*/
+
+#ifndef SWIGRUNTIME
+# define SWIGRUNTIME SWIGINTERN
+#endif
+
+#ifndef SWIGRUNTIMEINLINE
+# define SWIGRUNTIMEINLINE SWIGRUNTIME SWIGINLINE
+#endif
+
+/* Generic buffer size */
+#ifndef SWIG_BUFFER_SIZE
+# define SWIG_BUFFER_SIZE 1024
+#endif
+
+/* Flags for pointer conversions */
+#define SWIG_POINTER_DISOWN 0x1
+
+/* Flags for new pointer objects */
+#define SWIG_POINTER_OWN 0x1
+
+
+/*
+ Flags/methods for returning states.
+
+ The swig conversion methods, as ConvertPtr, return and integer
+ that tells if the conversion was successful or not. And if not,
+ an error code can be returned (see swigerrors.swg for the codes).
+
+ Use the following macros/flags to set or process the returning
+ states.
+
+ In old swig versions, you usually write code as:
+
+ if (SWIG_ConvertPtr(obj,vptr,ty.flags) != -1) {
+ // success code
+ } else {
+ //fail code
+ }
+
+ Now you can be more explicit as:
+
+ int res = SWIG_ConvertPtr(obj,vptr,ty.flags);
+ if (SWIG_IsOK(res)) {
+ // success code
+ } else {
+ // fail code
+ }
+
+ that seems to be the same, but now you can also do
+
+ Type *ptr;
+ int res = SWIG_ConvertPtr(obj,(void **)(&ptr),ty.flags);
+ if (SWIG_IsOK(res)) {
+ // success code
+ if (SWIG_IsNewObj(res) {
+ ...
+ delete *ptr;
+ } else {
+ ...
+ }
+ } else {
+ // fail code
+ }
+
+ I.e., now SWIG_ConvertPtr can return new objects and you can
+ identify the case and take care of the deallocation. Of course that
+ requires also to SWIG_ConvertPtr to return new result values, as
+
+ int SWIG_ConvertPtr(obj, ptr,...) {
+ if (<obj is ok>) {
+ if (<need new object>) {
+ *ptr = <ptr to new allocated object>;
+ return SWIG_NEWOBJ;
+ } else {
+ *ptr = <ptr to old object>;
+ return SWIG_OLDOBJ;
+ }
+ } else {
+ return SWIG_BADOBJ;
+ }
+ }
+
+ Of course, returning the plain '0(success)/-1(fail)' still works, but you can be
+ more explicit by returning SWIG_BADOBJ, SWIG_ERROR or any of the
+ swig errors code.
+
+ Finally, if the SWIG_CASTRANK_MODE is enabled, the result code
+ allows to return the 'cast rank', for example, if you have this
+
+ int food(double)
+ int fooi(int);
+
+ and you call
+
+ food(1) // cast rank '1' (1 -> 1.0)
+ fooi(1) // cast rank '0'
+
+ just use the SWIG_AddCast()/SWIG_CheckState()
+
+
+ */
+#define SWIG_OK (0)
+#define SWIG_ERROR (-1)
+#define SWIG_IsOK(r) (r >= 0)
+#define SWIG_ArgError(r) ((r != SWIG_ERROR) ? r : SWIG_TypeError)
+
+/* The CastRankLimit says how many bits are used for the cast rank */
+#define SWIG_CASTRANKLIMIT (1 << 8)
+/* The NewMask denotes the object was created (using new/malloc) */
+#define SWIG_NEWOBJMASK (SWIG_CASTRANKLIMIT << 1)
+/* The TmpMask is for in/out typemaps that use temporal objects */
+#define SWIG_TMPOBJMASK (SWIG_NEWOBJMASK << 1)
+/* Simple returning values */
+#define SWIG_BADOBJ (SWIG_ERROR)
+#define SWIG_OLDOBJ (SWIG_OK)
+#define SWIG_NEWOBJ (SWIG_OK | SWIG_NEWOBJMASK)
+#define SWIG_TMPOBJ (SWIG_OK | SWIG_TMPOBJMASK)
+/* Check, add and del mask methods */
+#define SWIG_AddNewMask(r) (SWIG_IsOK(r) ? (r | SWIG_NEWOBJMASK) : r)
+#define SWIG_DelNewMask(r) (SWIG_IsOK(r) ? (r & ~SWIG_NEWOBJMASK) : r)
+#define SWIG_IsNewObj(r) (SWIG_IsOK(r) && (r & SWIG_NEWOBJMASK))
+#define SWIG_AddTmpMask(r) (SWIG_IsOK(r) ? (r | SWIG_TMPOBJMASK) : r)
+#define SWIG_DelTmpMask(r) (SWIG_IsOK(r) ? (r & ~SWIG_TMPOBJMASK) : r)
+#define SWIG_IsTmpObj(r) (SWIG_IsOK(r) && (r & SWIG_TMPOBJMASK))
+
+
+/* Cast-Rank Mode */
+#if defined(SWIG_CASTRANK_MODE)
+# ifndef SWIG_TypeRank
+# define SWIG_TypeRank unsigned long
+# endif
+# ifndef SWIG_MAXCASTRANK /* Default cast allowed */
+# define SWIG_MAXCASTRANK (2)
+# endif
+# define SWIG_CASTRANKMASK ((SWIG_CASTRANKLIMIT) -1)
+# define SWIG_CastRank(r) (r & SWIG_CASTRANKMASK)
+SWIGINTERNINLINE int SWIG_AddCast(int r) {
+ return SWIG_IsOK(r) ? ((SWIG_CastRank(r) < SWIG_MAXCASTRANK) ? (r + 1) : SWIG_ERROR) : r;
+}
+SWIGINTERNINLINE int SWIG_CheckState(int r) {
+ return SWIG_IsOK(r) ? SWIG_CastRank(r) + 1 : 0;
+}
+#else /* no cast-rank mode */
+# define SWIG_AddCast
+# define SWIG_CheckState(r) (SWIG_IsOK(r) ? 1 : 0)
+#endif
+
+
+
+
+#include <string.h>
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+typedef void *(*swig_converter_func)(void *);
+typedef struct swig_type_info *(*swig_dycast_func)(void **);
+
+/* Structure to store inforomation on one type */
+typedef struct swig_type_info {
+ const char *name; /* mangled name of this type */
+ const char *str; /* human readable name of this type */
+ swig_dycast_func dcast; /* dynamic cast function down a hierarchy */
+ struct swig_cast_info *cast; /* linked list of types that can cast into this type */
+ void *clientdata; /* language specific type data */
+ int owndata; /* flag if the structure owns the clientdata */
+} swig_type_info;
+
+/* Structure to store a type and conversion function used for casting */
+typedef struct swig_cast_info {
+ swig_type_info *type; /* pointer to type that is equivalent to this type */
+ swig_converter_func converter; /* function to cast the void pointers */
+ struct swig_cast_info *next; /* pointer to next cast in linked list */
+ struct swig_cast_info *prev; /* pointer to the previous cast */
+} swig_cast_info;
+
+/* Structure used to store module information
+ * Each module generates one structure like this, and the runtime collects
+ * all of these structures and stores them in a circularly linked list.*/
+typedef struct swig_module_info {
+ swig_type_info **types; /* Array of pointers to swig_type_info structures that are in this module */
+ size_t size; /* Number of types in this module */
+ struct swig_module_info *next; /* Pointer to next element in circularly linked list */
+ swig_type_info **type_initial; /* Array of initially generated type structures */
+ swig_cast_info **cast_initial; /* Array of initially generated casting structures */
+ void *clientdata; /* Language specific module data */
+} swig_module_info;
+
+/*
+ Compare two type names skipping the space characters, therefore
+ "char*" == "char *" and "Class<int>" == "Class<int >", etc.
+
+ Return 0 when the two name types are equivalent, as in
+ strncmp, but skipping ' '.
+*/
+SWIGRUNTIME int
+SWIG_TypeNameComp(const char *f1, const char *l1,
+ const char *f2, const char *l2) {
+ for (;(f1 != l1) && (f2 != l2); ++f1, ++f2) {
+ while ((*f1 == ' ') && (f1 != l1)) ++f1;
+ while ((*f2 == ' ') && (f2 != l2)) ++f2;
+ if (*f1 != *f2) return (*f1 > *f2) ? 1 : -1;
+ }
+ return (l1 - f1) - (l2 - f2);
+}
+
+/*
+ Check type equivalence in a name list like <name1>|<name2>|...
+ Return 0 if not equal, 1 if equal
+*/
+SWIGRUNTIME int
+SWIG_TypeEquiv(const char *nb, const char *tb) {
+ int equiv = 0;
+ const char* te = tb + strlen(tb);
+ const char* ne = nb;
+ while (!equiv && *ne) {
+ for (nb = ne; *ne; ++ne) {
+ if (*ne == '|') break;
+ }
+ equiv = (SWIG_TypeNameComp(nb, ne, tb, te) == 0) ? 1 : 0;
+ if (*ne) ++ne;
+ }
+ return equiv;
+}
+
+/*
+ Check type equivalence in a name list like <name1>|<name2>|...
+ Return 0 if equal, -1 if nb < tb, 1 if nb > tb
+*/
+SWIGRUNTIME int
+SWIG_TypeCompare(const char *nb, const char *tb) {
+ int equiv = 0;
+ const char* te = tb + strlen(tb);
+ const char* ne = nb;
+ while (!equiv && *ne) {
+ for (nb = ne; *ne; ++ne) {
+ if (*ne == '|') break;
+ }
+ equiv = (SWIG_TypeNameComp(nb, ne, tb, te) == 0) ? 1 : 0;
+ if (*ne) ++ne;
+ }
+ return equiv;
+}
+
+
+/* think of this as a c++ template<> or a scheme macro */
+#define SWIG_TypeCheck_Template(comparison, ty) \
+ if (ty) { \
+ swig_cast_info *iter = ty->cast; \
+ while (iter) { \
+ if (comparison) { \
+ if (iter == ty->cast) return iter; \
+ /* Move iter to the top of the linked list */ \
+ iter->prev->next = iter->next; \
+ if (iter->next) \
+ iter->next->prev = iter->prev; \
+ iter->next = ty->cast; \
+ iter->prev = 0; \
+ if (ty->cast) ty->cast->prev = iter; \
+ ty->cast = iter; \
+ return iter; \
+ } \
+ iter = iter->next; \
+ } \
+ } \
+ return 0
+
+/*
+ Check the typename
+*/
+SWIGRUNTIME swig_cast_info *
+SWIG_TypeCheck(const char *c, swig_type_info *ty) {
+ SWIG_TypeCheck_Template(strcmp(iter->type->name, c) == 0, ty);
+}
+
+/* Same as previous function, except strcmp is replaced with a pointer comparison */
+SWIGRUNTIME swig_cast_info *
+SWIG_TypeCheckStruct(swig_type_info *from, swig_type_info *into) {
+ SWIG_TypeCheck_Template(iter->type == from, into);
+}
+
+/*
+ Cast a pointer up an inheritance hierarchy
+*/
+SWIGRUNTIMEINLINE void *
+SWIG_TypeCast(swig_cast_info *ty, void *ptr) {
+ return ((!ty) || (!ty->converter)) ? ptr : (*ty->converter)(ptr);
+}
+
+/*
+ Dynamic pointer casting. Down an inheritance hierarchy
+*/
+SWIGRUNTIME swig_type_info *
+SWIG_TypeDynamicCast(swig_type_info *ty, void **ptr) {
+ swig_type_info *lastty = ty;
+ if (!ty || !ty->dcast) return ty;
+ while (ty && (ty->dcast)) {
+ ty = (*ty->dcast)(ptr);
+ if (ty) lastty = ty;
+ }
+ return lastty;
+}
+
+/*
+ Return the name associated with this type
+*/
+SWIGRUNTIMEINLINE const char *
+SWIG_TypeName(const swig_type_info *ty) {
+ return ty->name;
+}
+
+/*
+ Return the pretty name associated with this type,
+ that is an unmangled type name in a form presentable to the user.
+*/
+SWIGRUNTIME const char *
+SWIG_TypePrettyName(const swig_type_info *type) {
+ /* The "str" field contains the equivalent pretty names of the
+ type, separated by vertical-bar characters. We choose
+ to print the last name, as it is often (?) the most
+ specific. */
+ if (!type) return NULL;
+ if (type->str != NULL) {
+ const char *last_name = type->str;
+ const char *s;
+ for (s = type->str; *s; s++)
+ if (*s == '|') last_name = s+1;
+ return last_name;
+ }
+ else
+ return type->name;
+}
+
+/*
+ Set the clientdata field for a type
+*/
+SWIGRUNTIME void
+SWIG_TypeClientData(swig_type_info *ti, void *clientdata) {
+ swig_cast_info *cast = ti->cast;
+ /* if (ti->clientdata == clientdata) return; */
+ ti->clientdata = clientdata;
+
+ while (cast) {
+ if (!cast->converter) {
+ swig_type_info *tc = cast->type;
+ if (!tc->clientdata) {
+ SWIG_TypeClientData(tc, clientdata);
+ }
+ }
+ cast = cast->next;
+ }
+}
+SWIGRUNTIME void
+SWIG_TypeNewClientData(swig_type_info *ti, void *clientdata) {
+ SWIG_TypeClientData(ti, clientdata);
+ ti->owndata = 1;
+}
+
+/*
+ Search for a swig_type_info structure only by mangled name
+ Search is a O(log #types)
+
+ We start searching at module start, and finish searching when start == end.
+ Note: if start == end at the beginning of the function, we go all the way around
+ the circular list.
+*/
+SWIGRUNTIME swig_type_info *
+SWIG_MangledTypeQueryModule(swig_module_info *start,
+ swig_module_info *end,
+ const char *name) {
+ swig_module_info *iter = start;
+ do {
+ if (iter->size) {
+ register size_t l = 0;
+ register size_t r = iter->size - 1;
+ do {
+ /* since l+r >= 0, we can (>> 1) instead (/ 2) */
+ register size_t i = (l + r) >> 1;
+ const char *iname = iter->types[i]->name;
+ if (iname) {
+ register int compare = strcmp(name, iname);
+ if (compare == 0) {
+ return iter->types[i];
+ } else if (compare < 0) {
+ if (i) {
+ r = i - 1;
+ } else {
+ break;
+ }
+ } else if (compare > 0) {
+ l = i + 1;
+ }
+ } else {
+ break; /* should never happen */
+ }
+ } while (l <= r);
+ }
+ iter = iter->next;
+ } while (iter != end);
+ return 0;
+}
+
+/*
+ Search for a swig_type_info structure for either a mangled name or a human readable name.
+ It first searches the mangled names of the types, which is a O(log #types)
+ If a type is not found it then searches the human readable names, which is O(#types).
+
+ We start searching at module start, and finish searching when start == end.
+ Note: if start == end at the beginning of the function, we go all the way around
+ the circular list.
+*/
+SWIGRUNTIME swig_type_info *
+SWIG_TypeQueryModule(swig_module_info *start,
+ swig_module_info *end,
+ const char *name) {
+ /* STEP 1: Search the name field using binary search */
+ swig_type_info *ret = SWIG_MangledTypeQueryModule(start, end, name);
+ if (ret) {
+ return ret;
+ } else {
+ /* STEP 2: If the type hasn't been found, do a complete search
+ of the str field (the human readable name) */
+ swig_module_info *iter = start;
+ do {
+ register size_t i = 0;
+ for (; i < iter->size; ++i) {
+ if (iter->types[i]->str && (SWIG_TypeEquiv(iter->types[i]->str, name)))
+ return iter->types[i];
+ }
+ iter = iter->next;
+ } while (iter != end);
+ }
+
+ /* neither found a match */
+ return 0;
+}
+
+/*
+ Pack binary data into a string
+*/
+SWIGRUNTIME char *
+SWIG_PackData(char *c, void *ptr, size_t sz) {
+ static const char hex[17] = "0123456789abcdef";
+ register const unsigned char *u = (unsigned char *) ptr;
+ register const unsigned char *eu = u + sz;
+ for (; u != eu; ++u) {
+ register unsigned char uu = *u;
+ *(c++) = hex[(uu & 0xf0) >> 4];
+ *(c++) = hex[uu & 0xf];
+ }
+ return c;
+}
+
+/*
+ Unpack binary data from a string
+*/
+SWIGRUNTIME const char *
+SWIG_UnpackData(const char *c, void *ptr, size_t sz) {
+ register unsigned char *u = (unsigned char *) ptr;
+ register const unsigned char *eu = u + sz;
+ for (; u != eu; ++u) {
+ register char d = *(c++);
+ register unsigned char uu;
+ if ((d >= '0') && (d <= '9'))
+ uu = ((d - '0') << 4);
+ else if ((d >= 'a') && (d <= 'f'))
+ uu = ((d - ('a'-10)) << 4);
+ else
+ return (char *) 0;
+ d = *(c++);
+ if ((d >= '0') && (d <= '9'))
+ uu |= (d - '0');
+ else if ((d >= 'a') && (d <= 'f'))
+ uu |= (d - ('a'-10));
+ else
+ return (char *) 0;
+ *u = uu;
+ }
+ return c;
+}
+
+/*
+ Pack 'void *' into a string buffer.
+*/
+SWIGRUNTIME char *
+SWIG_PackVoidPtr(char *buff, void *ptr, const char *name, size_t bsz) {
+ char *r = buff;
+ if ((2*sizeof(void *) + 2) > bsz) return 0;
+ *(r++) = '_';
+ r = SWIG_PackData(r,&ptr,sizeof(void *));
+ if (strlen(name) + 1 > (bsz - (r - buff))) return 0;
+ strcpy(r,name);
+ return buff;
+}
+
+SWIGRUNTIME const char *
+SWIG_UnpackVoidPtr(const char *c, void **ptr, const char *name) {
+ if (*c != '_') {
+ if (strcmp(c,"NULL") == 0) {
+ *ptr = (void *) 0;
+ return name;
+ } else {
+ return 0;
+ }
+ }
+ return SWIG_UnpackData(++c,ptr,sizeof(void *));
+}
+
+SWIGRUNTIME char *
+SWIG_PackDataName(char *buff, void *ptr, size_t sz, const char *name, size_t bsz) {
+ char *r = buff;
+ size_t lname = (name ? strlen(name) : 0);
+ if ((2*sz + 2 + lname) > bsz) return 0;
+ *(r++) = '_';
+ r = SWIG_PackData(r,ptr,sz);
+ if (lname) {
+ strncpy(r,name,lname+1);
+ } else {
+ *r = 0;
+ }
+ return buff;
+}
+
+SWIGRUNTIME const char *
+SWIG_UnpackDataName(const char *c, void *ptr, size_t sz, const char *name) {
+ if (*c != '_') {
+ if (strcmp(c,"NULL") == 0) {
+ memset(ptr,0,sz);
+ return name;
+ } else {
+ return 0;
+ }
+ }
+ return SWIG_UnpackData(++c,ptr,sz);
+}
+
+#ifdef __cplusplus
+}
+#endif
+
+/* Errors in SWIG */
+#define SWIG_UnknownError -1
+#define SWIG_IOError -2
+#define SWIG_RuntimeError -3
+#define SWIG_IndexError -4
+#define SWIG_TypeError -5
+#define SWIG_DivisionByZero -6
+#define SWIG_OverflowError -7
+#define SWIG_SyntaxError -8
+#define SWIG_ValueError -9
+#define SWIG_SystemError -10
+#define SWIG_AttributeError -11
+#define SWIG_MemoryError -12
+#define SWIG_NullReferenceError -13
+
+
+
+#include <ruby.h>
+
+/* Ruby 1.7 defines NUM2LL(), LL2NUM() and ULL2NUM() macros */
+#ifndef NUM2LL
+#define NUM2LL(x) NUM2LONG((x))
+#endif
+#ifndef LL2NUM
+#define LL2NUM(x) INT2NUM((long) (x))
+#endif
+#ifndef ULL2NUM
+#define ULL2NUM(x) UINT2NUM((unsigned long) (x))
+#endif
+
+/* Ruby 1.7 doesn't (yet) define NUM2ULL() */
+#ifndef NUM2ULL
+#ifdef HAVE_LONG_LONG
+#define NUM2ULL(x) rb_num2ull((x))
+#else
+#define NUM2ULL(x) NUM2ULONG(x)
+#endif
+#endif
+
+/* RSTRING_LEN, etc are new in Ruby 1.9, but ->ptr and ->len no longer work */
+/* Define these for older versions so we can just write code the new way */
+#ifndef RSTRING_LEN
+# define RSTRING_LEN(x) RSTRING(x)->len
+#endif
+#ifndef RSTRING_PTR
+# define RSTRING_PTR(x) RSTRING(x)->ptr
+#endif
+#ifndef RARRAY_LEN
+# define RARRAY_LEN(x) RARRAY(x)->len
+#endif
+#ifndef RARRAY_PTR
+# define RARRAY_PTR(x) RARRAY(x)->ptr
+#endif
+
+/*
+ * Need to be very careful about how these macros are defined, especially
+ * when compiling C++ code or C code with an ANSI C compiler.
+ *
+ * VALUEFUNC(f) is a macro used to typecast a C function that implements
+ * a Ruby method so that it can be passed as an argument to API functions
+ * like rb_define_method() and rb_define_singleton_method().
+ *
+ * VOIDFUNC(f) is a macro used to typecast a C function that implements
+ * either the "mark" or "free" stuff for a Ruby Data object, so that it
+ * can be passed as an argument to API functions like Data_Wrap_Struct()
+ * and Data_Make_Struct().
+ */
+
+#ifdef __cplusplus
+# ifndef RUBY_METHOD_FUNC /* These definitions should work for Ruby 1.4.6 */
+# define PROTECTFUNC(f) ((VALUE (*)()) f)
+# define VALUEFUNC(f) ((VALUE (*)()) f)
+# define VOIDFUNC(f) ((void (*)()) f)
+# else
+# ifndef ANYARGS /* These definitions should work for Ruby 1.6 */
+# define PROTECTFUNC(f) ((VALUE (*)()) f)
+# define VALUEFUNC(f) ((VALUE (*)()) f)
+# define VOIDFUNC(f) ((RUBY_DATA_FUNC) f)
+# else /* These definitions should work for Ruby 1.7+ */
+# define PROTECTFUNC(f) ((VALUE (*)(VALUE)) f)
+# define VALUEFUNC(f) ((VALUE (*)(ANYARGS)) f)
+# define VOIDFUNC(f) ((RUBY_DATA_FUNC) f)
+# endif
+# endif
+#else
+# define VALUEFUNC(f) (f)
+# define VOIDFUNC(f) (f)
+#endif
+
+/* Don't use for expressions have side effect */
+#ifndef RB_STRING_VALUE
+#define RB_STRING_VALUE(s) (TYPE(s) == T_STRING ? (s) : (*(volatile VALUE *)&(s) = rb_str_to_str(s)))
+#endif
+#ifndef StringValue
+#define StringValue(s) RB_STRING_VALUE(s)
+#endif
+#ifndef StringValuePtr
+#define StringValuePtr(s) RSTRING_PTR(RB_STRING_VALUE(s))
+#endif
+#ifndef StringValueLen
+#define StringValueLen(s) RSTRING_LEN(RB_STRING_VALUE(s))
+#endif
+#ifndef SafeStringValue
+#define SafeStringValue(v) do {\
+ StringValue(v);\
+ rb_check_safe_str(v);\
+} while (0)
+#endif
+
+#ifndef HAVE_RB_DEFINE_ALLOC_FUNC
+#define rb_define_alloc_func(klass, func) rb_define_singleton_method((klass), "new", VALUEFUNC((func)), -1)
+#define rb_undef_alloc_func(klass) rb_undef_method(CLASS_OF((klass)), "new")
+#endif
+
+
+/* -----------------------------------------------------------------------------
+ * error manipulation
+ * ----------------------------------------------------------------------------- */
+
+
+/* Define some additional error types */
+#define SWIG_ObjectPreviouslyDeletedError -100
+
+
+/* Define custom exceptions for errors that do not map to existing Ruby
+ exceptions. Note this only works for C++ since a global cannot be
+ initialized by a funtion in C. For C, fallback to rb_eRuntimeError.*/
+
+SWIGINTERN VALUE
+getNullReferenceError(void) {
+ static int init = 0;
+ static VALUE rb_eNullReferenceError ;
+ if (!init) {
+ init = 1;
+ rb_eNullReferenceError = rb_define_class("NullReferenceError", rb_eRuntimeError);
+ }
+ return rb_eNullReferenceError;
+}
+
+SWIGINTERN VALUE
+getObjectPreviouslyDeletedError(void) {
+ static int init = 0;
+ static VALUE rb_eObjectPreviouslyDeleted ;
+ if (!init) {
+ init = 1;
+ rb_eObjectPreviouslyDeleted = rb_define_class("ObjectPreviouslyDeleted", rb_eRuntimeError);
+ }
+ return rb_eObjectPreviouslyDeleted;
+}
+
+
+SWIGINTERN VALUE
+SWIG_Ruby_ErrorType(int SWIG_code) {
+ VALUE type;
+ switch (SWIG_code) {
+ case SWIG_MemoryError:
+ type = rb_eNoMemError;
+ break;
+ case SWIG_IOError:
+ type = rb_eIOError;
+ break;
+ case SWIG_RuntimeError:
+ type = rb_eRuntimeError;
+ break;
+ case SWIG_IndexError:
+ type = rb_eIndexError;
+ break;
+ case SWIG_TypeError: