1 /* -*- Mode: C; tab-width: 4; indent-tabs-mode: t; c-basic-offset: 4 -*- */
2 /* NetworkManager -- Network link manager
4 * This program is free software; you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License as published by
6 * the Free Software Foundation; either version 2 of the License, or
7 * (at your option) any later version.
9 * This program is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License for more details.
14 * You should have received a copy of the GNU General Public License along
15 * with this program; if not, write to the Free Software Foundation, Inc.,
16 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
18 * Copyright (C) 2008 Red Hat, Inc.
21 #include "nm-default.h"
25 #include "nm-dbus-interface.h"
26 #include "nm-dhcp4-config.h"
29 #include "nmdbus-dhcp4-config.h"
31 G_DEFINE_TYPE (NMDhcp4Config, nm_dhcp4_config, NM_TYPE_EXPORTED_OBJECT)
33 #define NM_DHCP4_CONFIG_GET_PRIVATE(o) (G_TYPE_INSTANCE_GET_PRIVATE ((o), NM_TYPE_DHCP4_CONFIG, NMDhcp4ConfigPrivate))
37 } NMDhcp4ConfigPrivate;
49 nm_dhcp4_config_new (void)
51 return NM_DHCP4_CONFIG (g_object_new (NM_TYPE_DHCP4_CONFIG, NULL));
55 nm_dhcp4_config_set_options (NMDhcp4Config *self,
58 NMDhcp4ConfigPrivate *priv = NM_DHCP4_CONFIG_GET_PRIVATE (self);
60 const char *key, *value;
61 GVariantBuilder builder;
63 g_return_if_fail (NM_IS_DHCP4_CONFIG (self));
64 g_return_if_fail (options != NULL);
66 g_variant_unref (priv->options);
68 g_variant_builder_init (&builder, G_VARIANT_TYPE ("a{sv}"));
69 g_hash_table_iter_init (&iter, options);
70 while (g_hash_table_iter_next (&iter, (gpointer) &key, (gpointer) &value))
71 g_variant_builder_add (&builder, "{sv}", key, g_variant_new_string (value));
73 priv->options = g_variant_builder_end (&builder);
74 g_variant_ref_sink (priv->options);
75 g_object_notify (G_OBJECT (self), NM_DHCP4_CONFIG_OPTIONS);
79 nm_dhcp4_config_get_option (NMDhcp4Config *self, const char *key)
81 NMDhcp4ConfigPrivate *priv = NM_DHCP4_CONFIG_GET_PRIVATE (self);
84 g_return_val_if_fail (NM_IS_DHCP4_CONFIG (self), NULL);
85 g_return_val_if_fail (key != NULL, NULL);
87 if (g_variant_lookup (priv->options, key, "&s", &value))
94 nm_dhcp4_config_get_options (NMDhcp4Config *self)
96 g_return_val_if_fail (NM_IS_DHCP4_CONFIG (self), NULL);
98 return g_variant_ref (NM_DHCP4_CONFIG_GET_PRIVATE (self)->options);
102 nm_dhcp4_config_init (NMDhcp4Config *self)
104 NMDhcp4ConfigPrivate *priv = NM_DHCP4_CONFIG_GET_PRIVATE (self);
106 priv->options = g_variant_new_array (G_VARIANT_TYPE ("{sv}"), NULL, 0);
107 g_variant_ref_sink (priv->options);
111 finalize (GObject *object)
113 NMDhcp4ConfigPrivate *priv = NM_DHCP4_CONFIG_GET_PRIVATE (object);
115 g_variant_unref (priv->options);
117 G_OBJECT_CLASS (nm_dhcp4_config_parent_class)->finalize (object);
121 get_property (GObject *object, guint prop_id,
122 GValue *value, GParamSpec *pspec)
124 NMDhcp4ConfigPrivate *priv = NM_DHCP4_CONFIG_GET_PRIVATE (object);
128 g_value_set_variant (value, priv->options);
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);
140 NMExportedObjectClass *exported_object_class = NM_EXPORTED_OBJECT_CLASS (config_class);
142 g_type_class_add_private (config_class, sizeof (NMDhcp4ConfigPrivate));
144 exported_object_class->export_path = NM_DBUS_PATH "/DHCP4Config/%u";
145 exported_object_class->export_on_construction = TRUE;
147 /* virtual methods */
148 object_class->get_property = get_property;
149 object_class->finalize = finalize;
152 g_object_class_install_property
153 (object_class, PROP_OPTIONS,
154 g_param_spec_variant (NM_DHCP4_CONFIG_OPTIONS, "", "",
155 G_VARIANT_TYPE ("a{sv}"),
158 G_PARAM_STATIC_STRINGS));
160 nm_exported_object_class_add_interface (NM_EXPORTED_OBJECT_CLASS (config_class),
161 NMDBUS_TYPE_DHCP4_CONFIG_SKELETON,