summary refs log tree commit diff
path: root/libnm/nm-device-modem.c
diff options
context:
space:
mode:
Diffstat (limited to 'libnm/nm-device-modem.c')
-rw-r--r--libnm/nm-device-modem.c169
1 files changed, 75 insertions, 94 deletions
diff --git a/libnm/nm-device-modem.c b/libnm/nm-device-modem.c
index 60c707b8..5e7b064b 100644
--- a/libnm/nm-device-modem.c
+++ b/libnm/nm-device-modem.c
@@ -1,21 +1,7 @@
+// 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 2011 - 2012 Red Hat, Inc.
- * Copyright 2008 Novell, Inc.
+ * Copyright (C) 2011 - 2012 Red Hat, Inc.
+ * Copyright (C) 2008 Novell, Inc.
  */
 
 #include "nm-default.h"
@@ -28,28 +14,39 @@
 #include "nm-object-private.h"
 #include "nm-enum-types.h"
 
-G_DEFINE_TYPE (NMDeviceModem, nm_device_modem, NM_TYPE_DEVICE)
+/*****************************************************************************/
 
-#define NM_DEVICE_MODEM_GET_PRIVATE(o) (G_TYPE_INSTANCE_GET_PRIVATE ((o), NM_TYPE_DEVICE_MODEM, NMDeviceModemPrivate))
+NM_GOBJECT_PROPERTIES_DEFINE_BASE (
+	PROP_MODEM_CAPABILITIES,
+	PROP_CURRENT_CAPABILITIES,
+	PROP_DEVICE_ID,
+	PROP_OPERATOR_CODE,
+	PROP_APN,
+);
 
 typedef struct {
-	NMDeviceModemCapabilities caps;
-	NMDeviceModemCapabilities current_caps;
 	char *device_id;
 	char *operator_code;
 	char *apn;
+	guint32 modem_capabilities;
+	guint32 current_capabilities;
 } NMDeviceModemPrivate;
 
