code_app/sdk/scannerlib/HGScannerLibJni.cpp

865 lines
32 KiB
C++
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

#include <jni.h>
#include "HGScannerLib.h"
#include <map>
#include <assert.h>
struct JNICallbackParam
{
JavaVM *vm;
jobject obj;
};
extern "C" JNIEXPORT jlong JNICALL Java_com_easing_java_HGScannerLib_LoadImage(
JNIEnv* env, jclass clazz, jstring filePath)
{
(void)clazz;
printf("\nJava_com_easing_java_HGScannerLib_LoadImage\n");
jboolean isCopy;
const char* ptr = env->GetStringUTFChars(filePath, &isCopy);
printf("filePath=%s\n", ptr);
HGLibImage img = HGLib_LoadImage(ptr);
printf("img=0x%p\n", img);
env->ReleaseStringUTFChars(filePath, ptr);
printf("\n");
return (jlong)img;
}
extern "C" JNIEXPORT jboolean JNICALL Java_com_easing_java_HGScannerLib_SaveImage(
JNIEnv* env, jclass clazz, jlong img, jstring filePath, jobject saveParam)
{
(void)clazz;
printf("\nJava_com_easing_java_HGScannerLib_SaveImage\n");
HGLibSaveImageParam saveParam2 = {0};
saveParam2.size = sizeof(HGLibSaveImageParam);
jclass cls = env->GetObjectClass(saveParam);
saveParam2.jpegQuality = (HGUInt)env->GetIntField(saveParam, env->GetFieldID(cls, "jpegQuality", "I"));
saveParam2.tiffCompression = (HGUInt)env->GetIntField(saveParam, env->GetFieldID(cls, "tiffCompression", "I"));
saveParam2.tiffJpegQuality = (HGUInt)env->GetIntField(saveParam, env->GetFieldID(cls, "tiffJpegQuality", "I"));
saveParam2.ocr = (HGBool)env->GetBooleanField(saveParam, env->GetFieldID(cls, "ocr", "Z"));
printf("jpegQuality=%u\n", saveParam2.jpegQuality);
printf("tiffCompression=%u\n", saveParam2.tiffCompression);
printf("tiffJpegQuality=%u\n", saveParam2.tiffJpegQuality);
printf("ocr=%d\n", saveParam2.ocr);
jboolean isCopy;
const char* ptr = env->GetStringUTFChars(filePath, &isCopy);
printf("img=0x%p, filePath=%s\n", (HGLibImage)img, ptr);
HGBool ret = HGLib_SaveImage((HGLibImage)img, ptr, &saveParam2);
printf("ret=%d\n", ret);
env->ReleaseStringUTFChars(filePath, ptr);
printf("\n");
return (jboolean)ret;
}
extern "C" JNIEXPORT jlong JNICALL Java_com_easing_java_HGScannerLib_CloneImage(
JNIEnv* env, jclass clazz, jlong img, jint type, jint origin)
{
(void)env;
(void)clazz;
printf("\Java_com_easing_java_HGScannerLib_CloneImage\n");
HGLibImage destImg = HGLib_CloneImage((HGLibImage)img, (HGUInt)type, (HGUInt)origin);
printf("destImg=0x%p\n", destImg);
printf("\n");
return (jlong)destImg;
}
extern "C" JNIEXPORT jboolean JNICALL Java_com_easing_java_HGScannerLib_ReleaseImage(
JNIEnv* env, jclass clazz, jlong img)
{
(void)env;
(void)clazz;
printf("\nJava_com_easing_java_HGScannerLib_ReleaseImage\n");
HGBool ret = HGLib_ReleaseImage((HGLibImage)img);
printf("ret=%d\n", ret);
printf("\n");
return (jboolean)ret;
}
extern "C" JNIEXPORT jobject JNICALL Java_com_easing_java_HGScannerLib_GetImageInfo(
JNIEnv* env, jclass clazz, jlong img)
{
(void)clazz;
printf("\nJava_com_easing_java_HGScannerLib_GetImageInfo\n");
jclass cls = env->FindClass("com/easing/java/HGLibImageInfo");
jmethodID init = env->GetMethodID(cls, "<init>", "()V");
jobject imgInfo = env->NewObject(cls, init);
HGLibImageInfo imgInfo2 = {0};
HGBool ret = HGLib_GetImageInfo((HGLibImage)img, &imgInfo2);
printf("ret=%d\n", ret);
if (ret)
{
env->SetIntField(imgInfo, env->GetFieldID(cls, "width", "I"), (jint)imgInfo2.width);
env->SetIntField(imgInfo, env->GetFieldID(cls, "height", "I"), (jint)imgInfo2.height);
env->SetIntField(imgInfo, env->GetFieldID(cls, "type", "I"), (jint)imgInfo2.type);
env->SetIntField(imgInfo, env->GetFieldID(cls, "widthStep", "I"), (jint)imgInfo2.widthStep);
env->SetIntField(imgInfo, env->GetFieldID(cls, "origin", "I"), (jint)imgInfo2.origin);
}
printf("\n");
return imgInfo;
}
extern "C" JNIEXPORT jbyteArray JNICALL Java_com_easing_java_HGScannerLib_GetImageData(
JNIEnv* env, jclass clazz, jlong img)
{
(void)clazz;
printf("\nJava_com_easing_java_HGScannerLib_GetImageData\n");
jbyteArray imgData;
HGByte *imgData2 = HGLib_GetImageData((HGLibImage)img);
printf("imgData=0x%p\n", imgData2);
if (NULL != imgData2)
{
HGLibImageInfo imgInfo = {0};
if (HGLib_GetImageInfo((HGLibImage)img, &imgInfo))
{
imgData = env->NewByteArray(imgInfo.widthStep * imgInfo.height);
env->SetByteArrayRegion(imgData, 0, imgInfo.widthStep * imgInfo.height, (const jbyte*)imgData2);
}
else
{
imgData = env->NewByteArray(0);
}
}
else
{
imgData = env->NewByteArray(0);
}
printf("\n");
return imgData;
}
extern "C" JNIEXPORT jobject JNICALL Java_com_easing_java_HGScannerLib_GetImageDpi(
JNIEnv* env, jclass clazz, jlong img)
{
(void)clazz;
printf("\nJava_com_easing_java_HGScannerLib_GetImageDpi\n");
jclass cls = env->FindClass("com/easing/java/HGLibImageDpi");
jmethodID init = env->GetMethodID(cls, "<init>", "()V");
jobject imgDpi = env->NewObject(cls, init);
HGUInt xDpi, yDpi;
HGBool ret = HGLib_GetImageDpi((HGLibImage)img, &xDpi, &yDpi);
printf("ret=%d\n", ret);
if (ret)
{
env->SetIntField(imgDpi, env->GetFieldID(cls, "xDpi", "I"), (jint)xDpi);
env->SetIntField(imgDpi, env->GetFieldID(cls, "yDpi", "I"), (jint)yDpi);
}
printf("\n");
return imgDpi;
}
static JNICallbackParam g_deviceHotPlugParam;
static void HGAPI DeviceHotPlugEventFunc(HGUInt event, const HGChar *deviceName, HGPointer param)
{
(void)param;
if (NULL == g_deviceHotPlugParam.vm)
{
return;
}
HGBool needDetach = HGFALSE;
JNIEnv *env = NULL;
//获取当前native线程是否有没有被附加到jvm环境中
int getEnvStat = g_deviceHotPlugParam.vm->GetEnv((void **)&env, JNI_VERSION_1_6);
if (getEnvStat == JNI_EDETACHED)
{
// 如果没有主动附加到jvm环境中获取到env
if (g_deviceHotPlugParam.vm->AttachCurrentThread((void **)&env, NULL) != 0)
{
return;
}
needDetach = HGTRUE;
}
//通过全局变量g_obj获取到要回调的类
jclass cls = env->GetObjectClass(g_deviceHotPlugParam.obj);
if (NULL != cls)
{
jmethodID jmethodId = env->GetMethodID(cls, "onDeviceHotPlugEvent", "(ILjava/lang/String;)V");
if (NULL != jmethodId)
{
env->CallVoidMethod(g_deviceHotPlugParam.obj, jmethodId, (jint)event, env->NewStringUTF(deviceName));
}
}
if (needDetach)
{
g_deviceHotPlugParam.vm->DetachCurrentThread();
}
}
extern "C" JNIEXPORT jboolean JNICALL Java_com_easing_java_HGScannerLib_InitDevice(
JNIEnv* env, jobject thiz)
{
printf("\nJava_com_easing_java_HGScannerLib_InitDevice\n");
if (NULL != g_deviceHotPlugParam.vm)
{
printf("Already Init Device\n");
return (jboolean)HGFALSE;
}
env->GetJavaVM(&g_deviceHotPlugParam.vm);
g_deviceHotPlugParam.obj = env->NewGlobalRef(thiz);
HGBool ret = HGLib_InitDevice(DeviceHotPlugEventFunc, NULL);
printf("ret=%d\n", ret);
if (!ret)
{
env->DeleteGlobalRef(g_deviceHotPlugParam.obj);
g_deviceHotPlugParam.obj = NULL;
g_deviceHotPlugParam.vm = NULL;
}
printf("\n");
return (jboolean)ret;
}
extern "C" JNIEXPORT jboolean JNICALL Java_com_easing_java_HGScannerLib_DeinitDevice(
JNIEnv* env, jclass clazz)
{
(void)clazz;
printf("\nJava_com_easing_java_HGScannerLib_DeinitDevice\n");
if (NULL == g_deviceHotPlugParam.vm)
{
printf("Do not Init Device yet\n");
return (jboolean)HGFALSE;
}
HGBool ret = HGLib_DeinitDevice();
printf("ret=%d\n", ret);
if (ret)
{
env->DeleteGlobalRef(g_deviceHotPlugParam.obj);
g_deviceHotPlugParam.obj = NULL;
g_deviceHotPlugParam.vm = NULL;
}
printf("\n");
return (jboolean)ret;
}
extern "C" JNIEXPORT jobjectArray JNICALL Java_com_easing_java_HGScannerLib_GetDeviceNameList(
JNIEnv* env, jclass clazz)
{
(void)clazz;
printf("\nJava_com_easing_java_HGScannerLib_GetDeviceNameList\n");
jobjectArray devNameList;
jclass cls = env->FindClass("java/lang/String");
HGChar** devNameList2 = HGLib_GetDeviceNameList();
printf("devNameList=0x%p\n", devNameList2);
if (NULL != devNameList2)
{
HGUInt count = 0;
HGChar** p = devNameList2;
while (0 != *p)
{
printf("devName=%s\n", *p);
++count;
++p;
}
printf("count=%u\n", count);
devNameList = env->NewObjectArray(count, cls, env->NewStringUTF(NULL));
HGUInt i = 0;
while (0 != devNameList2[i])
{
env->SetObjectArrayElement(devNameList, i, env->NewStringUTF(devNameList2[i]));
++i;
}
HGLib_ReleaseDeviceNameList(devNameList2);
}
else
{
printf("cound=%u\n", 0);
devNameList = env->NewObjectArray(0, cls, env->NewStringUTF(NULL));
}
printf("\n");
return devNameList;
}
extern "C" JNIEXPORT jlong JNICALL Java_com_easing_java_HGScannerLib_OpenDevice(
JNIEnv* env, jclass clazz, jstring deviceName)
{
(void)clazz;
printf("\nJava_com_easing_java_HGScannerLib_OpenDevice\n");
jboolean isCopy;
const char* ptr = env->GetStringUTFChars(deviceName, &isCopy);
printf("deviceName=%s\n", ptr);
HGLibDevice dev = HGLib_OpenDevice(ptr);
printf("dev=0x%p\n", dev);
env->ReleaseStringUTFChars(deviceName, ptr);
printf("\n");
return (jlong)dev;
}
extern "C" JNIEXPORT jboolean JNICALL Java_com_easing_java_HGScannerLib_CloseDevice(
JNIEnv* env, jclass clazz, jlong dev)
{
(void)env;
(void)clazz;
printf("\nJava_com_easing_java_HGScannerLib_CloseDevice\n");
HGBool ret = HGLib_CloseDevice((HGLibDevice)dev);
printf("ret=%d\n", ret);
printf("\n");
return (jboolean)ret;
}
extern "C" JNIEXPORT jstring JNICALL Java_com_easing_java_HGScannerLib_GetDeviceSN(
JNIEnv* env, jclass clazz, jlong dev)
{
(void)clazz;
printf("\nJava_com_easing_java_HGScannerLib_GetDeviceSN\n");
jstring sn;
HGChar sn2[256];
HGBool ret = HGLib_GetDeviceSN((HGLibDevice)dev, sn2, 256);
printf("ret=%d\n", ret);
if (ret)
{
sn = env->NewStringUTF(sn2);
}
else
{
sn = env->NewStringUTF(NULL);
}
printf("\n");
return sn;
}
extern "C" JNIEXPORT jstring JNICALL Java_com_easing_java_HGScannerLib_GetDeviceFWVersion(
JNIEnv* env, jclass clazz, jlong dev)
{
(void)clazz;
printf("\nJava_com_easing_java_HGScannerLib_GetDeviceFWVersion\n");
jstring fwVersion;
HGChar fwVersion2[256];
HGBool ret = HGLib_GetDeviceFWVersion((HGLibDevice)dev, fwVersion2, 256);
printf("ret=%d\n", ret);
if (ret)
{
fwVersion = env->NewStringUTF(fwVersion2);
}
else
{
fwVersion = env->NewStringUTF(NULL);
}
printf("\n");
return fwVersion;
}
static std::map<HGLibDevice, JNICallbackParam> g_deviceScanParams;
static void HGAPI DeviceScanEventFunc(HGLibDevice device, HGUInt event, HGBool err, const HGChar *info, HGPointer param)
{
(void)param;
std::map<HGLibDevice, JNICallbackParam>::iterator iter = g_deviceScanParams.find(device);
if (iter == g_deviceScanParams.end() || NULL == iter->second.vm)
{
return;
}
HGBool needDetach = HGFALSE;
JNIEnv *env = NULL;
//获取当前native线程是否有没有被附加到jvm环境中
int getEnvStat = iter->second.vm->GetEnv((void **)&env, JNI_VERSION_1_6);
if (getEnvStat == JNI_EDETACHED)
{
// 如果没有主动附加到jvm环境中获取到env
if (iter->second.vm->AttachCurrentThread((void **)&env, NULL) != 0)
{
return;
}
needDetach = HGTRUE;
}
//通过全局变量g_obj获取到要回调的类
jclass cls = env->GetObjectClass(iter->second.obj);
if (NULL != cls)
{
jmethodID jmethodId = env->GetMethodID(cls, "onDeviceScanEvent", "(JIZLjava/lang/String;)V");
if (NULL != jmethodId)
{
env->CallVoidMethod(iter->second.obj, jmethodId, (jlong)device, (jint)event, (jboolean)err, env->NewStringUTF(info));
}
}
if (needDetach)
{
iter->second.vm->DetachCurrentThread();
}
if (HGLIB_DEVSCAN_EVENT_END == event)
{
printf("HGLIB_DEVSCAN_EVENT_END == event\n");
env->DeleteGlobalRef(iter->second.obj);
iter->second.obj = NULL;
iter->second.vm = NULL;
g_deviceScanParams.erase(iter);
}
}
static void HGAPI DeviceScanImageFunc(HGLibDevice device, HGLibImage image, HGPointer param)
{
(void)param;
std::map<HGLibDevice, JNICallbackParam>::iterator iter = g_deviceScanParams.find(device);
if (iter == g_deviceScanParams.end() || NULL == iter->second.vm)
{
return;
}
HGBool needDetach = HGFALSE;
JNIEnv *env = NULL;
//获取当前native线程是否有没有被附加到jvm环境中
int getEnvStat = iter->second.vm->GetEnv((void **)&env, JNI_VERSION_1_6);
if (getEnvStat == JNI_EDETACHED)
{
// 如果没有主动附加到jvm环境中获取到env
if (iter->second.vm->AttachCurrentThread((void **)&env, NULL) != 0)
{
return;
}
needDetach = HGTRUE;
}
//通过全局变量g_obj获取到要回调的类
jclass cls = env->GetObjectClass(iter->second.obj);
if (NULL != cls)
{
jmethodID jmethodId = env->GetMethodID(cls, "onDeviceScanImage", "(JJ)V");
if (NULL != jmethodId)
{
env->CallVoidMethod(iter->second.obj, jmethodId, (jlong)device, (jlong)image);
}
}
if (needDetach)
{
iter->second.vm->DetachCurrentThread();
}
}
extern "C" JNIEXPORT jboolean JNICALL Java_com_easing_java_HGScannerLib_StartDeviceScan(
JNIEnv* env, jobject thiz, jlong dev)
{
printf("\nJava_com_easing_java_HGScannerLib_StartDeviceScan\n");
std::map<HGLibDevice, JNICallbackParam>::iterator iter = g_deviceScanParams.find((HGLibDevice)dev);
if (iter != g_deviceScanParams.end())
{
printf("Already Start Device Scan\n");
return (jboolean)HGFALSE;
}
JNICallbackParam deviceScanParam;
env->GetJavaVM(&deviceScanParam.vm);
deviceScanParam.obj = env->NewGlobalRef(thiz);
g_deviceScanParams[(HGLibDevice)dev] = deviceScanParam;
HGBool ret = HGLib_StartDeviceScan((HGLibDevice)dev, DeviceScanEventFunc, NULL, DeviceScanImageFunc, NULL);
printf("ret=%d\n", ret);
if (!ret)
{
std::map<HGLibDevice, JNICallbackParam>::iterator iter = g_deviceScanParams.find((HGLibDevice)dev);
assert(iter != g_deviceScanParams.end());
env->DeleteGlobalRef(iter->second.obj);
iter->second.obj = NULL;
iter->second.vm = NULL;
g_deviceScanParams.erase(iter);
}
printf("\n");
return (jboolean)ret;
}
extern "C" JNIEXPORT jboolean JNICALL Java_com_easing_java_HGScannerLib_StopDeviceScan(
JNIEnv* env, jclass clazz, jlong dev)
{
(void)clazz;
printf("\nJava_com_easing_java_HGScannerLib_StopDeviceScan\n");
std::map<HGLibDevice, JNICallbackParam>::iterator iter = g_deviceScanParams.find((HGLibDevice)dev);
if (iter == g_deviceScanParams.end())
{
printf("Do not Start Device Scan yet\n");
return (jboolean)HGFALSE;
}
HGBool ret = HGLib_StopDeviceScan((HGLibDevice)dev);
printf("ret=%d\n", ret);
if (ret)
{
std::map<HGLibDevice, JNICallbackParam>::iterator iter = g_deviceScanParams.find((HGLibDevice)dev);
if (iter != g_deviceScanParams.end())
{
env->DeleteGlobalRef(iter->second.obj);
iter->second.obj = NULL;
iter->second.vm = NULL;
g_deviceScanParams.erase(iter);
}
}
printf("\n");
return (jboolean)ret;
}
extern "C" JNIEXPORT jobjectArray JNICALL Java_com_easing_java_HGScannerLib_GetDeviceParamGroupList(
JNIEnv* env, jclass clazz, jlong dev)
{
(void)clazz;
printf("\nJava_com_easing_java_HGScannerLib_GetDeviceParamGroupList\n");
jobjectArray devParamGroupList;
jclass clsDeviceParamGroup = env->FindClass("com/easing/java/HGLibDeviceParamGroup");
jmethodID initDeviceParamGroup = env->GetMethodID(clsDeviceParamGroup, "<init>", "()V");
jclass clsDeviceParam = env->FindClass("com/easing/java/HGLibDeviceParam");
jmethodID initDeviceParam = env->GetMethodID(clsDeviceParam, "<init>", "()V");
jclass clsIntValueRange = env->FindClass("com/easing/java/HGLibDeviceIntValueRange");
jmethodID initIntValueRange = env->GetMethodID(clsIntValueRange, "<init>", "()V");
jclass clsDoubleValueRange = env->FindClass("com/easing/java/HGLibDeviceDoubleValueRange");
jmethodID initDoubleValueRange = env->GetMethodID(clsDoubleValueRange, "<init>", "()V");
HGUInt count = 0;
HGLibDeviceParamGroup* devParamGroupList2 = HGLib_GetDeviceParamGroupList((HGLibDevice)dev, &count);
if (NULL != devParamGroupList2)
{
devParamGroupList = env->NewObjectArray(count, clsDeviceParamGroup, env->NewObject(clsDeviceParamGroup, initDeviceParamGroup));
for (HGUInt i = 0; i < count; ++i)
{
jobject devParamGroup = env->NewObject(clsDeviceParamGroup, initDeviceParamGroup);
env->SetIntField(devParamGroup, env->GetFieldID(clsDeviceParamGroup, "group", "I"), (jint)devParamGroupList2[i].group);
jobjectArray devParamList = env->NewObjectArray(devParamGroupList2[i].paramCount, clsDeviceParam, env->NewObject(clsDeviceParam, initDeviceParam));
for (HGUInt j = 0; j < devParamGroupList2[i].paramCount; ++j)
{
jobject devParam = env->NewObject(clsDeviceParam, initDeviceParam);
env->SetIntField(devParam, env->GetFieldID(clsDeviceParam, "option", "I"), (jint)devParamGroupList2[i].param[j].option);
env->SetIntField(devParam, env->GetFieldID(clsDeviceParam, "type", "I"), (jint)devParamGroupList2[i].param[j].type);
if (HGLIB_OPTION_VALUETYPE_INT == devParamGroupList2[i].param[j].type)
{
env->SetIntField(devParam, env->GetFieldID(clsDeviceParam, "intValue", "I"), (jint)devParamGroupList2[i].param[j].intValue);
}
else if (HGLIB_OPTION_VALUETYPE_ENUM == devParamGroupList2[i].param[j].type)
{
env->SetIntField(devParam, env->GetFieldID(clsDeviceParam, "enumValue", "I"), (jint)devParamGroupList2[i].param[j].enumValue);
}
else if (HGLIB_OPTION_VALUETYPE_DOUBLE == devParamGroupList2[i].param[j].type)
{
env->SetDoubleField(devParam, env->GetFieldID(clsDeviceParam, "doubleValue", "D"), (jdouble)devParamGroupList2[i].param[j].doubleValue);
}
else if (HGLIB_OPTION_VALUETYPE_BOOL == devParamGroupList2[i].param[j].type)
{
env->SetBooleanField(devParam, env->GetFieldID(clsDeviceParam, "boolValue", "Z"), (jboolean)devParamGroupList2[i].param[j].boolValue);
}
env->SetIntField(devParam, env->GetFieldID(clsDeviceParam, "rangeType", "I"), (jint)devParamGroupList2[i].param[j].rangeType);
if (HGLIB_OPTION_VALUERANGETYPE_INTLIST == devParamGroupList2[i].param[j].rangeType)
{
jintArray intValueList = env->NewIntArray(devParamGroupList2[i].param[j].intValueList.count);
env->SetIntArrayRegion(intValueList, 0, devParamGroupList2[i].param[j].intValueList.count, (jint*)devParamGroupList2[i].param[j].intValueList.value);
env->SetObjectField(devParam, env->GetFieldID(clsDeviceParam, "intValueList", "[I"), intValueList);
}
else if (HGLIB_OPTION_VALUERANGETYPE_ENUMLIST == devParamGroupList2[i].param[j].rangeType)
{
jintArray enumValueList = env->NewIntArray(devParamGroupList2[i].param[j].enumValueList.count);
env->SetIntArrayRegion(enumValueList, 0, devParamGroupList2[i].param[j].enumValueList.count, (jint*)devParamGroupList2[i].param[j].enumValueList.value);
env->SetObjectField(devParam, env->GetFieldID(clsDeviceParam, "enumValueList", "[I"), enumValueList);
}
else if (HGLIB_OPTION_VALUERANGETYPE_DOUBLELIST == devParamGroupList2[i].param[j].rangeType)
{
jdoubleArray doubleValueList = env->NewDoubleArray(devParamGroupList2[i].param[j].doubleValueList.count);
env->SetDoubleArrayRegion(doubleValueList, 0, devParamGroupList2[i].param[j].doubleValueList.count, (jdouble*)devParamGroupList2[i].param[j].doubleValueList.value);
env->SetObjectField(devParam, env->GetFieldID(clsDeviceParam, "doubleValueList", "[D"), doubleValueList);
}
else if (HGLIB_OPTION_VALUERANGETYPE_INTRANGE == devParamGroupList2[i].param[j].rangeType)
{
jobject intValueRange = env->NewObject(clsIntValueRange, initIntValueRange);
env->SetIntField(intValueRange, env->GetFieldID(clsIntValueRange, "minValue", "I"), (jint)devParamGroupList2[i].param[j].intValueRange.minValue);
env->SetIntField(intValueRange, env->GetFieldID(clsIntValueRange, "maxValue", "I"), (jint)devParamGroupList2[i].param[j].intValueRange.maxValue);
env->SetObjectField(devParam, env->GetFieldID(clsDeviceParam, "intValueRange", "Lcom/easing/java/HGLibDeviceIntValueRange;"), intValueRange);
}
else if (HGLIB_OPTION_VALUERANGETYPE_DOUBLERANGE == devParamGroupList2[i].param[j].rangeType)
{
jobject doubleValueRange = env->NewObject(clsDoubleValueRange, initDoubleValueRange);
env->SetDoubleField(doubleValueRange, env->GetFieldID(clsDoubleValueRange, "minValue", "D"), (jdouble)devParamGroupList2[i].param[j].doubleValueRange.minValue);
env->SetDoubleField(doubleValueRange, env->GetFieldID(clsDoubleValueRange, "maxValue", "D"), (jdouble)devParamGroupList2[i].param[j].doubleValueRange.maxValue);
env->SetObjectField(devParam, env->GetFieldID(clsDeviceParam, "doubleValueRange", "Lcom/easing/java/HGLibDeviceDoubleValueRange;"), doubleValueRange);
}
env->SetObjectArrayElement(devParamList, j, devParam);
}
env->SetObjectField(devParamGroup, env->GetFieldID(clsDeviceParamGroup, "params", "[Lcom/easing/java/HGLibDeviceParam;"), devParamList);
env->SetObjectArrayElement(devParamGroupList, i, devParamGroup);
}
HGLib_ReleaseDeviceParamGroupList(devParamGroupList2, count);
}
else
{
devParamGroupList = env->NewObjectArray(0, clsDeviceParamGroup, env->NewObject(clsDeviceParamGroup, initDeviceParamGroup));
}
printf("\n");
return devParamGroupList;
}
extern "C" JNIEXPORT jobject JNICALL Java_com_easing_java_HGScannerLib_GetDeviceParam(
JNIEnv* env, jclass clazz, jlong dev, jint option)
{
(void)clazz;
printf("\nJava_com_easing_java_HGScannerLib_GetDeviceParam\n");
jclass clsDeviceParam = env->FindClass("com/easing/java/HGLibDeviceParam");
jmethodID initDeviceParam = env->GetMethodID(clsDeviceParam, "<init>", "()V");
jclass clsIntValueRange = env->FindClass("com/easing/java/HGLibDeviceIntValueRange");
jmethodID initIntValueRange = env->GetMethodID(clsIntValueRange, "<init>", "()V");
jclass clsDoubleValueRange = env->FindClass("com/easing/java/HGLibDeviceDoubleValueRange");
jmethodID initDoubleValueRange = env->GetMethodID(clsDoubleValueRange, "<init>", "()V");
jobject devParam = env->NewObject(clsDeviceParam, initDeviceParam);
HGLibDeviceParam* devParam2 = HGLib_GetDeviceParam((HGLibDevice)dev, (HGUInt)option);
if (NULL != devParam2)
{
env->SetIntField(devParam, env->GetFieldID(clsDeviceParam, "option", "I"), (jint)devParam2->option);
env->SetIntField(devParam, env->GetFieldID(clsDeviceParam, "type", "I"), (jint)devParam2->type);
if (HGLIB_OPTION_VALUETYPE_INT == devParam2->type)
{
env->SetIntField(devParam, env->GetFieldID(clsDeviceParam, "intValue", "I"), (jint)devParam2->intValue);
}
else if (HGLIB_OPTION_VALUETYPE_ENUM == devParam2->type)
{
env->SetIntField(devParam, env->GetFieldID(clsDeviceParam, "enumValue", "I"), (jint)devParam2->enumValue);
}
else if (HGLIB_OPTION_VALUETYPE_DOUBLE == devParam2->type)
{
env->SetDoubleField(devParam, env->GetFieldID(clsDeviceParam, "doubleValue", "D"), (jdouble)devParam2->doubleValue);
}
else if (HGLIB_OPTION_VALUETYPE_BOOL == devParam2->type)
{
env->SetBooleanField(devParam, env->GetFieldID(clsDeviceParam, "boolValue", "Z"), (jboolean)devParam2->boolValue);
}
env->SetIntField(devParam, env->GetFieldID(clsDeviceParam, "rangeType", "I"), (jint)devParam2->rangeType);
if (HGLIB_OPTION_VALUERANGETYPE_INTLIST == devParam2->rangeType)
{
jintArray intValueList = env->NewIntArray(devParam2->intValueList.count);
env->SetIntArrayRegion(intValueList, 0, devParam2->intValueList.count, (jint*)devParam2->intValueList.value);
env->SetObjectField(devParam, env->GetFieldID(clsDeviceParam, "intValueList", "[I"), intValueList);
}
else if (HGLIB_OPTION_VALUERANGETYPE_ENUMLIST == devParam2->rangeType)
{
jintArray enumValueList = env->NewIntArray(devParam2->enumValueList.count);
env->SetIntArrayRegion(enumValueList, 0, devParam2->enumValueList.count, (jint*)devParam2->enumValueList.value);
env->SetObjectField(devParam, env->GetFieldID(clsDeviceParam, "enumValueList", "[I"), enumValueList);
}
else if (HGLIB_OPTION_VALUERANGETYPE_DOUBLELIST == devParam2->rangeType)
{
jdoubleArray doubleValueList = env->NewDoubleArray(devParam2->doubleValueList.count);
env->SetDoubleArrayRegion(doubleValueList, 0, devParam2->doubleValueList.count, (jdouble*)devParam2->doubleValueList.value);
env->SetObjectField(devParam, env->GetFieldID(clsDeviceParam, "doubleValueList", "[D"), doubleValueList);
}
else if (HGLIB_OPTION_VALUERANGETYPE_INTRANGE == devParam2->rangeType)
{
jobject intValueRange = env->NewObject(clsIntValueRange, initIntValueRange);
env->SetIntField(intValueRange, env->GetFieldID(clsIntValueRange, "minValue", "I"), (jint)devParam2->intValueRange.minValue);
env->SetIntField(intValueRange, env->GetFieldID(clsIntValueRange, "maxValue", "I"), (jint)devParam2->intValueRange.maxValue);
env->SetObjectField(devParam, env->GetFieldID(clsDeviceParam, "intValueRange", "Lcom/easing/java/HGLibDeviceIntValueRange;"), intValueRange);
}
else if (HGLIB_OPTION_VALUERANGETYPE_DOUBLERANGE == devParam2->rangeType)
{
jobject doubleValueRange = env->NewObject(clsDoubleValueRange, initDoubleValueRange);
env->SetDoubleField(doubleValueRange, env->GetFieldID(clsDoubleValueRange, "minValue", "D"), (jdouble)devParam2->doubleValueRange.minValue);
env->SetDoubleField(doubleValueRange, env->GetFieldID(clsDoubleValueRange, "maxValue", "D"), (jdouble)devParam2->doubleValueRange.maxValue);
env->SetObjectField(devParam, env->GetFieldID(clsDeviceParam, "doubleValueRange", "Lcom/easing/java/HGLibDeviceDoubleValueRange;"), doubleValueRange);
}
HGLib_ReleaseDeviceParam(devParam2);
}
printf("\n");
return devParam;
}
extern "C" JNIEXPORT jboolean JNICALL Java_com_easing_java_HGScannerLib_SetDeviceParam(
JNIEnv* env, jclass clazz, jlong dev, jobject deviceSetParam)
{
(void)clazz;
printf("\nJava_com_easing_java_HGScannerLib_SetDeviceParam\n");
jclass cls = env->GetObjectClass(deviceSetParam);
HGUInt option = (HGUInt)env->GetIntField(deviceSetParam, env->GetFieldID(cls, "option", "I"));
HGUInt type = (HGUInt)env->GetIntField(deviceSetParam, env->GetFieldID(cls, "type", "I"));
HGInt intValue = (HGInt)env->GetIntField(deviceSetParam, env->GetFieldID(cls, "intValue", "I"));
HGUInt enumValue = (HGUInt)env->GetIntField(deviceSetParam, env->GetFieldID(cls, "enumValue", "I"));
HGDouble doubleValue = (HGDouble)env->GetDoubleField(deviceSetParam, env->GetFieldID(cls, "doubleValue", "D"));
HGBool boolValue = (HGBool)env->GetBooleanField(deviceSetParam, env->GetFieldID(cls, "boolValue", "Z"));
printf("option=%u\n", option);
printf("type=%u\n", type);
HGVoid *data = NULL;
if (HGLIB_OPTION_VALUETYPE_INT == type)
{
printf("intValue=%d\n", intValue);
data = &intValue;
}
else if (HGLIB_OPTION_VALUETYPE_ENUM == type)
{
printf("enumValue=%u\n", enumValue);
data = &enumValue;
}
else if (HGLIB_OPTION_VALUETYPE_DOUBLE == type)
{
printf("doubleValue=%f\n", doubleValue);
data = &doubleValue;
}
else if (HGLIB_OPTION_VALUETYPE_BOOL == type)
{
printf("boolValue=%d\n", boolValue);
data = &boolValue;
}
if (NULL == data)
{
printf("Invalid Parameter\n");
return (jboolean)HGFALSE;
}
HGBool ret = HGLib_SetDeviceParam((HGLibDevice)dev, option, data);
printf("ret=%d\n", ret);
printf("\n");
return (jboolean)ret;
}
extern "C" JNIEXPORT jboolean JNICALL Java_com_easing_java_HGScannerLib_ResetDeviceParam(
JNIEnv* env, jclass clazz, jlong dev)
{
(void)env;
(void)clazz;
printf("\nJava_com_easing_java_HGScannerLib_ResetDeviceParam\n");
HGBool ret = HGLib_ResetDeviceParam((HGLibDevice)dev);
printf("ret=%d\n", ret);
printf("\n");
return (jboolean)ret;
}
extern "C" JNIEXPORT jboolean JNICALL Java_com_easing_java_HGScannerLib_DeviceIsPaperOn(
JNIEnv* env, jclass clazz, jlong dev)
{
(void)env;
(void)clazz;
printf("\nJava_com_easing_java_HGScannerLib_DeviceIsPaperOn\n");
HGBool ret = HGLib_DeviceIsPaperOn((HGLibDevice)dev);
printf("ret=%d\n", ret);
printf("\n");
return (jboolean)ret;
}
extern "C" JNIEXPORT jboolean JNICALL Java_com_easing_java_HGScannerLib_DeviceRestart(
JNIEnv* env, jclass clazz, jlong dev)
{
(void)env;
(void)clazz;
printf("\nJava_com_easing_java_HGScannerLib_DeviceRestart\n");
HGBool ret = HGLib_DeviceRestart((HGLibDevice)dev);
printf("ret=%d\n", ret);
printf("\n");
return (jboolean)ret;
}
extern "C" JNIEXPORT jboolean JNICALL Java_com_easing_java_HGScannerLib_DeviceShutDown(
JNIEnv* env, jclass clazz, jlong dev)
{
(void)env;
(void)clazz;
printf("\nJava_com_easing_java_HGScannerLib_DeviceShutDown\n");
HGBool ret = HGLib_DeviceShutDown((HGLibDevice)dev);
printf("ret=%d\n", ret);
printf("\n");
return (jboolean)ret;
}
extern "C" JNIEXPORT jint JNICALL Java_com_easing_java_HGScannerLib_GetDeviceStatus(
JNIEnv* env, jclass clazz, jlong dev)
{
(void)env;
(void)clazz;
printf("\nJava_com_easing_java_HGScannerLib_GetDeviceStatus\n");
HGInt status = HGLib_GetDeviceStatus((HGLibDevice)dev);
printf("status=%d\n", status);
printf("\n");
return (jint)status;
}
extern "C" JNIEXPORT jint JNICALL Java_com_easing_java_HGScannerLib_GetDeviceOperateCode(
JNIEnv* env, jclass clazz, jlong dev)
{
(void)env;
(void)clazz;
printf("\nJava_com_easing_java_HGScannerLib_GetDeviceOperateCode\n");
HGInt code = HGLib_GetDeviceOperateCode((HGLibDevice)dev);
printf("code=%d\n", code);
printf("\n");
return (jint)code;
}