From ab0e3a223d3aa6291eb71ecbbe74820ed58a2001 Mon Sep 17 00:00:00 2001 From: Thomas Haller Date: Tue, 11 Aug 2015 12:49:38 +0200 Subject: [PATCH] core/utils: add NM_UTILS_KEEP_ALIVE() utility --- src/NetworkManagerUtils.h | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/src/NetworkManagerUtils.h b/src/NetworkManagerUtils.h index f79006f60..df4b35b14 100644 --- a/src/NetworkManagerUtils.h +++ b/src/NetworkManagerUtils.h @@ -76,6 +76,17 @@ GETTER (void) \ return singleton_instance; \ } +/* attach @instance to the data or @owner. @owner owns a reference + * to @instance thus the lifetime of @instance is at least as long + * as that of @owner. Use this when @owner depends on @instance. */ +#define NM_UTILS_KEEP_ALIVE(owner, instance, unique_token) \ + G_STMT_START { \ + g_object_set_data_full (G_OBJECT (owner), \ + ".nm-utils-keep-alive-" unique_token "", \ + g_object_ref (instance), \ + g_object_unref); \ + } G_STMT_END + /*****************************************************************************/ gboolean nm_ethernet_address_is_valid (gconstpointer addr, gssize len);