* way of working with proxies is to subclass #GDBusProxy, and have
* more natural properties and signals in your derived class.
*
+ * A #GDBusProxy instance can be used from multiple threads but note
+ * that all signals (e.g. #GDBusProxy::g-signal, #GDBusProxy::g-properties
+ * and #GObject::notify) are emitted in the
+ * <link linkend="g-main-context-push-thread-default">thread-default main loop</link>
+ * of the thread where the instance was constructed.
+ *
* See <xref linkend="gdbus-example-proxy-subclass"/> for an example.
*
* <example id="gdbus-wellknown-proxy"><title>GDBusProxy for a well-known-name</title><programlisting><xi:include xmlns:xi="http://www.w3.org/2001/XInclude" parse="text" href="../../../../gio/tests/gdbus-example-watch-proxy.c"><xi:fallback>FIXME: MISSING XINCLUDE CONTENT</xi:fallback></xi:include></programlisting></example>
*/
+/* lock protecting the properties GHashTable */
+G_LOCK_DEFINE_STATIC (properties_lock);
+
/* ---------------------------------------------------------------------------------------------------- */
G_LOCK_DEFINE_STATIC (signal_subscription_lock);
g_return_val_if_fail (G_IS_DBUS_PROXY (proxy), NULL);
+ G_LOCK (properties_lock);
+
names = NULL;
if (g_hash_table_size (proxy->priv->properties) == 0)
goto out;
names = (gchar **) g_ptr_array_free (p, FALSE);
out:
+ G_UNLOCK (properties_lock);
return names;
}
g_return_val_if_fail (G_IS_DBUS_PROXY (proxy), NULL);
g_return_val_if_fail (property_name != NULL, NULL);
+ G_LOCK (properties_lock);
+
value = g_hash_table_lookup (proxy->priv->properties, property_name);
if (value == NULL)
{
g_variant_ref (value);
out:
+ G_UNLOCK (properties_lock);
return value;
}
g_return_if_fail (G_IS_DBUS_PROXY (proxy));
g_return_if_fail (property_name != NULL);
+ G_LOCK (properties_lock);
+
if (value != NULL)
{
info = lookup_property_info_or_warn (proxy, property_name);
}
out:
- ;
+ G_UNLOCK (properties_lock);
}
/* ---------------------------------------------------------------------------------------------------- */
/* ---------------------------------------------------------------------------------------------------- */
+/* must hold properties_lock */
static void
insert_property_checked (GDBusProxy *proxy,
gchar *property_name,
if (g_strcmp0 (interface_name_for_signal, proxy->priv->interface_name) != 0)
goto out;
+ G_LOCK (properties_lock);
+
g_variant_iter_init (&iter, changed_properties);
while (g_variant_iter_next (&iter, "{sv}", &key, &value))
{
g_hash_table_remove (proxy->priv->properties, invalidated_properties[n]);
}
+ G_UNLOCK (properties_lock);
+
/* emit signal */
g_signal_emit (proxy, signals[PROPERTIES_CHANGED_SIGNAL],
0,
GVariantIter *iter;
gchar *key;
GVariant *value;
+ guint num_properties;
if (!g_variant_is_of_type (result, G_VARIANT_TYPE ("(a{sv})")))
{
goto out;
}
+ G_LOCK (properties_lock);
+
g_variant_get (result, "(a{sv})", &iter);
while (g_variant_iter_next (iter, "{sv}", &key, &value))
{
}
g_variant_iter_free (iter);
+ num_properties = g_hash_table_size (proxy->priv->properties);
+ G_UNLOCK (properties_lock);
+
/* Synthesize ::g-properties-changed changed */
- if (g_hash_table_size (proxy->priv->properties) > 0)
+ if (num_properties > 0)
{
GVariant *changed_properties;
const gchar *invalidated_properties[1] = {NULL};
data->proxy->priv->name_owner = data->name_owner;
data->name_owner = NULL; /* to avoid an extra copy, we steal the string */
+ G_LOCK (properties_lock);
g_hash_table_remove_all (data->proxy->priv->properties);
+ G_UNLOCK (properties_lock);
if (result != NULL)
{
process_get_all_reply (data->proxy, result);
g_free (proxy->priv->name_owner);
proxy->priv->name_owner = NULL;
+ G_LOCK (properties_lock);
+
/* Synthesize ::g-properties-changed changed */
if (!(proxy->priv->flags & G_DBUS_PROXY_FLAGS_DO_NOT_LOAD_PROPERTIES) &&
g_hash_table_size (proxy->priv->properties) > 0)
/* ... throw out the properties ... */
g_hash_table_remove_all (proxy->priv->properties);
+ G_UNLOCK (properties_lock);
+
/* ... and finally emit the ::g-properties-changed signal */
g_signal_emit (proxy, signals[PROPERTIES_CHANGED_SIGNAL],
0,
(const gchar* const *) invalidated_properties->pdata);
g_ptr_array_unref (invalidated_properties);
}
+ else
+ {
+ G_UNLOCK (properties_lock);
+ }
g_object_notify (G_OBJECT (proxy), "g-name-owner");
}
else
{
g_free (proxy->priv->name_owner);
proxy->priv->name_owner = g_strdup (new_owner);
+ G_LOCK (properties_lock);
g_hash_table_remove_all (proxy->priv->properties);
+ G_UNLOCK (properties_lock);
g_object_notify (G_OBJECT (proxy), "g-name-owner");
}
else
*
* This is an asynchronous method. When the operation is finished,
* @callback will be invoked in the
- * <link linkend="g-main-context-push-thread-default">thread-default
- * main loop</link> of the thread you are calling this method from.
+ * <link linkend="g-main-context-push-thread-default">thread-default main loop</link>
+ * of the thread you are calling this method from.
* You can then call g_dbus_proxy_call_finish() to get the result of
* the operation. See g_dbus_proxy_call_sync() for the synchronous
* version of this method.