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
2019-05-28 11:06:28 +02:00

63 lines
1.5 KiB
Go

package gonetworkmanager
import (
"encoding/json"
"github.com/godbus/dbus"
)
const (
WirelessDeviceInterface = DeviceInterface + ".Wireless"
WirelessDeviceGetAccessPoints = WirelessDeviceInterface + ".GetAccessPoints"
WirelessDeviceRequestScan = WirelessDeviceInterface + ".RequestScan"
)
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
RequestScan()
}
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.callWithReturnAndPanic(&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) RequestScan() {
var options map[string]interface{}
d.obj.Call(WirelessDeviceRequestScan, 0, options).Store()
}
func (d *wirelessDevice) MarshalJSON() ([]byte, error) {
m := d.device.marshalMap()
m["AccessPoints"] = d.GetAccessPoints()
return json.Marshal(m)
}