mirror of
https://gitlab.freedesktop.org/NetworkManager/NetworkManager
synced 2024-10-15 12:34:55 +00:00
2008-05-05 Tambet Ingo <tambet@gmail.com>
* libnm-glib/nm-dbus-settings.c (constructor): Fix the "PropertiesChanged" signal signature. * libnm-glib/nm-dbus-connection.c (constructor): Use the common GType defined in nm-dbus-glib-types.h. Don't register the connection on dbus, we're a proxy class to communicate with an already registered connection over dbus. 2008-04-30 Tambet Ingo <tambet@gmail.com> Implement new subclasses of NMSettings and NMExportedConnection to make it easier for the applet to access and modify system settings. * libnm-glib/nm-dbus-connection.[ch]: * libnm-glib/nm-dbus-settings.[ch]: * libnm-glib/nm-dbus-settings-system.[ch]: Implement. * libnm-glib/Makefile.am: Add the new files to build, generate some more bindings and glue. * include/NetworkManager.h: Define the system settings DBus interface. 2008-04-30 Tambet Ingo <tambet@gmail.com> Implement additional C API for exported connections to make them identical with the DBus API. Change the (list_connections) virtual function to be more usable from C - instead of requiring implementers to return a GPtrArray of dbus paths, return a list of connections. * libnm-glib/nm-settings.c (nm_exported_connection_class_init): Fix a typo. (nm_settings_list_connections): (nm_exported_connection_new): (nm_exported_connection_update): (nm_exported_connection_delete): Implement. (impl_settings_list_connections): (impl_exported_connection_update): (impl_exported_connection_delete): Use the new public functions to make sure the C and dbus interfaces stay in sync. * system-settings/src/dbus-settings.c (list_connections): Return a list of connections. git-svn-id: http://svn-archive.gnome.org/svn/NetworkManager/trunk@3630 4912f4e0-d625-0410-9fb7-b9a5a253dbdc
This commit is contained in:
parent
9fdd6fb123
commit
17f26b8d31
45
ChangeLog
45
ChangeLog
|
@ -1,3 +1,48 @@
|
|||
2008-05-05 Tambet Ingo <tambet@gmail.com>
|
||||
|
||||
* libnm-glib/nm-dbus-settings.c (constructor): Fix the
|
||||
"PropertiesChanged" signal signature.
|
||||
|
||||
* libnm-glib/nm-dbus-connection.c (constructor): Use the common GType
|
||||
defined in nm-dbus-glib-types.h.
|
||||
Don't register the connection on dbus, we're a proxy class to
|
||||
communicate with an already registered connection over dbus.
|
||||
|
||||
2008-04-30 Tambet Ingo <tambet@gmail.com>
|
||||
|
||||
Implement new subclasses of NMSettings and NMExportedConnection to make
|
||||
it easier for the applet to access and modify system settings.
|
||||
|
||||
* libnm-glib/nm-dbus-connection.[ch]:
|
||||
* libnm-glib/nm-dbus-settings.[ch]:
|
||||
* libnm-glib/nm-dbus-settings-system.[ch]: Implement.
|
||||
|
||||
* libnm-glib/Makefile.am: Add the new files to build, generate some more
|
||||
bindings and glue.
|
||||
|
||||
* include/NetworkManager.h: Define the system settings DBus interface.
|
||||
|
||||
2008-04-30 Tambet Ingo <tambet@gmail.com>
|
||||
|
||||
Implement additional C API for exported connections to make them identical
|
||||
with the DBus API. Change the (list_connections) virtual function to be
|
||||
more usable from C - instead of requiring implementers to return a GPtrArray
|
||||
of dbus paths, return a list of connections.
|
||||
|
||||
* libnm-glib/nm-settings.c (nm_exported_connection_class_init): Fix a typo.
|
||||
(nm_settings_list_connections):
|
||||
(nm_exported_connection_new):
|
||||
(nm_exported_connection_update):
|
||||
(nm_exported_connection_delete): Implement.
|
||||
|
||||
(impl_settings_list_connections):
|
||||
(impl_exported_connection_update):
|
||||
(impl_exported_connection_delete): Use the new public functions to make
|
||||
sure the C and dbus interfaces stay in sync.
|
||||
|
||||
* system-settings/src/dbus-settings.c (list_connections): Return a list of
|
||||
connections.
|
||||
|
||||
2008-05-02 Dan Williams <dcbw@redhat.com>
|
||||
|
||||
* system-settings/plugins/ifcfg-fedora/plugin.c
|
||||
|
|
|
@ -43,6 +43,7 @@
|
|||
#define NM_DBUS_SERVICE_USER_SETTINGS "org.freedesktop.NetworkManagerUserSettings"
|
||||
#define NM_DBUS_SERVICE_SYSTEM_SETTINGS "org.freedesktop.NetworkManagerSystemSettings"
|
||||
#define NM_DBUS_IFACE_SETTINGS "org.freedesktop.NetworkManagerSettings"
|
||||
#define NM_DBUS_IFACE_SETTINGS_SYSTEM "org.freedesktop.NetworkManagerSettings.System"
|
||||
#define NM_DBUS_PATH_SETTINGS "/org/freedesktop/NetworkManagerSettings"
|
||||
|
||||
#define NM_DBUS_IFACE_SETTINGS_CONNECTION "org.freedesktop.NetworkManagerSettings.Connection"
|
||||
|
|
|
@ -10,7 +10,10 @@ BUILT_SOURCES = \
|
|||
nm-device-802-3-ethernet-bindings.h \
|
||||
nm-device-802-11-wireless-bindings.h \
|
||||
nm-exported-connection-glue.h \
|
||||
nm-exported-connection-bindings.h \
|
||||
nm-settings-glue.h \
|
||||
nm-settings-bindings.h \
|
||||
nm-settings-system-bindings.h
|
||||
nm-vpn-connection-bindings.h \
|
||||
nm-vpn-plugin-glue.h \
|
||||
nm-active-connection-bindings.h
|
||||
|
@ -41,7 +44,10 @@ libnminclude_HEADERS = \
|
|||
nm-vpn-connection.h \
|
||||
nm-vpn-plugin.h \
|
||||
nm-types.h \
|
||||
nm-active-connection.h
|
||||
nm-active-connection.h \
|
||||
nm-dbus-connection.h \
|
||||
nm-dbus-settings.h \
|
||||
nm-dbus-settings-system.h
|
||||
|
||||
libnm_glib_la_SOURCES = \
|
||||
libnm_glib.c \
|
||||
|
@ -64,7 +70,10 @@ libnm_glib_la_SOURCES = \
|
|||
nm-types-private.h \
|
||||
nm-object-cache.c \
|
||||
nm-object-cache.h \
|
||||
nm-active-connection.c
|
||||
nm-active-connection.c \
|
||||
nm-dbus-connection.c \
|
||||
nm-dbus-settings.c \
|
||||
nm-dbus-settings-system.c
|
||||
|
||||
libnm_glib_la_LIBADD = \
|
||||
$(top_builddir)/libnm-util/libnm-util.la \
|
||||
|
@ -104,9 +113,18 @@ nm-access-point-bindings.h: $(top_srcdir)/introspection/nm-access-point.xml
|
|||
nm-settings-glue.h: $(top_srcdir)/introspection/nm-settings.xml
|
||||
dbus-binding-tool --prefix=nm_settings --mode=glib-server --output=nm-settings-glue.h $(top_srcdir)/introspection/nm-settings.xml
|
||||
|
||||
nm-settings-bindings.h: $(top_srcdir)/introspection/nm-settings.xml
|
||||
dbus-binding-tool --prefix=nm_settings --mode=glib-client --output=nm-settings-bindings.h $(top_srcdir)/introspection/nm-settings.xml
|
||||
|
||||
nm-settings-system-bindings.h: $(top_srcdir)/introspection/nm-settings-system.xml
|
||||
dbus-binding-tool --prefix=nm_settings_system --mode=glib-client --output=nm-settings-system-bindings.h $(top_srcdir)/introspection/nm-settings-system.xml
|
||||
|
||||
nm-exported-connection-glue.h: $(top_srcdir)/introspection/nm-exported-connection.xml
|
||||
dbus-binding-tool --prefix=nm_exported_connection --mode=glib-server --output=nm-exported-connection-glue.h $(top_srcdir)/introspection/nm-exported-connection.xml
|
||||
|
||||
nm-exported-connection-bindings.h: $(top_srcdir)/introspection/nm-exported-connection.xml
|
||||
dbus-binding-tool --prefix=nm_exported_connection --mode=glib-client --output=nm-exported-connection-bindings.h $(top_srcdir)/introspection/nm-exported-connection.xml
|
||||
|
||||
nm-vpn-connection-bindings.h: $(top_srcdir)/introspection/nm-vpn-connection.xml
|
||||
dbus-binding-tool --prefix=nm_vpn_connection --mode=glib-client --output=nm-vpn-connection-bindings.h $(top_srcdir)/introspection/nm-vpn-connection.xml
|
||||
|
||||
|
|
317
libnm-glib/nm-dbus-connection.c
Normal file
317
libnm-glib/nm-dbus-connection.c
Normal file
|
@ -0,0 +1,317 @@
|
|||
/* -*- Mode: C; tab-width: 5; indent-tabs-mode: t; c-basic-offset: 5 -*- */
|
||||
|
||||
#include <string.h>
|
||||
#include <NetworkManager.h>
|
||||
#include <nm-dbus-glib-types.h>
|
||||
#include "nm-dbus-connection.h"
|
||||
#include "nm-exported-connection-bindings.h"
|
||||
#include "nm-utils.h"
|
||||
|
||||
G_DEFINE_TYPE (NMDBusConnection, nm_dbus_connection, NM_TYPE_EXPORTED_CONNECTION)
|
||||
|
||||
#define NM_DBUS_CONNECTION_GET_PRIVATE(o) (G_TYPE_INSTANCE_GET_PRIVATE ((o), NM_TYPE_DBUS_CONNECTION, NMDBusConnectionPrivate))
|
||||
|
||||
typedef struct {
|
||||
DBusGConnection *dbus_connection;
|
||||
NMConnectionScope scope;
|
||||
char *path;
|
||||
|
||||
DBusGProxy *proxy;
|
||||
|
||||
gboolean disposed;
|
||||
} NMDBusConnectionPrivate;
|
||||
|
||||
enum {
|
||||
PROP_0,
|
||||
PROP_BUS,
|
||||
PROP_SCOPE,
|
||||
PROP_PATH,
|
||||
|
||||
LAST_PROP
|
||||
};
|
||||
|
||||
NMDBusConnection *
|
||||
nm_dbus_connection_new (DBusGConnection *dbus_connection,
|
||||
NMConnectionScope scope,
|
||||
const char *path)
|
||||
{
|
||||
g_return_val_if_fail (dbus_connection != NULL, NULL);
|
||||
g_return_val_if_fail (scope != NM_CONNECTION_SCOPE_UNKNOWN, NULL);
|
||||
g_return_val_if_fail (path != NULL, NULL);
|
||||
|
||||
return (NMDBusConnection *) g_object_new (NM_TYPE_DBUS_CONNECTION,
|
||||
NM_DBUS_CONNECTION_BUS, dbus_connection,
|
||||
NM_DBUS_CONNECTION_SCOPE, scope,
|
||||
NM_DBUS_CONNECTION_PATH, path,
|
||||
NULL);
|
||||
}
|
||||
|
||||
static GHashTable *
|
||||
get_settings (NMExportedConnection *exported)
|
||||
{
|
||||
return nm_connection_to_hash (nm_exported_connection_get_connection (exported));
|
||||
}
|
||||
|
||||
static const char *
|
||||
get_id (NMExportedConnection *exported)
|
||||
{
|
||||
return NM_DBUS_CONNECTION_GET_PRIVATE (exported)->path;
|
||||
}
|
||||
|
||||
static void
|
||||
get_secrets (NMExportedConnection *connection,
|
||||
const gchar *setting_name,
|
||||
const gchar **hints,
|
||||
gboolean request_new,
|
||||
DBusGMethodInvocation *context)
|
||||
{
|
||||
/* FIXME: */
|
||||
g_warning ("Implement me");
|
||||
}
|
||||
|
||||
static void
|
||||
update (NMExportedConnection *exported, GHashTable *new_settings)
|
||||
{
|
||||
NMDBusConnectionPrivate *priv = NM_DBUS_CONNECTION_GET_PRIVATE (exported);
|
||||
GError *err = NULL;
|
||||
|
||||
if (!org_freedesktop_NetworkManagerSettings_Connection_update (priv->proxy, new_settings, &err)) {
|
||||
nm_warning ("Can not update dbus connection: %s", err->message);
|
||||
g_error_free (err);
|
||||
}
|
||||
}
|
||||
|
||||
static void
|
||||
delete (NMExportedConnection *exported)
|
||||
{
|
||||
NMDBusConnectionPrivate *priv = NM_DBUS_CONNECTION_GET_PRIVATE (exported);
|
||||
GError *err = NULL;
|
||||
|
||||
if (!org_freedesktop_NetworkManagerSettings_Connection_delete (priv->proxy, &err)) {
|
||||
nm_warning ("Can not delete dbus connection: %s", err->message);
|
||||
g_error_free (err);
|
||||
}
|
||||
}
|
||||
|
||||
static void
|
||||
connection_updated_cb (DBusGProxy *proxy, GHashTable *settings, gpointer user_data)
|
||||
{
|
||||
NMExportedConnection *exported = NM_EXPORTED_CONNECTION (user_data);
|
||||
NMConnection *wrapped;
|
||||
|
||||
wrapped = nm_exported_connection_get_connection (exported);
|
||||
if (nm_connection_replace_settings (wrapped, settings))
|
||||
nm_exported_connection_signal_updated (exported, settings);
|
||||
else
|
||||
nm_exported_connection_signal_removed (exported);
|
||||
}
|
||||
|
||||
static void
|
||||
connection_removed_cb (DBusGProxy *proxy, gpointer user_data)
|
||||
{
|
||||
nm_exported_connection_signal_removed (NM_EXPORTED_CONNECTION (user_data));
|
||||
}
|
||||
|
||||
/* GObject */
|
||||
|
||||
static void
|
||||
nm_dbus_connection_init (NMDBusConnection *connection)
|
||||
{
|
||||
}
|
||||
|
||||
static GObject *
|
||||
constructor (GType type,
|
||||
guint n_construct_params,
|
||||
GObjectConstructParam *construct_params)
|
||||
{
|
||||
GObject *object;
|
||||
NMDBusConnectionPrivate *priv;
|
||||
NMConnection *wrapped;
|
||||
const char *service;
|
||||
GHashTable *settings = NULL;
|
||||
GError *err = NULL;
|
||||
|
||||
object = G_OBJECT_CLASS (nm_dbus_connection_parent_class)->constructor (type, n_construct_params, construct_params);
|
||||
|
||||
if (!object)
|
||||
return NULL;
|
||||
|
||||
priv = NM_DBUS_CONNECTION_GET_PRIVATE (object);
|
||||
|
||||
if (!priv->dbus_connection) {
|
||||
nm_warning ("DBusGConnection not provided.");
|
||||
goto err;
|
||||
}
|
||||
|
||||
if (!priv->path)
|
||||
nm_warning ("DBus path not provided.");
|
||||
|
||||
service = (priv->scope == NM_CONNECTION_SCOPE_SYSTEM) ?
|
||||
NM_DBUS_SERVICE_SYSTEM_SETTINGS : NM_DBUS_SERVICE_USER_SETTINGS;
|
||||
|
||||
priv->proxy = dbus_g_proxy_new_for_name (priv->dbus_connection,
|
||||
service,
|
||||
priv->path,
|
||||
NM_DBUS_IFACE_SETTINGS_CONNECTION);
|
||||
|
||||
if (!org_freedesktop_NetworkManagerSettings_Connection_get_settings (priv->proxy, &settings, &err)) {
|
||||
nm_warning ("Can not retrieve settings: %s", err->message);
|
||||
g_error_free (err);
|
||||
goto err;
|
||||
}
|
||||
|
||||
wrapped = nm_connection_new_from_hash (settings);
|
||||
g_hash_table_destroy (settings);
|
||||
|
||||
if (!wrapped) {
|
||||
nm_warning ("Invalid settings");
|
||||
goto err;
|
||||
}
|
||||
|
||||
nm_connection_set_scope (wrapped, priv->scope);
|
||||
nm_connection_set_path (wrapped, priv->path);
|
||||
|
||||
g_object_set (object, NM_EXPORTED_CONNECTION_CONNECTION, wrapped, NULL);
|
||||
g_object_unref (wrapped);
|
||||
|
||||
dbus_g_proxy_add_signal (priv->proxy, "Updated",
|
||||
DBUS_TYPE_G_MAP_OF_MAP_OF_VARIANT,
|
||||
G_TYPE_INVALID);
|
||||
dbus_g_proxy_connect_signal (priv->proxy, "Updated",
|
||||
G_CALLBACK (connection_updated_cb),
|
||||
object, NULL);
|
||||
|
||||
dbus_g_proxy_add_signal (priv->proxy, "Removed", G_TYPE_INVALID, G_TYPE_INVALID);
|
||||
dbus_g_proxy_connect_signal (priv->proxy, "Removed",
|
||||
G_CALLBACK (connection_removed_cb),
|
||||
object, NULL);
|
||||
|
||||
return object;
|
||||
|
||||
err:
|
||||
g_object_unref (object);
|
||||
|
||||
return NULL;
|
||||
}
|
||||
|
||||
static void
|
||||
dispose (GObject *object)
|
||||
{
|
||||
NMDBusConnectionPrivate *priv = NM_DBUS_CONNECTION_GET_PRIVATE (object);
|
||||
|
||||
if (priv->disposed)
|
||||
return;
|
||||
|
||||
priv->disposed = TRUE;
|
||||
|
||||
g_object_unref (priv->proxy);
|
||||
dbus_g_connection_unref (priv->dbus_connection);
|
||||
|
||||
G_OBJECT_CLASS (nm_dbus_connection_parent_class)->dispose (object);
|
||||
}
|
||||
|
||||
static void
|
||||
finalize (GObject *object)
|
||||
{
|
||||
NMDBusConnectionPrivate *priv = NM_DBUS_CONNECTION_GET_PRIVATE (object);
|
||||
|
||||
g_free (priv->path);
|
||||
|
||||
G_OBJECT_CLASS (nm_dbus_connection_parent_class)->finalize (object);
|
||||
}
|
||||
|
||||
static void
|
||||
set_property (GObject *object, guint prop_id,
|
||||
const GValue *value, GParamSpec *pspec)
|
||||
{
|
||||
NMDBusConnectionPrivate *priv = NM_DBUS_CONNECTION_GET_PRIVATE (object);
|
||||
|
||||
switch (prop_id) {
|
||||
case PROP_BUS:
|
||||
/* Construct only */
|
||||
priv->dbus_connection = dbus_g_connection_ref ((DBusGConnection *) g_value_get_boxed (value));
|
||||
break;
|
||||
case PROP_SCOPE:
|
||||
/* Construct only */
|
||||
priv->scope = (NMConnectionScope) g_value_get_uint (value);
|
||||
break;
|
||||
case PROP_PATH:
|
||||
/* Construct only */
|
||||
priv->path = g_value_dup_string (value);
|
||||
break;
|
||||
default:
|
||||
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
static void
|
||||
get_property (GObject *object, guint prop_id,
|
||||
GValue *value, GParamSpec *pspec)
|
||||
{
|
||||
NMDBusConnectionPrivate *priv = NM_DBUS_CONNECTION_GET_PRIVATE (object);
|
||||
|
||||
switch (prop_id) {
|
||||
case PROP_BUS:
|
||||
g_value_set_boxed (value, priv->dbus_connection);
|
||||
break;
|
||||
case PROP_SCOPE:
|
||||
g_value_set_uint (value, priv->scope);
|
||||
break;
|
||||
case PROP_PATH:
|
||||
g_value_set_string (value, priv->path);
|
||||
break;
|
||||
default:
|
||||
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
static void
|
||||
nm_dbus_connection_class_init (NMDBusConnectionClass *dbus_connection_class)
|
||||
{
|
||||
GObjectClass *object_class = G_OBJECT_CLASS (dbus_connection_class);
|
||||
NMExportedConnectionClass *connection_class = NM_EXPORTED_CONNECTION_CLASS (dbus_connection_class);
|
||||
|
||||
g_type_class_add_private (dbus_connection_class, sizeof (NMDBusConnectionPrivate));
|
||||
|
||||
/* Virtual methods */
|
||||
object_class->constructor = constructor;
|
||||
object_class->set_property = set_property;
|
||||
object_class->get_property = get_property;
|
||||
object_class->dispose = dispose;
|
||||
object_class->finalize = finalize;
|
||||
|
||||
connection_class->get_settings = get_settings;
|
||||
connection_class->get_id = get_id;
|
||||
connection_class->get_secrets = get_secrets;
|
||||
connection_class->update = update;
|
||||
connection_class->delete = delete;
|
||||
|
||||
/* Properties */
|
||||
g_object_class_install_property
|
||||
(object_class, PROP_BUS,
|
||||
g_param_spec_boxed (NM_DBUS_CONNECTION_BUS,
|
||||
"DBusGConnection",
|
||||
"DBusGConnection",
|
||||
DBUS_TYPE_G_CONNECTION,
|
||||
G_PARAM_READWRITE | G_PARAM_CONSTRUCT_ONLY));
|
||||
|
||||
g_object_class_install_property
|
||||
(object_class, PROP_SCOPE,
|
||||
g_param_spec_uint (NM_DBUS_CONNECTION_SCOPE,
|
||||
"Scope",
|
||||
"NMConnection scope",
|
||||
NM_CONNECTION_SCOPE_UNKNOWN,
|
||||
NM_CONNECTION_SCOPE_USER,
|
||||
NM_CONNECTION_SCOPE_UNKNOWN,
|
||||
G_PARAM_READWRITE | G_PARAM_CONSTRUCT_ONLY));
|
||||
|
||||
g_object_class_install_property
|
||||
(object_class, PROP_PATH,
|
||||
g_param_spec_string (NM_DBUS_CONNECTION_PATH,
|
||||
"DBus path",
|
||||
"DBus path",
|
||||
NULL,
|
||||
G_PARAM_READWRITE | G_PARAM_CONSTRUCT_ONLY));
|
||||
}
|
38
libnm-glib/nm-dbus-connection.h
Normal file
38
libnm-glib/nm-dbus-connection.h
Normal file
|
@ -0,0 +1,38 @@
|
|||
/* -*- Mode: C; tab-width: 5; indent-tabs-mode: t; c-basic-offset: 5 -*- */
|
||||
|
||||
#ifndef NM_DBUS_CONNECTION_H
|
||||
#define NM_DBUS_CONNECTION_H
|
||||
|
||||
#include <dbus/dbus-glib.h>
|
||||
#include <nm-settings.h>
|
||||
|
||||
G_BEGIN_DECLS
|
||||
|
||||
#define NM_TYPE_DBUS_CONNECTION (nm_dbus_connection_get_type ())
|
||||
#define NM_DBUS_CONNECTION(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), NM_TYPE_DBUS_CONNECTION, NMDBusConnection))
|
||||
#define NM_DBUS_CONNECTION_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), NM_TYPE_DBUS_CONNECTION, NMDBusConnectionClass))
|
||||
#define NM_IS_DBUS_CONNECTION(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), NM_TYPE_DBUS_CONNECTION))
|
||||
#define NM_IS_DBUS_CONNECTION_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((obj), NM_TYPE_DBUS_CONNECTION))
|
||||
#define NM_DBUS_CONNECTION_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), NM_TYPE_DBUS_CONNECTION, NMDBusConnectionClass))
|
||||
|
||||
#define NM_DBUS_CONNECTION_BUS "bus"
|
||||
#define NM_DBUS_CONNECTION_SCOPE "scope"
|
||||
#define NM_DBUS_CONNECTION_PATH "path"
|
||||
|
||||
typedef struct {
|
||||
NMExportedConnection parent;
|
||||
} NMDBusConnection;
|
||||
|
||||
typedef struct {
|
||||
NMExportedConnectionClass parent;
|
||||
} NMDBusConnectionClass;
|
||||
|
||||
GType nm_dbus_connection_get_type (void);
|
||||
|
||||
NMDBusConnection *nm_dbus_connection_new (DBusGConnection *dbus_connection,
|
||||
NMConnectionScope scope,
|
||||
const char *path);
|
||||
|
||||
G_END_DECLS
|
||||
|
||||
#endif /* NM_DBUS_CONNECTION_H */
|
235
libnm-glib/nm-dbus-settings-system.c
Normal file
235
libnm-glib/nm-dbus-settings-system.c
Normal file
|
@ -0,0 +1,235 @@
|
|||
/* -*- Mode: C; tab-width: 5; indent-tabs-mode: t; c-basic-offset: 5 -*- */
|
||||
|
||||
#include <NetworkManager.h>
|
||||
#include <nm-dbus-glib-types.h>
|
||||
#include "nm-dbus-settings-system.h"
|
||||
#include "nm-settings-system-bindings.h"
|
||||
|
||||
G_DEFINE_TYPE (NMDBusSettingsSystem, nm_dbus_settings_system, NM_TYPE_DBUS_SETTINGS)
|
||||
|
||||
#define NM_DBUS_SETTINGS_SYSTEM_GET_PRIVATE(o) (G_TYPE_INSTANCE_GET_PRIVATE ((o), NM_TYPE_DBUS_SETTINGS_SYSTEM, NMDBusSettingsSystemPrivate))
|
||||
|
||||
typedef struct {
|
||||
DBusGProxy *settings_proxy;
|
||||
DBusGProxy *props_proxy;
|
||||
|
||||
gboolean got_unmanaged_devices;
|
||||
GSList *unmanaged_devices;
|
||||
|
||||
gboolean disposed;
|
||||
} NMDBusSettingsSystemPrivate;
|
||||
|
||||
enum {
|
||||
PROP_0,
|
||||
PROP_UNMANAGED_DEVICES,
|
||||
|
||||
LAST_PROP
|
||||
};
|
||||
|
||||
NMDBusSettingsSystem *
|
||||
nm_dbus_settings_system_new (DBusGConnection *dbus_connection)
|
||||
{
|
||||
g_return_val_if_fail (dbus_connection != NULL, NULL);
|
||||
|
||||
return (NMDBusSettingsSystem *) g_object_new (NM_TYPE_DBUS_SETTINGS_SYSTEM,
|
||||
NM_DBUS_SETTINGS_DBUS_CONNECTION, dbus_connection,
|
||||
NM_DBUS_SETTINGS_SCOPE, NM_CONNECTION_SCOPE_SYSTEM,
|
||||
NULL);
|
||||
}
|
||||
|
||||
void
|
||||
nm_dbus_settings_system_add_connection (NMDBusSettingsSystem *self,
|
||||
NMConnection *connection)
|
||||
{
|
||||
NMDBusSettingsSystemPrivate *priv;
|
||||
GHashTable *settings;
|
||||
GError *err = NULL;
|
||||
|
||||
g_return_if_fail (NM_IS_DBUS_SETTINGS_SYSTEM (self));
|
||||
g_return_if_fail (NM_IS_CONNECTION (connection));
|
||||
|
||||
priv = NM_DBUS_SETTINGS_SYSTEM_GET_PRIVATE (self);
|
||||
settings = nm_connection_to_hash (connection);
|
||||
|
||||
org_freedesktop_NetworkManagerSettings_System_add_connection (priv->settings_proxy, settings, &err);
|
||||
if (err) {
|
||||
g_warning ("Could not add system settings: %s", err->message);
|
||||
g_error_free (err);
|
||||
}
|
||||
|
||||
g_hash_table_destroy (settings);
|
||||
}
|
||||
|
||||
static void
|
||||
update_unmanaged_devices (NMDBusSettingsSystem *self, GValue *value)
|
||||
{
|
||||
NMDBusSettingsSystemPrivate *priv = NM_DBUS_SETTINGS_SYSTEM_GET_PRIVATE (self);
|
||||
|
||||
if (priv->unmanaged_devices) {
|
||||
g_slist_foreach (priv->unmanaged_devices, (GFunc) g_free, NULL);
|
||||
g_slist_free (priv->unmanaged_devices);
|
||||
priv->unmanaged_devices = NULL;
|
||||
}
|
||||
|
||||
if (G_VALUE_TYPE (value) == DBUS_TYPE_G_OBJECT_ARRAY) {
|
||||
GPtrArray *array;
|
||||
int i;
|
||||
|
||||
array = (GPtrArray *) g_value_get_boxed (value);
|
||||
for (i = 0; i < array->len; i++)
|
||||
priv->unmanaged_devices = g_slist_prepend (priv->unmanaged_devices,
|
||||
g_strdup ((const char *) g_ptr_array_index (array, i)));
|
||||
|
||||
priv->got_unmanaged_devices = TRUE;
|
||||
} else
|
||||
g_warning ("Invalid return value type: %s", G_VALUE_TYPE_NAME (&value));
|
||||
}
|
||||
|
||||
GSList *
|
||||
nm_dbus_settings_system_get_unmanaged_devices (NMDBusSettingsSystem *self)
|
||||
{
|
||||
NMDBusSettingsSystemPrivate *priv;
|
||||
GValue value = { 0, };
|
||||
GError *err = NULL;
|
||||
|
||||
g_return_val_if_fail (NM_IS_DBUS_SETTINGS_SYSTEM (self), NULL);
|
||||
|
||||
priv = NM_DBUS_SETTINGS_SYSTEM_GET_PRIVATE (self);
|
||||
|
||||
if (priv->got_unmanaged_devices)
|
||||
return priv->unmanaged_devices;
|
||||
|
||||
if (!dbus_g_proxy_call (priv->props_proxy, "Get", &err,
|
||||
G_TYPE_STRING, NM_DBUS_SERVICE_SYSTEM_SETTINGS,
|
||||
G_TYPE_STRING, "UnmanagedDevices",
|
||||
G_TYPE_INVALID,
|
||||
G_TYPE_VALUE, &value,
|
||||
G_TYPE_INVALID)) {
|
||||
g_warning ("Could not retrieve unmanaged devices: %s", err->message);
|
||||
g_error_free (err);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
update_unmanaged_devices (self, &value);
|
||||
g_value_unset (&value);
|
||||
|
||||
return priv->unmanaged_devices;
|
||||
}
|
||||
|
||||
static void
|
||||
proxy_properties_changed (DBusGProxy *proxy,
|
||||
GHashTable *properties,
|
||||
gpointer user_data)
|
||||
{
|
||||
NMDBusSettingsSystem *self = NM_DBUS_SETTINGS_SYSTEM (user_data);
|
||||
GValue *value;
|
||||
|
||||
value = (GValue *) g_hash_table_lookup (properties, "UnmanagedDevices");
|
||||
if (value) {
|
||||
update_unmanaged_devices (self, value);
|
||||
g_object_notify (G_OBJECT (self), NM_DBUS_SETTINGS_SYSTEM_UNMANAGED_DEVICES);
|
||||
}
|
||||
}
|
||||
|
||||
static void
|
||||
nm_dbus_settings_system_init (NMDBusSettingsSystem *self)
|
||||
{
|
||||
}
|
||||
|
||||
static GObject *
|
||||
constructor (GType type,
|
||||
guint n_construct_params,
|
||||
GObjectConstructParam *construct_params)
|
||||
{
|
||||
GObject *object;
|
||||
NMDBusSettingsSystemPrivate *priv;
|
||||
DBusGConnection *dbus_connection = NULL;
|
||||
|
||||
object = G_OBJECT_CLASS (nm_dbus_settings_system_parent_class)->constructor (type, n_construct_params, construct_params);
|
||||
|
||||
if (!object)
|
||||
return NULL;
|
||||
|
||||
priv = NM_DBUS_SETTINGS_SYSTEM_GET_PRIVATE (object);
|
||||
|
||||
g_object_get (object,
|
||||
NM_DBUS_SETTINGS_DBUS_CONNECTION, &dbus_connection,
|
||||
NULL);
|
||||
|
||||
priv->settings_proxy = dbus_g_proxy_new_for_name (dbus_connection,
|
||||
NM_DBUS_SERVICE_SYSTEM_SETTINGS,
|
||||
NM_DBUS_PATH_SETTINGS,
|
||||
NM_DBUS_IFACE_SETTINGS_SYSTEM);
|
||||
|
||||
priv->props_proxy = dbus_g_proxy_new_for_name (dbus_connection,
|
||||
NM_DBUS_SERVICE_SYSTEM_SETTINGS,
|
||||
NM_DBUS_PATH_SETTINGS,
|
||||
"org.freedesktop.DBus.Properties");
|
||||
|
||||
dbus_g_proxy_add_signal (priv->props_proxy, "PropertiesChanged",
|
||||
DBUS_TYPE_G_MAP_OF_VARIANT,
|
||||
G_TYPE_INVALID);
|
||||
dbus_g_proxy_connect_signal (priv->props_proxy, "PropertiesChanged",
|
||||
G_CALLBACK (proxy_properties_changed),
|
||||
object, NULL);
|
||||
|
||||
return object;
|
||||
}
|
||||
|
||||
static void
|
||||
dispose (GObject *object)
|
||||
{
|
||||
NMDBusSettingsSystemPrivate *priv = NM_DBUS_SETTINGS_SYSTEM_GET_PRIVATE (object);
|
||||
|
||||
if (priv->disposed)
|
||||
return;
|
||||
|
||||
priv->disposed = TRUE;
|
||||
|
||||
if (priv->unmanaged_devices) {
|
||||
g_slist_foreach (priv->unmanaged_devices, (GFunc) g_free, NULL);
|
||||
g_slist_free (priv->unmanaged_devices);
|
||||
}
|
||||
|
||||
g_object_unref (priv->settings_proxy);
|
||||
g_object_unref (priv->props_proxy);
|
||||
|
||||
G_OBJECT_CLASS (nm_dbus_settings_system_parent_class)->dispose (object);
|
||||
}
|
||||
|
||||
static void
|
||||
get_property (GObject *object, guint prop_id,
|
||||
GValue *value, GParamSpec *pspec)
|
||||
{
|
||||
NMDBusSettingsSystem *self = NM_DBUS_SETTINGS_SYSTEM (object);
|
||||
|
||||
switch (prop_id) {
|
||||
case PROP_UNMANAGED_DEVICES:
|
||||
g_value_set_pointer (value, nm_dbus_settings_system_get_unmanaged_devices (self));
|
||||
break;
|
||||
default:
|
||||
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
static void
|
||||
nm_dbus_settings_system_class_init (NMDBusSettingsSystemClass *dbus_settings_class)
|
||||
{
|
||||
GObjectClass *object_class = G_OBJECT_CLASS (dbus_settings_class);
|
||||
|
||||
g_type_class_add_private (dbus_settings_class, sizeof (NMDBusSettingsSystemPrivate));
|
||||
|
||||
/* Virtual methods */
|
||||
object_class->constructor = constructor;
|
||||
object_class->get_property = get_property;
|
||||
object_class->dispose = dispose;
|
||||
|
||||
/* Properties */
|
||||
g_object_class_install_property
|
||||
(object_class, PROP_UNMANAGED_DEVICES,
|
||||
g_param_spec_pointer (NM_DBUS_SETTINGS_SYSTEM_UNMANAGED_DEVICES,
|
||||
"Unmanaged devices",
|
||||
"Unmanaged devices",
|
||||
G_PARAM_READABLE));
|
||||
}
|
39
libnm-glib/nm-dbus-settings-system.h
Normal file
39
libnm-glib/nm-dbus-settings-system.h
Normal file
|
@ -0,0 +1,39 @@
|
|||
/* -*- Mode: C; tab-width: 5; indent-tabs-mode: t; c-basic-offset: 5 -*- */
|
||||
|
||||
#ifndef NM_DBUS_SETTINGS_SYSTEM_H
|
||||
#define NM_DBUS_SETTINGS_SYSTEM_H
|
||||
|
||||
#include <nm-dbus-settings.h>
|
||||
|
||||
G_BEGIN_DECLS
|
||||
|
||||
#define NM_TYPE_DBUS_SETTINGS_SYSTEM (nm_dbus_settings_system_get_type ())
|
||||
#define NM_DBUS_SETTINGS_SYSTEM(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), NM_TYPE_DBUS_SETTINGS_SYSTEM, NMDBusSettingsSystem))
|
||||
#define NM_DBUS_SETTINGS_SYSTEM_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), NM_TYPE_DBUS_SETTINGS_SYSTEM, NMDBusSettingsSystemClass))
|
||||
#define NM_IS_DBUS_SETTINGS_SYSTEM(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), NM_TYPE_DBUS_SETTINGS_SYSTEM))
|
||||
#define NM_IS_DBUS_SETTINGS_SYSTEM_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((obj), NM_TYPE_DBUS_SETTINGS_SYSTEM))
|
||||
#define NM_DBUS_SETTINGS_SYSTEM_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), NM_TYPE_DBUS_SETTINGS_SYSTEM, NMDBusSettingsSystemClass))
|
||||
|
||||
#define NM_DBUS_SETTINGS_SYSTEM_UNMANAGED_DEVICES "unmanaged-devices"
|
||||
|
||||
typedef struct {
|
||||
NMDBusSettings parent;
|
||||
} NMDBusSettingsSystem;
|
||||
|
||||
typedef struct {
|
||||
NMDBusSettingsClass parent;
|
||||
} NMDBusSettingsSystemClass;
|
||||
|
||||
GType nm_dbus_settings_system_get_type (void);
|
||||
|
||||
NMDBusSettingsSystem *nm_dbus_settings_system_new (DBusGConnection *dbus_connection);
|
||||
|
||||
void nm_dbus_settings_system_add_connection (NMDBusSettingsSystem *self,
|
||||
NMConnection *connection);
|
||||
|
||||
GSList *nm_dbus_settings_system_get_unmanaged_devices (NMDBusSettingsSystem *self);
|
||||
|
||||
|
||||
G_END_DECLS
|
||||
|
||||
#endif /* NM_DBUS_SETTINGS_SYSTEM_H */
|
350
libnm-glib/nm-dbus-settings.c
Normal file
350
libnm-glib/nm-dbus-settings.c
Normal file
|
@ -0,0 +1,350 @@
|
|||
/* -*- Mode: C; tab-width: 5; indent-tabs-mode: t; c-basic-offset: 5 -*- */
|
||||
|
||||
#include <string.h>
|
||||
#include <NetworkManager.h>
|
||||
#include <nm-connection.h>
|
||||
|
||||
#include "nm-dbus-settings.h"
|
||||
#include "nm-settings-bindings.h"
|
||||
|
||||
G_DEFINE_TYPE (NMDBusSettings, nm_dbus_settings, NM_TYPE_SETTINGS)
|
||||
|
||||
#define NM_DBUS_SETTINGS_GET_PRIVATE(o) (G_TYPE_INSTANCE_GET_PRIVATE ((o), NM_TYPE_DBUS_SETTINGS, NMDBusSettingsPrivate))
|
||||
|
||||
typedef struct {
|
||||
DBusGConnection *dbus_connection;
|
||||
NMConnectionScope scope;
|
||||
DBusGProxy *settings_proxy;
|
||||
DBusGProxy *dbus_proxy;
|
||||
|
||||
GHashTable *connections;
|
||||
|
||||
gboolean disposed;
|
||||
} NMDBusSettingsPrivate;
|
||||
|
||||
enum {
|
||||
PROP_0,
|
||||
PROP_DBUS_CONNECTION,
|
||||
PROP_SCOPE,
|
||||
|
||||
LAST_PROP
|
||||
};
|
||||
|
||||
NMDBusSettings *
|
||||
nm_dbus_settings_new (DBusGConnection *dbus_connection)
|
||||
{
|
||||
g_return_val_if_fail (dbus_connection != NULL, NULL);
|
||||
|
||||
return (NMDBusSettings *) g_object_new (NM_TYPE_DBUS_SETTINGS,
|
||||
NM_DBUS_SETTINGS_DBUS_CONNECTION, dbus_connection,
|
||||
NM_DBUS_SETTINGS_SCOPE, NM_CONNECTION_SCOPE_USER,
|
||||
NULL);
|
||||
}
|
||||
|
||||
NMDBusConnection *
|
||||
nm_dbus_settings_get_connection_by_path (NMDBusSettings *self, const char *path)
|
||||
{
|
||||
g_return_val_if_fail (NM_IS_DBUS_SETTINGS (self), NULL);
|
||||
g_return_val_if_fail (path != NULL, NULL);
|
||||
|
||||
return g_hash_table_lookup (NM_DBUS_SETTINGS_GET_PRIVATE (self)->connections, path);
|
||||
}
|
||||
|
||||
static void
|
||||
connection_removed_cb (NMExportedConnection *exported, gpointer user_data)
|
||||
{
|
||||
NMDBusSettingsPrivate *priv = NM_DBUS_SETTINGS_GET_PRIVATE (user_data);
|
||||
NMConnection *connection;
|
||||
|
||||
connection = nm_exported_connection_get_connection (exported);
|
||||
g_hash_table_remove (priv->connections, nm_connection_get_path (connection));
|
||||
}
|
||||
|
||||
static void
|
||||
new_connection_cb (DBusGProxy *proxy,
|
||||
const char *path,
|
||||
gpointer user_data)
|
||||
{
|
||||
NMDBusSettingsPrivate *priv = NM_DBUS_SETTINGS_GET_PRIVATE (user_data);
|
||||
NMDBusConnection *connection;
|
||||
|
||||
connection = nm_dbus_connection_new (priv->dbus_connection, priv->scope, path);
|
||||
if (connection) {
|
||||
g_signal_connect (connection, "removed",
|
||||
G_CALLBACK (connection_removed_cb),
|
||||
user_data);
|
||||
|
||||
g_hash_table_insert (priv->connections, g_strdup (path), connection);
|
||||
nm_settings_signal_new_connection (NM_SETTINGS (user_data),
|
||||
NM_EXPORTED_CONNECTION (connection));
|
||||
}
|
||||
}
|
||||
|
||||
static void
|
||||
fetch_connections_done (DBusGProxy *proxy,
|
||||
GPtrArray *connections,
|
||||
GError *err,
|
||||
gpointer user_data)
|
||||
{
|
||||
if (!err) {
|
||||
int i;
|
||||
|
||||
for (i = 0; i < connections->len; i++)
|
||||
new_connection_cb (proxy, g_ptr_array_index (connections, i), user_data);
|
||||
} else {
|
||||
g_warning ("Could not retrieve dbus connections: %s.", err->message);
|
||||
g_error_free (err);
|
||||
}
|
||||
|
||||
if (connections)
|
||||
g_ptr_array_free (connections, TRUE);
|
||||
}
|
||||
|
||||
static void
|
||||
settings_proxy_destroyed (gpointer data, GObject *destroyed_object)
|
||||
{
|
||||
NM_DBUS_SETTINGS_GET_PRIVATE (data)->settings_proxy = NULL;
|
||||
}
|
||||
|
||||
static gboolean
|
||||
fetch_connections (gpointer data)
|
||||
{
|
||||
NMDBusSettingsPrivate *priv = NM_DBUS_SETTINGS_GET_PRIVATE (data);
|
||||
DBusGProxyCall *call;
|
||||
|
||||
if (!priv->settings_proxy) {
|
||||
const char *service = (priv->scope == NM_CONNECTION_SCOPE_SYSTEM) ?
|
||||
NM_DBUS_SERVICE_SYSTEM_SETTINGS : NM_DBUS_SERVICE_USER_SETTINGS;
|
||||
|
||||
priv->settings_proxy = dbus_g_proxy_new_for_name (priv->dbus_connection,
|
||||
service,
|
||||
NM_DBUS_PATH_SETTINGS,
|
||||
NM_DBUS_IFACE_SETTINGS);
|
||||
|
||||
g_object_weak_ref (G_OBJECT (priv->settings_proxy), settings_proxy_destroyed, data);
|
||||
|
||||
dbus_g_proxy_add_signal (priv->settings_proxy, "NewConnection",
|
||||
DBUS_TYPE_G_OBJECT_PATH,
|
||||
G_TYPE_INVALID);
|
||||
|
||||
dbus_g_proxy_connect_signal (priv->settings_proxy, "NewConnection",
|
||||
G_CALLBACK (new_connection_cb),
|
||||
data,
|
||||
NULL);
|
||||
}
|
||||
|
||||
call = org_freedesktop_NetworkManagerSettings_list_connections_async (priv->settings_proxy,
|
||||
fetch_connections_done,
|
||||
data);
|
||||
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
static void
|
||||
hash_values_to_slist (gpointer key, gpointer data, gpointer user_data)
|
||||
{
|
||||
GSList **list = (GSList **) user_data;
|
||||
|
||||
*list = g_slist_prepend (*list, data);
|
||||
}
|
||||
|
||||
static GSList *
|
||||
list_connections (NMSettings *settings)
|
||||
{
|
||||
GSList *list = NULL;
|
||||
|
||||
g_return_val_if_fail (NM_IS_DBUS_SETTINGS (settings), NULL);
|
||||
|
||||
g_hash_table_foreach (NM_DBUS_SETTINGS_GET_PRIVATE (settings)->connections, hash_values_to_slist, &list);
|
||||
|
||||
return list;
|
||||
}
|
||||
|
||||
static void
|
||||
remove_one_connection (gpointer key, gpointer value, gpointer user_data)
|
||||
{
|
||||
nm_exported_connection_signal_removed (NM_EXPORTED_CONNECTION (value));
|
||||
}
|
||||
|
||||
static gboolean
|
||||
remove_connections (gpointer data)
|
||||
{
|
||||
NMDBusSettings *self = NM_DBUS_SETTINGS (data);
|
||||
NMDBusSettingsPrivate *priv = NM_DBUS_SETTINGS_GET_PRIVATE (self);
|
||||
|
||||
g_hash_table_foreach (priv->connections, remove_one_connection, NULL);
|
||||
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
static void
|
||||
name_owner_changed (DBusGProxy *proxy,
|
||||
const char *name,
|
||||
const char *old_owner,
|
||||
const char *new_owner,
|
||||
gpointer user_data)
|
||||
{
|
||||
if (!strcmp (name, NM_DBUS_SERVICE_SYSTEM_SETTINGS)) {
|
||||
if (new_owner && strlen (new_owner) > 0)
|
||||
g_idle_add (fetch_connections, user_data);
|
||||
else
|
||||
g_idle_add (remove_connections, user_data);
|
||||
}
|
||||
}
|
||||
|
||||
/* GObject stuff */
|
||||
|
||||
static void
|
||||
nm_dbus_settings_init (NMDBusSettings *settings)
|
||||
{
|
||||
NMDBusSettingsPrivate *priv = NM_DBUS_SETTINGS_GET_PRIVATE (settings);
|
||||
|
||||
priv->connections = g_hash_table_new_full (g_str_hash, g_str_equal, g_free, g_object_unref);
|
||||
}
|
||||
|
||||
static GObject *
|
||||
constructor (GType type,
|
||||
guint n_construct_params,
|
||||
GObjectConstructParam *construct_params)
|
||||
{
|
||||
GObject *object;
|
||||
NMDBusSettingsPrivate *priv;
|
||||
|
||||
object = G_OBJECT_CLASS (nm_dbus_settings_parent_class)->constructor (type, n_construct_params, construct_params);
|
||||
|
||||
if (!object)
|
||||
return NULL;
|
||||
|
||||
priv = NM_DBUS_SETTINGS_GET_PRIVATE (object);
|
||||
|
||||
if (!priv->dbus_connection) {
|
||||
g_warning ("DBus connection not provided.");
|
||||
goto err;
|
||||
}
|
||||
|
||||
if (priv->scope == NM_CONNECTION_SCOPE_UNKNOWN) {
|
||||
g_warning ("Connection scope not provided.");
|
||||
goto err;
|
||||
}
|
||||
|
||||
priv->dbus_proxy = dbus_g_proxy_new_for_name (priv->dbus_connection,
|
||||
"org.freedesktop.DBus",
|
||||
"/org/freedesktop/DBus",
|
||||
"org.freedesktop.DBus");
|
||||
|
||||
dbus_g_proxy_add_signal (priv->dbus_proxy, "NameOwnerChanged",
|
||||
G_TYPE_STRING, G_TYPE_STRING, G_TYPE_STRING,
|
||||
G_TYPE_INVALID);
|
||||
dbus_g_proxy_connect_signal (priv->dbus_proxy,
|
||||
"NameOwnerChanged",
|
||||
G_CALLBACK (name_owner_changed),
|
||||
object, NULL);
|
||||
|
||||
g_idle_add (fetch_connections, object);
|
||||
|
||||
return object;
|
||||
|
||||
err:
|
||||
g_object_unref (object);
|
||||
|
||||
return NULL;
|
||||
}
|
||||
|
||||
static void
|
||||
dispose (GObject *object)
|
||||
{
|
||||
NMDBusSettingsPrivate *priv = NM_DBUS_SETTINGS_GET_PRIVATE (object);
|
||||
|
||||
if (priv->disposed)
|
||||
return;
|
||||
|
||||
priv->disposed = TRUE;
|
||||
|
||||
if (priv->connections)
|
||||
g_hash_table_destroy (priv->connections);
|
||||
|
||||
if (priv->dbus_proxy)
|
||||
g_object_unref (priv->dbus_proxy);
|
||||
|
||||
if (priv->settings_proxy)
|
||||
g_object_unref (priv->settings_proxy);
|
||||
|
||||
dbus_g_connection_unref (priv->dbus_connection);
|
||||
|
||||
G_OBJECT_CLASS (nm_dbus_settings_parent_class)->dispose (object);
|
||||
}
|
||||
|
||||
static void
|
||||
set_property (GObject *object, guint prop_id,
|
||||
const GValue *value, GParamSpec *pspec)
|
||||
{
|
||||
NMDBusSettingsPrivate *priv = NM_DBUS_SETTINGS_GET_PRIVATE (object);
|
||||
|
||||
switch (prop_id) {
|
||||
case PROP_DBUS_CONNECTION:
|
||||
/* Construct only */
|
||||
priv->dbus_connection = dbus_g_connection_ref ((DBusGConnection *) g_value_get_boxed (value));
|
||||
break;
|
||||
case PROP_SCOPE:
|
||||
priv->scope = (NMConnectionScope) g_value_get_uint (value);
|
||||
break;
|
||||
default:
|
||||
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
static void
|
||||
get_property (GObject *object, guint prop_id,
|
||||
GValue *value, GParamSpec *pspec)
|
||||
{
|
||||
NMDBusSettingsPrivate *priv = NM_DBUS_SETTINGS_GET_PRIVATE (object);
|
||||
|
||||
switch (prop_id) {
|
||||
case PROP_DBUS_CONNECTION:
|
||||
g_value_set_boxed (value, priv->dbus_connection);
|
||||
break;
|
||||
case PROP_SCOPE:
|
||||
g_value_set_uint (value, priv->scope);
|
||||
break;
|
||||
default:
|
||||
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
static void
|
||||
nm_dbus_settings_class_init (NMDBusSettingsClass *dbus_settings_class)
|
||||
{
|
||||
GObjectClass *object_class = G_OBJECT_CLASS (dbus_settings_class);
|
||||
NMSettingsClass *settings_class = NM_SETTINGS_CLASS (dbus_settings_class);
|
||||
|
||||
g_type_class_add_private (dbus_settings_class, sizeof (NMDBusSettingsPrivate));
|
||||
|
||||
/* Virtual methods */
|
||||
object_class->constructor = constructor;
|
||||
object_class->set_property = set_property;
|
||||
object_class->get_property = get_property;
|
||||
object_class->dispose = dispose;
|
||||
|
||||
settings_class->list_connections = list_connections;
|
||||
|
||||
/* Properties */
|
||||
g_object_class_install_property
|
||||
(object_class, PROP_DBUS_CONNECTION,
|
||||
g_param_spec_boxed (NM_DBUS_SETTINGS_DBUS_CONNECTION,
|
||||
"DBusGConnection",
|
||||
"DBusGConnection",
|
||||
DBUS_TYPE_G_CONNECTION,
|
||||
G_PARAM_READWRITE | G_PARAM_CONSTRUCT_ONLY));
|
||||
|
||||
g_object_class_install_property
|
||||
(object_class, PROP_SCOPE,
|
||||
g_param_spec_uint (NM_DBUS_SETTINGS_SCOPE,
|
||||
"Scope",
|
||||
"NMConnection scope",
|
||||
NM_CONNECTION_SCOPE_UNKNOWN,
|
||||
NM_CONNECTION_SCOPE_USER,
|
||||
NM_CONNECTION_SCOPE_USER,
|
||||
G_PARAM_READWRITE | G_PARAM_CONSTRUCT_ONLY));
|
||||
}
|
40
libnm-glib/nm-dbus-settings.h
Normal file
40
libnm-glib/nm-dbus-settings.h
Normal file
|
@ -0,0 +1,40 @@
|
|||
/* -*- Mode: C; tab-width: 5; indent-tabs-mode: t; c-basic-offset: 5 -*- */
|
||||
|
||||
#ifndef NM_DBUS_SETTINGS_H
|
||||
#define NM_DBUS_SETTINGS_H
|
||||
|
||||
#include <dbus/dbus-glib.h>
|
||||
#include <nm-connection.h>
|
||||
#include <nm-settings.h>
|
||||
#include <nm-dbus-connection.h>
|
||||
|
||||
G_BEGIN_DECLS
|
||||
|
||||
#define NM_TYPE_DBUS_SETTINGS (nm_dbus_settings_get_type ())
|
||||
#define NM_DBUS_SETTINGS(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), NM_TYPE_DBUS_SETTINGS, NMDBusSettings))
|
||||
#define NM_DBUS_SETTINGS_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), NM_TYPE_DBUS_SETTINGS, NMDBusSettingsClass))
|
||||
#define NM_IS_DBUS_SETTINGS(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), NM_TYPE_DBUS_SETTINGS))
|
||||
#define NM_IS_DBUS_SETTINGS_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((obj), NM_TYPE_DBUS_SETTINGS))
|
||||
#define NM_DBUS_SETTINGS_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), NM_TYPE_DBUS_SETTINGS, NMDBusSettingsClass))
|
||||
|
||||
#define NM_DBUS_SETTINGS_DBUS_CONNECTION "dbus-connection"
|
||||
#define NM_DBUS_SETTINGS_SCOPE "scope"
|
||||
|
||||
typedef struct {
|
||||
NMSettings parent;
|
||||
} NMDBusSettings;
|
||||
|
||||
typedef struct {
|
||||
NMSettingsClass parent;
|
||||
} NMDBusSettingsClass;
|
||||
|
||||
GType nm_dbus_settings_get_type (void);
|
||||
|
||||
NMDBusSettings *nm_dbus_settings_new (DBusGConnection *dbus_connection);
|
||||
|
||||
NMDBusConnection *nm_dbus_settings_get_connection_by_path (NMDBusSettings *self,
|
||||
const char *path);
|
||||
|
||||
G_END_DECLS
|
||||
|
||||
#endif /* NM_DBUS_SETTINGS_H */
|
|
@ -1,3 +1,5 @@
|
|||
/* -*- Mode: C; tab-width: 5; indent-tabs-mode: t; c-basic-offset: 5 -*- */
|
||||
|
||||
#include <NetworkManager.h>
|
||||
#include <nm-utils.h>
|
||||
#include <nm-setting-connection.h>
|
||||
|
@ -38,16 +40,20 @@ static guint settings_signals[S_LAST_SIGNAL] = { 0 };
|
|||
static gboolean
|
||||
impl_settings_list_connections (NMSettings *settings, GPtrArray **connections, GError **error)
|
||||
{
|
||||
GSList *list, *iter;
|
||||
|
||||
g_return_val_if_fail (NM_IS_SETTINGS (settings), FALSE);
|
||||
|
||||
if (!SETTINGS_CLASS (settings)->list_connections) {
|
||||
g_set_error (error, NM_SETTINGS_ERROR, 1,
|
||||
"%s.%d - Missing implementation for Settings::list_connections.",
|
||||
__FILE__, __LINE__);
|
||||
return FALSE;
|
||||
list = nm_settings_list_connections (settings);
|
||||
|
||||
*connections = g_ptr_array_new ();
|
||||
for (iter = list; iter; iter = iter->next) {
|
||||
NMConnection *connection = nm_exported_connection_get_connection (NM_EXPORTED_CONNECTION (iter->data));
|
||||
|
||||
g_ptr_array_add (*connections, g_strdup (nm_connection_get_path (connection)));
|
||||
}
|
||||
|
||||
*connections = SETTINGS_CLASS (settings)->list_connections (settings);
|
||||
g_slist_free (list);
|
||||
|
||||
return TRUE;
|
||||
}
|
||||
|
@ -88,6 +94,21 @@ nm_settings_class_init (NMSettingsClass *settings_class)
|
|||
&dbus_glib_nm_settings_object_info);
|
||||
}
|
||||
|
||||
GSList *
|
||||
nm_settings_list_connections (NMSettings *settings)
|
||||
{
|
||||
GSList *list = NULL;
|
||||
|
||||
g_return_val_if_fail (NM_IS_SETTINGS (settings), NULL);
|
||||
|
||||
if (SETTINGS_CLASS (settings)->list_connections)
|
||||
list = SETTINGS_CLASS (settings)->list_connections (settings);
|
||||
else
|
||||
g_warning ("Missing implementation for Settings::list_connections.");
|
||||
|
||||
return list;
|
||||
}
|
||||
|
||||
void
|
||||
nm_settings_signal_new_connection (NMSettings *settings, NMExportedConnection *connection)
|
||||
{
|
||||
|
@ -151,6 +172,16 @@ typedef struct {
|
|||
NM_TYPE_EXPORTED_CONNECTION, \
|
||||
NMExportedConnectionPrivate))
|
||||
|
||||
NMExportedConnection *
|
||||
nm_exported_connection_new (NMConnection *wrapped)
|
||||
{
|
||||
g_return_val_if_fail (NM_IS_CONNECTION (wrapped), NULL);
|
||||
|
||||
return (NMExportedConnection *) g_object_new (NM_TYPE_EXPORTED_CONNECTION,
|
||||
NM_EXPORTED_CONNECTION_CONNECTION, wrapped,
|
||||
NULL);
|
||||
}
|
||||
|
||||
const char *
|
||||
nm_exported_connection_get_id (NMExportedConnection *connection)
|
||||
{
|
||||
|
@ -212,12 +243,7 @@ impl_exported_connection_update (NMExportedConnection *connection,
|
|||
GHashTable *new_settings,
|
||||
GError *err)
|
||||
{
|
||||
if (EXPORTED_CONNECTION_CLASS (connection)->update)
|
||||
EXPORTED_CONNECTION_CLASS (connection)->update (connection, new_settings);
|
||||
else
|
||||
nm_connection_replace_settings (NM_EXPORTED_CONNECTION_GET_PRIVATE (connection)->wrapped, new_settings);
|
||||
|
||||
nm_exported_connection_signal_updated (connection, new_settings);
|
||||
nm_exported_connection_update (connection, new_settings);
|
||||
|
||||
return TRUE;
|
||||
}
|
||||
|
@ -225,10 +251,7 @@ impl_exported_connection_update (NMExportedConnection *connection,
|
|||
static gboolean
|
||||
impl_exported_connection_delete (NMExportedConnection *connection, GError *err)
|
||||
{
|
||||
if (EXPORTED_CONNECTION_CLASS (connection)->delete)
|
||||
EXPORTED_CONNECTION_CLASS (connection)->delete (connection);
|
||||
|
||||
nm_exported_connection_signal_removed (connection);
|
||||
nm_exported_connection_delete (connection);
|
||||
|
||||
return TRUE;
|
||||
}
|
||||
|
@ -353,7 +376,7 @@ nm_exported_connection_class_init (NMExportedConnectionClass *exported_connectio
|
|||
G_SIGNAL_RUN_FIRST,
|
||||
G_STRUCT_OFFSET (NMExportedConnectionClass, updated),
|
||||
NULL, NULL,
|
||||
g_cclosure_marshal_VOID__POINTER,
|
||||
g_cclosure_marshal_VOID__BOXED,
|
||||
G_TYPE_NONE, 1,
|
||||
DBUS_TYPE_G_MAP_OF_MAP_OF_VARIANT);
|
||||
|
||||
|
@ -402,6 +425,32 @@ nm_exported_connection_register_object (NMExportedConnection *connection,
|
|||
g_free (path);
|
||||
}
|
||||
|
||||
void
|
||||
nm_exported_connection_update (NMExportedConnection *connection,
|
||||
GHashTable *new_settings)
|
||||
{
|
||||
g_return_if_fail (NM_IS_EXPORTED_CONNECTION (connection));
|
||||
g_return_if_fail (new_settings != NULL);
|
||||
|
||||
nm_connection_replace_settings (NM_EXPORTED_CONNECTION_GET_PRIVATE (connection)->wrapped, new_settings);
|
||||
|
||||
if (EXPORTED_CONNECTION_CLASS (connection)->update)
|
||||
EXPORTED_CONNECTION_CLASS (connection)->update (connection, new_settings);
|
||||
|
||||
nm_exported_connection_signal_updated (connection, new_settings);
|
||||
}
|
||||
|
||||
void
|
||||
nm_exported_connection_delete (NMExportedConnection *connection)
|
||||
{
|
||||
g_return_if_fail (NM_IS_EXPORTED_CONNECTION (connection));
|
||||
|
||||
if (EXPORTED_CONNECTION_CLASS (connection)->delete)
|
||||
EXPORTED_CONNECTION_CLASS (connection)->delete (connection);
|
||||
|
||||
nm_exported_connection_signal_removed (connection);
|
||||
}
|
||||
|
||||
void
|
||||
nm_exported_connection_signal_updated (NMExportedConnection *connection, GHashTable *settings)
|
||||
{
|
||||
|
|
|
@ -49,6 +49,8 @@ typedef struct {
|
|||
|
||||
GType nm_exported_connection_get_type (void);
|
||||
|
||||
NMExportedConnection *nm_exported_connection_new (NMConnection *wrapped);
|
||||
|
||||
void nm_exported_connection_register_object (NMExportedConnection *connection,
|
||||
NMConnectionScope scope,
|
||||
DBusGConnection *dbus_connection);
|
||||
|
@ -57,7 +59,14 @@ NMConnection *nm_exported_connection_get_connection (NMExportedConnection *conne
|
|||
|
||||
const char *nm_exported_connection_get_id (NMExportedConnection *connection);
|
||||
|
||||
void nm_exported_connection_signal_updated (NMExportedConnection *connection, GHashTable *settings);
|
||||
void nm_exported_connection_update (NMExportedConnection *connection,
|
||||
GHashTable *new_settings);
|
||||
|
||||
void nm_exported_connection_delete (NMExportedConnection *connection);
|
||||
|
||||
void nm_exported_connection_signal_updated (NMExportedConnection *connection,
|
||||
GHashTable *new_settings);
|
||||
|
||||
void nm_exported_connection_signal_removed (NMExportedConnection *connection);
|
||||
|
||||
|
||||
|
@ -77,7 +86,8 @@ typedef struct {
|
|||
GObjectClass parent_class;
|
||||
|
||||
/* virtual methods */
|
||||
GPtrArray * (* list_connections) (NMSettings *settings);
|
||||
/* Returns a list of NMExportedConnections. Caller should free the list. */
|
||||
GSList * (*list_connections) (NMSettings *settings);
|
||||
|
||||
/* signals */
|
||||
void (* new_connection) (NMSettings *settings, NMExportedConnection *connection);
|
||||
|
@ -85,8 +95,11 @@ typedef struct {
|
|||
|
||||
GType nm_settings_get_type (void);
|
||||
|
||||
GSList *nm_settings_list_connections (NMSettings *settings);
|
||||
|
||||
void nm_settings_signal_new_connection (NMSettings *settings, NMExportedConnection *connection);
|
||||
|
||||
|
||||
G_END_DECLS
|
||||
|
||||
#endif
|
||||
|
|
|
@ -213,27 +213,12 @@ enum {
|
|||
LAST_PROP
|
||||
};
|
||||
|
||||
static GPtrArray *
|
||||
static GSList *
|
||||
list_connections (NMSettings *settings)
|
||||
{
|
||||
NMSysconfigSettings *self = NM_SYSCONFIG_SETTINGS (settings);
|
||||
GPtrArray *connections;
|
||||
GSList *iter;
|
||||
|
||||
connections = g_ptr_array_new ();
|
||||
for (iter = nm_sysconfig_settings_get_connections (self); iter; iter = g_slist_next (iter)) {
|
||||
NMExportedConnection *exported = NM_EXPORTED_CONNECTION (iter->data);
|
||||
NMConnection *connection;
|
||||
char *path;
|
||||
|
||||
connection = nm_exported_connection_get_connection (exported);
|
||||
path = g_strdup (nm_connection_get_path (connection));
|
||||
if (path)
|
||||
g_ptr_array_add (connections, path);
|
||||
}
|
||||
|
||||
/* Return a list of strings with paths to connection settings objects */
|
||||
return connections;
|
||||
return g_slist_copy (nm_sysconfig_settings_get_connections (self));
|
||||
}
|
||||
|
||||
static void
|
||||
|
|
Loading…
Reference in a new issue