aboutsummaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorChuck Claunch <[email protected]>2017-06-11 22:53:31 -0500
committerChuck Claunch <[email protected]>2017-06-11 22:53:31 -0500
commit7afdda37826d56ecf407e9d79bbafabeac4ce79e (patch)
tree95a493e8f17cd38e57afbfb9cefc6f00d0bb06cf /src
parentb9cdd91d075420911e6f56f633fb1048cbe4350c (diff)
Added annotations to dbus profile so GVariants would replace gchars in the code generation, and modified BluetoothGattCharacteristc to match.
Signed-off-by: Chuck Claunch <[email protected]>
Diffstat (limited to 'src')
-rw-r--r--src/BluetoothGattCharacteristic.cpp20
-rw-r--r--src/generated-code.c58
-rw-r--r--src/org.bluez.xml14
3 files changed, 49 insertions, 43 deletions
diff --git a/src/BluetoothGattCharacteristic.cpp b/src/BluetoothGattCharacteristic.cpp
index ff2ed1b..fec6d2f 100644
--- a/src/BluetoothGattCharacteristic.cpp
+++ b/src/BluetoothGattCharacteristic.cpp
@@ -123,7 +123,7 @@ std::unique_ptr<BluetoothGattCharacteristic> BluetoothGattCharacteristic::make(
std::vector<unsigned char> BluetoothGattCharacteristic::read_value (uint16_t offset)
{
GError *error = NULL;
- gchar *result_chars;
+ GVariant *result_variant;
GVariantDict dict;
g_variant_dict_init(&dict, NULL);
@@ -136,14 +136,15 @@ std::vector<unsigned char> BluetoothGattCharacteristic::read_value (uint16_t off
gatt_characteristic1_call_read_value_sync(
object,
variant,
- &result_chars,
+ &result_variant,
NULL,
&error
);
handle_error(error);
- std::vector<unsigned char> result = from_chars_to_vector(result_chars);
+ GBytes *result_gbytes = g_variant_get_data_as_bytes(result_variant);
+ std::vector<unsigned char> result = from_gbytes_to_vector(result_gbytes);
return result;
}
@@ -154,7 +155,10 @@ bool BluetoothGattCharacteristic::write_value (
GError *error = NULL;
bool result = true;
- std::string arg_value_str(arg_value.begin(), arg_value.end());
+ gboolean trusted = true;
+ GBytes *arg_value_gbytes = from_vector_to_gbytes(arg_value);
+ GVariant *value = g_variant_new_from_bytes(
+ G_VARIANT_TYPE_BYTESTRING, arg_value_gbytes, trusted);
GVariantDict dict;
g_variant_dict_init(&dict, NULL);
@@ -166,7 +170,7 @@ bool BluetoothGattCharacteristic::write_value (
result = gatt_characteristic1_call_write_value_sync(
object,
- arg_value_str.c_str(),
+ value,
variant,
NULL,
&error
@@ -259,10 +263,10 @@ BluetoothGattService BluetoothGattCharacteristic::get_service ()
std::vector<unsigned char> BluetoothGattCharacteristic::get_value ()
{
- gchar *value_chars = const_cast<gchar *>(gatt_characteristic1_get_value (object));
- std::vector<unsigned char> result;
+ GVariant *value_variant = gatt_characteristic1_get_value (object);
+ GBytes *value_gbytes = g_variant_get_data_as_bytes(value_variant);
- result = from_chars_to_vector(value_chars);
+ std::vector<unsigned char> result = from_gbytes_to_vector(value_gbytes);
return result;
}
diff --git a/src/generated-code.c b/src/generated-code.c
index 4492c3b..ad14d09 100644
--- a/src/generated-code.c
+++ b/src/generated-code.c
@@ -7719,7 +7719,7 @@ static const _ExtendedGDBusArgInfo _gatt_characteristic1_method_info_read_value_
(gchar *) "ay",
NULL
},
- FALSE
+ TRUE
};
static const _ExtendedGDBusArgInfo * const _gatt_characteristic1_method_info_read_value_OUT_ARG_pointers[] =
@@ -7749,7 +7749,7 @@ static const _ExtendedGDBusArgInfo _gatt_characteristic1_method_info_write_value
(gchar *) "ay",
NULL
},
- FALSE
+ TRUE
};
static const _ExtendedGDBusArgInfo _gatt_characteristic1_method_info_write_value_IN_ARG_options =
@@ -7854,7 +7854,7 @@ static const _ExtendedGDBusPropertyInfo _gatt_characteristic1_property_info_valu
NULL
},
"value",
- FALSE
+ TRUE
};
static const _ExtendedGDBusPropertyInfo _gatt_characteristic1_property_info_notifying =
@@ -8033,7 +8033,7 @@ gatt_characteristic1_default_init (GattCharacteristic1Iface *iface)
g_cclosure_marshal_generic,
G_TYPE_BOOLEAN,
3,
- G_TYPE_DBUS_METHOD_INVOCATION, G_TYPE_STRING, G_TYPE_VARIANT);
+ G_TYPE_DBUS_METHOD_INVOCATION, G_TYPE_VARIANT, G_TYPE_VARIANT);
/**
* GattCharacteristic1::handle-start-notify:
@@ -8106,7 +8106,7 @@ gatt_characteristic1_default_init (GattCharacteristic1Iface *iface)
* Since the D-Bus property for this #GObject property is readable but not writable, it is meaningful to read from it on both the client- and service-side. It is only meaningful, however, to write to it on the service-side.
*/
g_object_interface_install_property (iface,
- g_param_spec_string ("value", "Value", "Value", NULL, G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS));
+ g_param_spec_variant ("value", "Value", "Value", G_VARIANT_TYPE ("ay"), NULL, G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS));
/**
* GattCharacteristic1:notifying:
*
@@ -8250,7 +8250,7 @@ gatt_characteristic1_set_service (GattCharacteristic1 *object, const gchar *valu
*
* Returns: (transfer none): The property value or %NULL if the property is not set. Do not free the returned value, it belongs to @object.
*/
-const gchar *
+GVariant *
gatt_characteristic1_get_value (GattCharacteristic1 *object)
{
return GATT_CHARACTERISTIC1_GET_IFACE (object)->get_value (object);
@@ -8264,12 +8264,12 @@ gatt_characteristic1_get_value (GattCharacteristic1 *object)
*
* Since this D-Bus property is readable, it is meaningful to use this function on both the client- and service-side.
*
- * Returns: (transfer full): The property value or %NULL if the property is not set. The returned value should be freed with g_free().
+ * Returns: (transfer full): The property value or %NULL if the property is not set. The returned value should be freed with g_variant_unref().
*/
-gchar *
+GVariant *
gatt_characteristic1_dup_value (GattCharacteristic1 *object)
{
- gchar *value;
+ GVariant *value;
g_object_get (G_OBJECT (object), "value", &value, NULL);
return value;
}
@@ -8284,7 +8284,7 @@ gatt_characteristic1_dup_value (GattCharacteristic1 *object)
* Since this D-Bus property is not writable, it is only meaningful to use this function on the service-side.
*/
void
-gatt_characteristic1_set_value (GattCharacteristic1 *object, const gchar *value)
+gatt_characteristic1_set_value (GattCharacteristic1 *object, GVariant *value)
{
g_object_set (G_OBJECT (object), "value", value, NULL);
}
@@ -8469,7 +8469,7 @@ gatt_characteristic1_call_read_value (
gboolean
gatt_characteristic1_call_read_value_finish (
GattCharacteristic1 *proxy,
- gchar **out_value,
+ GVariant **out_value,
GAsyncResult *res,
GError **error)
{
@@ -8478,7 +8478,7 @@ gatt_characteristic1_call_read_value_finish (
if (_ret == NULL)
goto _out;
g_variant_get (_ret,
- "(^ay)",
+ "(@ay)",
out_value);
g_variant_unref (_ret);
_out:
@@ -8503,7 +8503,7 @@ gboolean
gatt_characteristic1_call_read_value_sync (
GattCharacteristic1 *proxy,
GVariant *arg_options,
- gchar **out_value,
+ GVariant **out_value,
GCancellable *cancellable,
GError **error)
{
@@ -8519,7 +8519,7 @@ gatt_characteristic1_call_read_value_sync (
if (_ret == NULL)
goto _out;
g_variant_get (_ret,
- "(^ay)",
+ "(@ay)",
out_value);
g_variant_unref (_ret);
_out:
@@ -8544,7 +8544,7 @@ _out:
void
gatt_characteristic1_call_write_value (
GattCharacteristic1 *proxy,
- const gchar *arg_value,
+ GVariant *arg_value,
GVariant *arg_options,
GCancellable *cancellable,
GAsyncReadyCallback callback,
@@ -8552,7 +8552,7 @@ gatt_characteristic1_call_write_value (
{
g_dbus_proxy_call (G_DBUS_PROXY (proxy),
"WriteValue",
- g_variant_new ("(^ay@a{sv})",
+ g_variant_new ("(@ay@a{sv})",
arg_value,
arg_options),
G_DBUS_CALL_FLAGS_NONE,
@@ -8606,7 +8606,7 @@ _out:
gboolean
gatt_characteristic1_call_write_value_sync (
GattCharacteristic1 *proxy,
- const gchar *arg_value,
+ GVariant *arg_value,
GVariant *arg_options,
GCancellable *cancellable,
GError **error)
@@ -8614,7 +8614,7 @@ gatt_characteristic1_call_write_value_sync (
GVariant *_ret;
_ret = g_dbus_proxy_call_sync (G_DBUS_PROXY (proxy),
"WriteValue",
- g_variant_new ("(^ay@a{sv})",
+ g_variant_new ("(@ay@a{sv})",
arg_value,
arg_options),
G_DBUS_CALL_FLAGS_NONE,
@@ -8828,10 +8828,10 @@ void
gatt_characteristic1_complete_read_value (
GattCharacteristic1 *object,
GDBusMethodInvocation *invocation,
- const gchar *value)
+ GVariant *value)
{
g_dbus_method_invocation_return_value (invocation,
- g_variant_new ("(^ay)",
+ g_variant_new ("(@ay)",
value));
}
@@ -9096,18 +9096,16 @@ gatt_characteristic1_proxy_get_service (GattCharacteristic1 *object)
return value;
}
-static const gchar *
+static GVariant *
gatt_characteristic1_proxy_get_value (GattCharacteristic1 *object)
{
GattCharacteristic1Proxy *proxy = GATT_CHARACTERISTIC1_PROXY (object);
GVariant *variant;
- const gchar *value = NULL;
+ GVariant *value = NULL;
variant = g_dbus_proxy_get_cached_property (G_DBUS_PROXY (proxy), "Value");
+ value = variant;
if (variant != NULL)
- {
- value = g_variant_get_bytestring (variant);
- g_variant_unref (variant);
- }
+ g_variant_unref (variant);
return value;
}
@@ -9793,7 +9791,7 @@ gatt_characteristic1_skeleton_init (GattCharacteristic1Skeleton *skeleton)
skeleton->priv->properties = g_new0 (GValue, 6);
g_value_init (&skeleton->priv->properties[0], G_TYPE_STRING);
g_value_init (&skeleton->priv->properties[1], G_TYPE_STRING);
- g_value_init (&skeleton->priv->properties[2], G_TYPE_STRING);
+ g_value_init (&skeleton->priv->properties[2], G_TYPE_VARIANT);
g_value_init (&skeleton->priv->properties[3], G_TYPE_BOOLEAN);
g_value_init (&skeleton->priv->properties[4], G_TYPE_STRV);
g_value_init (&skeleton->priv->properties[5], G_TYPE_STRV);
@@ -9821,13 +9819,13 @@ gatt_characteristic1_skeleton_get_service (GattCharacteristic1 *object)
return value;
}
-static const gchar *
+static GVariant *
gatt_characteristic1_skeleton_get_value (GattCharacteristic1 *object)
{
GattCharacteristic1Skeleton *skeleton = GATT_CHARACTERISTIC1_SKELETON (object);
- const gchar *value;
+ GVariant *value;
g_mutex_lock (&skeleton->priv->lock);
- value = g_value_get_string (&(skeleton->priv->properties[2]));
+ value = g_value_get_variant (&(skeleton->priv->properties[2]));
g_mutex_unlock (&skeleton->priv->lock);
return value;
}
diff --git a/src/org.bluez.xml b/src/org.bluez.xml
index ea3ec29..0574ec2 100644
--- a/src/org.bluez.xml
+++ b/src/org.bluez.xml
@@ -83,18 +83,24 @@ THE SOFTWARE.
<interface name="org.bluez.GattCharacteristic1">
<method name="ReadValue">
- <arg name="value" type="ay" direction="out"/>
+ <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"/>
+ <arg name="value" type="ay" byte_arrays="True" 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="Value" type="ay" access="read">
+ <annotation name="org.gtk.GDBus.C.ForceGVariant" value="true"/>
+ </property>
<property name="Notifying" type="b" access="read"/>
<property name="Flags" type="as" access="read"/>
<property name="Descriptors" type="ao" access="read"/>
@@ -118,9 +124,7 @@ THE SOFTWARE.
<method name="Release">
<annotation name="org.freedesktop.DBus.Method.NoReply" value="true"/>
</method>
-
<annotation name="org.freedesktop.DBus.Properties.PropertiesChanged" value="const"/>
-
<property name="Type" type="s" access="read"/>
<property name="ServiceUUIDs" type="as" access="read"/>
<property name="ManufacturerData" type="a{sv}" access="read"/>