From 79378fe268ff0a2924e0586f1d64b862a7621657 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Christian=20M=C3=BCller?= Date: Wed, 12 Jun 2019 14:42:59 +0200 Subject: [PATCH] Add Checkpoint properties --- Checkpoint.go | 42 +++++++++++++++++++++++++++++++++++++++++- utils.go | 8 ++++++++ 2 files changed, 49 insertions(+), 1 deletion(-) diff --git a/Checkpoint.go b/Checkpoint.go index 5a290b7..2b27125 100644 --- a/Checkpoint.go +++ b/Checkpoint.go @@ -2,9 +2,26 @@ package gonetworkmanager import "github.com/godbus/dbus" -type Checkpoint interface { +const ( + CheckpointInterface = NetworkManagerInterface + ".Checkpoint" + /* Properties */ + CheckpointPropertyDevices = CheckpointInterface + ".Devices" // readable ao + CheckpointPropertyCreated = CheckpointInterface + ".Created" // readable x + CheckpointPropertyRollbackTimeout = CheckpointInterface + ".RollbackTimeout" // readable u +) + +type Checkpoint interface { GetPath() dbus.ObjectPath + + // Array of object paths for devices which are part of this checkpoint. + GetPropertyDevices() []Device + + // The timestamp (in CLOCK_BOOTTIME milliseconds) of checkpoint creation. + GetPropertyCreated() int64 + + // Timeout in seconds for automatic rollback, or zero. + GetPropertyRollbackTimeout() uint32 } func NewCheckpoint(objectPath dbus.ObjectPath) (Checkpoint, error) { @@ -16,6 +33,29 @@ type checkpoint struct { dbusBase } +func (c *checkpoint) GetPropertyDevices() []Device { + devicesPaths := c.getSliceObjectProperty(CheckpointPropertyDevices) + devices := make([]Device, len(devicesPaths)) + + var err error + for i, path := range devicesPaths { + devices[i], err = NewDevice(path) + if err != nil { + panic(err) + } + } + + return devices +} + +func (c *checkpoint) GetPropertyCreated() int64 { + return c.getInt64Property(CheckpointPropertyCreated) +} + +func (c *checkpoint) GetPropertyRollbackTimeout() uint32 { + return c.getUint32Property(CheckpointPropertyRollbackTimeout) +} + func (c *checkpoint) GetPath() dbus.ObjectPath { return c.obj.Path() } diff --git a/utils.go b/utils.go index c03bdcc..8868534 100644 --- a/utils.go +++ b/utils.go @@ -140,6 +140,14 @@ func (d *dbusBase) getUint32Property(iface string) uint32 { return value } +func (d *dbusBase) getInt64Property(iface string) int64 { + value, ok := d.getProperty(iface).(int64) + if !ok { + panic(makeErrVariantType(iface)) + } + return value +} + func (d *dbusBase) getSliceUint32Property(iface string) []uint32 { value, ok := d.getProperty(iface).([]uint32) if !ok {