How to validate a DBus property when using gdbus-codegen skeleton
- From: Anders Norman <norman anders gmail com>
- To: gtk-list gnome org
- Subject: How to validate a DBus property when using gdbus-codegen skeleton
- Date: Tue, 31 May 2016 12:32:15 +0200
I'm creating a service on DBus using `gdbus` and `gdbus-codegen`.
Introspection is this:
<!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="com.example.foo">
<property name="Bar" type="s" access="readwrite" />
</interface>
</node>
I'm executing `gdbus-codegen` like this:
gdbus-codegen --interface-prefix com.example \
--generate-c-code=foo foo.xml
And my main.cpp looks like this:
#include <iostream>
#include "foo.h"
void OnBarChanged(GObject * gobject,
GParamSpec * pspec,
gpointer user_data)
{
std::cout << "Bar: " << foo_get_bar((Foo *)gobject) << std::endl;
}
void OnBusNameAquired(GDBusConnection * connection,
const gchar * name,
gpointer user_data)
{
Foo * foo = foo_skeleton_new();
g_signal_connect(foo, "notify::bar", G_CALLBACK(&OnBarChanged), NULL);
g_dbus_interface_skeleton_export(G_DBUS_INTERFACE_SKELETON(foo),
connection,
"/com/example/foo",
NULL);
}
int main()
{
std::cout << "Testing DBus properties" << std::endl;
GMainLoop * loop;
loop = g_main_loop_new(NULL, FALSE);
g_bus_own_name(G_BUS_TYPE_SESSION,
"com.example.foo",
G_BUS_NAME_OWNER_FLAGS_NONE,
NULL,
OnBusNameAquired,
NULL,
NULL,
NULL);
g_main_loop_run(loop);
return 0;
}
This works as expected and I'm able to set and get properties using:
gdbus call --session --dest com.example.foo \
--object-path /com/example/foo \
--method org.freedesktop.DBus.Properties.Set \
"com.example.foo" "Bar" "<'baz'>"
and
gdbus call --session --dest com.example.foo \
--object-path /com/example/foo \
--method org.freedesktop.DBus.Properties.Get \
"com.example.foo" "Bar"
(<'baz'>,)
The problem:
I want to validate the setting of the property synchronously and be able
to return an error if it fails. How can this be accomplished using the
`gdbus-codegen`-generated code?
PS:
The code leaks and is generally not production ready. I'm fine with that
for now :-)
PPS:
This question is also posted on
http://stackoverflow.com/questions/37541857/how-to-validate-a-dbus-property-when-using-gdbus-codegen-skeleton
[
Date Prev][Date Next] [
Thread Prev][Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]