platform: expose emit-signal function from platform

It will be used by NMFakePlatform too.
This commit is contained in:
Thomas Haller
2017-06-29 13:13:54 +02:00
parent e160928b9e
commit c5af191dbf
3 changed files with 87 additions and 82 deletions

View File

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