mirror of
https://github.com/PurpleI2P/i2pd
synced 2024-11-10 08:00:38 +03:00
moved hard code into java side and successfully passed back to native
This commit is contained in:
parent
cf5081d300
commit
bc72800fef
@ -44,18 +44,27 @@ JNIEXPORT jstring JNICALL Java_org_purplei2p_i2pd_I2PD_1JNI_getABICompiledWith
|
|||||||
}
|
}
|
||||||
|
|
||||||
JNIEXPORT jstring JNICALL Java_org_purplei2p_i2pd_I2PD_1JNI_startDaemon
|
JNIEXPORT jstring JNICALL Java_org_purplei2p_i2pd_I2PD_1JNI_startDaemon
|
||||||
(JNIEnv * env, jclass clazz) {
|
(JNIEnv * env, jclass clazz, jobjectArray args) {
|
||||||
|
int argc = env->GetArrayLength(args);
|
||||||
|
typedef char *pchar;
|
||||||
|
pchar* argv = new pchar[argc];
|
||||||
|
for (int i = 0; i < argc; i++) {
|
||||||
|
jstring arg = (jstring) env->GetObjectArrayElement(args, i);
|
||||||
|
const char *argStr = env->GetStringUTFChars(arg, 0);
|
||||||
|
size_t len = strlen(argStr);
|
||||||
|
argv[i] = new char[len + 1];
|
||||||
|
strcpy(argv[i], argStr);
|
||||||
|
env->ReleaseStringUTFChars(arg, argStr);
|
||||||
|
}
|
||||||
|
|
||||||
int argc=5;
|
const char* result = i2p::android::start(argc,argv).c_str();
|
||||||
static char* argv[]={
|
|
||||||
strdup("i2pd"),
|
for (int i = 0; i < argc; i++) {
|
||||||
strdup("--conf=/sdcard/i2pd/i2pd.conf"),
|
delete [] argv[i];
|
||||||
strdup("--tunconf=/sdcard/i2pd/tunnels.conf"),
|
}
|
||||||
strdup("--datadir=/data/data/org.purplei2p.i2pd/app_data/"),
|
delete [] argv;
|
||||||
strdup("--service"), strdup("--daemon")
|
|
||||||
};
|
|
||||||
|
|
||||||
return env->NewStringUTF(i2p::android::start(argc,argv).c_str());
|
return env->NewStringUTF(result);
|
||||||
}
|
}
|
||||||
|
|
||||||
JNIEXPORT void JNICALL Java_org_purplei2p_i2pd_I2PD_1JNI_stopDaemon
|
JNIEXPORT void JNICALL Java_org_purplei2p_i2pd_I2PD_1JNI_stopDaemon
|
||||||
|
@ -16,7 +16,7 @@ JNIEXPORT jstring JNICALL Java_org_purplei2p_i2pd_I2PD_1JNI_getABICompiledWith
|
|||||||
(JNIEnv *, jclass);
|
(JNIEnv *, jclass);
|
||||||
|
|
||||||
JNIEXPORT jstring JNICALL Java_org_purplei2p_i2pd_I2PD_1JNI_startDaemon
|
JNIEXPORT jstring JNICALL Java_org_purplei2p_i2pd_I2PD_1JNI_startDaemon
|
||||||
(JNIEnv *, jclass);
|
(JNIEnv *, jclass, jobjectArray args);
|
||||||
|
|
||||||
JNIEXPORT void JNICALL Java_org_purplei2p_i2pd_I2PD_1JNI_stopDaemon
|
JNIEXPORT void JNICALL Java_org_purplei2p_i2pd_I2PD_1JNI_stopDaemon
|
||||||
(JNIEnv *, jclass);
|
(JNIEnv *, jclass);
|
||||||
|
@ -62,7 +62,16 @@ public class DaemonSingleton {
|
|||||||
}
|
}
|
||||||
try {
|
try {
|
||||||
synchronized (DaemonSingleton.this) {
|
synchronized (DaemonSingleton.this) {
|
||||||
daemonStartResult = I2PD_JNI.startDaemon();
|
String args[] = {
|
||||||
|
"i2pd",
|
||||||
|
"--conf=/sdcard/i2pd/i2pd.conf",
|
||||||
|
"--tunconf=/sdcard/i2pd/tunnels.conf",
|
||||||
|
"--datadir=/data/data/org.purplei2p.i2pd/app_data/",
|
||||||
|
"--service",
|
||||||
|
"--daemon"
|
||||||
|
};
|
||||||
|
|
||||||
|
daemonStartResult = I2PD_JNI.startDaemon(args);
|
||||||
if("ok".equals(daemonStartResult)){
|
if("ok".equals(daemonStartResult)){
|
||||||
state=State.startedOkay;
|
state=State.startedOkay;
|
||||||
setStartedOkay(true);
|
setStartedOkay(true);
|
||||||
|
@ -6,7 +6,7 @@ public class I2PD_JNI {
|
|||||||
* returns error info if failed
|
* returns error info if failed
|
||||||
* returns "ok" if daemon initialized and started okay
|
* returns "ok" if daemon initialized and started okay
|
||||||
*/
|
*/
|
||||||
public static native String startDaemon();
|
public static native String startDaemon(String args[]);
|
||||||
//should only be called after startDaemon() success
|
//should only be called after startDaemon() success
|
||||||
public static native void stopDaemon();
|
public static native void stopDaemon();
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user