├── .gitignore ├── Android.mk ├── Application.mk ├── LICENSE ├── README.md ├── app ├── .classpath ├── .project ├── AndroidManifest.xml ├── assets │ └── .gitignore ├── build.xml ├── contrib │ └── jtar-2.2.jar ├── proguard.cfg ├── res │ ├── drawable-hdpi │ │ └── icon.png │ ├── drawable-ldpi │ │ └── icon.png │ ├── drawable-mdpi │ │ └── icon.png │ ├── layout │ │ └── main.xml │ └── values │ │ └── strings.xml └── src │ └── org │ └── meshpoint │ └── anode │ ├── AnodeActivity.java │ ├── AnodeReceiver.java │ ├── AnodeService.java │ ├── Constants.java │ └── util │ ├── AndroidLog.java │ ├── ArgProcessor.java │ ├── ModuleUtils.java │ ├── TarExtractor.java │ └── ZipExtractor.java ├── bridge-java ├── .classpath ├── .project ├── build.xml ├── jni │ └── src │ │ ├── org_meshpoint_anode_bridge_BridgeNative.cpp │ │ └── org_meshpoint_anode_bridge_BridgeNative.h └── src │ └── org │ ├── meshpoint │ └── anode │ │ ├── bridge │ │ ├── BridgeNative.java │ │ ├── Env.java │ │ ├── FinalizeQueue.java │ │ ├── ModuleContext.java │ │ └── SynchronousOperation.java │ │ ├── error │ │ ├── GeneralError.java │ │ ├── InternalError.java │ │ ├── ReferenceError.java │ │ ├── ScriptError.java │ │ └── TypeError.java │ │ ├── idl │ │ ├── BoundInterface.java │ │ ├── Callback.java │ │ ├── Dictionary.java │ │ ├── IDLInterface.java │ │ ├── InterfaceManager.java │ │ ├── StubUtil.java │ │ └── Types.java │ │ ├── java │ │ ├── Array.java │ │ ├── Base.java │ │ ├── ByteArray.java │ │ ├── DoubleArray.java │ │ ├── IntegerArray.java │ │ ├── LongArray.java │ │ └── ObjectArray.java │ │ ├── js │ │ ├── JSArray.java │ │ ├── JSByteArray.java │ │ ├── JSDoubleArray.java │ │ ├── JSFunction.java │ │ ├── JSIntegerArray.java │ │ ├── JSInterface.java │ │ ├── JSLongArray.java │ │ ├── JSObject.java │ │ ├── JSObjectArray.java │ │ └── JSValue.java │ │ ├── module │ │ ├── IModule.java │ │ └── IModuleContext.java │ │ ├── type │ │ ├── ICollection.java │ │ ├── IFunction.java │ │ └── IIndexedCollection.java │ │ └── util │ │ ├── Log.java │ │ └── PrintStreamLog.java │ └── w3c │ └── dom │ ├── Array.java │ ├── ByteArray.java │ ├── DoubleArray.java │ ├── IntegerArray.java │ ├── LongArray.java │ ├── ObjectArray.java │ └── PrimitiveArray.java ├── bridge-stub-generator ├── .classpath ├── .project ├── build.xml └── src │ └── org │ └── meshpoint │ └── anode │ └── stub │ ├── DictionaryStubGenerator.java │ ├── PlatformStubGenerator.java │ ├── StubGenerator.java │ ├── UserStubGenerator.java │ └── util │ ├── DirectoryClassLoader.java │ └── StubGen.java ├── bridge ├── Android.mk ├── Application.mk └── src │ ├── AndroidVM.cpp │ ├── AndroidVM.h │ ├── ArrayConv.cpp │ ├── ArrayConv.h │ ├── Bridge.cpp │ ├── Bridge.h │ ├── Conv.cpp │ ├── Conv.h │ ├── Env.cpp │ ├── Env.h │ ├── Interface.cpp │ ├── Interface.h │ ├── JREVM.cpp │ ├── JREVM.h │ ├── Utils-inl.h │ ├── Utils.h │ ├── VM.cpp │ ├── VM.h │ └── defines.h ├── libnode ├── .classpath ├── .project ├── AndroidManifest.xml ├── assets │ └── .gitignore ├── build.xml ├── custom_rules.xml ├── gen │ └── org │ │ └── meshpoint │ │ └── anode │ │ └── R.java ├── jni │ ├── Android.mk │ └── src │ │ ├── defines.h │ │ ├── org_meshpoint_anode_RuntimeNative.cpp │ │ └── org_meshpoint_anode_RuntimeNative.h ├── proguard.cfg ├── project.properties ├── res │ ├── drawable-hdpi │ │ └── icon.png │ ├── drawable-ldpi │ │ └── icon.png │ ├── drawable-mdpi │ │ └── icon.png │ ├── layout │ │ └── main.xml │ └── values │ │ └── strings.xml └── src │ └── org │ └── meshpoint │ └── anode │ ├── AndroidContext.java │ ├── Isolate.java │ ├── Runtime.java │ ├── RuntimeNative.java │ └── bridge │ └── ModuleClassLoader.java └── sdk ├── addon ├── build-node-addon.mk └── sample │ └── hello │ ├── Android.mk │ ├── Application.mk │ └── src │ └── hello.cc └── java ├── lib ├── .classpath ├── .project └── src │ └── org │ ├── meshpoint │ └── anode │ │ ├── bridge │ │ └── Env.java │ │ ├── idl │ │ ├── Dictionary.java │ │ ├── IDLInterface.java │ │ └── InterfaceManager.java │ │ ├── java │ │ └── Base.java │ │ └── module │ │ ├── IModule.java │ │ └── IModuleContext.java │ └── w3c │ └── dom │ ├── Array.java │ ├── ByteArray.java │ ├── DoubleArray.java │ ├── IntegerArray.java │ ├── LongArray.java │ ├── ObjectArray.java │ └── PrimitiveArray.java └── tools └── stubgen.jar /.gitignore: -------------------------------------------------------------------------------- 1 | # built application files 2 | *.apk 3 | *.ap_ 4 | 5 | # files for the dex VM 6 | *.dex 7 | 8 | # Java class files 9 | *.class 10 | 11 | # generated files 12 | app/bin/ 13 | app/gen/ 14 | libnode/gen/ 15 | libnode/bin/ 16 | bridge-java/bin/ 17 | bridge-java/out/ 18 | bridge-stub-generator/bin/ 19 | 20 | # shared libraries 21 | app/assets/ 22 | 23 | # Local configuration file (sdk path, etc) 24 | local.properties 25 | project.properties 26 | proguard-project.txt 27 | 28 | # ndk-build files 29 | libs/ 30 | obj/ 31 | -------------------------------------------------------------------------------- /Android.mk: -------------------------------------------------------------------------------- 1 | $(call import-module,libnode/jni) 2 | $(call import-module,bridge) 3 | -------------------------------------------------------------------------------- /Application.mk: -------------------------------------------------------------------------------- 1 | ANODE_ROOT := $(call my-dir) 2 | 3 | ifndef NODE_ROOT 4 | NODE_ROOT := $(ANODE_ROOT)/../node 5 | endif 6 | 7 | APP_PROJECT_PATH := $(ANODE_ROOT) 8 | APP_MODULES := jninode bridge 9 | APP_BUILD_SCRIPT := $(APP_PROJECT_PATH)/Android.mk 10 | APP_PLATFORM := android-14 11 | APP_ABI := armeabi 12 | NDK_MODULE_PATH := $(NDK_MODULE_PATH):$(ANODE_ROOT):$(ANODE_ROOT)/..:$(NODE_ROOT):$(NODE_ROOT)/.. 13 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2011-2012 Paddy Byers 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | ## Introduction 2 | 3 | Anode is an embryonic framework for running node.js applications on Android. There are two main parts to this: 4 | 5 | - a port of [node.js](https://github.com/joyent/node) to the Android OS and libraries. The code is [here](https://github.com/paddybyers/node); 6 | 7 | - a set of Android projects (this repo) that provide the integration with the Android frameworks. 8 | 9 | Anode builds to an Android application package (.apk) that encapsulates the node.js runtime and can run node.js applications through an intent-based API. 10 | 11 | ## Status 12 | 13 | This work is at an early stage. All input is welcome. 14 | 15 | The current target is to support node.js applications, invoked by intent. Multiple instances can be run in parallel. Modules (or addons) for node.js written in JavaScript or native are supported, and support for modules implemented in Java is on the roadmap. 16 | 17 | This framework depends on a port of node [here](https://github.com/paddybyers/node). 18 | 19 | ## More information 20 | 21 | Please see the [wiki](https://github.com/paddybyers/anode/wiki/Anode) for more information. 22 | -------------------------------------------------------------------------------- /app/.classpath: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | -------------------------------------------------------------------------------- /app/.project: -------------------------------------------------------------------------------- 1 | 2 | 3 | app 4 | 5 | 6 | 7 | 8 | 9 | com.android.ide.eclipse.adt.ResourceManagerBuilder 10 | 11 | 12 | 13 | 14 | com.android.ide.eclipse.adt.PreCompilerBuilder 15 | 16 | 17 | 18 | 19 | org.eclipse.jdt.core.javabuilder 20 | 21 | 22 | 23 | 24 | com.android.ide.eclipse.adt.ApkBuilder 25 | 26 | 27 | 28 | 29 | 30 | com.android.ide.eclipse.adt.AndroidNature 31 | org.eclipse.jdt.core.javanature 32 | 33 | 34 | -------------------------------------------------------------------------------- /app/AndroidManifest.xml: -------------------------------------------------------------------------------- 1 | 2 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | 29 | 30 | 31 | 32 | 33 | 34 | 35 | 36 | 37 | 38 | 39 | 40 | 41 | 42 | 43 | 44 | 45 | 46 | 47 | 48 | 49 | 60 | 61 | 62 | 63 | -------------------------------------------------------------------------------- /app/assets/.gitignore: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/paddybyers/anode/0dd99e2ec33e80c6ec46ed769530fe208bfcf488/app/assets/.gitignore -------------------------------------------------------------------------------- /app/build.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 7 | 8 | 9 | 29 | 30 | 31 | 35 | 36 | 37 | 38 | 39 | 40 | 49 | 50 | 51 | 52 | 56 | 57 | 69 | 70 | 71 | 89 | 90 | 91 | 92 | 93 | -------------------------------------------------------------------------------- /app/contrib/jtar-2.2.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/paddybyers/anode/0dd99e2ec33e80c6ec46ed769530fe208bfcf488/app/contrib/jtar-2.2.jar -------------------------------------------------------------------------------- /app/proguard.cfg: -------------------------------------------------------------------------------- 1 | -optimizationpasses 5 2 | -dontusemixedcaseclassnames 3 | -dontskipnonpubliclibraryclasses 4 | -dontpreverify 5 | -verbose 6 | -optimizations !code/simplification/arithmetic,!field/*,!class/merging/* 7 | 8 | -keep public class * extends android.app.Activity 9 | -keep public class * extends android.app.Application 10 | -keep public class * extends android.app.Service 11 | -keep public class * extends android.content.BroadcastReceiver 12 | -keep public class * extends android.content.ContentProvider 13 | -keep public class * extends android.app.backup.BackupAgentHelper 14 | -keep public class * extends android.preference.Preference 15 | -keep public class com.android.vending.licensing.ILicensingService 16 | 17 | -keepclasseswithmembernames class * { 18 | native ; 19 | } 20 | 21 | -keepclasseswithmembers class * { 22 | public (android.content.Context, android.util.AttributeSet); 23 | } 24 | 25 | -keepclasseswithmembers class * { 26 | public (android.content.Context, android.util.AttributeSet, int); 27 | } 28 | 29 | -keepclassmembers class * extends android.app.Activity { 30 | public void *(android.view.View); 31 | } 32 | 33 | -keepclassmembers enum * { 34 | public static **[] values(); 35 | public static ** valueOf(java.lang.String); 36 | } 37 | 38 | -keep class * implements android.os.Parcelable { 39 | public static final android.os.Parcelable$Creator *; 40 | } 41 | -------------------------------------------------------------------------------- /app/res/drawable-hdpi/icon.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/paddybyers/anode/0dd99e2ec33e80c6ec46ed769530fe208bfcf488/app/res/drawable-hdpi/icon.png -------------------------------------------------------------------------------- /app/res/drawable-ldpi/icon.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/paddybyers/anode/0dd99e2ec33e80c6ec46ed769530fe208bfcf488/app/res/drawable-ldpi/icon.png -------------------------------------------------------------------------------- /app/res/drawable-mdpi/icon.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/paddybyers/anode/0dd99e2ec33e80c6ec46ed769530fe208bfcf488/app/res/drawable-mdpi/icon.png -------------------------------------------------------------------------------- /app/res/layout/main.xml: -------------------------------------------------------------------------------- 1 | 2 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | -------------------------------------------------------------------------------- /app/res/values/strings.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | Anode 4 | Start 5 | Stop 6 | Arguments: 7 | Run state 8 | Created 9 | Started 10 | Stopping 11 | Stopped 12 | Anode Receiver 13 | A broadcast receiver for controlling invocations of node.js 14 | Anode Service 15 | A service that permits the running of node.js invocations in the background 16 | 17 | -------------------------------------------------------------------------------- /app/src/org/meshpoint/anode/AnodeActivity.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2011-2012 Paddy Byers 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package org.meshpoint.anode; 18 | 19 | import org.meshpoint.anode.Runtime; 20 | import org.meshpoint.anode.Runtime.IllegalStateException; 21 | import org.meshpoint.anode.Runtime.InitialisationException; 22 | import org.meshpoint.anode.Runtime.NodeException; 23 | import org.meshpoint.anode.Runtime.StateListener; 24 | 25 | import android.app.Activity; 26 | import android.content.Context; 27 | import android.content.res.Resources; 28 | import android.os.Bundle; 29 | import android.os.Handler; 30 | import android.util.Log; 31 | import android.view.KeyEvent; 32 | import android.view.View; 33 | import android.view.View.OnClickListener; 34 | import android.view.View.OnKeyListener; 35 | import android.widget.Button; 36 | import android.widget.EditText; 37 | import android.widget.TextView; 38 | 39 | public class AnodeActivity extends Activity implements StateListener { 40 | 41 | private static String TAG = "anode::AnodeActivity"; 42 | private Context ctx; 43 | private Button startButton; 44 | private Button stopButton; 45 | private EditText argsText; 46 | private TextView stateText; 47 | private Handler viewHandler = new Handler(); 48 | private long uiThread; 49 | private String instance; 50 | private Isolate isolate; 51 | 52 | /** Called when the activity is first created. */ 53 | @Override 54 | public void onCreate(Bundle savedInstanceState) { 55 | super.onCreate(savedInstanceState); 56 | setContentView(R.layout.main); 57 | ctx = getApplicationContext(); 58 | initUI(); 59 | uiThread = viewHandler.getLooper().getThread().getId(); 60 | } 61 | 62 | private void initUI() { 63 | startButton = (Button)findViewById(R.id.start_button); 64 | startButton.setOnClickListener(new StartClickListener()); 65 | stopButton = (Button)findViewById(R.id.stop_button); 66 | stopButton.setOnClickListener(new StopClickListener()); 67 | argsText = (EditText)findViewById(R.id.args_editText); 68 | stateText = (TextView)findViewById(R.id.args_stateText); 69 | argsText.setOnKeyListener(new OnKeyListener() { 70 | public boolean onKey(View v, int keyCode, KeyEvent event) { 71 | /* If the event is a key-down event on the "enter" button */ 72 | if ((event.getAction() == KeyEvent.ACTION_DOWN) && 73 | (keyCode == KeyEvent.KEYCODE_ENTER)) { 74 | startAction(); 75 | return true; 76 | } 77 | return false; 78 | } 79 | }); 80 | __stateChanged(Runtime.STATE_CREATED); 81 | } 82 | 83 | private void initRuntime(String[] opts) { 84 | try { 85 | Runtime.initRuntime(ctx, opts); 86 | } catch (InitialisationException e) { 87 | Log.v(TAG, "initRuntime: exception: " + e + "; cause: " + e.getCause()); 88 | } 89 | } 90 | 91 | private void startAction() { 92 | String options = getIntent().getStringExtra(AnodeReceiver.OPTS); 93 | String instance = getIntent().getStringExtra(AnodeReceiver.INST); 94 | String[] opts = options == null ? null : options.split("\\s"); 95 | initRuntime(opts); 96 | String args = argsText.getText().toString(); 97 | try { 98 | isolate = Runtime.createIsolate(); 99 | isolate.addStateListener(this); 100 | this.instance = AnodeService.addInstance(instance, isolate); 101 | isolate.start(args.split("\\s")); 102 | } catch (IllegalStateException e) { 103 | Log.v(TAG, "isolate start: exception: " + e + "; cause: " + e.getCause()); 104 | } catch (NodeException e) { 105 | Log.v(TAG, "isolate start: exception: " + e); 106 | } 107 | } 108 | 109 | private void stopAction() { 110 | if(instance == null) { 111 | Log.v(TAG, "AnodeReceiver.onReceive::stop: no instance currently running for this activity"); 112 | return; 113 | } 114 | try { 115 | isolate.stop(); 116 | } catch (IllegalStateException e) { 117 | Log.v(TAG, "isolate stop : exception: " + e + "; cause: " + e.getCause()); 118 | } catch (NodeException e) { 119 | Log.v(TAG, "isolate stop: exception: " + e); 120 | } 121 | } 122 | 123 | class StartClickListener implements OnClickListener { 124 | public void onClick(View arg0) { 125 | startAction(); 126 | } 127 | } 128 | 129 | class StopClickListener implements OnClickListener { 130 | public void onClick(View arg0) { 131 | stopAction(); 132 | } 133 | } 134 | 135 | @Override 136 | public void stateChanged(final int state) { 137 | if(Thread.currentThread().getId() == uiThread) { 138 | __stateChanged(state); 139 | } else { 140 | viewHandler.post(new Runnable() { 141 | public void run() { 142 | __stateChanged(state); 143 | } 144 | }); 145 | } 146 | } 147 | 148 | private void __stateChanged(final int state) { 149 | stateText.setText(getStateString(state)); 150 | startButton.setEnabled(state == Runtime.STATE_CREATED); 151 | stopButton.setEnabled(state == Runtime.STATE_STARTED); 152 | /* exit the activity if the runtime has exited */ 153 | if(state == Runtime.STATE_STOPPED) { 154 | finish(); 155 | } 156 | } 157 | 158 | private String getStateString(int state) { 159 | Resources res = ctx.getResources(); 160 | String result = null; 161 | switch(state) { 162 | case Runtime.STATE_CREATED: 163 | result = res.getString(R.string.created); 164 | break; 165 | case Runtime.STATE_STARTED: 166 | result = res.getString(R.string.started); 167 | break; 168 | case Runtime.STATE_STOPPING: 169 | result = res.getString(R.string.stopping); 170 | break; 171 | case Runtime.STATE_STOPPED: 172 | result = res.getString(R.string.stopped); 173 | break; 174 | } 175 | return result; 176 | } 177 | } 178 | -------------------------------------------------------------------------------- /app/src/org/meshpoint/anode/AnodeReceiver.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2011-2012 Paddy Byers 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package org.meshpoint.anode; 18 | 19 | import org.meshpoint.anode.Runtime.IllegalStateException; 20 | import org.meshpoint.anode.Runtime.NodeException; 21 | 22 | import android.content.BroadcastReceiver; 23 | import android.content.Context; 24 | import android.content.Intent; 25 | import android.util.Log; 26 | 27 | public class AnodeReceiver extends BroadcastReceiver { 28 | 29 | private static String TAG = "anode::AnodeReceiver"; 30 | public static final String ACTION_START = "org.meshpoint.anode.START"; 31 | public static final String ACTION_STOP = "org.meshpoint.anode.STOP"; 32 | public static final String ACTION_STOPALL = "org.meshpoint.anode.STOPALL"; 33 | public static final String ACTION_INSTALL = "org.meshpoint.anode.INSTALL"; 34 | public static final String ACTION_UNINSTALL = "org.meshpoint.anode.UNINSTALL"; 35 | public static final String CMD = "cmdline"; 36 | public static final String INST = "instance"; 37 | public static final String OPTS = "options"; 38 | public static final String MODULE = "module"; 39 | public static final String PATH = "path"; 40 | 41 | public AnodeReceiver() { 42 | super(); 43 | } 44 | 45 | @Override 46 | public void onReceive(Context ctx, Intent intent) { 47 | /* get the system options */ 48 | String action = intent.getAction(); 49 | if(ACTION_STOPALL.equals(action)) { 50 | if(Runtime.isInitialised()) { 51 | for(Isolate isolate : AnodeService.getAll()) 52 | stopInstance(isolate); 53 | } 54 | return; 55 | } 56 | if(ACTION_STOP.equals(action)) { 57 | if(Runtime.isInitialised()) { 58 | String instance = intent.getStringExtra(INST); 59 | if(instance == null) { 60 | instance = AnodeService.soleInstance(); 61 | if(instance == null) { 62 | Log.v(TAG, "AnodeReceiver.onReceive::stop: no instance specified"); 63 | return; 64 | } 65 | } 66 | Isolate isolate = AnodeService.getInstance(instance); 67 | if(isolate == null) { 68 | Log.v(TAG, "AnodeReceiver.onReceive::stop: instance " + instance + " not found"); 69 | return; 70 | } 71 | stopInstance(isolate); 72 | } 73 | return; 74 | } 75 | 76 | if(ACTION_START.equals(action)) { 77 | /* get the launch commandline */ 78 | String args = intent.getStringExtra(CMD); 79 | 80 | /* if no cmdline was sent, then launch the activity for interactive behaviour */ 81 | if(args == null || args.isEmpty()) { 82 | intent.setClassName(ctx, AnodeActivity.class.getName()); 83 | intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK); 84 | ctx.startActivity(intent); 85 | return; 86 | } 87 | } 88 | 89 | /* otherwise, start service */ 90 | intent.setClassName(ctx, AnodeService.class.getName()); 91 | ctx.startService(intent); 92 | } 93 | 94 | private void stopInstance(Isolate isolate) { 95 | try { 96 | isolate.stop(); 97 | } catch (IllegalStateException e) { 98 | Log.v(TAG, "AnodeReceiver.onReceive::stop: exception: " + e + "; cause: " + e.getCause()); 99 | } catch (NodeException e) { 100 | Log.v(TAG, "AnodeReceiver.onReceive::stop: exception: " + e + "; cause: " + e.getCause()); 101 | } 102 | } 103 | } 104 | -------------------------------------------------------------------------------- /app/src/org/meshpoint/anode/Constants.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2011-2012 Paddy Byers 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package org.meshpoint.anode; 18 | 19 | public interface Constants { 20 | 21 | public static final String RESOURCE_DIR = "/data/data/org.meshpoint.anode/uriCache"; 22 | public static final String MODULE_DIR = "/data/data/org.meshpoint.anode/node_modules"; 23 | public static final String APP_DIR = "/data/data/org.meshpoint.anode/app"; 24 | } 25 | -------------------------------------------------------------------------------- /app/src/org/meshpoint/anode/util/AndroidLog.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2011-2012 Paddy Byers 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package org.meshpoint.anode.util; 18 | 19 | public class AndroidLog implements Log { 20 | 21 | @Override 22 | public int v(String tag, String msg) { 23 | return android.util.Log.v(tag, msg); 24 | } 25 | 26 | @Override 27 | public int v(String tag, String msg, Throwable tr) { 28 | return android.util.Log.v(tag, msg, tr); 29 | } 30 | 31 | @Override 32 | public int d(String tag, String msg) { 33 | return android.util.Log.d(tag, msg); 34 | } 35 | 36 | @Override 37 | public int d(String tag, String msg, Throwable tr) { 38 | return android.util.Log.d(tag, msg, tr); 39 | } 40 | 41 | @Override 42 | public int i(String tag, String msg) { 43 | return android.util.Log.i(tag, msg); 44 | } 45 | 46 | @Override 47 | public int i(String tag, String msg, Throwable tr) { 48 | return android.util.Log.i(tag, msg, tr); 49 | } 50 | 51 | @Override 52 | public int w(String tag, String msg) { 53 | return android.util.Log.w(tag, msg); 54 | } 55 | 56 | @Override 57 | public int w(String tag, String msg, Throwable tr) { 58 | return android.util.Log.w(tag, msg, tr); 59 | } 60 | 61 | @Override 62 | public int w(String tag, Throwable tr) { 63 | return android.util.Log.w(tag, tr); 64 | } 65 | 66 | @Override 67 | public int e(String tag, String msg) { 68 | return android.util.Log.e(tag, msg); 69 | } 70 | 71 | @Override 72 | public int e(String tag, String msg, Throwable tr) { 73 | return android.util.Log.e(tag, msg, tr); 74 | } 75 | 76 | @Override 77 | public int wtf(String tag, String msg) { 78 | return android.util.Log.wtf(tag, msg); 79 | } 80 | 81 | @Override 82 | public int wtf(String tag, Throwable tr) { 83 | return android.util.Log.wtf(tag, tr); 84 | } 85 | 86 | @Override 87 | public int wtf(String tag, String msg, Throwable tr) { 88 | return android.util.Log.wtf(tag, msg, tr); 89 | } 90 | 91 | } 92 | -------------------------------------------------------------------------------- /app/src/org/meshpoint/anode/util/ArgProcessor.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2011-2012 Paddy Byers 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package org.meshpoint.anode.util; 18 | 19 | import java.io.IOException; 20 | import java.net.URI; 21 | import java.net.URISyntaxException; 22 | import java.util.HashMap; 23 | import java.util.Map; 24 | import java.util.Set; 25 | 26 | import org.meshpoint.anode.Constants; 27 | 28 | import android.os.Bundle; 29 | import android.util.Log; 30 | 31 | /** 32 | * A class that processes a given commandline together with an optional 33 | * mapping of resource identifiers and URLs to fetch those resources. 34 | * 35 | * Resources are limited to those that can be fetched with an http GET. 36 | * 37 | * Downloaded resources are cached in an asset directory specific to the 38 | * application, obtained using the supplied Context. 39 | * Cached resources are stored in files whose names are a hash of the 40 | * originating URL. It is safe to reuse the cache directory across 41 | * multiple invocations of the same app, or across invocations of different 42 | * apps. 43 | * 44 | * No processing is performed of expiry times of the specified resources 45 | * so they are downloaded again on each invocation. 46 | * 47 | * Name substitution is performed in the supplied commandline, to map 48 | * resource specifiers to the local cache filename. 49 | * 50 | * A resource is identified with a Bundle entry of: 51 | * get: = 52 | * and is referenced in the commandline by: 53 | * % 54 | */ 55 | public class ArgProcessor { 56 | 57 | private static String TAG = "anode::ArgsProcessor"; 58 | private static final String GET_PREFIX = "get:"; 59 | 60 | private Bundle extras; 61 | private String text; 62 | private Map uriMap; 63 | private Map filenameMap; 64 | 65 | /** 66 | * Constructs an instance of ArgProcessor 67 | * @param extras an optional bundle containing the mapping parameters 68 | * @param text the string to process 69 | */ 70 | public ArgProcessor(Bundle extras, String text) { 71 | this.extras = extras; 72 | this.text = text; 73 | uriMap = new HashMap(); 74 | filenameMap = new HashMap(); 75 | } 76 | 77 | /** 78 | * Process the text string 79 | * @return the processed string, with downloaded resource names substituted 80 | */ 81 | public String processString() { 82 | if(extras != null) { 83 | /* extract list of args to get */ 84 | try { 85 | Set keys = extras.keySet(); 86 | for(String key : keys) { 87 | if(key.startsWith(GET_PREFIX)) { 88 | String rawUri = extras.getString(key); 89 | String rawKey = key.substring(GET_PREFIX.length()); 90 | URI uri = new URI(rawUri); 91 | String filename = ModuleUtils.getResourceUriHash(rawUri); 92 | uriMap.put(rawKey, uri); 93 | filenameMap.put(rawKey, filename); 94 | } 95 | } 96 | } catch(URISyntaxException e) { 97 | Log.v(TAG, "process exception: aborting; exception: " + e); 98 | return null; 99 | } 100 | 101 | /* download each asset */ 102 | for(String key : uriMap.keySet()) { 103 | try { 104 | ModuleUtils.getResource(uriMap.get(key), filenameMap.get(key)); 105 | } catch(IOException e) { 106 | Log.v(TAG, "process exception: aborting; exception: " + e + "; resource = " + uriMap.get(key).toString()); 107 | return null; 108 | } 109 | } 110 | 111 | /* process the commandline */ 112 | for(String key : filenameMap.keySet()) { 113 | text = text.replace("%" + key, Constants.RESOURCE_DIR + '/' + filenameMap.get(key)); 114 | } 115 | } 116 | return text; 117 | } 118 | 119 | public String[] processArray() { 120 | /* split the commandline at whitespace */ 121 | processString(); 122 | return text.split("\\s"); 123 | } 124 | 125 | } 126 | -------------------------------------------------------------------------------- /app/src/org/meshpoint/anode/util/TarExtractor.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2011-2012 Paddy Byers 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package org.meshpoint.anode.util; 18 | 19 | import java.io.BufferedInputStream; 20 | import java.io.BufferedOutputStream; 21 | import java.io.File; 22 | import java.io.FileInputStream; 23 | import java.io.FileOutputStream; 24 | import java.io.IOException; 25 | import java.util.zip.GZIPInputStream; 26 | 27 | import org.kamranzafar.jtar.TarEntry; 28 | import org.kamranzafar.jtar.TarInputStream; 29 | 30 | public class TarExtractor implements ModuleUtils.Unpacker { 31 | 32 | public void unpack(File src, File dest) throws IOException { 33 | /* first extract the tar file */ 34 | File tarFile = new File(src.getAbsolutePath() + ".tar"); 35 | byte[] buf = new byte[1024]; 36 | GZIPInputStream zis = null; 37 | zis = new GZIPInputStream(new FileInputStream(src)); 38 | FileOutputStream tarfos = new FileOutputStream(tarFile); 39 | int count; 40 | while ((count = zis.read(buf, 0, 1024)) != -1) 41 | tarfos.write(buf, 0, count); 42 | tarfos.close(); 43 | zis.close(); 44 | 45 | /* now unpack the tar */ 46 | TarInputStream tis = new TarInputStream(new BufferedInputStream( 47 | new FileInputStream(tarFile))); 48 | TarEntry entry; 49 | while ((entry = tis.getNextEntry()) != null) { 50 | File entryFile = new File(dest, entry.getName()); 51 | File parentDir = new File(entryFile.getParent()); 52 | 53 | if (!parentDir.isDirectory() && !parentDir.mkdirs()) { 54 | tis.close(); 55 | throw new IOException( 56 | "TarExtractor.unpack(): unable to create directory"); 57 | } 58 | 59 | if (entry.getName().equals("././@LongLink")) { 60 | // GNU tar format not supported by jtar 61 | // attempt to recover: 62 | // LongLink entry provides full file name for following entry 63 | // -> read file name from body and skip ahead 64 | String filename = ""; 65 | while ((count = tis.read(buf)) != -1) { 66 | filename += new String(buf, 0, count - 1); 67 | } 68 | entry = tis.getNextEntry(); 69 | entryFile = new File(dest, filename); 70 | android.util.Log.v("TarExtractor", 71 | String.format("Encountered long filename." + 72 | " Moving on to: %s:%s -> %s", 73 | entry.getName(), entry.isDirectory(), entryFile)); 74 | } 75 | if (entry.isDirectory()) { 76 | if (entryFile.isDirectory()) { 77 | // directory already exists 78 | android.util.Log.v("TarExtractor", 79 | "directory for " + entry.getName() + " already exists"); 80 | } else if (entryFile.mkdir()) { 81 | // directory created (side effect) 82 | android.util.Log.v("TarExtractor", 83 | "directory created for " + entry.getName()); 84 | } else { 85 | // fail 86 | android.util.Log.w("TarExtractor", 87 | "failed to create directory for " + entry.getName()); 88 | } 89 | } else if (!entryFile.isDirectory()) { 90 | FileOutputStream fos = new FileOutputStream(entryFile); 91 | BufferedOutputStream bos = new BufferedOutputStream(fos); 92 | while ((count = tis.read(buf)) != -1) { 93 | bos.write(buf, 0, count); 94 | } 95 | 96 | bos.flush(); 97 | bos.close(); 98 | } else { 99 | android.util.Log.v("TarExtractor", 100 | String.format("What? %s:%s:%s", entryFile, 101 | entryFile.isDirectory(), entry.isDirectory()) 102 | ); 103 | } 104 | } 105 | tis.close(); 106 | 107 | /* delete the tar file */ 108 | tarFile.delete(); 109 | } 110 | } 111 | -------------------------------------------------------------------------------- /app/src/org/meshpoint/anode/util/ZipExtractor.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2011-2012 Paddy Byers 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package org.meshpoint.anode.util; 18 | 19 | import java.io.File; 20 | import java.io.FileInputStream; 21 | import java.io.FileOutputStream; 22 | import java.io.IOException; 23 | import java.util.zip.ZipEntry; 24 | import java.util.zip.ZipInputStream; 25 | 26 | public class ZipExtractor implements ModuleUtils.Unpacker { 27 | 28 | public void unpack(File src, File dest) throws IOException { 29 | int count; 30 | byte[] buf = new byte[1024]; 31 | ZipInputStream zis = null; 32 | ZipEntry zipentry; 33 | zis = new ZipInputStream(new FileInputStream(src)); 34 | 35 | while ((zipentry = zis.getNextEntry()) != null) { 36 | String entryName = zipentry.getName(); 37 | File entryFile = new File(dest, entryName); 38 | File parentDir = new File(entryFile.getParent()); 39 | if(!parentDir.isDirectory() && !parentDir.mkdirs()) 40 | throw new IOException("ZipExtractor.unpack(): unable to create directory"); 41 | 42 | if(zipentry.isDirectory()) { 43 | if(!entryFile.mkdir()) 44 | throw new IOException("ZipExtractor.unpack(): unable to create directory entry"); 45 | } else { 46 | FileOutputStream fos = new FileOutputStream(entryFile); 47 | while ((count = zis.read(buf, 0, 1024)) != -1) 48 | fos.write(buf, 0, count); 49 | 50 | fos.close(); 51 | } 52 | zis.closeEntry(); 53 | } 54 | zis.close(); 55 | } 56 | 57 | } 58 | -------------------------------------------------------------------------------- /bridge-java/.classpath: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | -------------------------------------------------------------------------------- /bridge-java/.project: -------------------------------------------------------------------------------- 1 | 2 | 3 | bridge-java 4 | 5 | 6 | 7 | 8 | 9 | org.eclipse.jdt.core.javabuilder 10 | 11 | 12 | 13 | 14 | 15 | org.eclipse.jdt.core.javanature 16 | 17 | 18 | -------------------------------------------------------------------------------- /bridge-java/build.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | 29 | -------------------------------------------------------------------------------- /bridge-java/src/org/meshpoint/anode/bridge/BridgeNative.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2011-2012 Paddy Byers 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package org.meshpoint.anode.bridge; 18 | 19 | import java.util.Collection; 20 | 21 | import org.meshpoint.anode.idl.IDLInterface; 22 | 23 | public class BridgeNative { 24 | 25 | private static final String LIBRARY_PATH = System.getenv("NODE_ROOT"); 26 | private static final String BRIDGE_LIBRARY = "bridge.node"; 27 | 28 | static { 29 | try { 30 | System.load(LIBRARY_PATH + '/' + BRIDGE_LIBRARY); 31 | } catch(UnsatisfiedLinkError e) { 32 | System.err.println("Unable to load bridge native library: " + LIBRARY_PATH); 33 | } 34 | } 35 | 36 | /* IFunction */ 37 | native static Object callAsFunction(long envHandle, long instHandle, Object target, Object[] args); 38 | native static Object callAsConstructor(long envHandle, long instHandle, Object[] args); 39 | 40 | /* ICollection */ 41 | native static Object getProperty(long envHandle, long instHandle, String key); 42 | native static void setProperty(long envHandle, long instHandle, String key, Object value); 43 | native static void deleteProperty(long envHandle, long instHandle, String key); 44 | native static boolean containsProperty(long envHandle, long instHandle, String key); 45 | native static Collection properties(long envHandle, long instHandle); 46 | 47 | /* IIndexedCollection */ 48 | public native static Object getIndexedProperty(long envHandle, long instHandle, int elementType, int idx); 49 | public native static void setIndexedProperty(long envHandle, long instHandle, int elementType, int idx, Object value); 50 | public native static void deleteIndexedProperty(long envHandle, long instHandle, int idx); 51 | public native static boolean containsIndex(long envHandle, long instHandle, int idx); 52 | public native static int getLength(long envHandle, long instHandle); 53 | public native static void setLength(long envHandle, long instHandle, int length); 54 | 55 | /* JSInterface */ 56 | public native static Object invokeJSInterface(long envHandle, long instHandle, int classId, int opIdx, Object[] args); 57 | public native static Object getJSInterface(long envHandle, long instHandle, int classId, int attrIdx); 58 | public native static void setJSInterface(long envHandle, long instHandle, int classId, int attrIdx, Object val); 59 | 60 | /* instance handle management */ 61 | native static void releaseObjectHandle(long envHandle, long instHandle, int type); 62 | 63 | /* interface handle management */ 64 | public native static long bindInterface(long envHandle, long parentHandle, IDLInterface iface, int classId, int attrCount, int opCount, Class declaredClass); 65 | public native static void bindAttribute(long envHandle, long ifaceHandle, int attrIdx, int type, String name); 66 | public native static void bindOperation(long envHandle, long ifaceHandle, int opIdx, int type, String name, int argCount, int[] argTypes); 67 | public native static void releaseInterface(long envHandle, long ifaceHandle); 68 | public native static void bindUserStub(long envHandle, long interfaceHandle, Class userStub); 69 | public native static void bindPlatformStub(long envHandle, long interfaceHandle, Class platformStub); 70 | public native static void bindDictStub(long envHandle, long interfaceHandle, Class dictStub); 71 | 72 | /* event thread management */ 73 | public native static void requestEntry(long envHandle); 74 | 75 | /* context initialisation: 76 | * used in the Android implementation to pass an Android context 77 | * object which is then passed to modules implemented in the bridge */ 78 | public native static void setContext(Object opaqueContextObject); 79 | } 80 | -------------------------------------------------------------------------------- /bridge-java/src/org/meshpoint/anode/bridge/FinalizeQueue.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2011-2012 Paddy Byers 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package org.meshpoint.anode.bridge; 18 | 19 | public class FinalizeQueue implements SynchronousOperation { 20 | 21 | /******************** 22 | * private state 23 | ********************/ 24 | private final String TAG = FinalizeQueue.class.getCanonicalName(); 25 | private Env env; 26 | private static final int QUEUE_LENGTH = 1024; 27 | private long[] handleBuffer = new long[QUEUE_LENGTH]; 28 | private int[] typeBuffer = new int[QUEUE_LENGTH]; 29 | private int count; 30 | 31 | /******************** 32 | * public API 33 | *******************/ 34 | 35 | public FinalizeQueue(Env env) { 36 | this.env = env; 37 | } 38 | 39 | /** 40 | * Appends a new item to the queue; may be called 41 | * from any thread 42 | * @param h the handle 43 | */ 44 | public synchronized void put(long h, int type) { 45 | if(count == QUEUE_LENGTH) 46 | env.waitForOperation(this); 47 | if(count == QUEUE_LENGTH) 48 | throw new RuntimeException("Fatal error processing FinalizeQueue"); 49 | handleBuffer[count] = h; 50 | typeBuffer[count++] = type; 51 | } 52 | 53 | /** 54 | * Removes and releases all items currently queued 55 | */ 56 | @Override 57 | public synchronized void run() { 58 | for(int i = 0; i < count; i++) { 59 | //Log.v(TAG, "Finalizing; instHandle = " + handleBuffer[i] + "; type = " + typeBuffer[i]); 60 | BridgeNative.releaseObjectHandle(env.envHandle, handleBuffer[i], typeBuffer[i]); 61 | } 62 | count = 0; 63 | } 64 | 65 | @Override 66 | public synchronized boolean isPending() { 67 | return count > 0; 68 | } 69 | 70 | @Override 71 | public void cancel() {} 72 | } 73 | -------------------------------------------------------------------------------- /bridge-java/src/org/meshpoint/anode/bridge/ModuleContext.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2011-2012 Paddy Byers 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package org.meshpoint.anode.bridge; 18 | 19 | import org.meshpoint.anode.js.JSObject; 20 | import org.meshpoint.anode.module.IModule; 21 | import org.meshpoint.anode.module.IModuleContext; 22 | import org.meshpoint.anode.type.IIndexedCollection; 23 | 24 | public class ModuleContext implements IModuleContext { 25 | @SuppressWarnings("unused") 26 | private Env env; 27 | private JSObject exports; 28 | private IModule module; 29 | private long threadId; 30 | 31 | protected ModuleContext(Env env, JSObject exports) { 32 | this.env = env; 33 | this.exports = exports; 34 | threadId = Thread.currentThread().getId(); 35 | } 36 | 37 | void setModule(IModule module) { 38 | this.module = module; 39 | } 40 | 41 | @Override 42 | public IIndexedCollection getModuleExports() { 43 | return exports; 44 | } 45 | 46 | @Override 47 | public long getEventThreadId() { 48 | return threadId; 49 | } 50 | 51 | public IModule getModule() { 52 | return module; 53 | } 54 | 55 | } 56 | -------------------------------------------------------------------------------- /bridge-java/src/org/meshpoint/anode/bridge/SynchronousOperation.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2011-2012 Paddy Byers 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package org.meshpoint.anode.bridge; 18 | 19 | public interface SynchronousOperation extends Runnable { 20 | public boolean isPending(); 21 | public void cancel(); 22 | } 23 | -------------------------------------------------------------------------------- /bridge-java/src/org/meshpoint/anode/error/GeneralError.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2011-2012 Paddy Byers 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package org.meshpoint.anode.error; 18 | 19 | /** 20 | * An exception type wrapping an arbitrary error code 21 | */ 22 | public class GeneralError extends Exception { 23 | private static final long serialVersionUID = 5692849251925713822L; 24 | public int errno; 25 | public GeneralError(int errno, String msg) {super(msg); this.errno = errno;} 26 | } 27 | -------------------------------------------------------------------------------- /bridge-java/src/org/meshpoint/anode/error/InternalError.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2011-2012 Paddy Byers 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package org.meshpoint.anode.error; 18 | 19 | /** 20 | * An exception type signifying that an internal or VM error occurred 21 | */ 22 | public class InternalError extends Exception { 23 | private static final long serialVersionUID = -4261803988702224429L; 24 | } 25 | -------------------------------------------------------------------------------- /bridge-java/src/org/meshpoint/anode/error/ReferenceError.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2011-2012 Paddy Byers 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package org.meshpoint.anode.error; 18 | 19 | /** 20 | * An exception type signifying that a JavaScript ReferenceError occurred 21 | */ 22 | public class ReferenceError extends Exception { 23 | private static final long serialVersionUID = 6724405414298940337L; 24 | } 25 | -------------------------------------------------------------------------------- /bridge-java/src/org/meshpoint/anode/error/ScriptError.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2011-2012 Paddy Byers 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package org.meshpoint.anode.error; 18 | 19 | /** 20 | * An exception type signifying that an error occurred in the 21 | * execution of a JavaScript callback 22 | */ 23 | public class ScriptError extends Exception { 24 | private static final long serialVersionUID = 5114577282565680809L; 25 | } 26 | -------------------------------------------------------------------------------- /bridge-java/src/org/meshpoint/anode/error/TypeError.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2011-2012 Paddy Byers 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package org.meshpoint.anode.error; 18 | 19 | /** 20 | * An exception type signifying that an error occurred in the 21 | * conversion of types 22 | */ 23 | public class TypeError extends Exception { 24 | private static final long serialVersionUID = 8329224726700461954L; 25 | } 26 | -------------------------------------------------------------------------------- /bridge-java/src/org/meshpoint/anode/idl/BoundInterface.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2011-2012 Paddy Byers 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package org.meshpoint.anode.idl; 18 | 19 | import org.meshpoint.anode.bridge.BridgeNative; 20 | import org.meshpoint.anode.bridge.Env; 21 | import org.meshpoint.anode.idl.IDLInterface.Attribute; 22 | import org.meshpoint.anode.idl.IDLInterface.Operation; 23 | 24 | public class BoundInterface { 25 | private long ifaceHandle; 26 | private Env env; 27 | private IDLInterface iface; 28 | 29 | public BoundInterface(Env env, short classId) { 30 | this.env = env; 31 | iface = env.getInterfaceManager().getById(classId); 32 | } 33 | 34 | public Env getEnv() { return env; } 35 | 36 | public int getType() { return Types.classid2Type(iface.getId()); } 37 | 38 | public void bind() { 39 | /* create native binding for this interface */ 40 | long envHandle = env.getHandle(); 41 | IDLInterface parent = iface.getParent(); 42 | long parentHandle = (parent == null) ? 0 : env.bindInterface(parent.getId()).ifaceHandle; 43 | ifaceHandle = BridgeNative.bindInterface(envHandle, parentHandle, iface, iface.getId(), iface.getAttributes().length, iface.getOperations().length, iface.getJavaClass()); 44 | InterfaceManager mgr = env.getInterfaceManager(); 45 | 46 | /* bind stubs */ 47 | try { 48 | Class userStub = mgr.getStubClass(iface, StubUtil.MODE_USER); 49 | BridgeNative.bindUserStub(envHandle, ifaceHandle, userStub); 50 | } catch(ClassNotFoundException e) {} 51 | try { 52 | Class platformStub = mgr.getStubClass(iface, StubUtil.MODE_PLATFORM); 53 | BridgeNative.bindPlatformStub(envHandle, ifaceHandle, platformStub); 54 | } catch(ClassNotFoundException e) {} 55 | try { 56 | Class dictStub = mgr.getStubClass(iface, StubUtil.MODE_DICT); 57 | BridgeNative.bindDictStub(envHandle, ifaceHandle, dictStub); 58 | } catch(ClassNotFoundException e) {} 59 | 60 | /* bind attributes, including recursively binding attribute types */ 61 | Attribute[] attributes = iface.getAttributes(); 62 | for(int i = 0; i < attributes.length; i++) { 63 | Attribute attr = attributes[i]; 64 | IDLInterface attrType = Types.baseInterface(mgr, attr.type); 65 | if(attrType != null) 66 | env.bindInterface(attrType.getId()); 67 | BridgeNative.bindAttribute(envHandle, ifaceHandle, i, attr.type, attr.name); 68 | } 69 | 70 | /* bind operations, including recursively binding operation and arg types */ 71 | Operation[] operations = iface.getOperations(); 72 | for(int i = 0; i < operations.length; i++) { 73 | Operation op = operations[i]; 74 | IDLInterface opType = Types.baseInterface(mgr, op.type); 75 | if(opType != null) 76 | env.bindInterface(opType.getId()); 77 | for(int j = 0; j < op.args.length; j++) { 78 | IDLInterface argType = Types.baseInterface(mgr, op.args[j]); 79 | if(argType != null) 80 | env.bindInterface(argType.getId()); 81 | } 82 | BridgeNative.bindOperation(envHandle, ifaceHandle, i, op.type, op.name, op.args.length, op.args); 83 | } 84 | } 85 | 86 | public void dispose() { 87 | BridgeNative.releaseInterface(env.getHandle(), ifaceHandle); 88 | } 89 | } 90 | -------------------------------------------------------------------------------- /bridge-java/src/org/meshpoint/anode/idl/Callback.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2011-2012 Paddy Byers 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package org.meshpoint.anode.idl; 18 | 19 | public interface Callback {} 20 | -------------------------------------------------------------------------------- /bridge-java/src/org/meshpoint/anode/idl/Dictionary.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2011-2012 Paddy Byers 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package org.meshpoint.anode.idl; 18 | 19 | public interface Dictionary {} 20 | -------------------------------------------------------------------------------- /bridge-java/src/org/meshpoint/anode/idl/IDLInterface.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2011-2012 Paddy Byers 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package org.meshpoint.anode.idl; 18 | 19 | /** 20 | * An interface defined in IDL for use within one or more modules 21 | * @author paddy 22 | * 23 | */ 24 | public class IDLInterface { 25 | /******************** 26 | * private state 27 | ********************/ 28 | 29 | private static final int MAX_NAME_LENGTH = 80; 30 | private short id = -1; 31 | private String name; 32 | private Class javaClass; 33 | private boolean isCallback; 34 | private boolean isValueType; 35 | 36 | /******************** 37 | * interface metadata 38 | ********************/ 39 | 40 | int modifiers; 41 | IDLInterface parent; 42 | Attribute[] attributes; 43 | Operation[] operations; 44 | 45 | /** 46 | * A class encapsulating the metadata for an attribute 47 | */ 48 | public class Attribute implements Comparable { 49 | public String name; 50 | public int type; 51 | public int modifiers; 52 | @Override 53 | public int compareTo(Attribute attr) { return name.compareTo(attr.name); } 54 | } 55 | 56 | /** 57 | * A class encapsulating the metadata for an operation (method) 58 | */ 59 | public class Operation implements Comparable { 60 | public String name; 61 | public int type; 62 | public int modifiers; 63 | public int[] args; 64 | @Override 65 | public int compareTo(Operation op) { return name.compareTo(op.name); } 66 | } 67 | 68 | /******************** 69 | * public API 70 | ********************/ 71 | 72 | public IDLInterface(InterfaceManager mgr, Class javaClass) { 73 | name = javaClass.getCanonicalName(); 74 | this.javaClass = javaClass; 75 | if(Callback.class.isAssignableFrom(javaClass)) 76 | isCallback = true; 77 | if(Dictionary.class.isAssignableFrom(javaClass)) 78 | isValueType = true; 79 | id = mgr.put(this); 80 | } 81 | 82 | public short getId() { 83 | return id; 84 | } 85 | 86 | public Class getJavaClass() { 87 | return javaClass; 88 | } 89 | 90 | public IDLInterface getParent() { 91 | return parent; 92 | } 93 | 94 | public String getName() { 95 | return name; 96 | } 97 | 98 | public int getModifiers() { 99 | return modifiers; 100 | } 101 | 102 | public Attribute[] getAttributes() { 103 | return attributes; 104 | } 105 | 106 | public Operation[] getOperations() { 107 | return operations; 108 | } 109 | 110 | public String getStubClassname() { 111 | String candidate = StubUtil.uclName(name.replace('.', '_')); 112 | if(candidate.length() > MAX_NAME_LENGTH) { 113 | /* hash the remainder of the name */ 114 | /* FIXME: implement this */ 115 | } 116 | return candidate; 117 | } 118 | 119 | public boolean isCallback() { return isCallback; } 120 | public boolean isValueType() { return isValueType; } 121 | } 122 | -------------------------------------------------------------------------------- /bridge-java/src/org/meshpoint/anode/idl/StubUtil.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2011-2012 Paddy Byers 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package org.meshpoint.anode.idl; 18 | 19 | public class StubUtil { 20 | 21 | public static final int MODE_USER = 0; 22 | public static final int MODE_PLATFORM = 1; 23 | public static final int MODE_DICT = 2; 24 | 25 | public static final String[] modes = new String[]{"user", "platform", "dict"}; 26 | 27 | private static final String STUB_PACKAGE = "org.meshpoint.anode.stub.gen."; 28 | 29 | public static String getStubPackage(int mode) { 30 | return STUB_PACKAGE + modes[mode]; 31 | } 32 | 33 | public static String uclName(String attrName) { 34 | return Character.toUpperCase(attrName.charAt(0)) + attrName.substring(1); 35 | } 36 | 37 | } 38 | -------------------------------------------------------------------------------- /bridge-java/src/org/meshpoint/anode/java/Array.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2011-2012 Paddy Byers 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package org.meshpoint.anode.java; 18 | 19 | public abstract class Array extends Base { 20 | boolean isReadOnly; 21 | boolean isFixedLength; 22 | 23 | protected Array(int type, boolean isFixedLength) { 24 | super(type); 25 | this.isFixedLength = isFixedLength; 26 | } 27 | } 28 | -------------------------------------------------------------------------------- /bridge-java/src/org/meshpoint/anode/java/Base.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2011-2012 Paddy Byers 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package org.meshpoint.anode.java; 18 | 19 | import org.meshpoint.anode.bridge.Env; 20 | import org.meshpoint.anode.idl.Types; 21 | 22 | public class Base { 23 | 24 | /********************* 25 | * private state 26 | *********************/ 27 | private static final String TAG = Base.class.getCanonicalName(); 28 | long instHandle; /* (long)Persistent* */ 29 | protected Env env; 30 | protected int type; 31 | 32 | /********************* 33 | * private API 34 | *********************/ 35 | protected Base(short classId) { 36 | this(classId, Env.getCurrent()); 37 | } 38 | 39 | protected Base(short classId, Env env) { 40 | this.env = env; 41 | env.bindInterface(classId); 42 | type = Types.classid2Type(classId); 43 | } 44 | 45 | protected Base(int type) { 46 | this.type = type; 47 | } 48 | 49 | public void finalize() { 50 | if(instHandle != 0) { 51 | //Log.v(TAG, "Putting for finalization; this class = " + this.getClass().getName() + "; instHandle = " + instHandle + "; type = " + type); 52 | env.finalizeQueue.put(instHandle, type); 53 | } 54 | } 55 | 56 | public Env getEnv() { 57 | return env; 58 | } 59 | } 60 | -------------------------------------------------------------------------------- /bridge-java/src/org/meshpoint/anode/java/ByteArray.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2011-2012 Paddy Byers 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package org.meshpoint.anode.java; 18 | 19 | import org.meshpoint.anode.idl.Types; 20 | 21 | public class ByteArray extends Array implements org.w3c.dom.ByteArray { 22 | private byte[] data; 23 | 24 | public ByteArray(byte[] data) { 25 | this(data, true); 26 | } 27 | 28 | public ByteArray(byte[] data, boolean isFixedLength) { 29 | super(Types.TYPE_BYTE|Types.TYPE_ARRAY, isFixedLength); 30 | this.data = data; 31 | } 32 | 33 | @Override 34 | public int getLength() { 35 | return data.length; 36 | } 37 | 38 | @Override 39 | public void setLength(int length) { 40 | if(isFixedLength) throw new UnsupportedOperationException(); 41 | if(length != data.length) { 42 | byte[] newData = new byte[length]; 43 | System.arraycopy(data, 0, newData, 0, Math.min(length, data.length)); 44 | data = newData; 45 | } 46 | } 47 | 48 | @Override 49 | public byte getElement(int index) { 50 | return data[index]; 51 | } 52 | 53 | @Override 54 | public void setElement(int index, byte value) { 55 | if(!isFixedLength && index >= data.length) { 56 | setLength(index + 1); 57 | for(int i = data.length; i < index; i++) data[i] = value; 58 | } 59 | data[index] = value; 60 | } 61 | 62 | } 63 | -------------------------------------------------------------------------------- /bridge-java/src/org/meshpoint/anode/java/DoubleArray.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2011-2012 Paddy Byers 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package org.meshpoint.anode.java; 18 | 19 | import org.meshpoint.anode.idl.Types; 20 | 21 | public class DoubleArray extends Array implements org.w3c.dom.DoubleArray { 22 | private double[] data; 23 | 24 | public DoubleArray(double[] data) { 25 | this(data, true); 26 | } 27 | 28 | public DoubleArray(double[] data, boolean isFixedLength) { 29 | super(Types.TYPE_DOUBLE|Types.TYPE_ARRAY, isFixedLength); 30 | this.data = data; 31 | } 32 | 33 | @Override 34 | public int getLength() { 35 | return data.length; 36 | } 37 | 38 | @Override 39 | public void setLength(int length) { 40 | if(isFixedLength) throw new UnsupportedOperationException(); 41 | if(length != data.length) { 42 | double[] newData = new double[length]; 43 | System.arraycopy(data, 0, newData, 0, Math.min(length, data.length)); 44 | data = newData; 45 | } 46 | } 47 | 48 | @Override 49 | public double getElement(int index) { 50 | return data[index]; 51 | } 52 | 53 | @Override 54 | public void setElement(int index, double value) { 55 | if(!isFixedLength && index >= data.length) { 56 | setLength(index + 1); 57 | for(int i = data.length; i < index; i++) data[i] = value; 58 | } 59 | data[index] = value; 60 | } 61 | 62 | } 63 | -------------------------------------------------------------------------------- /bridge-java/src/org/meshpoint/anode/java/IntegerArray.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2011-2012 Paddy Byers 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package org.meshpoint.anode.java; 18 | 19 | import org.meshpoint.anode.idl.Types; 20 | 21 | public class IntegerArray extends Array implements org.w3c.dom.IntegerArray { 22 | private int[] data; 23 | 24 | public IntegerArray(int[] data) { 25 | this(data, true); 26 | } 27 | 28 | public IntegerArray(int[] data, boolean isFixedLength) { 29 | super(Types.TYPE_INT|Types.TYPE_ARRAY, isFixedLength); 30 | this.data = data; 31 | } 32 | 33 | @Override 34 | public int getLength() { 35 | return data.length; 36 | } 37 | 38 | @Override 39 | public void setLength(int length) { 40 | if(isFixedLength) throw new UnsupportedOperationException(); 41 | if(length != data.length) { 42 | int[] newData = new int[length]; 43 | System.arraycopy(data, 0, newData, 0, Math.min(length, data.length)); 44 | data = newData; 45 | } 46 | } 47 | 48 | @Override 49 | public int getElement(int index) { 50 | return data[index]; 51 | } 52 | 53 | @Override 54 | public void setElement(int index, int value) { 55 | if(!isFixedLength && index >= data.length) { 56 | setLength(index + 1); 57 | for(int i = data.length; i < index; i++) data[i] = value; 58 | } 59 | data[index] = value; 60 | } 61 | 62 | } 63 | -------------------------------------------------------------------------------- /bridge-java/src/org/meshpoint/anode/java/LongArray.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2011-2012 Paddy Byers 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package org.meshpoint.anode.java; 18 | 19 | import org.meshpoint.anode.idl.Types; 20 | 21 | public class LongArray extends Array implements org.w3c.dom.LongArray { 22 | private long[] data; 23 | 24 | public LongArray(long[] data) { 25 | this(data, true); 26 | } 27 | 28 | public LongArray(long[] data, boolean isFixedLength) { 29 | super(Types.TYPE_LONG|Types.TYPE_ARRAY, isFixedLength); 30 | this.data = data; 31 | } 32 | 33 | @Override 34 | public int getLength() { 35 | return data.length; 36 | } 37 | 38 | @Override 39 | public void setLength(int length) { 40 | if(isFixedLength) throw new UnsupportedOperationException(); 41 | if(length != data.length) { 42 | long[] newData = new long[length]; 43 | System.arraycopy(data, 0, newData, 0, Math.min(length, data.length)); 44 | data = newData; 45 | } 46 | } 47 | 48 | @Override 49 | public long getElement(int index) { 50 | return data[index]; 51 | } 52 | 53 | @Override 54 | public void setElement(int index, long value) { 55 | if(!isFixedLength && index >= data.length) { 56 | setLength(index + 1); 57 | for(int i = data.length; i < index; i++) data[i] = value; 58 | } 59 | data[index] = value; 60 | } 61 | 62 | } 63 | -------------------------------------------------------------------------------- /bridge-java/src/org/meshpoint/anode/java/ObjectArray.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2011-2012 Paddy Byers 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package org.meshpoint.anode.java; 18 | 19 | import org.meshpoint.anode.idl.InterfaceManager; 20 | import org.meshpoint.anode.idl.Types; 21 | 22 | public class ObjectArray extends Array implements org.w3c.dom.ObjectArray { 23 | private Object[] data; 24 | 25 | public ObjectArray(T[] data) { 26 | this(data, true); 27 | } 28 | 29 | public ObjectArray(T[] data, boolean isFixedLength) { 30 | super(0, isFixedLength); 31 | this.data = data; 32 | type = Types.fromJavaType(InterfaceManager.getInstance(), data.getClass()); 33 | } 34 | 35 | @Override 36 | public int getLength() { 37 | return data.length; 38 | } 39 | 40 | @Override 41 | public void setLength(int length) { 42 | if(isFixedLength) throw new UnsupportedOperationException(); 43 | if(length != data.length) { 44 | Object[] newData = new Object[length]; 45 | System.arraycopy(data, 0, newData, 0, Math.min(length, data.length)); 46 | data = newData; 47 | } 48 | } 49 | 50 | @SuppressWarnings("unchecked") 51 | @Override 52 | public T getElement(int index) { 53 | return (T)data[index]; 54 | } 55 | 56 | @Override 57 | public void setElement(int index, T value) { 58 | if(!isFixedLength && index >= data.length) { 59 | setLength(index + 1); 60 | for(int i = data.length; i < index; i++) data[i] = value; 61 | } 62 | data[index] = value; 63 | } 64 | 65 | } 66 | -------------------------------------------------------------------------------- /bridge-java/src/org/meshpoint/anode/js/JSArray.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2011-2012 Paddy Byers 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package org.meshpoint.anode.js; 18 | 19 | import org.meshpoint.anode.bridge.BridgeNative; 20 | import org.meshpoint.anode.bridge.Env; 21 | import org.meshpoint.anode.bridge.SynchronousOperation; 22 | import org.w3c.dom.Array; 23 | 24 | public class JSArray implements Array { 25 | 26 | /********************* 27 | * private state 28 | *********************/ 29 | 30 | private static final String TAG = JSArray.class.getCanonicalName(); 31 | long instHandle; /* (long)Persistent* */ 32 | Env env; 33 | 34 | /********************* 35 | * private API 36 | *********************/ 37 | 38 | JSArray(long instHandle) { 39 | this.instHandle = instHandle; 40 | env = Env.getCurrent(); 41 | } 42 | 43 | protected void dispose(int type) { 44 | //Log.v(TAG, "Putting for finalization; this class = " + this.getClass().getName() + "; instHandle = " + instHandle + "; type = " + type); 45 | env.finalizeQueue.put(instHandle, type); 46 | } 47 | 48 | /********************* 49 | * public API 50 | *********************/ 51 | 52 | public int getLength() { 53 | if(env.isEventThread()) 54 | return BridgeNative.getLength(env.getHandle(), instHandle); 55 | SyncOp op = deferOp(OP.GET_LENGTH, env, instHandle, 0, 0, null); 56 | return (op == null) ? 0 : op.idxOrLength; 57 | } 58 | 59 | public void setLength(int length) { 60 | if(env.isEventThread()) 61 | BridgeNative.setLength(env.getHandle(), instHandle, length); 62 | deferOp(OP.SET_LENGTH, env, instHandle, 0, length, null); 63 | } 64 | 65 | protected SyncOp deferOp(OP op, Env env, long instHandle, int elementType, int idxOrLength, Object val) { 66 | SyncOp syncOp = threadSyncOp.get(); 67 | if(syncOp == null) { 68 | syncOp = new SyncOp(); 69 | threadSyncOp.set(syncOp); 70 | } 71 | return syncOp.scheduleWait(op, env, instHandle, elementType, idxOrLength, val); 72 | } 73 | 74 | /********************* 75 | * SynchronousOperation 76 | *********************/ 77 | 78 | protected enum OP {GET_LENGTH, SET_LENGTH, GET_ELEMENT, SET_ELEMENT}; 79 | 80 | protected static ThreadLocal threadSyncOp = new ThreadLocal(); 81 | 82 | protected static class SyncOp implements SynchronousOperation { 83 | 84 | private OP op; 85 | private Env env; 86 | private long instHandle; 87 | Object ob; 88 | private int idxOrLength; 89 | private int elementType; 90 | private boolean isPending; 91 | private boolean isCancelled; 92 | 93 | @Override 94 | public void run() { 95 | switch(op) { 96 | case GET_LENGTH: 97 | idxOrLength = BridgeNative.getLength(env.getHandle(), instHandle); 98 | break; 99 | case SET_LENGTH: 100 | BridgeNative.setLength(env.getHandle(), instHandle, idxOrLength); 101 | break; 102 | case GET_ELEMENT: 103 | ob = BridgeNative.getIndexedProperty(env.getHandle(), instHandle, elementType, idxOrLength); 104 | break; 105 | case SET_ELEMENT: 106 | BridgeNative.setIndexedProperty(env.getHandle(), instHandle, elementType, idxOrLength, ob); 107 | break; 108 | } 109 | isPending = false; 110 | } 111 | 112 | @Override 113 | public boolean isPending() {return isPending;} 114 | 115 | private SyncOp scheduleWait(OP op, Env env, long instHandle, int elementType, int idxOrLength, Object val) { 116 | this.op = op; 117 | this.env = env; 118 | this.instHandle = instHandle; 119 | this.elementType = elementType; 120 | this.idxOrLength = idxOrLength; 121 | this.ob = val; 122 | this.isPending = true; 123 | this.isCancelled = false; 124 | /* FIXME: consider not waiting if void */ 125 | env.waitForOperation(this); 126 | return isCancelled ? null : this; 127 | } 128 | 129 | @Override 130 | public void cancel() { 131 | isCancelled = true; 132 | isPending = false; 133 | } 134 | } 135 | } 136 | -------------------------------------------------------------------------------- /bridge-java/src/org/meshpoint/anode/js/JSByteArray.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2011-2012 Paddy Byers 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package org.meshpoint.anode.js; 18 | 19 | import org.meshpoint.anode.bridge.BridgeNative; 20 | import org.meshpoint.anode.idl.Types; 21 | import org.w3c.dom.ByteArray; 22 | 23 | public class JSByteArray extends JSArray implements ByteArray { 24 | 25 | JSByteArray(long instHandle) { super(instHandle);} 26 | 27 | public void finalize() { super.dispose(Types.TYPE_BYTE|Types.TYPE_ARRAY); } 28 | 29 | /********************* 30 | * public API 31 | *********************/ 32 | 33 | @Override 34 | public byte getElement(int index) { 35 | if(env.isEventThread()) { 36 | return (byte)((JSValue)BridgeNative.getIndexedProperty(env.getHandle(), instHandle, Types.TYPE_BYTE, index)).getLongValue(); 37 | } 38 | SyncOp op = deferOp(OP.GET_ELEMENT, env, instHandle, Types.TYPE_BYTE, index, null); 39 | if(op == null) return 0; 40 | return (byte)((JSValue)op.ob).getLongValue(); 41 | } 42 | 43 | @Override 44 | public void setElement(int index, byte value) { 45 | Object element = JSValue.asJSNumber((long)value); 46 | if(env.isEventThread()) 47 | BridgeNative.setIndexedProperty(env.getHandle(), instHandle, Types.TYPE_BYTE, index, element); 48 | else 49 | deferOp(OP.SET_ELEMENT, env, instHandle, Types.TYPE_BYTE, index, element); 50 | } 51 | 52 | } 53 | -------------------------------------------------------------------------------- /bridge-java/src/org/meshpoint/anode/js/JSDoubleArray.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2011-2012 Paddy Byers 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package org.meshpoint.anode.js; 18 | 19 | import org.meshpoint.anode.bridge.BridgeNative; 20 | import org.meshpoint.anode.idl.Types; 21 | import org.w3c.dom.DoubleArray; 22 | 23 | public class JSDoubleArray extends JSArray implements DoubleArray { 24 | 25 | JSDoubleArray(long instHandle) { super(instHandle); } 26 | 27 | public void finalize() { super.dispose(Types.TYPE_DOUBLE|Types.TYPE_ARRAY); } 28 | 29 | /********************* 30 | * public API 31 | *********************/ 32 | 33 | @Override 34 | public double getElement(int index) { 35 | if(env.isEventThread()) { 36 | return ((JSValue)BridgeNative.getIndexedProperty(env.getHandle(), instHandle, Types.TYPE_DOUBLE, index)).getDoubleValue(); 37 | } 38 | SyncOp op = deferOp(OP.GET_ELEMENT, env, instHandle, Types.TYPE_DOUBLE, index, null); 39 | if(op == null) return 0; 40 | return ((JSValue)op.ob).getDoubleValue(); 41 | } 42 | 43 | @Override 44 | public void setElement(int index, double value) { 45 | Object element = JSValue.asJSNumber(value); 46 | if(env.isEventThread()) 47 | BridgeNative.setIndexedProperty(env.getHandle(), instHandle, Types.TYPE_DOUBLE, index, element); 48 | else 49 | deferOp(OP.SET_ELEMENT, env, instHandle, Types.TYPE_DOUBLE, index, element); 50 | } 51 | 52 | } 53 | -------------------------------------------------------------------------------- /bridge-java/src/org/meshpoint/anode/js/JSFunction.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2011-2012 Paddy Byers 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package org.meshpoint.anode.js; 18 | 19 | import org.meshpoint.anode.type.IFunction; 20 | 21 | public class JSFunction extends JSObject implements IFunction { 22 | 23 | JSFunction(long instHandle) { 24 | super(instHandle); 25 | } 26 | 27 | @Override 28 | public Object callAsFunction(Object target, Object[] args) { 29 | // TODO Auto-generated method stub 30 | return null; 31 | } 32 | 33 | @Override 34 | public Object callAsConstructor(Object[] args) { 35 | // TODO Auto-generated method stub 36 | return null; 37 | } 38 | 39 | } 40 | -------------------------------------------------------------------------------- /bridge-java/src/org/meshpoint/anode/js/JSIntegerArray.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2011-2012 Paddy Byers 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package org.meshpoint.anode.js; 18 | 19 | import org.meshpoint.anode.bridge.BridgeNative; 20 | import org.meshpoint.anode.idl.Types; 21 | import org.w3c.dom.IntegerArray; 22 | 23 | public class JSIntegerArray extends JSArray implements IntegerArray { 24 | 25 | JSIntegerArray(long instHandle) { super(instHandle); } 26 | 27 | public void finalize() { super.dispose(Types.TYPE_INT|Types.TYPE_ARRAY); } 28 | 29 | /********************* 30 | * public API 31 | *********************/ 32 | 33 | @Override 34 | public int getElement(int index) { 35 | if(env.isEventThread()) { 36 | return (int)((JSValue)BridgeNative.getIndexedProperty(env.getHandle(), instHandle, Types.TYPE_INT, index)).getLongValue(); 37 | } 38 | SyncOp op = deferOp(OP.GET_ELEMENT, env, instHandle, Types.TYPE_INT, index, null); 39 | if(op == null) return 0; 40 | return (int)((JSValue)op.ob).getLongValue(); 41 | } 42 | 43 | @Override 44 | public void setElement(int index, int value) { 45 | Object element = JSValue.asJSNumber((long)value); 46 | if(env.isEventThread()) 47 | BridgeNative.setIndexedProperty(env.getHandle(), instHandle, Types.TYPE_INT, index, element); 48 | else 49 | deferOp(OP.SET_ELEMENT, env, instHandle, Types.TYPE_INT, index, element); 50 | } 51 | 52 | } 53 | -------------------------------------------------------------------------------- /bridge-java/src/org/meshpoint/anode/js/JSInterface.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2011-2012 Paddy Byers 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package org.meshpoint.anode.js; 18 | 19 | import org.meshpoint.anode.bridge.BridgeNative; 20 | import org.meshpoint.anode.bridge.Env; 21 | import org.meshpoint.anode.bridge.SynchronousOperation; 22 | import org.meshpoint.anode.idl.Types; 23 | 24 | public class JSInterface { 25 | 26 | /********************* 27 | * private state 28 | *********************/ 29 | private static final String TAG = JSInterface.class.getCanonicalName(); 30 | long instHandle; /* (long)Persistent* */ 31 | protected Env env = Env.getCurrent(); 32 | 33 | /********************* 34 | * private API 35 | *********************/ 36 | protected JSInterface(long instHandle) { 37 | this.instHandle = instHandle; 38 | } 39 | 40 | public void release(int classId) { 41 | //Log.v(TAG, "Putting for finalization; this class = " + this.getClass().getName() + "; instHandle = " + instHandle + "; classId = " + classId); 42 | env.finalizeQueue.put(instHandle, Types.classid2Type(classId)); 43 | } 44 | 45 | /********************* 46 | * bridge API 47 | *********************/ 48 | protected Object __invoke(int classId, int opIdx, Object[] args) { 49 | if(env.isEventThread()) 50 | return BridgeNative.invokeJSInterface(env.getHandle(), instHandle, classId, opIdx, args); 51 | return deferOp(OP.INVOKE, env, instHandle, classId, opIdx, null, args); 52 | } 53 | 54 | protected Object __get(int classId, int attrIdx) { 55 | if(env.isEventThread()) 56 | return BridgeNative.getJSInterface(env.getHandle(), instHandle, classId, attrIdx); 57 | return deferOp(OP.GET, env, instHandle, classId, attrIdx, null, null); 58 | 59 | } 60 | 61 | protected void __set(int classId, int attrIdx, Object val) { 62 | if(env.isEventThread()) 63 | BridgeNative.setJSInterface(env.getHandle(), instHandle, classId, attrIdx, val); 64 | deferOp(OP.SET, env, instHandle, classId, attrIdx, val, null); 65 | } 66 | 67 | private Object deferOp(OP op, Env env, long instHandle, int classId, int idx, Object val, Object[] args) { 68 | SyncOp syncOp = threadSyncOp.get(); 69 | if(syncOp == null) { 70 | syncOp = new SyncOp(); 71 | threadSyncOp.set(syncOp); 72 | } 73 | return syncOp.scheduleWait(op, env, instHandle, classId, idx, val, args); 74 | } 75 | 76 | /********************* 77 | * SynchronousOperation 78 | *********************/ 79 | 80 | private enum OP {INVOKE, GET, SET}; 81 | 82 | private static ThreadLocal threadSyncOp = new ThreadLocal(); 83 | 84 | private static class SyncOp implements SynchronousOperation { 85 | 86 | private Env env; 87 | private long instHandle; 88 | private int classId; 89 | private OP op; 90 | private Object[] args; 91 | private Object ob; 92 | private int idx; 93 | private boolean isPending; 94 | private boolean isCancelled; 95 | 96 | @Override 97 | public void run() { 98 | switch(op) { 99 | case INVOKE: 100 | ob = BridgeNative.invokeJSInterface(env.getHandle(), instHandle, classId, idx, args); 101 | break; 102 | case GET: 103 | ob = BridgeNative.getJSInterface(env.getHandle(), instHandle, classId, idx); 104 | break; 105 | case SET: 106 | BridgeNative.setJSInterface(env.getHandle(), instHandle, classId, idx, ob); 107 | break; 108 | } 109 | isPending = false; 110 | } 111 | 112 | @Override 113 | public boolean isPending() {return isPending;} 114 | 115 | private Object scheduleWait(OP op, Env env, long instHandle, int classId, int idx, Object val, Object[] args) { 116 | this.op = op; 117 | this.env = env; 118 | this.instHandle = instHandle; 119 | this.classId = classId; 120 | this.idx = idx; 121 | this.ob = val; 122 | this.args = args; 123 | this.isPending = true; 124 | this.isCancelled = false; 125 | /* FIXME: consider not waiting if void */ 126 | env.waitForOperation(this); 127 | return isCancelled ? null : ob; 128 | } 129 | 130 | @Override 131 | public void cancel() { 132 | isCancelled = true; 133 | isPending = false; 134 | } 135 | } 136 | } 137 | -------------------------------------------------------------------------------- /bridge-java/src/org/meshpoint/anode/js/JSLongArray.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2011-2012 Paddy Byers 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package org.meshpoint.anode.js; 18 | 19 | import org.meshpoint.anode.bridge.BridgeNative; 20 | import org.meshpoint.anode.idl.Types; 21 | import org.w3c.dom.LongArray; 22 | 23 | public class JSLongArray extends JSArray implements LongArray { 24 | 25 | JSLongArray(long instHandle) { super(instHandle); } 26 | 27 | public void finalize() { super.dispose(Types.TYPE_LONG|Types.TYPE_ARRAY); } 28 | 29 | /********************* 30 | * public API 31 | *********************/ 32 | 33 | @Override 34 | public long getElement(int index) { 35 | if(env.isEventThread()) { 36 | return ((JSValue)BridgeNative.getIndexedProperty(env.getHandle(), instHandle, Types.TYPE_LONG, index)).getLongValue(); 37 | } 38 | SyncOp op = deferOp(OP.GET_ELEMENT, env, instHandle, Types.TYPE_LONG, index, null); 39 | if(op == null) return 0; 40 | return ((JSValue)op.ob).getLongValue(); 41 | } 42 | 43 | @Override 44 | public void setElement(int index, long value) { 45 | Object element = JSValue.asJSNumber(value); 46 | if(env.isEventThread()) 47 | BridgeNative.setIndexedProperty(env.getHandle(), instHandle, Types.TYPE_LONG, index, element); 48 | else 49 | deferOp(OP.SET_ELEMENT, env, instHandle, Types.TYPE_LONG, index, element); 50 | } 51 | 52 | } 53 | -------------------------------------------------------------------------------- /bridge-java/src/org/meshpoint/anode/js/JSObject.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2011-2012 Paddy Byers 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package org.meshpoint.anode.js; 18 | 19 | import java.util.Collection; 20 | 21 | import org.meshpoint.anode.bridge.Env; 22 | import org.meshpoint.anode.type.ICollection; 23 | import org.meshpoint.anode.type.IIndexedCollection; 24 | 25 | /** 26 | * An object that is a wrapper of a native JS object 27 | * @author paddy 28 | * 29 | */ 30 | public class JSObject implements ICollection, IIndexedCollection { 31 | 32 | /********************* 33 | * private state 34 | *********************/ 35 | private static final String TAG = JSObject.class.getCanonicalName(); 36 | long instHandle; /* (long)Persistent* */ 37 | Env env; 38 | 39 | /********************* 40 | * private API 41 | *********************/ 42 | 43 | JSObject(long instHandle) { 44 | this.instHandle = instHandle; 45 | env = Env.getCurrent(); 46 | } 47 | 48 | public void finalize() { 49 | //Log.v(TAG, "Putting for finalization; this class = " + this.getClass().getName() + "; instHandle = " + instHandle + "; classId = " + -1); 50 | env.finalizeQueue.put(instHandle, -1); 51 | } 52 | 53 | /********************* 54 | * public API 55 | *********************/ 56 | 57 | @Override 58 | public Object getIndexedProperty(int idx) { 59 | // TODO Auto-generated method stub 60 | return null; 61 | } 62 | 63 | @Override 64 | public void setIndexedProperty(int idx, Object value) { 65 | // TODO Auto-generated method stub 66 | 67 | } 68 | 69 | @Override 70 | public void deleteIndexedProperty(int idx) { 71 | // TODO Auto-generated method stub 72 | 73 | } 74 | 75 | @Override 76 | public boolean containsIndex(int idx) { 77 | // TODO Auto-generated method stub 78 | return false; 79 | } 80 | 81 | @Override 82 | public int length() { 83 | // TODO Auto-generated method stub 84 | return 0; 85 | } 86 | 87 | @Override 88 | public Object getProperty(String key) { 89 | // TODO Auto-generated method stub 90 | return null; 91 | } 92 | 93 | @Override 94 | public void setProperty(String key, Object value) { 95 | // TODO Auto-generated method stub 96 | 97 | } 98 | 99 | @Override 100 | public void deleteProperty(String key) { 101 | // TODO Auto-generated method stub 102 | 103 | } 104 | 105 | @Override 106 | public boolean containsProperty(String key) { 107 | // TODO Auto-generated method stub 108 | return false; 109 | } 110 | 111 | @Override 112 | public Collection properties() { 113 | // TODO Auto-generated method stub 114 | return null; 115 | } 116 | 117 | } 118 | -------------------------------------------------------------------------------- /bridge-java/src/org/meshpoint/anode/js/JSObjectArray.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2011-2012 Paddy Byers 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package org.meshpoint.anode.js; 18 | 19 | import org.meshpoint.anode.bridge.BridgeNative; 20 | import org.meshpoint.anode.idl.Types; 21 | import org.w3c.dom.ObjectArray; 22 | 23 | public class JSObjectArray extends JSArray implements ObjectArray { 24 | 25 | private int componentType; 26 | JSObjectArray(long instHandle, int componentType) { 27 | super(instHandle); 28 | this.componentType = componentType; 29 | } 30 | 31 | public void finalize() { super.dispose(Types.TYPE_OBJECT|Types.TYPE_ARRAY); } 32 | 33 | @SuppressWarnings("unchecked") 34 | @Override 35 | public T getElement(int index) { 36 | if(env.isEventThread()) 37 | return (T)BridgeNative.getIndexedProperty(env.getHandle(), instHandle, componentType, index); 38 | return (T)deferOp(OP.GET_ELEMENT, env, instHandle, componentType, index, null).ob; 39 | } 40 | 41 | @Override 42 | public void setElement(int index, T value) { 43 | if(env.isEventThread()) 44 | BridgeNative.setIndexedProperty(env.getHandle(), instHandle, componentType, index, value); 45 | deferOp(OP.SET_ELEMENT, env, instHandle, componentType, index, value); 46 | } 47 | 48 | } 49 | -------------------------------------------------------------------------------- /bridge-java/src/org/meshpoint/anode/js/JSValue.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2011-2012 Paddy Byers 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package org.meshpoint.anode.js; 18 | 19 | import org.meshpoint.anode.idl.Types; 20 | 21 | /** 22 | * A variant to hold an arbitrary value, plus a pool of free 23 | * variant instances. The pool is grown on demand. 24 | * 25 | * The re-pooled objects are freed if the number available 26 | * exceeds a hard-coded count. 27 | */ 28 | public final class JSValue { 29 | 30 | /************************ 31 | * private state 32 | ************************/ 33 | 34 | int type; 35 | public long longValue; 36 | public double dblValue; 37 | 38 | /************************ 39 | * public API 40 | ************************/ 41 | 42 | /** 43 | * JSNumber 44 | */ 45 | public static JSValue asJSNumber(long l) { 46 | JSValue result = get(); 47 | result.longValue = l; 48 | result.type = Types.TYPE_LONG; 49 | return result; 50 | } 51 | 52 | public static JSValue asJSNumber(double d) { 53 | JSValue result = get(); 54 | result.dblValue = d; 55 | result.type = Types.TYPE_DOUBLE; 56 | return result; 57 | } 58 | 59 | public static JSValue asJSNumber(Number n) { 60 | JSValue result = get(); 61 | Class nClass = n.getClass(); 62 | if(nClass == Float.class || nClass == Double.class) { 63 | result.dblValue = n.doubleValue(); 64 | } else { 65 | result.longValue = n.longValue(); 66 | if(nClass == Short.class) 67 | result.type = Types.TYPE_SHORT; 68 | else if(nClass == Integer.class) 69 | result.type = Types.TYPE_INT; 70 | else 71 | result.type = Types.TYPE_LONG; 72 | } 73 | return result; 74 | } 75 | 76 | public long getLongValue() { 77 | switch(type) { 78 | case Types.TYPE_BYTE: 79 | case Types.TYPE_SHORT: 80 | case Types.TYPE_INT: 81 | case Types.TYPE_LONG: 82 | return longValue; 83 | } 84 | throw new Types.TypeError(); 85 | } 86 | 87 | public double getDoubleValue() { 88 | if(type == Types.TYPE_DOUBLE) 89 | return dblValue; 90 | throw new Types.TypeError(); 91 | } 92 | 93 | public Number getNumberValue() { 94 | Number result; 95 | switch(type) { 96 | case Types.TYPE_BYTE: 97 | result = new Byte((byte)longValue); 98 | break; 99 | case Types.TYPE_SHORT: 100 | result = new Short((short)longValue); 101 | break; 102 | case Types.TYPE_INT: 103 | result = new Integer((int)longValue); 104 | break; 105 | case Types.TYPE_LONG: 106 | result = new Long(longValue); 107 | break; 108 | case Types.TYPE_DOUBLE: 109 | result = new Double(dblValue); 110 | break; 111 | default: 112 | throw new Types.TypeError(); 113 | } 114 | return result; 115 | } 116 | 117 | /** 118 | * JSBoolean 119 | */ 120 | public static JSValue asJSBoolean(boolean b) { 121 | JSValue result = get(); 122 | result.longValue = b ? 1 : 0; 123 | result.type = Types.TYPE_BOOL; 124 | return result; 125 | } 126 | 127 | public static JSValue asJSBoolean(Boolean b) { 128 | JSValue result = get(); 129 | result.longValue = b.booleanValue() ? 1 : 0; 130 | result.type = Types.TYPE_BOOL; 131 | return result; 132 | } 133 | 134 | public boolean getBooleanValue() { 135 | if(type == Types.TYPE_BOOL) 136 | return longValue != 0; 137 | throw new Types.TypeError(); 138 | } 139 | 140 | /** 141 | * The maximum number of cached instances 142 | */ 143 | final static int MAX_POOL_COUNT = 256; 144 | 145 | /** 146 | * The current count of cached instances 147 | */ 148 | private static int count; 149 | 150 | /** 151 | * The head of the pool 152 | */ 153 | private static JSValue pool; 154 | 155 | /** 156 | * Get a Variant instance from the pool, allocating one if necessary 157 | * @return Variant instance 158 | */ 159 | static synchronized JSValue get() { 160 | if(pool == null) { 161 | pool = new JSValue(); 162 | ++count; 163 | } 164 | JSValue result = pool; 165 | pool = result.next; 166 | --count; 167 | return result; 168 | } 169 | 170 | /** 171 | * Return a Variant to the pool 172 | * @param val the Variant to be returned 173 | */ 174 | synchronized void put(JSValue val) { 175 | if(count < MAX_POOL_COUNT) { 176 | val.next = pool; 177 | pool = val; 178 | ++count; 179 | } 180 | } 181 | 182 | /** 183 | * Pointer for the pool list 184 | */ 185 | private JSValue next; 186 | } 187 | -------------------------------------------------------------------------------- /bridge-java/src/org/meshpoint/anode/module/IModule.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2011-2012 Paddy Byers 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package org.meshpoint.anode.module; 18 | 19 | public interface IModule { 20 | public Object startModule(IModuleContext ctx); 21 | public void stopModule(); 22 | } 23 | -------------------------------------------------------------------------------- /bridge-java/src/org/meshpoint/anode/module/IModuleContext.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2011-2012 Paddy Byers 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package org.meshpoint.anode.module; 18 | 19 | public interface IModuleContext { 20 | public Object getModuleExports(); 21 | public long getEventThreadId(); 22 | } 23 | -------------------------------------------------------------------------------- /bridge-java/src/org/meshpoint/anode/type/ICollection.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2011-2012 Paddy Byers 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package org.meshpoint.anode.type; 18 | 19 | import java.util.Collection; 20 | 21 | public interface ICollection { 22 | public Object getProperty(String key); 23 | public void setProperty(String key, Object value); 24 | public void deleteProperty(String key); 25 | public boolean containsProperty(String key); 26 | public Collection properties(); 27 | } 28 | -------------------------------------------------------------------------------- /bridge-java/src/org/meshpoint/anode/type/IFunction.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2011-2012 Paddy Byers 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package org.meshpoint.anode.type; 18 | 19 | public interface IFunction { 20 | public Object callAsFunction(Object target, Object[] args); 21 | public Object callAsConstructor(Object[] args); 22 | } 23 | -------------------------------------------------------------------------------- /bridge-java/src/org/meshpoint/anode/type/IIndexedCollection.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2011-2012 Paddy Byers 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package org.meshpoint.anode.type; 18 | 19 | public interface IIndexedCollection { 20 | public T getIndexedProperty(int idx); 21 | public void setIndexedProperty(int idx, T value); 22 | public void deleteIndexedProperty(int idx); 23 | public boolean containsIndex(int idx); 24 | public int length(); 25 | } 26 | -------------------------------------------------------------------------------- /bridge-java/src/org/meshpoint/anode/util/PrintStreamLog.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2011-2012 Paddy Byers 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package org.meshpoint.anode.util; 18 | 19 | import java.io.PrintStream; 20 | 21 | public class PrintStreamLog implements Log { 22 | 23 | public PrintStreamLog(PrintStream ps) { 24 | this.ps = ps; 25 | } 26 | 27 | @Override 28 | public int v(String tag, String msg) { 29 | print(severities[VERBOSE], tag, msg, null); 30 | return 0; 31 | } 32 | 33 | @Override 34 | public int v(String tag, String msg, Throwable tr) { 35 | print(severities[VERBOSE], tag, msg, tr); 36 | return 0; 37 | } 38 | 39 | @Override 40 | public int d(String tag, String msg) { 41 | print(severities[DEBUG], tag, msg, null); 42 | return 0; 43 | } 44 | 45 | @Override 46 | public int d(String tag, String msg, Throwable tr) { 47 | print(severities[DEBUG], tag, msg, tr); 48 | return 0; 49 | } 50 | 51 | @Override 52 | public int i(String tag, String msg) { 53 | print(severities[INFO], tag, msg, null); 54 | return 0; 55 | } 56 | 57 | @Override 58 | public int i(String tag, String msg, Throwable tr) { 59 | print(severities[INFO], tag, msg, tr); 60 | return 0; 61 | } 62 | 63 | @Override 64 | public int w(String tag, String msg) { 65 | print(severities[WARN], tag, msg, null); 66 | return 0; 67 | } 68 | 69 | @Override 70 | public int w(String tag, String msg, Throwable tr) { 71 | print(severities[WARN], tag, msg, tr); 72 | return 0; 73 | } 74 | 75 | @Override 76 | public int w(String tag, Throwable tr) { 77 | print(severities[WARN], tag, null, tr); 78 | return 0; 79 | } 80 | 81 | @Override 82 | public int e(String tag, String msg) { 83 | print(severities[ERROR], tag, msg, null); 84 | return 0; 85 | } 86 | 87 | @Override 88 | public int e(String tag, String msg, Throwable tr) { 89 | print(severities[ERROR], tag, msg, tr); 90 | return 0; 91 | } 92 | 93 | @Override 94 | public int wtf(String tag, String msg) { 95 | print(severities[ASSERT], tag, msg, null); 96 | return 0; 97 | } 98 | 99 | @Override 100 | public int wtf(String tag, Throwable tr) { 101 | print(severities[ASSERT], tag, null, tr); 102 | return 0; 103 | } 104 | 105 | @Override 106 | public int wtf(String tag, String msg, Throwable tr) { 107 | print(severities[ASSERT], tag, msg, tr); 108 | return 0; 109 | } 110 | 111 | private PrintStream ps; 112 | private String[] severities = new String[]{"", "", "VERBOSE", "DEBUG", "INFO", "WARN", "ERROR", "ASSERT"}; 113 | 114 | private void print(String severity, String tag, String msg, Throwable tr) { 115 | ps.print("(" + severity + "): "); 116 | if(tag != null && tag.length() != 0) 117 | ps.print(tag + ": "); 118 | if(msg != null && msg.length() != 0) 119 | ps.print(msg); 120 | ps.println(); 121 | if(tr != null) { 122 | tr.printStackTrace(ps); 123 | } 124 | } 125 | } 126 | -------------------------------------------------------------------------------- /bridge-java/src/org/w3c/dom/Array.java: -------------------------------------------------------------------------------- 1 | package org.w3c.dom; 2 | 3 | public interface Array {} 4 | -------------------------------------------------------------------------------- /bridge-java/src/org/w3c/dom/ByteArray.java: -------------------------------------------------------------------------------- 1 | package org.w3c.dom; 2 | 3 | public interface ByteArray extends PrimitiveArray { 4 | public int getLength(); 5 | public void setLength(int length); 6 | public byte getElement(int index); 7 | public void setElement(int index, byte value); 8 | } 9 | -------------------------------------------------------------------------------- /bridge-java/src/org/w3c/dom/DoubleArray.java: -------------------------------------------------------------------------------- 1 | package org.w3c.dom; 2 | 3 | public interface DoubleArray extends PrimitiveArray { 4 | public int getLength(); 5 | public void setLength(int length); 6 | public double getElement(int index); 7 | public void setElement(int index, double value); 8 | } 9 | -------------------------------------------------------------------------------- /bridge-java/src/org/w3c/dom/IntegerArray.java: -------------------------------------------------------------------------------- 1 | package org.w3c.dom; 2 | 3 | public interface IntegerArray extends PrimitiveArray { 4 | public int getLength(); 5 | public void setLength(int length); 6 | public int getElement(int index); 7 | public void setElement(int index, int value); 8 | } 9 | -------------------------------------------------------------------------------- /bridge-java/src/org/w3c/dom/LongArray.java: -------------------------------------------------------------------------------- 1 | package org.w3c.dom; 2 | 3 | public interface LongArray extends PrimitiveArray { 4 | public int getLength(); 5 | public void setLength(int length); 6 | public long getElement(int index); 7 | public void setElement(int index, long value); 8 | } 9 | -------------------------------------------------------------------------------- /bridge-java/src/org/w3c/dom/ObjectArray.java: -------------------------------------------------------------------------------- 1 | package org.w3c.dom; 2 | 3 | public interface ObjectArray extends Array { 4 | public int getLength(); 5 | public void setLength(int length); 6 | public T getElement(int index); 7 | public void setElement(int index, T value); 8 | } 9 | -------------------------------------------------------------------------------- /bridge-java/src/org/w3c/dom/PrimitiveArray.java: -------------------------------------------------------------------------------- 1 | package org.w3c.dom; 2 | 3 | public interface PrimitiveArray extends Array { 4 | 5 | } 6 | -------------------------------------------------------------------------------- /bridge-stub-generator/.classpath: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | -------------------------------------------------------------------------------- /bridge-stub-generator/.project: -------------------------------------------------------------------------------- 1 | 2 | 3 | bridge-stub-generator 4 | 5 | 6 | 7 | 8 | 9 | org.eclipse.jdt.core.javabuilder 10 | 11 | 12 | 13 | 14 | 15 | org.eclipse.jdt.core.javanature 16 | 17 | 18 | -------------------------------------------------------------------------------- /bridge-stub-generator/build.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | 29 | 30 | 31 | 32 | 33 | 34 | 35 | 36 | 37 | 39 | 40 | 41 | 42 | 43 | 44 | 45 | 46 | 47 | 48 | 49 | 50 | 51 | 52 | -------------------------------------------------------------------------------- /bridge-stub-generator/src/org/meshpoint/anode/stub/DictionaryStubGenerator.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2011-2012 Paddy Byers 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package org.meshpoint.anode.stub; 18 | 19 | import java.io.File; 20 | import java.io.IOException; 21 | import java.lang.reflect.Modifier; 22 | 23 | import org.meshpoint.anode.idl.IDLInterface; 24 | import org.meshpoint.anode.idl.IDLInterface.Attribute; 25 | import org.meshpoint.anode.idl.InterfaceManager; 26 | import org.meshpoint.anode.idl.StubUtil; 27 | 28 | public class DictionaryStubGenerator extends StubGenerator { 29 | 30 | /******************** 31 | * public API 32 | ********************/ 33 | 34 | public DictionaryStubGenerator(InterfaceManager mgr, IDLInterface iface, File destination) { 35 | super(mgr, iface, destination); 36 | } 37 | 38 | public void generate() throws IOException, GeneratorException { 39 | if((iface.getModifiers() & Modifier.INTERFACE) != 0) 40 | throw new GeneratorException("ValueStubGenerator: class must not be an interface", null); 41 | if(iface.getOperations().length > 0) 42 | throw new GeneratorException("ValueStubGenerator: class must not have any operations", null); 43 | String className = iface.getStubClassname(); 44 | ClassWriter cw = new ClassWriter(className, StubUtil.MODE_DICT); 45 | try { 46 | writePreamble(cw, className, null, null, StubUtil.MODE_DICT); 47 | /******************* 48 | * attribute methods 49 | *******************/ 50 | Attribute[] attributes = iface.getAttributes(); 51 | emitArgsArray(cw, attributes.length, true); 52 | 53 | /* __import */ 54 | cw.openScope("public static void __import(" + iface.getName() + " ob, Object[] vals)"); 55 | for(int i = 0; i < attributes.length; i++) { 56 | Attribute attr = attributes[i]; 57 | if((attr.modifiers & Modifier.STATIC) == 0) { 58 | registerName(attr.name); 59 | cw.writeln("ob." + attr.name + " = " + getObjectToArgExpression(attr.type, "vals[" + i + "]") + ";"); 60 | } 61 | } 62 | cw.closeScope(); 63 | cw.writeln(); 64 | 65 | /* __export */ 66 | cw.openScope("public static Object[] __export(" + iface.getName() + " ob)"); 67 | for(int i = 0; i < attributes.length; i++) { 68 | Attribute attr = attributes[i]; 69 | if((attr.modifiers & Modifier.STATIC) == 0) 70 | cw.writeln("__args[" + i + "] = " + getArgToObjectExpression(attr.type, "ob." + attr.name) + ";"); 71 | } 72 | cw.writeln("return __args;"); 73 | cw.closeScope(); 74 | cw.writeln(); 75 | cw.closeScope(); 76 | } finally { 77 | cw.close(); 78 | } 79 | } 80 | 81 | } 82 | -------------------------------------------------------------------------------- /bridge-stub-generator/src/org/meshpoint/anode/stub/UserStubGenerator.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2011-2012 Paddy Byers 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package org.meshpoint.anode.stub; 18 | 19 | import java.io.File; 20 | import java.io.IOException; 21 | import java.lang.reflect.Modifier; 22 | 23 | import org.meshpoint.anode.idl.IDLInterface; 24 | import org.meshpoint.anode.idl.IDLInterface.Attribute; 25 | import org.meshpoint.anode.idl.IDLInterface.Operation; 26 | import org.meshpoint.anode.idl.InterfaceManager; 27 | import org.meshpoint.anode.idl.StubUtil; 28 | import org.meshpoint.anode.idl.Types; 29 | 30 | public class UserStubGenerator extends StubGenerator { 31 | 32 | /******************** 33 | * private state 34 | ********************/ 35 | 36 | private static final String STUB_BASE = "org.meshpoint.anode.js.JSInterface"; 37 | 38 | /******************** 39 | * public API 40 | ********************/ 41 | 42 | public UserStubGenerator(InterfaceManager mgr, IDLInterface iface, File destination) { 43 | super(mgr, iface, destination); 44 | } 45 | 46 | public void generate() throws IOException, GeneratorException { 47 | if((iface.getModifiers() & Modifier.INTERFACE) == 0) 48 | throw new GeneratorException("UserStubGenerator: class must be an interface", null); 49 | String className = iface.getStubClassname(); 50 | ClassWriter cw = new ClassWriter(className, StubUtil.MODE_USER); 51 | String parentName = STUB_BASE; 52 | IDLInterface parent; 53 | if((parent = iface.getParent()) != null) 54 | parentName = parent.getStubClassname(); 55 | 56 | try { 57 | writePreamble(cw, className, parentName, iface.getName(), StubUtil.MODE_USER); 58 | /*************** 59 | * statics 60 | ****************/ 61 | cw.writeln("private static int classId = org.meshpoint.anode.bridge.Env.getInterfaceId(" + iface.getName() + ".class);"); 62 | cw.writeln(); 63 | 64 | /*************** 65 | * constructor 66 | ****************/ 67 | cw.writeln(className + "(long instHandle) { super(instHandle); }"); 68 | cw.writeln(); 69 | 70 | /*************** 71 | * finalizer 72 | ****************/ 73 | cw.writeln("public void finalize() { super.release(classId); " + (parent == null ? "" : "super.finalize(); ") + "}"); 74 | cw.writeln(); 75 | 76 | /******************* 77 | * operation methods 78 | *******************/ 79 | emitMaxargsArray(cw, iface, false); 80 | Operation[] operations = iface.getOperations(); 81 | for(int i = 0; i < operations.length; i++) { 82 | Operation op = operations[i]; 83 | registerName(op.name); 84 | cw.openScope(getModifiers(op.modifiers) + " " + getType(op.type) + " " + op.name + "(" + getArgListExpression(op) + ")"); 85 | for(int argIdx = 0; argIdx < op.args.length; argIdx++) { 86 | /* argument bashing */ 87 | cw.writeln("__args[" + argIdx + "] = " + getArgToObjectExpression(op.args[argIdx], getArgName(argIdx)) + ";"); 88 | } 89 | String subExpr = "__invoke(classId, " + i + ", __args)"; 90 | if(op.type == Types.TYPE_UNDEFINED) { 91 | cw.writeln(subExpr + ";"); 92 | } else { 93 | cw.writeln("return " + getObjectToArgExpression(op.type, subExpr) + ";"); 94 | } 95 | cw.closeScope(); 96 | cw.writeln(); 97 | } 98 | 99 | /******************* 100 | * attribute methods 101 | *******************/ 102 | Attribute[] attributes = iface.getAttributes(); 103 | for(int i = 0; i < attributes.length; i++) { 104 | Attribute attr = attributes[i]; 105 | registerName(attr.name); 106 | String typeStr = getType(attr.type); 107 | String modifiersStr = getModifiers(attr.modifiers); 108 | /* getter */ 109 | cw.openScope(modifiersStr + " " + typeStr + " " + getterName(attr.name) + "()"); 110 | String subExpr = "__get(classId, " + i + ")"; 111 | cw.writeln("return " + getObjectToArgExpression(attr.type, subExpr) + ";"); 112 | cw.closeScope(); 113 | cw.writeln(); 114 | /* setter */ 115 | cw.openScope(modifiersStr + " void " + setterName(attr.name) + "(" + typeStr + " arg0) {"); 116 | cw.writeln("__set(classId, " + i + ", " + getArgToObjectExpression(attr.type, getArgName(0)) + ");"); 117 | cw.closeScope(); 118 | cw.writeln(); 119 | } 120 | cw.closeScope(); 121 | } finally { 122 | cw.close(); 123 | } 124 | } 125 | 126 | private String getArgListExpression(Operation op) throws GeneratorException { 127 | StringBuffer buf = new StringBuffer(); 128 | for(int argIdx = 0; argIdx < op.args.length; argIdx++) { 129 | if(argIdx > 0) buf.append(", "); 130 | buf.append(getType(op.args[argIdx]) + " " + getArgName(argIdx)); 131 | } 132 | return buf.toString(); 133 | } 134 | } 135 | -------------------------------------------------------------------------------- /bridge-stub-generator/src/org/meshpoint/anode/stub/util/DirectoryClassLoader.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2011-2012 Paddy Byers 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package org.meshpoint.anode.stub.util; 18 | 19 | import java.io.File; 20 | import java.io.FileInputStream; 21 | import java.io.IOException; 22 | import java.util.ArrayList; 23 | import java.util.HashMap; 24 | 25 | public class DirectoryClassLoader extends ClassLoader { 26 | 27 | private HashMap> loadedClasses = new HashMap>(); 28 | private ArrayList pathEntries = new ArrayList(); 29 | 30 | public DirectoryClassLoader(String[] classPath) { 31 | for(String pathElement : classPath) { 32 | if(pathElement.isEmpty()) continue; 33 | if(!(new File(pathElement).exists())) continue; 34 | if(pathElement.charAt(pathElement.length()-1) != '/') 35 | pathElement += '/'; 36 | pathEntries.add(pathElement); 37 | } 38 | } 39 | 40 | public Class loadClass(String className, boolean resolve) throws ClassNotFoundException { 41 | Class result = null; 42 | try { 43 | result = findSystemClass(className); 44 | if(result != null) 45 | return result; 46 | } catch(ClassNotFoundException e) {} 47 | 48 | result = loadedClasses.get(className); 49 | if(result != null) 50 | return result; 51 | 52 | File classFile = null; 53 | String qualifiedPath = className.replace('.', '/') + ".class"; 54 | for(String pathElement : pathEntries) { 55 | File candidate = new File(pathElement + qualifiedPath); 56 | if(candidate.exists()) { 57 | classFile = candidate; 58 | break; 59 | } 60 | } 61 | if(classFile == null) 62 | throw new ClassNotFoundException("DirectoryClassLoader: unable to find class (" + className + ")"); 63 | 64 | Exception e = null; 65 | int offset = 0, read, len = (int)classFile.length(); 66 | byte[] classData = new byte[len]; 67 | try { 68 | FileInputStream fis = new FileInputStream(classFile); 69 | while(offset < len && (read = fis.read(classData, offset, len-offset)) != -1) { 70 | offset += read; 71 | } 72 | } catch(IOException ioe) {e = ioe;} 73 | if(offset < len) 74 | throw new ClassNotFoundException("DirectoryClassLoader: error reading class (" + className + ")", e); 75 | 76 | result = defineClass(className, classData, 0, len); 77 | loadedClasses.put(className, result); 78 | if(resolve) 79 | resolveClass(result); 80 | return result; 81 | } 82 | } 83 | -------------------------------------------------------------------------------- /bridge/Android.mk: -------------------------------------------------------------------------------- 1 | # Set up the following environment variables 2 | # NODE_ROOT: location of the node root directory (for include files) 3 | # ANODE_ROOT: location of the anode root directory (for the libjninode binary) 4 | 5 | LOCAL_PATH := $(call my-dir) 6 | include $(CLEAR_VARS) 7 | 8 | LOCAL_MODULE := bridge 9 | 10 | LOCAL_CFLAGS := \ 11 | -D__POSIX__ \ 12 | -DBUILDING_NODE_EXTENSION \ 13 | -include sys/select.h 14 | 15 | LOCAL_CPPFLAGS := 16 | 17 | LOCAL_C_INCLUDES := \ 18 | $(LOCAL_PATH)/src \ 19 | $(NODE_ROOT)/src \ 20 | $(NODE_ROOT)/deps/v8/include \ 21 | $(NODE_ROOT)/deps/uv/include 22 | 23 | LOCAL_LDLIBS := \ 24 | $(ANODE_ROOT)/libs/armeabi/libjninode.so \ 25 | -llog 26 | 27 | LOCAL_CPP_EXTENSION := .cpp 28 | 29 | LOCAL_SRC_FILES := \ 30 | src/AndroidVM.cpp \ 31 | src/ArrayConv.cpp \ 32 | src/Bridge.cpp \ 33 | src/Conv.cpp \ 34 | src/Env.cpp \ 35 | src/Interface.cpp \ 36 | src/VM.cpp \ 37 | ../bridge-java/jni/src/org_meshpoint_anode_bridge_BridgeNative.cpp 38 | 39 | LOCAL_STATIC_LIBRARIES := 40 | 41 | LOCAL_SHARED_LIBRARIES := 42 | 43 | # Do not edit this line. 44 | include $(ANODE_ROOT)/sdk/addon/build-node-addon.mk 45 | 46 | -------------------------------------------------------------------------------- /bridge/Application.mk: -------------------------------------------------------------------------------- 1 | APP_PROJECT_PATH :=. 2 | APP_BUILD_SCRIPT :=$(APP_PROJECT_PATH)/Android.mk 3 | APP_PLATFORM := android-9 4 | -------------------------------------------------------------------------------- /bridge/src/AndroidVM.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2011-2012 Paddy Byers 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | #include "AndroidVM.h" 18 | 19 | using namespace bridge; 20 | 21 | AndroidVM::AndroidVM(JNIEnv *jniEnv, jobject jAndroidContext) : VM() { 22 | this->jniEnv = jniEnv; 23 | this->jAndroidContext = jniEnv->NewGlobalRef(jAndroidContext); 24 | jContextClass = (jclass)jniEnv->NewGlobalRef(jniEnv->FindClass("org/meshpoint/anode/AndroidContext")); 25 | createContextMethodId = jniEnv->GetMethodID(jContextClass, "", "(Lorg/meshpoint/anode/bridge/Env;Lorg/meshpoint/anode/js/JSObject;Landroid/content/Context;)V"); 26 | } 27 | 28 | AndroidVM::~AndroidVM() { 29 | jniEnv->DeleteGlobalRef(jContextClass); 30 | jniEnv->DeleteGlobalRef(jAndroidContext); 31 | } 32 | 33 | int AndroidVM::createEnvContext(jobject *jCtx) { 34 | int result = OK; 35 | *jCtx = jAndroidContext; 36 | return result; 37 | } 38 | 39 | int AndroidVM::createModuleContext(jobject jEnv, jobject jExports, jobject *jCtx) { 40 | int result = OK; 41 | *jCtx = jniEnv->NewObject(jContextClass, createContextMethodId, jEnv, jExports, jAndroidContext); 42 | if(jniEnv->ExceptionCheck()) { 43 | result = ErrorVM; 44 | jniEnv->ExceptionClear(); 45 | } 46 | return result; 47 | } 48 | -------------------------------------------------------------------------------- /bridge/src/AndroidVM.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2011-2012 Paddy Byers 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | #ifndef BRIDGE_ANDROIDVM_H 18 | #define BRIDGE_ANDROIDVM_H 19 | 20 | #include "VM.h" 21 | 22 | namespace bridge { 23 | 24 | class AndroidVM : public VM { 25 | public: 26 | AndroidVM(JNIEnv *jniEnv, jobject jAndroidContext); 27 | virtual ~AndroidVM(); 28 | virtual int createEnvContext(jobject *jCtx); 29 | virtual int createModuleContext(jobject jEnv, jobject jExports, jobject *jCtx); 30 | 31 | private: 32 | jobject jAndroidContext; 33 | }; 34 | 35 | } // namespace bridge 36 | 37 | #endif 38 | -------------------------------------------------------------------------------- /bridge/src/ArrayConv.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2011-2012 Paddy Byers 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | #ifndef BRIDGE_ARRAYCONV_H 18 | #define BRIDGE_ARRAYCONV_H 19 | 20 | #include "defines.h" 21 | #include "Conv.h" 22 | #include "Utils.h" 23 | 24 | namespace bridge { 25 | 26 | class ArrayType; 27 | class Env; 28 | 29 | typedef v8::Handle (*eltGetter)(ArrayType *arr, JNIEnv *jniEnv, jobject ob, uint32_t index); 30 | typedef void (*eltSetter)(ArrayType *arr, JNIEnv *jniEnv, jobject ob, uint32_t index, v8::Handle); 31 | 32 | class ArrayType { 33 | public: 34 | unsigned int componentType; 35 | classRefs_s js; 36 | classRefs_s java; 37 | jmethodID getLength; 38 | jmethodID setLength; 39 | jmethodID getElement; 40 | jmethodID setElement; 41 | v8::Persistent sHiddenKey; 42 | v8::Persistent sClassName; 43 | v8::Persistent functionTemplate; 44 | v8::Persistent function; 45 | ArrayType(Env *env, JNIEnv *jniEnv, 46 | unsigned int componentType, 47 | const char *ClassName, 48 | const char *jsCtor, 49 | const char *javaGetterSig, 50 | const char *javaSetterSig, 51 | eltGetter getter = 0, 52 | eltSetter setter = 0 53 | ); 54 | ~ArrayType() {} 55 | int UserNew(JNIEnv *jniEnv, jlong handle, jobject *jVal); 56 | int PlatformNew(JNIEnv *jniEnv, v8::Handle *val); 57 | void dispose(JNIEnv *jniEnv); 58 | 59 | inline v8::Handle getHiddenKey() { return sHiddenKey; } 60 | 61 | private: 62 | Env *env; 63 | eltGetter getter; 64 | eltSetter setter; 65 | static v8::Handle PlatformLengthGet(v8::Local property, const v8::AccessorInfo& info); 66 | static void PlatformLengthSet(v8::Local property, v8::Local value, const v8::AccessorInfo& info); 67 | static v8::Handle PlatformElementGet(uint32_t index, const v8::AccessorInfo& info); 68 | static v8::Handle PlatformElementSet(uint32_t index, v8::Local value, const v8::AccessorInfo& info); 69 | static v8::Handle PlatformCtor(const v8::Arguments& args); 70 | 71 | static v8::Handle ByteGet(ArrayType *arr, JNIEnv *jniEnv, jobject ob, uint32_t index); 72 | static v8::Handle IntegerGet(ArrayType *arr, JNIEnv *jniEnv, jobject ob, uint32_t index); 73 | static v8::Handle LongGet(ArrayType *arr, JNIEnv *jniEnv, jobject ob, uint32_t index); 74 | static v8::Handle DoubleGet(ArrayType *arr, JNIEnv *jniEnv, jobject ob, uint32_t index); 75 | static void ByteSet(ArrayType *arr, JNIEnv *jniEnv, jobject ob, uint32_t index, v8::Handle elt); 76 | static void IntegerSet(ArrayType *arr, JNIEnv *jniEnv, jobject ob, uint32_t index, v8::Handle elt); 77 | static void LongSet(ArrayType *arr, JNIEnv *jniEnv, jobject ob, uint32_t index, v8::Handle elt); 78 | static void DoubleSet(ArrayType *arr, JNIEnv *jniEnv, jobject ob, uint32_t index, v8::Handle elt); 79 | 80 | friend class ArrayConv; 81 | }; 82 | 83 | class ArrayConv { 84 | public: 85 | ArrayConv(Env *env, Conv *conv, JNIEnv *jniEnv); 86 | void dispose(JNIEnv *jniEnv); 87 | ~ArrayConv(); 88 | inline v8::Persistent getHiddenKey() {return sArrayHiddenKey;} 89 | inline v8::Persistent getSLength() {return sLength;} 90 | int GetArrayType(JNIEnv *jniEnv, classId class_, ArrayType **ref); 91 | 92 | int WrapV8Array(JNIEnv *jniEnv, v8::Handle val, jobject *jVal); 93 | int WrapV8Array(JNIEnv *jniEnv, v8::Handle val, int componentType, ArrayType *arr, jobject *jVal); 94 | int ToJavaArray(JNIEnv *jniEnv, v8::Handle val, int componentType, jobject *jVal); 95 | int ToV8Array(JNIEnv *jniEnv, jobject jVal, int expectedType, v8::Handle *val); 96 | 97 | int UserGetLength(JNIEnv *jniEnv, v8::Handle val, int *length); 98 | int UserSetLength(JNIEnv *jniEnv, v8::Handle val, int length); 99 | int UserGetElement(JNIEnv *jniEnv, v8::Handle val, unsigned int type, int idx, jobject *jVal); 100 | int UserSetElement(JNIEnv *jniEnv, v8::Handle val, unsigned int type, int idx, jobject jVal); 101 | 102 | int GetRefsForComponentType(JNIEnv *jniEnv, unsigned int componentType, ArrayType **ref); 103 | 104 | private: 105 | Env *env; 106 | Conv *conv; 107 | v8::Persistent sArrayHiddenKey; 108 | v8::Persistent sLength; 109 | ArrayType *typeToArray[TYPE___END]; 110 | TArray *interfaces; 111 | 112 | friend class ArrayType; 113 | }; 114 | 115 | } // namespace bridge 116 | #endif 117 | -------------------------------------------------------------------------------- /bridge/src/Bridge.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2011-2012 Paddy Byers 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | #include "Bridge.h" 18 | 19 | #include "defines.h" 20 | #include "Env.h" 21 | 22 | using namespace v8; 23 | using namespace bridge; 24 | 25 | /* 26 | * Creates an instance of a java module, specified by name. 27 | */ 28 | Handle Load(const Arguments& args) { 29 | HandleScope scope; 30 | 31 | /* Check arguments */ 32 | if (args.Length() < 2) { 33 | return ThrowException( 34 | Exception::TypeError(String::New("bridge.load(): error: no modulName argument")) 35 | ); 36 | } 37 | 38 | if(!args[0]->IsString()) { 39 | return ThrowException( 40 | Exception::TypeError(String::New("bridge.load(): error: moduleName argument must be a String")) 41 | ); 42 | } 43 | 44 | if(!args[1]->IsObject()) { 45 | return ThrowException( 46 | Exception::TypeError(String::New("bridge.load(): error: moduleExports argument must be an Object")) 47 | ); 48 | } 49 | 50 | Local moduleName = args[0]->ToString(); 51 | Local moduleExports = args[1]->ToObject(); 52 | return scope.Close(bridge::Env::getEnv_nocheck()->load(moduleName, moduleExports)); 53 | } 54 | 55 | /* 56 | * Releases an instance of a java module, specified by name. 57 | */ 58 | Handle Unload(const Arguments& args) { 59 | HandleScope scope; 60 | 61 | /* Check arguments */ 62 | if (args.Length() < 1) { 63 | return ThrowException( 64 | Exception::TypeError(String::New("bridge.unload(): error: no modulName argument")) 65 | ); 66 | } 67 | 68 | if(!args[0]->IsString()) { 69 | return ThrowException( 70 | Exception::TypeError(String::New("bridge.unload(): error: moduleName argument must be a String")) 71 | ); 72 | } 73 | 74 | Local moduleName = args[0]->ToString(); 75 | Env::getEnv_nocheck()->unload(moduleName); 76 | return Undefined(); 77 | } 78 | 79 | void init(Handle target) { 80 | int result = Env::getEnv()->init(); 81 | if(result == OK) { 82 | target->Set(String::NewSymbol("load"), FunctionTemplate::New(Load)->GetFunction()); 83 | target->Set(String::NewSymbol("unload"), FunctionTemplate::New(Unload)->GetFunction()); 84 | return; 85 | } 86 | LOGV("Fatal error in Bridge::init(): errno = %d\n", result); 87 | } 88 | 89 | NODE_MODULE(bridge, init); 90 | -------------------------------------------------------------------------------- /bridge/src/Bridge.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2011-2012 Paddy Byers 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | #ifndef BRIDGE_BRIDGE_H 18 | #define BRIDGE_BRIDGE_H 19 | 20 | #include 21 | 22 | v8::Handle Load(const v8::Arguments& args); 23 | v8::Handle Unload(const v8::Arguments& args); 24 | 25 | extern "C" NODE_EXTERN void init(v8::Handle target); 26 | 27 | #endif 28 | -------------------------------------------------------------------------------- /bridge/src/Env.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2011-2012 Paddy Byers 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | #ifndef BRIDGE_ENV_H 18 | #define BRIDGE_ENV_H 19 | 20 | #include "defines.h" 21 | #include 22 | #ifdef __APPLE__ 23 | # include 24 | #else 25 | # include 26 | #endif 27 | 28 | #include "Interface.h" 29 | #include "Utils-inl.h" 30 | 31 | namespace bridge { 32 | 33 | class Conv; 34 | class VM; 35 | 36 | class Env { 37 | public: 38 | #ifdef ANDROID 39 | static void setupEnv(VM *vm); 40 | #endif 41 | static Env *getEnv(); 42 | static Env *getEnv_nocheck(); 43 | int init(); 44 | v8::Local load(v8::Handle moduleName, v8::Handle moduleExports); 45 | v8::Local unload(v8::Handle moduleName); 46 | inline Conv *getConv() {return conv;} 47 | inline Interface *getInterface(classId class_) {return interfaces->get(Interface::classId2Idx(class_));} 48 | inline void putInterface(classId class_, Interface *interface) {interfaces->put(Interface::classId2Idx(class_), interface);} 49 | inline VM *getVM() {return vm;} 50 | void setAsync(); 51 | 52 | private: 53 | Env(VM *vm); 54 | ~Env(); 55 | int initV8(); 56 | int initJava(); 57 | static void atExit(); 58 | static void asyncCb(uv_async_t *async, int status); 59 | 60 | void moduleLoaded(); 61 | void moduleUnloaded(); 62 | int moduleCount; 63 | uv_async_t async; 64 | 65 | static Env *initThread(VM *vm); 66 | node::Isolate *nodeIsolate; 67 | v8::Isolate *v8Isolate; 68 | VM *vm; 69 | Conv *conv; 70 | TArray *interfaces; 71 | 72 | /* JNI */ 73 | jclass jEnvClass; 74 | jobject jEnv; 75 | jmethodID createMethodId; 76 | jmethodID releaseMethodId; 77 | jmethodID loadMethodId; 78 | jmethodID unloadMethodId; 79 | jmethodID onEntryMethodId; 80 | jmethodID findClassMethodId; 81 | 82 | friend class Conv; 83 | }; 84 | 85 | } //namespace bridge 86 | #endif 87 | -------------------------------------------------------------------------------- /bridge/src/Interface.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2011-2012 Paddy Byers 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | #ifndef BRIDGE_INTERFACE_H 18 | #define BRIDGE_INTERFACE_H 19 | 20 | #include "defines.h" 21 | #include "Conv.h" 22 | #include "Utils-inl.h" 23 | 24 | namespace bridge { 25 | 26 | class ArrayType; 27 | class Attribute; 28 | class Operation; 29 | 30 | class Interface { 31 | public: 32 | static int Create(JNIEnv *jniEnv, Env *env, Interface *parent, jobject jInterface, classId class_, int attrCount, int opCount, jclass declaredClass, Interface **inst); 33 | void dispose(JNIEnv *jniEnv); 34 | ~Interface() {}; 35 | 36 | int InitUserStub(JNIEnv *jniEnv, jclass userStub); 37 | int InitPlatformStub(JNIEnv *jniEnv, jclass platformStub); 38 | int InitDictStub(JNIEnv *jniEnv, jclass dictStub); 39 | int InitAttribute(JNIEnv *jniEnv, jint idx, jint type, jstring jName); 40 | int InitOperation(JNIEnv *jniEnv, jint idx, jint type, jstring jName, jint argCount, jint *argTypes); 41 | 42 | int DictCreate(JNIEnv *jniEnv, v8::Handle val, jobject *jVal); 43 | int DictImport(JNIEnv *jnIEnv, v8::Handle val, jobject jVal); 44 | int DictExport(JNIEnv *jniEnv, jobject jVal, v8::Handle val); 45 | 46 | int UserCreate(JNIEnv *jniEnv, jlong handle, jobject *jVal); 47 | int UserInvoke(JNIEnv *jniEnv, v8::Handle target, int opIdx, jobjectArray jArgs, jobject *jResult); 48 | int UserSet(JNIEnv *jniEnv, v8::Handle target, int attrIdx, jobject jVal); 49 | int UserGet(JNIEnv *jniEnv, v8::Handle target, int attrIdx, jobject *jVal); 50 | 51 | int PlatformCreate(JNIEnv *jniEnv, jobject jVal, v8::Handle *val); 52 | 53 | inline v8::Persistent getHiddenKey() {return hiddenKey;} 54 | inline Interface *getParent() {return parent;} 55 | static inline int classId2Idx(classId class_) {return class_ >> 1;} 56 | static inline classId idx2ClassId(int idx, bool isDict) {return (idx << 1) + (int)isDict;} 57 | inline jclass getDeclaredClass() {return declaredClass;} 58 | 59 | private: 60 | Interface() : attributes(0), operations(0) {}; 61 | int Init(JNIEnv *jniEnv, Env *env, Interface *parent, jobject jInterface, classId class_, int attrCount, int opCount, jclass declaredClass); 62 | 63 | static v8::Handle PlatformAttrGet(v8::Local property, const v8::AccessorInfo& info); 64 | static void PlatformAttrSet(v8::Local property, v8::Local value, const v8::AccessorInfo& info); 65 | static v8::Handle PlatformOpInvoke(const v8::Arguments& args); 66 | static v8::Handle PlatformCtor(const v8::Arguments& args); 67 | 68 | Env *env; 69 | Interface *parent; 70 | Conv *conv; 71 | 72 | v8::Persistent hiddenKey; 73 | v8::Persistent sClassName; 74 | v8::Persistent functionTemplate; 75 | v8::Persistent function; 76 | v8::Persistent instanceTemplate; 77 | 78 | classId class_; 79 | TArray *attributes; 80 | TArray *operations; 81 | 82 | /* JNI */ 83 | jclass declaredClass; 84 | jobject jInterface; 85 | 86 | jclass jUserStub; 87 | jmethodID jUserCtor; 88 | 89 | jclass jPlatformStub; 90 | jmethodID jPlatformGetArgs; 91 | jmethodID jPlatformInvoke; 92 | jmethodID jPlatformGet; 93 | jmethodID jPlatformSet; 94 | 95 | jclass jDictStub; 96 | jmethodID jDictCtor; 97 | jmethodID jDictGetArgs; 98 | jmethodID jDictImport; 99 | jmethodID jDictExport; 100 | 101 | friend class Attribute; 102 | friend class Operation; 103 | }; 104 | 105 | class Attribute { 106 | public: 107 | int type; 108 | v8::Persistent name; 109 | Attribute() {}; 110 | ~Attribute(); 111 | int Init(JNIEnv *jniEnv, Conv *conv, jint type, jstring jName); 112 | }; 113 | 114 | class Operation : public Attribute { 115 | public: 116 | int argCount; 117 | jint *argTypes; 118 | v8::Handle *vArgs; 119 | Operation() : Attribute(), argTypes(0) {}; 120 | ~Operation(); 121 | int Init(JNIEnv *jniEnv, Conv *conv, Interface *interface, jint type, jstring jName, jint argCount, jint *argTypes); 122 | }; 123 | 124 | } // namespace bridge 125 | #endif 126 | -------------------------------------------------------------------------------- /bridge/src/JREVM.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2011-2012 Paddy Byers 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | #ifndef BRIDGE_JREVM_H 18 | #define BRIDGE_JREVM_H 19 | 20 | #include "VM.h" 21 | #include 22 | 23 | namespace bridge { 24 | 25 | class JREVM : public VM { 26 | public: 27 | JREVM(); 28 | virtual ~JREVM(); 29 | static int initProcess(); 30 | virtual int createEnvContext(jobject *jCtx); 31 | virtual int createModuleContext(jobject jEnv, jobject jExports, jobject *jCtx); 32 | 33 | private: 34 | static char *buildClasspath(const char *anodeRoot, size_t len); 35 | static char *buildLibrarypath(const char *anodeRoot, size_t len); 36 | static int createVM(); 37 | int attach(); 38 | }; 39 | 40 | } // namespace bridge 41 | #endif 42 | -------------------------------------------------------------------------------- /bridge/src/Utils-inl.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2011-2012 Paddy Byers 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | #ifndef BRIDGE_UTILSINL_H 18 | #define BRIDGE_UTILSINL_H 19 | 20 | #include "Utils.h" 21 | #include "defines.h" 22 | #include 23 | 24 | template TArray *TArray::New(unsigned int count, unsigned int increment) { 25 | TArray *ob = new TArray(increment); 26 | if(ob) { 27 | if(ob->alloc(count) == ErrorMem) { 28 | delete ob; 29 | ob = 0; 30 | } 31 | } 32 | return ob; 33 | } 34 | 35 | template TArray::TArray(unsigned int increment) { 36 | arr = 0; 37 | count = 0; 38 | this->increment = increment; 39 | } 40 | 41 | template T TArray::get(unsigned int idx) { 42 | return arr[idx]; 43 | } 44 | 45 | template T *TArray::addr(unsigned int idx) { 46 | return &arr[idx]; 47 | } 48 | 49 | template int TArray::put(unsigned int idx, T value) { 50 | if(idx >= count) { 51 | int newCount = (idx + increment) & -increment; 52 | int result = alloc(newCount); 53 | if(result != OK) return result; 54 | } 55 | arr[idx] = value; 56 | return OK; 57 | } 58 | 59 | template int TArray::setLength(unsigned int count) { 60 | int result = OK; 61 | if(count >= this->count) 62 | result = alloc(count); 63 | if(result == OK) 64 | this->count = count; 65 | return result; 66 | } 67 | 68 | template int TArray::alloc(unsigned int count) { 69 | if(count > 0) { 70 | T *arr = new T[count]; 71 | if(!arr) return ErrorMem; 72 | if(this->arr) 73 | memcpy(arr, this->arr, this->count * sizeof(T)); 74 | memset(&arr[this->count], 0, (count - this->count) * sizeof(T)); 75 | this->count = count; 76 | this->arr = arr; 77 | } 78 | return OK; 79 | } 80 | 81 | template TArray::~TArray() { 82 | delete[] arr; 83 | } 84 | 85 | #endif 86 | -------------------------------------------------------------------------------- /bridge/src/Utils.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2011-2012 Paddy Byers 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | #ifndef BRIDGE_UTILS_H 18 | #define BRIDGE_UTILS_H 19 | 20 | template class TArray { 21 | public: 22 | static TArray *New(unsigned int count=32, unsigned int increment=32); 23 | T get(unsigned int idx); 24 | T *addr(unsigned int idx); 25 | int put(unsigned int idx, T value); 26 | int setLength(unsigned int count); 27 | inline int getLength() {return count;} 28 | ~TArray(); 29 | 30 | protected: 31 | TArray(unsigned int increment); 32 | int alloc(unsigned int count); 33 | T *arr; 34 | unsigned int count; 35 | unsigned int increment; 36 | }; 37 | 38 | #endif 39 | -------------------------------------------------------------------------------- /bridge/src/VM.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2011-2012 Paddy Byers 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | #include "VM.h" 18 | 19 | using namespace bridge; 20 | 21 | VM::VM() : jniEnv(0) {} 22 | 23 | VM::~VM() {} 24 | 25 | JNIEnv *VM::getJNIEnv() { 26 | return jniEnv; 27 | } 28 | -------------------------------------------------------------------------------- /bridge/src/VM.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2011-2012 Paddy Byers 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | #ifndef BRIDGE_VM_H 18 | #define BRIDGE_VM_H 19 | 20 | #include "defines.h" 21 | 22 | namespace bridge { 23 | 24 | class VM { 25 | public: 26 | VM(); 27 | virtual ~VM(); 28 | JNIEnv *getJNIEnv(); 29 | virtual int createEnvContext(jobject *jCtx) = 0; 30 | virtual int createModuleContext(jobject jEnv, jobject jExports, jobject *jCtx) = 0; 31 | 32 | protected: 33 | JNIEnv *jniEnv; 34 | /* module lifecycle */ 35 | jclass jContextClass; 36 | jmethodID createContextMethodId; 37 | }; 38 | 39 | } // namespace bridge 40 | #endif 41 | -------------------------------------------------------------------------------- /bridge/src/defines.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2011-2012 Paddy Byers 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | #ifndef BRIDGE_DEFINES_H 18 | #define BRIDGE_DEFINES_H 19 | 20 | /**************** 21 | * misc defines 22 | ****************/ 23 | 24 | #define LIB_EXPORT __attribute__ ((visibility("default"))) 25 | 26 | /****************** 27 | * global inclusion 28 | ******************/ 29 | 30 | #include 31 | 32 | #ifdef __APPLE__ 33 | # include 34 | #else 35 | # include 36 | #endif 37 | 38 | /**************** 39 | * log 40 | ****************/ 41 | #define DEBUG 42 | #ifdef DEBUG 43 | # ifdef ANDROID 44 | # include 45 | # define DEBUG_TAG "bridge-core" 46 | # define LOGV(...) __android_log_print(ANDROID_LOG_VERBOSE, DEBUG_TAG, __VA_ARGS__) 47 | # else 48 | # define LOGV(...) fprintf(stderr, __VA_ARGS__) 49 | # endif 50 | #else 51 | # define LOGV(...) 52 | #endif 53 | /**************** 54 | * error codes 55 | ****************/ 56 | 57 | enum { 58 | OK = 0, 59 | ErrorMem = -1, /* out of memory */ 60 | ErrorConfig = -2, /* configuration error */ 61 | ErrorVM = -3, /* Java exception java framework code */ 62 | ErrorIO = -4, /* IO error */ 63 | ErrorNotfound = -5, /* resource not found */ 64 | ErrorInvalid = -6, /* invalid argument or value */ 65 | ErrorType = -7, /* incompatible type */ 66 | ErrorJS = -8, /* V8 exception in user code */ 67 | ErrorInvocation = -9, /* Java exception in user (module) code */ 68 | ErrorInternal = -10, /* internal error */ 69 | ErrorTBD = -11 70 | }; 71 | 72 | /**************** 73 | * types 74 | ****************/ 75 | 76 | enum { 77 | TYPE_INVALID = -1, 78 | TYPE_NONE = 0, 79 | TYPE_UNDEFINED , 80 | TYPE_NULL , 81 | TYPE_BOOL , 82 | TYPE_BYTE , 83 | TYPE_SHORT , /* = 5 */ 84 | TYPE_INT , 85 | TYPE_LONG , 86 | TYPE_DOUBLE , 87 | TYPE_STRING , 88 | TYPE__OB_START = TYPE_STRING, 89 | TYPE_FUNCTION , /*= 10 */ 90 | TYPE_DATE , 91 | TYPE_OBJECT = 16, 92 | TYPE___END , 93 | TYPE_SEQUENCE = 32, 94 | TYPE_ARRAY = 64, 95 | TYPE_IDL = 128, 96 | TYPE_MAP = 256 97 | }; 98 | 99 | typedef unsigned short classId; 100 | 101 | inline classId getClassId(int type) { 102 | return (short)(type >> 16); 103 | } 104 | 105 | inline unsigned int getInterfaceType(classId clsid) { 106 | return (clsid << 16) | TYPE_IDL; 107 | } 108 | 109 | inline bool isDictClass(classId class_) { return class_ & 1; } 110 | 111 | inline bool isInterfaceOrDict(int type) { 112 | return (type & TYPE_IDL) != 0; 113 | } 114 | 115 | inline bool isInterface(int type) { 116 | return isInterfaceOrDict(type) && !isDictClass(getClassId(type)); 117 | } 118 | 119 | inline bool isDict(int type) { 120 | return isInterfaceOrDict(type) && isDictClass(getClassId(type)); 121 | } 122 | 123 | inline bool isSequence(int type) { 124 | return (type & TYPE_SEQUENCE) != 0; 125 | } 126 | 127 | inline bool isArray(int type) { 128 | return (type & TYPE_ARRAY) != 0; 129 | } 130 | 131 | inline bool isMap(int type) { 132 | return (type & TYPE_MAP) != 0; 133 | } 134 | 135 | inline bool isBase(int type) { 136 | return (type < TYPE___END); 137 | } 138 | 139 | inline bool isJavaObject(int type) { 140 | return (type >= TYPE__OB_START); 141 | } 142 | 143 | inline int getComponentType(int type) { 144 | return (type & (~TYPE_ARRAY & ~TYPE_SEQUENCE & ~TYPE_MAP)); 145 | } 146 | 147 | inline int getArrayType(int type) { 148 | return (type | TYPE_ARRAY); 149 | } 150 | 151 | inline int getSequenceType(int type) { 152 | return (type | TYPE_SEQUENCE); 153 | } 154 | 155 | inline int getMapType(int type) { 156 | return (type | TYPE_MAP); 157 | } 158 | 159 | /****************************** 160 | * stub modes 161 | ******************************/ 162 | 163 | enum MODE { 164 | MODE_IMPORT, 165 | MODE_EXPORT, 166 | MODE_VALUE 167 | }; 168 | 169 | /****************************** 170 | * object private field indices 171 | ******************************/ 172 | 173 | enum { 174 | PRIVATE_GLOBALREF, 175 | PRIVATE_UNUSED, 176 | PRIVATE_COUNT 177 | }; 178 | 179 | /****************************** 180 | * conv to jlong for Persistent<> 181 | ******************************/ 182 | 183 | inline jlong asLong(v8::Persistent val) { 184 | return (jlong)*val; 185 | } 186 | 187 | inline v8::Persistent asHandle(jlong jVal) { 188 | return v8::Persistent((v8::Object*)jVal); 189 | } 190 | 191 | #endif 192 | -------------------------------------------------------------------------------- /libnode/.classpath: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | -------------------------------------------------------------------------------- /libnode/.project: -------------------------------------------------------------------------------- 1 | 2 | 3 | libnode 4 | 5 | 6 | 7 | 8 | 9 | com.android.ide.eclipse.adt.ResourceManagerBuilder 10 | 11 | 12 | 13 | 14 | com.android.ide.eclipse.adt.PreCompilerBuilder 15 | 16 | 17 | 18 | 19 | org.eclipse.jdt.core.javabuilder 20 | 21 | 22 | 23 | 24 | com.android.ide.eclipse.adt.ApkBuilder 25 | 26 | 27 | 28 | 29 | 30 | com.android.ide.eclipse.adt.AndroidNature 31 | org.eclipse.jdt.core.javanature 32 | 33 | 34 | 35 | bridge-java 36 | 2 37 | PARENT-1-PROJECT_LOC/bridge-java/src 38 | 39 | 40 | 41 | -------------------------------------------------------------------------------- /libnode/AndroidManifest.xml: -------------------------------------------------------------------------------- 1 | 2 | 6 | 7 | -------------------------------------------------------------------------------- /libnode/assets/.gitignore: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/paddybyers/anode/0dd99e2ec33e80c6ec46ed769530fe208bfcf488/libnode/assets/.gitignore -------------------------------------------------------------------------------- /libnode/build.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 7 | 8 | 9 | 29 | 30 | 31 | 35 | 36 | 37 | 38 | 39 | 40 | 49 | 50 | 51 | 52 | 56 | 57 | 69 | 70 | 71 | 89 | 90 | 91 | 92 | 93 | -------------------------------------------------------------------------------- /libnode/custom_rules.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | 29 | -------------------------------------------------------------------------------- /libnode/gen/org/meshpoint/anode/R.java: -------------------------------------------------------------------------------- 1 | /* AUTO-GENERATED FILE. DO NOT MODIFY. 2 | * 3 | * This class was automatically generated by the 4 | * aapt tool from the resource data it found. It 5 | * should not be modified by hand. 6 | */ 7 | 8 | package org.meshpoint.anode; 9 | 10 | public final class R { 11 | public static final class attr { 12 | } 13 | public static final class drawable { 14 | public static int icon=0x7f020000; 15 | } 16 | public static final class layout { 17 | public static int main=0x7f030000; 18 | } 19 | public static final class string { 20 | public static int app_name=0x7f040001; 21 | public static int hello=0x7f040000; 22 | } 23 | } 24 | -------------------------------------------------------------------------------- /libnode/jni/Android.mk: -------------------------------------------------------------------------------- 1 | # Copyright (C) 2009 The Android Open Source Project 2 | # 3 | # Licensed under the Apache License, Version 2.0 (the "License"); 4 | # you may not use this file except in compliance with the License. 5 | # You may obtain a copy of the License at 6 | # 7 | # http://www.apache.org/licenses/LICENSE-2.0 8 | # 9 | # Unless required by applicable law or agreed to in writing, software 10 | # distributed under the License is distributed on an "AS IS" BASIS, 11 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | # See the License for the specific language governing permissions and 13 | # limitations under the License. 14 | # 15 | LOCAL_PATH := $(call my-dir) 16 | 17 | include $(CLEAR_VARS) 18 | 19 | LOCAL_MODULE := jninode 20 | 21 | LOCAL_C_INCLUDES += \ 22 | $(LOCAL_PATH) \ 23 | $(NODE_ROOT)/src 24 | 25 | LOCAL_CFLAGS += \ 26 | -include sys/select.h 27 | 28 | LOCAL_SRC_FILES += src/org_meshpoint_anode_RuntimeNative.cpp 29 | 30 | LOCAL_STATIC_LIBRARIES := \ 31 | node \ 32 | uv \ 33 | http_parser \ 34 | v8 \ 35 | pty 36 | 37 | LOCAL_SHARED_LIBRARIES := 38 | 39 | LOCAL_LDLIBS += \ 40 | -lz \ 41 | -llog \ 42 | -lssl \ 43 | -lcrypto 44 | 45 | ifdef ANODE_ROOT 46 | LOCAL_LDFLAGS += \ 47 | -L $(ANODE_ROOT)/../openssl-android/libs/armeabi 48 | endif 49 | 50 | include $(BUILD_SHARED_LIBRARY) 51 | 52 | $(call import-module,deps/uv) 53 | $(call import-module,deps/http_parser) 54 | $(call import-module,deps/v8) 55 | $(call import-module,pty) 56 | $(call import-module,node) 57 | 58 | -------------------------------------------------------------------------------- /libnode/jni/src/defines.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2011-2012 Paddy Byers 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | #ifndef DEFINES_H 18 | #define DEFINES_H 19 | 20 | #define DEFAULT_MODE (S_IRWXU | S_IRWXG | S_IROTH | S_IXOTH) 21 | 22 | #endif 23 | -------------------------------------------------------------------------------- /libnode/jni/src/org_meshpoint_anode_RuntimeNative.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2011-2012 Paddy Byers 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | #include "org_meshpoint_anode_RuntimeNative.h" 18 | 19 | #include 20 | #include 21 | #include 22 | 23 | #include "defines.h" 24 | #include "node.h" 25 | 26 | #define DEBUG 27 | #ifdef DEBUG 28 | # include 29 | # define DEBUG_TAG "libjninode" 30 | # define LOGV(...) __android_log_print(ANDROID_LOG_VERBOSE, DEBUG_TAG, __VA_ARGS__) 31 | #else 32 | # define LOGV(...) 33 | #endif 34 | 35 | static void freeNativeArgs(jint argc, char **argv) { 36 | for(int i = 0; i < argc; i++) 37 | delete[] argv[i + 1]; 38 | delete[] argv; 39 | } 40 | 41 | static int getNativeArgs(JNIEnv *jniEnv, jobjectArray jargv, char ***pargv) { 42 | LOGV("getNativeArgs: ent\n"); 43 | jint argc = jargv ? jniEnv->GetArrayLength(jargv) : 0; 44 | 45 | /* convert jargv to native */ 46 | char **argv = new char*[argc + 2]; 47 | if(!argv) return -1; 48 | argv[0] = strdup((char *)"node"); 49 | if(!argv[0]) { freeNativeArgs(0, argv); return -1; } 50 | if(jargv) { 51 | for(int i = 0; i < argc; i++) { 52 | jstring jarg = (jstring)jniEnv->GetObjectArrayElement(jargv, i); 53 | if(!jarg) { freeNativeArgs(i, argv); return -1; } 54 | char *argCopy = 0; 55 | const char *arg = jniEnv->GetStringUTFChars(jarg, 0); 56 | int argLen = jniEnv->GetStringUTFLength(jarg); 57 | argCopy = new char[argLen + 1]; 58 | if(!argCopy) { freeNativeArgs(i, argv); return -1; } 59 | memcpy(argCopy, arg, argLen); 60 | argCopy[argLen] = 0; 61 | jniEnv->ReleaseStringUTFChars(jarg, arg); 62 | argv[i + 1] = argCopy; 63 | } 64 | } 65 | argv[++argc] = 0; 66 | *pargv = argv; 67 | LOGV("getNativeArgs: ret %d\n", argc); 68 | return argc; 69 | } 70 | 71 | /* 72 | * Class: org_meshpoint_anode_RuntimeNative 73 | * Method: nodeInit 74 | * Signature: ([Ljava/lang/String;Ljava/lang/String;)V 75 | */ 76 | JNIEXPORT void JNICALL Java_org_meshpoint_anode_RuntimeNative_nodeInit 77 | (JNIEnv *jniEnv, jclass, jobjectArray jargv, jstring jModulePath) { 78 | LOGV("Java_org_meshpoint_anode_RuntimeNative_nodeInit: ent\n"); 79 | 80 | /* set environment variable to support node modules */ 81 | const char *modulePath = jniEnv->GetStringUTFChars(jModulePath, 0); 82 | setenv("NODE_PATH", modulePath, 0); 83 | jniEnv->ReleaseStringUTFChars(jModulePath, modulePath); 84 | modulePath = NULL; 85 | 86 | /* process node arguments */ 87 | char **argv; 88 | int argc; 89 | if((argc = getNativeArgs(jniEnv, jargv, &argv)) >= 0) 90 | node::Initialize(argc, argv); 91 | LOGV("Java_org_meshpoint_anode_RuntimeNative_nodeInit: ret\n"); 92 | } 93 | 94 | /* 95 | * Class: org_meshpoint_anode_RuntimeNative 96 | * Method: nodeDispose 97 | * Signature: ()V 98 | */ 99 | JNIEXPORT void JNICALL Java_org_meshpoint_anode_RuntimeNative_nodeDispose 100 | (JNIEnv *, jclass) { 101 | LOGV("Java_org_meshpoint_anode_RuntimeNative_nodeDispose: ent\n"); 102 | node::Dispose(); 103 | LOGV("Java_org_meshpoint_anode_RuntimeNative_nodeDispose: ret\n"); 104 | } 105 | 106 | /* 107 | * Class: org_meshpoint_anode_RuntimeNative 108 | * Method: create 109 | * Signature: ()J 110 | */ 111 | JNIEXPORT jlong JNICALL Java_org_meshpoint_anode_RuntimeNative_create 112 | (JNIEnv *, jclass) { 113 | LOGV("Java_org_meshpoint_anode_RuntimeNative_create ent\n"); 114 | jlong result = (jlong)node::Isolate::New(); 115 | LOGV("Java_org_meshpoint_anode_RuntimeNative_create ret\n"); 116 | return result; 117 | } 118 | 119 | /* 120 | * Class: org_meshpoint_anode_RuntimeNative 121 | * Method: start 122 | * Signature: (J[Ljava/lang/String;)I 123 | */ 124 | JNIEXPORT jint JNICALL Java_org_meshpoint_anode_RuntimeNative_start 125 | (JNIEnv *jniEnv, jclass, jlong handle, jobjectArray jargv) { 126 | LOGV("Java_org_meshpoint_anode_RuntimeNative_start: ent\n"); 127 | node::Isolate *isolate = reinterpret_cast(handle); 128 | char **argv; 129 | int argc; 130 | if((argc = getNativeArgs(jniEnv, jargv, &argv)) >= 0) { 131 | int result = isolate->Start(argc, argv); 132 | freeNativeArgs(argc, argv); 133 | argc = result; 134 | } 135 | LOGV("Java_org_meshpoint_anode_RuntimeNative_start: ret %d\n", argc); 136 | return argc; 137 | } 138 | 139 | /* 140 | * Class: org_meshpoint_anode_RuntimeNative 141 | * Method: stop 142 | * Signature: (JI)I 143 | */ 144 | JNIEXPORT jint JNICALL Java_org_meshpoint_anode_RuntimeNative_stop 145 | (JNIEnv *, jclass, jlong handle, jint signum) { 146 | node::Isolate *isolate = reinterpret_cast(handle); 147 | LOGV("Java_org_meshpoint_anode_RuntimeNative_stop: ent\n"); 148 | int result = isolate->Stop(signum); 149 | LOGV("Java_org_meshpoint_anode_RuntimeNative_stop: ret %d\n", result); 150 | return result; 151 | } 152 | 153 | /* 154 | * Class: org_meshpoint_anode_RuntimeNative 155 | * Method: isolateDispose 156 | * Signature: (J)V 157 | */ 158 | JNIEXPORT void JNICALL Java_org_meshpoint_anode_RuntimeNative_isolateDispose 159 | (JNIEnv *, jclass, jlong handle) { 160 | node::Isolate *isolate = reinterpret_cast(handle); 161 | LOGV("Java_org_meshpoint_anode_RuntimeNative_isolateDispose: ent\n"); 162 | isolate->Dispose(); 163 | LOGV("Java_org_meshpoint_anode_RuntimeNative_isolateDispose: ret\n"); 164 | } 165 | -------------------------------------------------------------------------------- /libnode/jni/src/org_meshpoint_anode_RuntimeNative.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2011-2012 Paddy Byers 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | /* DO NOT EDIT THIS FILE - it is machine generated */ 18 | #include 19 | /* Header for class org_meshpoint_anode_RuntimeNative */ 20 | 21 | #ifndef _Included_org_meshpoint_anode_RuntimeNative 22 | #define _Included_org_meshpoint_anode_RuntimeNative 23 | #ifdef __cplusplus 24 | extern "C" { 25 | #endif 26 | #undef org_meshpoint_anode_RuntimeNative_SIGINT 27 | #define org_meshpoint_anode_RuntimeNative_SIGINT 2L 28 | #undef org_meshpoint_anode_RuntimeNative_SIGABRT 29 | #define org_meshpoint_anode_RuntimeNative_SIGABRT 6L 30 | #undef org_meshpoint_anode_RuntimeNative_SIGKILL 31 | #define org_meshpoint_anode_RuntimeNative_SIGKILL 9L 32 | #undef org_meshpoint_anode_RuntimeNative_SIGTERM 33 | #define org_meshpoint_anode_RuntimeNative_SIGTERM 15L 34 | /* 35 | * Class: org_meshpoint_anode_RuntimeNative 36 | * Method: nodeInit 37 | * Signature: ([Ljava/lang/String;)V 38 | */ 39 | JNIEXPORT void JNICALL Java_org_meshpoint_anode_RuntimeNative_nodeInit 40 | (JNIEnv *, jclass, jobjectArray, jstring jModulePath); 41 | 42 | /* 43 | * Class: org_meshpoint_anode_RuntimeNative 44 | * Method: nodeDispose 45 | * Signature: ()V 46 | */ 47 | JNIEXPORT void JNICALL Java_org_meshpoint_anode_RuntimeNative_nodeDispose 48 | (JNIEnv *, jclass); 49 | 50 | /* 51 | * Class: org_meshpoint_anode_RuntimeNative 52 | * Method: create 53 | * Signature: ()J 54 | */ 55 | JNIEXPORT jlong JNICALL Java_org_meshpoint_anode_RuntimeNative_create 56 | (JNIEnv *, jclass); 57 | 58 | /* 59 | * Class: org_meshpoint_anode_RuntimeNative 60 | * Method: start 61 | * Signature: (J[Ljava/lang/String;)I 62 | */ 63 | JNIEXPORT jint JNICALL Java_org_meshpoint_anode_RuntimeNative_start 64 | (JNIEnv *, jclass, jlong, jobjectArray); 65 | 66 | /* 67 | * Class: org_meshpoint_anode_RuntimeNative 68 | * Method: stop 69 | * Signature: (JI)I 70 | */ 71 | JNIEXPORT jint JNICALL Java_org_meshpoint_anode_RuntimeNative_stop 72 | (JNIEnv *, jclass, jlong, jint); 73 | 74 | /* 75 | * Class: org_meshpoint_anode_RuntimeNative 76 | * Method: isolateDispose 77 | * Signature: (J)V 78 | */ 79 | JNIEXPORT void JNICALL Java_org_meshpoint_anode_RuntimeNative_isolateDispose 80 | (JNIEnv *, jclass, jlong); 81 | 82 | #ifdef __cplusplus 83 | } 84 | #endif 85 | #endif 86 | -------------------------------------------------------------------------------- /libnode/proguard.cfg: -------------------------------------------------------------------------------- 1 | -optimizationpasses 5 2 | -dontusemixedcaseclassnames 3 | -dontskipnonpubliclibraryclasses 4 | -dontpreverify 5 | -verbose 6 | -optimizations !code/simplification/arithmetic,!field/*,!class/merging/* 7 | 8 | -keep public class * extends android.app.Activity 9 | -keep public class * extends android.app.Application 10 | -keep public class * extends android.app.Service 11 | -keep public class * extends android.content.BroadcastReceiver 12 | -keep public class * extends android.content.ContentProvider 13 | -keep public class * extends android.app.backup.BackupAgentHelper 14 | -keep public class * extends android.preference.Preference 15 | -keep public class com.android.vending.licensing.ILicensingService 16 | 17 | -keepclasseswithmembernames class * { 18 | native ; 19 | } 20 | 21 | -keepclasseswithmembers class * { 22 | public (android.content.Context, android.util.AttributeSet); 23 | } 24 | 25 | -keepclasseswithmembers class * { 26 | public (android.content.Context, android.util.AttributeSet, int); 27 | } 28 | 29 | -keepclassmembers class * extends android.app.Activity { 30 | public void *(android.view.View); 31 | } 32 | 33 | -keepclassmembers enum * { 34 | public static **[] values(); 35 | public static ** valueOf(java.lang.String); 36 | } 37 | 38 | -keep class * implements android.os.Parcelable { 39 | public static final android.os.Parcelable$Creator *; 40 | } 41 | -------------------------------------------------------------------------------- /libnode/project.properties: -------------------------------------------------------------------------------- 1 | # This file is automatically generated by Android Tools. 2 | # Do not modify this file -- YOUR CHANGES WILL BE ERASED! 3 | # 4 | # This file must be checked in Version Control Systems. 5 | # 6 | # To customize properties used by the Ant build system edit 7 | # "ant.properties", and override values to adapt the script to your 8 | # project structure. 9 | # 10 | # To enable ProGuard to shrink and obfuscate your code, uncomment this (available properties: sdk.dir, user.home): 11 | #proguard.config=${sdk.dir}/tools/proguard/proguard-android.txt:proguard-project.txt 12 | 13 | android.library=true 14 | # Project target. 15 | target=android-18 16 | -------------------------------------------------------------------------------- /libnode/res/drawable-hdpi/icon.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/paddybyers/anode/0dd99e2ec33e80c6ec46ed769530fe208bfcf488/libnode/res/drawable-hdpi/icon.png -------------------------------------------------------------------------------- /libnode/res/drawable-ldpi/icon.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/paddybyers/anode/0dd99e2ec33e80c6ec46ed769530fe208bfcf488/libnode/res/drawable-ldpi/icon.png -------------------------------------------------------------------------------- /libnode/res/drawable-mdpi/icon.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/paddybyers/anode/0dd99e2ec33e80c6ec46ed769530fe208bfcf488/libnode/res/drawable-mdpi/icon.png -------------------------------------------------------------------------------- /libnode/res/layout/main.xml: -------------------------------------------------------------------------------- 1 | 2 | 7 | 12 | 13 | -------------------------------------------------------------------------------- /libnode/res/values/strings.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | Hello World! 4 | Anode 5 | 6 | -------------------------------------------------------------------------------- /libnode/src/org/meshpoint/anode/AndroidContext.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2011-2012 Paddy Byers 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package org.meshpoint.anode; 18 | 19 | import org.meshpoint.anode.bridge.Env; 20 | import org.meshpoint.anode.bridge.ModuleContext; 21 | import org.meshpoint.anode.js.JSObject; 22 | 23 | import android.content.Context; 24 | 25 | public class AndroidContext extends ModuleContext { 26 | 27 | private Context ctx; 28 | 29 | AndroidContext(Env env, JSObject exports, Context ctx) { 30 | super(env, exports); 31 | this.ctx = ctx; 32 | } 33 | 34 | public Context getAndroidContext() { 35 | return ctx; 36 | } 37 | 38 | } 39 | -------------------------------------------------------------------------------- /libnode/src/org/meshpoint/anode/Isolate.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2011-2012 Paddy Byers 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package org.meshpoint.anode; 18 | 19 | import java.util.HashSet; 20 | import java.util.Set; 21 | 22 | import org.meshpoint.anode.Runtime.IllegalStateException; 23 | import org.meshpoint.anode.Runtime.NodeException; 24 | import org.meshpoint.anode.Runtime.StateListener; 25 | import org.meshpoint.anode.bridge.BridgeNative; 26 | 27 | import android.content.Context; 28 | import android.util.Log; 29 | 30 | public class Isolate { 31 | 32 | private static String TAG = "anode::Isolate"; 33 | 34 | /************************** 35 | * private state 36 | **************************/ 37 | 38 | private final Context ctx; 39 | private final long handle; 40 | private int state; 41 | private int exitval; 42 | private final RuntimeThread runner; 43 | private final Set listeners = new HashSet(); 44 | 45 | /************************** 46 | * public API 47 | **************************/ 48 | 49 | /** 50 | * Start the Isolate. 51 | * This is a non-blocking call. 52 | * @param argv the command-line arguments to pass to the runtime 53 | * @throws IllegalStateException if the runtime is already started, 54 | * or is otherwise in a state that prevents it from starting 55 | * @throws NodeException if the runtime exited with an error 56 | */ 57 | public void start(String[] argv) throws IllegalStateException, NodeException { 58 | synchronized(runner) { 59 | if(state != Runtime.STATE_CREATED) { 60 | throw new IllegalStateException( 61 | "Attempting to start Runtime when not in CREATED state" 62 | ); 63 | } 64 | runner.start(argv); 65 | try{runner.wait();}catch(InterruptedException e){} 66 | if(state == Runtime.STATE_STOPPED) 67 | handleExitval(); 68 | } 69 | } 70 | 71 | /** 72 | * Stop a running Runtime instance. 73 | * This is a non-blocking call. 74 | * @throws IllegalStateException if the runtime was not previously started, 75 | * or is otherwise in a state that prevents it from being stopped 76 | * @throws NodeException if the runtime exited with an error 77 | */ 78 | public void stop() throws IllegalStateException, NodeException { 79 | synchronized(runner) { 80 | switch(state) { 81 | case Runtime.STATE_STARTED: 82 | /* expected case, the instance is running normally */ 83 | setState(Runtime.STATE_STOPPING); 84 | RuntimeNative.stop(handle, RuntimeNative.SIGKILL); 85 | try{runner.wait();}catch(InterruptedException e){} 86 | case Runtime.STATE_STOPPED: 87 | /* already stopped, throw error if 88 | * there was one, otherwise silently succeed */ 89 | handleExitval(); 90 | return; 91 | default: 92 | throw new IllegalStateException( 93 | "Attempting to stop Runtime when not in STARTED state" 94 | ); 95 | } 96 | } 97 | } 98 | 99 | /** 100 | * Get the current runtime state 101 | * @return 102 | */ 103 | public int getState() { 104 | synchronized(runner) { 105 | return state; 106 | } 107 | } 108 | 109 | /** 110 | * Get the exit code for this isolate if in the stopped state 111 | * @return 112 | * @throws IllegalStateException 113 | */ 114 | public int getExitval() throws IllegalStateException { 115 | synchronized(runner) { 116 | if(state == Runtime.STATE_STOPPED) 117 | return exitval; 118 | 119 | throw new IllegalStateException( 120 | "Attempting to access exit code when not in STOPPED state" 121 | ); 122 | } 123 | } 124 | 125 | /************************** 126 | * private 127 | **************************/ 128 | 129 | Isolate(Context ctx) { 130 | this.ctx = ctx; 131 | runner = new RuntimeThread(); 132 | handle = RuntimeNative.create(); 133 | state = Runtime.STATE_CREATED; 134 | } 135 | 136 | private void setState(int state) { 137 | Log.v(TAG, "stateState: state = " + state); 138 | synchronized(runner) { 139 | this.state = state; 140 | runner.notifyAll(); 141 | } 142 | synchronized(listeners) { 143 | for(StateListener listener : listeners) { 144 | try { 145 | listener.stateChanged(state); 146 | } catch(Throwable t) { 147 | Log.e(TAG, "Unexpected exception calling state listener", t); 148 | } 149 | } 150 | } 151 | } 152 | 153 | /** 154 | * Listener interface for being notified of state changes 155 | */ 156 | public void addStateListener(StateListener listener) { 157 | synchronized(listeners) { 158 | listeners.add(listener); 159 | } 160 | } 161 | 162 | public void removeStateListener(StateListener listener) { 163 | synchronized(listeners) { 164 | listeners.remove(listener); 165 | } 166 | } 167 | 168 | private void handleExitval() throws NodeException { 169 | if(exitval != 0) { 170 | /* clear exitval because we have consumed that error here */ 171 | exitval = 0; 172 | throw new NodeException(exitval); 173 | } 174 | } 175 | 176 | private class RuntimeThread extends Thread { 177 | private String[] argv; 178 | 179 | public void start(String[] argv) { 180 | this.argv = argv; 181 | super.start(); 182 | } 183 | 184 | public void run() { 185 | try { 186 | Log.v(TAG, "Isolate.run(): setting context"); 187 | BridgeNative.setContext(ctx); 188 | Log.v(TAG, "Isolate.run(): set context"); 189 | setState(Runtime.STATE_STARTED); 190 | exitval = RuntimeNative.start(handle, argv); 191 | setState(Runtime.STATE_STOPPED); 192 | } catch(Throwable t) { 193 | Log.e(TAG, "Isolate.run(): exception", t); 194 | exitval = 1; 195 | setState(Runtime.STATE_STOPPED); 196 | } 197 | } 198 | } 199 | 200 | } 201 | -------------------------------------------------------------------------------- /libnode/src/org/meshpoint/anode/Runtime.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2011-2012 Paddy Byers 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package org.meshpoint.anode; 18 | 19 | import java.io.IOException; 20 | 21 | import android.content.Context; 22 | 23 | /** 24 | * Public API to obtain and manage Isolate instances of node.js 25 | * @author paddy 26 | */ 27 | public class Runtime { 28 | 29 | /************************** 30 | * private state 31 | **************************/ 32 | 33 | private static Runtime theRuntime; 34 | private Context ctx; 35 | 36 | /************************** 37 | * public API 38 | **************************/ 39 | 40 | /** 41 | * Public factory method to initialise the runtime environment. 42 | * @param ctx the Context associated with the invoking activity, 43 | * used to locate the assets 44 | * @throws InitialisationException if there was a problem initialising the Runtime 45 | */ 46 | public static synchronized void initRuntime(Context ctx, String[] argv) throws InitialisationException { 47 | if(theRuntime == null) { 48 | try { 49 | theRuntime = new Runtime(ctx, argv); 50 | } catch (IOException e) { 51 | throw new InitialisationException(e); } 52 | } 53 | } 54 | 55 | public static boolean isInitialised() { 56 | return theRuntime != null; 57 | } 58 | 59 | public static Isolate createIsolate() throws IllegalStateException { 60 | if(theRuntime == null) { 61 | throw new IllegalStateException("Runtime has not beed initialised"); 62 | } 63 | return new Isolate(theRuntime.ctx); 64 | } 65 | 66 | /** 67 | * States 68 | */ 69 | public static final int STATE_UNINITIALISED = 0; 70 | public static final int STATE_CREATED = 1; 71 | public static final int STATE_STARTED = 2; 72 | public static final int STATE_STOPPING = 3; 73 | public static final int STATE_STOPPED = 4; 74 | 75 | /** 76 | * Listener interface for being notified of state changes 77 | */ 78 | public interface StateListener { 79 | public void stateChanged(int state); 80 | } 81 | 82 | /** 83 | * Exception class signifying an initialisation problem with the 84 | * framework, wrapping the underlying exception cause. 85 | */ 86 | public static class InitialisationException extends Exception { 87 | private static final long serialVersionUID = 2496406014266651847L; 88 | InitialisationException(Throwable cause) {super(cause);} 89 | InitialisationException(String msg) {super(msg);} 90 | } 91 | 92 | /** 93 | * Exception class signifying a lifecycle operation failed 94 | * as a result of the runtime being in an inappropriate state. 95 | */ 96 | public static class IllegalStateException extends Exception { 97 | private static final long serialVersionUID = -8553913470826899835L; 98 | public IllegalStateException(String msg) {super(msg);} 99 | } 100 | 101 | /** 102 | * Exception class signifying an error in the node runtime, 103 | * wrapping the indicated exit code. 104 | */ 105 | public static class NodeException extends Exception { 106 | private static final long serialVersionUID = 5950820713527212317L; 107 | NodeException(int exitval) {super("node exited with error code: " + exitval);} 108 | } 109 | 110 | /************************** 111 | * private 112 | **************************/ 113 | 114 | Runtime(Context ctx, String[] argv) throws IOException { 115 | this.ctx = ctx; 116 | RuntimeNative.init(ctx, argv); 117 | } 118 | 119 | public void finalize() { 120 | RuntimeNative.nodeDispose(); 121 | } 122 | } 123 | -------------------------------------------------------------------------------- /libnode/src/org/meshpoint/anode/RuntimeNative.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2011-2012 Paddy Byers 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package org.meshpoint.anode; 18 | 19 | import java.io.File; 20 | import java.io.FileOutputStream; 21 | import java.io.IOException; 22 | import java.io.InputStream; 23 | 24 | import android.content.Context; 25 | import android.util.Log; 26 | 27 | /** 28 | * Wraps the native jni node.js library 29 | * This is a static class only 30 | * @author paddy 31 | */ 32 | final class RuntimeNative { 33 | 34 | private static String TAG = "anode::RuntimeNative"; 35 | private static String RUNTIME_LIBRARY = "libjninode.so"; 36 | private static String BRIDGE_LIBRARY = "bridge.node"; 37 | 38 | static final int SIGINT = 2; 39 | static final int SIGABRT = 6; 40 | static final int SIGKILL = 9; 41 | static final int SIGTERM = 15; 42 | 43 | /** 44 | * Initialise the native interface 45 | * @param ctx the Context associated with the invoking activity, 46 | * used to locate the assets 47 | * @throws IOException if there was a problem accessing the native library file 48 | * @throws UnsatisifiedLinkError if there was a problem initialising the native library 49 | */ 50 | static void init(Context ctx, String[] argv) throws IOException { 51 | char sep = File.separatorChar; 52 | String packageName = ctx.getPackageName(); 53 | 54 | // Example: `/data/data/org.mypackage.android/node_modules` 55 | // TODO: make the node dynamic library not depend on assumed /data/data filesystem structure 56 | String modulePath = sep + "data" + sep + "data" + sep + packageName + sep + "node_modules"; 57 | String runtimePath = sep + "data" + sep + "data" + sep + packageName + sep + "app"; 58 | 59 | try { 60 | extractLib(ctx, runtimePath, RUNTIME_LIBRARY); 61 | System.load(runtimePath + '/' + RUNTIME_LIBRARY); 62 | extractLib(ctx, modulePath, BRIDGE_LIBRARY); 63 | System.load(modulePath + '/' + BRIDGE_LIBRARY); 64 | Log.v(TAG, "init: loaded libraries: modulePath = " + modulePath); 65 | nodeInit(argv, modulePath); 66 | } catch(UnsatisfiedLinkError e) { 67 | Log.v(TAG, "init: unable to load library: " + e); 68 | throw e; 69 | } catch (IOException e) { 70 | Log.v(TAG, "init: unable to write library to file: " + e); 71 | throw e; 72 | } 73 | } 74 | 75 | /** 76 | * Initialise the native node runtime 77 | */ 78 | static native void nodeInit(String[] argv, String modulePath); 79 | 80 | /** 81 | * Dispose the native node runtime 82 | */ 83 | static native void nodeDispose(); 84 | 85 | /** 86 | * Create a node.js isolate 87 | * @return isolate handle, or 0 if error 88 | */ 89 | static native long create(); 90 | 91 | /** 92 | * Launch the node.js runtime. The thread that enters this method 93 | * will block until the runtime exits. 94 | * It is critical that a thread blocked in this method is not forcibly 95 | * terminated by the calling application, except in the case that the 96 | * entire application is about to exit, or native library resources 97 | * may be leaked 98 | * @param isolate the isolate handle 99 | * @param argv the options and arguments to pass to the node.js invocation 100 | * @return 0 if successful, else an error code 101 | */ 102 | static native int start(long isolate, String[] argv); 103 | 104 | /** 105 | * Stop a running runtime. An event will be delivered to the runtime that 106 | * simulates the delivery of the specified signal. 107 | * The supported events/signals are: 108 | * SIGINT: interrupt a current blocked operation; may be caught by a handler 109 | * in the runtime 110 | * SIGTERM: request termination of the runtime; may be caught by a handler 111 | * in the runtime 112 | * SIGKILL: request termination of the runtime; may be caught by a handler 113 | * in the runtime 114 | * SIGABRT: forcibly terminate the runtime instance 115 | * @param isolate the isolate handle 116 | * @param signum the signal number 117 | * @return 0 if successful, error code otherwise 118 | */ 119 | static native int stop(long isolate, int signum); 120 | 121 | /** 122 | * Dispose a native isolate instance 123 | */ 124 | static native void isolateDispose(long isolate); 125 | 126 | /** 127 | * Extract the library from assets to the default library location. 128 | * @throws IOException 129 | */ 130 | private static void extractLib(Context ctx, String path, String name) throws IOException { 131 | File dir, so, pkg; 132 | if(!(dir = new File(path)).exists()) 133 | dir.mkdirs(); 134 | 135 | if((so = new File(dir, name)).exists()) { 136 | /* check to see if this timestamp pre-dates 137 | * the current package */ 138 | if((pkg = new File(ctx.getPackageResourcePath())).exists()) { 139 | if(pkg.lastModified() < so.lastModified()) { 140 | Log.v(TAG, "extractLib: library up to date"); 141 | return; 142 | } 143 | } 144 | Log.v(TAG, "extractLib: library present but out of date"); 145 | so.delete(); 146 | } 147 | Log.v(TAG, "extractLib: copying library"); 148 | InputStream in = ctx.getAssets().open(name); 149 | FileOutputStream out = new FileOutputStream(so); 150 | int read; 151 | byte[] buf = new byte[8192]; 152 | while((read = in.read(buf)) != -1) 153 | out.write(buf, 0, read); 154 | in.close(); 155 | out.flush(); 156 | out.close(); 157 | so.setExecutable(true); 158 | } 159 | } 160 | -------------------------------------------------------------------------------- /libnode/src/org/meshpoint/anode/bridge/ModuleClassLoader.java: -------------------------------------------------------------------------------- 1 | package org.meshpoint.anode.bridge; 2 | 3 | import android.content.Context; 4 | import android.content.pm.PackageManager; 5 | import android.content.pm.PackageManager.NameNotFoundException; 6 | import dalvik.system.DexClassLoader; 7 | 8 | public class ModuleClassLoader extends ClassLoader { 9 | private static String packageName = "org.webinos.modules"; 10 | 11 | private ClassLoader defaultClassLoader; 12 | private DexClassLoader internalClassLoader; 13 | 14 | public ModuleClassLoader(Object envContext) { 15 | if (!(envContext instanceof Context)) { 16 | throw new IllegalArgumentException(); 17 | } 18 | Context androidContext = (Context) envContext; 19 | defaultClassLoader = androidContext.getClassLoader(); 20 | PackageManager pkgMgr = androidContext.getPackageManager(); 21 | 22 | if (pkgMgr != null 23 | && pkgMgr.checkSignatures(androidContext.getPackageName(), packageName) >= 0) { 24 | String dexPath = null; 25 | try { 26 | dexPath = pkgMgr.getApplicationInfo(packageName, 0).sourceDir; 27 | } catch (NameNotFoundException e) {} 28 | if (dexPath != null) { 29 | String dexOutputDir = androidContext.getDir("dex", 0).getAbsolutePath(); 30 | internalClassLoader = new DexClassLoader(dexPath, dexOutputDir, null, 31 | androidContext.getClassLoader()); 32 | } 33 | } 34 | } 35 | 36 | @Override 37 | public Class findClass(String className) throws ClassNotFoundException { 38 | Class clazz; 39 | try { 40 | if((clazz = defaultClassLoader.loadClass(className)) != null) 41 | return clazz; 42 | } catch(ClassNotFoundException cnfe) {} 43 | 44 | if (internalClassLoader != null && (clazz = internalClassLoader.loadClass(className)) != null) 45 | return clazz; 46 | 47 | throw new ClassNotFoundException(className); 48 | } 49 | } 50 | -------------------------------------------------------------------------------- /sdk/addon/build-node-addon.mk: -------------------------------------------------------------------------------- 1 | LOCAL_BUILD_SCRIPT := $(BUILD_SYSTEM)/build-node-addon.mk 2 | LOCAL_MAKEFILE := $(local-makefile) 3 | 4 | $(call check-defined-LOCAL_MODULE,$(LOCAL_BUILD_SCRIPT)) 5 | $(call check-LOCAL_MODULE,$(LOCAL_MAKEFILE)) 6 | $(call check-LOCAL_MODULE_FILENAME) 7 | 8 | # we are building target objects 9 | my := TARGET_ 10 | 11 | $(call handle-module-filename,,.node) 12 | $(call handle-module-built) 13 | 14 | LOCAL_MODULE_CLASS := SHARED_LIBRARY 15 | 16 | include $(BUILD_SYSTEM)/build-module.mk 17 | ALL_SHARED_LIBRARIES += $(LOCAL_BUILT_MODULE) 18 | -------------------------------------------------------------------------------- /sdk/addon/sample/hello/Android.mk: -------------------------------------------------------------------------------- 1 | # Set up the following environment variables 2 | # NODE_ROOT: location of the node root directory (for include files) 3 | # ANODE_ROOT: location of the anode root directory (for the libjninode binary) 4 | 5 | # Variable definitions for Android applications 6 | LOCAL_PATH := $(call my-dir) 7 | include $(CLEAR_VARS) 8 | 9 | # Modify this line to configure to the module name. 10 | LOCAL_MODULE := hello 11 | 12 | # Add any additional defines or compiler flags. 13 | # Do not delete these existing flags as these are required 14 | # for the included node header files. 15 | LOCAL_CFLAGS := \ 16 | -D__POSIX__ \ 17 | -DBUILDING_NODE_EXTENSION \ 18 | -include sys/select.h 19 | 20 | LOCAL_CPPFLAGS := 21 | 22 | # Add any additional required directories for the include path. 23 | # Do not delete these existing directories as these are required 24 | # for the included node header files. 25 | LOCAL_C_INCLUDES := $(NODE_ROOT)/src \ 26 | $(NODE_ROOT)/deps/v8/include \ 27 | $(NODE_ROOT)/deps/uv/include 28 | 29 | # Add any additional required shared libraries that the addon depends on. 30 | LOCAL_LDLIBS := \ 31 | $(ANODE_ROOT)/libs/armeabi/libjninode.so 32 | 33 | LOCAL_CPP_EXTENSION := .cc 34 | 35 | LOCAL_SRC_FILES :=\ 36 | src/hello.cc 37 | 38 | LOCAL_STATIC_LIBRARIES := 39 | 40 | # Do not edit this line. 41 | include $(ANODE_ROOT)/sdk/addon/build-node-addon.mk 42 | 43 | -------------------------------------------------------------------------------- /sdk/addon/sample/hello/Application.mk: -------------------------------------------------------------------------------- 1 | APP_PROJECT_PATH :=. 2 | APP_BUILD_SCRIPT :=$(APP_PROJECT_PATH)/Android.mk 3 | APP_PLATFORM := android-9 4 | -------------------------------------------------------------------------------- /sdk/addon/sample/hello/src/hello.cc: -------------------------------------------------------------------------------- 1 | // addons/hello/hello.cc 2 | #include 3 | #include 4 | 5 | using namespace v8; 6 | 7 | extern "C" void 8 | init (Handle target) 9 | { 10 | HandleScope scope; 11 | target->Set(String::New("hello"), String::New("world")); 12 | } 13 | -------------------------------------------------------------------------------- /sdk/java/lib/.classpath: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | -------------------------------------------------------------------------------- /sdk/java/lib/.project: -------------------------------------------------------------------------------- 1 | 2 | 3 | sdk 4 | 5 | 6 | 7 | 8 | 9 | org.eclipse.jdt.core.javabuilder 10 | 11 | 12 | 13 | 14 | 15 | org.eclipse.jdt.core.javanature 16 | 17 | 18 | -------------------------------------------------------------------------------- /sdk/java/lib/src/org/meshpoint/anode/bridge/Env.java: -------------------------------------------------------------------------------- 1 | package org.meshpoint.anode.bridge; 2 | 3 | /* 4 | * NOTE that this is a stub class only. 5 | */ 6 | 7 | import org.meshpoint.anode.idl.InterfaceManager; 8 | 9 | public class Env { 10 | public static Env getCurrent() {return (Env)null;} 11 | public InterfaceManager getInterfaceManager() {return (InterfaceManager)null;} 12 | } 13 | -------------------------------------------------------------------------------- /sdk/java/lib/src/org/meshpoint/anode/idl/Dictionary.java: -------------------------------------------------------------------------------- 1 | package org.meshpoint.anode.idl; 2 | 3 | public interface Dictionary {} 4 | -------------------------------------------------------------------------------- /sdk/java/lib/src/org/meshpoint/anode/idl/IDLInterface.java: -------------------------------------------------------------------------------- 1 | package org.meshpoint.anode.idl; 2 | 3 | /* 4 | * NOTE that this is a stub class only. 5 | */ 6 | 7 | public class IDLInterface {} 8 | -------------------------------------------------------------------------------- /sdk/java/lib/src/org/meshpoint/anode/idl/InterfaceManager.java: -------------------------------------------------------------------------------- 1 | package org.meshpoint.anode.idl; 2 | 3 | /* 4 | * NOTE that this is a stub class only. 5 | */ 6 | 7 | public class InterfaceManager { 8 | public synchronized IDLInterface getByName(String name) {return (IDLInterface)null;} 9 | public synchronized IDLInterface getByClass(Class javaClass) {return (IDLInterface)null;} 10 | } 11 | -------------------------------------------------------------------------------- /sdk/java/lib/src/org/meshpoint/anode/java/Base.java: -------------------------------------------------------------------------------- 1 | package org.meshpoint.anode.java; 2 | 3 | /* 4 | * NOTE that this is a stub class only. 5 | */ 6 | 7 | import org.meshpoint.anode.idl.IDLInterface; 8 | 9 | public class Base { 10 | protected Base(IDLInterface iface) {} 11 | } 12 | -------------------------------------------------------------------------------- /sdk/java/lib/src/org/meshpoint/anode/module/IModule.java: -------------------------------------------------------------------------------- 1 | package org.meshpoint.anode.module; 2 | 3 | public interface IModule { 4 | public Object startModule(IModuleContext ctx); 5 | public void stopModule(); 6 | } 7 | -------------------------------------------------------------------------------- /sdk/java/lib/src/org/meshpoint/anode/module/IModuleContext.java: -------------------------------------------------------------------------------- 1 | package org.meshpoint.anode.module; 2 | 3 | public interface IModuleContext { 4 | public Object getModuleExports(); 5 | public long getEventThreadId(); 6 | } 7 | -------------------------------------------------------------------------------- /sdk/java/lib/src/org/w3c/dom/Array.java: -------------------------------------------------------------------------------- 1 | package org.w3c.dom; 2 | 3 | public interface Array {} 4 | -------------------------------------------------------------------------------- /sdk/java/lib/src/org/w3c/dom/ByteArray.java: -------------------------------------------------------------------------------- 1 | package org.w3c.dom; 2 | 3 | public interface ByteArray extends PrimitiveArray { 4 | public int getLength(); 5 | public void setLength(int length); 6 | public byte getElement(int index); 7 | public void setElement(int index, byte value); 8 | } 9 | -------------------------------------------------------------------------------- /sdk/java/lib/src/org/w3c/dom/DoubleArray.java: -------------------------------------------------------------------------------- 1 | package org.w3c.dom; 2 | 3 | public interface DoubleArray extends PrimitiveArray { 4 | public int getLength(); 5 | public void setLength(int length); 6 | public double getElement(int index); 7 | public void setElement(int index, double value); 8 | } 9 | -------------------------------------------------------------------------------- /sdk/java/lib/src/org/w3c/dom/IntegerArray.java: -------------------------------------------------------------------------------- 1 | package org.w3c.dom; 2 | 3 | public interface IntegerArray extends PrimitiveArray { 4 | public int getLength(); 5 | public void setLength(int length); 6 | public int getElement(int index); 7 | public void setElement(int index, int value); 8 | } 9 | -------------------------------------------------------------------------------- /sdk/java/lib/src/org/w3c/dom/LongArray.java: -------------------------------------------------------------------------------- 1 | package org.w3c.dom; 2 | 3 | public interface LongArray extends PrimitiveArray { 4 | public int getLength(); 5 | public void setLength(int length); 6 | public long getElement(int index); 7 | public void setElement(int index, long value); 8 | } 9 | -------------------------------------------------------------------------------- /sdk/java/lib/src/org/w3c/dom/ObjectArray.java: -------------------------------------------------------------------------------- 1 | package org.w3c.dom; 2 | 3 | public interface ObjectArray extends Array { 4 | public int getLength(); 5 | public void setLength(int length); 6 | public T getElement(int index); 7 | public void setElement(int index, T value); 8 | } 9 | -------------------------------------------------------------------------------- /sdk/java/lib/src/org/w3c/dom/PrimitiveArray.java: -------------------------------------------------------------------------------- 1 | package org.w3c.dom; 2 | 3 | public interface PrimitiveArray extends Array { 4 | 5 | } 6 | -------------------------------------------------------------------------------- /sdk/java/tools/stubgen.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/paddybyers/anode/0dd99e2ec33e80c6ec46ed769530fe208bfcf488/sdk/java/tools/stubgen.jar --------------------------------------------------------------------------------