From 0bb1e9a116dba2f48a08155b1680b6c64c001449 Mon Sep 17 00:00:00 2001 From: Thomas Haller Date: Sun, 15 Jan 2017 12:15:58 +0100 Subject: [PATCH] ip[46]-config/trivial: move code around Move the GObject related functions to the end of the source file. Similar to how it's done for most other implementations. --- src/devices/adsl/nm-device-adsl.c | 2 +- src/devices/bluetooth/nm-bluez-device.c | 2 +- src/devices/bluetooth/nm-bluez4-adapter.c | 2 +- src/dhcp/nm-dhcp-client.c | 2 +- src/nm-auth-manager.c | 2 +- src/nm-config.c | 4 +- src/nm-ip4-config.c | 137 ++++++++++++---------- src/nm-ip6-config.c | 113 +++++++++--------- src/platform/nmp-netns.c | 4 +- 9 files changed, 141 insertions(+), 127 deletions(-) diff --git a/src/devices/adsl/nm-device-adsl.c b/src/devices/adsl/nm-device-adsl.c index 82974be31..53841a7fc 100644 --- a/src/devices/adsl/nm-device-adsl.c +++ b/src/devices/adsl/nm-device-adsl.c @@ -577,7 +577,7 @@ set_property (GObject *object, guint prop_id, { switch (prop_id) { case PROP_ATM_INDEX: - /* construct only */ + /* construct-only */ NM_DEVICE_ADSL_GET_PRIVATE ((NMDeviceAdsl *) object)->atm_index = g_value_get_int (value); break; default: diff --git a/src/devices/bluetooth/nm-bluez-device.c b/src/devices/bluetooth/nm-bluez-device.c index 4d2e9b1d7..92b2c9189 100644 --- a/src/devices/bluetooth/nm-bluez-device.c +++ b/src/devices/bluetooth/nm-bluez-device.c @@ -1077,7 +1077,7 @@ set_property (GObject *object, guint prop_id, switch (prop_id) { case PROP_PATH: - /* construct only */ + /* construct-only */ priv->path = g_value_dup_string (value); break; default: diff --git a/src/devices/bluetooth/nm-bluez4-adapter.c b/src/devices/bluetooth/nm-bluez4-adapter.c index b781def3a..c0c1be30b 100644 --- a/src/devices/bluetooth/nm-bluez4-adapter.c +++ b/src/devices/bluetooth/nm-bluez4-adapter.c @@ -281,7 +281,7 @@ set_property (GObject *object, guint prop_id, switch (prop_id) { case PROP_PATH: - /* construct only */ + /* construct-only */ priv->path = g_value_dup_string (value); break; default: diff --git a/src/dhcp/nm-dhcp-client.c b/src/dhcp/nm-dhcp-client.c index 31eb8276c..ba7c6dbf0 100644 --- a/src/dhcp/nm-dhcp-client.c +++ b/src/dhcp/nm-dhcp-client.c @@ -851,7 +851,7 @@ set_property (GObject *object, guint prop_id, g_warn_if_fail (priv->ifindex > 0); break; case PROP_HWADDR: - /* construct only */ + /* construct-only */ priv->hwaddr = g_value_dup_boxed (value); break; case PROP_IPV6: diff --git a/src/nm-auth-manager.c b/src/nm-auth-manager.c index 73063b9b9..4359d8f18 100644 --- a/src/nm-auth-manager.c +++ b/src/nm-auth-manager.c @@ -509,7 +509,7 @@ set_property (GObject *object, guint prop_id, const GValue *value, GParamSpec *p switch (prop_id) { case PROP_POLKIT_ENABLED: - /* construct only */ + /* construct-only */ priv->polkit_enabled = !!g_value_get_boolean (value); break; default: diff --git a/src/nm-config.c b/src/nm-config.c index 2d61b9296..87d0c8a7b 100644 --- a/src/nm-config.c +++ b/src/nm-config.c @@ -2232,7 +2232,7 @@ set_property (GObject *object, guint prop_id, switch (prop_id) { case PROP_CMD_LINE_OPTIONS: - /* construct only */ + /* construct-only */ cli = g_value_get_pointer (value); if (!cli) _nm_config_cmd_line_options_clear (&priv->cli); @@ -2240,7 +2240,7 @@ set_property (GObject *object, guint prop_id, _nm_config_cmd_line_options_copy (cli, &priv->cli); break; case PROP_ATOMIC_SECTION_PREFIXES: - /* construct only */ + /* construct-only */ priv->atomic_section_prefixes = g_strdupv (g_value_get_boxed (value)); break; default: diff --git a/src/nm-ip4-config.c b/src/nm-ip4-config.c index 2bd0d36cb..310ce4194 100644 --- a/src/nm-ip4-config.c +++ b/src/nm-ip4-config.c @@ -35,6 +35,29 @@ #include "introspection/org.freedesktop.NetworkManager.IP4Config.h" +/*****************************************************************************/ + +/* internal guint32 are assigned to gobject properties of type uint. Ensure, that uint is large enough */ +G_STATIC_ASSERT (sizeof (uint) >= sizeof (guint32)); +G_STATIC_ASSERT (G_MAXUINT >= 0xFFFFFFFF); + +/*****************************************************************************/ + +NM_GOBJECT_PROPERTIES_DEFINE (NMIP4Config, + PROP_IFINDEX, + PROP_ADDRESS_DATA, + PROP_ADDRESSES, + PROP_ROUTE_DATA, + PROP_ROUTES, + PROP_GATEWAY, + PROP_NAMESERVERS, + PROP_DOMAINS, + PROP_SEARCHES, + PROP_DNS_OPTIONS, + PROP_WINS_SERVERS, + PROP_DNS_PRIORITY, +); + typedef struct { gboolean never_default; guint32 gateway; @@ -72,33 +95,7 @@ G_DEFINE_TYPE (NMIP4Config, nm_ip4_config, NM_TYPE_EXPORTED_OBJECT) #define NM_IP4_CONFIG_GET_PRIVATE(self) _NM_GET_PRIVATE(self, NMIP4Config, NM_IS_IP4_CONFIG) -/* internal guint32 are assigned to gobject properties of type uint. Ensure, that uint is large enough */ -G_STATIC_ASSERT (sizeof (uint) >= sizeof (guint32)); -G_STATIC_ASSERT (G_MAXUINT >= 0xFFFFFFFF); - -NM_GOBJECT_PROPERTIES_DEFINE (NMIP4Config, - PROP_IFINDEX, - PROP_ADDRESS_DATA, - PROP_ADDRESSES, - PROP_ROUTE_DATA, - PROP_ROUTES, - PROP_GATEWAY, - PROP_NAMESERVERS, - PROP_DOMAINS, - PROP_SEARCHES, - PROP_DNS_OPTIONS, - PROP_WINS_SERVERS, - PROP_DNS_PRIORITY, -); - -NMIP4Config * -nm_ip4_config_new (int ifindex) -{ - g_return_val_if_fail (ifindex >= -1, NULL); - return (NMIP4Config *) g_object_new (NM_TYPE_IP4_CONFIG, - NM_IP4_CONFIG_IFINDEX, ifindex, - NULL); -} +/*****************************************************************************/ int nm_ip4_config_get_ifindex (const NMIP4Config *config) @@ -2233,43 +2230,6 @@ nm_ip4_config_equal (const NMIP4Config *a, const NMIP4Config *b) /*****************************************************************************/ -static void -nm_ip4_config_init (NMIP4Config *config) -{ - NMIP4ConfigPrivate *priv = NM_IP4_CONFIG_GET_PRIVATE (config); - - priv->addresses = g_array_new (FALSE, FALSE, sizeof (NMPlatformIP4Address)); - priv->routes = g_array_new (FALSE, FALSE, sizeof (NMPlatformIP4Route)); - priv->nameservers = g_array_new (FALSE, FALSE, sizeof (guint32)); - priv->domains = g_ptr_array_new_with_free_func (g_free); - priv->searches = g_ptr_array_new_with_free_func (g_free); - priv->dns_options = g_ptr_array_new_with_free_func (g_free); - priv->nis = g_array_new (FALSE, TRUE, sizeof (guint32)); - priv->wins = g_array_new (FALSE, TRUE, sizeof (guint32)); - priv->route_metric = -1; -} - -static void -finalize (GObject *object) -{ - NMIP4Config *self = NM_IP4_CONFIG (object); - NMIP4ConfigPrivate *priv = NM_IP4_CONFIG_GET_PRIVATE (self); - - nm_clear_g_variant (&priv->address_data_variant); - nm_clear_g_variant (&priv->addresses_variant); - g_array_unref (priv->addresses); - g_array_unref (priv->routes); - g_array_unref (priv->nameservers); - g_ptr_array_unref (priv->domains); - g_ptr_array_unref (priv->searches); - g_ptr_array_unref (priv->dns_options); - g_array_unref (priv->nis); - g_free (priv->nis_domain); - g_array_unref (priv->wins); - - G_OBJECT_CLASS (nm_ip4_config_parent_class)->finalize (object); -} - static void get_property (GObject *object, guint prop_id, GValue *value, GParamSpec *pspec) @@ -2459,6 +2419,7 @@ set_property (GObject *object, switch (prop_id) { case PROP_IFINDEX: + /* construct-only */ priv->ifindex = g_value_get_int (value); break; default: @@ -2467,6 +2428,54 @@ set_property (GObject *object, } } +/*****************************************************************************/ + +static void +nm_ip4_config_init (NMIP4Config *config) +{ + NMIP4ConfigPrivate *priv = NM_IP4_CONFIG_GET_PRIVATE (config); + + priv->addresses = g_array_new (FALSE, FALSE, sizeof (NMPlatformIP4Address)); + priv->routes = g_array_new (FALSE, FALSE, sizeof (NMPlatformIP4Route)); + priv->nameservers = g_array_new (FALSE, FALSE, sizeof (guint32)); + priv->domains = g_ptr_array_new_with_free_func (g_free); + priv->searches = g_ptr_array_new_with_free_func (g_free); + priv->dns_options = g_ptr_array_new_with_free_func (g_free); + priv->nis = g_array_new (FALSE, TRUE, sizeof (guint32)); + priv->wins = g_array_new (FALSE, TRUE, sizeof (guint32)); + priv->route_metric = -1; +} + +NMIP4Config * +nm_ip4_config_new (int ifindex) +{ + g_return_val_if_fail (ifindex >= -1, NULL); + return (NMIP4Config *) g_object_new (NM_TYPE_IP4_CONFIG, + NM_IP4_CONFIG_IFINDEX, ifindex, + NULL); +} + +static void +finalize (GObject *object) +{ + NMIP4Config *self = NM_IP4_CONFIG (object); + NMIP4ConfigPrivate *priv = NM_IP4_CONFIG_GET_PRIVATE (self); + + nm_clear_g_variant (&priv->address_data_variant); + nm_clear_g_variant (&priv->addresses_variant); + g_array_unref (priv->addresses); + g_array_unref (priv->routes); + g_array_unref (priv->nameservers); + g_ptr_array_unref (priv->domains); + g_ptr_array_unref (priv->searches); + g_ptr_array_unref (priv->dns_options); + g_array_unref (priv->nis); + g_free (priv->nis_domain); + g_array_unref (priv->wins); + + G_OBJECT_CLASS (nm_ip4_config_parent_class)->finalize (object); +} + static void nm_ip4_config_class_init (NMIP4ConfigClass *config_class) { diff --git a/src/nm-ip6-config.c b/src/nm-ip6-config.c index 713e2c12a..2e6faf561 100644 --- a/src/nm-ip6-config.c +++ b/src/nm-ip6-config.c @@ -35,6 +35,8 @@ #include "introspection/org.freedesktop.NetworkManager.IP6Config.h" +/*****************************************************************************/ + typedef struct { gboolean never_default; struct in6_addr gateway; @@ -80,26 +82,7 @@ NM_GOBJECT_PROPERTIES_DEFINE (NMIP6Config, PROP_DNS_PRIORITY, ); -NMIP6Config * -nm_ip6_config_new (int ifindex) -{ - g_return_val_if_fail (ifindex >= -1, NULL); - return (NMIP6Config *) g_object_new (NM_TYPE_IP6_CONFIG, - NM_IP6_CONFIG_IFINDEX, ifindex, - NULL); -} - -NMIP6Config * -nm_ip6_config_new_cloned (const NMIP6Config *src) -{ - NMIP6Config *new; - - g_return_val_if_fail (NM_IS_IP6_CONFIG (src), NULL); - - new = nm_ip6_config_new (nm_ip6_config_get_ifindex (src)); - nm_ip6_config_replace (new, src, NULL); - return new; -} +/*****************************************************************************/ int nm_ip6_config_get_ifindex (const NMIP6Config *config) @@ -1999,38 +1982,6 @@ nm_ip6_config_equal (const NMIP6Config *a, const NMIP6Config *b) /*****************************************************************************/ -static void -nm_ip6_config_init (NMIP6Config *config) -{ - NMIP6ConfigPrivate *priv = NM_IP6_CONFIG_GET_PRIVATE (config); - - priv->addresses = g_array_new (FALSE, TRUE, sizeof (NMPlatformIP6Address)); - priv->routes = g_array_new (FALSE, TRUE, sizeof (NMPlatformIP6Route)); - priv->nameservers = g_array_new (FALSE, TRUE, sizeof (struct in6_addr)); - priv->domains = g_ptr_array_new_with_free_func (g_free); - priv->searches = g_ptr_array_new_with_free_func (g_free); - priv->dns_options = g_ptr_array_new_with_free_func (g_free); - priv->route_metric = -1; -} - -static void -finalize (GObject *object) -{ - NMIP6Config *self = NM_IP6_CONFIG (object); - NMIP6ConfigPrivate *priv = NM_IP6_CONFIG_GET_PRIVATE (self); - - g_array_unref (priv->addresses); - g_array_unref (priv->routes); - g_array_unref (priv->nameservers); - g_ptr_array_unref (priv->domains); - g_ptr_array_unref (priv->searches); - g_ptr_array_unref (priv->dns_options); - nm_clear_g_variant (&priv->address_data_variant); - nm_clear_g_variant (&priv->addresses_variant); - - G_OBJECT_CLASS (nm_ip6_config_parent_class)->finalize (object); -} - static void nameservers_to_gvalue (GArray *array, GValue *value) { @@ -2223,6 +2174,7 @@ set_property (GObject *object, switch (prop_id) { case PROP_IFINDEX: + /* construct-only */ priv->ifindex = g_value_get_int (value); break; default: @@ -2231,6 +2183,61 @@ set_property (GObject *object, } } +/*****************************************************************************/ + +static void +nm_ip6_config_init (NMIP6Config *config) +{ + NMIP6ConfigPrivate *priv = NM_IP6_CONFIG_GET_PRIVATE (config); + + priv->addresses = g_array_new (FALSE, TRUE, sizeof (NMPlatformIP6Address)); + priv->routes = g_array_new (FALSE, TRUE, sizeof (NMPlatformIP6Route)); + priv->nameservers = g_array_new (FALSE, TRUE, sizeof (struct in6_addr)); + priv->domains = g_ptr_array_new_with_free_func (g_free); + priv->searches = g_ptr_array_new_with_free_func (g_free); + priv->dns_options = g_ptr_array_new_with_free_func (g_free); + priv->route_metric = -1; +} + +NMIP6Config * +nm_ip6_config_new (int ifindex) +{ + g_return_val_if_fail (ifindex >= -1, NULL); + return (NMIP6Config *) g_object_new (NM_TYPE_IP6_CONFIG, + NM_IP6_CONFIG_IFINDEX, ifindex, + NULL); +} + +NMIP6Config * +nm_ip6_config_new_cloned (const NMIP6Config *src) +{ + NMIP6Config *new; + + g_return_val_if_fail (NM_IS_IP6_CONFIG (src), NULL); + + new = nm_ip6_config_new (nm_ip6_config_get_ifindex (src)); + nm_ip6_config_replace (new, src, NULL); + return new; +} + +static void +finalize (GObject *object) +{ + NMIP6Config *self = NM_IP6_CONFIG (object); + NMIP6ConfigPrivate *priv = NM_IP6_CONFIG_GET_PRIVATE (self); + + g_array_unref (priv->addresses); + g_array_unref (priv->routes); + g_array_unref (priv->nameservers); + g_ptr_array_unref (priv->domains); + g_ptr_array_unref (priv->searches); + g_ptr_array_unref (priv->dns_options); + nm_clear_g_variant (&priv->address_data_variant); + nm_clear_g_variant (&priv->addresses_variant); + + G_OBJECT_CLASS (nm_ip6_config_parent_class)->finalize (object); +} + static void nm_ip6_config_class_init (NMIP6ConfigClass *config_class) { @@ -2239,12 +2246,10 @@ nm_ip6_config_class_init (NMIP6ConfigClass *config_class) exported_object_class->export_path = NM_EXPORT_PATH_NUMBERED (NM_DBUS_PATH"/IP6Config"); - /* virtual methods */ object_class->get_property = get_property; object_class->set_property = set_property; object_class->finalize = finalize; - /* properties */ obj_properties[PROP_IFINDEX] = g_param_spec_int (NM_IP6_CONFIG_IFINDEX, "", "", -1, G_MAXINT, -1, diff --git a/src/platform/nmp-netns.c b/src/platform/nmp-netns.c index 232c6efc9..c9c6850d5 100644 --- a/src/platform/nmp-netns.c +++ b/src/platform/nmp-netns.c @@ -676,12 +676,12 @@ set_property (GObject *object, guint prop_id, switch (prop_id) { case PROP_FD_NET: - /* construct only */ + /* construct-only */ priv->fd_net = g_value_get_int (value); g_return_if_fail (priv->fd_net > 0); break; case PROP_FD_MNT: - /* construct only */ + /* construct-only */ priv->fd_mnt = g_value_get_int (value); g_return_if_fail (priv->fd_mnt > 0); break;