SWIGJAVA: Remove the last JAVA ifdefs from src

Removed all references to #ifdef SWIGJAVA and JAVACALLBACK from the
library source.  All java-specific source code has been moved to the
corresponding library's .i file for java.

    * Update library source
    * Update examples where necessary
    * The function pointer methodology has been remove from libraries
      which provided callbacks as both a class and a function pointer
      implementation.  Examples were updated to use the class version
      of callbacks.
    * Updated documentation for SWIGJAVA

Signed-off-by: Noel Eck <noel.eck@intel.com>
This commit is contained in:
Noel Eck
2018-01-23 11:58:12 -08:00
parent d49ab2ac95
commit 666452e873
44 changed files with 280 additions and 509 deletions

View File

@ -600,25 +600,23 @@ void H3LIS331DL::getXYZ(int *x, int *y, int*z)
*z = (m_rawZ - m_adjZ);
}
#ifdef SWIGJAVA
float *H3LIS331DL::getAcceleration()
std::vector<float> H3LIS331DL::getAcceleration()
{
float *v = new float[3];
std::vector<float> v(3);
getAcceleration(&v[0], &v[1], &v[2]);
return v;
}
int *H3LIS331DL::getRawXYZ()
std::vector<int> H3LIS331DL::getRawXYZ()
{
int *v = new int[3];
std::vector<int> v(3);
getRawXYZ(&v[0], &v[1], &v[2]);
return v;
}
int *H3LIS331DL::getXYZ()
std::vector<int> H3LIS331DL::getXYZ()
{
int *v = new int[3];
std::vector<int> v(3);
getXYZ(&v[0], &v[1], &v[2]);
return v;
}
#endif

View File

@ -24,6 +24,7 @@
#pragma once
#include <string>
#include <vector>
#include <mraa/common.hpp>
#include <mraa/i2c.hpp>
@ -594,29 +595,26 @@ namespace upm {
*/
void getXYZ(int *x, int *y, int *z);
#ifdef SWIGJAVA
/**
* Gets acceleration values for each of the axes
*
* @return Array containing X, Y, Z acceleration values
* @return std::vector containing X, Y, Z acceleration values
*/
float *getAcceleration();
std::vector<float> getAcceleration();
/**
* Gets raw axis values
*
* @return Array containing X, Y, Z raw values
* @return std::vector containing X, Y, Z raw values
*/
int *getRawXYZ();
std::vector<int> getRawXYZ();
/**
* Gets adjusted axis values
*
* @return Array containing X, Y, Z adjusted axis values
* @return std::vector containing X, Y, Z adjusted axis values
*/
int *getXYZ();
#endif
std::vector<int> getXYZ();
/**
* Provides public access to the MRAA I2C context of the class for

View File

@ -2,6 +2,10 @@
%include "../upm.i"
%include "cpointer.i"
%include "typemaps.i"
%include "std_vector.i"
%template(IntVector) std::vector<int>;
%template(FloatVector) std::vector<float>;
%apply int *OUTPUT { int *x, int *y, int*z };
%apply float *OUTPUT { float *aX, float *aY, float *aZ };
@ -9,45 +13,8 @@
%ignore i2cContext;
%{
#include "h3lis331dl.hpp"
#include "h3lis331dl.hpp"
%}
%typemap(jni) float* "jfloatArray"
%typemap(jstype) float* "float[]"
%typemap(jtype) float* "float[]"
%typemap(javaout) float* {
return $jnicall;
}
%typemap(out) float *getAcceleration {
$result = JCALL1(NewFloatArray, jenv, 3);
JCALL4(SetFloatArrayRegion, jenv, $result, 0, 3, $1);
delete [] $1;
}
%typemap(jni) int* "jintArray"
%typemap(jstype) int* "int[]"
%typemap(jtype) int* "int[]"
%typemap(javaout) int* {
return $jnicall;
}
%typemap(out) int *getRawXYZ {
$result = JCALL1(NewIntArray, jenv, 3);
JCALL4(SetIntArrayRegion, jenv, $result, 0, 3, (const int*)$1);
}
%typemap(out) int *getXYZ {
$result = JCALL1(NewIntArray, jenv, 3);
JCALL4(SetIntArrayRegion, jenv, $result, 0, 3, (const int*)$1);
}
%ignore getRawXYZ(int *, int *, int *);
%ignore getXYZ(int *, int *, int *);
%ignore getAcceleration(float *, float *, float *);
%include "h3lis331dl.hpp"
JAVA_JNI_LOADLIBRARY(javaupm_h3lis331dl)
JAVA_JNI_LOADLIBRARY(javaupm_h3lis331dl)