forked from BellerophonMobile/gonetworkmanager
-
Notifications
You must be signed in to change notification settings - Fork 42
/
DeviceWired.go
80 lines (61 loc) · 2.46 KB
/
DeviceWired.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
80
package gonetworkmanager
import (
"encoding/json"
"github.com/godbus/dbus/v5"
)
const (
DeviceWiredInterface = DeviceInterface + ".Wired"
// Properties
DeviceWiredPropertyHwAddress = DeviceWiredInterface + ".HwAddress" // readable s
DeviceWiredPropertyPermHwAddress = DeviceWiredInterface + ".PermHwAddress" // readable s
DeviceWiredPropertySpeed = DeviceWiredInterface + ".Speed" // readable u
DeviceWiredPropertyS390Subchannels = DeviceWiredInterface + ".S390Subchannels" // readable as
DeviceWiredPropertyCarrier = DeviceWiredInterface + ".Carrier" // readable b
)
type DeviceWired interface {
Device
// GetPropertyHwAddress Active hardware address of the device.
GetPropertyHwAddress() (string, error)
// GetPropertyPermHwAddress Permanent hardware address of the device.
GetPropertyPermHwAddress() (string, error)
// GetPropertySpeed Design speed of the device, in megabits/second (Mb/s).
GetPropertySpeed() (uint32, error)
// GetPropertyS390Subchannels Array of S/390 subchannels for S/390 or z/Architecture devices.
GetPropertyS390Subchannels() ([]string, error)
// GetPropertyCarrier Indicates whether the physical carrier is found (e.g. whether a cable is plugged in or not).
GetPropertyCarrier() (bool, error)
}
func NewDeviceWired(objectPath dbus.ObjectPath) (DeviceWired, error) {
var d deviceWired
return &d, d.init(NetworkManagerInterface, objectPath)
}
type deviceWired struct {
device
}
func (d *deviceWired) GetPropertyHwAddress() (string, error) {
return d.getStringProperty(DeviceWiredPropertyHwAddress)
}
func (d *deviceWired) GetPropertyPermHwAddress() (string, error) {
return d.getStringProperty(DeviceWiredPropertyPermHwAddress)
}
func (d *deviceWired) GetPropertySpeed() (uint32, error) {
return d.getUint32Property(DeviceWiredPropertySpeed)
}
func (d *deviceWired) GetPropertyS390Subchannels() ([]string, error) {
return d.getSliceStringProperty(DeviceWiredPropertyS390Subchannels)
}
func (d *deviceWired) GetPropertyCarrier() (bool, error) {
return d.getBoolProperty(DeviceWiredPropertyCarrier)
}
func (d *deviceWired) MarshalJSON() ([]byte, error) {
m, err := d.device.marshalMap()
if err != nil {
return nil, err
}
m["HwAddress"], _ = d.GetPropertyHwAddress()
m["PermHwAddress"], _ = d.GetPropertyPermHwAddress()
m["Speed"], _ = d.GetPropertySpeed()
m["S390Subchannels"], _ = d.GetPropertyS390Subchannels()
m["Carrier"], _ = d.GetPropertyCarrier()
return json.Marshal(m)
}