dbus: Added support for Bluez DBus API v5.40

pull/32/head
Olivier Martin 2017-07-02 15:15:14 +02:00
parent 2e88aec8e1
commit c890f64dd9
12 changed files with 192 additions and 10 deletions

View File

@ -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'"
)

View File

@ -0,0 +1,27 @@
<!DOCTYPE node PUBLIC "-//freedesktop//DTD D-BUS Object Introspection 1.0//EN"
"http://www.freedesktop.org/standards/dbus/1.0/introspect.dtd">
<node>
<interface name="org.bluez.Adapter1">
<method name="StartDiscovery"></method>
<method name="SetDiscoveryFilter">
<arg name="properties" type="a{sv}" direction="in"/>
</method>
<method name="StopDiscovery"></method>
<method name="RemoveDevice">
<arg name="device" type="o" direction="in"/>
</method>
<property name="Address" type="s" access="read"></property>
<property name="Name" type="s" access="read"></property>
<property name="Alias" type="s" access="readwrite"></property>
<property name="Class" type="u" access="read"></property>
<property name="Powered" type="b" access="readwrite"></property>
<property name="Discoverable" type="b" access="readwrite"></property>
<property name="DiscoverableTimeout" type="u" access="readwrite"></property>
<property name="Pairable" type="b" access="readwrite"></property>
<property name="PairableTimeout" type="u" access="readwrite"></property>
<property name="Discovering" type="b" access="read"></property>
<property name="UUIDs" type="as" access="read"></property>
<property name="Modalias" type="s" access="read"></property>
</interface>
</node>

View File

@ -0,0 +1,45 @@
<!DOCTYPE node PUBLIC "-//freedesktop//DTD D-BUS Object Introspection 1.0//EN"
"http://www.freedesktop.org/standards/dbus/1.0/introspect.dtd">
<node>
<interface name="org.bluez.Device1">
<method name="Disconnect"></method>
<method name="Connect"></method>
<method name="ConnectProfile">
<arg name="UUID" type="s" direction="in"/>
</method>
<method name="DisconnectProfile">
<arg name="UUID" type="s" direction="in"/>
</method>
<method name="Pair"></method>
<method name="CancelPairing"></method>
<property name="Address" type="s" access="read"></property>
<property name="Name" type="s" access="read"></property>
<property name="Alias" type="s" access="readwrite"></property>
<property name="Class" type="u" access="read"></property>
<property name="Appearance" type="q" access="read"></property>
<property name="Icon" type="s" access="read"></property>
<property name="Paired" type="b" access="read"></property>
<property name="Trusted" type="b" access="readwrite"></property>
<property name="Blocked" type="b" access="readwrite"></property>
<property name="LegacyPairing" type="b" access="read"></property>
<property name="RSSI" type="n" access="read"></property>
<property name="Connected" type="b" access="read"></property>
<property name="UUIDs" type="as" access="read"></property>
<property name="Modalias" type="s" access="read"></property>
<property name="Adapter" type="o" access="read"></property>
<property name="TxPower" type="n" access="read"></property>
<!--<property name="ManufacturerData" type="" access="read"></property>-->
<!--<property name="ServiceData" type="" access="read"></property>-->
<!-- Was available until Bluez v5.37 to expose the list of available org.bluez.GattService1 -->
<property name="GattServices" type="ao" access="read"></property>
<signal name="PropertiesChanged">
<arg name="interface" type="s"/>
<arg name="changed_properties" type="a{sv}"/>
<arg name="invalidated_properties" type="as"/>
</signal>
</interface>
</node>

View File

@ -0,0 +1,34 @@
<!DOCTYPE node PUBLIC "-//freedesktop//DTD D-BUS Object Introspection 1.0//EN"
"http://www.freedesktop.org/standards/dbus/1.0/introspect.dtd">
<node>
<interface name="org.bluez.GattCharacteristic1">
<method name="ReadValue">
<arg name="value" type="ay" direction="out">
<annotation name="org.gtk.GDBus.C.ForceGVariant" value="true"/>
</arg>
<arg name="options" type="a{sv}" direction="in"/>
</method>
<method name="WriteValue">
<arg name="value" type="ay" direction="in">
<annotation name="org.gtk.GDBus.C.ForceGVariant" value="true"/>
</arg>
<arg name="options" type="a{sv}" direction="in"/>
</method>
<method name="StartNotify"/>
<method name="StopNotify"/>
<property name="UUID" type="s" access="read"/>
<property name="Service" type="o" access="read"/>
<property name="Value" type="ay" access="read"/>
<property name="Notifying" type="b" access="read"/>
<property name="Flags" type="as" access="read"/>
<property name="Descriptors" type="ao" access="read"/>
<signal name="PropertiesChanged">
<arg name="interface" type="s"/>
<arg name="changed_properties" type="a{sv}"/>
<arg name="invalidated_properties" type="as"/>
</signal>
</interface>
</node>

View File

@ -0,0 +1,25 @@
<!DOCTYPE node PUBLIC "-//freedesktop//DTD D-BUS Object Introspection 1.0//EN"
"http://www.freedesktop.org/standards/dbus/1.0/introspect.dtd">
<node>
<interface name="org.bluez.GattDescriptor1">
<method name="ReadValue">
<arg name="value" type="ay" direction="out"/>
<arg name="options" type="a{sv}" direction="in"/>
</method>
<method name="WriteValue">
<arg name="value" type="ay" direction="in"/>
<arg name="options" type="a{sv}" direction="in"/>
</method>
<property name="UUID" type="s" access="read"/>
<property name="Characteristic" type="o" access="read"/>
<property name="Value" type="ay" access="read"/>
<signal name="PropertiesChanged">
<arg name="interface" type="s"/>
<arg name="changed_properties" type="a{sv}"/>
<arg name="invalidated_properties" type="as"/>
</signal>
</interface>
</node>

View File

@ -0,0 +1,17 @@
<!DOCTYPE node PUBLIC "-//freedesktop//DTD D-BUS Object Introspection 1.0//EN"
"http://www.freedesktop.org/standards/dbus/1.0/introspect.dtd">
<node>
<interface name="org.bluez.GattService1">
<property name="UUID" type="s" access="read"></property>
<property name="Device" type="o" access="read"></property>
<property name="Primary" type="b" access="read"></property>
<property name="Characteristics" type="ao" access="read"></property>
<signal name="PropertiesChanged">
<arg name="interface" type="s"/>
<arg name="changed_properties" type="a{sv}"/>
<arg name="invalidated_properties" type="as"/>
</signal>
</interface>
</node>

View File

@ -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;
}