aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorPetre Eftime <[email protected]>2016-01-27 15:07:30 +0200
committerPetre Eftime <[email protected]>2016-01-27 15:08:19 +0200
commitffda062a689e303702005f24a87a164dee8cba8b (patch)
tree9a9f6d8ac7a00960f016d560c06b1f8e320209ee
parent706445a43828269019851e34861f949a1232ebe0 (diff)
Fix Java package runtime mismatchv0.3.0
Signed-off-by: Petre Eftime <[email protected]>
-rw-r--r--api/tinyb/BluetoothAdapter.hpp4
-rw-r--r--api/tinyb/BluetoothDevice.hpp4
-rw-r--r--api/tinyb/BluetoothGattCharacteristic.hpp5
-rw-r--r--api/tinyb/BluetoothGattDescriptor.hpp5
-rw-r--r--api/tinyb/BluetoothGattService.hpp5
-rw-r--r--api/tinyb/BluetoothManager.hpp5
-rw-r--r--api/tinyb/BluetoothObject.hpp6
-rw-r--r--java/jni/BluetoothAdapter.cxx3
-rw-r--r--java/jni/BluetoothDevice.cxx5
-rw-r--r--java/jni/BluetoothGattCharacteristic.cxx5
-rw-r--r--java/jni/BluetoothGattDescriptor.cxx4
-rw-r--r--java/jni/BluetoothGattService.cxx5
-rw-r--r--java/jni/BluetoothManager.cxx5
-rw-r--r--java/jni/BluetoothObject.cxx2
-rw-r--r--java/jni/helper.cxx10
-rw-r--r--java/jni/helper.hpp (renamed from java/jni/helper.h)14
16 files changed, 60 insertions, 27 deletions
diff --git a/api/tinyb/BluetoothAdapter.hpp b/api/tinyb/BluetoothAdapter.hpp
index 856eda61..b200f786 100644
--- a/api/tinyb/BluetoothAdapter.hpp
+++ b/api/tinyb/BluetoothAdapter.hpp
@@ -64,6 +64,10 @@ protected:
BluetoothObject *parent = nullptr);
public:
+ static std::string java_class() {
+ return std::string(JAVA_PACKAGE "/BluetoothAdapter");
+ }
+
virtual std::string get_java_class() const;
virtual std::string get_class_name() const;
virtual std::string get_object_path() const;
diff --git a/api/tinyb/BluetoothDevice.hpp b/api/tinyb/BluetoothDevice.hpp
index 5a44795e..c8554081 100644
--- a/api/tinyb/BluetoothDevice.hpp
+++ b/api/tinyb/BluetoothDevice.hpp
@@ -58,6 +58,10 @@ protected:
BluetoothObject *parent = nullptr);
public:
+ static std::string java_class() {
+ return std::string(JAVA_PACKAGE "/BluetoothDevice");
+ }
+
virtual std::string get_java_class() const;
virtual std::string get_class_name() const;
virtual std::string get_object_path() const;
diff --git a/api/tinyb/BluetoothGattCharacteristic.hpp b/api/tinyb/BluetoothGattCharacteristic.hpp
index 4aa78ecb..7164d519 100644
--- a/api/tinyb/BluetoothGattCharacteristic.hpp
+++ b/api/tinyb/BluetoothGattCharacteristic.hpp
@@ -57,6 +57,11 @@ protected:
std::string *identifier = nullptr,
BluetoothObject *parent = nullptr);
public:
+
+ static std::string java_class() {
+ return std::string(JAVA_PACKAGE "/BluetoothGattCharacteristic");
+ }
+
virtual std::string get_java_class() const;
virtual std::string get_class_name() const ;
virtual std::string get_object_path() const;
diff --git a/api/tinyb/BluetoothGattDescriptor.hpp b/api/tinyb/BluetoothGattDescriptor.hpp
index dc281295..28a030fd 100644
--- a/api/tinyb/BluetoothGattDescriptor.hpp
+++ b/api/tinyb/BluetoothGattDescriptor.hpp
@@ -57,6 +57,11 @@ protected:
BluetoothObject *parent = nullptr);
public:
+
+ static std::string java_class() {
+ return std::string(JAVA_PACKAGE "/BluetoothGattDescriptor");
+ }
+
virtual std::string get_java_class() const;
virtual std::string get_class_name() const;
virtual std::string get_object_path() const;
diff --git a/api/tinyb/BluetoothGattService.hpp b/api/tinyb/BluetoothGattService.hpp
index e947e1ae..88f2716d 100644
--- a/api/tinyb/BluetoothGattService.hpp
+++ b/api/tinyb/BluetoothGattService.hpp
@@ -58,6 +58,11 @@ protected:
BluetoothObject *parent = nullptr);
public:
+
+ static std::string java_class() {
+ return std::string(JAVA_PACKAGE "/BluetoothGattService");
+ }
+
virtual std::string get_java_class() const;
virtual std::string get_class_name() const;
virtual std::string get_object_path() const;
diff --git a/api/tinyb/BluetoothManager.hpp b/api/tinyb/BluetoothManager.hpp
index 199cbda4..b01da946 100644
--- a/api/tinyb/BluetoothManager.hpp
+++ b/api/tinyb/BluetoothManager.hpp
@@ -46,6 +46,11 @@ private:
BluetoothManager(const BluetoothManager &object);
public:
+
+ static std::string java_class() {
+ return std::string(JAVA_PACKAGE "/BluetoothManager");
+ }
+
virtual std::string get_java_class() const;
virtual std::string get_class_name() const;
virtual std::string get_object_path() const;
diff --git a/api/tinyb/BluetoothObject.hpp b/api/tinyb/BluetoothObject.hpp
index 0be38cbb..43866380 100644
--- a/api/tinyb/BluetoothObject.hpp
+++ b/api/tinyb/BluetoothObject.hpp
@@ -25,7 +25,7 @@
#include <memory>
#pragma once
-#define JAVA_PACKAGE "io/mraa/tinyb"
+#define JAVA_PACKAGE "tinyb"
namespace tinyb {
enum class BluetoothType {
@@ -52,6 +52,10 @@ class tinyb::BluetoothObject
{
public:
+ static std::string java_class() {
+ return std::string(JAVA_PACKAGE "/BluetoothObject");
+ }
+
/** Returns the complete Java class of this object
* @return A std::string containing the java class of this object
*/
diff --git a/java/jni/BluetoothAdapter.cxx b/java/jni/BluetoothAdapter.cxx
index 1ac72773..8538ba8c 100644
--- a/java/jni/BluetoothAdapter.cxx
+++ b/java/jni/BluetoothAdapter.cxx
@@ -28,7 +28,7 @@
#include "tinyb_BluetoothAdapter.h"
-#include "helper.h"
+#include "helper.hpp"
using namespace tinyb;
@@ -63,7 +63,6 @@ jobject Java_tinyb_BluetoothAdapter_getDevices(JNIEnv *env, jobject obj)
BluetoothAdapter *obj_adapter = getInstance<BluetoothAdapter>(env, obj);
std::vector<std::unique_ptr<BluetoothDevice>> array = obj_adapter->get_devices();
jobject result = convert_vector_to_jobject<BluetoothDevice>(env, array,
- "BluetoothDevice",
"(J)V");
return result;
diff --git a/java/jni/BluetoothDevice.cxx b/java/jni/BluetoothDevice.cxx
index 9971c6ed..da15cd00 100644
--- a/java/jni/BluetoothDevice.cxx
+++ b/java/jni/BluetoothDevice.cxx
@@ -29,7 +29,7 @@
#include "tinyb_BluetoothDevice.h"
-#include "helper.h"
+#include "helper.hpp"
using namespace tinyb;
@@ -104,7 +104,6 @@ jobject Java_tinyb_BluetoothDevice_getServices(JNIEnv *env, jobject obj)
BluetoothDevice *obj_device = getInstance<BluetoothDevice>(env, obj);
std::vector<std::unique_ptr<BluetoothGattService>> array = obj_device->get_services();
jobject result = convert_vector_to_jobject<BluetoothGattService>(env, array,
- "BluetoothGattService",
"(J)V");
return result;
@@ -259,7 +258,7 @@ jobject Java_tinyb_BluetoothDevice_getAdapter(JNIEnv *env, jobject obj)
BluetoothDevice *obj_device = getInstance<BluetoothDevice>(env, obj);
BluetoothAdapter *obj_adapter = obj_device->get_adapter().clone();
- jclass b_adapter_class = search_class(env, "BluetoothAdapter");
+ jclass b_adapter_class = search_class(env, *obj_adapter);
jmethodID b_adapter_ctor = search_method(env, b_adapter_class, "<init>",
"(J)V", false);
jobject result = env->NewObject(b_adapter_class, b_adapter_ctor, (jlong)obj_adapter);
diff --git a/java/jni/BluetoothGattCharacteristic.cxx b/java/jni/BluetoothGattCharacteristic.cxx
index b0c4a0b0..0c7dfb74 100644
--- a/java/jni/BluetoothGattCharacteristic.cxx
+++ b/java/jni/BluetoothGattCharacteristic.cxx
@@ -29,7 +29,7 @@
#include "tinyb_BluetoothGattCharacteristic.h"
-#include "helper.h"
+#include "helper.hpp"
using namespace tinyb;
@@ -105,7 +105,7 @@ jobject Java_tinyb_BluetoothGattCharacteristic_getService(JNIEnv *env, jobject o
getInstance<BluetoothGattCharacteristic>(env, obj);
BluetoothGattService *obj_gatt_serv = obj_gatt_char->get_service().clone();
- jclass b_gatt_serv_class = search_class(env, "BluetoothGattService");
+ jclass b_gatt_serv_class = search_class(env, *obj_gatt_serv);
jmethodID b_gatt_serv_ctor = search_method(env, b_gatt_serv_class, "<init>",
"(J)V", false);
jobject result = env->NewObject(b_gatt_serv_class, b_gatt_serv_ctor, (jlong)obj_gatt_serv);
@@ -164,7 +164,6 @@ jobject Java_tinyb_BluetoothGattCharacteristic_getDescriptors(JNIEnv *env, jobje
std::vector<std::unique_ptr<BluetoothGattDescriptor>> array = obj_gatt_char->get_descriptors();
jobject result = convert_vector_to_jobject<BluetoothGattDescriptor>(env, array,
- "BluetoothGattDescriptor",
"(J)V");
return result;
}
diff --git a/java/jni/BluetoothGattDescriptor.cxx b/java/jni/BluetoothGattDescriptor.cxx
index 609e2715..05c45c3c 100644
--- a/java/jni/BluetoothGattDescriptor.cxx
+++ b/java/jni/BluetoothGattDescriptor.cxx
@@ -28,7 +28,7 @@
#include "tinyb_BluetoothGattDescriptor.h"
-#include "helper.h"
+#include "helper.hpp"
using namespace tinyb;
@@ -86,7 +86,7 @@ jobject Java_tinyb_BluetoothGattDescriptor_getCharacteristic(JNIEnv *env, jobjec
BluetoothGattDescriptor *obj_gatt_desc = getInstance<BluetoothGattDescriptor>(env, obj);
BluetoothGattCharacteristic *obj_gatt_char = obj_gatt_desc->get_characteristic().clone();
- jclass b_gatt_char_class = search_class(env, "BluetoothGattCharacteristic");
+ jclass b_gatt_char_class = search_class(env, *obj_gatt_char);
jmethodID b_gatt_char_ctor = search_method(env, b_gatt_char_class, "<init>",
"(J)V", false);
jobject result = env->NewObject(b_gatt_char_class, b_gatt_char_ctor, (jlong)obj_gatt_char);
diff --git a/java/jni/BluetoothGattService.cxx b/java/jni/BluetoothGattService.cxx
index d60c6afe..c42e5c18 100644
--- a/java/jni/BluetoothGattService.cxx
+++ b/java/jni/BluetoothGattService.cxx
@@ -29,7 +29,7 @@
#include "tinyb_BluetoothGattService.h"
-#include "helper.h"
+#include "helper.hpp"
using namespace tinyb;
@@ -58,7 +58,7 @@ jobject Java_tinyb_BluetoothGattService_getDevice(JNIEnv *env, jobject obj)
BluetoothGattService *obj_gatt_serv = getInstance<BluetoothGattService>(env, obj);
BluetoothDevice *obj_device = obj_gatt_serv->get_device().clone();
- jclass b_device_class = search_class(env, "BluetoothDevice");
+ jclass b_device_class = search_class(env, *obj_device);
jmethodID b_device_ctor = search_method(env, b_device_class, "<init>",
"(J)V", false);
jobject result = env->NewObject(b_device_class, b_device_ctor, (jlong)obj_device);
@@ -83,7 +83,6 @@ jobject Java_tinyb_BluetoothGattService_getCharacteristics(JNIEnv *env, jobject
std::vector<std::unique_ptr<BluetoothGattCharacteristic>> array =
obj_gatt_serv->get_characteristics();
jobject result = convert_vector_to_jobject<BluetoothGattCharacteristic>(env, array,
- "BluetoothGattCharacteristic",
"(J)V");
return result;
}
diff --git a/java/jni/BluetoothManager.cxx b/java/jni/BluetoothManager.cxx
index 476f9baa..6788f2c1 100644
--- a/java/jni/BluetoothManager.cxx
+++ b/java/jni/BluetoothManager.cxx
@@ -29,7 +29,7 @@
#include "tinyb_BluetoothManager.h"
-#include "helper.h"
+#include "helper.hpp"
using namespace tinyb;
@@ -72,7 +72,6 @@ jobject Java_tinyb_BluetoothManager_getAdapters(JNIEnv *env, jobject obj)
std::vector<std::unique_ptr<BluetoothAdapter>> array = manager->get_adapters();
jobject result = convert_vector_to_jobject<BluetoothAdapter>(env, array,
- "BluetoothAdapter",
"(J)V");
return result;
}
@@ -83,7 +82,6 @@ jobject Java_tinyb_BluetoothManager_getDevices(JNIEnv *env, jobject obj)
std::vector<std::unique_ptr<BluetoothDevice>> array = manager->get_devices();
jobject result = convert_vector_to_jobject<BluetoothDevice>(env, array,
- "BluetoothDevice",
"(J)V");
return result;
@@ -95,7 +93,6 @@ jobject Java_tinyb_BluetoothManager_getServices(JNIEnv *env, jobject obj)
std::vector<std::unique_ptr<BluetoothGattService>> array = manager->get_services();
jobject result = convert_vector_to_jobject<BluetoothGattService>(env, array,
- "BluetoothGattService",
"(J)V");
return result;
}
diff --git a/java/jni/BluetoothObject.cxx b/java/jni/BluetoothObject.cxx
index ce62db43..cdd51614 100644
--- a/java/jni/BluetoothObject.cxx
+++ b/java/jni/BluetoothObject.cxx
@@ -26,7 +26,7 @@
#include "tinyb_BluetoothObject.h"
-#include "helper.h"
+#include "helper.hpp"
using namespace tinyb;
diff --git a/java/jni/helper.cxx b/java/jni/helper.cxx
index d5cea134..3344ab85 100644
--- a/java/jni/helper.cxx
+++ b/java/jni/helper.cxx
@@ -27,7 +27,7 @@
#include <stdexcept>
#include <vector>
-#include "helper.h"
+#include "helper.hpp"
jfieldID getInstanceField(JNIEnv *env, jobject obj)
{
@@ -36,12 +36,18 @@ jfieldID getInstanceField(JNIEnv *env, jobject obj)
return env->GetFieldID(clazz, "nativeInstance", "J");
}
+jclass search_class(JNIEnv *env, tinyb::BluetoothObject &object)
+{
+ return search_class(env, object.get_java_class().c_str());
+}
+
jclass search_class(JNIEnv *env, const char *clazz_name)
{
jclass clazz = env->FindClass(clazz_name);
if (clazz == NULL)
{
- throw std::runtime_error("no class found\n");
+ std::string error = "no class found: "; error += clazz_name;
+ throw std::runtime_error(error);
}
return clazz;
}
diff --git a/java/jni/helper.h b/java/jni/helper.hpp
index accf2609..a6b698f1 100644
--- a/java/jni/helper.h
+++ b/java/jni/helper.hpp
@@ -22,14 +22,15 @@
* WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
*/
-#ifndef _HELPER_H_
-#define _HELPER_H_
+#pragma once
#include <vector>
+#include "tinyb/BluetoothObject.hpp"
jfieldID getInstanceField(JNIEnv *env, jobject obj);
jclass search_class(JNIEnv *env, const char *clazz_name);
+jclass search_class(JNIEnv *env, tinyb::BluetoothObject &object);
jmethodID search_method(JNIEnv *env, jclass clazz, const char *method_name,
const char *prototype, bool is_static);
jfieldID search_field(JNIEnv *env, jclass clazz, const char *field_name,
@@ -72,14 +73,17 @@ jobject generic_clone(JNIEnv *env, jobject obj, const char *class_name)
template <typename T>
jobject convert_vector_to_jobject(JNIEnv *env, std::vector<std::unique_ptr<T>>& array,
- const char *class_name, const char *ctor_prototype)
+ const char *ctor_prototype)
{
unsigned int array_size = array.size();
jmethodID arraylist_add;
jobject result = get_new_arraylist(env, array_size, &arraylist_add);
- jclass clazz = search_class(env, class_name);
+ if (array_size == 0)
+ return result;
+
+ jclass clazz = search_class(env, T::java_class().c_str());
jmethodID clazz_ctor = search_method(env, clazz, "<init>", ctor_prototype, false);
for (unsigned int i = 0; i < array_size; ++i)
@@ -94,5 +98,3 @@ jobject convert_vector_to_jobject(JNIEnv *env, std::vector<std::unique_ptr<T>>&
}
return result;
}
-
-#endif