diff options
author | Thomas Haller <thaller@redhat.com> | 2016-07-05 14:34:53 +0200 |
---|---|---|
committer | Thomas Haller <thaller@redhat.com> | 2016-07-05 23:08:23 +0200 |
commit | 87169e681a7f56ff10ff3b5c7f96695aaf2db0dd (patch) | |
tree | f464606c6df3317a16c7d92e6cd677a920c89771 | |
parent | a040e447d0117db62c1a25295c8e67848bb4f530 (diff) | |
download | NetworkManager-87169e681a7f56ff10ff3b5c7f96695aaf2db0dd.tar.gz |
veth: refactor type definition of NMDeviceVeth
Embed the private data inside NMDeviceVeth structure and use NM_GOBJECT_PROPERTIES_DEFINE().
-rw-r--r-- | src/devices/nm-device-veth.c | 55 | ||||
-rw-r--r-- | src/devices/nm-device-veth.h | 4 |
2 files changed, 39 insertions, 20 deletions
diff --git a/src/devices/nm-device-veth.c b/src/devices/nm-device-veth.c index ff198a7d76..cca86fbe90 100644 --- a/src/devices/nm-device-veth.c +++ b/src/devices/nm-device-veth.c @@ -38,23 +38,44 @@ #include "nm-device-logging.h" _LOG_DECLARE_SELF(NMDeviceVeth); -G_DEFINE_TYPE (NMDeviceVeth, nm_device_veth, NM_TYPE_DEVICE_ETHERNET) - -#define NM_DEVICE_VETH_GET_PRIVATE(o) (G_TYPE_INSTANCE_GET_PRIVATE ((o), NM_TYPE_DEVICE_VETH, NMDeviceVethPrivate)) +/*****************************************************************************/ typedef struct { NMDevice *peer; gboolean ever_had_peer; } NMDeviceVethPrivate; -enum { - PROP_0, - PROP_PEER, +struct _NMDeviceVeth { + NMDeviceEthernet parent; + NMDeviceVethPrivate _priv; +}; - LAST_PROP +struct _NMDeviceVethClass { + NMDeviceEthernetClass parent_class; }; -/**************************************************************/ +NM_GOBJECT_PROPERTIES_DEFINE (NMDeviceVeth, + PROP_PEER, +); + +/*****************************************************************************/ + +G_DEFINE_TYPE (NMDeviceVeth, nm_device_veth, NM_TYPE_DEVICE_ETHERNET) + +#define NM_DEVICE_VETH_GET_PRIVATE(self) \ + ({ \ + /* preserve the const-ness of self. Unfortunately, that + * way, @self cannot be a void pointer */ \ + typeof (self) _self = (self); \ + \ + /* Get compiler error if variable is of wrong type */ \ + _nm_unused const NMDeviceVeth *_self2 = (_self); \ + \ + nm_assert (NM_IS_DEVICE_VETH (_self)); \ + &_self->_priv; \ + }) + +/*****************************************************************************/ static void set_peer (NMDeviceVeth *self, NMDevice *peer) @@ -66,7 +87,7 @@ set_peer (NMDeviceVeth *self, NMDevice *peer) priv->peer = peer; g_object_add_weak_pointer (G_OBJECT (peer), (gpointer *) &priv->peer); - g_object_notify (G_OBJECT (self), NM_DEVICE_VETH_PEER); + _notify (self, PROP_PEER); } } @@ -150,8 +171,6 @@ nm_device_veth_class_init (NMDeviceVethClass *klass) GObjectClass *object_class = G_OBJECT_CLASS (klass); NMDeviceClass *device_class = NM_DEVICE_CLASS (klass); - g_type_class_add_private (klass, sizeof (NMDeviceVethPrivate)); - NM_DEVICE_CLASS_DECLARE_TYPES (klass, NULL, NM_LINK_TYPE_VETH) object_class->get_property = get_property; @@ -159,13 +178,13 @@ nm_device_veth_class_init (NMDeviceVethClass *klass) device_class->can_unmanaged_external_down = can_unmanaged_external_down; - /* properties */ - g_object_class_install_property - (object_class, PROP_PEER, - g_param_spec_string (NM_DEVICE_VETH_PEER, "", "", - NULL, - G_PARAM_READABLE | - G_PARAM_STATIC_STRINGS)); + obj_properties[PROP_PEER] = + g_param_spec_string (NM_DEVICE_VETH_PEER, "", "", + NULL, + G_PARAM_READABLE | + G_PARAM_STATIC_STRINGS); + + g_object_class_install_properties (object_class, _PROPERTY_ENUMS_LAST, obj_properties); nm_exported_object_class_add_interface (NM_EXPORTED_OBJECT_CLASS (klass), NMDBUS_TYPE_DEVICE_VETH_SKELETON, diff --git a/src/devices/nm-device-veth.h b/src/devices/nm-device-veth.h index c7b8ec3ad0..3ba5af6939 100644 --- a/src/devices/nm-device-veth.h +++ b/src/devices/nm-device-veth.h @@ -34,8 +34,8 @@ G_BEGIN_DECLS #define NM_DEVICE_VETH_PEER "peer" -typedef NMDeviceEthernet NMDeviceVeth; -typedef NMDeviceEthernetClass NMDeviceVethClass; +typedef struct _NMDeviceVeth NMDeviceVeth; +typedef struct _NMDeviceVethClass NMDeviceVethClass; GType nm_device_veth_get_type (void); |