diff --git a/dbus/CMakeLists.txt b/dbus/CMakeLists.txt
index fe6ed5f..0abb5f4 100644
--- a/dbus/CMakeLists.txt
+++ b/dbus/CMakeLists.txt
@@ -34,33 +34,39 @@ pkg_search_module(BLUEZ REQUIRED bluez)
message("Build DBus gattlib for Bluez v${BLUEZ_VERSION_MAJOR}.${BLUEZ_VERSION_MINOR}")
+if (BLUEZ_VERSION_MINOR LESS 40)
+ set(DBUS_BLUEZ_API dbus-bluez-pre-v5.40)
+else()
+ set(DBUS_BLUEZ_API dbus-bluez-v5.40)
+endif()
+
add_custom_command(OUTPUT ${CMAKE_CURRENT_BINARY_DIR}/org-bluez-adaptater1.c
- COMMAND gdbus-codegen --interface-prefix org.bluez.Adapter1. --generate-c-code ${CMAKE_CURRENT_BINARY_DIR}/org-bluez-adaptater1 ${CMAKE_CURRENT_SOURCE_DIR}/interfaces/org.bluez.Adapter1.xml
- DEPENDS ${CMAKE_CURRENT_SOURCE_DIR}/interfaces/org.bluez.Adapter1.xml
+ COMMAND gdbus-codegen --interface-prefix org.bluez.Adapter1. --generate-c-code ${CMAKE_CURRENT_BINARY_DIR}/org-bluez-adaptater1 ${CMAKE_CURRENT_SOURCE_DIR}/${DBUS_BLUEZ_API}/org.bluez.Adapter1.xml
+ DEPENDS ${CMAKE_CURRENT_SOURCE_DIR}/${DBUS_BLUEZ_API}/org.bluez.Adapter1.xml
COMMENT "Generate D-Bus 'org.bluez.Adapter1.xml'"
)
add_custom_command(OUTPUT ${CMAKE_CURRENT_BINARY_DIR}/org-bluez-device1.c
- COMMAND gdbus-codegen --interface-prefix org.bluez.Device1. --generate-c-code ${CMAKE_CURRENT_BINARY_DIR}/org-bluez-device1 ${CMAKE_CURRENT_SOURCE_DIR}/interfaces/org.bluez.Device1.xml
- DEPENDS ${CMAKE_CURRENT_SOURCE_DIR}/interfaces/org.bluez.Device1.xml
+ COMMAND gdbus-codegen --interface-prefix org.bluez.Device1. --generate-c-code ${CMAKE_CURRENT_BINARY_DIR}/org-bluez-device1 ${CMAKE_CURRENT_SOURCE_DIR}/${DBUS_BLUEZ_API}/org.bluez.Device1.xml
+ DEPENDS ${CMAKE_CURRENT_SOURCE_DIR}/${DBUS_BLUEZ_API}/org.bluez.Device1.xml
COMMENT "Generate D-Bus 'org.bluez.Device1.xml'"
)
add_custom_command(OUTPUT ${CMAKE_CURRENT_BINARY_DIR}/org-bluez-gattservice1.c
- COMMAND gdbus-codegen --interface-prefix org.bluez.GattService1. --generate-c-code ${CMAKE_CURRENT_BINARY_DIR}/org-bluez-gattservice1 ${CMAKE_CURRENT_SOURCE_DIR}/interfaces/org.bluez.GattService1.xml
- DEPENDS ${CMAKE_CURRENT_SOURCE_DIR}/interfaces/org.bluez.GattService1.xml
+ COMMAND gdbus-codegen --interface-prefix org.bluez.GattService1. --generate-c-code ${CMAKE_CURRENT_BINARY_DIR}/org-bluez-gattservice1 ${CMAKE_CURRENT_SOURCE_DIR}/${DBUS_BLUEZ_API}/org.bluez.GattService1.xml
+ DEPENDS ${CMAKE_CURRENT_SOURCE_DIR}/${DBUS_BLUEZ_API}/org.bluez.GattService1.xml
COMMENT "Generate D-Bus 'org.bluez.GattService1.xml'"
)
add_custom_command(OUTPUT ${CMAKE_CURRENT_BINARY_DIR}/org-bluez-gattcharacteristic1.c
- COMMAND gdbus-codegen --interface-prefix org.bluez.Characteristic1. --generate-c-code ${CMAKE_CURRENT_BINARY_DIR}/org-bluez-gattcharacteristic1 ${CMAKE_CURRENT_SOURCE_DIR}/interfaces/org.bluez.GattCharacteristic1.xml
- DEPENDS ${CMAKE_CURRENT_SOURCE_DIR}/interfaces/org.bluez.GattCharacteristic1.xml
+ COMMAND gdbus-codegen --interface-prefix org.bluez.Characteristic1. --generate-c-code ${CMAKE_CURRENT_BINARY_DIR}/org-bluez-gattcharacteristic1 ${CMAKE_CURRENT_SOURCE_DIR}/${DBUS_BLUEZ_API}/org.bluez.GattCharacteristic1.xml
+ DEPENDS ${CMAKE_CURRENT_SOURCE_DIR}/${DBUS_BLUEZ_API}/org.bluez.GattCharacteristic1.xml
COMMENT "Generate D-Bus 'org.bluez.GattCharacteristic1.xml'"
)
add_custom_command(OUTPUT ${CMAKE_CURRENT_BINARY_DIR}/org-bluez-gattdescriptor1.c
- COMMAND gdbus-codegen --interface-prefix org.bluez.Descriptor1. --generate-c-code ${CMAKE_CURRENT_BINARY_DIR}/org-bluez-gattdescriptor1 ${CMAKE_CURRENT_SOURCE_DIR}/interfaces/org.bluez.GattDescriptor1.xml
- DEPENDS ${CMAKE_CURRENT_SOURCE_DIR}/interfaces/org.bluez.GattDescriptor1.xml
+ COMMAND gdbus-codegen --interface-prefix org.bluez.Descriptor1. --generate-c-code ${CMAKE_CURRENT_BINARY_DIR}/org-bluez-gattdescriptor1 ${CMAKE_CURRENT_SOURCE_DIR}/${DBUS_BLUEZ_API}/org.bluez.GattDescriptor1.xml
+ DEPENDS ${CMAKE_CURRENT_SOURCE_DIR}/${DBUS_BLUEZ_API}/org.bluez.GattDescriptor1.xml
COMMENT "Generate D-Bus 'org.bluez.GattDescriptor1.xml'"
)
diff --git a/dbus/interfaces/org.bluez.Adapter1.xml b/dbus/dbus-bluez-pre-v5.40/org.bluez.Adapter1.xml
similarity index 100%
rename from dbus/interfaces/org.bluez.Adapter1.xml
rename to dbus/dbus-bluez-pre-v5.40/org.bluez.Adapter1.xml
diff --git a/dbus/interfaces/org.bluez.Device1.xml b/dbus/dbus-bluez-pre-v5.40/org.bluez.Device1.xml
similarity index 100%
rename from dbus/interfaces/org.bluez.Device1.xml
rename to dbus/dbus-bluez-pre-v5.40/org.bluez.Device1.xml
diff --git a/dbus/interfaces/org.bluez.GattCharacteristic1.xml b/dbus/dbus-bluez-pre-v5.40/org.bluez.GattCharacteristic1.xml
similarity index 100%
rename from dbus/interfaces/org.bluez.GattCharacteristic1.xml
rename to dbus/dbus-bluez-pre-v5.40/org.bluez.GattCharacteristic1.xml
diff --git a/dbus/interfaces/org.bluez.GattDescriptor1.xml b/dbus/dbus-bluez-pre-v5.40/org.bluez.GattDescriptor1.xml
similarity index 100%
rename from dbus/interfaces/org.bluez.GattDescriptor1.xml
rename to dbus/dbus-bluez-pre-v5.40/org.bluez.GattDescriptor1.xml
diff --git a/dbus/interfaces/org.bluez.GattService1.xml b/dbus/dbus-bluez-pre-v5.40/org.bluez.GattService1.xml
similarity index 100%
rename from dbus/interfaces/org.bluez.GattService1.xml
rename to dbus/dbus-bluez-pre-v5.40/org.bluez.GattService1.xml
diff --git a/dbus/dbus-bluez-v5.40/org.bluez.Adapter1.xml b/dbus/dbus-bluez-v5.40/org.bluez.Adapter1.xml
new file mode 100644
index 0000000..e13abfd
--- /dev/null
+++ b/dbus/dbus-bluez-v5.40/org.bluez.Adapter1.xml
@@ -0,0 +1,27 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
diff --git a/dbus/dbus-bluez-v5.40/org.bluez.Device1.xml b/dbus/dbus-bluez-v5.40/org.bluez.Device1.xml
new file mode 100644
index 0000000..b9b1c62
--- /dev/null
+++ b/dbus/dbus-bluez-v5.40/org.bluez.Device1.xml
@@ -0,0 +1,45 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
diff --git a/dbus/dbus-bluez-v5.40/org.bluez.GattCharacteristic1.xml b/dbus/dbus-bluez-v5.40/org.bluez.GattCharacteristic1.xml
new file mode 100644
index 0000000..f6c1eaa
--- /dev/null
+++ b/dbus/dbus-bluez-v5.40/org.bluez.GattCharacteristic1.xml
@@ -0,0 +1,34 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
diff --git a/dbus/dbus-bluez-v5.40/org.bluez.GattDescriptor1.xml b/dbus/dbus-bluez-v5.40/org.bluez.GattDescriptor1.xml
new file mode 100644
index 0000000..e4549ff
--- /dev/null
+++ b/dbus/dbus-bluez-v5.40/org.bluez.GattDescriptor1.xml
@@ -0,0 +1,25 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
diff --git a/dbus/dbus-bluez-v5.40/org.bluez.GattService1.xml b/dbus/dbus-bluez-v5.40/org.bluez.GattService1.xml
new file mode 100644
index 0000000..0ae67c4
--- /dev/null
+++ b/dbus/dbus-bluez-v5.40/org.bluez.GattService1.xml
@@ -0,0 +1,17 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
diff --git a/dbus/gattlib.c b/dbus/gattlib.c
index 1e571fd..cea368d 100644
--- a/dbus/gattlib.c
+++ b/dbus/gattlib.c
@@ -784,8 +784,14 @@ int gattlib_read_char_by_uuid(gatt_connection_t* connection, uuid_t* uuid, void*
GVariant *out_value;
GError *error = NULL;
+#if BLUEZ_VERSION < BLUEZ_VERSIONS(5, 40)
org_bluez_gatt_characteristic1_call_read_value_sync(
characteristic, &out_value, NULL, &error);
+#else
+ GVariant *options = g_variant_new ("{}");
+ org_bluez_gatt_characteristic1_call_read_value_sync(
+ characteristic, options, &out_value, NULL, &error);
+#endif
if (error != NULL) {
return -1;
}
@@ -800,6 +806,10 @@ int gattlib_read_char_by_uuid(gatt_connection_t* connection, uuid_t* uuid, void*
*buffer_len = n_elements;
g_object_unref(characteristic);
+
+#if BLUEZ_VERSION >= BLUEZ_VERSIONS(5, 40)
+ //g_variant_unref(in_params); See: https://github.com/labapart/gattlib/issues/28#issuecomment-311486629
+#endif
return 0;
}
@@ -812,8 +822,14 @@ int gattlib_read_char_by_uuid_async(gatt_connection_t* connection, uuid_t* uuid,
GVariant *out_value;
GError *error = NULL;
+#if BLUEZ_VERSION < BLUEZ_VERSIONS(5, 40)
org_bluez_gatt_characteristic1_call_read_value_sync(
characteristic, &out_value, NULL, &error);
+#else
+ GVariant *options = g_variant_new ("{}");
+ org_bluez_gatt_characteristic1_call_read_value_sync(
+ characteristic, options, &out_value, NULL, &error);
+#endif
if (error != NULL) {
return -1;
}
@@ -825,6 +841,10 @@ int gattlib_read_char_by_uuid_async(gatt_connection_t* connection, uuid_t* uuid,
}
g_object_unref(characteristic);
+
+#if BLUEZ_VERSION >= BLUEZ_VERSIONS(5, 40)
+ //g_variant_unref(in_params); See: https://github.com/labapart/gattlib/issues/28#issuecomment-311486629
+#endif
return 0;
}
@@ -837,12 +857,20 @@ int gattlib_write_char_by_uuid(gatt_connection_t* connection, uuid_t* uuid, cons
GVariant *value = g_variant_new_from_data(G_VARIANT_TYPE ("ay"), buffer, buffer_len, TRUE, NULL, NULL);
GError *error = NULL;
+#if BLUEZ_VERSION < BLUEZ_VERSIONS(5, 40)
org_bluez_gatt_characteristic1_call_write_value_sync(characteristic, value, NULL, &error);
+#else
+ GVariant *options = g_variant_new ("{}");
+ org_bluez_gatt_characteristic1_call_write_value_sync(characteristic, options, value, NULL, &error);
+#endif
if (error != NULL) {
return -1;
}
g_object_unref(characteristic);
+#if BLUEZ_VERSION >= BLUEZ_VERSIONS(5, 40)
+ //g_variant_unref(in_params); See: https://github.com/labapart/gattlib/issues/28#issuecomment-311486629
+#endif
return 0;
}