summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorThomas Haller <thaller@redhat.com>2017-06-29 13:13:54 +0200
committerThomas Haller <thaller@redhat.com>2017-07-05 18:37:39 +0200
commitc5af191dbfaeee5c8508549a7bcdedff30a2ff13 (patch)
treedee3a0d13d95beb9e6847fc27581c6bd7ad10da1
parente160928b9ed3ca00e81bb0a6e24d8f1f7d088bc5 (diff)
downloadNetworkManager-c5af191dbfaeee5c8508549a7bcdedff30a2ff13.tar.gz
platform: expose emit-signal function from platform
It will be used by NMFakePlatform too.
-rw-r--r--src/platform/nm-linux-platform.c88
-rw-r--r--src/platform/nm-platform-private.h13
-rw-r--r--src/platform/nm-platform.c68
3 files changed, 87 insertions, 82 deletions
diff --git a/src/platform/nm-linux-platform.c b/src/platform/nm-linux-platform.c
index 135d325cce..4a7531fd9d 100644
--- a/src/platform/nm-linux-platform.c
+++ b/src/platform/nm-linux-platform.c
@@ -262,7 +262,6 @@ static void cache_on_change (NMPlatform *platform,
const NMPObject *obj_new);
static void cache_prune_all (NMPlatform *platform);
static gboolean event_handler_read_netlink (NMPlatform *platform, gboolean wait_for_acks);
-static void ASSERT_NETNS_CURRENT (NMPlatform *platform);
/*****************************************************************************/
@@ -632,7 +631,7 @@ _linktype_get_type (NMPlatform *platform,
{
guint i;
- ASSERT_NETNS_CURRENT (platform);
+ NMTST_ASSERT_PLATFORM_NETNS_CURRENT (platform);
nm_assert (ifname);
if (completed_from_cache) {
@@ -2638,13 +2637,6 @@ nm_linux_platform_setup (void)
nm_platform_setup (nm_linux_platform_new (FALSE, FALSE));
}
-static void
-ASSERT_NETNS_CURRENT (NMPlatform *platform)
-{
- nm_assert (NM_IS_LINUX_PLATFORM (platform));
- nm_assert (NM_IN_SET (nm_platform_netns_get (platform), NULL, nmp_netns_get_current ()));
-}
-
/*****************************************************************************/
#define ASSERT_SYSCTL_ARGS(pathid, dirfd, path) \
@@ -2923,74 +2915,6 @@ process_events (NMPlatform *platform)
/*****************************************************************************/
-static void
-do_emit_signal (NMPlatform *platform,
- NMPCacheOpsType cache_op,
- const NMPObject *obj_old,
- const NMPObject *obj_new)
-{
- gboolean visible_new;
- gboolean visible_old;
- const NMPObject *o;
- const NMPClass *klass;
-
- nm_assert (NM_IN_SET ((NMPlatformSignalChangeType) cache_op, (NMPlatformSignalChangeType) NMP_CACHE_OPS_UNCHANGED, NM_PLATFORM_SIGNAL_ADDED, NM_PLATFORM_SIGNAL_CHANGED, NM_PLATFORM_SIGNAL_REMOVED));
-
- ASSERT_nmp_cache_ops (nm_platform_get_cache (platform), cache_op, obj_old, obj_new);
-
- ASSERT_NETNS_CURRENT (platform);
-
- switch (cache_op) {
- case NMP_CACHE_OPS_ADDED:
- if (!nmp_object_is_visible (obj_new))
- return;
- o = obj_new;
- break;
- case NMP_CACHE_OPS_UPDATED:
- visible_old = nmp_object_is_visible (obj_old);
- visible_new = nmp_object_is_visible (obj_new);
- if (!visible_old && visible_new) {
- o = obj_new;
- cache_op = NMP_CACHE_OPS_ADDED;
- } else if (visible_old && !visible_new) {
- o = obj_old;
- cache_op = NMP_CACHE_OPS_REMOVED;
- } else if (!visible_new) {
- /* it was invisible and stayed invisible. Nothing to do. */
- return;
- } else
- o = obj_new;
- break;
- case NMP_CACHE_OPS_REMOVED:
- if (!nmp_object_is_visible (obj_old))
- return;
- o = obj_old;
- break;
- default:
- nm_assert (cache_op == NMP_CACHE_OPS_UNCHANGED);
- return;
- }
-
- klass = NMP_OBJECT_GET_CLASS (o);
-
- _LOGt ("emit signal %s %s: %s",
- klass->signal_type,
- nm_platform_signal_change_type_to_string ((NMPlatformSignalChangeType) cache_op),
- nmp_object_to_string (o, NMP_OBJECT_TO_STRING_PUBLIC, NULL, 0));
-
- nmp_object_ref (o);
- g_signal_emit (platform,
- _nm_platform_signal_id_get (klass->signal_type_id),
- 0,
- (int) klass->obj_type,
- o->object.ifindex,
- &o->object,
- (int) cache_op);
- nmp_object_unref (o);
-}
-
-/*****************************************************************************/
-
_NM_UTILS_LOOKUP_DEFINE (static, delayed_action_refresh_from_object_type, NMPObjectType, DelayedActionType,
NM_UTILS_LOOKUP_DEFAULT_NM_ASSERT (DELAYED_ACTION_TYPE_NONE),
NM_UTILS_LOOKUP_ITEM (NMP_OBJECT_TYPE_LINK, DELAYED_ACTION_TYPE_REFRESH_ALL_LINKS),
@@ -3169,7 +3093,7 @@ delayed_action_handle_MASTER_CONNECTED (NMPlatform *platform, int master_ifindex
if (cache_op == NMP_CACHE_OPS_UNCHANGED)
return;
cache_on_change (platform, cache_op, obj_old, obj_new);
- do_emit_signal (platform, cache_op, obj_old, obj_new);
+ nm_platform_cache_update_emit_signal (platform, cache_op, obj_old, obj_new);
}
static void
@@ -3376,7 +3300,7 @@ cache_prune_one_type (NMPlatform *platform, NMPObjectType obj_type)
cache_op = nmp_cache_remove (cache, obj, TRUE, &obj_old);
nm_assert (cache_op == NMP_CACHE_OPS_REMOVED);
cache_on_change (platform, cache_op, obj_old, NULL);
- do_emit_signal (platform, cache_op, obj_old, NULL);
+ nm_platform_cache_update_emit_signal (platform, cache_op, obj_old, NULL);
}
}
}
@@ -3914,7 +3838,7 @@ event_valid_msg (NMPlatform *platform, struct nl_msg *msg, gboolean handle_event
cache_op = nmp_cache_update_netlink (cache, obj, &obj_old, &obj_new);
cache_on_change (platform, cache_op, obj_old, obj_new);
cache_post (platform, msghdr, cache_op, obj, obj_old, obj_new);
- do_emit_signal (platform, cache_op, obj_old, obj_new);
+ nm_platform_cache_update_emit_signal (platform, cache_op, obj_old, obj_new);
break;
case RTM_DELLINK:
@@ -3923,7 +3847,7 @@ event_valid_msg (NMPlatform *platform, struct nl_msg *msg, gboolean handle_event
cache_op = nmp_cache_remove_netlink (cache, obj, &obj_old, &obj_new);
if (cache_op != NMP_CACHE_OPS_UNCHANGED) {
cache_on_change (platform, cache_op, obj_old, obj_new);
- do_emit_signal (platform, cache_op, obj_old, obj_new);
+ nm_platform_cache_update_emit_signal (platform, cache_op, obj_old, obj_new);
}
break;
@@ -6606,7 +6530,7 @@ cache_update_link_udev (NMPlatform *platform,
cache_on_change (platform, cache_op, obj_old, obj_new);
if (!nm_platform_netns_push (platform, &netns))
return;
- do_emit_signal (platform, cache_op, obj_old, obj_new);
+ nm_platform_cache_update_emit_signal (platform, cache_op, obj_old, obj_new);
}
}
diff --git a/src/platform/nm-platform-private.h b/src/platform/nm-platform-private.h
index 10799f36bd..b6c94baaf7 100644
--- a/src/platform/nm-platform-private.h
+++ b/src/platform/nm-platform-private.h
@@ -26,4 +26,17 @@
NMPCache *nm_platform_get_cache (NMPlatform *self);
+#define NMTST_ASSERT_PLATFORM_NETNS_CURRENT(platform) \
+ G_STMT_START { \
+ NMPlatform *_platform = (platform); \
+ \
+ nm_assert (NM_IS_PLATFORM (_platform)); \
+ nm_assert (NM_IN_SET (nm_platform_netns_get (_platform), NULL, nmp_netns_get_current ())); \
+ } G_STMT_END
+
+void nm_platform_cache_update_emit_signal (NMPlatform *platform,
+ NMPCacheOpsType cache_op,
+ const NMPObject *obj_old,
+ const NMPObject *obj_new);
+
#endif /* __NM_PLATFORM_PRIVATE_H__ */
diff --git a/src/platform/nm-platform.c b/src/platform/nm-platform.c
index 5c45a19c2f..8c1b6ceca5 100644
--- a/src/platform/nm-platform.c
+++ b/src/platform/nm-platform.c
@@ -4795,6 +4795,74 @@ log_ip6_route (NMPlatform *self, NMPObjectType obj_type, int ifindex, NMPlatform
/*****************************************************************************/
+void
+nm_platform_cache_update_emit_signal (NMPlatform *self,
+ NMPCacheOpsType cache_op,
+ const NMPObject *obj_old,
+ const NMPObject *obj_new)
+{
+ gboolean visible_new;
+ gboolean visible_old;
+ const NMPObject *o;
+ const NMPClass *klass;
+
+ nm_assert (NM_IN_SET ((NMPlatformSignalChangeType) cache_op, (NMPlatformSignalChangeType) NMP_CACHE_OPS_UNCHANGED, NM_PLATFORM_SIGNAL_ADDED, NM_PLATFORM_SIGNAL_CHANGED, NM_PLATFORM_SIGNAL_REMOVED));
+
+ ASSERT_nmp_cache_ops (nm_platform_get_cache (self), cache_op, obj_old, obj_new);
+
+ NMTST_ASSERT_PLATFORM_NETNS_CURRENT (self);
+
+ switch (cache_op) {
+ case NMP_CACHE_OPS_ADDED:
+ if (!nmp_object_is_visible (obj_new))
+ return;
+ o = obj_new;
+ break;
+ case NMP_CACHE_OPS_UPDATED:
+ visible_old = nmp_object_is_visible (obj_old);
+ visible_new = nmp_object_is_visible (obj_new);
+ if (!visible_old && visible_new) {
+ o = obj_new;
+ cache_op = NMP_CACHE_OPS_ADDED;
+ } else if (visible_old && !visible_new) {
+ o = obj_old;
+ cache_op = NMP_CACHE_OPS_REMOVED;
+ } else if (!visible_new) {
+ /* it was invisible and stayed invisible. Nothing to do. */
+ return;
+ } else
+ o = obj_new;
+ break;
+ case NMP_CACHE_OPS_REMOVED:
+ if (!nmp_object_is_visible (obj_old))
+ return;
+ o = obj_old;
+ break;
+ default:
+ nm_assert (cache_op == NMP_CACHE_OPS_UNCHANGED);
+ return;
+ }
+
+ klass = NMP_OBJECT_GET_CLASS (o);
+
+ _LOGt ("emit signal %s %s: %s",
+ klass->signal_type,
+ nm_platform_signal_change_type_to_string ((NMPlatformSignalChangeType) cache_op),
+ nmp_object_to_string (o, NMP_OBJECT_TO_STRING_PUBLIC, NULL, 0));
+
+ nmp_object_ref (o);
+ g_signal_emit (self,
+ _nm_platform_signal_id_get (klass->signal_type_id),
+ 0,
+ (int) klass->obj_type,
+ o->object.ifindex,
+ &o->object,
+ (int) cache_op);
+ nmp_object_unref (o);
+}
+
+/*****************************************************************************/
+
NMPCache *
nm_platform_get_cache (NMPlatform *self)
{