Commit c3efedf5 authored by Beniamino Galvani's avatar Beniamino Galvani

libnm: add checkpoint support

parent dece9f9d
......@@ -737,6 +737,7 @@ libnm_lib_h_pub_real = \
libnm/NetworkManager.h \
libnm/nm-access-point.h \
libnm/nm-active-connection.h \
libnm/nm-checkpoint.h \
libnm/nm-client.h \
libnm/nm-device-adsl.h \
libnm/nm-device-bond.h \
......@@ -792,6 +793,7 @@ libnm_lib_h_priv = \
libnm_lib_c_real = \
libnm/nm-access-point.c \
libnm/nm-active-connection.c \
libnm/nm-checkpoint.c \
libnm/nm-client.c \
libnm/nm-dbus-helpers.c \
libnm/nm-device-adsl.c \
......
......@@ -76,6 +76,7 @@
#define NM_DBUS_INTERFACE_DEVICE_GRE NM_DBUS_INTERFACE_DEVICE ".Gre"
#define NM_DBUS_INTERFACE_DEVICE_IP_TUNNEL NM_DBUS_INTERFACE_DEVICE ".IPTunnel"
#define NM_DBUS_INTERFACE_DEVICE_STATISTICS NM_DBUS_INTERFACE_DEVICE ".Statistics"
#define NM_DBUS_INTERFACE_CHECKPOINT NM_DBUS_INTERFACE ".Checkpoint"
#define NM_DBUS_INTERFACE_SETTINGS "org.freedesktop.NetworkManager.Settings"
#define NM_DBUS_PATH_SETTINGS "/org/freedesktop/NetworkManager/Settings"
......
......@@ -1221,3 +1221,18 @@ global:
nm_setting_wireless_security_pmf_get_type;
nm_setting_wireless_security_wps_method_get_type;
} libnm_1_8_0;
libnm_1_12_0 {
global:
nm_checkpoint_get_created;
nm_checkpoint_get_devices;
nm_checkpoint_get_rollback_timeout;
nm_checkpoint_get_type;
nm_client_checkpoint_create_async;
nm_client_checkpoint_create_finish;
nm_client_checkpoint_destroy_async;
nm_client_checkpoint_destroy_finish;
nm_client_checkpoint_rollback_async;
nm_client_checkpoint_rollback_finish;
nm_client_get_checkpoints;
} libnm_1_10_0;
/* -*- Mode: C; tab-width: 4; indent-tabs-mode: t; c-basic-offset: 4 -*- */
/*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 2 of the License, or (at your option) any later version.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this program. If not, see
* <http://www.gnu.org/licenses/>.
*
* Copyright 2017 Red Hat, Inc.
*/
#include "nm-default.h"
#include "nm-checkpoint.h"
#include "nm-core-internal.h"
#include "nm-dbus-interface.h"
#include "nm-device.h"
#include "nm-object-private.h"
typedef struct {
GPtrArray *devices;
gint64 created;
guint32 rollback_timeout;
} NMCheckpointPrivate;
struct _NMCheckpoint {
NMObject parent;
NMCheckpointPrivate _priv;
};
struct _NMCheckpointClass {
NMObjectClass parent;
};
G_DEFINE_TYPE (NMCheckpoint, nm_checkpoint, NM_TYPE_OBJECT)
#define NM_CHECKPOINT_GET_PRIVATE(self) _NM_GET_PRIVATE (self, NMCheckpoint, NM_IS_CHECKPOINT)
enum {
PROP_0,
PROP_DEVICES,
PROP_CREATED,
PROP_ROLLBACK_TIMEOUT,
LAST_PROP
};
/**
* nm_checkpoint_get_devices:
* @checkpoint: a #NMCheckpoint
*
* The devices that are part of this checkpoint.
*
* Returns: (element-type NMDevice): the devices list.
*
* Since: 1.12
**/
const GPtrArray *
nm_checkpoint_get_devices (NMCheckpoint *checkpoint)
{
g_return_val_if_fail (NM_IS_CHECKPOINT (checkpoint), NULL);
return NM_CHECKPOINT_GET_PRIVATE (checkpoint)->devices;
}
/**
* nm_checkpoint_get_created:
* @checkpoint: a #NMCheckpoint
*
* Gets the timestamp (in CLOCK_BOOTTIME milliseconds)
* of checkpoint creation.
*
* Returns: the timestamp of checkpoint creation.
*
* Since: 1.12
**/
gint64
nm_checkpoint_get_created (NMCheckpoint *checkpoint)
{
g_return_val_if_fail (NM_IS_CHECKPOINT (checkpoint), 0);
return NM_CHECKPOINT_GET_PRIVATE (checkpoint)->created;
}
/**
* nm_checkpoint_get_rollback_timeout:
* @checkpoint: a #NMCheckpoint
*
* Gets the the timeout in seconds for automatic rollback.
*
* Returns: the rollback timeout.
*
* Since: 1.12
**/
guint32
nm_checkpoint_get_rollback_timeout (NMCheckpoint *checkpoint)
{
g_return_val_if_fail (NM_IS_CHECKPOINT (checkpoint), 0);
return NM_CHECKPOINT_GET_PRIVATE (checkpoint)->rollback_timeout;
}
/*****************************************************************************/
static void
nm_checkpoint_init (NMCheckpoint *checkpoint)
{
}
static void
finalize (GObject *object)
{
NMCheckpointPrivate *priv = NM_CHECKPOINT_GET_PRIVATE (NM_CHECKPOINT (object));
g_ptr_array_unref (priv->devices);
G_OBJECT_CLASS (nm_checkpoint_parent_class)->finalize (object);
}
static void
get_property (GObject *object,
guint prop_id,
GValue *value,
GParamSpec *pspec)
{
NMCheckpoint *checkpoint = NM_CHECKPOINT (object);
NMCheckpointPrivate *priv = NM_CHECKPOINT_GET_PRIVATE (checkpoint);
switch (prop_id) {
case PROP_DEVICES:
g_value_take_boxed (value, _nm_utils_copy_object_array (priv->devices));
break;
case PROP_CREATED:
g_value_set_int64 (value, priv->created);
break;
case PROP_ROLLBACK_TIMEOUT:
g_value_set_uint (value, priv->rollback_timeout);
break;
default:
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
break;
}
}
static void
init_dbus (NMObject *object)
{
NMCheckpointPrivate *priv = NM_CHECKPOINT_GET_PRIVATE (NM_CHECKPOINT (object));
const NMPropertiesInfo property_info[] = {
{ NM_CHECKPOINT_DEVICES, &priv->devices, NULL, NM_TYPE_DEVICE },
{ NM_CHECKPOINT_CREATED, &priv->created },
{ NM_CHECKPOINT_ROLLBACK_TIMEOUT, &priv->rollback_timeout },
{ NULL },
};
NM_OBJECT_CLASS (nm_checkpoint_parent_class)->init_dbus (object);
_nm_object_register_properties (object,
NM_DBUS_INTERFACE_CHECKPOINT,
property_info);
}
static void
nm_checkpoint_class_init (NMCheckpointClass *checkpoint_class)
{
GObjectClass *object_class = G_OBJECT_CLASS (checkpoint_class);
NMObjectClass *nm_object_class = NM_OBJECT_CLASS (checkpoint_class);
object_class->get_property = get_property;
object_class->finalize = finalize;
nm_object_class->init_dbus = init_dbus;
/**
* NMCheckpoint:devices:
*
* The devices that are part of this checkpoint.
*
* Since: 1.12
**/
g_object_class_install_property
(object_class, PROP_DEVICES,
g_param_spec_boxed (NM_CHECKPOINT_DEVICES, "", "",
G_TYPE_PTR_ARRAY,
G_PARAM_READABLE |
G_PARAM_STATIC_STRINGS));
/**
* NMCheckpoint:created:
*
* The timestamp (in CLOCK_BOOTTIME milliseconds) of checkpoint creation.
*
* Since: 1.12
**/
g_object_class_install_property
(object_class, PROP_CREATED,
g_param_spec_int64 (NM_CHECKPOINT_CREATED, "", "",
G_MININT64, G_MAXINT64, 0,
G_PARAM_READABLE |
G_PARAM_STATIC_STRINGS));
/**
* NMCheckpoint:rollback-timeout:
*
* Timeout in seconds for automatic rollback, or zero.
*
* Since: 1.12
**/
g_object_class_install_property
(object_class, PROP_ROLLBACK_TIMEOUT,
g_param_spec_uint (NM_CHECKPOINT_ROLLBACK_TIMEOUT, "", "",
0, G_MAXUINT32, 0,
G_PARAM_READABLE |
G_PARAM_STATIC_STRINGS));
}
/* -*- Mode: C; tab-width: 4; indent-tabs-mode: t; c-basic-offset: 4 -*- */
/*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 2 of the License, or (at your option) any later version.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this program. If not, see
* <http://www.gnu.org/licenses/>.
*
* Copyright 2017 Red Hat, Inc.
*/
#ifndef __NM_CHECKPOINT_H__
#define __NM_CHECKPOINT_H__
#if !defined (__NETWORKMANAGER_H_INSIDE__) && !defined (NETWORKMANAGER_COMPILATION)
#error "Only <NetworkManager.h> can be included directly."
#endif
#include "nm-object.h"
G_BEGIN_DECLS
#define NM_TYPE_CHECKPOINT (nm_checkpoint_get_type ())
#define NM_CHECKPOINT(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), NM_TYPE_CHECKPOINT, NMCheckpoint))
#define NM_CHECKPOINT_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), NM_TYPE_CHECKPOINT, NMCheckpointClass))
#define NM_IS_CHECKPOINT(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), NM_TYPE_CHECKPOINT))
#define NM_IS_CHECKPOINT_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), NM_TYPE_CHECKPOINT))
#define NM_CHECKPOINT_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), NM_TYPE_CHECKPOINT, NMCheckpointClass))
#define NM_CHECKPOINT_DEVICES "devices"
#define NM_CHECKPOINT_CREATED "created"
#define NM_CHECKPOINT_ROLLBACK_TIMEOUT "rollback-timeout"
/**
* NMCheckpoint:
*/
typedef struct _NMCheckpointClass NMCheckpointClass;
GType nm_checkpoint_get_type (void);
NM_AVAILABLE_IN_1_12
const GPtrArray *nm_checkpoint_get_devices (NMCheckpoint *checkpoint);
NM_AVAILABLE_IN_1_12
gint64 nm_checkpoint_get_created (NMCheckpoint *checkpoint);
NM_AVAILABLE_IN_1_12
guint32 nm_checkpoint_get_rollback_timeout (NMCheckpoint *checkpoint);
G_END_DECLS
#endif /* __NM_CHECKPOINT_H__ */
This diff is collapsed.
......@@ -403,6 +403,45 @@ const char *nm_client_get_dns_rc_manager (NMClient *client);
NM_AVAILABLE_IN_1_6
const GPtrArray *nm_client_get_dns_configuration (NMClient *client);
NM_AVAILABLE_IN_1_12
const GPtrArray *nm_client_get_checkpoints (NMClient *client);
NM_AVAILABLE_IN_1_12
void nm_client_checkpoint_create_async (NMClient *client,
const GPtrArray *devices,
guint32 rollback_timeout,
NMCheckpointCreateFlags flags,
GCancellable *cancellable,
GAsyncReadyCallback callback,
gpointer user_data);
NM_AVAILABLE_IN_1_12
NMCheckpoint *nm_client_checkpoint_create_finish (NMClient *client,
GAsyncResult *result,
GError **error);
NM_AVAILABLE_IN_1_12
void nm_client_checkpoint_destroy_async (NMClient *client,
NMCheckpoint *checkpoint,
GCancellable *cancellable,
GAsyncReadyCallback callback,
gpointer user_data);
NM_AVAILABLE_IN_1_12
gboolean nm_client_checkpoint_destroy_finish (NMClient *client,
GAsyncResult *result,
GError **error);
NM_AVAILABLE_IN_1_12
void nm_client_checkpoint_rollback_async (NMClient *client,
NMCheckpoint *checkpoint,
GCancellable *cancellable,
GAsyncReadyCallback callback,
gpointer user_data);
NM_AVAILABLE_IN_1_12
GHashTable *nm_client_checkpoint_rollback_finish (NMClient *client,
GAsyncResult *result,
GError **error);
G_END_DECLS
#endif /* __NM_CLIENT_H__ */
This diff is collapsed.
......@@ -51,6 +51,7 @@ G_BEGIN_DECLS
#define NM_MANAGER_PRIMARY_CONNECTION "primary-connection"
#define NM_MANAGER_ACTIVATING_CONNECTION "activating-connection"
#define NM_MANAGER_DEVICES "devices"
#define NM_MANAGER_CHECKPOINTS "checkpoints"
#define NM_MANAGER_METERED "metered"
#define NM_MANAGER_ALL_DEVICES "all-devices"
......@@ -69,6 +70,8 @@ typedef struct {
void (*device_removed) (NMManager *manager, NMDevice *device);
void (*active_connection_added) (NMManager *manager, NMActiveConnection *ac);
void (*active_connection_removed) (NMManager *manager, NMActiveConnection *ac);
void (*checkpoint_added) (NMManager *manager, NMCheckpoint *checkpoint);
void (*checkpoint_removed) (NMManager *manager, NMCheckpoint *checkpoint);
void (*permission_changed) (NMManager *manager,
NMClientPermission permission,
NMClientPermissionResult result);
......@@ -184,6 +187,34 @@ gboolean nm_manager_deactivate_connection_finish (NMManager *manager,
GAsyncResult *result,
GError **error);
const GPtrArray *nm_manager_get_checkpoints (NMManager *manager);
void nm_manager_checkpoint_create_async (NMManager *manager,
const GPtrArray *devices,
guint32 rollback_timeout,
NMCheckpointCreateFlags flags,
GCancellable *cancellable,
GAsyncReadyCallback callback,
gpointer user_data);
NMCheckpoint *nm_manager_checkpoint_create_finish (NMManager *manager,
GAsyncResult *result,
GError **error);
void nm_manager_checkpoint_destroy_async (NMManager *manager,
NMCheckpoint *checkpoint,
GCancellable *cancellable,
GAsyncReadyCallback callback,
gpointer user_data);
gboolean nm_manager_checkpoint_destroy_finish (NMManager *manager,
GAsyncResult *result,
GError **error);
void nm_manager_checkpoint_rollback_async (NMManager *manager,
NMCheckpoint *checkpoint,
GCancellable *cancellable,
GAsyncReadyCallback callback,
gpointer user_data);
GHashTable *nm_manager_checkpoint_rollback_finish (NMManager *manager,
GAsyncResult *result,
GError **error);
G_END_DECLS
#endif /* __NM_MANAGER_H__ */
......@@ -28,6 +28,7 @@
typedef struct _NMAccessPoint NMAccessPoint;
typedef struct _NMActiveConnection NMActiveConnection;
typedef struct _NMCheckpoint NMCheckpoint;
typedef struct _NMClient NMClient;
typedef struct _NMDevice NMDevice;
typedef struct _NMDeviceAdsl NMDeviceAdsl;
......
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