diff options
author | Petre Eftime <[email protected]> | 2016-05-04 18:40:55 +0300 |
---|---|---|
committer | Petre Eftime <[email protected]> | 2016-05-04 18:40:55 +0300 |
commit | f5f8c4a87f3963a65c7041fa139800f45e0dc689 (patch) | |
tree | 06646508c555ed6fe679b7800c753008739fcfb2 | |
parent | f3298303bbf32b7f49b8aaa85aec3076fd13a2d6 (diff) |
Add functions to retrieve version information. Check library versions in getBluetoothManager.
Signed-off-by: Petre Eftime <[email protected]>
-rw-r--r-- | api/tinyb/BluetoothManager.hpp | 3 | ||||
-rw-r--r-- | java/BluetoothManager.java | 23 | ||||
-rw-r--r-- | java/jni/BluetoothManager.cxx | 7 | ||||
-rw-r--r-- | java/manifest.txt.in | 13 | ||||
-rw-r--r-- | src/BluetoothManager.cpp | 9 |
5 files changed, 48 insertions, 7 deletions
diff --git a/api/tinyb/BluetoothManager.hpp b/api/tinyb/BluetoothManager.hpp index 221f4756..75b1ed1f 100644 --- a/api/tinyb/BluetoothManager.hpp +++ b/api/tinyb/BluetoothManager.hpp @@ -56,6 +56,9 @@ public: return std::string(JAVA_PACKAGE "/BluetoothManager"); } + static std::string get_api_version(); + static std::string get_library_version(); + virtual std::string get_java_class() const; virtual std::string get_class_name() const; virtual std::string get_object_path() const; diff --git a/java/BluetoothManager.java b/java/BluetoothManager.java index b198b873..c101a133 100644 --- a/java/BluetoothManager.java +++ b/java/BluetoothManager.java @@ -41,6 +41,8 @@ public class BluetoothManager } } + private native static String getNativeAPIVersion(); + public native BluetoothType getBluetoothType(); private native BluetoothObject find(int type, String name, String identifier, BluetoothObject parent, long milliseconds); @@ -208,12 +210,31 @@ public class BluetoothManager /** Returns an instance of BluetoothManager, to be used instead of constructor. * @return An initialized BluetoothManager instance. */ - public static synchronized BluetoothManager getBluetoothManager() + public static synchronized BluetoothManager getBluetoothManager() throws RuntimeException { if (inst == null) { inst = new BluetoothManager(); inst.init(); + String nativeAPIVersion = getNativeAPIVersion(); + String APIVersion = BluetoothManager.class.getPackage().getSpecificationVersion(); + if (APIVersion.equals(nativeAPIVersion) == false) { + String[] nativeAPIVersionCode = nativeAPIVersion.split("\\D"); + String[] APIVersionCode = APIVersion.split("\\D"); + if (APIVersionCode[0].equals(nativeAPIVersionCode[0]) == false) { + if (Integer.valueOf(APIVersionCode[0]) < Integer.valueOf(nativeAPIVersionCode[0])) + throw new RuntimeException("Java library is out of date. Please update the Java library."); + else throw new RuntimeException("Native library is out of date. Please update the native library."); + } + else if (APIVersionCode[0].equals("0") == true) { + if (Integer.valueOf(APIVersionCode[1]) < Integer.valueOf(nativeAPIVersionCode[1])) + throw new RuntimeException("Java library is out of date. Please update the Java library."); + else throw new RuntimeException("Native library is out of date. Please update the native library."); + } + else if (Integer.valueOf(APIVersionCode[1]) < Integer.valueOf(nativeAPIVersionCode[1])) + System.err.println("Java library is out of date. Please update the Java library."); + else System.err.println("Native library is out of date. Please update the native library."); + } } return inst; } diff --git a/java/jni/BluetoothManager.cxx b/java/jni/BluetoothManager.cxx index 52b05577..568a302c 100644 --- a/java/jni/BluetoothManager.cxx +++ b/java/jni/BluetoothManager.cxx @@ -241,3 +241,10 @@ void Java_tinyb_BluetoothManager_delete(JNIEnv *env, jobject obj) delete manager; } +jstring Java_tinyb_BluetoothManager_getNativeAPIVersion(JNIEnv *env, jclass clazz) +{ + (void) clazz; + + BluetoothManager *manager = BluetoothManager::get_bluetooth_manager(); + return env->NewStringUTF(manager->get_api_version().c_str()); +} diff --git a/java/manifest.txt.in b/java/manifest.txt.in index d6e768f3..0e84c814 100644 --- a/java/manifest.txt.in +++ b/java/manifest.txt.in @@ -1,9 +1,10 @@ Manifest-version: 1.0 Name: tinyb/ -Specification-Title: "TinyB" -Specification-Version: "@VERSION_API@" -Specification-Vendor: "Intel Corp." -Package-Title: "tinyb" -Package-Version: "@VERSION_SHORT@" -Package-Vendor: "Intel Corp." +Specification-Title: TinyB +Specification-Version: @VERSION_API@ +Specification-Vendor: Intel Corp. +Package-Title: tinyb +Package-Version: @VERSION_SHORT@ +Package-Vendor: Intel Corp. + diff --git a/src/BluetoothManager.cpp b/src/BluetoothManager.cpp index 4b318e3e..8de8003c 100644 --- a/src/BluetoothManager.cpp +++ b/src/BluetoothManager.cpp @@ -30,6 +30,7 @@ #include "BluetoothGattCharacteristic.hpp" #include "BluetoothGattDescriptor.hpp" #include "BluetoothEvent.hpp" +#include "version.h" #include <pthread.h> #include <cassert> @@ -121,6 +122,14 @@ BluetoothType BluetoothManager::get_bluetooth_type() const return BluetoothType::NONE; } +std::string BluetoothManager::get_api_version() { + return std::string(gVERSION_API); +} + +std::string BluetoothManager::get_library_version() { + return std::string(gVERSION_SHORT); +} + std::unique_ptr<BluetoothObject> BluetoothManager::get_object( BluetoothType type, std::string *name, std::string *identifier, BluetoothObject *parent) |