summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDan Winship <danw@gnome.org>2014-07-17 16:24:17 -0400
committerDan Winship <danw@gnome.org>2014-07-23 10:56:26 -0400
commit7da97fc6fece2b462d420e01bc3ab1c9ea6b351e (patch)
treef63ed573ecc79f1b0073573f9f1408ef659e2a36
parent2b2faf9c28a0a3442942681ecf4ad9b31b7a49ae (diff)
downloadNetworkManager-7da97fc6fece2b462d420e01bc3ab1c9ea6b351e.tar.gz
config: drop NMConfigDevice, use NMDevice directly
NMConfigDevice was added because in the 0.9.8 days, when each subdir of src/ was compiled separately, it was impossible to make src/config/ depend on src/devices/ because of circular dependencies. Since now everything gets compiled into a single libNetworkManager.la, this is no longer a problem, and so NMConfigDevice is just an unnecessary complication.
-rw-r--r--src/Makefile.am2
-rw-r--r--src/config/nm-config-device.c66
-rw-r--r--src/config/nm-config-device.h47
-rw-r--r--src/config/nm-config.c38
-rw-r--r--src/config/nm-config.h8
-rw-r--r--src/config/tests/Makefile.am2
-rw-r--r--src/config/tests/nm-test-device.c86
-rw-r--r--src/config/tests/nm-test-device.h10
-rw-r--r--src/config/tests/test-config.c22
-rw-r--r--src/devices/nm-device.c15
-rw-r--r--src/settings/nm-settings.c4
11 files changed, 104 insertions, 196 deletions
diff --git a/src/Makefile.am b/src/Makefile.am
index 04387c7274..d4ffab0901 100644
--- a/src/Makefile.am
+++ b/src/Makefile.am
@@ -64,8 +64,6 @@ noinst_LTLIBRARIES = libNetworkManager.la
nm_sources = \
config/nm-config.c \
config/nm-config.h \
- config/nm-config-device.c \
- config/nm-config-device.h \
\
devices/nm-device.c \
devices/nm-device.h \
diff --git a/src/config/nm-config-device.c b/src/config/nm-config-device.c
deleted file mode 100644
index b1b9e61fef..0000000000
--- a/src/config/nm-config-device.c
+++ /dev/null
@@ -1,66 +0,0 @@
-/* -*- Mode: C; tab-width: 4; indent-tabs-mode: t; c-basic-offset: 4 -*- */
-/* NetworkManager -- Network link manager
- *
- * This program is free software; you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation; either version 2 of the License, or
- * (at your option) any later version.
- *
- * This program 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 General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License along
- * with this program; if not, write to the Free Software Foundation, Inc.,
- * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
- *
- * Copyright 2013 Red Hat, Inc.
- */
-
-#include "config.h"
-
-#include "nm-config-device.h"
-
-#include <net/if_arp.h>
-
-#include <nm-utils.h>
-
-G_DEFINE_INTERFACE (NMConfigDevice, nm_config_device, G_TYPE_OBJECT)
-
-static void
-nm_config_device_default_init (NMConfigDeviceInterface *iface)
-{
-}
-
-gboolean
-nm_config_device_spec_match_list (NMConfigDevice *self, const char **config_specs)
-{
- GSList *specs = NULL;
- gboolean match;
- int i;
-
- g_return_val_if_fail (NM_IS_CONFIG_DEVICE (self), FALSE);
-
- if (!config_specs)
- return FALSE;
-
- for (i = 0; config_specs[i]; i++)
- specs = g_slist_prepend (specs, (char *) config_specs[i]);
- specs = g_slist_reverse (specs);
-
- match = NM_CONFIG_DEVICE_GET_INTERFACE (self)->spec_match_list (self, specs);
-
- g_slist_free (specs);
- return match;
-}
-
-char *
-nm_config_device_get_hwaddr (NMConfigDevice *self)
-{
- const guint8 *bytes;
- guint len = 0;
-
- bytes = NM_CONFIG_DEVICE_GET_INTERFACE (self)->get_hw_address (self, &len);
- return nm_utils_hwaddr_ntoa_len (bytes, len);
-}
diff --git a/src/config/nm-config-device.h b/src/config/nm-config-device.h
deleted file mode 100644
index 8b5409a02a..0000000000
--- a/src/config/nm-config-device.h
+++ /dev/null
@@ -1,47 +0,0 @@
-/* -*- Mode: C; tab-width: 4; indent-tabs-mode: t; c-basic-offset: 4 -*- */
-/* NetworkManager -- Network link manager
- *
- * This program is free software; you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation; either version 2 of the License, or
- * (at your option) any later version.
- *
- * This program 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 General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License along
- * with this program; if not, write to the Free Software Foundation, Inc.,
- * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
- *
- * Copyright 2013 Red Hat, Inc.
- */
-
-#ifndef NM_CONFIG_DEVICE_H
-#define NM_CONFIG_DEVICE_H
-
-#include <glib-object.h>
-
-#define NM_TYPE_CONFIG_DEVICE (nm_config_device_get_type ())
-#define NM_CONFIG_DEVICE(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), NM_TYPE_CONFIG_DEVICE, NMConfigDevice))
-#define NM_IS_CONFIG_DEVICE(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), NM_TYPE_CONFIG_DEVICE))
-#define NM_CONFIG_DEVICE_GET_INTERFACE(obj) (G_TYPE_INSTANCE_GET_INTERFACE ((obj), NM_TYPE_CONFIG_DEVICE, NMConfigDeviceInterface))
-
-typedef struct _NMConfigDevice NMConfigDevice;
-typedef struct _NMConfigDeviceInterface NMConfigDeviceInterface;
-
-struct _NMConfigDeviceInterface {
- GTypeInterface g_iface;
-
- /* Methods */
- gboolean (*spec_match_list) (NMConfigDevice *device, const GSList *specs);
- const guint8 * (* get_hw_address) (NMConfigDevice *device, guint *out_len);
-};
-
-GType nm_config_device_get_type (void);
-
-gboolean nm_config_device_spec_match_list (NMConfigDevice *device, const char **config_specs);
-char *nm_config_device_get_hwaddr (NMConfigDevice *device);
-
-#endif /* NM_CONFIG_DEVICE_H */
diff --git a/src/config/nm-config.c b/src/config/nm-config.c
index 32874f649d..711cf4687c 100644
--- a/src/config/nm-config.c
+++ b/src/config/nm-config.c
@@ -27,6 +27,7 @@
#include "nm-logging.h"
#include "nm-utils.h"
#include "nm-glib-compat.h"
+#include "nm-device.h"
#include <gio/gio.h>
#include <glib/gi18n.h>
@@ -177,11 +178,20 @@ nm_config_get_value (NMConfig *config, const char *group, const char *key, GErro
}
gboolean
-nm_config_get_ignore_carrier (NMConfig *config, NMConfigDevice *device)
+nm_config_get_ignore_carrier (NMConfig *config, NMDevice *device)
{
NMConfigPrivate *priv = NM_CONFIG_GET_PRIVATE (config);
+ GSList *specs = NULL;
+ int i;
+ gboolean match;
+
+ for (i = 0; priv->ignore_carrier[i]; i++)
+ specs = g_slist_prepend (specs, priv->ignore_carrier[i]);
+
+ match = nm_device_spec_match_list (device, specs);
- return nm_config_device_spec_match_list (device, (const char **) priv->ignore_carrier);
+ g_slist_free (specs);
+ return match;
}
/************************************************************************/
@@ -227,18 +237,29 @@ merge_no_auto_default_state (NMConfig *config)
}
gboolean
-nm_config_get_ethernet_can_auto_default (NMConfig *config, NMConfigDevice *device)
+nm_config_get_ethernet_can_auto_default (NMConfig *config, NMDevice *device)
{
NMConfigPrivate *priv = NM_CONFIG_GET_PRIVATE (config);
+ GSList *specs = NULL;
+ int i;
+ gboolean match;
+
+ for (i = 0; priv->no_auto_default[i]; i++)
+ specs = g_slist_prepend (specs, priv->no_auto_default[i]);
+
+ match = nm_device_spec_match_list (device, specs);
- return !nm_config_device_spec_match_list (device, (const char **) priv->no_auto_default);
+ g_slist_free (specs);
+ return !match;
}
void
-nm_config_set_ethernet_no_auto_default (NMConfig *config, NMConfigDevice *device)
+nm_config_set_ethernet_no_auto_default (NMConfig *config, NMDevice *device)
{
NMConfigPrivate *priv = NM_CONFIG_GET_PRIVATE (config);
- char *current;
+ const guint8 *hwaddr;
+ guint hwaddr_len;
+ char *current, *hwaddr_str;
GString *updated;
GError *error = NULL;
@@ -253,7 +274,10 @@ nm_config_set_ethernet_no_auto_default (NMConfig *config, NMConfigDevice *device
g_string_append_c (updated, '\n');
}
- g_string_append (updated, nm_config_device_get_hwaddr (device));
+ hwaddr = nm_device_get_hw_address (device, &hwaddr_len);
+ hwaddr_str = nm_utils_hwaddr_ntoa_len (hwaddr, hwaddr_len);
+ g_string_append (updated, hwaddr_str);
+ g_free (hwaddr_str);
g_string_append_c (updated, '\n');
if (!g_file_set_contents (priv->no_auto_default_file, updated->str, updated->len, &error)) {
diff --git a/src/config/nm-config.h b/src/config/nm-config.h
index 2e335c7165..aeb0ce8441 100644
--- a/src/config/nm-config.h
+++ b/src/config/nm-config.h
@@ -25,7 +25,7 @@
#include <glib.h>
#include <glib-object.h>
-#include "nm-config-device.h"
+#include "nm-types.h"
G_BEGIN_DECLS
@@ -61,10 +61,10 @@ const char *nm_config_get_connectivity_uri (NMConfig *config);
const guint nm_config_get_connectivity_interval (NMConfig *config);
const char *nm_config_get_connectivity_response (NMConfig *config);
-gboolean nm_config_get_ethernet_can_auto_default (NMConfig *config, NMConfigDevice *device);
-void nm_config_set_ethernet_no_auto_default (NMConfig *config, NMConfigDevice *device);
+gboolean nm_config_get_ethernet_can_auto_default (NMConfig *config, NMDevice *device);
+void nm_config_set_ethernet_no_auto_default (NMConfig *config, NMDevice *device);
-gboolean nm_config_get_ignore_carrier (NMConfig *config, NMConfigDevice *device);
+gboolean nm_config_get_ignore_carrier (NMConfig *config, NMDevice *device);
char *nm_config_get_value (NMConfig *config, const char *group, const char *key, GError **error);
diff --git a/src/config/tests/Makefile.am b/src/config/tests/Makefile.am
index 3dac9cfb48..dc0f308bab 100644
--- a/src/config/tests/Makefile.am
+++ b/src/config/tests/Makefile.am
@@ -4,9 +4,11 @@ AM_CPPFLAGS = \
-I$(top_builddir)/libnm-util \
-I$(top_srcdir)/src/ \
-I$(top_srcdir)/src/config \
+ -I$(top_srcdir)/src/devices \
-DG_LOG_DOMAIN=\""NetworkManager"\" \
-DNM_VERSION_MAX_ALLOWED=NM_VERSION_NEXT_STABLE \
$(GLIB_CFLAGS) \
+ $(DBUS_CFLAGS) \
-DSRCDIR=\""$(srcdir)"\"
noinst_PROGRAMS = \
diff --git a/src/config/tests/nm-test-device.c b/src/config/tests/nm-test-device.c
index 799d98c7da..fcfc63a7db 100644
--- a/src/config/tests/nm-test-device.c
+++ b/src/config/tests/nm-test-device.c
@@ -24,72 +24,82 @@
#include <netinet/ether.h>
#include "nm-test-device.h"
-#include "nm-config-device.h"
-#include "nm-utils.h"
-#include "NetworkManagerUtils.h"
+#include "nm-device-private.h"
-static void nm_test_device_config_device_interface_init (NMConfigDeviceInterface *iface);
+static GObjectClass *g_object_class;
-G_DEFINE_TYPE_WITH_CODE (NMTestDevice, nm_test_device, G_TYPE_OBJECT,
- G_IMPLEMENT_INTERFACE (NM_TYPE_CONFIG_DEVICE, nm_test_device_config_device_interface_init))
+G_DEFINE_TYPE (NMTestDevice, nm_test_device, NM_TYPE_DEVICE)
static void
nm_test_device_init (NMTestDevice *self)
{
}
+/* We jump over NMDevice's construct/destruct methods, which require NMPlatform
+ * and NMConnectionProvider to be initialized.
+ */
+
+static GObject*
+constructor (GType type,
+ guint n_construct_params,
+ GObjectConstructParam *construct_params)
+{
+ return g_object_class->constructor (type,
+ n_construct_params,
+ construct_params);
+}
+
static void
-finalize (GObject *object)
+constructed (GObject *object)
{
- NMTestDevice *self = NM_TEST_DEVICE (object);
+ NMDevice *device = NM_DEVICE (object);
- g_free (self->hwaddr);
- g_free (self->hwaddr_bytes);
+ nm_device_update_hw_address (device);
- G_OBJECT_CLASS (nm_test_device_parent_class)->finalize (object);
+ g_object_class->constructed (object);
}
static void
-nm_test_device_class_init (NMTestDeviceClass *klass)
+dispose (GObject *object)
{
- GObjectClass *object_class = G_OBJECT_CLASS (klass);
-
- object_class->finalize = finalize;
+ g_object_class->dispose (object);
}
-static gboolean
-spec_match_list (NMConfigDevice *device, const GSList *specs)
+static void
+finalize (GObject *object)
{
- NMTestDevice *self = NM_TEST_DEVICE (device);
-
- return nm_match_spec_hwaddr (specs, self->hwaddr);
+ g_object_class->finalize (object);
}
-static const guint8 *
-get_hw_address (NMConfigDevice *device, guint *out_len)
+static guint
+get_hw_address_length (NMDevice *dev, gboolean *out_permanent)
{
- NMTestDevice *self = NM_TEST_DEVICE (device);
-
- if (out_len)
- *out_len = ETH_ALEN;
- return self->hwaddr_bytes;
+ if (out_permanent)
+ *out_permanent = TRUE;
+ return ETH_ALEN;
}
static void
-nm_test_device_config_device_interface_init (NMConfigDeviceInterface *iface)
+nm_test_device_class_init (NMTestDeviceClass *klass)
{
- iface->spec_match_list = spec_match_list;
- iface->get_hw_address = get_hw_address;
+ GObjectClass *object_class = G_OBJECT_CLASS (klass);
+ NMDeviceClass *device_class = NM_DEVICE_CLASS (klass);
+
+ g_object_class = g_type_class_peek (G_TYPE_OBJECT);
+
+ object_class->constructor = constructor;
+ object_class->constructed = constructed;
+ object_class->dispose = dispose;
+ object_class->finalize = finalize;
+
+ device_class->get_hw_address_length = get_hw_address_length;
}
-NMTestDevice *
+NMDevice *
nm_test_device_new (const char *hwaddr)
{
- NMTestDevice *self = g_object_new (NM_TYPE_TEST_DEVICE, NULL);
-
- self->hwaddr = g_strdup (hwaddr);
- self->hwaddr_bytes = g_malloc (ETH_ALEN);
- nm_utils_hwaddr_aton (hwaddr, ARPHRD_ETHER, self->hwaddr_bytes);
-
- return self;
+ return g_object_new (NM_TYPE_TEST_DEVICE,
+ NM_DEVICE_IFACE, "dummy:",
+ NM_DEVICE_HW_ADDRESS, hwaddr,
+ NULL);
}
diff --git a/src/config/tests/nm-test-device.h b/src/config/tests/nm-test-device.h
index ad63bf5fd2..5c4f28b51e 100644
--- a/src/config/tests/nm-test-device.h
+++ b/src/config/tests/nm-test-device.h
@@ -21,7 +21,7 @@
#ifndef NM_TEST_DEVICE_H
#define NM_TEST_DEVICE_H
-#include <glib-object.h>
+#include <nm-device.h>
G_BEGIN_DECLS
@@ -33,19 +33,17 @@ G_BEGIN_DECLS
#define NM_TEST_DEVICE_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), NM_TYPE_TEST_DEVICE, NMTestDeviceClass))
typedef struct {
- GObject parent;
+ NMDevice parent;
- char *hwaddr;
- guint8 *hwaddr_bytes;
} NMTestDevice;
typedef struct {
- GObjectClass parent;
+ NMDeviceClass parent;
} NMTestDeviceClass;
GType nm_test_device_get_type (void);
-NMTestDevice *nm_test_device_new (const char *hwaddr);
+NMDevice *nm_test_device_new (const char *hwaddr);
G_END_DECLS
diff --git a/src/config/tests/test-config.c b/src/config/tests/test-config.c
index fb6baaccaf..fff2d2a092 100644
--- a/src/config/tests/test-config.c
+++ b/src/config/tests/test-config.c
@@ -163,7 +163,7 @@ test_config_no_auto_default (void)
GError *error = NULL;
int fd, nwrote;
char *state_file;
- NMTestDevice *dev1, *dev2, *dev3, *dev4;
+ NMDevice *dev1, *dev2, *dev3, *dev4;
fd = g_file_open_tmp (NULL, &state_file, &error);
g_assert_no_error (error);
@@ -185,13 +185,13 @@ test_config_no_auto_default (void)
dev3 = nm_test_device_new ("33:33:33:33:33:33");
dev4 = nm_test_device_new ("44:44:44:44:44:44");
- g_assert (!nm_config_get_ethernet_can_auto_default (config, NM_CONFIG_DEVICE (dev1)));
- g_assert (!nm_config_get_ethernet_can_auto_default (config, NM_CONFIG_DEVICE (dev2)));
- g_assert (nm_config_get_ethernet_can_auto_default (config, NM_CONFIG_DEVICE (dev3)));
- g_assert (!nm_config_get_ethernet_can_auto_default (config, NM_CONFIG_DEVICE (dev4)));
+ g_assert (!nm_config_get_ethernet_can_auto_default (config, dev1));
+ g_assert (!nm_config_get_ethernet_can_auto_default (config, dev2));
+ g_assert (nm_config_get_ethernet_can_auto_default (config, dev3));
+ g_assert (!nm_config_get_ethernet_can_auto_default (config, dev4));
- nm_config_set_ethernet_no_auto_default (config, NM_CONFIG_DEVICE (dev3));
- g_assert (!nm_config_get_ethernet_can_auto_default (config, NM_CONFIG_DEVICE (dev3)));
+ nm_config_set_ethernet_no_auto_default (config, dev3);
+ g_assert (!nm_config_get_ethernet_can_auto_default (config, dev3));
g_object_unref (config);
@@ -201,10 +201,10 @@ test_config_no_auto_default (void)
config = nm_config_new (&error);
g_assert_no_error (error);
- g_assert (!nm_config_get_ethernet_can_auto_default (config, NM_CONFIG_DEVICE (dev1)));
- g_assert (!nm_config_get_ethernet_can_auto_default (config, NM_CONFIG_DEVICE (dev2)));
- g_assert (!nm_config_get_ethernet_can_auto_default (config, NM_CONFIG_DEVICE (dev3)));
- g_assert (!nm_config_get_ethernet_can_auto_default (config, NM_CONFIG_DEVICE (dev4)));
+ g_assert (!nm_config_get_ethernet_can_auto_default (config, dev1));
+ g_assert (!nm_config_get_ethernet_can_auto_default (config, dev2));
+ g_assert (!nm_config_get_ethernet_can_auto_default (config, dev3));
+ g_assert (!nm_config_get_ethernet_can_auto_default (config, dev4));
g_object_unref (config);
diff --git a/src/devices/nm-device.c b/src/devices/nm-device.c
index 29d35fb2d5..b3de5580f5 100644
--- a/src/devices/nm-device.c
+++ b/src/devices/nm-device.c
@@ -70,7 +70,6 @@
#include "nm-manager-auth.h"
#include "nm-dbus-glib-types.h"
#include "nm-dispatcher.h"
-#include "nm-config-device.h"
#include "nm-config.h"
#include "nm-dns-manager.h"
@@ -79,10 +78,7 @@ static void impl_device_delete (NMDevice *device, DBusGMethodInvocation *con
#include "nm-device-glue.h"
-static void nm_device_config_device_interface_init (NMConfigDeviceInterface *iface);
-
-G_DEFINE_ABSTRACT_TYPE_WITH_CODE (NMDevice, nm_device, G_TYPE_OBJECT,
- G_IMPLEMENT_INTERFACE (NM_TYPE_CONFIG_DEVICE, nm_device_config_device_interface_init))
+G_DEFINE_ABSTRACT_TYPE (NMDevice, nm_device, G_TYPE_OBJECT)
#define NM_DEVICE_GET_PRIVATE(o) (G_TYPE_INSTANCE_GET_PRIVATE ((o), NM_TYPE_DEVICE, NMDevicePrivate))
@@ -7143,13 +7139,6 @@ nm_device_init (NMDevice *self)
priv->ip6_saved_properties = g_hash_table_new_full (g_str_hash, g_str_equal, NULL, g_free);
}
-static void
-nm_device_config_device_interface_init (NMConfigDeviceInterface *iface)
-{
- iface->spec_match_list = (gboolean (*) (NMConfigDevice *, const GSList *)) nm_device_spec_match_list;
- iface->get_hw_address = (const guint8 * (*) (NMConfigDevice *, guint *)) nm_device_get_hw_address;
-}
-
/*
* Get driver info from SIOCETHTOOL ioctl() for 'iface'
* Returns driver and firmware versions to 'driver_version and' 'firmware_version'
@@ -7256,7 +7245,7 @@ constructed (GObject *object)
/* Have to call update_initial_hw_address() before calling get_ignore_carrier() */
if (device_has_capability (dev, NM_DEVICE_CAP_CARRIER_DETECT)) {
- priv->ignore_carrier = nm_config_get_ignore_carrier (nm_config_get (), NM_CONFIG_DEVICE (dev));
+ priv->ignore_carrier = nm_config_get_ignore_carrier (nm_config_get (), dev);
check_carrier (dev);
nm_log_info (LOGD_HW,
diff --git a/src/settings/nm-settings.c b/src/settings/nm-settings.c
index 44c7f3e950..3a833db0c9 100644
--- a/src/settings/nm-settings.c
+++ b/src/settings/nm-settings.c
@@ -1580,7 +1580,7 @@ default_wired_clear_tag (NMSettings *self,
g_signal_handlers_disconnect_by_func (connection, G_CALLBACK (default_wired_connection_updated_by_user_cb), self);
if (add_to_no_auto_default)
- nm_config_set_ethernet_no_auto_default (NM_SETTINGS_GET_PRIVATE (self)->config, NM_CONFIG_DEVICE (device));
+ nm_config_set_ethernet_no_auto_default (NM_SETTINGS_GET_PRIVATE (self)->config, device);
}
void
@@ -1605,7 +1605,7 @@ nm_settings_device_added (NMSettings *self, NMDevice *device)
if ( !nm_device_get_managed (device)
|| g_object_get_data (G_OBJECT (device), DEFAULT_WIRED_CONNECTION_TAG)
|| have_connection_for_device (self, device)
- || !nm_config_get_ethernet_can_auto_default (priv->config, NM_CONFIG_DEVICE (device)))
+ || !nm_config_get_ethernet_can_auto_default (priv->config, device))
return;
hw_address = nm_device_get_hw_address (device, &len);