forked from BellerophonMobile/gonetworkmanager
-
Notifications
You must be signed in to change notification settings - Fork 41
/
Checkpoint.go
79 lines (59 loc) · 2.03 KB
/
Checkpoint.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
package gonetworkmanager
import (
"encoding/json"
"github.com/godbus/dbus/v5"
)
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
// GetPropertyDevices Array of object paths for devices which are part of this checkpoint.
GetPropertyDevices() ([]Device, error)
// GetPropertyCreated The timestamp (in CLOCK_BOOTTIME milliseconds) of checkpoint creation.
GetPropertyCreated() (int64, error)
// GetPropertyRollbackTimeout Timeout in seconds for automatic rollback, or zero.
GetPropertyRollbackTimeout() (uint32, error)
MarshalJSON() ([]byte, error)
}
func NewCheckpoint(objectPath dbus.ObjectPath) (Checkpoint, error) {
var c checkpoint
return &c, c.init(NetworkManagerInterface, objectPath)
}
type checkpoint struct {
dbusBase
}
func (c *checkpoint) GetPropertyDevices() ([]Device, error) {
devicesPaths, err := c.getSliceObjectProperty(CheckpointPropertyDevices)
if err != nil {
return nil, err
}
devices := make([]Device, len(devicesPaths))
for i, path := range devicesPaths {
devices[i], err = NewDevice(path)
if err != nil {
return devices, err
}
}
return devices, nil
}
func (c *checkpoint) GetPropertyCreated() (int64, error) {
return c.getInt64Property(CheckpointPropertyCreated)
}
func (c *checkpoint) GetPropertyRollbackTimeout() (uint32, error) {
return c.getUint32Property(CheckpointPropertyRollbackTimeout)
}
func (c *checkpoint) GetPath() dbus.ObjectPath {
return c.obj.Path()
}
func (c *checkpoint) MarshalJSON() ([]byte, error) {
m := make(map[string]interface{})
m["Devices"], _ = c.GetPropertyDevices()
m["Created"], _ = c.GetPropertyCreated()
m["RollbackTimeout"], _ = c.GetPropertyRollbackTimeout()
return json.Marshal(m)
}