libnm-glib: add NMDHCP6Config class

This commit is contained in:
Dan Williams 2010-01-15 12:40:19 -08:00
parent f9bd97020d
commit 4f537c195c
6 changed files with 427 additions and 4 deletions

View file

@ -42,6 +42,7 @@
#define NM_DBUS_INTERFACE_IP4_CONFIG NM_DBUS_INTERFACE ".IP4Config"
#define NM_DBUS_INTERFACE_DHCP4_CONFIG NM_DBUS_INTERFACE ".DHCP4Config"
#define NM_DBUS_INTERFACE_IP6_CONFIG NM_DBUS_INTERFACE ".IP6Config"
#define NM_DBUS_INTERFACE_DHCP6_CONFIG NM_DBUS_INTERFACE ".DHCP6Config"
#define NM_DBUS_SERVICE_USER_SETTINGS "org.freedesktop.NetworkManagerUserSettings"

View file

@ -20,7 +20,8 @@ BUILT_SOURCES = \
nm-active-connection-bindings.h \
nm-ip4-config-bindings.h \
nm-dhcp4-config-bindings.h \
nm-ip6-config-bindings.h
nm-ip6-config-bindings.h \
nm-dhcp6-config-bindings.h
lib_LTLIBRARIES = libnm-glib.la libnm-glib-vpn.la
@ -52,6 +53,7 @@ libnminclude_HEADERS = \
nm-active-connection.h \
nm-dhcp4-config.h \
nm-ip6-config.h \
nm-dhcp6-config.h \
nm-remote-connection.h \
nm-settings-interface.h \
nm-settings-system-interface.h \
@ -86,6 +88,7 @@ libnm_glib_la_SOURCES = \
nm-active-connection.c \
nm-dhcp4-config.c \
nm-ip6-config.c \
nm-dhcp6-config.c \
nm-remote-connection.c \
nm-remote-connection-private.h \
nm-settings-interface.c \
@ -172,6 +175,9 @@ nm-dhcp4-config-bindings.h: $(top_srcdir)/introspection/nm-dhcp4-config.xml
nm-ip6-config-bindings.h: $(top_srcdir)/introspection/nm-ip6-config.xml
dbus-binding-tool --prefix=nm_ip6_config --mode=glib-client --output=$@ $<
nm-dhcp6-config-bindings.h: $(top_srcdir)/introspection/nm-dhcp6-config.xml
dbus-binding-tool --prefix=nm_dhcp6_config --mode=glib-client --output=$@ $<
pkgconfigdir = $(libdir)/pkgconfig
pkgconfig_DATA = libnm-glib.pc libnm-glib-vpn.pc

View file

