Add Java API for setting the instance path

This commit is contained in:
Jeremy Lakeman 2016-01-18 11:59:43 +10:30
parent 87ab136d0f
commit b5c62a19d5
4 changed files with 25 additions and 5 deletions

@ -18,7 +18,6 @@ SERVALD_LOCAL_CFLAGS = \
-g \ -g \
-Wall -Wno-unused-variable -Wno-unused-value -Werror \ -Wall -Wno-unused-variable -Wno-unused-value -Werror \
-DSERVALD_VERSION="\"Android\"" -DSERVALD_COPYRIGHT="\"Android\"" \ -DSERVALD_VERSION="\"Android\"" -DSERVALD_COPYRIGHT="\"Android\"" \
-DINSTANCE_PATH="\"/data/data/org.servalproject/var/serval-node\"" \
-DSHELL -DPACKAGE_NAME=\"\" -DPACKAGE_TARNAME=\"\" -DPACKAGE_VERSION=\"\" \ -DSHELL -DPACKAGE_NAME=\"\" -DPACKAGE_TARNAME=\"\" -DPACKAGE_VERSION=\"\" \
-DPACKAGE_STRING=\"\" -DPACKAGE_BUGREPORT=\"\" -DPACKAGE_URL=\"\" \ -DPACKAGE_STRING=\"\" -DPACKAGE_BUGREPORT=\"\" -DPACKAGE_URL=\"\" \
-DHAVE_FUNC_ATTRIBUTE_ERROR=1 \ -DHAVE_FUNC_ATTRIBUTE_ERROR=1 \

@ -18,12 +18,21 @@ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
*/ */
#include <stdlib.h> #include <stdlib.h>
#ifdef HAVE_JNI_H
#include <jni.h>
// Stop OpenJDK 7 from foisting their UNUSED() macro on us in <jni_md.h>
#ifdef UNUSED
# undef UNUSED
#endif
#endif
#include "instance.h" #include "instance.h"
#include "str.h" #include "str.h"
#include "os.h" #include "os.h"
#include "strbuf.h" #include "strbuf.h"
#include "strbuf_helpers.h" #include "strbuf_helpers.h"
/* /*
* A default INSTANCE_PATH can be set on the ./configure command line, eg: * A default INSTANCE_PATH can be set on the ./configure command line, eg:
* *
@ -36,9 +45,6 @@ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
* always use an instance path and never fall back to FHS paths. * always use an instance path and never fall back to FHS paths.
*/ */
#ifdef ANDROID #ifdef ANDROID
# ifndef INSTANCE_PATH
# error Must set INSTANCE_PATH macro on Android systems
# endif
# define SERVAL_ETC_PATH "" # define SERVAL_ETC_PATH ""
# define SERVAL_RUN_PATH "" # define SERVAL_RUN_PATH ""
# define SYSTEM_LOG_PATH "" # define SYSTEM_LOG_PATH ""
@ -98,6 +104,19 @@ const char *instance_path()
return instancepath; return instancepath;
} }
#ifdef HAVE_JNI_H
JNIEXPORT jint JNICALL Java_org_servalproject_servaldna_ServalDCommand_setInstancePath(
JNIEnv *env, jobject UNUSED(this), jobject path)
{
const char *cpath = (*env)->GetStringUTFChars(env, path, NULL);
instancepath = strdup(cpath);
know_instancepath = 1;
(*env)->ReleaseStringUTFChars(env, path, cpath);
return (jint)0;
}
#endif
static int vformf_path(struct __sourceloc __whence, strbuf b, const char *syspath, const char *fmt, va_list ap) static int vformf_path(struct __sourceloc __whence, strbuf b, const char *syspath, const char *fmt, va_list ap)
{ {
if (fmt) if (fmt)

@ -70,6 +70,8 @@ public class ServalDCommand
public static native int server(IJniServer callback, String keyringPin, String[] entryPins); public static native int server(IJniServer callback, String keyringPin, String[] entryPins);
public static native int setInstancePath(String path);
/** /**
* Common entry point into servald command line. * Common entry point into servald command line.
* *

@ -13,7 +13,7 @@ public class ServerControl {
private int loopbackMdpPort; private int loopbackMdpPort;
private int httpPort=0; private int httpPort=0;
private int pid; private int pid;
private static final String restfulUsername="ServalDClient"; public static final String restfulUsername="ServalDClient";
private ServalDClient client; private ServalDClient client;
public ServerControl(){ public ServerControl(){