This repository has been archived on 2025-03-19. You can view files and clone it, but cannot push or open issues or pull requests.
gonetworkmanager/WirelessDevice.go

55 lines
1.2 KiB
Go

package gonetworkmanager
import (
"encoding/json"
"github.com/godbus/dbus"
)
const (
WirelessDeviceInterface = DeviceInterface + ".Wireless"
WirelessDeviceGetAccessPoints = WirelessDeviceInterface + ".GetAccessPoints"
)
type WirelessDevice interface {
Device
// GetAccessPoints gets the list of access points visible to this device.
// 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
}
func NewWirelessDevice(objectPath dbus.ObjectPath) (WirelessDevice, error) {
var d wirelessDevice
return &d, d.init(NetworkManagerInterface, objectPath)
}
type wirelessDevice struct {
device
}
func (d *wirelessDevice) GetAccessPoints() []AccessPoint {
var apPaths []dbus.ObjectPath
d.call(&apPaths, WirelessDeviceGetAccessPoints)
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
}
func (d *wirelessDevice) MarshalJSON() ([]byte, error) {
m := d.device.marshalMap()
m["AccessPoints"] = d.GetAccessPoints()
return json.Marshal(m)
}