Ad DeviceEthernet / Wired

This commit is contained in:
Christian Müller 2019-06-11 17:18:09 +02:00
parent acdef35b8f
commit fee15bfbc3
2 changed files with 77 additions and 0 deletions

View file

@ -57,6 +57,8 @@ func DeviceFactory(objectPath dbus.ObjectPath) (Device, error) {
return NewDeviceGeneric(objectPath) return NewDeviceGeneric(objectPath)
case NmDeviceTypeIpTunnel: case NmDeviceTypeIpTunnel:
return NewDeviceIpTunnel(objectPath) return NewDeviceIpTunnel(objectPath)
case NmDeviceTypeEthernet:
return NewDeviceWired(objectPath)
case NmDeviceTypeWifi: case NmDeviceTypeWifi:
return NewDeviceWireless(objectPath) return NewDeviceWireless(objectPath)
} }

75
DeviceWired.go Normal file
View file

@ -0,0 +1,75 @@
package gonetworkmanager
import (
"encoding/json"
"github.com/godbus/dbus"
)
const (
DeviceWiredInterface = DeviceInterface + ".Wired"
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
// Active hardware address of the device.
GetHwAddress() string
// Permanent hardware address of the device.
GetPermHwAddress() string
// Design speed of the device, in megabits/second (Mb/s).
GetSpeed() uint32
// Array of S/390 subchannels for S/390 or z/Architecture devices.
GetS390Subchannels() []string
// Indicates whether the physical carrier is found (e.g. whether a cable is plugged in or not).
GetCarrier() bool
}
func NewDeviceWired(objectPath dbus.ObjectPath) (DeviceWired, error) {
var d deviceWired
return &d, d.init(NetworkManagerInterface, objectPath)
}
type deviceWired struct {
device
}
func (d *deviceWired) GetHwAddress() string {
return d.getStringProperty(DeviceWiredPropertyHwAddress)
}
func (d *deviceWired) GetPermHwAddress() string {
return d.getStringProperty(DeviceWiredPropertyPermHwAddress)
}
func (d *deviceWired) GetSpeed() uint32 {
return d.getUint32Property(DeviceWiredPropertySpeed)
}
func (d *deviceWired) GetS390Subchannels() []string {
return d.getSliceStringProperty(DeviceWiredPropertyS390Subchannels)
}
func (d *deviceWired) GetCarrier() bool {
return d.getBoolProperty(DeviceWiredPropertyCarrier)
}
func (d *deviceWired) MarshalJSON() ([]byte, error) {
m := d.device.marshalMap()
m["HwAddress"] = d.GetHwAddress()
m["PermHwAddress"] = d.GetPermHwAddress()
m["Speed"] = d.GetSpeed()
m["S390Subchannels"] = d.GetS390Subchannels()
m["Carrier"] = d.GetCarrier()
return json.Marshal(m)
}