Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Merge branch 'master' of github.com:paddybyers/anode

  • Loading branch information...
commit d29e2404f333b4184fb5b34d4e98f3e6b74251e5 2 parents 5510de4 + f727428
@paddybyers authored
View
1  libnode/jni/src/defines.h
@@ -17,7 +17,6 @@
#ifndef DEFINES_H
#define DEFINES_H
-#define MODULE_PATH "/data/data/org.meshpoint.anode/node_modules"
#define DEFAULT_MODE (S_IRWXU | S_IRWXG | S_IROTH | S_IXOTH)
#endif
View
23 libnode/jni/src/org_meshpoint_anode_RuntimeNative.cpp
@@ -71,19 +71,22 @@ static int getNativeArgs(JNIEnv *jniEnv, jobjectArray jargv, char ***pargv) {
/*
* Class: org_meshpoint_anode_RuntimeNative
* Method: nodeInit
- * Signature: ([Ljava/lang/String;)V
+ * Signature: ([Ljava/lang/String;Ljava/lang/String;)V
*/
JNIEXPORT void JNICALL Java_org_meshpoint_anode_RuntimeNative_nodeInit
- (JNIEnv *jniEnv, jclass, jobjectArray jargv) {
+ (JNIEnv *jniEnv, jclass, jobjectArray jargv, jstring jModulePath) {
LOGV("Java_org_meshpoint_anode_RuntimeNative_nodeInit: ent\n");
-
- /* set environment variable to support modules */
- setenv("NODE_PATH", MODULE_PATH, 0);
-
- /* process node arguments */
- char **argv;
- int argc;
- if((argc = getNativeArgs(jniEnv, jargv, &argv)) >= 0)
+
+ /* set environment variable to support node modules */
+ const char *modulePath = jniEnv->GetStringUTFChars(jModulePath, 0);
+ setenv("NODE_PATH", modulePath, 0);
+ jniEnv->ReleaseStringUTFChars(jModulePath, modulePath);
+ modulePath = NULL;
+
+ /* process node arguments */
+ char **argv;
+ int argc;
+ if((argc = getNativeArgs(jniEnv, jargv, &argv)) >= 0)
node::Initialize(argc, argv);
LOGV("Java_org_meshpoint_anode_RuntimeNative_nodeInit: ret\n");
}
View
2  libnode/jni/src/org_meshpoint_anode_RuntimeNative.h
@@ -37,7 +37,7 @@ extern "C" {
* Signature: ([Ljava/lang/String;)V
*/
JNIEXPORT void JNICALL Java_org_meshpoint_anode_RuntimeNative_nodeInit
- (JNIEnv *, jclass, jobjectArray);
+ (JNIEnv *, jclass, jobjectArray, jstring jModulePath);
/*
* Class: org_meshpoint_anode_RuntimeNative
View
11 libnode/src/org/meshpoint/anode/RuntimeNative.java
@@ -51,13 +51,20 @@
* @throws UnsatisifiedLinkError if there was a problem initialising the native library
*/
static void init(Context ctx, String[] argv) throws IOException {
+ char sep = File.separatorChar;
+ String packageName = ctx.getPackageName();
+
+ // Example: `/data/data/org.mypackage.android/node_modules`
+ // TODO: make the node dynamic library not depend on assumed /data/data filesystem structure
+ String modulePath = sep + "data" + sep + "data" + sep + packageName + sep + "node_modules";
+
try {
extractLib(ctx, RUNTIME_PATH, RUNTIME_LIBRARY);
System.load(RUNTIME_PATH + '/' + RUNTIME_LIBRARY);
extractLib(ctx, MODULE_PATH, BRIDGE_LIBRARY);
System.load(MODULE_PATH + '/' + BRIDGE_LIBRARY);
Log.v(TAG, "init: loaded libraries");
- nodeInit(argv);
+ nodeInit(argv, modulePath);
} catch(UnsatisfiedLinkError e) {
Log.v(TAG, "init: unable to load library: " + e);
throw e;
@@ -70,7 +77,7 @@ static void init(Context ctx, String[] argv) throws IOException {
/**
* Initialise the native node runtime
*/
- static native void nodeInit(String[] argv);
+ static native void nodeInit(String[] argv, String modulePath);
/**
* Dispose the native node runtime

0 comments on commit d29e240

Please sign in to comment.
Something went wrong with that request. Please try again.