summary refs log tree commit diff
path: root/libnm/nm-device-vlan.c
diff options
context:
space:
mode:
authorMichael Biebl <biebl@debian.org>2019-12-18 18:29:24 +0100
committerMichael Biebl <biebl@debian.org>2019-12-18 18:29:24 +0100
commit28028b26b3371756811e95d894f709f4b1207c00 (patch)
tree6fe7316fd743b51042db47601a8ef8814b3134ac /libnm/nm-device-vlan.c
parente22609983008e1a669196ad64ba3a59ae8c76e0d (diff)
New upstream version 1.22.0 upstream/1.22.0
Diffstat (limited to 'libnm/nm-device-vlan.c')
-rw-r--r--libnm/nm-device-vlan.c157
1 files changed, 70 insertions, 87 deletions
diff --git a/libnm/nm-device-vlan.c b/libnm/nm-device-vlan.c
index ede50cc7..ee57d0f4 100644
--- a/libnm/nm-device-vlan.c
+++ b/libnm/nm-device-vlan.c
@@ -1,20 +1,6 @@
+// SPDX-License-Identifier: LGPL-2.1+
 /*
- * This library is free software; you can redistribute it and/or
- * modify it under the terms of the GNU Lesser General Public
- * License as published by the Free Software Foundation; either
- * version 2 of the License, or (at your option) any later version.
- *
- * This library is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
- * Lesser General Public License for more details.
- *
- * You should have received a copy of the GNU Lesser General Public
- * License along with this library; if not, write to the
- * Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
- * Boston, MA 02110-1301 USA.
- *
- * Copyright 2012 Red Hat, Inc.
+ * Copyright (C) 2012 Red Hat, Inc.
  */
 
 #include "nm-default.h"
@@ -27,27 +13,37 @@
 #include "nm-utils.h"
 #include "nm-object-private.h"
 
-G_DEFINE_TYPE (NMDeviceVlan, nm_device_vlan, NM_TYPE_DEVICE)
+/*****************************************************************************/
 
-#define NM_DEVICE_VLAN_GET_PRIVATE(o) (G_TYPE_INSTANCE_GET_PRIVATE ((o), NM_TYPE_DEVICE_VLAN, NMDeviceVlanPrivate))
+NM_GOBJECT_PROPERTIES_DEFINE_BASE (
+	PROP_HW_ADDRESS,
+	PROP_CARRIER,
+	PROP_PARENT,
+	PROP_VLAN_ID,
+);
 
 typedef struct {
+	NMLDBusPropertyO parent;
 	char *hw_address;
-	gboolean carrier;
-	NMDevice *parent;
-	guint vlan_id;
+	guint32 vlan_id;
+	bool carrier;
 } NMDeviceVlanPrivate;
 
