summaryrefslogtreecommitdiff
path: root/shared
diff options
context:
space:
mode:
authorThomas Haller <thaller@redhat.com>2018-07-15 07:25:36 +0200
committerThomas Haller <thaller@redhat.com>2018-08-01 14:26:36 +0200
commitccf6bdb0e2c9fa1ccac4bb1c482ca967eac9dbe9 (patch)
treedb859f1fa7005810abf79c2d4ef8a94194cf9501 /shared
parentd209966c29e00030617d1753e8361cce99cff27e (diff)
downloadNetworkManager-ccf6bdb0e2c9fa1ccac4bb1c482ca967eac9dbe9.tar.gz
shared: add nm_gobject_notify_together() helper
NM_GOBJECT_PROPERTIES_DEFINE() defines a helper function _notify() to emit a GObject property changed notification. Add another helper function to emit multiple notifications together, and freeze/thaw the notification before. This is particularly useful, because our D-Bus glue in "nm-dbus-object.c" hooks into dispatch_properties_changed(), to emit a combined PropertiesChanged signal for multiple properties. By carefully freezing/thawing the notifications, the exported objects can combine changes of multiple properties in one D-Bus signal. This helper is here to make that simpler. Note that the compiler still has no problem to inline _notify() entirey. So, in a non-debug build, there is little difference in the generated code. It can even nicely inline calls like nm_gobject_notify_together (self, PROP_ADDRESS_DATA, PROP_ADDRESSES);
Diffstat (limited to 'shared')
-rw-r--r--shared/nm-utils/nm-macros-internal.h32
1 files changed, 28 insertions, 4 deletions
diff --git a/shared/nm-utils/nm-macros-internal.h b/shared/nm-utils/nm-macros-internal.h
index 2ff95a288e..4879e33d04 100644
--- a/shared/nm-utils/nm-macros-internal.h
+++ b/shared/nm-utils/nm-macros-internal.h
@@ -933,12 +933,36 @@ static GParamSpec *obj_properties[_PROPERTY_ENUMS_LAST] = { NULL, }
#define NM_GOBJECT_PROPERTIES_DEFINE(obj_type, ...) \
NM_GOBJECT_PROPERTIES_DEFINE_BASE (__VA_ARGS__); \
static inline void \
-_notify (obj_type *obj, _PropertyEnums prop) \
+_nm_gobject_notify_together_impl (obj_type *obj, guint n, const _PropertyEnums *props) \
{ \
+ const gboolean freeze_thaw = (n > 1); \
+ \
nm_assert (G_IS_OBJECT (obj)); \
- nm_assert ((gsize) prop < G_N_ELEMENTS (obj_properties)); \
- g_object_notify_by_pspec ((GObject *) obj, obj_properties[prop]); \
-}
+ nm_assert (n > 0); \
+ \
+ if (freeze_thaw) \
+ g_object_freeze_notify ((GObject *) obj); \
+ while (n-- > 0) { \
+ const _PropertyEnums prop = *props++; \
+ \
+ nm_assert ((gsize) prop < G_N_ELEMENTS (obj_properties)); \
+ g_object_notify_by_pspec ((GObject *) obj, obj_properties[prop]); \
+ } \
+ if (freeze_thaw) \
+ g_object_thaw_notify ((GObject *) obj); \
+} \
+\
+static inline void \
+_notify (obj_type *obj, _PropertyEnums prop) \
+{ \
+ _nm_gobject_notify_together_impl (obj, 1, &prop); \
+} \
+
+/* invokes _notify() for all arguments (of type _PropertyEnums). Note, that if
+ * there are more than one prop arguments, this will involve a freeze/thaw
+ * of GObject property notifications. */
+#define nm_gobject_notify_together(obj, ...) \
+ _nm_gobject_notify_together_impl (obj, NM_NARG (__VA_ARGS__), (const _PropertyEnums[]) { __VA_ARGS__ })
/*****************************************************************************/