@ -59,6 +59,8 @@ typedef struct {
gboolean null_dhcp4_config;
NMIP6Config *ip6_config;
gboolean null_ip6_config;
NMDHCP6Config *dhcp6_config;
gboolean null_dhcp6_config;
NMDeviceState state;
GUdevClient *client;
@ -79,6 +81,7 @@ enum {
PROP_STATE,
PROP_PRODUCT,
PROP_VENDOR,
PROP_DHCP6_CONFIG,
LAST_PROP
};
@ -220,6 +223,46 @@ demarshal_ip6_config (NMObject *object, GParamSpec *pspec, GValue *value, gpoint
return TRUE;
}
static gboolean
demarshal_dhcp6_config (NMObject *object, GParamSpec *pspec, GValue *value, gpointer field)
{
NMDevicePrivate *priv = NM_DEVICE_GET_PRIVATE (object);
const char *path;
NMDHCP6Config *config = NULL;
DBusGConnection *connection;
if (!G_VALUE_HOLDS (value, DBUS_TYPE_G_OBJECT_PATH))
return FALSE;
priv->null_dhcp6_config = FALSE;
path = g_value_get_boxed (value);
if (path) {
if (!strcmp (path, "/"))
priv->null_dhcp6_config = TRUE;
else {
config = NM_DHCP6_CONFIG (_nm_object_cache_get (path));
if (config)
config = g_object_ref (config);
else {
connection = nm_object_get_connection (object);
config = NM_DHCP6_CONFIG (nm_dhcp6_config_new (connection, path));
}
}
}
if (priv->dhcp6_config) {
g_object_unref (priv->dhcp6_config);
priv->dhcp6_config = NULL;
}
if (config)
priv->dhcp6_config = config;
_nm_object_queue_notify (object, NM_DEVICE_DHCP6_CONFIG);
return TRUE;
}
static void
register_for_property_changed (NMDevice *device)
{
@ -230,9 +273,10 @@ register_for_property_changed (NMDevice *device)
{ NM_DEVICE_DRIVER, _nm_object_demarshal_generic, &priv->driver },
{ NM_DEVICE_CAPABILITIES, _nm_object_demarshal_generic, &priv->capabilities },
{ NM_DEVICE_MANAGED, _nm_object_demarshal_generic, &priv->managed },
{ NM_DEVICE_IP4_CONFIG, demarshal_ip4_config, &priv->ip4_config },
{ NM_DEVICE_DHCP4_CONFIG, demarshal_dhcp4_config, &priv->dhcp4_config },
{ NM_DEVICE_IP6_CONFIG, demarshal_ip6_config, &priv->ip6_config },
{ NM_DEVICE_IP4_CONFIG, demarshal_ip4_config, &priv->ip4_config },
{ NM_DEVICE_DHCP4_CONFIG, demarshal_dhcp4_config, &priv->dhcp4_config },
{ NM_DEVICE_IP6_CONFIG, demarshal_ip6_config, &priv->ip6_config },
{ NM_DEVICE_DHCP6_CONFIG, demarshal_dhcp6_config, &priv->dhcp6_config },
{ NULL },
};
@ -318,6 +362,8 @@ dispose (GObject *object)
g_object_unref (priv->dhcp4_config);
if (priv->ip6_config)
g_object_unref (priv->ip6_config);
if (priv->dhcp6_config)
g_object_unref (priv->dhcp6_config);
if (priv->client)
g_object_unref (priv->client);
@ -371,6 +417,9 @@ get_property (GObject *object,
case PROP_IP6_CONFIG:
g_value_set_object (value, nm_device_get_ip6_config (device));
break;
case PROP_DHCP6_CONFIG:
g_value_set_object (value, nm_device_get_dhcp6_config (device));
break;
case PROP_STATE:
g_value_set_uint (value, nm_device_get_state (device));
break;
@ -505,6 +554,19 @@ nm_device_class_init (NMDeviceClass *device_class)
NM_TYPE_IP6_CONFIG,
G_PARAM_READABLE));
/**
* NMDevice:dhcp6-config:
*
* The #NMDHCP6Config of the device.
**/
g_object_class_install_property
(object_class, PROP_DHCP6_CONFIG,
g_param_spec_object (NM_DEVICE_DHCP6_CONFIG,
"DHCP6 Config",
"DHCP6 Config",
NM_TYPE_DHCP6_CONFIG,
G_PARAM_READABLE));
/**
* NMDevice:state:
*
@ -870,6 +932,41 @@ nm_device_get_ip6_config (NMDevice *device)
return priv->ip6_config;
}
/**
* nm_device_get_dhcp6_config:
* @device: a #NMDevice
*
* Gets the current #NMDHCP6Config associated with the #NMDevice.
*
* Returns: the #NMDHCPConfig or %NULL if the device is not activated or not
* using DHCP.
**/
NMDHCP6Config *
nm_device_get_dhcp6_config (NMDevice *device)
{
NMDevicePrivate *priv;
char *path;
GValue value = { 0, };
g_return_val_if_fail (NM_IS_DEVICE (device), NULL);
priv = NM_DEVICE_GET_PRIVATE (device);
if (priv->dhcp6_config)
return priv->dhcp6_config;
if (priv->null_dhcp6_config)
return NULL;
path = _nm_object_get_object_path_property (NM_OBJECT (device), NM_DBUS_INTERFACE_DEVICE, "Dhcp6Config");
if (path) {
g_value_init (&value, DBUS_TYPE_G_OBJECT_PATH);
g_value_take_boxed (&value, path);
demarshal_dhcp6_config (NM_OBJECT (device), NULL, &value, &priv->dhcp6_config);
g_value_unset (&value);
}
return priv->dhcp6_config;
}
/**
* nm_device_get_state:
* @device: a #NMDevice

View file

@ -32,6 +32,7 @@
#include "nm-ip4-config.h"
#include "nm-dhcp4-config.h"
#include "nm-ip6-config.h"
#include "nm-dhcp6-config.h"
#include "nm-connection.h"
G_BEGIN_DECLS
@ -51,6 +52,7 @@ G_BEGIN_DECLS
#define NM_DEVICE_IP4_CONFIG "ip4-config"
#define NM_DEVICE_DHCP4_CONFIG "dhcp4-config"
#define NM_DEVICE_IP6_CONFIG "ip6-config"
#define NM_DEVICE_DHCP6_CONFIG "dhcp6-config"
#define NM_DEVICE_STATE "state"
#define NM_DEVICE_VENDOR "vendor"
#define NM_DEVICE_PRODUCT "product"
@ -89,6 +91,7 @@ gboolean nm_device_get_managed (NMDevice *device);
NMIP4Config * nm_device_get_ip4_config (NMDevice *device);
NMDHCP4Config * nm_device_get_dhcp4_config (NMDevice *device);
NMIP6Config * nm_device_get_ip6_config (NMDevice *device);
NMDHCP6Config * nm_device_get_dhcp6_config (NMDevice *device);
NMDeviceState nm_device_get_state (NMDevice *device);
const char * nm_device_get_product (NMDevice *device);
const char * nm_device_get_vendor (NMDevice *device);

View file

@ -0,0 +1,248 @@
/* -*- Mode: C; tab-width: 4; indent-tabs-mode: t; c-basic-offset: 4 -*- */
/*
* libnm_glib -- Access network status & information from glib applications
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 2 of the License, or (at your option) any later version.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library; if not, write to the
* Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
* Boston, MA 02110-1301 USA.
*
* Copyright (C) 2008 - 2010 Red Hat, Inc.
* Copyright (C) 2008 Novell, Inc.
*/
#include <string.h>
#include "nm-dhcp6-config.h"
#include "NetworkManager.h"
#include "nm-types-private.h"
#include "nm-object-private.h"
#include "nm-utils.h"
G_DEFINE_TYPE (NMDHCP6Config, nm_dhcp6_config, NM_TYPE_OBJECT)
#define NM_DHCP6_CONFIG_GET_PRIVATE(o) (G_TYPE_INSTANCE_GET_PRIVATE ((o), NM_TYPE_DHCP6_CONFIG, NMDHCP6ConfigPrivate))
typedef struct {
DBusGProxy *proxy;
GHashTable *options;
} NMDHCP6ConfigPrivate;
enum {
PROP_0,
PROP_OPTIONS,
LAST_PROP
};
static void
nm_dhcp6_config_init (NMDHCP6Config *config)
{
}
static void
copy_options (gpointer key, gpointer data, gpointer user_data)
{
GHashTable *options = (GHashTable *) user_data;
GValue *value = (GValue *) data;
g_hash_table_insert (options, g_strdup (key), g_value_dup_string (value));
}
static gboolean
demarshal_dhcp6_options (NMObject *object, GParamSpec *pspec, GValue *value, gpointer field)
{
NMDHCP6ConfigPrivate *priv = NM_DHCP6_CONFIG_GET_PRIVATE (object);
GHashTable *new_options;
g_hash_table_remove_all (priv->options);
new_options = g_value_get_boxed (value);
if (new_options)
g_hash_table_foreach (new_options, copy_options, priv->options);
_nm_object_queue_notify (object, NM_DHCP6_CONFIG_OPTIONS);
return TRUE;
}
static void
register_for_property_changed (NMDHCP6Config *config)
{
NMDHCP6ConfigPrivate *priv = NM_DHCP6_CONFIG_GET_PRIVATE (config);
const NMPropertiesChangedInfo property_changed_info[] = {
{ NM_DHCP6_CONFIG_OPTIONS, demarshal_dhcp6_options, &priv->options },
{ NULL },
};
_nm_object_handle_properties_changed (NM_OBJECT (config),
priv->proxy,
property_changed_info);
}
static GObject*
constructor (GType type,
guint n_construct_params,
GObjectConstructParam *construct_params)
{
NMObject *object;
DBusGConnection *connection;
NMDHCP6ConfigPrivate *priv;
object = (NMObject *) G_OBJECT_CLASS (nm_dhcp6_config_parent_class)->constructor (type,
n_construct_params,
construct_params);
if (!object)
return NULL;
priv = NM_DHCP6_CONFIG_GET_PRIVATE (object);
priv->options = g_hash_table_new_full (g_str_hash, g_str_equal, g_free, g_free);
connection = nm_object_get_connection (object);
priv->proxy = dbus_g_proxy_new_for_name (connection,
NM_DBUS_SERVICE,
nm_object_get_path (object),
NM_DBUS_INTERFACE_DHCP6_CONFIG);
register_for_property_changed (NM_DHCP6_CONFIG (object));
return G_OBJECT (object);
}
static void
finalize (GObject *object)
{
NMDHCP6ConfigPrivate *priv = NM_DHCP6_CONFIG_GET_PRIVATE (object);
if (priv->options)
g_hash_table_destroy (priv->options);
g_object_unref (priv->proxy);
G_OBJECT_CLASS (nm_dhcp6_config_parent_class)->finalize (object);
}
static void
get_property (GObject *object,
guint prop_id,
GValue *value,
GParamSpec *pspec)
{
NMDHCP6Config *self = NM_DHCP6_CONFIG (object);
switch (prop_id) {
case PROP_OPTIONS:
g_value_set_boxed (value, nm_dhcp6_config_get_options (self));
break;
default:
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
break;
}
}
static void
nm_dhcp6_config_class_init (NMDHCP6ConfigClass *config_class)
{
GObjectClass *object_class = G_OBJECT_CLASS (config_class);
g_type_class_add_private (config_class, sizeof (NMDHCP6ConfigPrivate));
/* virtual methods */
object_class->constructor = constructor;
object_class->get_property = get_property;
object_class->finalize = finalize;
/* properties */
/**
* NMDHCP6Config:options:
*
* The #GHashTable containing options of the configuration.
**/
g_object_class_install_property
(object_class, PROP_OPTIONS,
g_param_spec_boxed (NM_DHCP6_CONFIG_OPTIONS,
"Options",
"Options",
G_TYPE_HASH_TABLE,
G_PARAM_READABLE));
}
/**
* nm_dhcp6_config_new:
* @connection: the #DBusGConnection
* @object_path: the DBus object path of the device
*
* Creates a new #NMDHCP6Config.
*
* Returns: a new configuration
**/
GObject *
nm_dhcp6_config_new (DBusGConnection *connection, const char *object_path)
{
return (GObject *) g_object_new (NM_TYPE_DHCP6_CONFIG,
NM_OBJECT_DBUS_CONNECTION, connection,
NM_OBJECT_DBUS_PATH, object_path,
NULL);
}
/**
* nm_dhcp6_config_get_options:
* @config: a #NMDHCP6Config
*
* Gets all the options contained in the configuration.
*
* Returns: the #GHashTable containing strings for keys and values.
* This is the internal copy used by the configuration, and must not be modified.
**/
GHashTable *
nm_dhcp6_config_get_options (NMDHCP6Config *config)
{
NMDHCP6ConfigPrivate *priv = NM_DHCP6_CONFIG_GET_PRIVATE (config);
GValue value = { 0, };
if (g_hash_table_size (priv->options))
return priv->options;
if (!_nm_object_get_property (NM_OBJECT (config),
"org.freedesktop.DBus.Properties",
"Options",
&value))
goto out;
demarshal_dhcp6_options (NM_OBJECT (config), NULL, &value, &priv->options);
g_value_unset (&value);
out:
return priv->options;
}
/**
* nm_dhcp6_config_get_one_option:
* @config: a #NMDHCP6Config
* @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_dhcp6_config_get_one_option (NMDHCP6Config *config, const char *option)
{
g_return_val_if_fail (NM_IS_DHCP6_CONFIG (config), NULL);
return g_hash_table_lookup (nm_dhcp6_config_get_options (config), option);
}

View file

@ -0,0 +1,68 @@
/* -*- Mode: C; tab-width: 4; indent-tabs-mode: t; c-basic-offset: 4 -*- */
/*
* libnm_glib -- Access network status & information from glib applications
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 2 of the License, or (at your option) any later version.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library; if not, write to the
* Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
* Boston, MA 02110-1301 USA.
*
* Copyright (C) 2008 - 2010 Red Hat, Inc.
* Copyright (C) 2008 Novell, Inc.
*/
#ifndef NM_DHCP6_CONFIG_H
#define NM_DHCP6_CONFIG_H
#include <glib.h>
#include <glib-object.h>
#include <dbus/dbus-glib.h>
#include "nm-object.h"
G_BEGIN_DECLS
#define NM_TYPE_DHCP6_CONFIG (nm_dhcp6_config_get_type ())
#define NM_DHCP6_CONFIG(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), NM_TYPE_DHCP6_CONFIG, NMDHCP6Config))
#define NM_DHCP6_CONFIG_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), NM_TYPE_DHCP6_CONFIG, NMDHCP6ConfigClass))
#define NM_IS_DHCP6_CONFIG(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), NM_TYPE_DHCP6_CONFIG))
#define NM_IS_DHCP6_CONFIG_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((obj), NM_TYPE_DHCP6_CONFIG))
typedef struct {
NMObject parent;
} NMDHCP6Config;
typedef struct {
NMObjectClass parent;
/* Padding for future expansion */
void (*_reserved1) (void);
void (*_reserved2) (void);
void (*_reserved3) (void);
void (*_reserved4) (void);
void (*_reserved5) (void);
void (*_reserved6) (void);
} NMDHCP6ConfigClass;
#define NM_DHCP6_CONFIG_OPTIONS "options"
GType nm_dhcp6_config_get_type (void);
GObject *nm_dhcp6_config_new (DBusGConnection *connection, const char *object_path);
GHashTable * nm_dhcp6_config_get_options (NMDHCP6Config *config);
const char * nm_dhcp6_config_get_one_option (NMDHCP6Config *config, const char *option);
G_END_DECLS
#endif /* NM_DHCP6_CONFIG_H */