From 204fcd33d85f374e5992f3a3bf069958c178fc0b Mon Sep 17 00:00:00 2001 From: Thomas Haller Date: Fri, 30 Oct 2015 11:52:06 +0100 Subject: [PATCH] macros: add nm_clear_g_cancellable() utility --- include/nm-macros-internal.h | 12 ++++++++++++ libnm-core/nm-core-internal.h | 6 ------ libnm/nm-manager.c | 5 +++-- libnm/nm-remote-settings.c | 5 +++-- 4 files changed, 18 insertions(+), 10 deletions(-) diff --git a/include/nm-macros-internal.h b/include/nm-macros-internal.h index 5c1d61dbaf..23918d7c84 100644 --- a/include/nm-macros-internal.h +++ b/include/nm-macros-internal.h @@ -229,6 +229,18 @@ nm_clear_g_variant (GVariant **variant) return FALSE; } +static inline gboolean +nm_clear_g_cancellable (GCancellable **cancellable) +{ + if (cancellable && *cancellable) { + g_cancellable_cancel (*cancellable); + g_object_unref (*cancellable); + *cancellable = NULL; + return TRUE; + } + return FALSE; +} + /*****************************************************************************/ /* Determine whether @x is a power of two (@x being an integer type). diff --git a/libnm-core/nm-core-internal.h b/libnm-core/nm-core-internal.h index 26c30b8a87..09e42d2c05 100644 --- a/libnm-core/nm-core-internal.h +++ b/libnm-core/nm-core-internal.h @@ -68,12 +68,6 @@ #include "nm-utils.h" #include "nm-vpn-dbus-interface.h" -#define NM_UTILS_CLEAR_CANCELLABLE(c) \ - if (c) { \ - g_cancellable_cancel (c); \ - g_clear_object (&c); \ - } - /* NM_SETTING_COMPARE_FLAG_INFERRABLE: check whether a device-generated * connection can be replaced by a already-defined connection. This flag only * takes into account properties marked with the %NM_SETTING_PARAM_INFERRABLE diff --git a/libnm/nm-manager.c b/libnm/nm-manager.c index c0d026291a..7ed50e3ced 100644 --- a/libnm/nm-manager.c +++ b/libnm/nm-manager.c @@ -35,6 +35,7 @@ #include "nm-vpn-connection.h" #include "nm-object-cache.h" #include "nm-dbus-helpers.h" +#include "nm-macros-internal.h" #include "nmdbus-manager.h" @@ -1255,7 +1256,7 @@ nm_running_changed_cb (GObject *object, NMManagerPrivate *priv = NM_MANAGER_GET_PRIVATE (manager); if (!nm_manager_get_nm_running (manager)) { - NM_UTILS_CLEAR_CANCELLABLE (priv->props_cancellable); + nm_clear_g_cancellable (&priv->props_cancellable); priv->state = NM_STATE_UNKNOWN; priv->startup = FALSE; @@ -1281,7 +1282,7 @@ nm_running_changed_cb (GObject *object, } else { _nm_object_suppress_property_updates (NM_OBJECT (manager), FALSE); - NM_UTILS_CLEAR_CANCELLABLE (priv->props_cancellable); + nm_clear_g_cancellable (&priv->props_cancellable); priv->props_cancellable = g_cancellable_new (); _nm_object_reload_properties_async (NM_OBJECT (manager), priv->props_cancellable, updated_properties, manager); diff --git a/libnm/nm-remote-settings.c b/libnm/nm-remote-settings.c index 4d240e3b38..480d7c19f5 100644 --- a/libnm/nm-remote-settings.c +++ b/libnm/nm-remote-settings.c @@ -34,6 +34,7 @@ #include "nm-dbus-helpers.h" #include "nm-object-private.h" #include "nm-core-internal.h" +#include "nm-macros-internal.h" #include "nmdbus-settings.h" @@ -626,7 +627,7 @@ nm_running_changed (GObject *object, GPtrArray *connections; int i; - NM_UTILS_CLEAR_CANCELLABLE (priv->props_cancellable); + nm_clear_g_cancellable (&priv->props_cancellable); /* Clear connections */ connections = priv->all_connections; @@ -651,7 +652,7 @@ nm_running_changed (GObject *object, } else { _nm_object_suppress_property_updates (NM_OBJECT (self), FALSE); - NM_UTILS_CLEAR_CANCELLABLE (priv->props_cancellable); + nm_clear_g_cancellable (&priv->props_cancellable); priv->props_cancellable = g_cancellable_new (); _nm_object_reload_properties_async (NM_OBJECT (self), priv->props_cancellable, updated_properties, self); }