diff --git a/ChangeLog b/ChangeLog index 150491a8ad..a067ab8d5f 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,13 @@ +2007-08-03 Rodrigo Moya + + * introspection/Makefile.am: + * introspection/nm-settings.xml: + * introspection/nm-settings-connection.xml: added Settings interfaces. + + * libnm-glib/nm-settings.[ch]: + * libnm-glib/Makefile.am: added abstract class for Settings interfaces + containing the DBus implementation. + 2007-07-26 Dan Williams Patch from Bernhard Miklautz diff --git a/introspection/Makefile.am b/introspection/Makefile.am index 1ebc1663e2..443c044005 100644 --- a/introspection/Makefile.am +++ b/introspection/Makefile.am @@ -4,4 +4,6 @@ EXTRA_DIST = \ nm-device-802-3-ethernet.xml \ nm-device.xml \ nm-ip4-config.xml \ - nm-manager.xml + nm-manager.xml \ + nm-settings.xml \ + nm-settings-connection.xml diff --git a/introspection/nm-settings-connection.xml b/introspection/nm-settings-connection.xml new file mode 100644 index 0000000000..1c05e1b2d2 --- /dev/null +++ b/introspection/nm-settings-connection.xml @@ -0,0 +1,32 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/introspection/nm-settings.xml b/introspection/nm-settings.xml new file mode 100644 index 0000000000..04cf597c47 --- /dev/null +++ b/introspection/nm-settings.xml @@ -0,0 +1,18 @@ + + + + + + + + + + + + + + + + + + diff --git a/libnm-glib/Makefile.am b/libnm-glib/Makefile.am index 1d10078e99..f2d6689c67 100644 --- a/libnm-glib/Makefile.am +++ b/libnm-glib/Makefile.am @@ -1,19 +1,23 @@ INCLUDES = -I$(top_srcdir)/include -I$(top_srcdir)/libnm-util BUILT_SOURCES = \ + nm-access-point-bindings.h \ nm-client-bindings.h \ nm-device-bindings.h \ nm-device-802-3-ethernet-bindings.h \ nm-device-802-11-wireless-bindings.h \ - nm-access-point-bindings.h \ nm-marshal.h \ - nm-marshal.c + nm-marshal.c \ + nm-settings-connection-glue.h \ + nm-settings-glue.h lib_LTLIBRARIES = libnm-glib.la -libnm_glib_la_CFLAGS = \ - $(GLIB_CFLAGS) \ - $(DBUS_CFLAGS) +libnm_glib_la_CFLAGS = \ + $(GLIB_CFLAGS) \ + $(DBUS_CFLAGS) \ + $(GCONF_CFLAGS) \ + $(GNOME_KEYRING_CFLAGS) libnmincludedir = $(includedir)/libnm-glib @@ -25,6 +29,7 @@ libnminclude_HEADERS = \ nm-device-802-11-wireless.h \ nm-access-point.h \ nm-ip4-config.h \ + nm-settings.h \ nm-vpn-connection.h libnm_glib_la_SOURCES = \ @@ -36,13 +41,16 @@ libnm_glib_la_SOURCES = \ nm-device-802-11-wireless.c \ nm-access-point.c \ nm-ip4-config.c \ + nm-settings.c \ nm-vpn-connection.c \ nm-marshal-main.c libnm_glib_la_LIBADD = \ $(top_builddir)/libnm-util/libnm-util.la \ $(GLIB_LIBS) \ - $(DBUS_LIBS) + $(DBUS_LIBS) \ + $(GCONF_LIBS) \ + $(GNOME_KEYRING_LIBS) noinst_PROGRAMS = libnm-glib-test @@ -79,6 +87,11 @@ nm-device-802-11-wireless-bindings.h: $(top_srcdir)/introspection/nm-device-802- nm-access-point-bindings.h: $(top_srcdir)/introspection/nm-access-point.xml dbus-binding-tool --prefix=nm_access_point --mode=glib-client --output=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-connection-glue.h: $(top_srcdir)/introspection/nm-settings-connection.xml + dbus-binding-tool --prefix=nm_connection_settings --mode=glib-server --output=nm-settings-connection-glue.h $(top_srcdir)/introspection/nm-settings-connection.xml pkgconfigdir = $(libdir)/pkgconfig pkgconfig_DATA = libnm-glib.pc diff --git a/libnm-glib/nm-settings.c b/libnm-glib/nm-settings.c new file mode 100644 index 0000000000..cea9dda82e --- /dev/null +++ b/libnm-glib/nm-settings.c @@ -0,0 +1,223 @@ +#include "nm-settings.h" + +static GError * +new_error (const gchar *format, ...) +{ + GError *err; + va_list args; + gchar *msg; + static GQuark domain_quark = 0; + + va_start (args, format); + msg = g_strdup_vprintf (format, args); + va_end (args); + + if (domain_quark == 0) { + domain_quark = g_quark_from_static_string ("nm-settings-error-quark"); + } + + err = g_error_new_literal (domain_quark, -1, (const gchar *) msg); + + g_free (msg); + + return err; +} + +/* + * NMSettings implementation + */ + +static gboolean impl_settings_list_connections (NMSettings *settings, GPtrArray **connections, GError **error); + +#include "nm-settings-glue.h" + +#define SETTINGS_CLASS(o) (NM_SETTINGS_CLASS (G_OBJECT_GET_CLASS (o))) + +G_DEFINE_TYPE (NMSettings, nm_settings, G_TYPE_OBJECT) + +enum { + S_NEW_CONNECTION, + + S_LAST_SIGNAL +}; + +static guint settings_signals[S_LAST_SIGNAL] = { 0 }; + +static gboolean +impl_settings_list_connections (NMSettings *settings, GPtrArray **connections, GError **error) +{ + g_return_val_if_fail (NM_IS_SETTINGS (settings), FALSE); + + if (!SETTINGS_CLASS (settings)->list_connections) { + *error = new_error ("%s.%d - Missing implementation for Settings::list_connections.", __FILE__, __LINE__); + return FALSE; + } + + *connections = SETTINGS_CLASS (settings)->list_connections (settings); + + return TRUE; +} + +static void +nm_settings_init (NMSettings *settings) +{ +} + +static void +nm_settings_finalize (GObject *object) +{ + G_OBJECT_CLASS (nm_settings_parent_class)->finalize (object); +} + +static void +nm_settings_class_init (NMSettingsClass *settings_class) +{ + GObjectClass *object_class = G_OBJECT_CLASS (settings_class); + + /* virtual methods */ + object_class->finalize = nm_settings_finalize; + + settings_class->list_connections = NULL; + + /* signals */ + settings_signals[S_NEW_CONNECTION] = + g_signal_new ("new-connection", + G_OBJECT_CLASS_TYPE (object_class), + G_SIGNAL_RUN_FIRST, + G_STRUCT_OFFSET (NMSettingsClass, new_connection), + NULL, NULL, + g_cclosure_marshal_VOID__OBJECT, + G_TYPE_NONE, 1, + G_TYPE_OBJECT); + + dbus_g_object_type_install_info (G_TYPE_FROM_CLASS (settings_class), + &dbus_glib_nm_settings_object_info); +} + +/* + * NMConnectionSettings implementation + */ + +static gboolean impl_connection_settings_get_id (NMConnectionSettings *connection, + gchar **id, + GError **error); +static gboolean impl_connection_settings_get_settings (NMConnectionSettings *connection, + GHashTable **settings, + GError **error); +static gboolean impl_connection_settings_get_secrets (NMConnectionSettings *connection, + const gchar *setting_name, + GHashTable **secrets, + GError **error); + +#include "nm-settings-connection-glue.h" + +#define CONNECTION_SETTINGS_CLASS(o) (NM_CONNECTION_SETTINGS_CLASS (G_OBJECT_GET_CLASS (o))) + +G_DEFINE_TYPE (NMConnectionSettings, nm_connection_settings, G_TYPE_OBJECT) + +enum { + CS_UPDATED, + CS_REMOVED, + + CS_LAST_SIGNAL +}; + +static guint connection_signals[CS_LAST_SIGNAL] = { 0 }; + +static gboolean +impl_connection_settings_get_id (NMConnectionSettings *connection, + gchar **id, + GError **error) +{ + g_return_val_if_fail (NM_IS_CONNECTION_SETTINGS (connection), FALSE); + + if (!CONNECTION_SETTINGS_CLASS (connection)->get_id) { + *error = new_error ("%s.%d - Missing implementation for ConnectionSettings::get_id.", __FILE__, __LINE__); + return FALSE; + } + + *id = CONNECTION_SETTINGS_CLASS (connection)->get_id (connection); + + return TRUE; +} + +static gboolean +impl_connection_settings_get_settings (NMConnectionSettings *connection, + GHashTable **settings, + GError **error) +{ + g_return_val_if_fail (NM_IS_CONNECTION_SETTINGS (connection), FALSE); + + if (!CONNECTION_SETTINGS_CLASS (connection)->get_settings) { + *error = new_error ("%s.%d - Missing implementation for ConnectionSettings::get_settings.", __FILE__, __LINE__); + return FALSE; + } + + *settings = CONNECTION_SETTINGS_CLASS (connection)->get_settings (connection); + + return TRUE; +} + +static gboolean +impl_connection_settings_get_secrets (NMConnectionSettings *connection, + const gchar *setting_name, + GHashTable **secrets, + GError **error) +{ + g_return_val_if_fail (NM_IS_CONNECTION_SETTINGS (connection), FALSE); + + if (!CONNECTION_SETTINGS_CLASS (connection)->get_secrets) { + *error = new_error ("%s.%d - Missing implementation for ConnectionSettings::get_secret.", __FILE__, __LINE__); + return FALSE; + } + + *secrets = CONNECTION_SETTINGS_CLASS (connection)->get_secrets (connection, setting_name); + + return TRUE; +} + +static void +nm_connection_settings_init (NMConnectionSettings *connection) +{ +} + +static void +nm_connection_settings_finalize (GObject *object) +{ + G_OBJECT_CLASS (nm_connection_settings_parent_class)->finalize (object); +} + +static void +nm_connection_settings_class_init (NMConnectionSettingsClass *connection_settings_class) +{ + GObjectClass *object_class = G_OBJECT_CLASS (connection_settings_class); + + /* virtual methods */ + object_class->finalize = nm_connection_settings_finalize; + + connection_settings_class->get_id = NULL; + connection_settings_class->get_settings = NULL; + connection_settings_class->get_secrets = NULL; + + /* signals */ + connection_signals[CS_UPDATED] = + g_signal_new ("updated", + G_OBJECT_CLASS_TYPE (object_class), + G_SIGNAL_RUN_FIRST, + G_STRUCT_OFFSET (NMConnectionSettingsClass, updated), + NULL, NULL, + g_cclosure_marshal_VOID__POINTER, + G_TYPE_NONE, 1, + G_TYPE_POINTER); + connection_signals[CS_REMOVED] = + g_signal_new ("removed", + G_OBJECT_CLASS_TYPE (object_class), + G_SIGNAL_RUN_FIRST, + G_STRUCT_OFFSET (NMConnectionSettingsClass, removed), + NULL, NULL, + g_cclosure_marshal_VOID__VOID, + G_TYPE_NONE, 0); + + dbus_g_object_type_install_info (G_TYPE_FROM_CLASS (connection_settings_class), + &dbus_glib_nm_connection_settings_object_info); +} diff --git a/libnm-glib/nm-settings.h b/libnm-glib/nm-settings.h new file mode 100644 index 0000000000..8a63d1f469 --- /dev/null +++ b/libnm-glib/nm-settings.h @@ -0,0 +1,56 @@ + +#ifndef NM_SETTINGS_H +#define NM_SETTINGS_H 1 + +#include + +#define NM_TYPE_CONNECTION_SETTINGS (nm_connection_settings_get_type ()) +#define NM_CONNECTION_SETTINGS(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), NM_TYPE_CONNECTION_SETTINGS, NMConnectionSettings)) +#define NM_CONNECTION_SETTINGS_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), NM_TYPE_CONNECTION_SETTINGS, NMConnectionSettingsClass)) +#define NM_IS_CONNECTION_SETTINGS(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), NM_TYPE_CONNECTION_SETTINGS)) +#define NM_IS_CONNECTION_SETTINGS_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((obj), NM_TYPE_CONNECTION_SETTINGS)) +#define NM_CONNECTION_SETTINGS_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), NM_TYPE_CONNECTION_SETTINGS, NMConnectionSettingsClass)) + +typedef struct { + GObject parent; +} NMConnectionSettings; + +typedef struct { + GObjectClass parent_class; + + /* virtual methods */ + gchar * (* get_id) (NMConnectionSettings *connection); + GHashTable * (* get_settings) (NMConnectionSettings *connection); + GHashTable * (* get_secrets) (NMConnectionSettings *connection, const gchar *setting_name); + + /* signals */ + void (* updated) (NMConnectionSettings *connection, GHashTable *settings); + void (* removed) (NMConnectionSettings *connection); +} NMConnectionSettingsClass; + +GType nm_connection_settings_get_type (void); + +#define NM_TYPE_SETTINGS (nm_settings_get_type ()) +#define NM_SETTINGS(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), NM_TYPE_SETTINGS, NMSettings)) +#define NM_SETTINGS_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), NM_TYPE_SETTINGS, NMSettingsClass)) +#define NM_IS_SETTINGS(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), NM_TYPE_SETTINGS)) +#define NM_IS_SETTINGS_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((obj), NM_TYPE_SETTINGS)) +#define NM_SETTINGS_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), NM_TYPE_SETTINGS, NMSettingsClass)) + +typedef struct { + GObject parent; +} NMSettings; + +typedef struct { + GObjectClass parent_class; + + /* virtual methods */ + GPtrArray * (* list_connections) (NMSettings *settings); + + /* signals */ + void (* new_connection) (NMSettings *settings, NMConnectionSettings *connection); +} NMSettingsClass; + +GType nm_settings_get_type (void); + +#endif