Merge pull request #1 from jkirkwood/master

Standardize property names and remove panics
This commit is contained in:
Christian Müller 2019-06-20 16:20:42 +02:00 committed by GitHub
commit 27de9ee243
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
18 changed files with 863 additions and 672 deletions

View file

@ -9,7 +9,7 @@ import (
const (
AccessPointInterface = NetworkManagerInterface + ".AccessPoint"
/* Property */
/* Properties */
AccessPointPropertyFlags = AccessPointInterface + ".Flags" // readable u
AccessPointPropertyWpaFlags = AccessPointInterface + ".WpaFlags" // readable u
AccessPointPropertyRsnFlags = AccessPointInterface + ".RsnFlags" // readable u
@ -26,36 +26,36 @@ type AccessPoint interface {
GetPath() dbus.ObjectPath
// GetFlags gets flags describing the capabilities of the access point.
GetFlags() uint32
GetPropertyFlags() (uint32, error)
// GetWPAFlags gets flags describing the access point's capabilities
// according to WPA (Wifi Protected Access).
GetWPAFlags() uint32
GetPropertyWPAFlags() (uint32, error)
// GetRSNFlags gets flags describing the access point's capabilities
// according to the RSN (Robust Secure Network) protocol.
GetRSNFlags() uint32
GetPropertyRSNFlags() (uint32, error)
// GetSSID returns the Service Set Identifier identifying the access point.
GetSSID() string
GetPropertySSID() (string, error)
// GetFrequency gets the radio channel frequency in use by the access point,
// in MHz.
GetFrequency() uint32
GetPropertyFrequency() (uint32, error)
// GetHWAddress gets the hardware address (BSSID) of the access point.
GetHWAddress() string
GetPropertyHWAddress() (string, error)
// GetMode describes the operating mode of the access point.
GetMode() Nm80211Mode
GetPropertyMode() (Nm80211Mode, error)
// GetMaxBitrate gets the maximum bitrate this access point is capable of, in
// kilobits/second (Kb/s).
GetMaxBitrate() uint32
GetPropertyMaxBitrate() (uint32, error)
// GetStrength gets the current signal quality of the access point, in
// percent.
GetStrength() uint8
GetPropertyStrength() (uint8, error)
MarshalJSON() ([]byte, error)
}
@ -73,52 +73,58 @@ func (a *accessPoint) GetPath() dbus.ObjectPath {
return a.obj.Path()
}
func (a *accessPoint) GetFlags() uint32 {
func (a *accessPoint) GetPropertyFlags() (uint32, error) {
return a.getUint32Property(AccessPointPropertyFlags)
}
func (a *accessPoint) GetWPAFlags() uint32 {
func (a *accessPoint) GetPropertyWPAFlags() (uint32, error) {
return a.getUint32Property(AccessPointPropertyWpaFlags)
}
func (a *accessPoint) GetRSNFlags() uint32 {
func (a *accessPoint) GetPropertyRSNFlags() (uint32, error) {
return a.getUint32Property(AccessPointPropertyRsnFlags)
}
func (a *accessPoint) GetSSID() string {
return string(a.getSliceByteProperty(AccessPointPropertySsid))
func (a *accessPoint) GetPropertySSID() (string, error) {
v, err := a.getSliceByteProperty(AccessPointPropertySsid)
return string(v), err
}
func (a *accessPoint) GetFrequency() uint32 {
func (a *accessPoint) GetPropertyFrequency() (uint32, error) {
return a.getUint32Property(AccessPointPropertyFrequency)
}
func (a *accessPoint) GetHWAddress() string {
func (a *accessPoint) GetPropertyHWAddress() (string, error) {
return a.getStringProperty(AccessPointPropertyHwAddress)
}
func (a *accessPoint) GetMode() Nm80211Mode {
return Nm80211Mode(a.getUint32Property(AccessPointPropertyMode))
func (a *accessPoint) GetPropertyMode() (Nm80211Mode, error) {
v, err := a.getUint32Property(AccessPointPropertyMode)
return Nm80211Mode(v), err
}
func (a *accessPoint) GetMaxBitrate() uint32 {
func (a *accessPoint) GetPropertyMaxBitrate() (uint32, error) {
return a.getUint32Property(AccessPointPropertyMaxBitrate)
}
func (a *accessPoint) GetStrength() uint8 {
func (a *accessPoint) GetPropertyStrength() (uint8, error) {
return a.getUint8Property(AccessPointPropertyStrength)
}
func (a *accessPoint) MarshalJSON() ([]byte, error) {
return json.Marshal(map[string]interface{}{
"Flags": a.GetFlags(),
"WPAFlags": a.GetWPAFlags(),
"RSNFlags": a.GetRSNFlags(),
"SSID": a.GetSSID(),
"Frequency": a.GetFrequency(),
"HWAddress": a.GetHWAddress(),
"Mode": a.GetMode().String(),
"MaxBitrate": a.GetMaxBitrate(),
"Strength": a.GetStrength(),
})
m := make(map[string]interface{})
m["Flags"], _ = a.GetPropertyFlags()
m["WPAFlags"], _ = a.GetPropertyWPAFlags()
m["RSNFlags"], _ = a.GetPropertyRSNFlags()
m["SSID"], _ = a.GetPropertySSID()
m["Frequency"], _ = a.GetPropertyFrequency()
m["HWAddress"], _ = a.GetPropertyHWAddress()
m["MaxBitrate"], _ = a.GetPropertyMaxBitrate()
m["Strength"], _ = a.GetPropertyStrength()
mode, _ := a.GetPropertyMode()
m["Mode"] = mode.String()
return json.Marshal(m)
}

View file

@ -7,7 +7,7 @@ import (
const (
ActiveConnectionInterface = NetworkManagerInterface + ".Connection.Active"
/* Property */
/* Properties */
ActiveConnectionPropertyConnection = ActiveConnectionInterface + ".Connection" // readable o
ActiveConnectionPropertySpecificObject = ActiveConnectionInterface + ".SpecificObject" // readable o
ActiveConnectionPropertyId = ActiveConnectionInterface + ".Id" // readable s
@ -30,52 +30,52 @@ type ActiveConnection interface {
GetPath() dbus.ObjectPath
// GetConnectionSettings gets connection object of the connection.
GetConnection() Connection
GetPropertyConnection() (Connection, error)
// GetSpecificObject gets a specific object associated with the active connection.
GetSpecificObject() AccessPoint
GetPropertySpecificObject() (AccessPoint, error)
// GetID gets the ID of the connection.
GetID() string
GetPropertyID() (string, error)
// GetUUID gets the UUID of the connection.
GetUUID() string
GetPropertyUUID() (string, error)
// GetType gets the type of the connection.
GetType() string
GetPropertyType() (string, error)
// GetDevices gets array of device objects which are part of this active connection.
GetDevices() []Device
GetPropertyDevices() ([]Device, error)
// GetState gets the state of the connection.
GetState() NmActiveConnectionState
GetPropertyState() (NmActiveConnectionState, error)
// GetStateFlags gets the state flags of the connection.
GetStateFlags() uint32
GetPropertyStateFlags() (uint32, error)
// GetDefault gets the default IPv4 flag of the connection.
GetDefault() bool
GetPropertyDefault() (bool, error)
// GetIP4Config gets the IP4Config of the connection.
GetIP4Config() IP4Config
GetPropertyIP4Config() (IP4Config, error)
// GetDHCP4Config gets the DHCP6Config of the connection.
GetDHCP4Config() DHCP4Config
GetPropertyDHCP4Config() (DHCP4Config, error)
// GetDefault gets the default IPv6 flag of the connection.
GetDefault6() bool
GetPropertyDefault6() (bool, error)
// GetIP6Config gets the IP6Config of the connection.
GetIP6Config() IP6Config
GetPropertyIP6Config() (IP6Config, error)
// GetDHCP6Config gets the DHCP4Config of the connection.
GetDHCP6Config() DHCP6Config
GetPropertyDHCP6Config() (DHCP6Config, error)
// GetVPN gets the VPN flag of the connection.
GetVPN() bool
GetPropertyVPN() (bool, error)
// GetMaster gets the master device of the connection.
GetMaster() Device
GetPropertyMaster() (Device, error)
}
func NewActiveConnection(objectPath dbus.ObjectPath) (ActiveConnection, error) {
@ -91,129 +91,114 @@ func (a *activeConnection) GetPath() dbus.ObjectPath {
return a.obj.Path()
}
func (a *activeConnection) GetConnection() Connection {
path := a.getObjectProperty(ActiveConnectionPropertyConnection)
con, err := NewConnection(path)
func (a *activeConnection) GetPropertyConnection() (Connection, error) {
path, err := a.getObjectProperty(ActiveConnectionPropertyConnection)
if err != nil {
panic(err)
}
return con
return nil, err
}
func (a *activeConnection) GetSpecificObject() AccessPoint {
path := a.getObjectProperty(ActiveConnectionPropertySpecificObject)
ap, err := NewAccessPoint(path)
if err != nil {
panic(err)
}
return ap
return NewConnection(path)
}
func (a *activeConnection) GetID() string {
func (a *activeConnection) GetPropertySpecificObject() (AccessPoint, error) {
path, err := a.getObjectProperty(ActiveConnectionPropertySpecificObject)
if err != nil {
return nil, err
}
return NewAccessPoint(path)
}
func (a *activeConnection) GetPropertyID() (string, error) {
return a.getStringProperty(ActiveConnectionPropertyId)
}
func (a *activeConnection) GetUUID() string {
func (a *activeConnection) GetPropertyUUID() (string, error) {
return a.getStringProperty(ActiveConnectionPropertyUuid)
}
func (a *activeConnection) GetType() string {
func (a *activeConnection) GetPropertyType() (string, error) {
return a.getStringProperty(ActiveConnectionPropertyType)
}
func (a *activeConnection) GetDevices() []Device {
paths := a.getSliceObjectProperty(ActiveConnectionPropertyDevices)
func (a *activeConnection) GetPropertyDevices() ([]Device, error) {
paths, err := a.getSliceObjectProperty(ActiveConnectionPropertyDevices)
if err != nil {
return nil, err
}
devices := make([]Device, len(paths))
var err error
for i, path := range paths {
devices[i], err = DeviceFactory(path)
if err != nil {
panic(err)
return devices, err
}
}
return devices
return devices, nil
}
func (a *activeConnection) GetState() NmActiveConnectionState {
return NmActiveConnectionState(a.getUint32Property(ActiveConnectionPropertyState))
func (a *activeConnection) GetPropertyState() (NmActiveConnectionState, error) {
v, err := a.getUint32Property(ActiveConnectionPropertyState)
return NmActiveConnectionState(v), err
}
func (a *activeConnection) GetStateFlags() uint32 {
func (a *activeConnection) GetPropertyStateFlags() (uint32, error) {
return a.getUint32Property(ActiveConnectionPropertyStateFlags)
}
func (a *activeConnection) GetDefault() bool {
b := a.getProperty(ActiveConnectionPropertyDefault)
return b.(bool)
func (a *activeConnection) GetPropertyDefault() (bool, error) {
return a.getBoolProperty(ActiveConnectionPropertyDefault)
}
func (a *activeConnection) GetIP4Config() IP4Config {
path := a.getObjectProperty(ActiveConnectionPropertyIp4Config)
if path == "/" {
return nil
func (a *activeConnection) GetPropertyIP4Config() (IP4Config, error) {
path, err := a.getObjectProperty(ActiveConnectionPropertyIp4Config)
if err != nil || path == "/" {
return nil, err
}
r, err := NewIP4Config(path)
return NewIP4Config(path)
}
func (a *activeConnection) GetPropertyDHCP4Config() (DHCP4Config, error) {
path, err := a.getObjectProperty(ActiveConnectionPropertyDhcp4Config)
if err != nil || path == "/" {
return nil, err
}
return NewDHCP4Config(path)
}
func (a *activeConnection) GetPropertyDefault6() (bool, error) {
return a.getBoolProperty(ActiveConnectionPropertyDefault6)
}
func (a *activeConnection) GetPropertyIP6Config() (IP6Config, error) {
path, err := a.getObjectProperty(ActiveConnectionPropertyIp6Config)
if err != nil || path == "/" {
return nil, err
}
return NewIP6Config(path)
}
func (a *activeConnection) GetPropertyDHCP6Config() (DHCP6Config, error) {
path, err := a.getObjectProperty(ActiveConnectionPropertyDhcp6Config)
if err != nil || path == "/" {
return nil, err
}
return NewDHCP6Config(path)
}
func (a *activeConnection) GetPropertyVPN() (bool, error) {
return a.getBoolProperty(ActiveConnectionPropertyVpn)
}
func (a *activeConnection) GetPropertyMaster() (Device, error) {
path, err := a.getObjectProperty(ActiveConnectionPropertyMaster)
if err != nil {
panic(err)
}
return r
return nil, err
}
func (a *activeConnection) GetDHCP4Config() DHCP4Config {
path := a.getObjectProperty(ActiveConnectionPropertyDhcp4Config)
if path == "/" {
return nil
}
r, err := NewDHCP4Config(path)
if err != nil {
panic(err)
}
return r
}
func (a *activeConnection) GetDefault6() bool {
b := a.getProperty(ActiveConnectionPropertyDefault6)
return b.(bool)
}
func (a *activeConnection) GetIP6Config() IP6Config {
path := a.getObjectProperty(ActiveConnectionPropertyIp6Config)
if path == "/" {
return nil
}
r, err := NewIP6Config(path)
if err != nil {
panic(err)
}
return r
}
func (a *activeConnection) GetDHCP6Config() DHCP6Config {
path := a.getObjectProperty(ActiveConnectionPropertyDhcp6Config)
if path == "/" {
return nil
}
r, err := NewDHCP6Config(path)
if err != nil {
panic(err)
}
return r
}
func (a *activeConnection) GetVPN() bool {
ret := a.getProperty(ActiveConnectionPropertyVpn)
return ret.(bool)
}
func (a *activeConnection) GetMaster() Device {
path := a.getObjectProperty(ActiveConnectionPropertyMaster)
r, err := DeviceFactory(path)
if err != nil {
panic(err)
}
return r
return DeviceFactory(path)
}

View file

@ -2,6 +2,7 @@ package gonetworkmanager
import (
"encoding/json"
"github.com/godbus/dbus"
)
@ -18,13 +19,13 @@ type Checkpoint interface {
GetPath() dbus.ObjectPath
// Array of object paths for devices which are part of this checkpoint.
GetPropertyDevices() []Device
GetPropertyDevices() ([]Device, error)
// The timestamp (in CLOCK_BOOTTIME milliseconds) of checkpoint creation.
GetPropertyCreated() int64
GetPropertyCreated() (int64, error)
// Timeout in seconds for automatic rollback, or zero.
GetPropertyRollbackTimeout() uint32
GetPropertyRollbackTimeout() (uint32, error)
MarshalJSON() ([]byte, error)
}
@ -38,26 +39,28 @@ type checkpoint struct {
dbusBase
}
func (c *checkpoint) GetPropertyDevices() []Device {
devicesPaths := c.getSliceObjectProperty(CheckpointPropertyDevices)
devices := make([]Device, len(devicesPaths))
func (c *checkpoint) GetPropertyDevices() ([]Device, error) {
devicesPaths, err := c.getSliceObjectProperty(CheckpointPropertyDevices)
if err != nil {
return nil, err
}
var err error
devices := make([]Device, len(devicesPaths))
for i, path := range devicesPaths {
devices[i], err = NewDevice(path)
if err != nil {
panic(err)
return devices, err
}
}
return devices
return devices, nil
}
func (c *checkpoint) GetPropertyCreated() int64 {
func (c *checkpoint) GetPropertyCreated() (int64, error) {
return c.getInt64Property(CheckpointPropertyCreated)
}
func (c *checkpoint) GetPropertyRollbackTimeout() uint32 {
func (c *checkpoint) GetPropertyRollbackTimeout() (uint32, error) {
return c.getUint32Property(CheckpointPropertyRollbackTimeout)
}
@ -65,14 +68,12 @@ func (c *checkpoint) GetPath() dbus.ObjectPath {
return c.obj.Path()
}
func (c *checkpoint) marshalMap() map[string]interface{} {
return map[string]interface{}{
"Devices": c.GetPropertyDevices(),
"Created": c.GetPropertyCreated(),
"RollbackTimeout": c.GetPropertyRollbackTimeout(),
}
}
func (c *checkpoint) MarshalJSON() ([]byte, error) {
return json.Marshal(c.marshalMap())
m := make(map[string]interface{})
m["Devices"], _ = c.GetPropertyDevices()
m["Created"], _ = c.GetPropertyCreated()
m["RollbackTimeout"], _ = c.GetPropertyRollbackTimeout()
return json.Marshal(m)
}

View file

@ -43,8 +43,8 @@ type Connection interface {
// GetSettings gets the settings maps describing this network configuration.
// This will never include any secrets required for connection to the
// network, as those are often protected. Secrets must be requested
// separately using the GetSecrets() callWithReturnAndPanic.
GetSettings() ConnectionSettings
// separately using the GetSecrets() method.
GetSettings() (ConnectionSettings, error)
// Clear the secrets belonging to this network connection profile.
ClearSecrets() error
@ -53,13 +53,13 @@ type Connection interface {
Save() error
// If set, indicates that the in-memory state of the connection does not match the on-disk state. This flag will be set when UpdateUnsaved() is called or when any connection details change, and cleared when the connection is saved to disk via Save() or from internal operations.
GetUnsaved() bool
GetPropertyUnsaved() (bool, error)
// Additional flags of the connection profile.
GetFlags() uint32
GetPropertyFlags() (uint32, error)
// File that stores the connection in case the connection is file-backed.
GetFilename() string
GetPropertyFilename() (string, error)
MarshalJSON() ([]byte, error)
}
@ -89,9 +89,13 @@ func (c *connection) Delete() error {
return c.call(ConnectionDelete)
}
func (c *connection) GetSettings() ConnectionSettings {
func (c *connection) GetSettings() (ConnectionSettings, error) {
var settings map[string]map[string]dbus.Variant
c.callWithReturnAndPanic(&settings, ConnectionGetSettings)
err := c.callWithReturn(&settings, ConnectionGetSettings)
if err != nil {
return nil, err
}
rv := make(ConnectionSettings)
@ -103,7 +107,7 @@ func (c *connection) GetSettings() ConnectionSettings {
}
}
return rv
return rv, nil
}
func (c *connection) ClearSecrets() error {
@ -114,18 +118,19 @@ func (c *connection) Save() error {
return c.call(ConnectionSave)
}
func (c *connection) GetUnsaved() bool {
func (c *connection) GetPropertyUnsaved() (bool, error) {
return c.getBoolProperty(ConnectionPropertyUnsaved)
}
func (c *connection) GetFlags() uint32 {
func (c *connection) GetPropertyFlags() (uint32, error) {
return c.getUint32Property(ConnectionPropertyFlags)
}
func (c *connection) GetFilename() string {
func (c *connection) GetPropertyFilename() (string, error) {
return c.getStringProperty(ConnectionPropertyFilename)
}
func (c *connection) MarshalJSON() ([]byte, error) {
return json.Marshal(c.GetSettings())
s, _ := c.GetSettings()
return json.Marshal(s)
}

View file

@ -9,6 +9,7 @@ import (
const (
DHCP4ConfigInterface = NetworkManagerInterface + ".DHCP4Config"
// Properties
DHCP4ConfigPropertyOptions = DHCP4ConfigInterface + ".Options"
)
@ -16,7 +17,7 @@ type DHCP4Options map[string]interface{}
type DHCP4Config interface {
// GetOptions gets options map of configuration returned by the IPv4 DHCP server.
GetOptions() DHCP4Options
GetPropertyOptions() (DHCP4Options, error)
MarshalJSON() ([]byte, error)
}
@ -30,19 +31,23 @@ type dhcp4Config struct {
dbusBase
}
func (c *dhcp4Config) GetOptions() DHCP4Options {
options := c.getMapStringVariantProperty(DHCP4ConfigPropertyOptions)
func (c *dhcp4Config) GetPropertyOptions() (DHCP4Options, error) {
options, err := c.getMapStringVariantProperty(DHCP4ConfigPropertyOptions)
rv := make(DHCP4Options)
if err != nil {
return rv, err
}
for k, v := range options {
rv[k] = v.Value()
}
return rv
return rv, nil
}
func (c *dhcp4Config) MarshalJSON() ([]byte, error) {
return json.Marshal(map[string]interface{}{
"Options": c.GetOptions(),
})
m := make(map[string]interface{})
m["Options"], _ = c.GetPropertyOptions()
return json.Marshal(m)
}

View file

@ -9,6 +9,7 @@ import (
const (
DHCP6ConfigInterface = NetworkManagerInterface + ".DHCP6Config"
// Properties
DHCP6ConfigPropertyOptions = DHCP6ConfigInterface + ".Options"
)
@ -16,7 +17,7 @@ type DHCP6Options map[string]interface{}
type DHCP6Config interface {
// GetOptions gets options map of configuration returned by the IPv4 DHCP server.
GetOptions() DHCP6Options
GetPropertyOptions() (DHCP6Options, error)
MarshalJSON() ([]byte, error)
}
@ -30,19 +31,24 @@ type dhcp6Config struct {
dbusBase
}
func (c *dhcp6Config) GetOptions() DHCP6Options {
options := c.getMapStringVariantProperty(DHCP6ConfigPropertyOptions)
func (c *dhcp6Config) GetPropertyOptions() (DHCP6Options, error) {
options, err := c.getMapStringVariantProperty(DHCP6ConfigPropertyOptions)
rv := make(DHCP6Options)
if err != nil {
return rv, err
}
for k, v := range options {
rv[k] = v.Value()
}
return rv
return rv, nil
}
func (c *dhcp6Config) MarshalJSON() ([]byte, error) {
return json.Marshal(map[string]interface{}{
"Options": c.GetOptions(),
})
m := make(map[string]interface{})
m["Options"], _ = c.GetPropertyOptions()
return json.Marshal(m)
}

181
Device.go
View file

@ -50,7 +50,12 @@ func DeviceFactory(objectPath dbus.ObjectPath) (Device, error) {
return nil, err
}
switch d.GetDeviceType() {
deviceType, err := d.GetPropertyDeviceType()
if err != nil {
return nil, err
}
switch deviceType {
case NmDeviceTypeDummy:
return NewDeviceDummy(objectPath)
case NmDeviceTypeGeneric:
@ -76,64 +81,64 @@ type Device interface {
Delete() error
// Operating-system specific transient device hardware identifier. This is an opaque string representing the underlying hardware for the device, and shouldn't be used to keep track of individual devices. For some device types (Bluetooth, Modems) it is an identifier used by the hardware service (ie bluez or ModemManager) to refer to that device, and client programs use it get additional information from those services which NM does not provide. The Udi is not guaranteed to be consistent across reboots or hotplugs of the hardware. If you're looking for a way to uniquely track each device in your application, use the object path. If you're looking for a way to track a specific piece of hardware across reboot or hotplug, use a MAC address or USB serial number.
GetUdi() string
GetPropertyUdi() (string, error)
// The name of the device's control (and often data) interface. Note that non UTF-8 characters are backslash escaped, so the resulting name may be longer then 15 characters. Use g_strcompress() to revert the escaping.
GetInterface() string
GetPropertyInterface() (string, error)
// The name of the device's data interface when available. This property may not refer to the actual data interface until the device has successfully established a data connection, indicated by the device's State becoming ACTIVATED. Note that non UTF-8 characters are backslash escaped, so the resulting name may be longer then 15 characters. Use g_strcompress() to revert the escaping.
GetIpInterface() string
GetPropertyIpInterface() (string, error)
// The driver handling the device. Non-UTF-8 sequences are backslash escaped. Use g_strcompress() to revert.
GetDriver() string
GetPropertyDriver() (string, error)
// The version of the driver handling the device. Non-UTF-8 sequences are backslash escaped. Use g_strcompress() to revert.
GetDriverVersion() string
GetPropertyDriverVersion() (string, error)
// The firmware version for the device. Non-UTF-8 sequences are backslash escaped. Use g_strcompress() to revert.
GetFirmwareVersion() string
GetPropertyFirmwareVersion() (string, error)
// The current state of the device.
GetState() NmDeviceState
GetPropertyState() (NmDeviceState, error)
// Object path of the Ip4Config object describing the configuration of the device. Only valid when the device is in the NM_DEVICE_STATE_ACTIVATED state.
GetIP4Config() IP4Config
GetPropertyIP4Config() (IP4Config, error)
// Object path of the Dhcp4Config object describing the DHCP options returned by the DHCP server. Only valid when the device is in the NM_DEVICE_STATE_ACTIVATED state.
GetDHCP4Config() DHCP4Config
GetPropertyDHCP4Config() (DHCP4Config, error)
// Object path of the Ip6Config object describing the configuration of the device. Only valid when the device is in the NM_DEVICE_STATE_ACTIVATED state.
GetIP6Config() IP6Config
GetPropertyIP6Config() (IP6Config, error)
// Object path of the Dhcp6Config object describing the DHCP options returned by the DHCP server. Only valid when the device is in the NM_DEVICE_STATE_ACTIVATED state.
GetDHCP6Config() DHCP6Config
GetPropertyDHCP6Config() (DHCP6Config, error)
// Whether or not this device is managed by NetworkManager. Setting this property has a similar effect to configuring the device as unmanaged via the keyfile.unmanaged-devices setting in NetworkManager.conf. Changes to this value are not persistent and lost after NetworkManager restart.
GetManaged() bool
GetPropertyManaged() (bool, error)
// If TRUE, indicates the device is allowed to autoconnect. If FALSE, manual intervention is required before the device will automatically connect to a known network, such as activating a connection using the device, or setting this property to TRUE. This property cannot be set to TRUE for default-unmanaged devices, since they never autoconnect.
GetAutoConnect() bool
GetPropertyAutoConnect() (bool, error)
// If TRUE, indicates the device is likely missing firmware necessary for its operation.
GetFirmwareMissing() bool
GetPropertyFirmwareMissing() (bool, error)
// If TRUE, indicates the NetworkManager plugin for the device is likely missing or misconfigured.
GetNmPluginMissing() bool
GetPropertyNmPluginMissing() (bool, error)
// The general type of the network device; ie Ethernet, Wi-Fi, etc.
GetDeviceType() NmDeviceType
GetPropertyDeviceType() (NmDeviceType, error)
// An array of object paths of every configured connection that is currently 'available' through this device.
GetAvailableConnections() []Connection
GetPropertyAvailableConnections() ([]Connection, error)
// If non-empty, an (opaque) indicator of the physical network port associated with the device. This can be used to recognize when two seemingly-separate hardware devices are actually just different virtual interfaces to the same physical port.
GetPhysicalPortId() string
GetPropertyPhysicalPortId() (string, error)
// The device MTU (maximum transmission unit).
GetMtu() uint32
GetPropertyMtu() (uint32, error)
// True if the device exists, or False for placeholder devices that do not yet exist but could be automatically created by NetworkManager if one of their AvailableConnections was activated.
GetReal() bool
GetPropertyReal() (bool, error)
MarshalJSON() ([]byte, error)
}
@ -159,147 +164,137 @@ func (d *device) Delete() error {
return d.call(DeviceDelete)
}
func (d *device) GetUdi() string {
func (d *device) GetPropertyUdi() (string, error) {
return d.getStringProperty(DevicePropertyUdi)
}
func (d *device) GetInterface() string {
func (d *device) GetPropertyInterface() (string, error) {
return d.getStringProperty(DevicePropertyInterface)
}
func (d *device) GetIpInterface() string {
func (d *device) GetPropertyIpInterface() (string, error) {
return d.getStringProperty(DevicePropertyIpInterface)
}
func (d *device) GetDriver() string {
func (d *device) GetPropertyDriver() (string, error) {
return d.getStringProperty(DevicePropertyDriver)
}
func (d *device) GetDriverVersion() string {
func (d *device) GetPropertyDriverVersion() (string, error) {
return d.getStringProperty(DevicePropertyDriverVersion)
}
func (d *device) GetFirmwareVersion() string {
func (d *device) GetPropertyFirmwareVersion() (string, error) {
return d.getStringProperty(DevicePropertyFirmwareVersion)
}
func (d *device) GetState() NmDeviceState {
return NmDeviceState(d.getUint32Property(DevicePropertyState))
func (d *device) GetPropertyState() (NmDeviceState, error) {
v, err := d.getUint32Property(DevicePropertyState)
return NmDeviceState(v), err
}
func (d *device) GetIP4Config() IP4Config {
path := d.getObjectProperty(DevicePropertyIp4Config)
if path == "/" {
return nil
func (d *device) GetPropertyIP4Config() (IP4Config, error) {
path, err := d.getObjectProperty(DevicePropertyIp4Config)
if err != nil || path == "/" {
return nil, err
}
cfg, err := NewIP4Config(path)
if err != nil {
panic(err)
return NewIP4Config(path)
}
return cfg
func (d *device) GetPropertyDHCP4Config() (DHCP4Config, error) {
path, err := d.getObjectProperty(DevicePropertyDhcp4Config)
if err != nil || path == "/" {
return nil, err
}
func (d *device) GetDHCP4Config() DHCP4Config {
path := d.getObjectProperty(DevicePropertyDhcp4Config)
if path == "/" {
return nil
return NewDHCP4Config(path)
}
cfg, err := NewDHCP4Config(path)
if err != nil {
panic(err)
func (d *device) GetPropertyIP6Config() (IP6Config, error) {
path, err := d.getObjectProperty(DevicePropertyIp6Config)
if err != nil || path == "/" {
return nil, err
}
return cfg
return NewIP6Config(path)
}
func (d *device) GetIP6Config() IP6Config {
path := d.getObjectProperty(DevicePropertyIp6Config)
if path == "/" {
return nil
func (d *device) GetPropertyDHCP6Config() (DHCP6Config, error) {
path, err := d.getObjectProperty(DevicePropertyDhcp6Config)
if err != nil || path == "/" {
return nil, err
}
cfg, err := NewIP6Config(path)
if err != nil {
panic(err)
return NewDHCP6Config(path)
}
return cfg
}
func (d *device) GetDHCP6Config() DHCP6Config {
path := d.getObjectProperty(DevicePropertyDhcp6Config)
if path == "/" {
return nil
}
cfg, err := NewDHCP6Config(path)
if err != nil {
panic(err)
}
return cfg
}
func (d *device) GetManaged() bool {
func (d *device) GetPropertyManaged() (bool, error) {
return d.getBoolProperty(DevicePropertyManaged)
}
func (d *device) GetAutoConnect() bool {
func (d *device) GetPropertyAutoConnect() (bool, error) {
return d.getBoolProperty(DevicePropertyAutoconnect)
}
func (d *device) GetFirmwareMissing() bool {
func (d *device) GetPropertyFirmwareMissing() (bool, error) {
return d.getBoolProperty(DevicePropertyFirmwareMissing)
}
func (d *device) GetNmPluginMissing() bool {
func (d *device) GetPropertyNmPluginMissing() (bool, error) {
return d.getBoolProperty(DevicePropertyNmPluginMissing)
}
func (d *device) GetDeviceType() NmDeviceType {
return NmDeviceType(d.getUint32Property(DevicePropertyDeviceType))
func (d *device) GetPropertyDeviceType() (NmDeviceType, error) {
v, err := d.getUint32Property(DevicePropertyDeviceType)
return NmDeviceType(v), err
}
func (d *device) GetAvailableConnections() []Connection {
connPaths := d.getSliceObjectProperty(DevicePropertyAvailableConnections)
conns := make([]Connection, len(connPaths))
func (d *device) GetPropertyAvailableConnections() ([]Connection, error) {
connPaths, err := d.getSliceObjectProperty(DevicePropertyAvailableConnections)
if err != nil {
return nil, err
}
var err error
conns := make([]Connection, len(connPaths))
for i, path := range connPaths {
conns[i], err = NewConnection(path)
if err != nil {
panic(err)
return conns, err
}
}
return conns
return conns, nil
}
func (d *device) GetPhysicalPortId() string {
func (d *device) GetPropertyPhysicalPortId() (string, error) {
return d.getStringProperty(DevicePropertyPhysicalPortId)
}
func (d *device) GetMtu() uint32 {
func (d *device) GetPropertyMtu() (uint32, error) {
return d.getUint32Property(DevicePropertyMtu)
}
func (d *device) GetReal() bool {
func (d *device) GetPropertyReal() (bool, error) {
return d.getBoolProperty(DevicePropertyReal)
}
func (d *device) marshalMap() map[string]interface{} {
return map[string]interface{}{
"Interface": d.GetInterface(),
"IP interface": d.GetIpInterface(),
"State": d.GetState().String(),
"IP4Config": d.GetIP4Config(),
"DHCP4Config": d.GetDHCP4Config(),
"DeviceType": d.GetDeviceType().String(),
"AvailableConnections": d.GetAvailableConnections(),
}
m := make(map[string]interface{})
m["Interface"], _ = d.GetPropertyInterface()
m["IPInterface"], _ = d.GetPropertyIpInterface()
m["IP4Config"], _ = d.GetPropertyIP4Config()
m["DHCP4Config"], _ = d.GetPropertyDHCP4Config()
m["AvailableConnections"], _ = d.GetPropertyAvailableConnections()
state, _ := d.GetPropertyState()
m["State"] = state.String()
deviceType, _ := d.GetPropertyDeviceType()
m["DeviceType"] = deviceType.String()
return m
}
func (d *device) MarshalJSON() ([]byte, error) {

View file

@ -9,6 +9,7 @@ import (
const (
DeviceDummyInterface = DeviceInterface + ".Dummy"
/* Properties */
DeviceDummyPropertyHwAddress = DeviceDummyInterface + ".HwAddress" // readable s
)
@ -16,7 +17,7 @@ type DeviceDummy interface {
Device
// Hardware address of the device.
GetHwAddress() string
GetPropertyHwAddress() (string, error)
}
func NewDeviceDummy(objectPath dbus.ObjectPath) (DeviceDummy, error) {
@ -28,12 +29,12 @@ type deviceDummy struct {
device
}
func (d *deviceDummy) GetHwAddress() string {
func (d *deviceDummy) GetPropertyHwAddress() (string, error) {
return d.getStringProperty(DeviceDummyPropertyHwAddress)
}
func (d *deviceDummy) MarshalJSON() ([]byte, error) {
m := d.device.marshalMap()
m["HwAddress"] = d.GetHwAddress()
m["HwAddress"], _ = d.GetPropertyHwAddress()
return json.Marshal(m)
}

View file

@ -9,6 +9,7 @@ import (
const (
DeviceGenericInterface = DeviceInterface + ".Generic"
// Properties
DeviceGenericPropertyHwAddress = DeviceGenericInterface + ".HwAddress" // readable s
DeviceGenericPropertyTypeDescription = DeviceGenericInterface + ".TypeDescription" // readable s
)
@ -17,10 +18,10 @@ type DeviceGeneric interface {
Device
// Active hardware address of the device.
GetHwAddress() string
GetPropertyHwAddress() (string, error)
// A (non-localized) description of the interface type, if known.
GetTypeDescription() string
GetPropertyTypeDescription() (string, error)
}
func NewDeviceGeneric(objectPath dbus.ObjectPath) (DeviceGeneric, error) {
@ -32,17 +33,17 @@ type deviceGeneric struct {
device
}
func (d *deviceGeneric) GetHwAddress() string {
func (d *deviceGeneric) GetPropertyHwAddress() (string, error) {
return d.getStringProperty(DeviceGenericPropertyHwAddress)
}
func (d *deviceGeneric) GetTypeDescription() string {
func (d *deviceGeneric) GetPropertyTypeDescription() (string, error) {
return d.getStringProperty(DeviceGenericPropertyTypeDescription)
}
func (d *deviceGeneric) MarshalJSON() ([]byte, error) {
m := d.device.marshalMap()
m["HwAddress"] = d.GetHwAddress()
m["TypeDescription"] = d.GetTypeDescription()
m["HwAddress"], _ = d.GetPropertyHwAddress()
m["TypeDescription"], _ = d.GetPropertyTypeDescription()
return json.Marshal(m)
}

View file

@ -2,14 +2,15 @@ package gonetworkmanager
import (
"encoding/json"
"github.com/godbus/dbus"
)
const (
DeviceIpTunnelInterface = DeviceInterface + ".IPTunnel"
// Properties
DeviceIpTunnelPropertyHwAddress = DeviceIpTunnelInterface + "HwAddress" // readable s
DeviceIpTunnelPropertyMode = DeviceIpTunnelInterface + ".Mode" // readable u
DeviceIpTunnelPropertyParent = DeviceIpTunnelInterface + ".Parent" // readable o
DeviceIpTunnelPropertyLocal = DeviceIpTunnelInterface + ".Local" // readable s
@ -29,40 +30,40 @@ type DeviceIpTunnel interface {
Device
// The tunneling mode
GetMode() uint32
GetPropertyMode() (uint32, error)
// The object path of the parent device.
GetParent() Device
GetPropertyParent() (Device, error)
// The local endpoint of the tunnel.
GetLocal() string
GetPropertyLocal() (string, error)
// The remote endpoint of the tunnel.
GetRemote() string
GetPropertyRemote() (string, error)
// The TTL assigned to tunneled packets. 0 is a special value meaning that packets inherit the TTL value
GetTtl() uint8
GetPropertyTtl() (uint8, error)
// The type of service (IPv4) or traffic class (IPv6) assigned to tunneled packets.
GetTos() uint8
GetPropertyTos() (uint8, error)
// Whether path MTU discovery is enabled on this tunnel.
GetPathMtuDiscovery() bool
GetPropertyPathMtuDiscovery() (bool, error)
// The key used for incoming packets.
GetInputKey() string
GetPropertyInputKey() (string, error)
// The key used for outgoing packets.
GetOutputKey() string
GetPropertyOutputKey() (string, error)
// How many additional levels of encapsulation are permitted to be prepended to packets. This property applies only to IPv6 tunnels.
GetEncapsulationLimit() uint8
GetPropertyEncapsulationLimit() (uint8, error)
// The flow label to assign to tunnel packets. This property applies only to IPv6 tunnels.
GetFlowLabel() uint32
GetPropertyFlowLabel() (uint32, error)
// Tunnel flags.
GetFlags() uint32
GetPropertyFlags() (uint32, error)
}
func NewDeviceIpTunnel(objectPath dbus.ObjectPath) (DeviceIpTunnel, error) {
@ -74,76 +75,72 @@ type deviceIpTunnel struct {
device
}
func (d *deviceIpTunnel) GetMode() uint32 {
func (d *deviceIpTunnel) GetPropertyMode() (uint32, error) {
return d.getUint32Property(DeviceIpTunnelPropertyMode)
}
func (d *deviceIpTunnel) GetParent() Device {
path := d.getObjectProperty(DeviceIpTunnelPropertyParent)
if path == "/" {
return nil
func (d *deviceIpTunnel) GetPropertyParent() (Device, error) {
path, err := d.getObjectProperty(DeviceIpTunnelPropertyParent)
if err != nil || path == "/" {
return nil, err
}
r, err := DeviceFactory(path)
if err != nil {
panic(err)
}
return r
return DeviceFactory(path)
}
func (d *deviceIpTunnel) GetLocal() string {
func (d *deviceIpTunnel) GetPropertyLocal() (string, error) {
return d.getStringProperty(DeviceIpTunnelPropertyLocal)
}
func (d *deviceIpTunnel) GetRemote() string {
func (d *deviceIpTunnel) GetPropertyRemote() (string, error) {
return d.getStringProperty(DeviceIpTunnelPropertyRemote)
}
func (d *deviceIpTunnel) GetTtl() uint8 {
func (d *deviceIpTunnel) GetPropertyTtl() (uint8, error) {
return d.getUint8Property(DeviceIpTunnelPropertyTtl)
}
func (d *deviceIpTunnel) GetTos() uint8 {
func (d *deviceIpTunnel) GetPropertyTos() (uint8, error) {
return d.getUint8Property(DeviceIpTunnelPropertyTos)
}
func (d *deviceIpTunnel) GetPathMtuDiscovery() bool {
func (d *deviceIpTunnel) GetPropertyPathMtuDiscovery() (bool, error) {
return d.getBoolProperty(DeviceIpTunnelPropertyPathMtuDiscovery)
}
func (d *deviceIpTunnel) GetInputKey() string {
func (d *deviceIpTunnel) GetPropertyInputKey() (string, error) {
return d.getStringProperty(DeviceIpTunnelPropertyInputKey)
}
func (d *deviceIpTunnel) GetOutputKey() string {
func (d *deviceIpTunnel) GetPropertyOutputKey() (string, error) {
return d.getStringProperty(DeviceIpTunnelPropertyOutputKey)
}
func (d *deviceIpTunnel) GetEncapsulationLimit() uint8 {
func (d *deviceIpTunnel) GetPropertyEncapsulationLimit() (uint8, error) {
return d.getUint8Property(DeviceIpTunnelPropertyEncapsulationLimit)
}
func (d *deviceIpTunnel) GetFlowLabel() uint32 {
func (d *deviceIpTunnel) GetPropertyFlowLabel() (uint32, error) {
return d.getUint32Property(DeviceIpTunnelPropertyFlowLabel)
}
func (d *deviceIpTunnel) GetFlags() uint32 {
func (d *deviceIpTunnel) GetPropertyFlags() (uint32, error) {
return d.getUint32Property(DeviceIpTunnelPropertyFlags)
}
func (d *deviceIpTunnel) MarshalJSON() ([]uint8, error) {
m := d.device.marshalMap()
m["Mode"] = d.GetMode()
m["Parent"] = d.GetParent()
m["Local"] = d.GetLocal()
m["Remote"] = d.GetRemote()
m["Ttl"] = d.GetTtl()
m["Tos"] = d.GetTos()
m["PathMtuDiscovery"] = d.GetPathMtuDiscovery()
m["InputKey"] = d.GetInputKey()
m["OutputKey"] = d.GetOutputKey()
m["EncapsulationLimit"] = d.GetEncapsulationLimit()
m["FlowLabel"] = d.GetFlowLabel()
m["Flags"] = d.GetFlags()
m["Mode"], _ = d.GetPropertyMode()
m["Parent"], _ = d.GetPropertyParent()
m["Local"], _ = d.GetPropertyLocal()
m["Remote"], _ = d.GetPropertyRemote()
m["Ttl"], _ = d.GetPropertyTtl()
m["Tos"], _ = d.GetPropertyTos()
m["PathMtuDiscovery"], _ = d.GetPropertyPathMtuDiscovery()
m["InputKey"], _ = d.GetPropertyInputKey()
m["OutputKey"], _ = d.GetPropertyOutputKey()
m["EncapsulationLimit"], _ = d.GetPropertyEncapsulationLimit()
m["FlowLabel"], _ = d.GetPropertyFlowLabel()
m["Flags"], _ = d.GetPropertyFlags()
return json.Marshal(m)
}

View file

@ -9,6 +9,7 @@ import (
const (
DeviceStatisticsInterface = DeviceInterface + ".Statistics"
// Properties
DeviceStatisticsPropertyRefreshRateMs = DeviceStatisticsInterface + ".RefreshRateMs" // readwrite u
DeviceStatisticsPropertyTxBytes = DeviceStatisticsInterface + ".TxBytes" // readable t
DeviceStatisticsPropertyRxBytes = DeviceStatisticsInterface + ".RxBytes" // readable t
@ -18,13 +19,13 @@ type DeviceStatistics interface {
GetPath() dbus.ObjectPath
// Refresh rate of the rest of properties of this interface. The properties are guaranteed to be refreshed each RefreshRateMs milliseconds in case the underlying counter has changed too. If zero, there is no guaranteed refresh rate of the properties.
GetPropertyRefreshRateMs() uint32
GetPropertyRefreshRateMs() (uint32, error)
// Number of transmitted bytes
GetPropertyTxBytes() uint64
GetPropertyTxBytes() (uint64, error)
// Number of received bytes
GetPropertyRxBytes() uint64
GetPropertyRxBytes() (uint64, error)
}
func NewDeviceStatistics(objectPath dbus.ObjectPath) (DeviceStatistics, error) {
@ -40,26 +41,28 @@ func (d *deviceStatistics) GetPath() dbus.ObjectPath {
return d.obj.Path()
}
func (d *deviceStatistics) GetPropertyRefreshRateMs() uint32 {
func (d *deviceStatistics) GetPropertyRefreshRateMs() (uint32, error) {
return d.getUint32Property(DeviceStatisticsPropertyRefreshRateMs)
}
func (d *deviceStatistics) GetPropertyTxBytes() uint64 {
func (d *deviceStatistics) GetPropertyTxBytes() (uint64, error) {
return d.getUint64Property(DeviceStatisticsPropertyTxBytes)
}
func (d *deviceStatistics) GetPropertyRxBytes() uint64 {
func (d *deviceStatistics) GetPropertyRxBytes() (uint64, error) {
return d.getUint64Property(DeviceStatisticsPropertyRxBytes)
}
func (d *deviceStatistics) marshalMap() map[string]interface{} {
return map[string]interface{}{
"RefreshRateMs": d.GetPropertyRefreshRateMs(),
"TxBytes": d.GetPropertyTxBytes(),
"RxBytes": d.GetPropertyRxBytes(),
}
return map[string]interface{}{}
}
func (d *deviceStatistics) MarshalJSON() ([]byte, error) {
return json.Marshal(d.marshalMap())
m := make(map[string]interface{})
m["RefreshRateMs"], _ = d.GetPropertyRefreshRateMs()
m["TxBytes"], _ = d.GetPropertyTxBytes()
m["RxBytes"], _ = d.GetPropertyRxBytes()
return json.Marshal(m)
}

View file

@ -9,6 +9,7 @@ import (
const (
DeviceWiredInterface = DeviceInterface + ".Wired"
// Properties
DeviceWiredPropertyHwAddress = DeviceWiredInterface + ".HwAddress" // readable s
DeviceWiredPropertyPermHwAddress = DeviceWiredInterface + ".PermHwAddress" // readable s
DeviceWiredPropertySpeed = DeviceWiredInterface + ".Speed" // readable u
@ -20,19 +21,19 @@ type DeviceWired interface {
Device
// Active hardware address of the device.
GetHwAddress() string
GetPropertyHwAddress() (string, error)
// Permanent hardware address of the device.
GetPermHwAddress() string
GetPropertyPermHwAddress() (string, error)
// Design speed of the device, in megabits/second (Mb/s).
GetSpeed() uint32
GetPropertySpeed() (uint32, error)
// Array of S/390 subchannels for S/390 or z/Architecture devices.
GetS390Subchannels() []string
GetPropertyS390Subchannels() ([]string, error)
// Indicates whether the physical carrier is found (e.g. whether a cable is plugged in or not).
GetCarrier() bool
GetPropertyCarrier() (bool, error)
}
func NewDeviceWired(objectPath dbus.ObjectPath) (DeviceWired, error) {
@ -44,32 +45,32 @@ type deviceWired struct {
device
}
func (d *deviceWired) GetHwAddress() string {
func (d *deviceWired) GetPropertyHwAddress() (string, error) {
return d.getStringProperty(DeviceWiredPropertyHwAddress)
}
func (d *deviceWired) GetPermHwAddress() string {
func (d *deviceWired) GetPropertyPermHwAddress() (string, error) {
return d.getStringProperty(DeviceWiredPropertyPermHwAddress)
}
func (d *deviceWired) GetSpeed() uint32 {
func (d *deviceWired) GetPropertySpeed() (uint32, error) {
return d.getUint32Property(DeviceWiredPropertySpeed)
}
func (d *deviceWired) GetS390Subchannels() []string {
func (d *deviceWired) GetPropertyS390Subchannels() ([]string, error) {
return d.getSliceStringProperty(DeviceWiredPropertyS390Subchannels)
}
func (d *deviceWired) GetCarrier() bool {
func (d *deviceWired) GetPropertyCarrier() (bool, error) {
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()
m["HwAddress"], _ = d.GetPropertyHwAddress()
m["PermHwAddress"], _ = d.GetPropertyPermHwAddress()
m["Speed"], _ = d.GetPropertySpeed()
m["S390Subchannels"], _ = d.GetPropertyS390Subchannels()
m["Carrier"], _ = d.GetPropertyCarrier()
return json.Marshal(m)
}

View file

@ -9,6 +9,7 @@ import (
const (
DeviceWirelessInterface = DeviceInterface + ".Wireless"
// Methods
DeviceWirelessGetAccessPoints = DeviceWirelessInterface + ".GetAccessPoints"
DeviceWirelessRequestScan = DeviceWirelessInterface + ".RequestScan"
)
@ -20,7 +21,7 @@ type DeviceWireless interface {
// Note that this list does not include access points which hide their SSID.
// To retrieve a list of all access points (including hidden ones) use the
// GetAllAccessPoints() method.
GetAccessPoints() []AccessPoint
GetAccessPoints() ([]AccessPoint, error)
RequestScan()
}
@ -34,21 +35,24 @@ type deviceWireless struct {
device
}
func (d *deviceWireless) GetAccessPoints() []AccessPoint {
func (d *deviceWireless) GetAccessPoints() ([]AccessPoint, error) {
var apPaths []dbus.ObjectPath
err := d.callWithReturn(&apPaths, DeviceWirelessGetAccessPoints)
if err != nil {
return nil, err
}
d.callWithReturnAndPanic(&apPaths, DeviceWirelessGetAccessPoints)
aps := make([]AccessPoint, len(apPaths))
var err error
for i, path := range apPaths {
aps[i], err = NewAccessPoint(path)
if err != nil {
panic(err)
return aps, err
}
}
return aps
return aps, nil
}
func (d *deviceWireless) RequestScan() {
@ -58,6 +62,6 @@ func (d *deviceWireless) RequestScan() {
func (d *deviceWireless) MarshalJSON() ([]byte, error) {
m := d.device.marshalMap()
m["AccessPoints"] = d.GetAccessPoints()
m["AccessPoints"], _ = d.GetAccessPoints()
return json.Marshal(m)
}

View file

@ -2,6 +2,8 @@ package gonetworkmanager
import (
"encoding/json"
"errors"
"github.com/godbus/dbus"
)
@ -59,42 +61,42 @@ type IP4NameserverData struct {
type IP4Config interface {
// Array of arrays of IPv4 address/prefix/gateway. All 3 elements of each array are in network byte order. Essentially: [(addr, prefix, gateway), (addr, prefix, gateway), ...]
// Deprecated: use AddressData and Gateway
GetAddresses() []IP4Address
GetPropertyAddresses() ([]IP4Address, error)
// Array of IP address data objects. All addresses will include "address" (an IP address string), and "prefix" (a uint). Some addresses may include additional attributes.
GetAddressData() []IP4AddressData
GetPropertyAddressData() ([]IP4AddressData, error)
// The gateway in use.
GetGateway() string
GetPropertyGateway() (string, error)
// Arrays of IPv4 route/prefix/next-hop/metric. All 4 elements of each tuple are in network byte order. 'route' and 'next hop' are IPv4 addresses, while prefix and metric are simple unsigned integers. Essentially: [(route, prefix, next-hop, metric), (route, prefix, next-hop, metric), ...]
// Deprecated: use RouteData
GetRoutes() []IP4Route
GetPropertyRoutes() ([]IP4Route, error)
// Array of IP route data objects. All routes will include "dest" (an IP address string) and "prefix" (a uint). Some routes may include "next-hop" (an IP address string), "metric" (a uint), and additional attributes.
GetRouteData() []IP4RouteData
GetPropertyRouteData() ([]IP4RouteData, error)
// The nameservers in use.
// Deprecated: use NameserverData
GetNameservers() []string
GetPropertyNameservers() ([]string, error)
// The nameservers in use. Currently only the value "address" is recognized (with an IP address string).
GetNameserverData() []IP4NameserverData
GetPropertyNameserverData() ([]IP4NameserverData, error)
// A list of domains this address belongs to.
GetDomains() []string
GetPropertyDomains() ([]string, error)
// A list of dns searches.
GetSearches() []string
GetPropertySearches() ([]string, error)
// A list of DNS options that modify the behavior of the DNS resolver. See resolv.conf(5) manual page for the list of supported options.
GetDnsOptions() []string
GetPropertyDnsOptions() ([]string, error)
// The relative priority of DNS servers.
GetDnsPriority() uint32
GetPropertyDnsPriority() (uint32, error)
// The Windows Internet Name Service servers associated with the connection.
GetWinsServerData() []string
GetPropertyWinsServerData() ([]string, error)
MarshalJSON() ([]byte, error)
}
@ -108,11 +110,15 @@ type ip4Config struct {
dbusBase
}
// Deprecated: use GetAddressData
func (c *ip4Config) GetAddresses() []IP4Address {
addresses := c.getSliceSliceUint32Property(IP4ConfigPropertyAddresses)
// Deprecated: use GetPropertyAddressData
func (c *ip4Config) GetPropertyAddresses() ([]IP4Address, error) {
addresses, err := c.getSliceSliceUint32Property(IP4ConfigPropertyAddresses)
ret := make([]IP4Address, len(addresses))
if err != nil {
return ret, err
}
for i, parts := range addresses {
ret[i] = IP4Address{
Address: ip4ToString(parts[0]),
@ -121,33 +127,50 @@ func (c *ip4Config) GetAddresses() []IP4Address {
}
}
return ret
return ret, nil
}
func (c *ip4Config) GetAddressData() []IP4AddressData {
addresses := c.getSliceMapStringVariantProperty(IP4ConfigPropertyAddressData)
func (c *ip4Config) GetPropertyAddressData() ([]IP4AddressData, error) {
addresses, err := c.getSliceMapStringVariantProperty(IP4ConfigPropertyAddressData)
ret := make([]IP4AddressData, len(addresses))
if err != nil {
return ret, err
}
for i, address := range addresses {
prefix := address["prefix"].Value().(uint32)
prefix, ok := address["prefix"].Value().(uint32)
if !ok {
return ret, errors.New("unexpected variant type for address prefix")
}
address, ok := address["address"].Value().(string)
if !ok {
return ret, errors.New("unexpected variant type for address")
}
ret[i] = IP4AddressData{
Address: address["address"].Value().(string),
Address: address,
Prefix: uint8(prefix),
}
}
return ret
return ret, nil
}
func (c *ip4Config) GetGateway() string {
func (c *ip4Config) GetPropertyGateway() (string, error) {
return c.getStringProperty(IP4ConfigPropertyGateway)
}
// Deprecated: use GetRouteData
func (c *ip4Config) GetRoutes() []IP4Route {
routes := c.getSliceSliceUint32Property(IP4ConfigPropertyRoutes)
// Deprecated: use GetPropertyRouteData
func (c *ip4Config) GetPropertyRoutes() ([]IP4Route, error) {
routes, err := c.getSliceSliceUint32Property(IP4ConfigPropertyRoutes)
ret := make([]IP4Route, len(routes))
if err != nil {
return ret, err
}
for i, parts := range routes {
ret[i] = IP4Route{
Route: ip4ToString(parts[0]),
@ -157,13 +180,17 @@ func (c *ip4Config) GetRoutes() []IP4Route {
}
}
return ret
return ret, nil
}
func (c *ip4Config) GetRouteData() []IP4RouteData {
routesData := c.getSliceMapStringVariantProperty(IP4ConfigPropertyRouteData)
func (c *ip4Config) GetPropertyRouteData() ([]IP4RouteData, error) {
routesData, err := c.getSliceMapStringVariantProperty(IP4ConfigPropertyRouteData)
routes := make([]IP4RouteData, len(routesData))
if err != nil {
return routes, err
}
for _, routeData := range routesData {
route := IP4RouteData{}
@ -171,14 +198,28 @@ func (c *ip4Config) GetRouteData() []IP4RouteData {
for routeDataAttributeName, routeDataAttribute := range routeData {
switch routeDataAttributeName {
case "dest":
route.Destination = routeDataAttribute.Value().(string)
destination, ok := routeDataAttribute.Value().(string)
if !ok {
return routes, errors.New("unexpected variant type for dest")
}
route.Destination = destination
case "prefix":
prefix, _ := routeDataAttribute.Value().(uint32)
prefix, ok := routeDataAttribute.Value().(uint32)
if !ok {
return routes, errors.New("unexpected variant type for prefix")
}
route.Prefix = uint8(prefix)
case "next-hop":
route.NextHop = routeDataAttribute.Value().(string)
nextHop, ok := routeDataAttribute.Value().(string)
if !ok {
return routes, errors.New("unexpected variant type for next-hop")
}
route.NextHop = nextHop
case "metric":
metric := routeDataAttribute.Value().(uint32)
metric, ok := routeDataAttribute.Value().(uint32)
if !ok {
return routes, errors.New("unexpected variant type for metric")
}
route.Metric = uint8(metric)
default:
route.AdditionalAttributes[routeDataAttributeName] = routeDataAttribute.String()
@ -187,61 +228,76 @@ func (c *ip4Config) GetRouteData() []IP4RouteData {
routes = append(routes, route)
}
return routes
return routes, nil
}
// Deprecated: use GetNameserverData
func (c *ip4Config) GetNameservers() []string {
nameservers := c.getSliceUint32Property(IP4ConfigPropertyNameservers)
// Deprecated: use GetPropertyNameserverData
func (c *ip4Config) GetPropertyNameservers() ([]string, error) {
nameservers, err := c.getSliceUint32Property(IP4ConfigPropertyNameservers)
ret := make([]string, len(nameservers))
if err != nil {
return ret, err
}
for i, ns := range nameservers {
ret[i] = ip4ToString(ns)
}
return ret
return ret, nil
}
func (c *ip4Config) GetNameserverData() []IP4NameserverData {
nameserversData := c.getSliceMapStringVariantProperty(IP4ConfigPropertyNameserverData)
func (c *ip4Config) GetPropertyNameserverData() ([]IP4NameserverData, error) {
nameserversData, err := c.getSliceMapStringVariantProperty(IP4ConfigPropertyNameserverData)
nameservers := make([]IP4NameserverData, len(nameserversData))
if err != nil {
return nameservers, err
}
for _, nameserverData := range nameserversData {
address, ok := nameserverData["address"].Value().(string)
if !ok {
return nameservers, errors.New("unexpected variant type for address")
}
nameserver := IP4NameserverData{
Address: nameserverData["address"].Value().(string),
Address: address,
}
nameservers = append(nameservers, nameserver)
}
return nameservers
return nameservers, nil
}
func (c *ip4Config) GetDomains() []string {
func (c *ip4Config) GetPropertyDomains() ([]string, error) {
return c.getSliceStringProperty(IP4ConfigPropertyDomains)
}
func (c *ip4Config) GetSearches() []string {
func (c *ip4Config) GetPropertySearches() ([]string, error) {
return c.getSliceStringProperty(IP4ConfigPropertySearches)
}
func (c *ip4Config) GetDnsOptions() []string {
func (c *ip4Config) GetPropertyDnsOptions() ([]string, error) {
return c.getSliceStringProperty(IP4ConfigPropertyDnsOptions)
}
func (c *ip4Config) GetDnsPriority() uint32 {
func (c *ip4Config) GetPropertyDnsPriority() (uint32, error) {
return c.getUint32Property(IP4ConfigPropertyDnsPriority)
}
func (c *ip4Config) GetWinsServerData() []string {
func (c *ip4Config) GetPropertyWinsServerData() ([]string, error) {
return c.getSliceStringProperty(IP4ConfigPropertyWinsServerData)
}
func (c *ip4Config) MarshalJSON() ([]byte, error) {
return json.Marshal(map[string]interface{}{
"Addresses": c.GetAddressData(),
"Routes": c.GetRouteData(),
"Nameservers": c.GetNameserverData(),
"Domains": c.GetDomains(),
})
m := make(map[string]interface{})
m["Addresses"], _ = c.GetPropertyAddressData()
m["Routes"], _ = c.GetPropertyRouteData()
m["Nameservers"], _ = c.GetPropertyNameserverData()
m["Domains"], _ = c.GetPropertyDomains()
return json.Marshal(m)
}

View file

@ -2,6 +2,8 @@ package gonetworkmanager
import (
"encoding/json"
"errors"
"github.com/godbus/dbus"
)
@ -52,28 +54,28 @@ type IP6RouteData struct {
type IP6Config interface {
// Array of IP address data objects. All addresses will include "address" (an IP address string), and "prefix" (a uint). Some addresses may include additional attributes.
GetAddressData() []IP6AddressData
GetPropertyAddressData() ([]IP6AddressData, error)
// The gateway in use.
GetGateway() string
GetPropertyGateway() (string, error)
// Array of IP route data objects. All routes will include "dest" (an IP address string) and "prefix" (a uint). Some routes may include "next-hop" (an IP address string), "metric" (a uint), and additional attributes.
GetRouteData() []IP6RouteData
GetPropertyRouteData() ([]IP6RouteData, error)
// GetNameservers gets the nameservers in use.
GetNameservers() []string
GetPropertyNameservers() ([]string, error)
// A list of domains this address belongs to.
GetDomains() []string
GetPropertyDomains() ([]string, error)
// A list of dns searches.
GetSearches() []string
GetPropertySearches() ([]string, error)
// A list of DNS options that modify the behavior of the DNS resolver. See resolv.conf(5) manual page for the list of supported options.
GetDnsOptions() []string
GetPropertyDnsOptions() ([]string, error)
// The relative priority of DNS servers.
GetDnsPriority() uint32
GetPropertyDnsPriority() (uint32, error)
MarshalJSON() ([]byte, error)
}
@ -87,30 +89,46 @@ type ip6Config struct {
dbusBase
}
func (c *ip6Config) GetAddressData() []IP6AddressData {
addresses := c.getSliceMapStringVariantProperty(IP6ConfigPropertyAddressData)
func (c *ip6Config) GetPropertyAddressData() ([]IP6AddressData, error) {
addresses, err := c.getSliceMapStringVariantProperty(IP6ConfigPropertyAddressData)
ret := make([]IP6AddressData, len(addresses))
if err != nil {
return ret, err
}
for i, address := range addresses {
prefix := address["prefix"].Value().(uint32)
prefix, ok := address["prefix"].Value().(uint32)
if !ok {
return ret, errors.New("unexpected variant type for prefix")
}
address, ok := address["address"].Value().(string)
if !ok {
return ret, errors.New("unexpected variant type for address")
}
ret[i] = IP6AddressData{
Address: address["address"].Value().(string),
Address: address,
Prefix: uint8(prefix),
}
}
return ret
return ret, nil
}
func (c *ip6Config) GetGateway() string {
func (c *ip6Config) GetPropertyGateway() (string, error) {
return c.getStringProperty(IP6ConfigPropertyGateway)
}
func (c *ip6Config) GetRouteData() []IP6RouteData {
routesData := c.getSliceMapStringVariantProperty(IP6ConfigPropertyRouteData)
func (c *ip6Config) GetPropertyRouteData() ([]IP6RouteData, error) {
routesData, err := c.getSliceMapStringVariantProperty(IP6ConfigPropertyRouteData)
routes := make([]IP6RouteData, len(routesData))
if err != nil {
return routes, err
}
for _, routeData := range routesData {
route := IP6RouteData{}
@ -118,14 +136,28 @@ func (c *ip6Config) GetRouteData() []IP6RouteData {
for routeDataAttributeName, routeDataAttribute := range routeData {
switch routeDataAttributeName {
case "dest":
route.Destination = routeDataAttribute.Value().(string)
destination, ok := routeDataAttribute.Value().(string)
if !ok {
return routes, errors.New("unexpected variant type for dest")
}
route.Destination = destination
case "prefix":
prefix, _ := routeDataAttribute.Value().(uint32)
prefix, ok := routeDataAttribute.Value().(uint32)
if !ok {
return routes, errors.New("unexpected variant type for prefix")
}
route.Prefix = uint8(prefix)
case "next-hop":
route.NextHop = routeDataAttribute.Value().(string)
nextHop, ok := routeDataAttribute.Value().(string)
if !ok {
return routes, errors.New("unexpected variant type for next-hop")
}
route.NextHop = nextHop
case "metric":
metric := routeDataAttribute.Value().(uint32)
metric, ok := routeDataAttribute.Value().(uint32)
if !ok {
return routes, errors.New("unexpected variant type for metric")
}
route.Metric = uint8(metric)
default:
route.AdditionalAttributes[routeDataAttributeName] = routeDataAttribute.String()
@ -134,41 +166,47 @@ func (c *ip6Config) GetRouteData() []IP6RouteData {
routes = append(routes, route)
}
return routes
return routes, nil
}
func (c *ip6Config) GetNameservers() []string {
nameservers := c.getSliceSliceByteProperty(IP6ConfigPropertyNameservers)
func (c *ip6Config) GetPropertyNameservers() ([]string, error) {
nameservers, err := c.getSliceSliceByteProperty(IP6ConfigPropertyNameservers)
ret := make([]string, len(nameservers))
if err != nil {
return ret, err
}
for i, nameserver := range nameservers {
ret[i] = string(nameserver)
}
return ret
return ret, nil
}
func (c *ip6Config) GetDomains() []string {
func (c *ip6Config) GetPropertyDomains() ([]string, error) {
return c.getSliceStringProperty(IP6ConfigPropertyDomains)
}
func (c *ip6Config) GetSearches() []string {
func (c *ip6Config) GetPropertySearches() ([]string, error) {
return c.getSliceStringProperty(IP6ConfigPropertySearches)
}
func (c *ip6Config) GetDnsOptions() []string {
func (c *ip6Config) GetPropertyDnsOptions() ([]string, error) {
return c.getSliceStringProperty(IP6ConfigPropertyDnsOptions)
}
func (c *ip6Config) GetDnsPriority() uint32 {
func (c *ip6Config) GetPropertyDnsPriority() (uint32, error) {
return c.getUint32Property(IP6ConfigPropertyDnsPriority)
}
func (c *ip6Config) MarshalJSON() ([]byte, error) {
return json.Marshal(map[string]interface{}{
"Addresses": c.GetAddressData(),
"Routes": c.GetRouteData(),
"Nameservers": c.GetNameservers(),
"Domains": c.GetDomains(),
})
m := make(map[string]interface{})
m["Addresses"], _ = c.GetPropertyAddressData()
m["Routes"], _ = c.GetPropertyRouteData()
m["Nameservers"], _ = c.GetPropertyNameservers()
m["Domains"], _ = c.GetPropertyDomains()
return json.Marshal(m)
}

View file

@ -2,6 +2,7 @@ package gonetworkmanager
import (
"encoding/json"
"github.com/godbus/dbus"
)
@ -132,75 +133,75 @@ type NetworkManager interface {
/* PROPERTIES */
// The list of realized network devices. Realized devices are those which have backing resources (eg from the kernel or a management daemon like ModemManager, teamd, etc).
GetPropertyDevices() []Device
GetPropertyDevices() ([]Device, error)
// The list of both realized and un-realized network devices. Un-realized devices are software devices which do not yet have backing resources, but for which backing resources can be created if the device is activated.
GetPropertyAllDevices() []Device
GetPropertyAllDevices() ([]Device, error)
// The list of active checkpoints.
GetPropertyCheckpoints() []Checkpoint
GetPropertyCheckpoints() ([]Checkpoint, error)
// Indicates if overall networking is currently enabled or not. See the Enable() method.
GetPropertyNetworkingEnabled() bool
GetPropertyNetworkingEnabled() (bool, error)
// Indicates if wireless is currently enabled or not.
GetPropertyWirelessEnabled() bool
GetPropertyWirelessEnabled() (bool, error)
// Indicates if the wireless hardware is currently enabled, i.e. the state of the RF kill switch.
GetPropertyWirelessHardwareEnabled() bool
GetPropertyWirelessHardwareEnabled() (bool, error)
// Indicates if mobile broadband devices are currently enabled or not.
GetPropertyWwanEnabled() bool
GetPropertyWwanEnabled() (bool, error)
// Indicates if the mobile broadband hardware is currently enabled, i.e. the state of the RF kill switch.
GetPropertyWwanHardwareEnabled() bool
GetPropertyWwanHardwareEnabled() (bool, error)
// Indicates if WiMAX devices are currently enabled or not.
GetPropertyWimaxEnabled() bool
GetPropertyWimaxEnabled() (bool, error)
// Indicates if the WiMAX hardware is currently enabled, i.e. the state of the RF kill switch.
GetPropertyWimaxHardwareEnabled() bool
GetPropertyWimaxHardwareEnabled() (bool, error)
// List of active connection object paths.
GetPropertyActiveConnections() []ActiveConnection
GetPropertyActiveConnections() ([]ActiveConnection, error)
// The object path of the "primary" active connection being used to access the network. In particular, if there is no VPN active, or the VPN does not have the default route, then this indicates the connection that has the default route. If there is a VPN active with the default route, then this indicates the connection that contains the route to the VPN endpoint.
GetPropertyPrimaryConnection() Connection
GetPropertyPrimaryConnection() (Connection, error)
// The connection type of the "primary" active connection being used to access the network. This is the same as the Type property on the object indicated by PrimaryConnection.
GetPropertyPrimaryConnectionType() string
GetPropertyPrimaryConnectionType() (string, error)
// Indicates whether the connectivity is metered. This is equivalent to the metered property of the device associated with the primary connection.
GetPropertyMetered() NmMetered
GetPropertyMetered() (NmMetered, error)
// The object path of an active connection that is currently being activated and which is expected to become the new PrimaryConnection when it finishes activating.
GetPropertyActivatingConnection() ActiveConnection
GetPropertyActivatingConnection() (ActiveConnection, error)
// Indicates whether NM is still starting up; this becomes FALSE when NM has finished attempting to activate every connection that it might be able to activate at startup.
GetPropertyStartup() bool
GetPropertyStartup() (bool, error)
// NetworkManager version.
GetPropertyVersion() string
GetPropertyVersion() (string, error)
// The current set of capabilities. See NMCapability for currently defined capability numbers. The array is guaranteed to be sorted in ascending order without duplicates.
GetPropertyCapabilities() []NmCapability
GetPropertyCapabilities() ([]NmCapability, error)
// The overall state of the NetworkManager daemon.
// This takes state of all active connections and the connectivity state into account to produce a single indicator of the network accessibility status.
// The graphical shells may use this property to provide network connection status indication and applications may use this to check if Internet connection is accessible. Shell that is able to cope with captive portals should use the "Connectivity" property to decide whether to present a captive portal authentication dialog.
GetPropertyState() NmState
GetPropertyState() (NmState, error)
// The result of the last connectivity check. The connectivity check is triggered automatically when a default connection becomes available, periodically and by calling a CheckConnectivity() method.
// This property is in general useful for the graphical shell to determine whether the Internet access is being hijacked by an authentication gateway (a "captive portal"). In such case it would typically present a web browser window to give the user a chance to authenticate and call CheckConnectivity() when the user submits a form or dismisses the window.
// To determine the whether the user is able to access the Internet without dealing with captive portals (e.g. to provide a network connection indicator or disable controls that require Internet access), the "State" property is more suitable.
GetPropertyConnectivity() NmConnectivity
GetPropertyConnectivity() (NmConnectivity, error)
// Indicates whether connectivity checking service has been configured. This may return true even if the service is not currently enabled.
// This is primarily intended for use in a privacy control panel, as a way to determine whether to show an option to enable/disable the feature.
GetPropertyConnectivityCheckAvailable() bool
GetPropertyConnectivityCheckAvailable() (bool, error)
// Indicates whether connectivity checking is enabled. This property can also be written to to disable connectivity checking (as a privacy control panel might want to do).
GetPropertyConnectivityCheckEnabled() bool
GetPropertyConnectivityCheckEnabled() (bool, error)
// Dictionary of global DNS settings where the key is one of "searches", "options" and "domains". The values for the "searches" and "options" keys are string arrays describing the list of search domains and resolver options, respectively. The value of the "domains" key is a second-level dictionary, where each key is a domain name, and each key's value is a third-level dictionary with the keys "servers" and "options". "servers" is a string array of DNS servers, "options" is a string array of domain-specific options.
//GetPropertyGlobalDnsConfiguration() []interface{}
@ -228,14 +229,17 @@ func (nm *networkManager) Reload(flags uint32) error {
func (nm *networkManager) GetDevices() (devices []Device, err error) {
var devicePaths []dbus.ObjectPath
err = nm.callWithReturn(&devicePaths, NetworkManagerGetDevices)
if err != nil {
return
}
nm.callWithReturnAndPanic(&devicePaths, NetworkManagerGetDevices)
devices = make([]Device, len(devicePaths))
for i, path := range devicePaths {
devices[i], err = DeviceFactory(path)
if err != nil {
panic(err)
return
}
}
@ -245,13 +249,17 @@ func (nm *networkManager) GetDevices() (devices []Device, err error) {
func (nm *networkManager) GetAllDevices() (devices []Device, err error) {
var devicePaths []dbus.ObjectPath
nm.callWithReturnAndPanic(&devicePaths, NetworkManagerGetAllDevices)
err = nm.callWithReturn(&devicePaths, NetworkManagerGetAllDevices)
if err != nil {
return
}
devices = make([]Device, len(devicePaths))
for i, path := range devicePaths {
devices[i], err = DeviceFactory(path)
if err != nil {
panic(err)
return
}
}
@ -276,11 +284,14 @@ func (nm *networkManager) GetDeviceByIpIface(interfaceId string) (device Device,
func (nm *networkManager) ActivateConnection(c Connection, d Device) (ac ActiveConnection, err error) {
var opath dbus.ObjectPath
nm.callWithReturnAndPanic(&opath, NetworkManagerActivateConnection, c.GetPath(), d.GetPath(), dbus.ObjectPath("/"))
err = nm.callWithReturn(&opath, NetworkManagerActivateConnection, c.GetPath(), d.GetPath(), dbus.ObjectPath("/"))
if err != nil {
return
}
ac, err = NewActiveConnection(opath)
if err != nil {
panic(err)
return
}
return
@ -379,142 +390,152 @@ func (nm *networkManager) CheckpointAdjustRollbackTimeout(checkpoint Checkpoint,
/* PROPERTIES */
func (nm *networkManager) GetPropertyDevices() []Device {
devicesPaths := nm.getSliceObjectProperty(NetworkManagerPropertyDevices)
devices := make([]Device, len(devicesPaths))
func (nm *networkManager) GetPropertyDevices() ([]Device, error) {
devicesPaths, err := nm.getSliceObjectProperty(NetworkManagerPropertyDevices)
if err != nil {
return nil, err
}
var err error
devices := make([]Device, len(devicesPaths))
for i, path := range devicesPaths {
devices[i], err = NewDevice(path)
if err != nil {
panic(err)
return devices, err
}
}
return devices
return devices, nil
}
func (nm *networkManager) GetPropertyAllDevices() ([]Device, error) {
devicesPaths, err := nm.getSliceObjectProperty(NetworkManagerPropertyAllDevices)
if err != nil {
return nil, err
}
func (nm *networkManager) GetPropertyAllDevices() []Device {
devicesPaths := nm.getSliceObjectProperty(NetworkManagerPropertyAllDevices)
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, err
}
}
return devices
return devices, nil
}
func (nm *networkManager) GetPropertyCheckpoints() ([]Checkpoint, error) {
checkpointsPaths, err := nm.getSliceObjectProperty(NetworkManagerPropertyAllDevices)
if err != nil {
return nil, err
}
func (nm *networkManager) GetPropertyCheckpoints() []Checkpoint {
checkpointsPaths := nm.getSliceObjectProperty(NetworkManagerPropertyAllDevices)
checkpoints := make([]Checkpoint, len(checkpointsPaths))
var err error
for i, path := range checkpointsPaths {
checkpoints[i], err = NewCheckpoint(path)
if err != nil {
panic(err)
return checkpoints, err
}
}
return checkpoints
return checkpoints, nil
}
func (nm *networkManager) GetPropertyNetworkingEnabled() bool {
func (nm *networkManager) GetPropertyNetworkingEnabled() (bool, error) {
return nm.getBoolProperty(NetworkManagerPropertyNetworkingEnabled)
}
func (nm *networkManager) GetPropertyWirelessEnabled() bool {
func (nm *networkManager) GetPropertyWirelessEnabled() (bool, error) {
return nm.getBoolProperty(NetworkManagerPropertyWirelessEnabled)
}
func (nm *networkManager) GetPropertyWirelessHardwareEnabled() bool {
func (nm *networkManager) GetPropertyWirelessHardwareEnabled() (bool, error) {
return nm.getBoolProperty(NetworkManagerPropertyWirelessHardwareEnabled)
}
func (nm *networkManager) GetPropertyWwanEnabled() bool {
func (nm *networkManager) GetPropertyWwanEnabled() (bool, error) {
return nm.getBoolProperty(NetworkManagerPropertyWwanEnabled)
}
func (nm *networkManager) GetPropertyWwanHardwareEnabled() bool {
func (nm *networkManager) GetPropertyWwanHardwareEnabled() (bool, error) {
return nm.getBoolProperty(NetworkManagerPropertyWwanHardwareEnabled)
}
func (nm *networkManager) GetPropertyWimaxEnabled() bool {
func (nm *networkManager) GetPropertyWimaxEnabled() (bool, error) {
return nm.getBoolProperty(NetworkManagerPropertyWimaxEnabled)
}
func (nm *networkManager) GetPropertyWimaxHardwareEnabled() bool {
func (nm *networkManager) GetPropertyWimaxHardwareEnabled() (bool, error) {
return nm.getBoolProperty(NetworkManagerPropertyWimaxHardwareEnabled)
}
func (nm *networkManager) GetPropertyActiveConnections() []ActiveConnection {
acPaths := nm.getSliceObjectProperty(NetworkManagerPropertyActiveConnections)
ac := make([]ActiveConnection, len(acPaths))
func (nm *networkManager) GetPropertyActiveConnections() ([]ActiveConnection, error) {
acPaths, err := nm.getSliceObjectProperty(NetworkManagerPropertyActiveConnections)
if err != nil {
return nil, err
}
var err error
ac := make([]ActiveConnection, len(acPaths))
for i, path := range acPaths {
ac[i], err = NewActiveConnection(path)
if err != nil {
panic(err)
return ac, err
}
}
return ac
return ac, nil
}
func (nm *networkManager) GetPropertyPrimaryConnection() Connection {
connectionPath := nm.getObjectProperty(NetworkManagerPropertyPrimaryConnection)
func (nm *networkManager) GetPropertyPrimaryConnection() (Connection, error) {
connectionPath, err := nm.getObjectProperty(NetworkManagerPropertyPrimaryConnection)
connection, err := NewConnection(connectionPath)
if err != nil {
panic(err)
return nil, err
}
return connection
return NewConnection(connectionPath)
}
func (nm *networkManager) GetPropertyPrimaryConnectionType() string {
func (nm *networkManager) GetPropertyPrimaryConnectionType() (string, error) {
return nm.getStringProperty(NetworkManagerPropertyPrimaryConnectionType)
}
func (nm *networkManager) GetPropertyMetered() NmMetered {
return NmMetered(nm.getUint32Property(NetworkManagerPropertyMetered))
func (nm *networkManager) GetPropertyMetered() (NmMetered, error) {
v, err := nm.getUint32Property(NetworkManagerPropertyMetered)
return NmMetered(v), err
}
func (nm *networkManager) GetPropertyActivatingConnection() ActiveConnection {
func (nm *networkManager) GetPropertyActivatingConnection() (ActiveConnection, error) {
panic("implement me")
}
func (nm *networkManager) GetPropertyStartup() bool {
func (nm *networkManager) GetPropertyStartup() (bool, error) {
return nm.getBoolProperty(NetworkManagerPropertyStartup)
}
func (nm *networkManager) GetPropertyVersion() string {
func (nm *networkManager) GetPropertyVersion() (string, error) {
return nm.getStringProperty(NetworkManagerPropertyVersion)
}
func (nm *networkManager) GetPropertyCapabilities() []NmCapability {
func (nm *networkManager) GetPropertyCapabilities() ([]NmCapability, error) {
panic("implement me")
}
func (nm *networkManager) GetPropertyState() NmState {
return NmState(nm.getUint32Property(NetworkManagerPropertyState))
func (nm *networkManager) GetPropertyState() (NmState, error) {
v, err := nm.getUint32Property(NetworkManagerPropertyState)
return NmState(v), err
}
func (nm *networkManager) GetPropertyConnectivity() NmConnectivity {
return NmConnectivity(nm.getUint32Property(NetworkManagerPropertyConnectivity))
func (nm *networkManager) GetPropertyConnectivity() (NmConnectivity, error) {
v, err := nm.getUint32Property(NetworkManagerPropertyConnectivity)
return NmConnectivity(v), err
}
func (nm *networkManager) GetPropertyConnectivityCheckAvailable() bool {
func (nm *networkManager) GetPropertyConnectivityCheckAvailable() (bool, error) {
return nm.getBoolProperty(NetworkManagerPropertyConnectivityCheckAvailable)
}
func (nm *networkManager) GetPropertyConnectivityCheckEnabled() bool {
func (nm *networkManager) GetPropertyConnectivityCheckEnabled() (bool, error) {
return nm.getBoolProperty(NetworkManagerPropertyConnectivityCheckEnabled)
}
@ -536,28 +557,30 @@ func (nm *networkManager) Unsubscribe() {
}
func (nm *networkManager) MarshalJSON() ([]byte, error) {
return json.Marshal(map[string]interface{}{
"Devices": nm.GetPropertyDevices(),
"AllDevices": nm.GetPropertyAllDevices(),
"Checkpoints": nm.GetPropertyCheckpoints(),
"NetworkingEnabled": nm.GetPropertyNetworkingEnabled(),
"WirelessEnabled": nm.GetPropertyWirelessEnabled(),
"WirelessHardwareEnabled": nm.GetPropertyWirelessHardwareEnabled(),
"WwanEnabled": nm.GetPropertyWwanEnabled(),
"WwanHardwareEnabled": nm.GetPropertyWwanHardwareEnabled(),
"WimaxEnabled": nm.GetPropertyWimaxEnabled(),
"WimaxHardwareEnabled": nm.GetPropertyWimaxHardwareEnabled(),
"ActiveConnections": nm.GetPropertyActiveConnections(),
"PrimaryConnection": nm.GetPropertyPrimaryConnection(),
"PrimaryConnectionType": nm.GetPropertyPrimaryConnectionType(),
"Metered": nm.GetPropertyMetered(),
"ActivatingConnection": nm.GetPropertyActivatingConnection(),
"Startup": nm.GetPropertyStartup(),
"Version": nm.GetPropertyVersion(),
"Capabilities": nm.GetPropertyCapabilities(),
"State": nm.GetPropertyState(),
"Connectivity": nm.GetPropertyConnectivity(),
"ConnectivityCheckAvailable": nm.GetPropertyConnectivityCheckAvailable(),
"ConnectivityCheckEnabled": nm.GetPropertyConnectivityCheckEnabled(),
})
m := make(map[string]interface{})
m["Devices"], _ = nm.GetPropertyDevices()
m["AllDevices"], _ = nm.GetPropertyAllDevices()
m["Checkpoints"], _ = nm.GetPropertyCheckpoints()
m["NetworkingEnabled"], _ = nm.GetPropertyNetworkingEnabled()
m["WirelessEnabled"], _ = nm.GetPropertyWirelessEnabled()
m["WirelessHardwareEnabled"], _ = nm.GetPropertyWirelessHardwareEnabled()
m["WwanEnabled"], _ = nm.GetPropertyWwanEnabled()
m["WwanHardwareEnabled"], _ = nm.GetPropertyWwanHardwareEnabled()
m["WimaxEnabled"], _ = nm.GetPropertyWimaxEnabled()
m["WimaxHardwareEnabled"], _ = nm.GetPropertyWimaxHardwareEnabled()
m["ActiveConnections"], _ = nm.GetPropertyActiveConnections()
m["PrimaryConnection"], _ = nm.GetPropertyPrimaryConnection()
m["PrimaryConnectionType"], _ = nm.GetPropertyPrimaryConnectionType()
m["Metered"], _ = nm.GetPropertyMetered()
m["ActivatingConnection"], _ = nm.GetPropertyActivatingConnection()
m["Startup"], _ = nm.GetPropertyStartup()
m["Version"], _ = nm.GetPropertyVersion()
m["Capabilities"], _ = nm.GetPropertyCapabilities()
m["State"], _ = nm.GetPropertyState()
m["Connectivity"], _ = nm.GetPropertyConnectivity()
m["ConnectivityCheckAvailable"], _ = nm.GetPropertyConnectivityCheckAvailable()
m["ConnectivityCheckEnabled"], _ = nm.GetPropertyConnectivityCheckEnabled()
return json.Marshal(m)
}

View file

@ -25,22 +25,22 @@ const (
type Settings interface {
// ListConnections gets list the saved network connections known to NetworkManager
ListConnections() []Connection
ListConnections() ([]Connection, error)
// AddConnection callWithReturnAndPanic new connection and save it to disk.
AddConnection(settings ConnectionSettings) Connection
// AddConnection adds new connection and save it to disk.
AddConnection(settings ConnectionSettings) (Connection, error)
// Add new connection but do not save it to disk immediately. This operation does not start the network connection unless (1) device is idle and able to connect to the network described by the new connection, and (2) the connection is allowed to be started automatically. Use the 'Save' method on the connection to save these changes to disk. Note that unsaved changes will be lost if the connection is reloaded from disk (either automatically on file change or due to an explicit ReloadConnections call).
AddConnectionUnsaved(settings ConnectionSettings) Connection
AddConnectionUnsaved(settings ConnectionSettings) (Connection, error)
// Save the hostname to persistent configuration.
SaveHostname(hostname string)
SaveHostname(hostname string) error
// If true, adding and modifying connections is supported.
CanModify() bool
GetPropertyCanModify() (bool, error)
// The machine hostname stored in persistent configuration.
Hostname() string
GetPropertyHostname() (string, error)
}
func NewSettings() (Settings, error) {
@ -52,56 +52,55 @@ type settings struct {
dbusBase
}
func (s *settings) ListConnections() []Connection {
func (s *settings) ListConnections() ([]Connection, error) {
var connectionPaths []dbus.ObjectPath
s.callWithReturnAndPanic(&connectionPaths, SettingsListConnections)
err := s.callWithReturn(&connectionPaths, SettingsListConnections)
if err != nil {
return nil, err
}
connections := make([]Connection, len(connectionPaths))
var err error
for i, path := range connectionPaths {
connections[i], err = NewConnection(path)
if err != nil {
panic(err)
return connections, err
}
}
return connections
return connections, nil
}
func (s *settings) AddConnection(settings ConnectionSettings) Connection {
func (s *settings) AddConnection(settings ConnectionSettings) (Connection, error) {
var path dbus.ObjectPath
s.callWithReturnAndPanic(&path, SettingsAddConnection, settings)
con, err := NewConnection(path)
err := s.callWithReturn(&path, SettingsAddConnection, settings)
if err != nil {
panic(err)
}
return con
return nil, err
}
func (s *settings) AddConnectionUnsaved(settings ConnectionSettings) Connection {
return NewConnection(path)
}
func (s *settings) AddConnectionUnsaved(settings ConnectionSettings) (Connection, error) {
var path dbus.ObjectPath
s.callWithReturnAndPanic(&path, SettingsAddConnectionUnsaved, settings)
con, err := NewConnection(path)
err := s.callWithReturn(&path, SettingsAddConnectionUnsaved, settings)
if err != nil {
panic(err)
}
return con
return nil, err
}
func (s *settings) SaveHostname(hostname string) {
err := s.call(SettingsSaveHostname, hostname)
if err != nil {
panic(err)
}
return NewConnection(path)
}
func (s *settings) Hostname() string {
hostname := s.getStringProperty(SettingsPropertyHostname)
return hostname
func (s *settings) SaveHostname(hostname string) error {
return s.call(SettingsSaveHostname, hostname)
}
func (s *settings) CanModify() bool {
func (s *settings) GetPropertyHostname() (string, error) {
return s.getStringProperty(SettingsPropertyHostname)
}
func (s *settings) GetPropertyCanModify() (bool, error) {
return s.getBoolProperty(SettingsPropertyCanModify)
}

239
utils.go
View file

@ -34,13 +34,6 @@ func (d *dbusBase) call(method string, args ...interface{}) error {
return d.obj.Call(method, 0, args...).Err
}
func (d *dbusBase) callWithReturnAndPanic(ret interface{}, method string, args ...interface{}) {
err := d.callWithReturn(ret, method, args...)
if err != nil {
panic(err)
}
}
func (d *dbusBase) callWithReturn(ret interface{}, method string, args ...interface{}) error {
return d.obj.Call(method, 0, args...).Store(ret)
}
@ -60,132 +53,204 @@ func (d *dbusBase) subscribeNamespace(namespace string) {
d.conn.BusObject().Call(dbusMethodAddMatch, 0, rule)
}
func (d *dbusBase) getProperty(iface string) interface{} {
func (d *dbusBase) getProperty(iface string) (interface{}, error) {
variant, err := d.obj.GetProperty(iface)
return variant.Value(), err
}
func (d *dbusBase) getObjectProperty(iface string) (value dbus.ObjectPath, err error) {
prop, err := d.getProperty(iface)
if err != nil {
panic(err)
return
}
return variant.Value()
value, ok := prop.(dbus.ObjectPath)
if !ok {
err = makeErrVariantType(iface)
return
}
return
}
func (d *dbusBase) getObjectProperty(iface string) dbus.ObjectPath {
value, ok := d.getProperty(iface).(dbus.ObjectPath)
if !ok {
panic(makeErrVariantType(iface))
func (d *dbusBase) getSliceObjectProperty(iface string) (value []dbus.ObjectPath, err error) {
prop, err := d.getProperty(iface)
if err != nil {
return
}
return value
value, ok := prop.([]dbus.ObjectPath)
if !ok {
err = makeErrVariantType(iface)
return
}
return
}
func (d *dbusBase) getSliceObjectProperty(iface string) []dbus.ObjectPath {
value, ok := d.getProperty(iface).([]dbus.ObjectPath)
if !ok {
panic(makeErrVariantType(iface))
func (d *dbusBase) getBoolProperty(iface string) (value bool, err error) {
prop, err := d.getProperty(iface)
if err != nil {
return
}
return value
value, ok := prop.(bool)
if !ok {
err = makeErrVariantType(iface)
return
}
return
}
func (d *dbusBase) getBoolProperty(iface string) bool {
value, ok := d.getProperty(iface).(bool)
if !ok {
panic(makeErrVariantType(iface))
func (d *dbusBase) getStringProperty(iface string) (value string, err error) {
prop, err := d.getProperty(iface)
if err != nil {
return
}
return value
value, ok := prop.(string)
if !ok {
err = makeErrVariantType(iface)
return
}
return
}
func (d *dbusBase) getStringProperty(iface string) string {
value, ok := d.getProperty(iface).(string)
if !ok {
panic(makeErrVariantType(iface))
func (d *dbusBase) getSliceStringProperty(iface string) (value []string, err error) {
prop, err := d.getProperty(iface)
if err != nil {
return
}
return value
value, ok := prop.([]string)
if !ok {
err = makeErrVariantType(iface)
return
}
return
}
func (d *dbusBase) getSliceStringProperty(iface string) []string {
value, ok := d.getProperty(iface).([]string)
if !ok {
panic(makeErrVariantType(iface))
func (d *dbusBase) getSliceSliceByteProperty(iface string) (value [][]byte, err error) {
prop, err := d.getProperty(iface)
if err != nil {
return
}
return value
value, ok := prop.([][]byte)
if !ok {
err = makeErrVariantType(iface)
return
}
return
}
func (d *dbusBase) getSliceSliceByteProperty(iface string) [][]byte {
value, ok := d.getProperty(iface).([][]byte)
if !ok {
panic(makeErrVariantType(iface))
func (d *dbusBase) getMapStringVariantProperty(iface string) (value map[string]dbus.Variant, err error) {
prop, err := d.getProperty(iface)
if err != nil {
return
}
return value
value, ok := prop.(map[string]dbus.Variant)
if !ok {
err = makeErrVariantType(iface)
return
}
return
}
func (d *dbusBase) getMapStringVariantProperty(iface string) map[string]dbus.Variant {
value, ok := d.getProperty(iface).(map[string]dbus.Variant)
if !ok {
panic(makeErrVariantType(iface))
func (d *dbusBase) getUint8Property(iface string) (value uint8, err error) {
prop, err := d.getProperty(iface)
if err != nil {
return
}
return value
value, ok := prop.(uint8)
if !ok {
err = makeErrVariantType(iface)
return
}
return
}
func (d *dbusBase) getUint8Property(iface string) uint8 {
value, ok := d.getProperty(iface).(uint8)
if !ok {
panic(makeErrVariantType(iface))
func (d *dbusBase) getUint32Property(iface string) (value uint32, err error) {
prop, err := d.getProperty(iface)
if err != nil {
return
}
return value
value, ok := prop.(uint32)
if !ok {
err = makeErrVariantType(iface)
return
}
return
}
func (d *dbusBase) getUint32Property(iface string) uint32 {
value, ok := d.getProperty(iface).(uint32)
if !ok {
panic(makeErrVariantType(iface))
func (d *dbusBase) getInt64Property(iface string) (value int64, err error) {
prop, err := d.getProperty(iface)
if err != nil {
return
}
return value
value, ok := prop.(int64)
if !ok {
err = makeErrVariantType(iface)
return
}
return
}
func (d *dbusBase) getInt64Property(iface string) int64 {
value, ok := d.getProperty(iface).(int64)
if !ok {
panic(makeErrVariantType(iface))
func (d *dbusBase) getUint64Property(iface string) (value uint64, err error) {
prop, err := d.getProperty(iface)
if err != nil {
return
}
return value
value, ok := prop.(uint64)
if !ok {
err = makeErrVariantType(iface)
return
}
return
}
func (d *dbusBase) getUint64Property(iface string) uint64 {
value, ok := d.getProperty(iface).(uint64)
if !ok {
panic(makeErrVariantType(iface))
func (d *dbusBase) getSliceUint32Property(iface string) (value []uint32, err error) {
prop, err := d.getProperty(iface)
if err != nil {
return
}
return value
value, ok := prop.([]uint32)
if !ok {
err = makeErrVariantType(iface)
return
}
return
}
func (d *dbusBase) getSliceUint32Property(iface string) []uint32 {
value, ok := d.getProperty(iface).([]uint32)
if !ok {
panic(makeErrVariantType(iface))
func (d *dbusBase) getSliceSliceUint32Property(iface string) (value [][]uint32, err error) {
prop, err := d.getProperty(iface)
if err != nil {
return
}
return value
value, ok := prop.([][]uint32)
if !ok {
err = makeErrVariantType(iface)
return
}
return
}
func (d *dbusBase) getSliceSliceUint32Property(iface string) [][]uint32 {
value, ok := d.getProperty(iface).([][]uint32)
if !ok {
panic(makeErrVariantType(iface))
func (d *dbusBase) getSliceMapStringVariantProperty(iface string) (value []map[string]dbus.Variant, err error) {
prop, err := d.getProperty(iface)
if err != nil {
return
}
return value
value, ok := prop.([]map[string]dbus.Variant)
if !ok {
err = makeErrVariantType(iface)
return
}
return
}
func (d *dbusBase) getSliceMapStringVariantProperty(iface string) []map[string]dbus.Variant {
value, ok := d.getProperty(iface).([]map[string]dbus.Variant)
func (d *dbusBase) getSliceByteProperty(iface string) (value []byte, err error) {
prop, err := d.getProperty(iface)
if err != nil {
return
}
value, ok := prop.([]byte)
if !ok {
panic(makeErrVariantType(iface))
err = makeErrVariantType(iface)
return
}
return value
}
func (d *dbusBase) getSliceByteProperty(iface string) []byte {
value, ok := d.getProperty(iface).([]byte)
if !ok {
panic(makeErrVariantType(iface))
}
return value
return
}
func makeErrVariantType(iface string) error {