1 /* -*- Mode: C; tab-width: 4; indent-tabs-mode: t; c-basic-offset: 4 -*- */
3 * This library is free software; you can redistribute it and/or
4 * modify it under the terms of the GNU Lesser General Public
5 * License as published by the Free Software Foundation; either
6 * version 2 of the License, or (at your option) any later version.
8 * This library is distributed in the hope that it will be useful,
9 * but WITHOUT ANY WARRANTY; without even the implied warranty of
10 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
11 * Lesser General Public License for more details.
13 * You should have received a copy of the GNU Lesser General Public
14 * License along with this library; if not, write to the
15 * Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
16 * Boston, MA 02110-1301 USA.
18 * Copyright 2008 - 2011 Red Hat, Inc.
19 * Copyright 2008 Novell, Inc.
22 #include "nm-default.h"
26 #include "nm-dhcp4-config.h"
27 #include "NetworkManager.h"
28 #include "nm-types-private.h"
29 #include "nm-object-private.h"
32 G_DEFINE_TYPE (NMDHCP4Config, nm_dhcp4_config, NM_TYPE_OBJECT)
34 #define NM_DHCP4_CONFIG_GET_PRIVATE(o) (G_TYPE_INSTANCE_GET_PRIVATE ((o), NM_TYPE_DHCP4_CONFIG, NMDHCP4ConfigPrivate))
40 } NMDHCP4ConfigPrivate;
50 nm_dhcp4_config_init (NMDHCP4Config *config)
55 demarshal_dhcp4_options (NMObject *object, GParamSpec *pspec, GValue *value, gpointer field)
57 NMDHCP4ConfigPrivate *priv = NM_DHCP4_CONFIG_GET_PRIVATE (object);
58 GHashTable *new_options;
63 g_hash_table_remove_all (priv->options);
65 new_options = g_value_get_boxed (value);
67 g_hash_table_iter_init (&iter, new_options);
68 while (g_hash_table_iter_next (&iter, (gpointer) &key, (gpointer) &opt))
69 g_hash_table_insert (priv->options, g_strdup (key), g_value_dup_string (opt));
72 _nm_object_queue_notify (object, NM_DHCP4_CONFIG_OPTIONS);
77 register_properties (NMDHCP4Config *config)
79 NMDHCP4ConfigPrivate *priv = NM_DHCP4_CONFIG_GET_PRIVATE (config);
80 const NMPropertiesInfo property_info[] = {
81 { NM_DHCP4_CONFIG_OPTIONS, &priv->options, demarshal_dhcp4_options },
85 _nm_object_register_properties (NM_OBJECT (config),
91 constructed (GObject *object)
93 NMDHCP4ConfigPrivate *priv = NM_DHCP4_CONFIG_GET_PRIVATE (object);
95 G_OBJECT_CLASS (nm_dhcp4_config_parent_class)->constructed (object);
97 priv->options = g_hash_table_new_full (g_str_hash, g_str_equal, g_free, g_free);
99 priv->proxy = _nm_object_new_proxy (NM_OBJECT (object), NULL, NM_DBUS_INTERFACE_DHCP4_CONFIG);
100 register_properties (NM_DHCP4_CONFIG (object));
104 finalize (GObject *object)
106 NMDHCP4ConfigPrivate *priv = NM_DHCP4_CONFIG_GET_PRIVATE (object);
109 g_hash_table_destroy (priv->options);
111 g_object_unref (priv->proxy);
113 G_OBJECT_CLASS (nm_dhcp4_config_parent_class)->finalize (object);
117 get_property (GObject *object,
122 NMDHCP4Config *self = NM_DHCP4_CONFIG (object);
124 _nm_object_ensure_inited (NM_OBJECT (object));
128 g_value_set_boxed (value, nm_dhcp4_config_get_options (self));
131 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
137 nm_dhcp4_config_class_init (NMDHCP4ConfigClass *config_class)
139 GObjectClass *object_class = G_OBJECT_CLASS (config_class);
141 g_type_class_add_private (config_class, sizeof (NMDHCP4ConfigPrivate));
143 /* virtual methods */
144 object_class->constructed = constructed;
145 object_class->get_property = get_property;
146 object_class->finalize = finalize;
151 * NMDHCP4Config:options:
153 * The #GHashTable containing options of the configuration.
155 * Type: GLib.HashTable(utf8,GObject.Value)
157 g_object_class_install_property
158 (object_class, PROP_OPTIONS,
159 g_param_spec_boxed (NM_DHCP4_CONFIG_OPTIONS, "", "",
162 G_PARAM_STATIC_STRINGS));
166 * nm_dhcp4_config_new:
167 * @connection: the #DBusGConnection
168 * @object_path: the DBus object path of the device
170 * Creates a new #NMDHCP4Config.
172 * Returns: (transfer full): a new configuration
175 nm_dhcp4_config_new (DBusGConnection *connection, const char *object_path)
177 return (GObject *) g_object_new (NM_TYPE_DHCP4_CONFIG,
178 NM_OBJECT_DBUS_CONNECTION, connection,
179 NM_OBJECT_DBUS_PATH, object_path,
184 * nm_dhcp4_config_get_options:
185 * @config: a #NMDHCP4Config
187 * Gets all the options contained in the configuration.
189 * Returns: (transfer none) (element-type utf8 GObject.Value): the #GHashTable containing strings for keys and values.
190 * This is the internal copy used by the configuration, and must not be modified.
193 nm_dhcp4_config_get_options (NMDHCP4Config *config)
195 g_return_val_if_fail (NM_IS_DHCP4_CONFIG (config), NULL);
197 _nm_object_ensure_inited (NM_OBJECT (config));
198 return NM_DHCP4_CONFIG_GET_PRIVATE (config)->options;
202 * nm_dhcp4_config_get_one_option:
203 * @config: a #NMDHCP4Config
204 * @option: the option to retrieve
206 * Gets one option by option name.
208 * Returns: the configuration option's value. This is the internal string used by the
209 * configuration, and must not be modified.
212 nm_dhcp4_config_get_one_option (NMDHCP4Config *config, const char *option)
214 g_return_val_if_fail (NM_IS_DHCP4_CONFIG (config), NULL);
216 return g_hash_table_lookup (nm_dhcp4_config_get_options (config), option);