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.
This commit is contained in:
Dan Winship
2014-07-17 16:24:17 -04:00
parent 2b2faf9c28
commit 7da97fc6fe
11 changed files with 110 additions and 202 deletions

View File

@@ -64,8 +64,6 @@ noinst_LTLIBRARIES = libNetworkManager.la
nm_sources = \ nm_sources = \
config/nm-config.c \ config/nm-config.c \
config/nm-config.h \ config/nm-config.h \
config/nm-config-device.c \
config/nm-config-device.h \
\ \
devices/nm-device.c \ devices/nm-device.c \
devices/nm-device.h \ devices/nm-device.h \

View File

@@ -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);
}

View File

@@ -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 */

View File

@@ -27,6 +27,7 @@
#include "nm-logging.h" #include "nm-logging.h"
#include "nm-utils.h" #include "nm-utils.h"
#include "nm-glib-compat.h" #include "nm-glib-compat.h"
#include "nm-device.h"
#include <gio/gio.h> #include <gio/gio.h>
#include <glib/gi18n.h> #include <glib/gi18n.h>
@@ -177,11 +178,20 @@ nm_config_get_value (NMConfig *config, const char *group, const char *key, GErro
} }
gboolean 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); NMConfigPrivate *priv = NM_CONFIG_GET_PRIVATE (config);
GSList *specs = NULL;
int i;
gboolean match;
return nm_config_device_spec_match_list (device, (const char **) priv->ignore_carrier); 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);
g_slist_free (specs);
return match;
} }
/************************************************************************/ /************************************************************************/
@@ -227,18 +237,29 @@ merge_no_auto_default_state (NMConfig *config)
} }
gboolean 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); NMConfigPrivate *priv = NM_CONFIG_GET_PRIVATE (config);
GSList *specs = NULL;
int i;
gboolean match;
return !nm_config_device_spec_match_list (device, (const char **) priv->no_auto_default); 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);
g_slist_free (specs);
return !match;
} }
void 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); NMConfigPrivate *priv = NM_CONFIG_GET_PRIVATE (config);
char *current; const guint8 *hwaddr;
guint hwaddr_len;
char *current, *hwaddr_str;
GString *updated; GString *updated;
GError *error = NULL; 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_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'); g_string_append_c (updated, '\n');
if (!g_file_set_contents (priv->no_auto_default_file, updated->str, updated->len, &error)) { if (!g_file_set_contents (priv->no_auto_default_file, updated->str, updated->len, &error)) {

View File

@@ -25,7 +25,7 @@
#include <glib.h> #include <glib.h>
#include <glib-object.h> #include <glib-object.h>
#include "nm-config-device.h" #include "nm-types.h"
G_BEGIN_DECLS 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 guint nm_config_get_connectivity_interval (NMConfig *config);
const char *nm_config_get_connectivity_response (NMConfig *config); const char *nm_config_get_connectivity_response (NMConfig *config);
gboolean nm_config_get_ethernet_can_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, NMConfigDevice *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); char *nm_config_get_value (NMConfig *config, const char *group, const char *key, GError **error);

View File

@@ -4,9 +4,11 @@ AM_CPPFLAGS = \
-I$(top_builddir)/libnm-util \ -I$(top_builddir)/libnm-util \
-I$(top_srcdir)/src/ \ -I$(top_srcdir)/src/ \
-I$(top_srcdir)/src/config \ -I$(top_srcdir)/src/config \
-I$(top_srcdir)/src/devices \
-DG_LOG_DOMAIN=\""NetworkManager"\" \ -DG_LOG_DOMAIN=\""NetworkManager"\" \
-DNM_VERSION_MAX_ALLOWED=NM_VERSION_NEXT_STABLE \ -DNM_VERSION_MAX_ALLOWED=NM_VERSION_NEXT_STABLE \
$(GLIB_CFLAGS) \ $(GLIB_CFLAGS) \
$(DBUS_CFLAGS) \
-DSRCDIR=\""$(srcdir)"\" -DSRCDIR=\""$(srcdir)"\"
noinst_PROGRAMS = \ noinst_PROGRAMS = \

View File

@@ -24,72 +24,82 @@
#include <netinet/ether.h> #include <netinet/ether.h>
#include "nm-test-device.h" #include "nm-test-device.h"
#include "nm-config-device.h" #include "nm-device-private.h"
#include "nm-utils.h"
#include "NetworkManagerUtils.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_DEFINE_TYPE (NMTestDevice, nm_test_device, NM_TYPE_DEVICE)
G_IMPLEMENT_INTERFACE (NM_TYPE_CONFIG_DEVICE, nm_test_device_config_device_interface_init))
static void static void
nm_test_device_init (NMTestDevice *self) 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
constructed (GObject *object)
{
NMDevice *device = NM_DEVICE (object);
nm_device_update_hw_address (device);
g_object_class->constructed (object);
}
static void
dispose (GObject *object)
{
g_object_class->dispose (object);
}
static void static void
finalize (GObject *object) finalize (GObject *object)
{ {
NMTestDevice *self = NM_TEST_DEVICE (object); g_object_class->finalize (object);
}
g_free (self->hwaddr); static guint
g_free (self->hwaddr_bytes); get_hw_address_length (NMDevice *dev, gboolean *out_permanent)
{
G_OBJECT_CLASS (nm_test_device_parent_class)->finalize (object); if (out_permanent)
*out_permanent = TRUE;
return ETH_ALEN;
} }
static void static void
nm_test_device_class_init (NMTestDeviceClass *klass) nm_test_device_class_init (NMTestDeviceClass *klass)
{ {
GObjectClass *object_class = G_OBJECT_CLASS (klass); 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; object_class->finalize = finalize;
device_class->get_hw_address_length = get_hw_address_length;
} }
static gboolean NMDevice *
spec_match_list (NMConfigDevice *device, const GSList *specs)
{
NMTestDevice *self = NM_TEST_DEVICE (device);
return nm_match_spec_hwaddr (specs, self->hwaddr);
}
static const guint8 *
get_hw_address (NMConfigDevice *device, guint *out_len)
{
NMTestDevice *self = NM_TEST_DEVICE (device);
if (out_len)
*out_len = ETH_ALEN;
return self->hwaddr_bytes;
}
static void
nm_test_device_config_device_interface_init (NMConfigDeviceInterface *iface)
{
iface->spec_match_list = spec_match_list;
iface->get_hw_address = get_hw_address;
}
NMTestDevice *
nm_test_device_new (const char *hwaddr) nm_test_device_new (const char *hwaddr)
{ {
NMTestDevice *self = g_object_new (NM_TYPE_TEST_DEVICE, NULL); return g_object_new (NM_TYPE_TEST_DEVICE,
NM_DEVICE_IFACE, "dummy:",
self->hwaddr = g_strdup (hwaddr); NM_DEVICE_HW_ADDRESS, hwaddr,
self->hwaddr_bytes = g_malloc (ETH_ALEN); NULL);
nm_utils_hwaddr_aton (hwaddr, ARPHRD_ETHER, self->hwaddr_bytes);
return self;
} }

