platform: register singleton instance early with NM_PLATFORM_REGISTER_SINGLETON
Add a construct-only property NM_PLATFORM_REGISTER_SINGLETON to NMPlatform. When set to TRUE, the constructor will self-register to nm_platform_setup(). The reason for this is that the _LOG() macro in NMLinuxPlatform logs the self pointer if the instance is not the singleton instance. During construction, we already have many log lines due to initialization of the instance. These lines all end up qualified with the self pointer. By earlier self-registering, printing the pointer value is omitted. Yes, this patch is really just to prettify logging.
This commit is contained in:
@@ -429,7 +429,9 @@ G_DEFINE_TYPE (NMLinuxPlatform, nm_linux_platform, NM_TYPE_PLATFORM)
|
||||
void
|
||||
nm_linux_platform_setup (void)
|
||||
{
|
||||
nm_platform_setup (g_object_new (NM_TYPE_LINUX_PLATFORM, NULL));
|
||||
g_object_new (NM_TYPE_LINUX_PLATFORM,
|
||||
NM_PLATFORM_REGISTER_SINGLETON, TRUE,
|
||||
NULL);
|
||||
}
|
||||
|
||||
/******************************************************************/
|
||||
|
@@ -58,6 +58,16 @@ enum {
|
||||
|
||||
static guint signals[LAST_SIGNAL] = { 0 };
|
||||
|
||||
enum {
|
||||
PROP_0,
|
||||
PROP_REGISTER_SINGLETON,
|
||||
LAST_PROP,
|
||||
};
|
||||
|
||||
typedef struct {
|
||||
gboolean register_singleton;
|
||||
} NMPlatformPrivate;
|
||||
|
||||
/******************************************************************/
|
||||
|
||||
/* Singleton NMPlatform subclass instance and cached class object */
|
||||
@@ -3119,6 +3129,35 @@ const NMPlatformVTableRoute nm_platform_vtable_route_v6 = {
|
||||
|
||||
/******************************************************************/
|
||||
|
||||
static void
|
||||
set_property (GObject *object, guint prop_id,
|
||||
const GValue *value, GParamSpec *pspec)
|
||||
{
|
||||
NMPlatformPrivate *priv = NM_PLATFORM_GET_PRIVATE (object);
|
||||
|
||||
switch (prop_id) {
|
||||
case PROP_REGISTER_SINGLETON:
|
||||
/* construct-only */
|
||||
priv->register_singleton = g_value_get_boolean (value);
|
||||
break;
|
||||
default:
|
||||
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
static void
|
||||
constructed (GObject *object)
|
||||
{
|
||||
NMPlatform *self = NM_PLATFORM (object);
|
||||
NMPlatformPrivate *priv = NM_PLATFORM_GET_PRIVATE (self);
|
||||
|
||||
G_OBJECT_CLASS (nm_platform_parent_class)->constructed (object);
|
||||
|
||||
if (priv->register_singleton)
|
||||
nm_platform_setup (self);
|
||||
}
|
||||
|
||||
static void
|
||||
nm_platform_init (NMPlatform *object)
|
||||
{
|
||||
@@ -3137,8 +3176,21 @@ nm_platform_class_init (NMPlatformClass *platform_class)
|
||||
{
|
||||
GObjectClass *object_class = G_OBJECT_CLASS (platform_class);
|
||||
|
||||
g_type_class_add_private (object_class, sizeof (NMPlatformPrivate));
|
||||
|
||||
object_class->set_property = set_property;
|
||||
object_class->constructed = constructed;
|
||||
|
||||
platform_class->wifi_set_powersave = wifi_set_powersave;
|
||||
|
||||
g_object_class_install_property
|
||||
(object_class, PROP_REGISTER_SINGLETON,
|
||||
g_param_spec_boolean (NM_PLATFORM_REGISTER_SINGLETON, "", "",
|
||||
FALSE,
|
||||
G_PARAM_WRITABLE |
|
||||
G_PARAM_CONSTRUCT_ONLY |
|
||||
G_PARAM_STATIC_STRINGS));
|
||||
|
||||
/* Signals */
|
||||
SIGNAL (SIGNAL_LINK_CHANGED, log_link)
|
||||
SIGNAL (SIGNAL_IP4_ADDRESS_CHANGED, log_ip4_address)
|
||||
|
@@ -40,6 +40,10 @@
|
||||
|
||||
/******************************************************************/
|
||||
|
||||
#define NM_PLATFORM_REGISTER_SINGLETON "register-singleton"
|
||||
|
||||
/******************************************************************/
|
||||
|
||||
typedef struct _NMPlatform NMPlatform;
|
||||
|
||||
/* workaround for older libnl version, that does not define these flags. */
|
||||
|
Reference in New Issue
Block a user