Blame libnm/nm-checkpoint.c

Packit Service a1bd4f
/* SPDX-License-Identifier: LGPL-2.1+ */
Packit 5756e2
/*
Packit 5756e2
 * Copyright (C) 2017 Red Hat, Inc.
Packit 5756e2
 */
Packit 5756e2
Packit 5756e2
#include "nm-default.h"
Packit 5756e2
Packit 5756e2
#include "nm-checkpoint.h"
Packit 5756e2
Packit 5756e2
#include "nm-core-internal.h"
Packit 5756e2
#include "nm-dbus-interface.h"
Packit 5756e2
#include "nm-device.h"
Packit 5756e2
#include "nm-object-private.h"
Packit 5756e2
Packit 5756e2
/*****************************************************************************/
Packit 5756e2
Packit Service a1bd4f
NM_GOBJECT_PROPERTIES_DEFINE_BASE(PROP_DEVICES, PROP_CREATED, PROP_ROLLBACK_TIMEOUT, );
Packit 5756e2
Packit 5756e2
typedef struct {
Packit Service a1bd4f
    NMLDBusPropertyAO devices;
Packit Service a1bd4f
    gint64            created;
Packit Service a1bd4f
    guint32           rollback_timeout;
Packit 5756e2
} NMCheckpointPrivate;
Packit 5756e2
Packit 5756e2
struct _NMCheckpoint {
Packit Service a1bd4f
    NMObject            parent;
Packit Service a1bd4f
    NMCheckpointPrivate _priv;
Packit 5756e2
};
Packit 5756e2
Packit 5756e2
struct _NMCheckpointClass {
Packit Service a1bd4f
    NMObjectClass parent;
Packit 5756e2
};
Packit 5756e2
Packit Service a1bd4f
G_DEFINE_TYPE(NMCheckpoint, nm_checkpoint, NM_TYPE_OBJECT)
Packit 5756e2
Packit Service a1bd4f
#define NM_CHECKPOINT_GET_PRIVATE(self) \
Packit Service a1bd4f
    _NM_GET_PRIVATE(self, NMCheckpoint, NM_IS_CHECKPOINT, NMObject)
Packit 5756e2
Packit 5756e2
/*****************************************************************************/
Packit 5756e2
Packit 5756e2
/**
Packit 5756e2
 * nm_checkpoint_get_devices:
Packit 5756e2
 * @checkpoint: a #NMCheckpoint
Packit 5756e2
 *
Packit 5756e2
 * The devices that are part of this checkpoint.
Packit 5756e2
 *
Packit 5756e2
 * Returns: (element-type NMDevice): the devices list.
Packit 5756e2
 *
Packit 5756e2
 * Since: 1.12
Packit 5756e2
 **/
Packit 5756e2
const GPtrArray *
Packit Service a1bd4f
nm_checkpoint_get_devices(NMCheckpoint *checkpoint)
Packit 5756e2
{
Packit Service a1bd4f
    g_return_val_if_fail(NM_IS_CHECKPOINT(checkpoint), NULL);
Packit 5756e2
Packit Service a1bd4f
    return nml_dbus_property_ao_get_objs_as_ptrarray(
Packit Service a1bd4f
        &NM_CHECKPOINT_GET_PRIVATE(checkpoint)->devices);
Packit 5756e2
}
Packit 5756e2
Packit 5756e2
/**
Packit 5756e2
 * nm_checkpoint_get_created:
Packit 5756e2
 * @checkpoint: a #NMCheckpoint
Packit 5756e2
 *
Packit 5756e2
 * Gets the timestamp (in CLOCK_BOOTTIME milliseconds) of checkpoint creation.
Packit 5756e2
 *
Packit 5756e2
 * Use nm_utils_get_timestamp_msec() to obtain current time value suitable for
Packit 5756e2
 * comparing to this value.
Packit 5756e2
 *
Packit 5756e2
 * Returns: the timestamp of checkpoint creation.
Packit 5756e2
 *
Packit 5756e2
 * Since: 1.12
Packit 5756e2
 **/
