Commit dece9f9d authored by Beniamino Galvani's avatar Beniamino Galvani

core: export checkpoint list over D-Bus

parent a034a917
......@@ -269,6 +269,13 @@
-->
<property name="AllDevices" type="ao" access="read"/>
<!--
Checkpoints:
The list of active checkpoints.
-->
<property name="Checkpoints" type="ao" access="read"/>
<!--
NetworkingEnabled:
......
......@@ -35,6 +35,7 @@
struct _NMCheckpointManager {
NMManager *_manager;
GParamSpec *property_spec;
GHashTable *checkpoints;
CList list;
guint rollback_timeout_id;
......@@ -65,6 +66,12 @@ typedef struct {
static void update_rollback_timeout (NMCheckpointManager *self);
static void
notify_checkpoints (NMCheckpointManager *self) {
g_object_notify_by_pspec ((GObject *) GET_MANAGER (self),
self->property_spec);
}
static void
item_destroy (gpointer data)
{
......@@ -83,6 +90,7 @@ rollback_timeout_cb (NMCheckpointManager *self)
GVariant *result;
gint64 ts, now;
const char *path;
gboolean removed = FALSE;
now = nm_utils_get_monotonic_timestamp_ms ();
......@@ -95,12 +103,16 @@ rollback_timeout_cb (NMCheckpointManager *self)
path = nm_exported_object_get_path (NM_EXPORTED_OBJECT (item->checkpoint));
if (!g_hash_table_remove (self->checkpoints, path))
nm_assert_not_reached();
removed = TRUE;
}
}
self->rollback_timeout_id = 0;
update_rollback_timeout (self);
if (removed)
notify_checkpoints (self);
return G_SOURCE_REMOVE;
}
......@@ -230,6 +242,7 @@ nm_checkpoint_manager_create (NMCheckpointManager *self,
item))
g_return_val_if_reached (NULL);
notify_checkpoints (self);
update_rollback_timeout (self);
return checkpoint;
......@@ -242,6 +255,7 @@ nm_checkpoint_manager_destroy_all (NMCheckpointManager *self,
g_return_val_if_fail (self, FALSE);
g_hash_table_remove_all (self->checkpoints);
notify_checkpoints (self);
return TRUE;
}
......@@ -259,7 +273,9 @@ nm_checkpoint_manager_destroy (NMCheckpointManager *self,
if (!nm_streq (checkpoint_path, "/")) {
ret = g_hash_table_remove (self->checkpoints, checkpoint_path);
if (!ret) {
if (ret) {
notify_checkpoints (self);
} else {
g_set_error (error,
NM_MANAGER_ERROR,
NM_MANAGER_ERROR_INVALID_ARGUMENTS,
......@@ -292,14 +308,37 @@ nm_checkpoint_manager_rollback (NMCheckpointManager *self,
*results = nm_checkpoint_rollback (item->checkpoint);
g_hash_table_remove (self->checkpoints, checkpoint_path);
notify_checkpoints (self);
return TRUE;
}
char **
nm_checkpoint_manager_get_checkpoint_paths (NMCheckpointManager *self)
{
CheckpointItem *item;
char **strv;
guint num, i = 0;
num = g_hash_table_size (self->checkpoints);
if (!num) {
nm_assert (c_list_is_empty (&self->list));
return NULL;
}
strv = g_new (char *, num + 1);
c_list_for_each_entry (item, &self->list, list)
strv[i++] = g_strdup (nm_exported_object_get_path (NM_EXPORTED_OBJECT (item->checkpoint)));
nm_assert (i == num);
strv[i] = NULL;
return strv;
}
/*****************************************************************************/
NMCheckpointManager *
nm_checkpoint_manager_new (NMManager *manager)
nm_checkpoint_manager_new (NMManager *manager, GParamSpec *spec)
{
NMCheckpointManager *self;
......@@ -316,6 +355,7 @@ nm_checkpoint_manager_new (NMManager *manager)
self->_manager = manager;
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);
return self;
......
......@@ -27,7 +27,7 @@
typedef struct _NMCheckpointManager NMCheckpointManager;
NMCheckpointManager *nm_checkpoint_manager_new (NMManager *manager);
NMCheckpointManager *nm_checkpoint_manager_new (NMManager *manager, GParamSpec *spec);
void nm_checkpoint_manager_unref (NMCheckpointManager *self);
NMCheckpoint *nm_checkpoint_manager_create (NMCheckpointManager *self,
......@@ -47,4 +47,6 @@ gboolean nm_checkpoint_manager_rollback (NMCheckpointManager *self,
GVariant **results,
GError **error);
char **nm_checkpoint_manager_get_checkpoint_paths (NMCheckpointManager *self);
#endif /* __NM_CHECKPOINT_MANAGER_H__ */
......@@ -220,6 +220,7 @@ NM_GOBJECT_PROPERTIES_DEFINE (NMManager,
PROP_METERED,
PROP_GLOBAL_DNS_CONFIGURATION,
PROP_ALL_DEVICES,
PROP_CHECKPOINTS,
/* Not exported */
PROP_SLEEPING,
......@@ -5709,7 +5710,7 @@ _checkpoint_mgr_get (NMManager *self, gboolean create_as_needed)
NMManagerPrivate *priv = NM_MANAGER_GET_PRIVATE (self);
if (G_UNLIKELY (!priv->checkpoint_mgr) && create_as_needed)
priv->checkpoint_mgr = nm_checkpoint_manager_new (self);
priv->checkpoint_mgr = nm_checkpoint_manager_new (self, obj_properties[PROP_CHECKPOINTS]);
return priv->checkpoint_mgr;
}
......@@ -6251,6 +6252,7 @@ get_property (GObject *object, guint prop_id,
const NMGlobalDnsConfig *dns_config;
const char *type;
NMConnectivity *connectivity;
char **strv;
switch (prop_id) {
case PROP_VERSION:
......@@ -6337,6 +6339,12 @@ get_property (GObject *object, guint prop_id,
case PROP_ALL_DEVICES:
nm_utils_g_value_set_object_path_array (value, priv->devices, NULL, NULL);
break;
case PROP_CHECKPOINTS:
strv = NULL;
if (priv->checkpoint_mgr)
strv = nm_checkpoint_manager_get_checkpoint_paths (priv->checkpoint_mgr);
g_value_take_boxed (value, strv);
break;
default:
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
break;
......@@ -6691,6 +6699,12 @@ nm_manager_class_init (NMManagerClass *manager_class)
G_PARAM_READABLE |
G_PARAM_STATIC_STRINGS);
obj_properties[PROP_CHECKPOINTS] =
g_param_spec_boxed (NM_MANAGER_CHECKPOINTS, "", "",
G_TYPE_STRV,
G_PARAM_READABLE |
G_PARAM_STATIC_STRINGS);
g_object_class_install_properties (object_class, _PROPERTY_ENUMS_LAST, obj_properties);
/* signals */
......
......@@ -54,6 +54,7 @@
#define NM_MANAGER_METERED "metered"
#define NM_MANAGER_GLOBAL_DNS_CONFIGURATION "global-dns-configuration"
#define NM_MANAGER_ALL_DEVICES "all-devices"
#define NM_MANAGER_CHECKPOINTS "checkpoints"
/* Not exported */
#define NM_MANAGER_SLEEPING "sleeping"
......
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