summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorWill Thompson <will.thompson@collabora.co.uk>2011-10-11 18:14:23 +0100
committerWill Thompson <will.thompson@collabora.co.uk>2011-10-11 18:14:25 +0100
commit3caf6bafbb2e4efe3154ebe1e833096d11e8ffce (patch)
treeb34eba818cdafdc511817b105dffa722619f7229
parenteaa0477a43617b2f9c4585a81c2b6bbbf7eefcc4 (diff)
parentd805cc7eb60597df6e819bdc7d251b5ad24ffb1a (diff)
Merge branch 'dbus-properties-mixin-stuff'
Reviewed-by: Xavier Claessens <xclaesse@gmail.com>
-rw-r--r--docs/reference/telepathy-glib-sections.txt2
-rw-r--r--telepathy-glib/dbus-properties-mixin.c123
-rw-r--r--telepathy-glib/dbus-properties-mixin.h8
3 files changed, 93 insertions, 40 deletions
diff --git a/docs/reference/telepathy-glib-sections.txt b/docs/reference/telepathy-glib-sections.txt
index 01e12f7b..10925ff7 100644
--- a/docs/reference/telepathy-glib-sections.txt
+++ b/docs/reference/telepathy-glib-sections.txt
@@ -2189,6 +2189,7 @@ TP_TYPE_DBUS_PROPERTIES_MIXIN_FLAGS
TpDBusPropertiesMixinIfaceInfo
TpDBusPropertiesMixinPropInfo
tp_svc_interface_set_dbus_properties_info
+tp_svc_interface_get_dbus_properties_info
<SUBSECTION>
TpDBusPropertiesMixinClass
TpDBusPropertiesMixinIfaceImpl
@@ -2201,6 +2202,7 @@ tp_dbus_properties_mixin_class_init
tp_dbus_properties_mixin_implement_interface
tp_dbus_properties_mixin_iface_init
tp_dbus_properties_mixin_get
+tp_dbus_properties_mixin_set
tp_dbus_properties_mixin_fill_properties_hash
tp_dbus_properties_mixin_make_properties_hash
tp_dbus_properties_mixin_emit_properties_changed
diff --git a/telepathy-glib/dbus-properties-mixin.c b/telepathy-glib/dbus-properties-mixin.c
index 940fa0f4..6b37fc61 100644
--- a/telepathy-glib/dbus-properties-mixin.c
+++ b/telepathy-glib/dbus-properties-mixin.c
@@ -147,6 +147,9 @@ _iface_prop_info_quark (void)
* given properties. This may only be called once per GInterface, usually from
* a section of its base_init function that only runs once.
*
+ * This is typically only used within generated code; there is normally no
+ * reason to call it manually.
+ *
* Since: 0.7.3
*/
void
@@ -190,8 +193,20 @@ tp_svc_interface_set_dbus_properties_info (GType g_interface,
g_type_set_qdata (g_interface, q, info);
}
-/* could make this public, but it doesn't seem necessary yet */
-static TpDBusPropertiesMixinIfaceInfo *
+/**
+ * tp_svc_interface_get_dbus_properties_info:
+ * @g_interface: The #GType of a service interface
+ *
+ * Retrieves the D-Bus property metadata for the given interface, if any.
+ * This function is typically not useful outside telepathy-glib itself, but may
+ * be useful for domain-specific variations on the theme of SetProperty. If in
+ * doubt, you probably don't need this function.
+ *
+ * Returns: D-Bus property metadata for @g_interface, or %NULL if it has
+ * none.
+ * Since: UNRELEASED
+ */
+TpDBusPropertiesMixinIfaceInfo *
tp_svc_interface_get_dbus_properties_info (GType g_interface)
{
return g_type_get_qdata (g_interface, _iface_prop_info_quark ());
@@ -1174,31 +1189,50 @@ out:
g_hash_table_destroy (values);
}
-static void
-_tp_dbus_properties_mixin_set (TpSvcDBusProperties *iface,
- const gchar *interface_name,
- const gchar *property_name,
- const GValue *value,
- DBusGMethodInvocation *context)
+/**
+ * tp_dbus_properties_mixin_set:
+ * @self: an object with this mixin
+ * @interface_name: a D-Bus interface name
+ * @property_name: a D-Bus property name
+ * @value: a GValue containing the new value for this property.
+ * @error: used to return an error on failure
+ *
+ * Sets a property to the value specified by @value, as if by
+ * calling the D-Bus method org.freedesktop.DBus.Properties.Set.
+ *
+ * If Set would return a D-Bus error, sets @error and returns %FALSE
+ *
+ * Returns: %TRUE on success; %FALSE (setting @error) on failure
+ * Since: UNRELEASED
+ */
+gboolean
+tp_dbus_properties_mixin_set (
+ GObject *self,
+ const gchar *interface_name,
+ const gchar *property_name,
+ const GValue *value,
+ GError **error)
{
- GObject *self = G_OBJECT (iface);
TpDBusPropertiesMixinIfaceImpl *iface_impl;
TpDBusPropertiesMixinIfaceInfo *iface_info;
TpDBusPropertiesMixinPropImpl *prop_impl;
TpDBusPropertiesMixinPropInfo *prop_info;
GValue copy = { 0 };
- GError *error = NULL;
+ gboolean ret;
+
+ g_return_val_if_fail (G_IS_OBJECT (self), FALSE);
+ g_return_val_if_fail (interface_name != NULL, FALSE);
+ g_return_val_if_fail (property_name != NULL, FALSE);
+ g_return_val_if_fail (G_IS_VALUE (value), FALSE);
iface_impl = _tp_dbus_properties_mixin_find_iface_impl (self,
interface_name);
if (iface_impl == NULL)
{
- GError e = { TP_ERRORS, TP_ERROR_NOT_IMPLEMENTED,
- "No properties known for that interface" };
-
- dbus_g_method_return_error (context, &e);
- return;
+ g_set_error (error, TP_ERRORS, TP_ERROR_NOT_IMPLEMENTED,
+ "No properties known for interface '%s'", interface_name);
+ return FALSE;
}
iface_info = iface_impl->mixin_priv;
@@ -1208,31 +1242,26 @@ _tp_dbus_properties_mixin_set (TpSvcDBusProperties *iface,
if (prop_impl == NULL)
{
- GError e = { TP_ERRORS, TP_ERROR_NOT_IMPLEMENTED,
- "Unknown property" };
-
- dbus_g_method_return_error (context, &e);
- return;
+ g_set_error (error, TP_ERRORS, TP_ERROR_NOT_IMPLEMENTED,
+ "Unknown property '%s' on interface '%s'", property_name,
+ interface_name);
+ return FALSE;
}
prop_info = prop_impl->mixin_priv;
if ((prop_info->flags & TP_DBUS_PROPERTIES_MIXIN_FLAG_WRITE) == 0)
{
- GError e = { TP_ERRORS, TP_ERROR_PERMISSION_DENIED,
- "This property is read-only" };
-
- dbus_g_method_return_error (context, &e);
- return;
+ g_set_error (error, TP_ERRORS, TP_ERROR_PERMISSION_DENIED,
+ "'%s.%s' is read-only", interface_name, property_name);
+ return FALSE;
}
if (iface_impl->setter == NULL)
{
- GError e = { TP_ERRORS, TP_ERROR_NOT_IMPLEMENTED,
- "Setting properties on this interface is unimplemented" };
-
- dbus_g_method_return_error (context, &e);
- return;
+ g_set_error (error, TP_ERRORS, TP_ERROR_NOT_IMPLEMENTED,
+ "Setting properties on '%s' is unimplemented", interface_name);
+ return FALSE;
}
if (G_VALUE_TYPE (value) != prop_info->type)
@@ -1241,14 +1270,12 @@ _tp_dbus_properties_mixin_set (TpSvcDBusProperties *iface,
if (!g_value_transform (value, &copy))
{
- error = g_error_new (TP_ERRORS, TP_ERROR_INVALID_ARGUMENT,
+ g_set_error (error, TP_ERRORS, TP_ERROR_INVALID_ARGUMENT,
"Cannot convert %s to %s for property %s",
g_type_name (G_VALUE_TYPE (value)),
g_type_name (prop_info->type),
property_name);
-
- dbus_g_method_return_error (context, error);
- g_error_free (error);
+ ret = FALSE;
goto out;
}
@@ -1256,8 +1283,28 @@ _tp_dbus_properties_mixin_set (TpSvcDBusProperties *iface,
value = &copy;
}
- if (iface_impl->setter (self, iface_info->dbus_interface,
- prop_info->name, value, prop_impl->setter_data, &error))
+ ret = iface_impl->setter (self, iface_info->dbus_interface,
+ prop_info->name, value, prop_impl->setter_data, error);
+
+out:
+ if (G_IS_VALUE (&copy))
+ g_value_unset (&copy);
+
+ return ret;
+}
+
+static void
+_tp_dbus_properties_mixin_set (TpSvcDBusProperties *iface,
+ const gchar *interface_name,
+ const gchar *property_name,
+ const GValue *value,
+ DBusGMethodInvocation *context)
+{
+ GObject *self = G_OBJECT (iface);
+ GError *error = NULL;
+
+ if (tp_dbus_properties_mixin_set (self, interface_name, property_name, value,
+ &error))
{
tp_svc_dbus_properties_return_from_set (context);
}
@@ -1266,10 +1313,6 @@ _tp_dbus_properties_mixin_set (TpSvcDBusProperties *iface,
dbus_g_method_return_error (context, error);
g_error_free (error);
}
-
-out:
- if (G_IS_VALUE (&copy))
- g_value_unset (&copy);
}
/**
diff --git a/telepathy-glib/dbus-properties-mixin.h b/telepathy-glib/dbus-properties-mixin.h
index 54f33515..b26081f3 100644
--- a/telepathy-glib/dbus-properties-mixin.h
+++ b/telepathy-glib/dbus-properties-mixin.h
@@ -56,6 +56,8 @@ typedef struct {
void tp_svc_interface_set_dbus_properties_info (GType g_interface,
TpDBusPropertiesMixinIfaceInfo *info);
+TpDBusPropertiesMixinIfaceInfo *tp_svc_interface_get_dbus_properties_info (
+ GType g_interface);
/* ---- Concrete implementation (in GObject subclasses) ------------- */
@@ -122,6 +124,12 @@ void tp_dbus_properties_mixin_iface_init (gpointer g_iface,
gboolean tp_dbus_properties_mixin_get (GObject *self,
const gchar *interface_name, const gchar *property_name,
GValue *value, GError **error);
+gboolean tp_dbus_properties_mixin_set (
+ GObject *self,
+ const gchar *interface_name,
+ const gchar *property_name,
+ const GValue *value,
+ GError **error);
GHashTable *tp_dbus_properties_mixin_make_properties_hash (
GObject *object, const gchar *first_interface,