Packit 5756e2
gint64
Packit Service a1bd4f
nm_checkpoint_get_created(NMCheckpoint *checkpoint)
Packit 5756e2
{
Packit Service a1bd4f
    g_return_val_if_fail(NM_IS_CHECKPOINT(checkpoint), 0);
Packit 5756e2
Packit Service a1bd4f
    return NM_CHECKPOINT_GET_PRIVATE(checkpoint)->created;
Packit 5756e2
}
Packit 5756e2
Packit 5756e2
/**
Packit 5756e2
 * nm_checkpoint_get_rollback_timeout:
Packit 5756e2
 * @checkpoint: a #NMCheckpoint
Packit 5756e2
 *
Packit 5756e2
 * Gets the timeout in seconds for automatic rollback.
Packit 5756e2
 *
Packit 5756e2
 * Returns: the rollback timeout.
Packit 5756e2
 *
Packit 5756e2
 * Since: 1.12
Packit 5756e2
 **/
Packit 5756e2
guint32
Packit Service a1bd4f
nm_checkpoint_get_rollback_timeout(NMCheckpoint *checkpoint)
Packit 5756e2
{
Packit Service a1bd4f
    g_return_val_if_fail(NM_IS_CHECKPOINT(checkpoint), 0);
Packit 5756e2
Packit Service a1bd4f
    return NM_CHECKPOINT_GET_PRIVATE(checkpoint)->rollback_timeout;
Packit 5756e2
}
Packit 5756e2
Packit 5756e2
/*****************************************************************************/
Packit 5756e2
Packit 5756e2
static void
Packit Service a1bd4f
nm_checkpoint_init(NMCheckpoint *checkpoint)
Packit Service a1bd4f
{}
Packit 5756e2
Packit 5756e2
static void
Packit Service a1bd4f
get_property(GObject *object, guint prop_id, GValue *value, GParamSpec *pspec)
Packit 5756e2
{
Packit Service a1bd4f
    NMCheckpoint *       checkpoint = NM_CHECKPOINT(object);
Packit Service a1bd4f
    NMCheckpointPrivate *priv       = NM_CHECKPOINT_GET_PRIVATE(checkpoint);
Packit Service a1bd4f
Packit Service a1bd4f
    switch (prop_id) {
Packit Service a1bd4f
    case PROP_DEVICES:
Packit Service a1bd4f
        g_value_take_boxed(value,
Packit Service a1bd4f
                           _nm_utils_copy_object_array(nm_checkpoint_get_devices(checkpoint)));
Packit Service a1bd4f
        break;
Packit Service a1bd4f
    case PROP_CREATED:
Packit Service a1bd4f
        g_value_set_int64(value, priv->created);
Packit Service a1bd4f
        break;
Packit Service a1bd4f
    case PROP_ROLLBACK_TIMEOUT:
Packit Service a1bd4f
        g_value_set_uint(value, priv->rollback_timeout);
Packit Service a1bd4f
        break;
Packit Service a1bd4f
    default:
Packit Service a1bd4f
        G_OBJECT_WARN_INVALID_PROPERTY_ID(object, prop_id, pspec);
Packit Service a1bd4f
        break;
Packit Service a1bd4f
    }
Packit 5756e2
}
Packit 5756e2
Packit Service a1bd4f
const NMLDBusMetaIface _nml_dbus_meta_iface_nm_checkpoint = NML_DBUS_META_IFACE_INIT_PROP(
Packit Service a1bd4f
    NM_DBUS_INTERFACE_CHECKPOINT,
Packit Service a1bd4f
    nm_checkpoint_get_type,
Packit Service a1bd4f
    NML_DBUS_META_INTERFACE_PRIO_INSTANTIATE_30,
Packit Service a1bd4f
    NML_DBUS_META_IFACE_DBUS_PROPERTIES(
Packit Service a1bd4f
        NML_DBUS_META_PROPERTY_INIT_X("Created", PROP_CREATED, NMCheckpoint, _priv.created),
Packit Service a1bd4f
        NML_DBUS_META_PROPERTY_INIT_AO_PROP("Devices",
Packit Service a1bd4f
                                            PROP_DEVICES,
Packit Service a1bd4f
                                            NMCheckpoint,
Packit Service a1bd4f
                                            _priv.devices,
Packit Service a1bd4f
                                            nm_device_get_type,
Packit Service a1bd4f
                                            .is_always_ready = TRUE),
Packit Service a1bd4f
        NML_DBUS_META_PROPERTY_INIT_U("RollbackTimeout",
Packit Service a1bd4f
                                      PROP_ROLLBACK_TIMEOUT,
Packit Service a1bd4f
                                      NMCheckpoint,
Packit Service a1bd4f
                                      _priv.rollback_timeout), ), );
