Added "getNativeLibVersion" method and and version mismatch check on jSSC lib loading

This commit is contained in:
Alexey Sokolov 2014-01-24 10:51:55 +03:00
parent e56d39fea0
commit 5d1515a117
3 changed files with 36 additions and 3 deletions

View File

@ -1,5 +1,5 @@
/* jSSC (Java Simple Serial Connector) - serial port communication library.
* © Alexey Sokolov (scream3r), 2010-2013.
* © Alexey Sokolov (scream3r), 2010-2014.
*
* This file is part of jSSC.
*
@ -31,6 +31,10 @@
#ifdef __cplusplus
extern "C" {
#endif
#undef jSSC_NATIVE_LIB_VERSION
#define jSSC_NATIVE_LIB_VERSION "2.8"
#undef jssc_SerialNativeInterface_OS_LINUX
#define jssc_SerialNativeInterface_OS_LINUX 0L
#undef jssc_SerialNativeInterface_OS_WINDOWS
@ -47,6 +51,14 @@ extern "C" {
#define jssc_SerialNativeInterface_ERR_PERMISSION_DENIED -3LL
#undef jssc_SerialNativeInterface_ERR_INCORRECT_SERIAL_PORT
#define jssc_SerialNativeInterface_ERR_INCORRECT_SERIAL_PORT -4LL
/*
* Class: jssc_SerialNativeInterface
* Method: getNativeLibraryVersion
* Signature: ()Ljava/lang/String;
*/
JNIEXPORT jstring JNICALL Java_jssc_SerialNativeInterface_getNativeLibraryVersion
(JNIEnv *, jobject);
/*
* Class: jssc_SerialNativeInterface
* Method: openPort

View File

@ -29,6 +29,13 @@
//#include <iostream>
/*
* Get native library version
*/
JNIEXPORT jstring JNICALL Java_jssc_SerialNativeInterface_getNativeLibraryVersion(JNIEnv *env, jobject object) {
return env->NewStringUTF(jSSC_NATIVE_LIB_VERSION);
}
/*
* Port opening.
*

View File

@ -36,7 +36,7 @@ import java.io.InputStreamReader;
*/
public class SerialNativeInterface {
private static final String libVersion = "2.7"; //jSSC-2.7.0 Release from 20.01.2014
private static final String libVersion = "2.8"; //jSSC-2.8.0 Release from 24.01.2014
private static final String libMinorSuffix = "0"; //since 0.9.0
public static final int OS_LINUX = 0;
@ -170,6 +170,11 @@ public class SerialNativeInterface {
if (loadLib) {
System.load(libFolderPath + fileSeparator + libName);
String versionBase = getLibraryBaseVersion();
String versionNative = getNativeLibraryVersion();
if (!versionBase.equals(versionNative)) {
System.err.println("Warning! jSSC Java and Native versions mismatch (Java: " + versionBase + ", Native: " + versionNative + ")");
}
}
}
@ -289,6 +294,15 @@ public class SerialNativeInterface {
return libMinorSuffix;
}
/**
* Get jSSC native library version
*
* @return Version base number. The native lib version for jSSC-2.8.0 should be 2.8 for example
*
* @since 2.8.0
*/
public static native String getNativeLibraryVersion();
/**
* Open port
*