summaryrefslogtreecommitdiff
path: root/libnm-core
diff options
context:
space:
mode:
authorThomas Haller <thaller@redhat.com>2018-10-11 10:54:12 +0200
committerThomas Haller <thaller@redhat.com>2018-10-17 13:03:50 +0200
commitc5c7dc59c5baff6afaee43ed95baec7f7ccf1d40 (patch)
treec791f25e051918bad77cf5e1247d395b1f76910c /libnm-core
parent09719bc479b63c8e5fef3950e980b263aca7eff5 (diff)
libnm-core: expose internal _nm_dbus_typecheck_response() helper
Diffstat (limited to 'libnm-core')
-rw-r--r--libnm-core/nm-core-internal.h9
-rw-r--r--libnm-core/nm-dbus-utils.c89
2 files changed, 72 insertions, 26 deletions
diff --git a/libnm-core/nm-core-internal.h b/libnm-core/nm-core-internal.h
index 8b36bbd27..22c85cd76 100644
--- a/libnm-core/nm-core-internal.h
+++ b/libnm-core/nm-core-internal.h
@@ -305,6 +305,10 @@ void _nm_dbus_errors_init (void);
extern gboolean _nm_utils_is_manager_process;
+gboolean _nm_dbus_typecheck_response (GVariant *response,
+ const GVariantType *reply_type,
+ GError **error);
+
gulong _nm_dbus_signal_connect_data (GDBusProxy *proxy,
const char *signal_name,
const GVariantType *signature,
@@ -329,6 +333,11 @@ GVariant *_nm_dbus_proxy_call_sync (GDBusProxy *proxy,
GCancellable *cancellable,
GError **error);
+GVariant * _nm_dbus_connection_call_finish (GDBusConnection *dbus_connection,
+ GAsyncResult *result,
+ const GVariantType *reply_type,
+ GError **error);
+
gboolean _nm_dbus_error_has_name (GError *error,
const char *dbus_error_name);
diff --git a/libnm-core/nm-dbus-utils.c b/libnm-core/nm-dbus-utils.c
index 25af7c996..69f4bb2f8 100644
--- a/libnm-core/nm-dbus-utils.c
+++ b/libnm-core/nm-dbus-utils.c
@@ -174,23 +174,35 @@ _nm_dbus_signal_connect_data (GDBusProxy *proxy,
* Returns: the signal handler ID, as with _nm_signal_connect_data().
*/
-static void
-typecheck_response (GVariant **response,
- const GVariantType *reply_type,
- GError **error)
+/**
+ * _nm_dbus_typecheck_response:
+ * @response: the #GVariant response to check.
+ * @reply_type: the expected reply type. It may be %NULL to perform no
+ * checking.
+ * @error: (allow-none): the error in case the @reply_type does not match.
+ *
+ * Returns: %TRUE, if @response is of the expected @reply_type.
+ */
+gboolean
+_nm_dbus_typecheck_response (GVariant *response,
+ const GVariantType *reply_type,
+ GError **error)
{
- if ( *response
- && reply_type
- && !g_variant_is_of_type (*response, reply_type)) {
- /* This is the same error code that g_dbus_connection_call() returns if
- * @reply_type doesn't match.
- */
- g_set_error (error, G_IO_ERROR, G_IO_ERROR_INVALID_ARGUMENT,
- _("Method returned type '%s', but expected '%s'"),
- g_variant_get_type_string (*response),
- g_variant_type_peek_string (reply_type));
- g_clear_pointer (response, g_variant_unref);
- }
+ g_return_val_if_fail (response, FALSE);
+
+ if (!reply_type)
+ return TRUE;
+ if (g_variant_is_of_type (response, reply_type))
+ return TRUE;
+
+ /* This is the same error code that g_dbus_connection_call() returns if
+ * @reply_type doesn't match.
+ */
+ g_set_error (error, G_IO_ERROR, G_IO_ERROR_INVALID_ARGUMENT,
+ _("Method returned type '%s', but expected '%s'"),
+ g_variant_get_type_string (response),
+ g_variant_type_peek_string (reply_type));
+ return FALSE;
}
/**
@@ -215,11 +227,15 @@ _nm_dbus_proxy_call_finish (GDBusProxy *proxy,
const GVariantType *reply_type,
GError **error)
{
- GVariant *ret;
+ GVariant *variant;
- ret = g_dbus_proxy_call_finish (proxy, res, error);
- typecheck_response (&ret, reply_type, error);
- return ret;
+ variant = g_dbus_proxy_call_finish (proxy,
+ res,
+ error);
+ if ( variant
+ && !_nm_dbus_typecheck_response (variant, reply_type, error))
+ nm_clear_pointer (&variant, g_variant_unref);
+ return variant;
}
/**
@@ -253,13 +269,34 @@ _nm_dbus_proxy_call_sync (GDBusProxy *proxy,
GCancellable *cancellable,
GError **error)
{
- GVariant *ret;
+ GVariant *variant;
+
+ variant = g_dbus_proxy_call_sync (proxy,
+ method_name,
+ parameters,
+ flags,
+ timeout_msec,
+ cancellable,
+ error);
+ if ( variant
+ && !_nm_dbus_typecheck_response (variant, reply_type, error))
+ nm_clear_pointer (&variant, g_variant_unref);
+ return variant;
+}
+
+GVariant *
+_nm_dbus_connection_call_finish (GDBusConnection *dbus_connection,
+ GAsyncResult *result,
+ const GVariantType *reply_type,
+ GError **error)
+{
+ GVariant *variant;
- ret = g_dbus_proxy_call_sync (proxy, method_name, parameters,
- flags, timeout_msec,
- cancellable, error);
- typecheck_response (&ret, reply_type, error);
- return ret;
+ variant = g_dbus_connection_call_finish (dbus_connection, result, error);
+ if ( variant
+ && !_nm_dbus_typecheck_response (variant, reply_type, error))
+ nm_clear_pointer (&variant, g_variant_unref);
+ return variant;
}
/**