[network-manager-applet: 12/15] editor: convert firewall zones retrieval to GDBus
- From: Dan Williams <dcbw src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [network-manager-applet: 12/15] editor: convert firewall zones retrieval to GDBus
- Date: Wed, 25 Feb 2015 19:13:00 +0000 (UTC)
commit 43f0b5a4249a85e20b6fc4d3176d789cfe929b77
Author: Dan Williams <dcbw redhat com>
Date: Wed Feb 18 15:36:32 2015 -0600
editor: convert firewall zones retrieval to GDBus
src/connection-editor/page-general.c | 99 ++++++++++++++++++++++------------
1 files changed, 65 insertions(+), 34 deletions(-)
---
diff --git a/src/connection-editor/page-general.c b/src/connection-editor/page-general.c
index 9e62505..9924620 100644
--- a/src/connection-editor/page-general.c
+++ b/src/connection-editor/page-general.c
@@ -22,7 +22,6 @@
#include <gtk/gtk.h>
#include <glib/gi18n.h>
-#include <dbus/dbus-glib.h>
#include "page-general.h"
#include "nm-glib-compat.h"
@@ -36,6 +35,8 @@ typedef struct {
gboolean is_vpn;
+ GDBusProxy *fw_proxy;
+ GCancellable *cancellable;
GtkComboBoxText *firewall_zone;
char **zones;
gboolean got_zones;
@@ -64,54 +65,69 @@ enum {
static void populate_firewall_zones_ui (CEPageGeneral *self);
static void
-zones_reply (DBusGProxy *proxy, DBusGProxyCall *call, gpointer user_data)
+get_zones_cb (GDBusProxy *proxy, GAsyncResult *result, gpointer user_data)
{
- CEPageGeneral *self = user_data;
- CEPageGeneralPrivate *priv = CE_PAGE_GENERAL_GET_PRIVATE (self);
+ CEPageGeneral *self;
+ CEPageGeneralPrivate *priv;
+ GVariant *variant = NULL;
GError *error = NULL;
- if (!dbus_g_proxy_end_call (proxy, call, &error,
- G_TYPE_STRV, &priv->zones,
- G_TYPE_INVALID)) {
- g_warning ("Failed to get zones from FirewallD: (%d) %s", error->code, error->message);
+ variant = g_dbus_proxy_call_finish (proxy, result, &error);
+ if (g_error_matches (error, G_IO_ERROR, G_IO_ERROR_CANCELLED)) {
+ g_clear_error (&error);
+ return;
}
- priv->got_zones = TRUE;
+ self = CE_PAGE_GENERAL (user_data);
+ priv = CE_PAGE_GENERAL_GET_PRIVATE (self);
+ if (variant) {
+ if (g_variant_is_of_type (variant, G_VARIANT_TYPE ("(as)")))
+ g_variant_get (variant, "(^as)", &priv->zones);
+ else {
+ g_warning ("Failed to get zones from FirewallD: invalid reply type '%s'",
+ g_variant_get_type_string (variant));
+ }
+ } else if (!g_error_matches (error, G_DBUS_ERROR, G_DBUS_ERROR_SERVICE_UNKNOWN))
+ g_warning ("Failed to get zones from FirewallD: %s", error->message);
+
+ priv->got_zones = TRUE;
if (priv->setup_finished)
populate_firewall_zones_ui (self);
g_clear_error (&error);
- g_object_unref (proxy);
+ g_variant_unref (variant);
+ g_clear_object (&priv->cancellable);
+ g_clear_object (&priv->fw_proxy);
}
-/* Get FirewallD zones */
static void
-get_zones_from_firewall (CEPageGeneral *self)
+on_fw_proxy_acquired (GObject *object, GAsyncResult *result, gpointer user_data)
{
- CEPageGeneralPrivate *priv = CE_PAGE_GENERAL_GET_PRIVATE (self);
- DBusGConnection *bus;
- DBusGProxy *proxy;
+ CEPageGeneral *self;
+ CEPageGeneralPrivate *priv;
+ GError *error = NULL;
+ GDBusProxy *proxy;
- /* Initialize got_zones to TRUE for cases there's no FirewallD */
- priv->got_zones = TRUE;
+ proxy = g_dbus_proxy_new_for_bus_finish (result, &error);
+ if (!proxy) {
+ g_warning ("Failed to get FirewallD proxy: %s", error->message);
+ g_clear_error (&error);
+ return;
+ }
- bus = dbus_g_bus_get (DBUS_BUS_SYSTEM, NULL);
- if (bus) {
- proxy = dbus_g_proxy_new_for_name (bus,
- "org.fedoraproject.FirewallD1",
- "/org/fedoraproject/FirewallD1",
- "org.fedoraproject.FirewallD1.zone");
- /* Call getZones to get list of available FirewallD zones */
- if (proxy) {
- dbus_g_proxy_begin_call (proxy, "getZones",
- zones_reply, self, NULL,
- G_TYPE_INVALID);
- priv->got_zones = FALSE;
- }
+ self = CE_PAGE_GENERAL (user_data);
+ priv = CE_PAGE_GENERAL_GET_PRIVATE (self);
- dbus_g_connection_unref (bus);
- }
+ priv->fw_proxy = proxy;
+ g_dbus_proxy_call (priv->fw_proxy,
+ "getZones",
+ NULL,
+ G_DBUS_CALL_FLAGS_NONE,
+ -1,
+ priv->cancellable,
+ (GAsyncReadyCallback) get_zones_cb,
+ self);
}
static void
@@ -132,7 +148,16 @@ general_private_init (CEPageGeneral *self)
gtk_widget_show_all (GTK_WIDGET (priv->firewall_zone));
/* Get zones from FirewallD */
- get_zones_from_firewall (self);
+ priv->cancellable = g_cancellable_new ();
+ g_dbus_proxy_new_for_bus (G_BUS_TYPE_SYSTEM,
+ G_DBUS_PROXY_FLAGS_NONE,
+ NULL,
+ "org.fedoraproject.FirewallD1",
+ "/org/fedoraproject/FirewallD1",
+ "org.fedoraproject.FirewallD1.zone",
+ priv->cancellable,
+ (GAsyncReadyCallback) on_fw_proxy_acquired,
+ self);
/* Set mnemonic widget for device Firewall zone label */
label = GTK_LABEL (gtk_builder_get_object (builder, "firewall_zone_label"));
@@ -152,6 +177,12 @@ dispose (GObject *object)
{
CEPageGeneralPrivate *priv = CE_PAGE_GENERAL_GET_PRIVATE (object);
+ if (priv->cancellable) {
+ g_cancellable_cancel (priv->cancellable);
+ g_clear_object (&priv->cancellable);
+ }
+ g_clear_object (&priv->fw_proxy);
+
g_clear_pointer (&priv->zones, g_strfreev);
G_OBJECT_CLASS (ce_page_general_parent_class)->dispose (object);
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]