1

I am using gdbus-codegen to generate code for DBUS client. I have GVariant property in third party DBUS server <property name="someProperty" type="(iiii)" access="read"/>

When I call the autogenerated method to get the property value:

GVariant* data = interface_name_get_some_property(proxy);

some times the data is NULL. The comment in the autogenerated code states:

Returns: (transfer none): The property value or %NULL if the property is not set. Do not free the returned value, it belongs to @object.

What does "not set" means and how should I treat this situation? I thought that by default (if option G_DBUS_PROXY_FLAGS_DO_NOT_LOAD_PROPERTIES is not set) glib loads all properties and they all should be set.

xXx_CodeMonkey_xXx
  • 800
  • 1
  • 7
  • 14

1 Answers1

2

The generated code uses g_dbus_proxy_get_cached_property() which will never do blocking I/O: if the property is not in cache for any reason, you will not get the correct value. A common gotcha would be fetching the property value immediately after creating the proxy: g_dbus_proxy_new() loads the property values asynchronously so they should not be available at that point.

The best way to deal with properties is to use the property change notifications. The generated GObjects "notify" signal should be the easiest way in your case:

void
on_some_property_notify (GObject    *proxy,
                         GParamSpec *pspec,
                         gpointer    user_data)
{
    GVariant* data = interface_name_get_some_property(proxy);
    // Do something with new prop value here
}

// TODO: check what the actual generated property name is
g_signal_connect (proxy, "notify::someProperty",
                  G_CALLBACK (on_some_property_notify), user_data);
Jussi Kukkonen
  • 13,857
  • 1
  • 37
  • 54
  • Thank you for the reply. I understand almost all of what you are saying. But what is this "any reason"? Could you please make an example? When I am implementing the DBUS server this never happens. Also, I am requesting the property value long after the proxy is created. – xXx_CodeMonkey_xXx Sep 28 '17 at 09:06