Packit 5756e2
Packit 5756e2
static void
Packit Service a1bd4f
nm_checkpoint_class_init(NMCheckpointClass *klass)
Packit 5756e2
{
Packit Service a1bd4f
    GObjectClass * object_class    = G_OBJECT_CLASS(klass);
Packit Service a1bd4f
    NMObjectClass *nm_object_class = NM_OBJECT_CLASS(klass);
Packit Service a1bd4f
Packit Service a1bd4f
    object_class->get_property = get_property;
Packit Service a1bd4f
Packit Service a1bd4f
    _NM_OBJECT_CLASS_INIT_PRIV_PTR_DIRECT(nm_object_class, NMCheckpoint);
Packit Service a1bd4f
Packit Service a1bd4f
    _NM_OBJECT_CLASS_INIT_PROPERTY_AO_FIELDS_1(nm_object_class, NMCheckpointPrivate, devices);
Packit Service a1bd4f
Packit Service a1bd4f
    /**
Packit Service a1bd4f
     * NMCheckpoint:devices: (type GPtrArray(NMDevice))
Packit Service a1bd4f
     *
Packit Service a1bd4f
     * The devices that are part of this checkpoint.
Packit Service a1bd4f
     *
Packit Service a1bd4f
     * Since: 1.12
Packit Service a1bd4f
     **/
Packit Service a1bd4f
    obj_properties[PROP_DEVICES] = g_param_spec_boxed(NM_CHECKPOINT_DEVICES,
Packit Service a1bd4f
                                                      "",
Packit Service a1bd4f
                                                      "",
Packit Service a1bd4f
                                                      G_TYPE_PTR_ARRAY,
Packit Service a1bd4f
                                                      G_PARAM_READABLE | G_PARAM_STATIC_STRINGS);
Packit Service a1bd4f
Packit Service a1bd4f
    /**
Packit Service a1bd4f
     * NMCheckpoint:created:
Packit Service a1bd4f
     *
Packit Service a1bd4f
     * The timestamp (in CLOCK_BOOTTIME milliseconds) of checkpoint creation.
Packit Service a1bd4f
     *
Packit Service a1bd4f
     * Since: 1.12
Packit Service a1bd4f
     **/
Packit Service a1bd4f
    obj_properties[PROP_CREATED] = g_param_spec_int64(NM_CHECKPOINT_CREATED,
Packit Service a1bd4f
                                                      "",
Packit Service a1bd4f
                                                      "",
Packit Service a1bd4f
                                                      G_MININT64,
Packit Service a1bd4f
                                                      G_MAXINT64,
Packit Service a1bd4f
                                                      0,
Packit Service a1bd4f
                                                      G_PARAM_READABLE | G_PARAM_STATIC_STRINGS);
Packit Service a1bd4f
Packit Service a1bd4f
    /**
Packit Service a1bd4f
     * NMCheckpoint:rollback-timeout:
Packit Service a1bd4f
     *
Packit Service a1bd4f
     * Timeout in seconds for automatic rollback, or zero.
Packit Service a1bd4f
     *
Packit Service a1bd4f
     * Since: 1.12
Packit Service a1bd4f
     **/
Packit Service a1bd4f
    obj_properties[PROP_ROLLBACK_TIMEOUT] =
Packit Service a1bd4f
        g_param_spec_uint(NM_CHECKPOINT_ROLLBACK_TIMEOUT,
Packit Service a1bd4f
                          "",
Packit Service a1bd4f
                          "",
Packit Service a1bd4f
                          0,
Packit Service a1bd4f
                          G_MAXUINT32,
Packit Service a1bd4f
                          0,
Packit Service a1bd4f
                          G_PARAM_READABLE | G_PARAM_STATIC_STRINGS);
Packit Service a1bd4f
Packit Service a1bd4f
    _nml_dbus_meta_class_init_with_properties(object_class, &_nml_dbus_meta_iface_nm_checkpoint);
Packit 5756e2
}