Move JNI setInstancePath() into own source file

This commit is contained in:
Andrew Bettison 2016-10-19 16:26:00 +10:30
parent a3f3de571a
commit 42f62d2b8b
5 changed files with 54 additions and 27 deletions

View File

@ -32,23 +32,31 @@ SERVAL_DAEMON_OBJS = \
$(addprefix $(OBJSDIR_SERVALD)/, $(SERVAL_CLIENT_SOURCES:.c=.o)) \ $(addprefix $(OBJSDIR_SERVALD)/, $(SERVAL_CLIENT_SOURCES:.c=.o)) \
$(addprefix $(OBJSDIR_SERVALD)/, $(MDP_CLIENT_SOURCES:.c=.o)) \ $(addprefix $(OBJSDIR_SERVALD)/, $(MDP_CLIENT_SOURCES:.c=.o)) \
$(addprefix $(OBJSDIR_SERVALD)/, $(SERVAL_DAEMON_SOURCES:.c=.o)) $(addprefix $(OBJSDIR_SERVALD)/, $(SERVAL_DAEMON_SOURCES:.c=.o))
ifeq (@HAVE_JNI_H@,yes)
SERVAL_DAEMON_OBJS += \ SERVAL_DAEMON_JNI_OBJS = \
$(addprefix $(OBJSDIR_SERVALD)/, $(SERVAL_DAEMON_JNI_SOURCES:.c=.o)) $(addprefix $(OBJSDIR_SERVALD)/, $(SERVAL_DAEMON_JNI_SOURCES:.c=.o))
ifeq (@HAVE_JNI_H@,yes)
SERVAL_DAEMON_OBJS += $(SERVAL_DAEMON_JNI_OBJS)
endif endif
SQLITE3_OBJS = \ SQLITE3_OBJS = \
$(addprefix $(OBJSDIR_SERVALD)/, $(notdir $(SQLITE3_SOURCES:.c=.o))) $(addprefix $(OBJSDIR_SERVALD)/, $(notdir $(SQLITE3_SOURCES:.c=.o)))
SERVALD_OBJS = \ SERVALD_OBJS = \
$(SQLITE3_OBJS) \ $(SQLITE3_OBJS) \
$(SERVAL_DAEMON_OBJS) $(SERVAL_DAEMON_OBJS)
LIB_SERVAL_OBJS = \ LIB_SERVAL_OBJS = \
$(addprefix $(OBJSDIR_LIB)/, $(SERVAL_CLIENT_SOURCES:.c=.o)) \ $(addprefix $(OBJSDIR_LIB)/, $(SERVAL_CLIENT_SOURCES:.c=.o)) \
$(addprefix $(OBJSDIR_LIB)/, $(CLIENT_ONLY_SOURCES:.c=.o)) \ $(addprefix $(OBJSDIR_LIB)/, $(CLIENT_ONLY_SOURCES:.c=.o)) \
$(addprefix $(OBJSDIR_LIB)/, $(MDP_CLIENT_SOURCES:.c=.o)) $(addprefix $(OBJSDIR_LIB)/, $(MDP_CLIENT_SOURCES:.c=.o))
MONITOR_CLIENT_OBJS = \ MONITOR_CLIENT_OBJS = \
$(addprefix $(OBJSDIR_LIB)/, $(SERVAL_CLIENT_SOURCES:.c=.o)) \ $(addprefix $(OBJSDIR_LIB)/, $(SERVAL_CLIENT_SOURCES:.c=.o)) \
$(addprefix $(OBJSDIR_LIB)/, $(CLIENT_ONLY_SOURCES:.c=.o)) \ $(addprefix $(OBJSDIR_LIB)/, $(CLIENT_ONLY_SOURCES:.c=.o)) \
$(addprefix $(OBJSDIR_LIB)/, $(MONITOR_CLIENT_SRCS:.c=.o)) $(addprefix $(OBJSDIR_LIB)/, $(MONITOR_CLIENT_SRCS:.c=.o))
SIMULATOR_OBJS = \ SIMULATOR_OBJS = \
$(addprefix $(OBJSDIR_TOOLS)/, $(SIMULATOR_SOURCES:.c=.o)) $(addprefix $(OBJSDIR_TOOLS)/, $(SIMULATOR_SOURCES:.c=.o))
@ -236,8 +244,7 @@ libservald.a: $(SERVALD_OBJS) \
libservald.so: \ libservald.so: \
$(OBJSDIR_SERVALD)/servald_features.o \ $(OBJSDIR_SERVALD)/servald_features.o \
$(OBJSDIR_SERVALD)/jni_commandline.o \ $(SERVAL_DAEMON_JNI_OBJS) \
$(OBJSDIR_SERVALD)/jni_server.o \
libservald.a libservald.a
@echo LINK $@ @echo LINK $@
@$(CC) -Wall -shared -o $@ $^ $(LDFLAGS) @$(CC) -Wall -shared -o $@ $^ $(LDFLAGS)

