-/Makefile
-/Makefile.in
+Makefile
+Makefile.in
/aclocal.m4
/autom4te.cache/
+/config.guess
/config.log
/config.status
+/config.sub
/configure
+/depcomp
/install-sh
+/libtool
+/ltmain.sh
/missing
*.jar
*.class
+*.o
+*.lo
+*.la
+.deps/
+.libs/
+/lib/libsigrokandroidutils.pc
+SUBDIRS = lib
+
pkgdata_DATA = device_filter.xml
jardir = $(prefix)/jar
#!/bin/sh
+libtoolize --install --copy --quiet || exit 1
aclocal || exit 1
automake --add-missing --copy --foreign || exit 1
autoconf || exit 1
[ANDROID_PLATFORM="$withval"],
[ANDROID_PLATFORM=android-14])
+LT_INIT
+AC_PROG_CXX
+
AC_SUBST([ANDROID_SDK])
AC_SUBST([ANDROID_PLATFORM])
-AC_OUTPUT([Makefile])
+AC_OUTPUT([Makefile lib/Makefile lib/libsigrokandroidutils.pc])
--- /dev/null
+lib_LTLIBRARIES = libsigrokandroidutils.la
+
+libsigrokandroidutils_la_CXXFLAGS = -fno-exceptions
+
+libsigrokandroidutils_la_SOURCES = \
+ jvm_glue.cpp \
+ envsetup.cpp
+
+pkgconfigdir = $(libdir)/pkgconfig
+pkgconfig_DATA = libsigrokandroidutils.pc
+
+library_includedir = $(includedir)/libsigrokandroidutils
+library_include_HEADERS = libsigrokandroidutils.h
+noinst_HEADERS = libsigrokandroidutils-internal.h
--- /dev/null
+/*
+ * This file is part of the sigrok project.
+ *
+ * Copyright (C) 2014 Marcus Comstedt <marcus@mc.pp.se>
+ *
+ * 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 3 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, see <http://www.gnu.org/licenses/>.
+ */
+
+#include "libsigrokandroidutils.h"
+#include "libsigrokandroidutils-internal.h"
+
+SRAU_API void srau_init_environment(void)
+{
+ JNIEnv* env;
+
+ int attach_mode = srau_get_java_env(&env);
+
+ if (attach_mode < 0)
+ return;
+
+ jclass envc = srau_get_environment_class(env);
+ if (!envc)
+ return;
+
+ jmethodID getEnv = env->GetStaticMethodID(envc, "getEnvironment",
+ "()[Ljava/lang/String;");
+ jobjectArray envs =
+ (jobjectArray)env->CallStaticObjectMethod(envc, getEnv);
+ jsize i, envn = env->GetArrayLength(envs);
+ for (i=0; i<envn; i+=2) {
+ jstring key = (jstring)env->GetObjectArrayElement(envs, i);
+ jstring value = (jstring)env->GetObjectArrayElement(envs, i+1);
+ const char *utfkey = env->GetStringUTFChars(key, 0);
+ const char *utfvalue = env->GetStringUTFChars(value, 0);
+ setenv(utfkey, utfvalue, 1);
+ env->ReleaseStringUTFChars(value, utfvalue);
+ env->ReleaseStringUTFChars(key, utfkey);
+ env->DeleteLocalRef(value);
+ env->DeleteLocalRef(key);
+ }
+ env->DeleteLocalRef(envs);
+ env->DeleteLocalRef(envc);
+
+ srau_unget_java_env(attach_mode);
+}
--- /dev/null
+/*
+ * This file is part of the sigrok project.
+ *
+ * Copyright (C) 2014 Marcus Comstedt <marcus@mc.pp.se>
+ *
+ * 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 3 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, see <http://www.gnu.org/licenses/>.
+ */
+
+#include "libsigrokandroidutils.h"
+#include "libsigrokandroidutils-internal.h"
+
+static JavaVM *g_jvm = NULL;
+static jclass g_environment_class = 0;
+
+SRAU_PRIV int srau_get_java_env(JNIEnv **env)
+{
+ jint st;
+
+ if (g_jvm == NULL) {
+ return -1;
+ }
+
+ st = g_jvm->GetEnv((void **)env, JNI_VERSION_1_6);
+
+ if (st == JNI_EDETACHED) {
+ st = g_jvm->AttachCurrentThread(env, NULL);
+ if (st == JNI_OK)
+ return 1;
+ }
+
+ return (st == JNI_OK? 0 : -1);
+}
+
+SRAU_PRIV void srau_unget_java_env(int mode)
+{
+ if (mode == 1) {
+ g_jvm->DetachCurrentThread();
+ }
+}
+
+SRAU_PRIV jclass srau_get_environment_class(JNIEnv *env)
+{
+ if (env && g_environment_class) {
+ return (jclass)env->NewLocalRef(g_environment_class);
+ } else {
+ return 0;
+ }
+}
+
+jint JNI_OnLoad(JavaVM *vm, void *reserved)
+{
+ JNIEnv* env;
+
+ (void)reserved;
+
+ if (vm->GetEnv((void **)&env, JNI_VERSION_1_6) != JNI_OK) {
+ return -1;
+ }
+
+ jclass envc = env->FindClass("org/sigrok/androidutils/Environment");
+ if (envc) {
+ g_environment_class = (jclass)env->NewGlobalRef(envc);
+ env->DeleteLocalRef(envc);
+ }
+
+ g_jvm = vm;
+
+ return JNI_VERSION_1_6;
+}
+
+void JNI_OnUnload(JavaVM *vm, void *reserved)
+{
+ JNIEnv* env;
+
+ (void)reserved;
+
+ g_jvm = NULL;
+
+ if (vm->GetEnv((void **)&env, JNI_VERSION_1_6) != JNI_OK) {
+ return;
+ }
+
+ if (g_environment_class) {
+ env->DeleteGlobalRef(g_environment_class);
+ g_environment_class = 0;
+ }
+}
--- /dev/null
+/*
+ * This file is part of the sigrok project.
+ *
+ * Copyright (C) 2014 Marcus Comstedt <marcus@mc.pp.se>
+ *
+ * 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 3 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, see <http://www.gnu.org/licenses/>.
+ */
+
+#ifndef LIBSIGROKANDROIDUTILS_LIBSIGROKANDROIDUTILS_INTERNAL_H
+#define LIBSIGROKANDROIDUTILS_LIBSIGROKANDROIDUTILS_INTERNAL_H
+
+#include <jni.h>
+#include <stdlib.h>
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+SRAU_PRIV int srau_get_java_env(JNIEnv **env);
+SRAU_PRIV void srau_unget_java_env(int mode);
+SRAU_PRIV jclass srau_get_environment_class(JNIEnv *env);
+
+#ifdef __cplusplus
+}
+#endif
+
+#endif
+
--- /dev/null
+/*
+ * This file is part of the sigrok project.
+ *
+ * Copyright (C) 2014 Marcus Comstedt <marcus@mc.pp.se>
+ *
+ * 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 3 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, see <http://www.gnu.org/licenses/>.
+ */
+
+#ifndef LIBSIGROKANDROIDUTILS_LIBSIGROKANDROIDUTILS_H
+#define LIBSIGROKANDROIDUTILS_LIBSIGROKANDROIDUTILS_H
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+/*
+ * Use SRAU_API to mark public API symbols, and SRAU_PRIV for private symbols.
+ *
+ * Variables and functions marked 'static' are private already and don't
+ * need SR_PRIV. However, functions which are not static (because they need
+ * to be used in other libsigrokandroidutils-internal files) but are also
+ * not meant to be part of the public libsigrokandroidutils API, must use
+ * SRAU_PRIV.
+ *
+ * This uses the 'visibility' feature of gcc (requires gcc >= 4.0).
+ *
+ * Details: http://gcc.gnu.org/wiki/Visibility
+ */
+
+/* Marks public libsigrokandroidutils API symbols. */
+#define SRAU_API __attribute__((visibility("default")))
+
+/* Marks private, non-public libsigrokandroidutils symbols (not part of the API). */
+#define SRAU_PRIV __attribute__((visibility("hidden")))
+
+
+
+SRAU_API void srau_init_environment(void);
+
+#ifdef __cplusplus
+}
+#endif
+
+#endif
+
--- /dev/null
+prefix=@prefix@
+exec_prefix=@exec_prefix@
+libdir=@libdir@
+includedir=@includedir@
+
+Name: libsigrokandroidutils
+Description: Android support code for sigrok
+URL: http://www.sigrok.org
+Version: @VERSION@
+Libs: -L${libdir} -lsigrokandroidutils
+Cflags: -I${includedir}
+