mirror of
https://gitlab.gnome.org/GNOME/glib.git
synced 2025-08-01 23:13:40 +02:00
GDBusConnection: allow async property handling
The existing advice in the documentation to "simply" register the "org.freedesktop.DBus.Properties" interface if you want to handle properties asynchronously is pretty unreasonable. If you want to handle this interface you have to deal with all properties for all interfaces on the path, and you have to do all of the checking for yourself. You also have to provide your own introspection data. Introduce a new convention for dealing with properties asynchronously. If the user provides NULL for their get_property() or set_property() functions in the vtable and has properties registered then the properties are sent to the method_call() handler. We get lucky here that this function takes an "interface_name" parameter that we can set to "org.freedesktop.DBus.Properties". We also do the user the favour of setting the GDBusPropertyInfo on the GDBusMethodInvocation for their convenience (for much the same reasons as they might want the already-available GDBusMethodInfo). Add a testcase as well as a bunch of documentation about this new feature. https://bugzilla.gnome.org/show_bug.cgi?id=698375
This commit is contained in:
@@ -4272,17 +4272,8 @@ validate_and_maybe_schedule_property_getset (GDBusConnection *connect
|
||||
&property_name,
|
||||
NULL);
|
||||
|
||||
|
||||
if (is_get)
|
||||
{
|
||||
if (vtable == NULL || vtable->get_property == NULL)
|
||||
goto out;
|
||||
}
|
||||
else
|
||||
{
|
||||
if (vtable == NULL || vtable->set_property == NULL)
|
||||
goto out;
|
||||
}
|
||||
if (vtable == NULL)
|
||||
goto out;
|
||||
|
||||
/* Check that the property exists - if not fail with org.freedesktop.DBus.Error.InvalidArgs
|
||||
*/
|
||||
@@ -4350,6 +4341,32 @@ validate_and_maybe_schedule_property_getset (GDBusConnection *connect
|
||||
g_variant_unref (value);
|
||||
}
|
||||
|
||||
/* If the vtable pointer for get_property() resp. set_property() is
|
||||
* NULL then dispatch the call via the method_call() handler.
|
||||
*/
|
||||
if (is_get)
|
||||
{
|
||||
if (vtable->get_property == NULL)
|
||||
{
|
||||
schedule_method_call (connection, message, registration_id, subtree_registration_id,
|
||||
interface_info, NULL, property_info, g_dbus_message_get_body (message),
|
||||
vtable, main_context, user_data);
|
||||
handled = TRUE;
|
||||
goto out;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
if (vtable->set_property == NULL)
|
||||
{
|
||||
schedule_method_call (connection, message, registration_id, subtree_registration_id,
|
||||
interface_info, NULL, property_info, g_dbus_message_get_body (message),
|
||||
vtable, main_context, user_data);
|
||||
handled = TRUE;
|
||||
goto out;
|
||||
}
|
||||
}
|
||||
|
||||
/* ok, got the property info - call user code in an idle handler */
|
||||
property_data = g_new0 (PropertyData, 1);
|
||||
property_data->connection = g_object_ref (connection);
|
||||
@@ -4538,9 +4555,21 @@ validate_and_maybe_schedule_property_get_all (GDBusConnection *connec
|
||||
|
||||
handled = FALSE;
|
||||
|
||||
if (vtable == NULL || vtable->get_property == NULL)
|
||||
if (vtable == NULL)
|
||||
goto out;
|
||||
|
||||
/* If the vtable pointer for get_property() is NULL, then dispatch the
|
||||
* call via the method_call() handler.
|
||||
*/
|
||||
if (vtable->get_property == NULL)
|
||||
{
|
||||
schedule_method_call (connection, message, registration_id, subtree_registration_id,
|
||||
interface_info, NULL, NULL, g_dbus_message_get_body (message),
|
||||
vtable, main_context, user_data);
|
||||
handled = TRUE;
|
||||
goto out;
|
||||
}
|
||||
|
||||
/* ok, got the property info - call user in an idle handler */
|
||||
property_get_all_data = g_new0 (PropertyGetAllData, 1);
|
||||
property_get_all_data->connection = g_object_ref (connection);
|
||||
|
Reference in New Issue
Block a user