diff options
| author | Michael Biebl <biebl@debian.org> | 2016-01-20 16:26:51 +0100 |
|---|---|---|
| committer | Michael Biebl <biebl@debian.org> | 2016-01-20 16:26:51 +0100 |
| commit | 494f296a3baab08522617b24b1f126d8f9a17502 (patch) | |
| tree | c8ef32fb0dd1c4ff35a0b38e787abb58692de0cd /src/nm-dhcp4-config.c | |
| parent | 54f6333410ffd570e62717d9e77c5c987175e397 (diff) | |
Imported Upstream version 1.1.90 upstream/1.1.90
Diffstat (limited to 'src/nm-dhcp4-config.c')
| -rw-r--r-- | src/nm-dhcp4-config.c | 116 |
1 files changed, 44 insertions, 72 deletions
diff --git a/src/nm-dhcp4-config.c b/src/nm-dhcp4-config.c index 096cf16d..00b9949b 100644 --- a/src/nm-dhcp4-config.c +++ b/src/nm-dhcp4-config.c @@ -20,24 +20,21 @@ #include "config.h" -#include <glib.h> #include <string.h> +#include "nm-default.h" #include "nm-dbus-interface.h" -#include "nm-dbus-manager.h" #include "nm-dhcp4-config.h" -#include "nm-dhcp4-config-glue.h" -#include "nm-dbus-glib-types.h" #include "nm-utils.h" +#include "nmdbus-dhcp4-config.h" -G_DEFINE_TYPE (NMDhcp4Config, nm_dhcp4_config, G_TYPE_OBJECT) +G_DEFINE_TYPE (NMDhcp4Config, nm_dhcp4_config, NM_TYPE_EXPORTED_OBJECT) #define NM_DHCP4_CONFIG_GET_PRIVATE(o) (G_TYPE_INSTANCE_GET_PRIVATE ((o), NM_TYPE_DHCP4_CONFIG, NMDhcp4ConfigPrivate)) typedef struct { - char *dbus_path; - GHashTable *options; + GVariant *options; } NMDhcp4ConfigPrivate; @@ -56,88 +53,59 @@ nm_dhcp4_config_new (void) } void -nm_dhcp4_config_add_option (NMDhcp4Config *self, - const char *key, - const char *option) +nm_dhcp4_config_set_options (NMDhcp4Config *self, + GHashTable *options) { - GValue *svalue; + NMDhcp4ConfigPrivate *priv = NM_DHCP4_CONFIG_GET_PRIVATE (self); + GHashTableIter iter; + const char *key, *value; + GVariantBuilder builder; g_return_if_fail (NM_IS_DHCP4_CONFIG (self)); - g_return_if_fail (key != NULL); - g_return_if_fail (option != NULL); + g_return_if_fail (options != NULL); - svalue = g_slice_new0 (GValue); - g_value_init (svalue, G_TYPE_STRING); - g_value_set_string (svalue, option); - g_hash_table_insert (NM_DHCP4_CONFIG_GET_PRIVATE (self)->options, g_strdup (key), svalue); - g_object_notify (G_OBJECT (self), NM_DHCP4_CONFIG_OPTIONS); -} + g_variant_unref (priv->options); -void -nm_dhcp4_config_reset (NMDhcp4Config *self) -{ - g_return_if_fail (NM_IS_DHCP4_CONFIG (self)); + g_variant_builder_init (&builder, G_VARIANT_TYPE ("a{sv}")); + g_hash_table_iter_init (&iter, options); + while (g_hash_table_iter_next (&iter, (gpointer) &key, (gpointer) &value)) + g_variant_builder_add (&builder, "{sv}", key, g_variant_new_string (value)); - g_hash_table_remove_all (NM_DHCP4_CONFIG_GET_PRIVATE (self)->options); + priv->options = g_variant_builder_end (&builder); + g_variant_ref_sink (priv->options); g_object_notify (G_OBJECT (self), NM_DHCP4_CONFIG_OPTIONS); } const char * nm_dhcp4_config_get_option (NMDhcp4Config *self, const char *key) { - GValue *value; + NMDhcp4ConfigPrivate *priv = NM_DHCP4_CONFIG_GET_PRIVATE (self); + const char *value; g_return_val_if_fail (NM_IS_DHCP4_CONFIG (self), NULL); g_return_val_if_fail (key != NULL, NULL); - value = g_hash_table_lookup (NM_DHCP4_CONFIG_GET_PRIVATE (self)->options, key); - return value ? g_value_get_string (value) : NULL; -} - -/* Caller owns the list, but not the values in the list */ -GSList * -nm_dhcp4_config_list_options (NMDhcp4Config *self) -{ - GHashTableIter iter; - const char *option = NULL; - GSList *list = NULL; - - g_return_val_if_fail (NM_IS_DHCP4_CONFIG (self), NULL); - - g_hash_table_iter_init (&iter, NM_DHCP4_CONFIG_GET_PRIVATE (self)->options); - while (g_hash_table_iter_next (&iter, (gpointer) &option, NULL)) - list = g_slist_prepend (list, (gpointer) option); - - return list; + if (g_variant_lookup (priv->options, key, "&s", &value)) + return value; + else + return NULL; } -const char * -nm_dhcp4_config_get_dbus_path (NMDhcp4Config *self) +GVariant * +nm_dhcp4_config_get_options (NMDhcp4Config *self) { g_return_val_if_fail (NM_IS_DHCP4_CONFIG (self), NULL); - return NM_DHCP4_CONFIG_GET_PRIVATE (self)->dbus_path; -} - -static void -nm_gvalue_destroy (gpointer data) -{ - GValue *value = (GValue *) data; - - g_value_unset (value); - g_slice_free (GValue, value); + return g_variant_ref (NM_DHCP4_CONFIG_GET_PRIVATE (self)->options); } static void nm_dhcp4_config_init (NMDhcp4Config *self) { NMDhcp4ConfigPrivate *priv = NM_DHCP4_CONFIG_GET_PRIVATE (self); - static guint32 counter = 0; - - priv->dbus_path = g_strdup_printf (NM_DBUS_PATH "/DHCP4Config/%d", counter++); - nm_dbus_manager_register_object (nm_dbus_manager_get (), priv->dbus_path, self); - priv->options = g_hash_table_new_full (g_str_hash, g_str_equal, g_free, nm_gvalue_destroy); + priv->options = g_variant_new_array (G_VARIANT_TYPE ("{sv}"), NULL, 0); + g_variant_ref_sink (priv->options); } static void @@ -145,8 +113,7 @@ finalize (GObject *object) { NMDhcp4ConfigPrivate *priv = NM_DHCP4_CONFIG_GET_PRIVATE (object); - g_free (priv->dbus_path); - g_hash_table_destroy (priv->options); + g_variant_unref (priv->options); G_OBJECT_CLASS (nm_dhcp4_config_parent_class)->finalize (object); } @@ -159,7 +126,7 @@ get_property (GObject *object, guint prop_id, switch (prop_id) { case PROP_OPTIONS: - g_value_set_boxed (value, priv->options); + g_value_set_variant (value, priv->options); break; default: G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec); @@ -171,9 +138,13 @@ static void nm_dhcp4_config_class_init (NMDhcp4ConfigClass *config_class) { GObjectClass *object_class = G_OBJECT_CLASS (config_class); + NMExportedObjectClass *exported_object_class = NM_EXPORTED_OBJECT_CLASS (config_class); g_type_class_add_private (config_class, sizeof (NMDhcp4ConfigPrivate)); + exported_object_class->export_path = NM_DBUS_PATH "/DHCP4Config/%u"; + exported_object_class->export_on_construction = TRUE; + /* virtual methods */ object_class->get_property = get_property; object_class->finalize = finalize; @@ -181,12 +152,13 @@ nm_dhcp4_config_class_init (NMDhcp4ConfigClass *config_class) /* properties */ g_object_class_install_property (object_class, PROP_OPTIONS, - g_param_spec_boxed (NM_DHCP4_CONFIG_OPTIONS, "", "", - DBUS_TYPE_G_MAP_OF_VARIANT, - G_PARAM_READABLE | - G_PARAM_STATIC_STRINGS)); - - nm_dbus_manager_register_exported_type (nm_dbus_manager_get (), - G_TYPE_FROM_CLASS (config_class), - &dbus_glib_nm_dhcp4_config_object_info); + g_param_spec_variant (NM_DHCP4_CONFIG_OPTIONS, "", "", + G_VARIANT_TYPE ("a{sv}"), + NULL, + G_PARAM_READABLE | + G_PARAM_STATIC_STRINGS)); + + nm_exported_object_class_add_interface (NM_EXPORTED_OBJECT_CLASS (config_class), + NMDBUS_TYPE_DHCP4_CONFIG_SKELETON, + NULL); } |