From 4809d7d585f85066e98dd7857b6ef7375966381e Mon Sep 17 00:00:00 2001 From: Jeremy Lakeman Date: Tue, 3 Apr 2018 16:25:22 +0930 Subject: [PATCH] Link java api into shared library by specifying features --- Makefile.in | 10 +++------- jni_commandline.c | 13 +++++++++++++ jni_server.c | 3 +++ servald_features.c | 1 + jni_instance.c => servald_jni_features.c | 15 +++++---------- sourcefiles.mk | 1 - test_features.c | 1 + 7 files changed, 26 insertions(+), 18 deletions(-) rename jni_instance.c => servald_jni_features.c (64%) diff --git a/Makefile.in b/Makefile.in index 4cef5d2d..2d9b0cd1 100644 --- a/Makefile.in +++ b/Makefile.in @@ -53,10 +53,10 @@ SERVAL_DAEMON_OBJS = \ ifeq (@HAVE_JNI_H@,yes) -SERVAL_DAEMON_JNI_OBJS = \ - $(addprefix $(OBJSDIR_SERVALD)/, $(SERVAL_DAEMON_JNI_SOURCES:.c=.o)) +SERVAL_DAEMON_JNI_OBJS = $(OBJSDIR_SERVALD)/servald_jni_features.o -SERVAL_DAEMON_OBJS += $(SERVAL_DAEMON_JNI_OBJS) +SERVAL_DAEMON_OBJS += \ + $(addprefix $(OBJSDIR_SERVALD)/, $(SERVAL_DAEMON_JNI_SOURCES:.c=.o)) endif @@ -366,7 +366,6 @@ libservaldaemon.a: _servald.a $(LIBSODIUM_A) libservaldaemon.so: \ $(OBJSDIR_SERVALD)/servald_features.o \ $(OBJSDIR_SERVALD)/log_output_console.o \ - $(OBJSDIR_SERVALD)/log_output_file.o \ $(SERVAL_DAEMON_JNI_OBJS) \ _servald.a \ $(LIBSODIUM_A) @@ -379,7 +378,6 @@ libservaldaemon.so: \ # to be pulled into the link. servald: $(OBJSDIR_SERVALD)/servald_features.o \ $(OBJSDIR_SERVALD)/log_output_console.o \ - $(OBJSDIR_SERVALD)/log_output_file.o \ libservaldaemon.a @echo LINK $@ @$(CC) -Wall -o $@ $^ $(LDFLAGS) @@ -393,7 +391,6 @@ ifneq ($(SWIFTC),) # Only provide Swift targets if the Swift compiler is availab # package. servaldswift: $(srcdir)/servaldswift.swift \ $(OBJSDIR_SERVALD)/servald_features.o \ - $(OBJSDIR_SERVALD)/log_output_file.o \ libservaldaemon.a \ $(SWIFT_MODULE_NAME).swiftmodule \ libServalDNA.a @@ -410,7 +407,6 @@ servaldwrap: $(OBJSDIR_SERVALD)/servalwrap.o @$(CC) -Wall -o $@ $^ $(LDFLAGS) serval-tests: $(OBJSDIR_SERVALD)/test_features.o \ - $(OBJSDIR_SERVALD)/log_output_console.o \ libservaldaemon.a @echo LINK $@ @$(CC) -Wall -o $@ $^ $(LDFLAGS) diff --git a/jni_commandline.c b/jni_commandline.c index c6802a25..1236b136 100644 --- a/jni_commandline.c +++ b/jni_commandline.c @@ -27,6 +27,10 @@ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. #include "strbuf_helpers.h" #include "conf.h" #include "debug.h" +#include "instance.h" +#include "feature.h" + +DEFINE_FEATURE(jni_commandline); static struct cli_vtable cli_vtable_jni; @@ -194,6 +198,15 @@ static int initJniTypes(JNIEnv *env) return 0; } +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; +} + /* JNI entry point to command line. See org.servalproject.servald.ServalD class for the Java side. JNI method descriptor: "(Ljava/util/List;[Ljava/lang/String;)I" */ diff --git a/jni_server.c b/jni_server.c index 9dfaa4ca..05d8da4f 100644 --- a/jni_server.c +++ b/jni_server.c @@ -26,6 +26,9 @@ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. #include "conf.h" #include "instance.h" #include "httpd.h" +#include "feature.h" + +DEFINE_FEATURE(jni_server); static JNIEnv *server_env=NULL; static jclass IJniServer= NULL; diff --git a/servald_features.c b/servald_features.c index 21ffc604..ea943756 100644 --- a/servald_features.c +++ b/servald_features.c @@ -52,6 +52,7 @@ void servald_features() USE_FEATURE(dna_helper); USE_FEATURE(directory_client); + USE_FEATURE(log_output_file); USE_FEATURE(http_server); USE_FEATURE(http_rhizome); diff --git a/jni_instance.c b/servald_jni_features.c similarity index 64% rename from jni_instance.c rename to servald_jni_features.c index 06179b3d..662e28be 100644 --- a/jni_instance.c +++ b/servald_jni_features.c @@ -1,5 +1,5 @@ /* -Serval DNA JNI instance directory path +Serval DNA daemon features Copyright (C) 2016 Flinders University This program is free software; you can redistribute it and/or @@ -17,15 +17,10 @@ along with this program; if not, write to the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. */ -#include -#include "jni_common.h" -#include "instance.h" +#include "feature.h" -JNIEXPORT jint JNICALL Java_org_servalproject_servaldna_ServalDCommand_setInstancePath( - JNIEnv *env, jobject UNUSED(this), jobject path) +void servald_jni_features() { - const char *cpath = (*env)->GetStringUTFChars(env, path, NULL); - set_instance_path(cpath); - (*env)->ReleaseStringUTFChars(env, path, cpath); - return (jint)0; + USE_FEATURE(jni_commandline); + USE_FEATURE(jni_server); } diff --git a/sourcefiles.mk b/sourcefiles.mk index a6c5a4e4..7ccb6388 100644 --- a/sourcefiles.mk +++ b/sourcefiles.mk @@ -130,7 +130,6 @@ SERVAL_DAEMON_SOURCES = \ SERVAL_DAEMON_JNI_SOURCES = \ jni_common.c \ jni_commandline.c \ - jni_instance.c \ jni_server.c SERVAL_DAEMON_SWIFT_SOURCES = \ diff --git a/test_features.c b/test_features.c index 3123d4b9..d1b543ac 100644 --- a/test_features.c +++ b/test_features.c @@ -26,6 +26,7 @@ void test_features() USE_FEATURE(cli_log); USE_FEATURE(cli_vomp_console); USE_FEATURE(cli_tests); + USE_FEATURE(log_output_console); } void command_cleanup() {}