aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorVlad Kolotov <[email protected]>2017-10-14 18:57:00 +1300
committerpetreeftime <[email protected]>2017-10-14 17:18:12 +0300
commitac6d3082d06183c860eea97f451d5a92022348e0 (patch)
treeac1355893f0dfe68b96429a0169bb8f421848532
parentbbe7933403df85309ccac68d4293678f5a3c1add (diff)
Implementing discovery filter by UUIDs (java) and fixing a bug with discovery filter by UUIDs (c++)v0.5.1tinyb-master
Signed-off-by: Vlad Kolotov <[email protected]>
-rw-r--r--java/BluetoothAdapter.java10
-rw-r--r--java/jni/BluetoothAdapter.cxx15
-rw-r--r--src/BluetoothAdapter.cpp6
3 files changed, 24 insertions, 7 deletions
diff --git a/java/BluetoothAdapter.java b/java/BluetoothAdapter.java
index 94fd1f76..7bd35c83 100644
--- a/java/BluetoothAdapter.java
+++ b/java/BluetoothAdapter.java
@@ -258,8 +258,12 @@ public class BluetoothAdapter extends BluetoothObject
* @param rssi a rssi value
* @param pathloss a pathloss value
*/
- public void setDiscoveryFilter(List<Integer> uuids, int rssi, int pathloss, TransportType transportType) {
- setDiscoveryFilter(uuids, rssi, pathloss, transportType.ordinal());
+ public void setDiscoveryFilter(List<UUID> uuids, int rssi, int pathloss, TransportType transportType) {
+ List<String> uuidsFmt = new ArrayList<>(uuids.size());
+ for (UUID uuid : uuids) {
+ uuidsFmt.add(uuid.toString());
+ }
+ setDiscoveryFilter(uuidsFmt, rssi, pathloss, transportType.ordinal());
}
/** This method sets RSSI device discovery filter for the caller. When this method is called
@@ -280,7 +284,7 @@ public class BluetoothAdapter extends BluetoothObject
private native void delete();
- private native void setDiscoveryFilter(List<Integer> uuids, int rssi, int pathloss, int transportType);
+ private native void setDiscoveryFilter(List<String> uuids, int rssi, int pathloss, int transportType);
private BluetoothAdapter(long instance)
{
diff --git a/java/jni/BluetoothAdapter.cxx b/java/jni/BluetoothAdapter.cxx
index c17d1fb5..fd4e7d4e 100644
--- a/java/jni/BluetoothAdapter.cxx
+++ b/java/jni/BluetoothAdapter.cxx
@@ -792,8 +792,21 @@ void Java_tinyb_BluetoothAdapter_setDiscoveryFilter(JNIEnv *env, jobject obj, jo
try {
BluetoothAdapter *obj_adapter = getInstance<BluetoothAdapter>(env, obj);
+ jclass cList = env->FindClass("java/util/List");
+
+ jmethodID mSize = env->GetMethodID(cList, "size", "()I");
+ jmethodID mGet = env->GetMethodID(cList, "get", "(I)Ljava/lang/Object;");
+
+ jint size = env->CallIntMethod(uuids, mSize);
std::vector<BluetoothUUID> native_uuids;
- native_uuids.reserve(0);
+
+ for (jint i = 0; i < size; i++) {
+ jstring strObj = (jstring) env->CallObjectMethod(uuids, mGet, i);
+ const char * chr = env->GetStringUTFChars(strObj, NULL);
+ BluetoothUUID uuid(chr);
+ native_uuids.push_back(uuid);
+ env->ReleaseStringUTFChars(strObj, chr);
+ }
TransportType t_type = from_int_to_transport_type((int) transportType);
diff --git a/src/BluetoothAdapter.cpp b/src/BluetoothAdapter.cpp
index c3844320..5e89e782 100644
--- a/src/BluetoothAdapter.cpp
+++ b/src/BluetoothAdapter.cpp
@@ -221,12 +221,12 @@ bool BluetoothAdapter::set_discovery_filter (std::vector<BluetoothUUID> uuids,
if (uuids.size() > 0)
{
- GVariantBuilder *builder = g_variant_builder_new(G_VARIANT_TYPE("a(s)"));
+ GVariantBuilder *builder = g_variant_builder_new(G_VARIANT_TYPE("as"));
for (std::vector<BluetoothUUID>::iterator i = uuids.begin(); i != uuids.end(); ++i)
- g_variant_builder_add(builder, "(s)", (*i).get_string().c_str());
+ g_variant_builder_add(builder, "s", (*i).get_string().c_str());
- GVariant *uuids_variant = g_variant_new("a(s)", builder);
+ GVariant *uuids_variant = g_variant_new("as", builder);
g_variant_builder_unref(builder);
g_variant_dict_insert_value(&dict, "UUIDs", uuids_variant);
}