View File

@ -1,6 +1,6 @@
/* /*
Serval DNA instance directory path Serval DNA instance paths
Copyright (C) 2012 Serval Project Inc. Copyright (C) 2012-2015 Serval Project Inc.
This program is free software; you can redistribute it and/or This program is free software; you can redistribute it and/or
modify it under the terms of the GNU General Public License modify it under the terms of the GNU General Public License
@ -18,21 +18,12 @@ 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:
* *
@ -104,19 +95,12 @@ const char *instance_path()
return instancepath; return instancepath;
} }
#ifdef HAVE_JNI_H void set_instance_path(const char *path)
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(path);
instancepath = strdup(cpath);
know_instancepath = 1; 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)

View File

@ -1,6 +1,7 @@
/* /*
Serval DNA header file - system paths Serval DNA instance paths
Copyright (C) 2014 Serval Project Inc. Copyright (C) 2014-2015 Serval Project Inc.
Copyright (C) 2016 Flinders University
This program is free software; you can redistribute it and/or This program is free software; you can redistribute it and/or
modify it under the terms of the GNU General Public License modify it under the terms of the GNU General Public License
@ -25,6 +26,9 @@ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
#include "strbuf.h" #include "strbuf.h"
const char *instance_path(); // returns NULL if not using an instance path const char *instance_path(); // returns NULL if not using an instance path
void set_instance_path(const char *path);
int create_serval_instance_dir(); int create_serval_instance_dir();
int _formf_serval_etc_path(struct __sourceloc, char *buf, size_t bufsiz, const char *fmt, ...) __attribute__((__ATTRIBUTE_format(printf,4,5))); int _formf_serval_etc_path(struct __sourceloc, char *buf, size_t bufsiz, const char *fmt, ...) __attribute__((__ATTRIBUTE_format(printf,4,5)));

31
jni_instance.c Normal file
View File

@ -0,0 +1,31 @@
/*
Serval DNA JNI instance directory path
Copyright (C) 2016 Flinders University
This program is free software; you can redistribute it and/or
modify it under the terms of the GNU General Public License
as published by the Free Software Foundation; either version 2
of the License, or (at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
*/
#include <assert.h>
#include "jni_common.h"
#include "instance.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);
set_instance_path(cpath);
(*env)->ReleaseStringUTFChars(env, path, cpath);
return (jint)0;
}

View File

@ -124,6 +124,7 @@ SERVAL_DAEMON_SOURCES = \
SERVAL_DAEMON_JNI_SOURCES = \ SERVAL_DAEMON_JNI_SOURCES = \
jni_common.c \ jni_common.c \
jni_commandline.c \ jni_commandline.c \
jni_instance.c \
jni_server.c jni_server.c
MDP_CLIENT_SOURCES = \ MDP_CLIENT_SOURCES = \