-enum {
-	PROP_0,
-	PROP_HW_ADDRESS,
-	PROP_CARRIER,
-	PROP_PARENT,
-	PROP_VLAN_ID,
+struct _NMDeviceVlan {
+	NMDevice parent;
+	NMDeviceVlanPrivate _priv;
+};
 
-	LAST_PROP
+struct _NMDeviceVlanClass {
+	NMDeviceClass parent;
 };
 
+G_DEFINE_TYPE (NMDeviceVlan, nm_device_vlan, NM_TYPE_DEVICE)
+
+#define NM_DEVICE_VLAN_GET_PRIVATE(self) _NM_GET_PRIVATE(self, NMDeviceVlan, NM_IS_DEVICE_VLAN, NMObject, NMDevice)
+
+/*****************************************************************************/
+
 /**
  * nm_device_vlan_get_hw_address:
  * @device: a #NMDeviceVlan
@@ -62,7 +58,7 @@ nm_device_vlan_get_hw_address (NMDeviceVlan *device)
 {
 	g_return_val_if_fail (NM_IS_DEVICE_VLAN (device), NULL);
 
-	return nm_str_not_empty (NM_DEVICE_VLAN_GET_PRIVATE (device)->hw_address);
+	return _nml_coerce_property_str_not_empty (NM_DEVICE_VLAN_GET_PRIVATE (device)->hw_address);
 }
 
 /**
@@ -92,7 +88,7 @@ nm_device_vlan_get_parent (NMDeviceVlan *device)
 {
 	g_return_val_if_fail (NM_IS_DEVICE_VLAN (device), FALSE);
 
-	return NM_DEVICE_VLAN_GET_PRIVATE (device)->parent;
+	return nml_dbus_property_o_get_obj (&NM_DEVICE_VLAN_GET_PRIVATE (device)->parent);
 }
 
 /**
@@ -171,31 +167,11 @@ nm_device_vlan_init (NMDeviceVlan *device)
 }
 
 static void
-init_dbus (NMObject *object)
-{
-	NMDeviceVlanPrivate *priv = NM_DEVICE_VLAN_GET_PRIVATE (object);
-	const NMPropertiesInfo property_info[] = {
-		{ NM_DEVICE_VLAN_HW_ADDRESS, &priv->hw_address },
-		{ NM_DEVICE_VLAN_CARRIER,    &priv->carrier },
-		{ NM_DEVICE_VLAN_PARENT,     &priv->parent, NULL, NM_TYPE_DEVICE },
-		{ NM_DEVICE_VLAN_VLAN_ID,    &priv->vlan_id },
-		{ NULL },
-	};
-
-	NM_OBJECT_CLASS (nm_device_vlan_parent_class)->init_dbus (object);
-
-	_nm_object_register_properties (object,
-	                                NM_DBUS_INTERFACE_DEVICE_VLAN,
-	                                property_info);
-}
-
-static void
 finalize (GObject *object)
 {
 	NMDeviceVlanPrivate *priv = NM_DEVICE_VLAN_GET_PRIVATE (object);
 
 	g_free (priv->hw_address);
-	g_clear_object (&priv->parent);
 
 	G_OBJECT_CLASS (nm_device_vlan_parent_class)->finalize (object);
 }
@@ -227,72 +203,79 @@ get_property (GObject *object,
 	}
 }
 
+const NMLDBusMetaIface _nml_dbus_meta_iface_nm_device_vlan = NML_DBUS_META_IFACE_INIT_PROP (
+	NM_DBUS_INTERFACE_DEVICE_VLAN,
+	nm_device_vlan_get_type,
+	NML_DBUS_META_INTERFACE_PRIO_INSTANTIATE_HIGH,
+	NML_DBUS_META_IFACE_DBUS_PROPERTIES (
+		NML_DBUS_META_PROPERTY_INIT_B      ("Carrier",   PROP_CARRIER,    NMDeviceVlan, _priv.carrier                       ),
+		NML_DBUS_META_PROPERTY_INIT_S      ("HwAddress", PROP_HW_ADDRESS, NMDeviceVlan, _priv.hw_address                    ),
+		NML_DBUS_META_PROPERTY_INIT_O_PROP ("Parent",    PROP_PARENT,     NMDeviceVlan, _priv.parent,    nm_device_get_type ),
+		NML_DBUS_META_PROPERTY_INIT_U      ("VlanId",    PROP_VLAN_ID,    NMDeviceVlan, _priv.vlan_id                       ),
+	),
+);
+
 static void
-nm_device_vlan_class_init (NMDeviceVlanClass *vlan_class)
+nm_device_vlan_class_init (NMDeviceVlanClass *klass)
 {
-	GObjectClass *object_class = G_OBJECT_CLASS (vlan_class);
-	NMObjectClass *nm_object_class = NM_OBJECT_CLASS (vlan_class);
-	NMDeviceClass *device_class = NM_DEVICE_CLASS (vlan_class);
-
-	g_type_class_add_private (vlan_class, sizeof (NMDeviceVlanPrivate));
+	GObjectClass *object_class = G_OBJECT_CLASS (klass);
+	NMObjectClass *nm_object_class = NM_OBJECT_CLASS (klass);
+	NMDeviceClass *device_class = NM_DEVICE_CLASS (klass);
 
-	/* virtual methods */
-	object_class->finalize = finalize;
 	object_class->get_property = get_property;
+	object_class->finalize     = finalize;
 
-	nm_object_class->init_dbus = init_dbus;
+	_NM_OBJECT_CLASS_INIT_PRIV_PTR_DIRECT (nm_object_class, NMDeviceVlan);
 
-	device_class->connection_compatible = connection_compatible;
-	device_class->get_setting_type = get_setting_type;
-	device_class->get_hw_address = get_hw_address;
+	_NM_OBJECT_CLASS_INIT_PROPERTY_O_FIELDS_1 (nm_object_class, NMDeviceVlanPrivate, parent);
 
-	/* properties */
+	device_class->connection_compatible = connection_compatible;
+	device_class->get_setting_type      = get_setting_type;
+	device_class->get_hw_address        = get_hw_address;
 
 	/**
 	 * NMDeviceVlan:hw-address:
 	 *
 	 * The hardware (MAC) address of the device.
 	 **/
-	g_object_class_install_property
-		(object_class, PROP_HW_ADDRESS,
-		 g_param_spec_string (NM_DEVICE_VLAN_HW_ADDRESS, "", "",
-		                      NULL,
-		                      G_PARAM_READABLE |
-		                      G_PARAM_STATIC_STRINGS));
+	obj_properties[PROP_HW_ADDRESS] =
+	    g_param_spec_string (NM_DEVICE_VLAN_HW_ADDRESS, "", "",
+	                         NULL,
+	                         G_PARAM_READABLE |
+	                         G_PARAM_STATIC_STRINGS);
 
 	/**
 	 * NMDeviceVlan:carrier:
 	 *
 	 * Whether the device has carrier.
 	 **/
-	g_object_class_install_property
-		(object_class, PROP_CARRIER,
-		 g_param_spec_boolean (NM_DEVICE_VLAN_CARRIER, "", "",
-		                       FALSE,
-		                       G_PARAM_READABLE |
-		                       G_PARAM_STATIC_STRINGS));
+	obj_properties[PROP_CARRIER] =
+	    g_param_spec_boolean (NM_DEVICE_VLAN_CARRIER, "", "",
+	                          FALSE,
+	                          G_PARAM_READABLE |
+	                          G_PARAM_STATIC_STRINGS);
 
 	/**
 	 * NMDeviceVlan:parent:
 	 *
 	 * The devices's parent device.
 	 **/
-	g_object_class_install_property
-	    (object_class, PROP_PARENT,
-	     g_param_spec_object (NM_DEVICE_VLAN_PARENT, "", "",
-	                          NM_TYPE_DEVICE,
-	                          G_PARAM_READABLE |
-	                          G_PARAM_STATIC_STRINGS));
+	obj_properties[PROP_PARENT] =
+	    g_param_spec_object (NM_DEVICE_VLAN_PARENT, "", "",
+	                         NM_TYPE_DEVICE,
+	                         G_PARAM_READABLE |
+	                         G_PARAM_STATIC_STRINGS);
 
 	/**
 	 * NMDeviceVlan:vlan-id:
 	 *
 	 * The device's VLAN ID.
 	 **/
-	g_object_class_install_property
-		(object_class, PROP_VLAN_ID,
-		 g_param_spec_uint (NM_DEVICE_VLAN_VLAN_ID, "", "",
-		                    0, 4095, 0,
-		                    G_PARAM_READABLE |
-		                    G_PARAM_STATIC_STRINGS));
+	obj_properties[PROP_VLAN_ID] =
+	    g_param_spec_uint (NM_DEVICE_VLAN_VLAN_ID, "", "",
+	                       0, 4095, 0,
+	                       G_PARAM_READABLE |
+	                       G_PARAM_STATIC_STRINGS);
+
+	_nml_dbus_meta_class_init_with_properties (object_class, &_nml_dbus_meta_iface_nm_device_vlan);
 }