Commit ffb49267 authored by Thomas Haller's avatar Thomas Haller

checkpoint: embed CList in NMCheckpoint instance

We don't need an external CheckpointItem, just to wrap the
CList instance. Embed it directly in NMCheckpoint.

Sure, that exposes the checkpoints_lst field in the (internal)
header file, hiding the private member less.
parent 6f85d3e0
......@@ -1466,10 +1466,10 @@ src_libNetworkManager_la_CPPFLAGS = $(src_cppflags)
src_libNetworkManager_la_SOURCES = \
\
src/nm-checkpoint-manager.c \
src/nm-checkpoint-manager.h \
src/nm-checkpoint.c \
src/nm-checkpoint.h \
src/nm-checkpoint-manager.c \
src/nm-checkpoint-manager.h \
\
src/devices/nm-device.c \
src/devices/nm-device.h \
......
......@@ -36,7 +36,7 @@ struct _NMCheckpointManager {
NMManager *_manager;
GParamSpec *property_spec;
GHashTable *checkpoints;
CList list;
CList checkpoints_lst_head;
guint rollback_timeout_id;
};
......@@ -58,11 +58,6 @@ struct _NMCheckpointManager {
/*****************************************************************************/
typedef struct {
CList list;
NMCheckpoint *checkpoint;
} CheckpointItem;
static void update_rollback_timeout (NMCheckpointManager *self);
static void
......@@ -74,18 +69,17 @@ notify_checkpoints (NMCheckpointManager *self) {
static void
item_destroy (gpointer data)
{
CheckpointItem *item = data;
NMCheckpoint *checkpoint = data;
c_list_unlink_stale (&item->list);
nm_dbus_object_unexport (NM_DBUS_OBJECT (item->checkpoint));
g_object_unref (G_OBJECT (item->checkpoint));
g_slice_free (CheckpointItem, item);
c_list_unlink (&checkpoint->checkpoints_lst);
nm_dbus_object_unexport (NM_DBUS_OBJECT (checkpoint));
g_object_unref (checkpoint);
}
static gboolean
rollback_timeout_cb (NMCheckpointManager *self)
{
CheckpointItem *item, *safe;
NMCheckpoint *checkpoint, *checkpoint_safe;
GVariant *result;
gint64 ts, now;
const char *path;
......@@ -93,13 +87,13 @@ rollback_timeout_cb (NMCheckpointManager *self)
now = nm_utils_get_monotonic_timestamp_ms ();
c_list_for_each_entry_safe (item, safe, &self->list, list) {
ts = nm_checkpoint_get_rollback_ts (item->checkpoint);
c_list_for_each_entry_safe (checkpoint, checkpoint_safe, &self->checkpoints_lst_head, checkpoints_lst) {
ts = nm_checkpoint_get_rollback_ts (checkpoint);
if (ts && ts <= now) {
result = nm_checkpoint_rollback (item->checkpoint);
result = nm_checkpoint_rollback (checkpoint);
if (result)
g_variant_unref (result);
path = nm_dbus_object_get_path (NM_DBUS_OBJECT (item->checkpoint));
path = nm_dbus_object_get_path (NM_DBUS_OBJECT (checkpoint));
if (!g_hash_table_remove (self->checkpoints, path))
nm_assert_not_reached();
removed = TRUE;
......@@ -118,11 +112,11 @@ rollback_timeout_cb (NMCheckpointManager *self)
static void
update_rollback_timeout (NMCheckpointManager *self)
{
CheckpointItem *item;
NMCheckpoint *checkpoint;
gint64 ts, delta, next = G_MAXINT64;
c_list_for_each_entry (item, &self->list, list) {
ts = nm_checkpoint_get_rollback_ts (item->checkpoint);
c_list_for_each_entry (checkpoint, &self->checkpoints_lst_head, checkpoints_lst) {
ts = nm_checkpoint_get_rollback_ts (checkpoint);
if (ts && ts < next)
next = ts;
}
......@@ -141,11 +135,11 @@ update_rollback_timeout (NMCheckpointManager *self)
static NMCheckpoint *
find_checkpoint_for_device (NMCheckpointManager *self, NMDevice *device)
{
CheckpointItem *item;
NMCheckpoint *checkpoint;
c_list_for_each_entry (item, &self->list, list) {
if (nm_checkpoint_includes_device (item->checkpoint, device))
return item->checkpoint;
c_list_for_each_entry (checkpoint, &self->checkpoints_lst_head, checkpoints_lst) {
if (nm_checkpoint_includes_device (checkpoint, device))
return checkpoint;
}
return NULL;
......@@ -160,7 +154,6 @@ nm_checkpoint_manager_create (NMCheckpointManager *self,
{
NMManager *manager;
NMCheckpoint *checkpoint;
CheckpointItem *item;
const char * const *path;
gs_unref_ptrarray GPtrArray *devices = NULL;
NMDevice *device;
......@@ -228,11 +221,9 @@ nm_checkpoint_manager_create (NMCheckpointManager *self,
checkpoint_path = nm_dbus_object_export (NM_DBUS_OBJECT (checkpoint));
item = g_slice_new0 (CheckpointItem);
item->checkpoint = checkpoint;
c_list_link_tail (&self->list, &item->list);
c_list_link_tail (&self->checkpoints_lst_head, &checkpoint->checkpoints_lst);
if (!g_hash_table_insert (self->checkpoints, (gpointer) checkpoint_path, item))
if (!g_hash_table_insert (self->checkpoints, (gpointer) checkpoint_path, checkpoint))
g_return_val_if_reached (NULL);
notify_checkpoints (self);
......@@ -285,21 +276,21 @@ nm_checkpoint_manager_rollback (NMCheckpointManager *self,
GVariant **results,
GError **error)
{
CheckpointItem *item;
NMCheckpoint *checkpoint;
g_return_val_if_fail (self, FALSE);
g_return_val_if_fail (checkpoint_path && checkpoint_path[0] == '/', FALSE);
g_return_val_if_fail (results, FALSE);
g_return_val_if_fail (!error || !*error, FALSE);
item = g_hash_table_lookup (self->checkpoints, checkpoint_path);
if (!item) {
checkpoint = g_hash_table_lookup (self->checkpoints, checkpoint_path);
if (!checkpoint) {
g_set_error (error, NM_MANAGER_ERROR, NM_MANAGER_ERROR_FAILED,
"checkpoint %s does not exist", checkpoint_path);
return FALSE;
}
*results = nm_checkpoint_rollback (item->checkpoint);
*results = nm_checkpoint_rollback (checkpoint);
g_hash_table_remove (self->checkpoints, checkpoint_path);
notify_checkpoints (self);
......@@ -309,19 +300,19 @@ nm_checkpoint_manager_rollback (NMCheckpointManager *self,
char **
nm_checkpoint_manager_get_checkpoint_paths (NMCheckpointManager *self)
{
CheckpointItem *item;
NMCheckpoint *checkpoint;
char **strv;
guint num, i = 0;
num = g_hash_table_size (self->checkpoints);
if (!num) {
nm_assert (c_list_is_empty (&self->list));
nm_assert (c_list_is_empty (&self->checkpoints_lst_head));
return NULL;
}
strv = g_new (char *, num + 1);
c_list_for_each_entry (item, &self->list, list)
strv[i++] = g_strdup (nm_dbus_object_get_path (NM_DBUS_OBJECT (item->checkpoint)));
c_list_for_each_entry (checkpoint, &self->checkpoints_lst_head, checkpoints_lst)
strv[i++] = g_strdup (nm_dbus_object_get_path (NM_DBUS_OBJECT (checkpoint)));
nm_assert (i == num);
strv[i] = NULL;
......@@ -349,7 +340,7 @@ nm_checkpoint_manager_new (NMManager *manager, GParamSpec *spec)
self->checkpoints = g_hash_table_new_full (nm_str_hash, g_str_equal,
NULL, item_destroy);
self->property_spec = spec;
c_list_init (&self->list);
c_list_init (&self->checkpoints_lst_head);
return self;
}
......
......@@ -54,7 +54,7 @@ NM_GOBJECT_PROPERTIES_DEFINE_BASE (
PROP_ROLLBACK_TIMEOUT,
);
typedef struct {
struct _NMCheckpointPrivate {
/* properties */
GHashTable *devices;
gint64 created;
......@@ -64,11 +64,6 @@ typedef struct {
gint64 rollback_ts;
NMCheckpointCreateFlags flags;
GHashTable *connection_uuids;
} NMCheckpointPrivate;
struct _NMCheckpoint {
NMDBusObject parent;
NMCheckpointPrivate _priv;
};
struct _NMCheckpointClass {
......@@ -77,7 +72,7 @@ struct _NMCheckpointClass {
G_DEFINE_TYPE (NMCheckpoint, nm_checkpoint, NM_TYPE_DBUS_OBJECT)
#define NM_CHECKPOINT_GET_PRIVATE(self) _NM_GET_PRIVATE (self, NMCheckpoint, NM_IS_CHECKPOINT)
#define NM_CHECKPOINT_GET_PRIVATE(self) _NM_GET_PRIVATE_PTR (self, NMCheckpoint, NM_IS_CHECKPOINT)
/*****************************************************************************/
......@@ -457,7 +452,13 @@ get_property (GObject *object, guint prop_id,
static void
nm_checkpoint_init (NMCheckpoint *self)
{
NMCheckpointPrivate *priv = NM_CHECKPOINT_GET_PRIVATE (self);
NMCheckpointPrivate *priv;
priv = G_TYPE_INSTANCE_GET_PRIVATE (self, NM_TYPE_CHECKPOINT, NMCheckpointPrivate);
self->_priv = priv;
c_list_init (&self->checkpoints_lst);
priv->devices = g_hash_table_new_full (nm_direct_hash, NULL,
NULL, device_checkpoint_destroy);
......@@ -525,6 +526,8 @@ dispose (GObject *object)
NMCheckpoint *self = NM_CHECKPOINT (object);
NMCheckpointPrivate *priv = NM_CHECKPOINT_GET_PRIVATE (self);
nm_assert (c_list_is_empty (&self->checkpoints_lst));
g_clear_pointer (&priv->devices, g_hash_table_unref);
g_clear_pointer (&priv->connection_uuids, g_hash_table_unref);
......@@ -552,6 +555,8 @@ nm_checkpoint_class_init (NMCheckpointClass *checkpoint_class)
GObjectClass *object_class = G_OBJECT_CLASS (checkpoint_class);
NMDBusObjectClass *dbus_object_class = NM_DBUS_OBJECT_CLASS (checkpoint_class);
g_type_class_add_private (object_class, sizeof (NMCheckpointPrivate));
dbus_object_class->export_path = NM_DBUS_EXPORT_PATH_NUMBERED (NM_DBUS_PATH"/Checkpoint");
dbus_object_class->interface_infos = NM_DBUS_INTERFACE_INFOS (&interface_info_checkpoint);
......
......@@ -35,7 +35,14 @@
#define NM_CHECKPOINT_CREATED "created"
#define NM_CHECKPOINT_ROLLBACK_TIMEOUT "rollback-timeout"
typedef struct _NMCheckpoint NMCheckpoint;
typedef struct _NMCheckpointPrivate NMCheckpointPrivate;
typedef struct {
NMDBusObject parent;
NMCheckpointPrivate *_priv;
CList checkpoints_lst;
} NMCheckpoint;
typedef struct _NMCheckpointClass NMCheckpointClass;
GType nm_checkpoint_get_type (void);
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment