diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index fcc534ac..92bf15aa 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -437,16 +437,10 @@ macro(upm_swig_java) set_source_files_properties (javaupm_${libname}.i PROPERTIES CPLUSPLUS ON) set_source_files_properties (javaupm_${libname}.i PROPERTIES SWIG_FLAGS ";-package;upm_${libname};-I${CMAKE_BINARY_DIR}/src") - # NOTE, ${module_src} is ONLY needed when swig'ing to JAVA. This is - # because *some* upm libraries have ifdef's for JAVA and SWIG in their - # source (cxx) which builds in different functionality. Because of this, - # the source must be added when building the JAVA wrapper. - # See issue #518 - # TODO: Fix this somehow if (CMAKE_VERSION VERSION_LESS "3.8") - swig_add_module (javaupm_${libname} java javaupm_${libname}.i ${module_src}) + swig_add_module (javaupm_${libname} java javaupm_${libname}.i) else () - swig_add_library (javaupm_${libname} LANGUAGE java SOURCES javaupm_${libname}.i ${module_src}) + swig_add_library (javaupm_${libname} LANGUAGE java SOURCES javaupm_${libname}.i) endif () # If the C++ target depends on C++ interfaces, make the JAVA target diff --git a/src/_upm.i b/src/_upm.i new file mode 100644 index 00000000..f4790af3 --- /dev/null +++ b/src/_upm.i @@ -0,0 +1,29 @@ +/* Macro for adding JAVA runnables. + example usage: JAVA_ADD_INSTALLISR(upm::A110x) + UPMClassName - UPM class name w/namespace. +*/ +%define JAVA_ADD_INSTALLISR(UPMClassName) +%extend UPMClassName { + void installISR(jobject runnable) + { + $self->installISR(mraa_java_isr_callback, runnable); + } +} +%enddef + +/* Macro for adding JNI loadLibrary dependency. + example usage: JAVA_JNI_LOADLIBRARY(javaupm_rhusb) + PackageName: Target UPM JAVA package. +*/ +%define JAVA_JNI_LOADLIBRARY(PackageName) +%pragma(java) jniclasscode=%{ +static { + try { + System.loadLibrary("PackageName"); + } catch (UnsatisfiedLinkError e) { + System.err.println("Native code library (PackageName) failed to load. \n" + e); + System.exit(1); + } +} +%} +%enddef diff --git a/src/a110x/a110x.cxx b/src/a110x/a110x.cxx index f6058654..b0b063f5 100644 --- a/src/a110x/a110x.cxx +++ b/src/a110x/a110x.cxx @@ -57,13 +57,6 @@ bool A110X::magnetDetected() return (!mraa_gpio_read(m_gpio) ? true : false); } -#ifdef JAVACALLBACK -void A110X::installISR(jobject runnable) -{ -installISR(mraa_java_isr_callback, runnable); -} -#endif - void A110X::installISR(void (*isr)(void *), void *arg) { if (m_isrInstalled) diff --git a/src/a110x/a110x.hpp b/src/a110x/a110x.hpp index de2147dd..fb5ca86a 100644 --- a/src/a110x/a110x.hpp +++ b/src/a110x/a110x.hpp @@ -85,11 +85,8 @@ namespace upm { * @param arg Pointer to an object to be supplied as an * argument to the ISR. */ -#if defined(SWIGJAVA) || defined(JAVACALLBACK) - void installISR(jobject runnable); -#else void installISR(void (*isr)(void *), void *arg); -#endif + /** * Uninstalls the previously installed ISR * @@ -97,9 +94,6 @@ namespace upm { void uninstallISR(); private: -#if defined(SWIGJAVA) || defined(JAVACALLBACK) - void installISR(void (*isr)(void *), void *arg); -#endif bool m_isrInstalled; mraa_gpio_context m_gpio; diff --git a/src/a110x/common.i b/src/a110x/common.i new file mode 100644 index 00000000..0c8257a3 --- /dev/null +++ b/src/a110x/common.i @@ -0,0 +1,6 @@ +%include "../upm.i" + +%{ +#include "a110x.hpp" +%} +%include "a110x.hpp" diff --git a/src/a110x/javaupm_a110x.i b/src/a110x/javaupm_a110x.i index 4e558725..7443506e 100644 --- a/src/a110x/javaupm_a110x.i +++ b/src/a110x/javaupm_a110x.i @@ -1,20 +1,11 @@ %module javaupm_a110x -%include "../upm.i" %include "stdint.i" %include "typemaps.i" -%{ - #include "a110x.hpp" -%} -%include "a110x.hpp" +%include "common.i" -%pragma(java) jniclasscode=%{ - static { - try { - System.loadLibrary("javaupm_a110x"); - } catch (UnsatisfiedLinkError e) { - System.err.println("Native code library failed to load. \n" + e); - System.exit(1); - } - } -%} +/* Macro for loading javaupm_a110x */ +JAVA_JNI_LOADLIBRARY(javaupm_a110x) + +/* Macro adding an installisr call w/JAVA runnable to A110X */ +JAVA_ADD_INSTALLISR(upm::A110X) diff --git a/src/a110x/jsupm_a110x.i b/src/a110x/jsupm_a110x.i index f6a53050..27befc34 100644 --- a/src/a110x/jsupm_a110x.i +++ b/src/a110x/jsupm_a110x.i @@ -1,8 +1,3 @@ %module jsupm_a110x -%include "../upm.i" -%{ - #include "a110x.hpp" -%} - -%include "a110x.hpp" +%include "common.i" diff --git a/src/a110x/pyupm_a110x.i b/src/a110x/pyupm_a110x.i index 19999662..c82bf319 100644 --- a/src/a110x/pyupm_a110x.i +++ b/src/a110x/pyupm_a110x.i @@ -1,9 +1,4 @@ -// Include doxygen-generated documentation %include "pyupm_doxy2swig.i" %module pyupm_a110x -%include "../upm.i" -%include "a110x.hpp" -%{ - #include "a110x.hpp" -%} +%include "common.i" diff --git a/src/upm.i b/src/upm.i index eb1c5391..0ac47854 100644 --- a/src/upm.i +++ b/src/upm.i @@ -2,6 +2,9 @@ %include "stdint.i" %include "upm_exception.i" +/* Additional swig file w/helper macros to import (but not expose) */ +%import "_upm.i" + %{ #include "version.hpp" %} diff --git a/tests/check_autoloadlibrary.py b/tests/check_autoloadlibrary.py index e91e260c..f4519e71 100755 --- a/tests/check_autoloadlibrary.py +++ b/tests/check_autoloadlibrary.py @@ -36,7 +36,9 @@ class AutoLoadLibrary(u.TestCase): if not '%module' in data: print "%%module not found in %s, skipping" % fileName continue - if not snippet in data: + # Check for the autoload code or the autoload macro + if (not 'JAVA_JNI_LOADLIBRARY(javaupm_' in data) and \ + (not snippet in data): broken_modules.append('%s: %s' % \ (moduleName, os.path.join(subdir, fileName)))