97 lines
2.9 KiB
OpenEdge ABL
97 lines
2.9 KiB
OpenEdge ABL
/* Copyright (c) 2013-2014 IONU Security, Inc. All rights reserved.
|
|
*
|
|
* SWIG interface for the EyeContainer, wraps the extern "C" interfaces
|
|
*/
|
|
|
|
%module eyeinterface
|
|
|
|
%pragma(java) moduleimports=%{
|
|
import java.util.Date;
|
|
%}
|
|
|
|
/*
|
|
%typemap(out) unsigned char * {
|
|
jbyteArray jresult = env->NewByteArray (len);
|
|
env->SetByteArrayRegion (jresult, 0, len, reinterpret_cast<jbyte*>(buf));
|
|
return array;
|
|
%typemap(in) unsigned char * {
|
|
unsigned char* as_unsigned_char_array(jbyteArray array) {
|
|
int len = env->GetArrayLength ($1);
|
|
unsigned char* buf = new unsigned char[len];
|
|
env->GetByteArrayRegion (array, 0, len, reinterpret_cast<jbyte*>(buf));
|
|
return buf;
|
|
}
|
|
*/
|
|
|
|
/* This allows a C function to return a char ** as a Java String array */
|
|
%typemap(out) char ** {
|
|
int i;
|
|
int len=0;
|
|
jstring temp_string;
|
|
const jclass clazz = (*jenv)->FindClass(jenv, "java/lang/String");
|
|
|
|
while ($1[len]) len++;
|
|
jresult = (*jenv)->NewObjectArray(jenv, len, clazz, NULL);
|
|
/* exception checking omitted */
|
|
|
|
for (i=0; i<len; i++) {
|
|
temp_string = (*jenv)->NewStringUTF(jenv, *result++);
|
|
(*jenv)->SetObjectArrayElement(jenv, jresult, i, temp_string);
|
|
(*jenv)->DeleteLocalRef(jenv, temp_string);
|
|
}
|
|
}
|
|
|
|
/* These 3 typemaps tell SWIG what JNI and Java types to use */
|
|
%typemap(jni) char ** "jobjectArray"
|
|
%typemap(jtype) char ** "String[]"
|
|
%typemap(jstype) char ** "String[]"
|
|
|
|
/* These 2 typemaps handle the conversion of the jtype to jstype typemap type
|
|
and vice versa */
|
|
%typemap(javain) char ** "$javainput"
|
|
%typemap(javaout) char ** {
|
|
return $jnicall;
|
|
}
|
|
|
|
%inline %{
|
|
#include "eyeinterface.h"
|
|
#include "eyering.h"
|
|
%}
|
|
|
|
%include "stl.i"
|
|
%include "various.i"
|
|
%include "typemaps.i"
|
|
%include "carrays.i"
|
|
|
|
%apply char **STRING_ARRAY { char ** }
|
|
%array_class(unsigned char,ByteArr);
|
|
|
|
%include "eyeinterface.h"
|
|
%include "eyering.h"
|
|
|
|
%pragma(java) modulecode=%{
|
|
// bootstrap JNI/Lib
|
|
static {
|
|
System.out.println("[JAVA] " + new Date() + " eyeinterface static init");
|
|
Exception here = new Exception("YOU ARE HERE: " + eyeinterface.class.getClassLoader());
|
|
here.fillInStackTrace();
|
|
//here.printStackTrace(System.out);
|
|
System.out.println("LD_LIBRARY_PATH (Linux): " + System.getenv("LD_LIBRARY_PATH"));
|
|
System.out.println("DYLD_LIBRARY_PATH (OSX): " + System.getenv("DYLD_LIBRARY_PATH"));
|
|
try
|
|
{
|
|
//System.out.println("[JAVA] " + new Date() + " Loading libz... " + System.getProperty("java.library.path"));
|
|
//System.loadLibrary("z");
|
|
System.out.println("[JAVA] " + new Date() + " Loading libeye... " + System.getProperty("java.library.path"));
|
|
System.loadLibrary("eye");
|
|
System.out.println("[JAVA] " + new Date() + " eyeinterface Loaded native libraries!");
|
|
}
|
|
catch (Throwable ex){
|
|
System.err.println("[JAVA] " + new Date() + " FATAL: eyeinterface Unable to load shared library: " + ex.getMessage());
|
|
ex.printStackTrace();
|
|
//throw ex;
|
|
}
|
|
}
|
|
%}
|
|
|