Example #1
0
void
nm_dhcp4_config_add_option (NMDHCP4Config *self,
                            const char *key,
                            const char *option)
{
	GValue *svalue;

	g_return_if_fail (NM_IS_DHCP4_CONFIG (self));
	g_return_if_fail (key != NULL);
	g_return_if_fail (option != 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);
}
Example #2
0
static gboolean
demarshal_dhcp4_options (NMObject *object, GParamSpec *pspec, GValue *value, gpointer field)
{
	NMDHCP4ConfigPrivate *priv = NM_DHCP4_CONFIG_GET_PRIVATE (object);
	GHashTable *new_options;
	GHashTableIter iter;
	const char *key;
	GValue *opt;

	g_hash_table_remove_all (priv->options);

	new_options = g_value_get_boxed (value);
	if (new_options) {
		g_hash_table_iter_init (&iter, new_options);
		while (g_hash_table_iter_next (&iter, (gpointer) &key, (gpointer) &opt))
			g_hash_table_insert (priv->options, g_strdup (key), g_value_dup_string (opt));
	}

	_nm_object_queue_notify (object, NM_DHCP4_CONFIG_OPTIONS);
	return TRUE;
}
void
nm_dhcp4_config_set_options (NMDhcp4Config *self,
                             GHashTable *options)
{
	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 (options != NULL);

	g_variant_unref (priv->options);

	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));

	priv->options = g_variant_builder_end (&builder);
	g_variant_ref_sink (priv->options);
	g_object_notify (G_OBJECT (self), NM_DHCP4_CONFIG_OPTIONS);
}