platform: add use-udev property for NMPlatform

We want to move the multi_idx from NMLinuxPlatform to NMPlatform,
so that it can be used by NMFakePlatform as well. For that, we need
to know whether NMPlatform will use udev or not. Add a constrctor
property.
This commit is contained in:
Thomas Haller
2017-06-29 10:51:38 +02:00
parent 55e66cc7e6
commit 485551286c
3 changed files with 34 additions and 6 deletions

View File

@@ -2619,8 +2619,15 @@ G_DEFINE_TYPE (NMLinuxPlatform, nm_linux_platform, NM_TYPE_PLATFORM)
NMPlatform * NMPlatform *
nm_linux_platform_new (gboolean log_with_ptr, gboolean netns_support) nm_linux_platform_new (gboolean log_with_ptr, gboolean netns_support)
{ {
gboolean use_udev = FALSE;
if ( nmp_netns_is_initial ()
&& access ("/sys", W_OK) == 0)
use_udev = TRUE;
return g_object_new (NM_TYPE_LINUX_PLATFORM, return g_object_new (NM_TYPE_LINUX_PLATFORM,
NM_PLATFORM_LOG_WITH_PTR, log_with_ptr, NM_PLATFORM_LOG_WITH_PTR, log_with_ptr,
NM_PLATFORM_USE_UDEV, use_udev,
NM_PLATFORM_NETNS_SUPPORT, netns_support, NM_PLATFORM_NETNS_SUPPORT, netns_support,
NULL); NULL);
} }
@@ -6723,12 +6730,6 @@ nm_linux_platform_init (NMLinuxPlatform *self)
priv->delayed_action.list_refresh_link = g_ptr_array_new (); priv->delayed_action.list_refresh_link = g_ptr_array_new ();
priv->delayed_action.list_wait_for_nl_response = g_array_new (FALSE, TRUE, sizeof (DelayedActionWaitForNlResponseData)); priv->delayed_action.list_wait_for_nl_response = g_array_new (FALSE, TRUE, sizeof (DelayedActionWaitForNlResponseData));
priv->wifi_data = g_hash_table_new_full (NULL, NULL, NULL, (GDestroyNotify) wifi_utils_deinit); priv->wifi_data = g_hash_table_new_full (NULL, NULL, NULL, (GDestroyNotify) wifi_utils_deinit);
if ( nmp_netns_is_initial ()
&& access ("/sys", W_OK) == 0) {
priv->udev_client = nm_udev_client_new ((const char *[]) { "net", NULL },
handle_udev_event, self);
}
} }
static void static void
@@ -6742,6 +6743,11 @@ constructed (GObject *_object)
nm_assert (!platform->_netns || platform->_netns == nmp_netns_get_current ()); nm_assert (!platform->_netns || platform->_netns == nmp_netns_get_current ());
if (nm_platform_get_use_udev (platform)) {
priv->udev_client = nm_udev_client_new ((const char *[]) { "net", NULL },
handle_udev_event, platform);
}
priv->cache = nmp_cache_new (nm_platform_get_multi_idx (platform), priv->cache = nmp_cache_new (nm_platform_get_multi_idx (platform),
priv->udev_client != NULL); priv->udev_client != NULL);

View File

@@ -80,11 +80,13 @@ static guint signals[_NM_PLATFORM_SIGNAL_ID_LAST] = { 0 };
enum { enum {
PROP_0, PROP_0,
PROP_NETNS_SUPPORT, PROP_NETNS_SUPPORT,
PROP_USE_UDEV,
PROP_LOG_WITH_PTR, PROP_LOG_WITH_PTR,
LAST_PROP, LAST_PROP,
}; };
typedef struct _NMPlatformPrivate { typedef struct _NMPlatformPrivate {
bool use_udev:1;
bool log_with_ptr:1; bool log_with_ptr:1;
NMDedupMultiIndex *multi_idx; NMDedupMultiIndex *multi_idx;
} NMPlatformPrivate; } NMPlatformPrivate;
@@ -95,6 +97,12 @@ G_DEFINE_TYPE (NMPlatform, nm_platform, G_TYPE_OBJECT)
/*****************************************************************************/ /*****************************************************************************/
gboolean
nm_platform_get_use_udev (NMPlatform *self)
{
return NM_PLATFORM_GET_PRIVATE (self)->use_udev;
}
gboolean gboolean
nm_platform_get_log_with_ptr (NMPlatform *self) nm_platform_get_log_with_ptr (NMPlatform *self)
{ {
@@ -4929,6 +4937,10 @@ set_property (GObject *object, guint prop_id,
self->_netns = g_object_ref (netns); self->_netns = g_object_ref (netns);
} }
break; break;
case PROP_USE_UDEV:
/* construct-only */
priv->use_udev = g_value_get_boolean (value);
break;
case PROP_LOG_WITH_PTR: case PROP_LOG_WITH_PTR:
/* construct-only */ /* construct-only */
priv->log_with_ptr = g_value_get_boolean (value); priv->log_with_ptr = g_value_get_boolean (value);
@@ -4976,6 +4988,14 @@ nm_platform_class_init (NMPlatformClass *platform_class)
G_PARAM_CONSTRUCT_ONLY | G_PARAM_CONSTRUCT_ONLY |
G_PARAM_STATIC_STRINGS)); G_PARAM_STATIC_STRINGS));
g_object_class_install_property
(object_class, PROP_USE_UDEV,
g_param_spec_boolean (NM_PLATFORM_USE_UDEV, "", "",
FALSE,
G_PARAM_WRITABLE |
G_PARAM_CONSTRUCT_ONLY |
G_PARAM_STATIC_STRINGS));
g_object_class_install_property g_object_class_install_property
(object_class, PROP_LOG_WITH_PTR, (object_class, PROP_LOG_WITH_PTR,
g_param_spec_boolean (NM_PLATFORM_LOG_WITH_PTR, "", "", g_param_spec_boolean (NM_PLATFORM_LOG_WITH_PTR, "", "",

View File

@@ -45,6 +45,7 @@
/*****************************************************************************/ /*****************************************************************************/
#define NM_PLATFORM_NETNS_SUPPORT "netns-support" #define NM_PLATFORM_NETNS_SUPPORT "netns-support"
#define NM_PLATFORM_USE_UDEV "use-udev"
#define NM_PLATFORM_LOG_WITH_PTR "log-with-ptr" #define NM_PLATFORM_LOG_WITH_PTR "log-with-ptr"
/*****************************************************************************/ /*****************************************************************************/
@@ -726,6 +727,7 @@ _nm_platform_uint8_inv (guint8 scope)
return (guint8) ~scope; return (guint8) ~scope;
} }
gboolean nm_platform_get_use_udev (NMPlatform *self);
gboolean nm_platform_get_log_with_ptr (NMPlatform *self); gboolean nm_platform_get_log_with_ptr (NMPlatform *self);
NMPNetns *nm_platform_netns_get (NMPlatform *self); NMPNetns *nm_platform_netns_get (NMPlatform *self);