diff options
author | Dan Winship <danw@gnome.org> | 2014-10-22 13:48:18 -0400 |
---|---|---|
committer | Dan Winship <danw@gnome.org> | 2014-11-07 07:49:40 -0500 |
commit | ca18b2d44290c938894dc63f7b03d04a3be271bc (patch) | |
tree | 9fdf5a36bd0de1c788fa810864801f5c4495f2cc /libnm/nm-dhcp4-config.c | |
parent | d34910b12860eb080b1a519f441946cbc378f769 (diff) | |
download | NetworkManager-ca18b2d44290c938894dc63f7b03d04a3be271bc.tar.gz |
libnm: create NMDhcpConfig as parent of NMDhcp4Config and NMDhcp6Config
As with NMIP4Config and NMIP6Config, merge the two DHCP config classes
into one in the public API.
Diffstat (limited to 'libnm/nm-dhcp4-config.c')
-rw-r--r-- | libnm/nm-dhcp4-config.c | 150 |
1 files changed, 2 insertions, 148 deletions
diff --git a/libnm/nm-dhcp4-config.c b/libnm/nm-dhcp4-config.c index 2bf84fa408..6bbd8d6b54 100644 --- a/libnm/nm-dhcp4-config.c +++ b/libnm/nm-dhcp4-config.c @@ -15,169 +15,23 @@ * Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, * Boston, MA 02110-1301 USA. * - * Copyright 2008 - 2011 Red Hat, Inc. - * Copyright 2008 Novell, Inc. + * Copyright 2014 Red Hat, Inc. */ -#include <string.h> - #include "nm-dhcp4-config.h" -#include "nm-dbus-interface.h" #include "nm-object-private.h" -#include "nm-utils.h" - -G_DEFINE_TYPE (NMDhcp4Config, nm_dhcp4_config, NM_TYPE_OBJECT) - -#define NM_DHCP4_CONFIG_GET_PRIVATE(o) (G_TYPE_INSTANCE_GET_PRIVATE ((o), NM_TYPE_DHCP4_CONFIG, NMDhcp4ConfigPrivate)) -typedef struct { - GHashTable *options; -} NMDhcp4ConfigPrivate; - -enum { - PROP_0, - PROP_OPTIONS, - - LAST_PROP -}; +G_DEFINE_TYPE (NMDhcp4Config, nm_dhcp4_config, NM_TYPE_DHCP_CONFIG) static void nm_dhcp4_config_init (NMDhcp4Config *config) { - NMDhcp4ConfigPrivate *priv = NM_DHCP4_CONFIG_GET_PRIVATE (config); - - priv->options = g_hash_table_new_full (g_str_hash, g_str_equal, g_free, g_free); -} - -static gboolean -demarshal_dhcp4_options (NMObject *object, GParamSpec *pspec, GVariant *value, gpointer field) -{ - NMDhcp4ConfigPrivate *priv = NM_DHCP4_CONFIG_GET_PRIVATE (object); - GVariantIter iter; - const char *key; - GVariant *opt; - - g_hash_table_remove_all (priv->options); - - g_variant_iter_init (&iter, value); - while (g_variant_iter_next (&iter, "{&sv}", &key, &opt)) { - g_hash_table_insert (priv->options, g_strdup (key), g_variant_dup_string (opt, NULL)); - g_variant_unref (opt); - } - - _nm_object_queue_notify (object, NM_DHCP4_CONFIG_OPTIONS); - return TRUE; -} - -static void -init_dbus (NMObject *object) -{ - NMDhcp4ConfigPrivate *priv = NM_DHCP4_CONFIG_GET_PRIVATE (object); - const NMPropertiesInfo property_info[] = { - { NM_DHCP4_CONFIG_OPTIONS, &priv->options, demarshal_dhcp4_options }, - { NULL }, - }; - - NM_OBJECT_CLASS (nm_dhcp4_config_parent_class)->init_dbus (object); - - _nm_object_register_properties (object, - NM_DBUS_INTERFACE_DHCP4_CONFIG, - property_info); -} - -static void -finalize (GObject *object) -{ - NMDhcp4ConfigPrivate *priv = NM_DHCP4_CONFIG_GET_PRIVATE (object); - - if (priv->options) - g_hash_table_destroy (priv->options); - - G_OBJECT_CLASS (nm_dhcp4_config_parent_class)->finalize (object); -} - -static void -get_property (GObject *object, - guint prop_id, - GValue *value, - GParamSpec *pspec) -{ - NMDhcp4Config *self = NM_DHCP4_CONFIG (object); - - switch (prop_id) { - case PROP_OPTIONS: - g_value_set_boxed (value, nm_dhcp4_config_get_options (self)); - break; - default: - G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec); - break; - } } static void nm_dhcp4_config_class_init (NMDhcp4ConfigClass *config_class) { - GObjectClass *object_class = G_OBJECT_CLASS (config_class); NMObjectClass *nm_object_class = NM_OBJECT_CLASS (config_class); - g_type_class_add_private (config_class, sizeof (NMDhcp4ConfigPrivate)); - _nm_object_class_add_interface (nm_object_class, NM_DBUS_INTERFACE_DHCP4_CONFIG); - - /* virtual methods */ - object_class->get_property = get_property; - object_class->finalize = finalize; - - nm_object_class->init_dbus = init_dbus; - - /* properties */ - - /** - * NMDhcp4Config:options: - * - * The #GHashTable containing options of the configuration. - * - * Type: GLib.HashTable(utf8,utf8) - **/ - g_object_class_install_property - (object_class, PROP_OPTIONS, - g_param_spec_boxed (NM_DHCP4_CONFIG_OPTIONS, "", "", - G_TYPE_HASH_TABLE, - G_PARAM_READABLE | - G_PARAM_STATIC_STRINGS)); -} - -/** - * nm_dhcp4_config_get_options: - * @config: a #NMDhcp4Config - * - * Gets all the options contained in the configuration. - * - * Returns: (transfer none) (element-type utf8 GObject.Value): the #GHashTable containing strings for keys and values. - * This is the internal copy used by the configuration, and must not be modified. - **/ -GHashTable * -nm_dhcp4_config_get_options (NMDhcp4Config *config) -{ - g_return_val_if_fail (NM_IS_DHCP4_CONFIG (config), NULL); - - return NM_DHCP4_CONFIG_GET_PRIVATE (config)->options; -} - -/** - * nm_dhcp4_config_get_one_option: - * @config: a #NMDhcp4Config - * @option: the option to retrieve - * - * Gets one option by option name. - * - * Returns: the configuration option's value. This is the internal string used by the - * configuration, and must not be modified. - **/ -const char * -nm_dhcp4_config_get_one_option (NMDhcp4Config *config, const char *option) -{ - g_return_val_if_fail (NM_IS_DHCP4_CONFIG (config), NULL); - - return g_hash_table_lookup (nm_dhcp4_config_get_options (config), option); } |