forked from Wifx/gonetworkmanager
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathDeviceGeneric.go
53 lines (40 loc) · 1.34 KB
/
DeviceGeneric.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
package gonetworkmanager
import (
"encoding/json"
"github.com/godbus/dbus/v5"
)
const (
DeviceGenericInterface = DeviceInterface + ".Generic"
// Properties
DeviceGenericPropertyHwAddress = DeviceGenericInterface + ".HwAddress" // readable s
DeviceGenericPropertyTypeDescription = DeviceGenericInterface + ".TypeDescription" // readable s
)
type DeviceGeneric interface {
Device
// GetPropertyHwAddress Active hardware address of the device.
GetPropertyHwAddress() (string, error)
// GetPropertyTypeDescription A (non-localized) description of the interface type, if known.
GetPropertyTypeDescription() (string, error)
}
func NewDeviceGeneric(objectPath dbus.ObjectPath) (DeviceGeneric, error) {
var d deviceGeneric
return &d, d.init(NetworkManagerInterface, objectPath)
}
type deviceGeneric struct {
device
}
func (d *deviceGeneric) GetPropertyHwAddress() (string, error) {
return d.getStringProperty(DeviceGenericPropertyHwAddress)
}
func (d *deviceGeneric) GetPropertyTypeDescription() (string, error) {
return d.getStringProperty(DeviceGenericPropertyTypeDescription)
}
func (d *deviceGeneric) MarshalJSON() ([]byte, error) {
m, err := d.device.marshalMap()
if err != nil {
return nil, err
}
m["HwAddress"], _ = d.GetPropertyHwAddress()
m["TypeDescription"], _ = d.GetPropertyTypeDescription()
return json.Marshal(m)
}