macros: add nm_clear_g_cancellable() utility

This commit is contained in:
Thomas Haller 2015-10-30 11:52:06 +01:00
parent 88a2f1c93b
commit 204fcd33d8
4 changed files with 18 additions and 10 deletions

View file

@ -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).

View file

@ -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

View file

@ -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);

View file

@ -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);
}