diff options
Diffstat (limited to 'libnm/nm-device-generic.c')
| -rw-r--r-- | libnm/nm-device-generic.c | 110 |
1 files changed, 47 insertions, 63 deletions
diff --git a/libnm/nm-device-generic.c b/libnm/nm-device-generic.c index 548334b4..b1c78475 100644 --- a/libnm/nm-device-generic.c +++ b/libnm/nm-device-generic.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 2013 Red Hat, Inc. + * Copyright (C) 2013 Red Hat, Inc. */ #include "nm-default.h" @@ -25,23 +11,33 @@ #include "nm-setting-generic.h" #include "nm-setting-connection.h" -G_DEFINE_TYPE (NMDeviceGeneric, nm_device_generic, NM_TYPE_DEVICE) +/*****************************************************************************/ -#define NM_DEVICE_GENERIC_GET_PRIVATE(o) (G_TYPE_INSTANCE_GET_PRIVATE ((o), NM_TYPE_DEVICE_GENERIC, NMDeviceGenericPrivate)) +NM_GOBJECT_PROPERTIES_DEFINE_BASE ( + PROP_HW_ADDRESS, + PROP_TYPE_DESCRIPTION, +); typedef struct { char *hw_address; char *type_description; } NMDeviceGenericPrivate; -enum { - PROP_0, - PROP_HW_ADDRESS, - PROP_TYPE_DESCRIPTION, +struct _NMDeviceGeneric { + NMDevice parent; + NMDeviceGenericPrivate _priv; +}; - LAST_PROP +struct _NMDeviceGenericClass { + NMDeviceClass parent; }; +G_DEFINE_TYPE (NMDeviceGeneric, nm_device_generic, NM_TYPE_DEVICE) + +#define NM_DEVICE_GENERIC_GET_PRIVATE(self) _NM_GET_PRIVATE(self, NMDeviceGeneric, NM_IS_DEVICE_GENERIC, NMObject, NMDevice) + +/*****************************************************************************/ + /** * nm_device_generic_get_hw_address: * @device: a #NMDeviceGeneric @@ -56,7 +52,7 @@ nm_device_generic_get_hw_address (NMDeviceGeneric *device) { g_return_val_if_fail (NM_IS_DEVICE_GENERIC (device), NULL); - return nm_str_not_empty (NM_DEVICE_GENERIC_GET_PRIVATE (device)->hw_address); + return _nml_coerce_property_str_not_empty (NM_DEVICE_GENERIC_GET_PRIVATE (device)->hw_address); } /*****************************************************************************/ @@ -66,7 +62,7 @@ get_type_description (NMDevice *device) { NMDeviceGenericPrivate *priv = NM_DEVICE_GENERIC_GET_PRIVATE (device); - return nm_str_not_empty (priv->type_description); + return _nml_coerce_property_str_not_empty (priv->type_description); } static const char * @@ -113,23 +109,6 @@ nm_device_generic_init (NMDeviceGeneric *device) } static void -init_dbus (NMObject *object) -{ - NMDeviceGenericPrivate *priv = NM_DEVICE_GENERIC_GET_PRIVATE (object); - const NMPropertiesInfo property_info[] = { - { NM_DEVICE_GENERIC_HW_ADDRESS, &priv->hw_address }, - { NM_DEVICE_GENERIC_TYPE_DESCRIPTION, &priv->type_description }, - { NULL }, - }; - - NM_OBJECT_CLASS (nm_device_generic_parent_class)->init_dbus (object); - - _nm_object_register_properties (object, - NM_DBUS_INTERFACE_DEVICE_GENERIC, - property_info); -} - -static void finalize (GObject *object) { NMDeviceGenericPrivate *priv = NM_DEVICE_GENERIC_GET_PRIVATE (object); @@ -162,36 +141,40 @@ get_property (GObject *object, } } +const NMLDBusMetaIface _nml_dbus_meta_iface_nm_device_generic = NML_DBUS_META_IFACE_INIT_PROP ( + NM_DBUS_INTERFACE_DEVICE_GENERIC, + nm_device_generic_get_type, + NML_DBUS_META_INTERFACE_PRIO_INSTANTIATE_HIGH, + NML_DBUS_META_IFACE_DBUS_PROPERTIES ( + NML_DBUS_META_PROPERTY_INIT_S ("HwAddress", PROP_HW_ADDRESS, NMDeviceGeneric, _priv.hw_address ), + NML_DBUS_META_PROPERTY_INIT_S ("TypeDescription", PROP_TYPE_DESCRIPTION, NMDeviceGeneric, _priv.type_description ), + ), +); + static void nm_device_generic_class_init (NMDeviceGenericClass *klass) { GObjectClass *object_class = G_OBJECT_CLASS (klass); - NMObjectClass *nm_object_class = NM_OBJECT_CLASS (klass); NMDeviceClass *device_class = NM_DEVICE_CLASS (klass); - g_type_class_add_private (klass, sizeof (NMDeviceGenericPrivate)); - - object_class->finalize = finalize; object_class->get_property = get_property; + object_class->finalize = finalize; - nm_object_class->init_dbus = init_dbus; - - device_class->get_type_description = get_type_description; - device_class->get_hw_address = get_hw_address; + device_class->get_type_description = get_type_description; + device_class->get_hw_address = get_hw_address; device_class->connection_compatible = connection_compatible; - device_class->get_setting_type = get_setting_type; + device_class->get_setting_type = get_setting_type; /** * NMDeviceGeneric:hw-address: * * The hardware address of the device. **/ - g_object_class_install_property - (object_class, PROP_HW_ADDRESS, - g_param_spec_string (NM_DEVICE_GENERIC_HW_ADDRESS, "", "", - NULL, - G_PARAM_READABLE | - G_PARAM_STATIC_STRINGS)); + obj_properties[PROP_HW_ADDRESS] = + g_param_spec_string (NM_DEVICE_GENERIC_HW_ADDRESS, "", "", + NULL, + G_PARAM_READABLE | + G_PARAM_STATIC_STRINGS); /** * NMDeviceGeneric:type-description: @@ -199,10 +182,11 @@ nm_device_generic_class_init (NMDeviceGenericClass *klass) * A description of the specific type of device this is, or %NULL * if not known. **/ - g_object_class_install_property - (object_class, PROP_TYPE_DESCRIPTION, - g_param_spec_string (NM_DEVICE_GENERIC_TYPE_DESCRIPTION, "", "", - NULL, - G_PARAM_READABLE | - G_PARAM_STATIC_STRINGS)); + obj_properties[PROP_TYPE_DESCRIPTION] = + g_param_spec_string (NM_DEVICE_GENERIC_TYPE_DESCRIPTION, "", "", + NULL, + G_PARAM_READABLE | + G_PARAM_STATIC_STRINGS); + + _nml_dbus_meta_class_init_with_properties (object_class, &_nml_dbus_meta_iface_nm_device_generic); } |