upm/src/_upm.i
Noel Eck 20aa4962f0 SWIG: Moved common SWIG syntax to ${libname}.i
This commit moves common SWIG syntax to a ${libname}.i for sensor
libraries.  Much of the swig content was originally duplicated for
each wrapper language which has lead to inconsistencies between wrappers
over time.  This commit moves all swig syntax to a common file.  Language
specific swig syntax can be added with #ifdef SWIG<LANGUAGE>.

The src/CMakeLists.txt will look first for a language-specific .i file,
then fall back to ${libname}.i.  In this way, it's possible to override
the common ${libname}.i file.  If a fallback .i file does NOT exist,
UPM CMake will generate a simple interface file for all languages.

Example:
    If no src/abp/pyupm_abp.i and no src/abp/abp.i then
    generate ${CMAKE_CURRENT_BINARY_DIR}/abp.i

When src/CMakeLists.txt uses a common ${libname}.i, it adds a -module
<language>upm_${libname} to the swig command line.

In the example below, a -module argument is provided for both Java and
Javascript, while the python module takes all syntax from pyupm_abp.i.

    SWIG FILE              Language       CMake added SWIG args
    ---------------        ----------     ---------------------
    src/abp/abp.i          java           -module javaupm_abp
    src/abp/abp.i          javascript     -module jsupm_abp
    src/abp/pyupm_abp.i    python

This commit removes ~4500 redundant lines for the UPM repository and
helps promote uniformity for the SWIG'ed languages.

Signed-off-by: Noel Eck <noel.eck@intel.com>
2018-02-21 10:51:44 -08:00

111 lines
2.9 KiB
OpenEdge ABL

/*
* This file provides additional non-wrapper code functionality for use
* throughout the UPM repository. This file is intended to be %imported
* from the top-level common_top.i (not directly by UPM libraries).
*
* No wrapper code will be generated from importing this .i file.
*/
/* Macro for adding JAVA installISR w/runnable.
UPM_Classname - UPM class name w/namespace.
example usage: JAVA_ADD_INSTALLISR(upm::A110x)
*/
%define JAVA_ADD_INSTALLISR(UPM_Classname)
%extend UPM_Classname {
void installISR(jobject runnable)
{
$self->installISR(mraa_java_isr_callback, runnable);
}
}
%enddef
/* Macro for adding JAVA installISR w/runnable for a GPIO
UPM_Classname - UPM class name w/namespace.
example usage: JAVA_ADD_INSTALLISR_GPIO(upm::A110x)
Requires: Define GETTER in the appropiate .i file with the getter
function name.
*/
%define JAVA_ADD_INSTALLISR_GPIO(UPM_Classname)
%extend UPM_Classname {
void installISR(int gpio, mraa::Edge level, jobject runnable)
{
/* delete any existing ISR and GPIO context */
$self->uninstallISR();
/* create gpio context */
mraa::Gpio* swg_gpioIntr = $self->GETTER;
swg_gpioIntr->dir(mraa::DIR_IN);
swg_gpioIntr->isr(level, runnable);
}
}
%enddef
/* Macro for adding JAVA installISR for GPIO interrupt w/runnable.
UPM_Classname - UPM class name w/namespace.
example usage: JAVA_ADD_INSTALLISR_INTERRUPT(upm::A110x)
Requires: Define INTERRUPT in the appropiate .i file with the
interrupt type.
*/
%define JAVA_ADD_INSTALLISR_INTERRUPT(UPM_Classname)
%extend UPM_Classname {
void installISR(INTERRUPT intr, int gpio,
mraa::Edge level, jobject runnable)
{
$self->installISR(intr, gpio, level, mraa_java_isr_callback, runnable);
}
}
%enddef
/* Macro for adding JAVA installISR for mraa::Edge w/runnable.
UPM_Classname - UPM class name w/namespace.
example usage: JAVA_ADD_INSTALLISR_EDGE(upm::A110x)
*/
%define JAVA_ADD_INSTALLISR_EDGE(UPM_Classname)
%extend UPM_Classname {
void installISR(mraa::Edge level, jobject runnable)
{
$self->installISR(level, mraa_java_isr_callback, runnable);
}
}
%enddef
/* Macro for adding JAVA installISR for pin w/runnable.
UPM_Classname - UPM class name w/namespace.
example usage: JAVA_ADD_INSTALLISR_PIN(upm::A110x)
*/
%define JAVA_ADD_INSTALLISR_PIN(UPM_Classname)
%extend UPM_Classname {
void installISR(int pin, jobject runnable)
{
$self->installISR(pin, mraa_java_isr_callback, runnable);
}
}
%enddef
/* Macro for adding JNI loadLibrary dependency.
MyModuleName: Target UPM JAVA package.
example usage: JAVA_JNI_LOADLIBRARY(javaupm_rhusb)
*/
%define JAVA_JNI_LOADLIBRARY(MyModuleName)
%pragma(java) jniclasscode=%{
static {
try {
System.loadLibrary("MyModuleName");
} catch (UnsatisfiedLinkError e) {
System.err.println("Native code library (MyModuleName) failed to load. \n" + e);
System.exit(1);
}
}
%}
%enddef