diff options
author | Thomas Haller <thaller@redhat.com> | 2020-01-28 16:50:18 +0100 |
---|---|---|
committer | Thomas Haller <thaller@redhat.com> | 2020-02-10 19:11:50 +0100 |
commit | c7e6573eb41ef91b29fb45aff04404ab4161f21a (patch) | |
tree | 1587166623e4ded372fffba8b18af411c63a768f | |
parent | 455cec9986b240bb7aa1ae3b17f4aeccb774c7f2 (diff) | |
download | NetworkManager-c7e6573eb41ef91b29fb45aff04404ab4161f21a.tar.gz |
shared: add nm_g_variant_lookup() and nm_g_variant_lookup_value() helpers
It's often convenient to accept %NULL as dictionary argument.
-rw-r--r-- | shared/nm-glib-aux/nm-shared-utils.h | 18 |
1 files changed, 18 insertions, 0 deletions
diff --git a/shared/nm-glib-aux/nm-shared-utils.h b/shared/nm-glib-aux/nm-shared-utils.h index d1257242fa..5b56713bcd 100644 --- a/shared/nm-glib-aux/nm-shared-utils.h +++ b/shared/nm-glib-aux/nm-shared-utils.h @@ -1051,6 +1051,24 @@ nm_g_variant_unref_floating (GVariant *var) g_variant_unref (var); } +#define nm_g_variant_lookup(dictionary, ...) \ + ({ \ + GVariant *const _dictionary = (dictionary); \ + \ + ( _dictionary \ + && g_variant_lookup (_dictionary, __VA_ARGS__)); \ + }) + +static inline GVariant * +nm_g_variant_lookup_value (GVariant *dictionary, + const char *key, + const GVariantType *expected_type) +{ + return dictionary + ? g_variant_lookup_value (dictionary, key, expected_type) + : NULL; +} + static inline void nm_g_source_destroy_and_unref (GSource *source) { |