diff --git a/ChangeLog b/ChangeLog index 18a3c6fd1f..0b19ffec54 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,11 @@ +2007-08-29 Dan Williams + + * libnm-glib/nm-settings.c + libnm-glib/nm-settings.h + - make the dbus path a property of the object, and autogenerate it. + It can't be composed of the 'id' field becuase that's not available + yet during the GObject creation in nm_connection_settings_init() + 2007-08-29 Dan Williams * introspection/nm-settings-connection.xml diff --git a/libnm-glib/nm-settings.c b/libnm-glib/nm-settings.c index 2dd51ab15f..efbc8df03b 100644 --- a/libnm-glib/nm-settings.c +++ b/libnm-glib/nm-settings.c @@ -187,24 +187,38 @@ impl_connection_settings_get_secrets (NMConnectionSettings *connection, return TRUE; } +static guint32 cs_counter = 0; + static void nm_connection_settings_init (NMConnectionSettings *connection) { DBusGConnection *bus_connection; GError *error = NULL; + connection->dbus_path = g_strdup_printf ("%s/%u", + NM_DBUS_PATH_CONNECTION_SETTINGS, + cs_counter++); + /* register object with DBus */ bus_connection = dbus_g_bus_get (DBUS_BUS_SESSION, &error); if (!bus_connection) { g_warning ("Couldn't connect to session bus: %s", error->message); g_error_free (error); } else { - gchar *path; + dbus_g_connection_register_g_object (bus_connection, + connection->dbus_path, + G_OBJECT (connection)); + } +} - path = nm_connection_settings_get_dbus_object_path (connection); - dbus_g_connection_register_g_object (bus_connection, path, G_OBJECT (connection)); +static void +nm_connection_settings_dispose (GObject *object) +{ + NMConnectionSettings * self = NM_CONNECTION_SETTINGS (object); - g_free (path); + if (self->dbus_path) { + g_free (self->dbus_path); + self->dbus_path = NULL; } } @@ -221,6 +235,7 @@ nm_connection_settings_class_init (NMConnectionSettingsClass *connection_setting /* virtual methods */ object_class->finalize = nm_connection_settings_finalize; + object_class->dispose = nm_connection_settings_dispose; connection_settings_class->get_id = NULL; connection_settings_class->get_settings = NULL; @@ -249,24 +264,12 @@ nm_connection_settings_class_init (NMConnectionSettingsClass *connection_setting &dbus_glib_nm_connection_settings_object_info); } -gchar * +const char * nm_connection_settings_get_dbus_object_path (NMConnectionSettings *connection) { - gchar *object_path, *escaped_object_path, *id; - g_return_val_if_fail (NM_IS_CONNECTION_SETTINGS (connection), NULL); - if (!CONNECTION_SETTINGS_CLASS (connection)->get_id) - return NULL; - - id = CONNECTION_SETTINGS_CLASS (connection)->get_id (connection); - object_path = g_strdup_printf ("%s/%s", NM_DBUS_PATH_CONNECTION_SETTINGS, id); - escaped_object_path = nm_dbus_escape_object_path ((const gchar *) object_path); - - g_free (object_path); - g_free (id); - - return escaped_object_path; + return connection->dbus_path; } void diff --git a/libnm-glib/nm-settings.h b/libnm-glib/nm-settings.h index edfe1ba10b..34df1836f9 100644 --- a/libnm-glib/nm-settings.h +++ b/libnm-glib/nm-settings.h @@ -15,6 +15,9 @@ G_BEGIN_DECLS typedef struct { GObject parent; + + /* private */ + char * dbus_path; } NMConnectionSettings; typedef struct { @@ -31,7 +34,7 @@ typedef struct { } NMConnectionSettingsClass; GType nm_connection_settings_get_type (void); -gchar *nm_connection_settings_get_dbus_object_path (NMConnectionSettings *connection); +const char *nm_connection_settings_get_dbus_object_path (NMConnectionSettings *connection); void nm_connection_settings_signal_updated (NMConnectionSettings *connection, GHashTable *settings); void nm_connection_settings_signal_removed (NMConnectionSettings *connection);