[next] telepathy-glib: tp_proxy_check_interface_by_id: factor out
Simon McVittie
smcv at kemper.freedesktop.org
Tue Mar 18 05:45:05 PDT 2014
Module: telepathy-glib
Branch: next
Commit: 42d5a76ea6cf48ebf2ed406d5b4805ae3b00a855
URL: http://cgit.freedesktop.org/telepathy/telepathy-glib/commit/?id=42d5a76ea6cf48ebf2ed406d5b4805ae3b00a855
Author: Simon McVittie <simon.mcvittie at collabora.co.uk>
Date: Thu Mar 13 14:49:05 2014 +0000
tp_proxy_check_interface_by_id: factor out
My updated code-generation for GDBus doesn't actually need the
GDBusProxy at all, so it's nicer to have a function in the core
library that raises the GError but doesn't create the object.
---
.../telepathy-glib/telepathy-glib-sections.txt | 1 +
telepathy-glib/core-proxy.c | 10 ++++
telepathy-glib/proxy-internal.h | 8 +++
telepathy-glib/proxy.c | 62 +++++++++++++++-----
telepathy-glib/proxy.h | 2 +
5 files changed, 67 insertions(+), 16 deletions(-)
diff --git a/docs/reference/telepathy-glib/telepathy-glib-sections.txt b/docs/reference/telepathy-glib/telepathy-glib-sections.txt
index 02c8791..755a7eb 100644
--- a/docs/reference/telepathy-glib/telepathy-glib-sections.txt
+++ b/docs/reference/telepathy-glib/telepathy-glib-sections.txt
@@ -3005,6 +3005,7 @@ tp_cli_generic_add_signals
tp_proxy_add_interface_by_id
tp_proxy_add_interfaces
tp_proxy_get_interface_by_id
+tp_proxy_check_interface_by_id
tp_proxy_invalidate
TpProxyInterfaceAddedCb
tp_proxy_or_subclass_hook_on_interface_add
diff --git a/telepathy-glib/core-proxy.c b/telepathy-glib/core-proxy.c
index 59c121a..78147f0 100644
--- a/telepathy-glib/core-proxy.c
+++ b/telepathy-glib/core-proxy.c
@@ -83,6 +83,15 @@ tp_proxy_get_interface_by_id (TpProxy *proxy,
return _tp_proxy_implementation.get_interface_by_id (proxy, iface, error);
}
+gboolean
+tp_proxy_check_interface_by_id (gpointer proxy,
+ GQuark iface,
+ GError **error)
+{
+ g_assert (_tp_proxy_implementation.version != NULL);
+ return _tp_proxy_implementation.check_interface_by_id (proxy, iface, error);
+}
+
TpProxyPendingCall *
tp_proxy_pending_call_v0_new (TpProxy *proxy,
GQuark iface,
@@ -161,6 +170,7 @@ tp_private_proxy_set_implementation (TpProxyImplementation *impl)
g_assert (_tp_proxy_implementation.version == NULL);
g_assert (impl->get_interface_by_id != NULL);
+ g_assert (impl->check_interface_by_id != NULL);
g_assert (impl->pending_call_new != NULL);
g_assert (impl->pending_call_take_pending_call != NULL);
g_assert (impl->pending_call_take_results != NULL);
diff --git a/telepathy-glib/proxy-internal.h b/telepathy-glib/proxy-internal.h
index e82d52a..c70ca82 100644
--- a/telepathy-glib/proxy-internal.h
+++ b/telepathy-glib/proxy-internal.h
@@ -32,6 +32,10 @@ typedef struct {
GQuark,
GError **);
+ gboolean (*check_interface_by_id) (TpProxy *,
+ GQuark,
+ GError **);
+
TpProxyPendingCall *(*pending_call_new) (TpProxy *,
GQuark,
const gchar *,
@@ -70,6 +74,10 @@ DBusGProxy *_tp_proxy_get_interface_by_id (TpProxy *self,
GQuark iface,
GError **error);
+gboolean _tp_proxy_check_interface_by_id (TpProxy *self,
+ GQuark iface,
+ GError **error);
+
TpProxyPendingCall *_tp_proxy_pending_call_new (TpProxy *self,
GQuark iface,
const gchar *member,
diff --git a/telepathy-glib/proxy.c b/telepathy-glib/proxy.c
index ed57d80..02c14c8 100644
--- a/telepathy-glib/proxy.c
+++ b/telepathy-glib/proxy.c
@@ -438,16 +438,8 @@ _tp_proxy_get_interface_by_id (TpProxy *self,
g_return_val_if_fail (TP_IS_PROXY (self), NULL);
- if (self->priv->invalidated != NULL)
- {
- g_set_error (error, self->priv->invalidated->domain, self->priv->invalidated->code,
- "%s", self->priv->invalidated->message);
- return NULL;
- }
-
- if (!tp_dbus_check_valid_interface_name (g_quark_to_string (iface),
- error))
- return NULL;
+ if (!_tp_proxy_check_interface_by_id (self, iface, error))
+ return NULL;
dgproxy = g_datalist_id_get_data (&self->priv->interfaces, iface);
@@ -471,16 +463,53 @@ _tp_proxy_get_interface_by_id (TpProxy *self,
(guint) iface, dgproxy);
}
- if (dgproxy != NULL)
+ return dgproxy;
+}
+
+/**
+ * tp_proxy_check_interface_by_id:
+ * @self: the #TpProxy (or subclass)
+ * @iface: quark representing the D-Bus interface required
+ * @error: used to raise an error in the #TP_DBUS_ERRORS domain if @iface
+ * is invalid, @self has been invalidated or @self does not implement
+ * @iface
+ *
+ * Return whether this proxy is known to have a particular interface, by its
+ * quark ID.
+ *
+ * Returns: %TRUE if this proxy implements the given interface.
+ */
+
+/* The implementation in the core library calls this: */
+
+gboolean
+_tp_proxy_check_interface_by_id (TpProxy *self,
+ GQuark iface,
+ GError **error)
+{
+ g_return_val_if_fail (TP_IS_PROXY (self), FALSE);
+
+ if (self->priv->invalidated != NULL)
{
- return dgproxy;
+ g_set_error (error, self->priv->invalidated->domain,
+ self->priv->invalidated->code,
+ "%s", self->priv->invalidated->message);
+ return FALSE;
}
- g_set_error (error, TP_DBUS_ERRORS, TP_DBUS_ERROR_NO_INTERFACE,
- "Object %s does not have interface %s",
- self->priv->object_path, g_quark_to_string (iface));
+ if (!tp_dbus_check_valid_interface_name (g_quark_to_string (iface),
+ error))
+ return FALSE;
- return NULL;
+ if (g_datalist_id_get_data (&self->priv->interfaces, iface) == NULL)
+ {
+ g_set_error (error, TP_DBUS_ERRORS, TP_DBUS_ERROR_NO_INTERFACE,
+ "Object %s does not have interface %s",
+ self->priv->object_path, g_quark_to_string (iface));
+ return FALSE;
+ }
+
+ return TRUE;
}
/**
@@ -1525,6 +1554,7 @@ tp_proxy_once (gpointer data G_GNUC_UNUSED)
VERSION,
sizeof (TpProxyImplementation),
_tp_proxy_get_interface_by_id,
+ _tp_proxy_check_interface_by_id,
_tp_proxy_pending_call_new,
_tp_proxy_pending_call_take_pending_call,
_tp_proxy_pending_call_take_results,
diff --git a/telepathy-glib/proxy.h b/telepathy-glib/proxy.h
index 814061f..085de34 100644
--- a/telepathy-glib/proxy.h
+++ b/telepathy-glib/proxy.h
@@ -151,6 +151,8 @@ GType tp_proxy_get_type (void);
TpProxyClass))
gboolean tp_proxy_has_interface_by_id (gpointer self, GQuark iface);
+gboolean tp_proxy_check_interface_by_id (gpointer self, GQuark iface,
+ GError **error);
gboolean tp_proxy_has_interface (gpointer self, const gchar *iface);
_TP_AVAILABLE_IN_0_16
More information about the telepathy-commits
mailing list