View File

@@ -21,7 +21,7 @@
#ifndef NM_TEST_DEVICE_H #ifndef NM_TEST_DEVICE_H
#define NM_TEST_DEVICE_H #define NM_TEST_DEVICE_H
#include <glib-object.h> #include <nm-device.h>
G_BEGIN_DECLS 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)) #define NM_TEST_DEVICE_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), NM_TYPE_TEST_DEVICE, NMTestDeviceClass))
typedef struct { typedef struct {
GObject parent; NMDevice parent;
char *hwaddr;
guint8 *hwaddr_bytes;
} NMTestDevice; } NMTestDevice;
typedef struct { typedef struct {
GObjectClass parent; NMDeviceClass parent;
} NMTestDeviceClass; } NMTestDeviceClass;
GType nm_test_device_get_type (void); 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 G_END_DECLS

View File

@@ -163,7 +163,7 @@ test_config_no_auto_default (void)
GError *error = NULL; GError *error = NULL;
int fd, nwrote; int fd, nwrote;
char *state_file; char *state_file;
NMTestDevice *dev1, *dev2, *dev3, *dev4; NMDevice *dev1, *dev2, *dev3, *dev4;
fd = g_file_open_tmp (NULL, &state_file, &error); fd = g_file_open_tmp (NULL, &state_file, &error);
g_assert_no_error (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"); dev3 = nm_test_device_new ("33:33:33:33:33:33");
dev4 = nm_test_device_new ("44:44:44:44:44:44"); 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, 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, 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, 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, dev4));
nm_config_set_ethernet_no_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, NM_CONFIG_DEVICE (dev3))); g_assert (!nm_config_get_ethernet_can_auto_default (config, dev3));
g_object_unref (config); g_object_unref (config);
@@ -201,10 +201,10 @@ test_config_no_auto_default (void)
config = nm_config_new (&error); config = nm_config_new (&error);
g_assert_no_error (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, 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, 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, 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, dev4));
g_object_unref (config); g_object_unref (config);

View File

@@ -70,7 +70,6 @@
#include "nm-manager-auth.h" #include "nm-manager-auth.h"
#include "nm-dbus-glib-types.h" #include "nm-dbus-glib-types.h"
#include "nm-dispatcher.h" #include "nm-dispatcher.h"
#include "nm-config-device.h"
#include "nm-config.h" #include "nm-config.h"
#include "nm-dns-manager.h" #include "nm-dns-manager.h"
@@ -79,10 +78,7 @@ static void impl_device_delete (NMDevice *device, DBusGMethodInvocation *con
#include "nm-device-glue.h" #include "nm-device-glue.h"
static void nm_device_config_device_interface_init (NMConfigDeviceInterface *iface); G_DEFINE_ABSTRACT_TYPE (NMDevice, nm_device, G_TYPE_OBJECT)
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))
#define NM_DEVICE_GET_PRIVATE(o) (G_TYPE_INSTANCE_GET_PRIVATE ((o), NM_TYPE_DEVICE, NMDevicePrivate)) #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); 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' * Get driver info from SIOCETHTOOL ioctl() for 'iface'
* Returns driver and firmware versions to 'driver_version and' 'firmware_version' * 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() */ /* Have to call update_initial_hw_address() before calling get_ignore_carrier() */
if (device_has_capability (dev, NM_DEVICE_CAP_CARRIER_DETECT)) { 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); check_carrier (dev);
nm_log_info (LOGD_HW, nm_log_info (LOGD_HW,

View File

@@ -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); g_signal_handlers_disconnect_by_func (connection, G_CALLBACK (default_wired_connection_updated_by_user_cb), self);
if (add_to_no_auto_default) 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 void
@@ -1605,7 +1605,7 @@ nm_settings_device_added (NMSettings *self, NMDevice *device)
if ( !nm_device_get_managed (device) if ( !nm_device_get_managed (device)
|| g_object_get_data (G_OBJECT (device), DEFAULT_WIRED_CONNECTION_TAG) || g_object_get_data (G_OBJECT (device), DEFAULT_WIRED_CONNECTION_TAG)
|| have_connection_for_device (self, device) || 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; return;
hw_address = nm_device_get_hw_address (device, &len); hw_address = nm_device_get_hw_address (device, &len);