-enum {
-	PROP_0,
-	PROP_MODEM_CAPS,
-	PROP_CURRENT_CAPS,
-	PROP_DEVICE_ID,
-	PROP_OPERATOR_CODE,
-	PROP_APN,
-	LAST_PROP
+struct _NMDeviceModem {
+	NMDevice parent;
+	NMDeviceModemPrivate _priv;
+};
+
+struct _NMDeviceModemClass {
+	NMDeviceClass parent;
 };
 
+G_DEFINE_TYPE (NMDeviceModem, nm_device_modem, NM_TYPE_DEVICE)
+
+#define NM_DEVICE_MODEM_GET_PRIVATE(self) _NM_GET_PRIVATE(self, NMDeviceModem, NM_IS_DEVICE_MODEM, NMObject, NMDevice)
+
+/*****************************************************************************/
+
 /**
  * nm_device_modem_get_modem_capabilities:
  * @self: a #NMDeviceModem
@@ -65,7 +62,7 @@ nm_device_modem_get_modem_capabilities (NMDeviceModem *self)
 {
 	g_return_val_if_fail (NM_IS_DEVICE_MODEM (self), NM_DEVICE_MODEM_CAPABILITY_NONE);
 
-	return NM_DEVICE_MODEM_GET_PRIVATE (self)->caps;
+	return NM_DEVICE_MODEM_GET_PRIVATE (self)->modem_capabilities;
 }
 
 /**
@@ -84,7 +81,7 @@ nm_device_modem_get_current_capabilities (NMDeviceModem *self)
 {
 	g_return_val_if_fail (NM_IS_DEVICE_MODEM (self), NM_DEVICE_MODEM_CAPABILITY_NONE);
 
-	return NM_DEVICE_MODEM_GET_PRIVATE (self)->current_caps;
+	return NM_DEVICE_MODEM_GET_PRIVATE (self)->current_capabilities;
 }
 
 /**
@@ -219,26 +216,6 @@ nm_device_modem_init (NMDeviceModem *device)
 }
 
 static void
-init_dbus (NMObject *object)
-{
-	NMDeviceModemPrivate *priv = NM_DEVICE_MODEM_GET_PRIVATE (object);
-	const NMPropertiesInfo property_info[] = {
-		{ NM_DEVICE_MODEM_MODEM_CAPABILITIES,   &priv->caps },
-		{ NM_DEVICE_MODEM_CURRENT_CAPABILITIES, &priv->current_caps },
-		{ NM_DEVICE_MODEM_DEVICE_ID,            &priv->device_id },
-		{ NM_DEVICE_MODEM_OPERATOR_CODE,        &priv->operator_code },
-		{ NM_DEVICE_MODEM_APN,                  &priv->apn },
-		{ NULL },
-	};
-
-	NM_OBJECT_CLASS (nm_device_modem_parent_class)->init_dbus (object);
-
-	_nm_object_register_properties (object,
-	                                NM_DBUS_INTERFACE_DEVICE_MODEM,
-	                                property_info);
-}
-
-static void
 finalize (GObject *object)
 {
 	NMDeviceModemPrivate *priv = NM_DEVICE_MODEM_GET_PRIVATE (object);
@@ -259,10 +236,10 @@ get_property (GObject *object,
 	NMDeviceModem *self = NM_DEVICE_MODEM (object);
 
 	switch (prop_id) {
-	case PROP_MODEM_CAPS:
+	case PROP_MODEM_CAPABILITIES:
 		g_value_set_flags (value, nm_device_modem_get_modem_capabilities (self));
 		break;
-	case PROP_CURRENT_CAPS:
+	case PROP_CURRENT_CAPABILITIES:
 		g_value_set_flags (value, nm_device_modem_get_current_capabilities (self));
 		break;
 	case PROP_DEVICE_ID:
@@ -280,24 +257,31 @@ get_property (GObject *object,
 	}
 }
 
+const NMLDBusMetaIface _nml_dbus_meta_iface_nm_device_modem = NML_DBUS_META_IFACE_INIT_PROP (
+	NM_DBUS_INTERFACE_DEVICE_MODEM,
+	nm_device_modem_get_type,
+	NML_DBUS_META_INTERFACE_PRIO_INSTANTIATE_HIGH,
+	NML_DBUS_META_IFACE_DBUS_PROPERTIES (
+		NML_DBUS_META_PROPERTY_INIT_S ("Apn",                 PROP_APN,                   NMDeviceModem, _priv.apn                  ),
+		NML_DBUS_META_PROPERTY_INIT_U ("CurrentCapabilities", PROP_CURRENT_CAPABILITIES,  NMDeviceModem, _priv.current_capabilities ),
+		NML_DBUS_META_PROPERTY_INIT_S ("DeviceId",            PROP_DEVICE_ID,             NMDeviceModem, _priv.device_id            ),
+		NML_DBUS_META_PROPERTY_INIT_U ("ModemCapabilities",   PROP_MODEM_CAPABILITIES,    NMDeviceModem, _priv.modem_capabilities   ),
+		NML_DBUS_META_PROPERTY_INIT_S ("OperatorCode",        PROP_OPERATOR_CODE,         NMDeviceModem, _priv.operator_code        ),
+	),
+);
+
 static void
 nm_device_modem_class_init (NMDeviceModemClass *modem_class)
 {
 	GObjectClass *object_class = G_OBJECT_CLASS (modem_class);
-	NMObjectClass *nm_object_class = NM_OBJECT_CLASS (modem_class);
 	NMDeviceClass *device_class = NM_DEVICE_CLASS (modem_class);
 
-	g_type_class_add_private (modem_class, sizeof (NMDeviceModemPrivate));
-
-	/* virtual methods */
-	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_type_description  = get_type_description;
 	device_class->connection_compatible = connection_compatible;
-	device_class->get_setting_type = get_setting_type;
+	device_class->get_setting_type      = get_setting_type;
 
 	/**
 	 * NMDeviceModem:modem-capabilities:
@@ -307,13 +291,12 @@ nm_device_modem_class_init (NMDeviceModemClass *modem_class)
 	 * a firmware reload or other reinitialization to switch between eg
 	 * CDMA/EVDO and GSM/UMTS.
 	 **/
-	g_object_class_install_property
-		(object_class, PROP_MODEM_CAPS,
-		 g_param_spec_flags (NM_DEVICE_MODEM_MODEM_CAPABILITIES, "", "",
-		                     NM_TYPE_DEVICE_MODEM_CAPABILITIES,
-		                     NM_DEVICE_MODEM_CAPABILITY_NONE,
-		                     G_PARAM_READABLE |
-		                     G_PARAM_STATIC_STRINGS));
+	obj_properties[PROP_MODEM_CAPABILITIES] =
+	    g_param_spec_flags (NM_DEVICE_MODEM_MODEM_CAPABILITIES, "", "",
+	                        NM_TYPE_DEVICE_MODEM_CAPABILITIES,
+	                        NM_DEVICE_MODEM_CAPABILITY_NONE,
+	                        G_PARAM_READABLE |
+	                        G_PARAM_STATIC_STRINGS);
 
 	/**
 	 * NMDeviceModem:current-capabilities:
@@ -321,47 +304,45 @@ nm_device_modem_class_init (NMDeviceModemClass *modem_class)
 	 * The generic family of access technologies the modem currently supports
 	 * without a firmware reload or reinitialization.
 	 **/
-	g_object_class_install_property
-		(object_class, PROP_CURRENT_CAPS,
-		 g_param_spec_flags (NM_DEVICE_MODEM_CURRENT_CAPABILITIES, "", "",
-		                     NM_TYPE_DEVICE_MODEM_CAPABILITIES,
-		                     NM_DEVICE_MODEM_CAPABILITY_NONE,
-		                     G_PARAM_READABLE |
-		                     G_PARAM_STATIC_STRINGS));
+	obj_properties[PROP_CURRENT_CAPABILITIES] =
+	    g_param_spec_flags (NM_DEVICE_MODEM_CURRENT_CAPABILITIES, "", "",
+	                        NM_TYPE_DEVICE_MODEM_CAPABILITIES,
+	                        NM_DEVICE_MODEM_CAPABILITY_NONE,
+	                        G_PARAM_READABLE |
+	                        G_PARAM_STATIC_STRINGS);
 
 	/**
 	 * NMDeviceModem:device-id:
 	 *
 	 * Since: 1.20
 	 **/
-	g_object_class_install_property
-		(object_class, PROP_CURRENT_CAPS,
-		 g_param_spec_string (NM_DEVICE_MODEM_DEVICE_ID, "", "",
-		                     NULL,
-		                     G_PARAM_READABLE |
-		                     G_PARAM_STATIC_STRINGS));
+	obj_properties[PROP_DEVICE_ID] =
+	    g_param_spec_string (NM_DEVICE_MODEM_DEVICE_ID, "", "",
+	                        NULL,
+	                        G_PARAM_READABLE |
+	                        G_PARAM_STATIC_STRINGS);
 
 	/**
 	 * NMDeviceModem:operator-code:
 	 *
 	 * Since: 1.20
 	 **/
-	g_object_class_install_property
-		(object_class, PROP_CURRENT_CAPS,
-		 g_param_spec_string (NM_DEVICE_MODEM_OPERATOR_CODE, "", "",
-		                     NULL,
-		                     G_PARAM_READABLE |
-		                     G_PARAM_STATIC_STRINGS));
+	obj_properties[PROP_OPERATOR_CODE] =
+	    g_param_spec_string (NM_DEVICE_MODEM_OPERATOR_CODE, "", "",
+	                        NULL,
+	                        G_PARAM_READABLE |
+	                        G_PARAM_STATIC_STRINGS);
 
 	/**
 	 * NMDeviceModem:apn:
 	 *
 	 * Since: 1.20
 	 **/
-	g_object_class_install_property
-		(object_class, PROP_CURRENT_CAPS,
-		 g_param_spec_string (NM_DEVICE_MODEM_APN, "", "",
-		                     NULL,
-		                     G_PARAM_READABLE |
-		                     G_PARAM_STATIC_STRINGS));
+	obj_properties[PROP_APN] =
+	    g_param_spec_string (NM_DEVICE_MODEM_APN, "", "",
+	                        NULL,
+	                        G_PARAM_READABLE |
+	                        G_PARAM_STATIC_STRINGS);
+
+	_nml_dbus_meta_class_init_with_properties (object_class, &_nml_dbus_meta_iface_nm_device_modem);
 }