Request scan and activate access point (#6)
Add some methods for wireless devices.
This commit is contained in:
parent
c185f6c3d0
commit
e95fae9eed
5 changed files with 37 additions and 0 deletions
|
@ -21,6 +21,8 @@ const (
|
|||
)
|
||||
|
||||
type AccessPoint interface {
|
||||
GetPath() dbus.ObjectPath
|
||||
|
||||
// GetFlags gets flags describing the capabilities of the access point.
|
||||
GetFlags() uint32
|
||||
|
||||
|
@ -65,6 +67,10 @@ type accessPoint struct {
|
|||
dbusBase
|
||||
}
|
||||
|
||||
func (a *accessPoint) GetPath() dbus.ObjectPath {
|
||||
return a.obj.Path()
|
||||
}
|
||||
|
||||
func (a *accessPoint) GetFlags() uint32 {
|
||||
return a.getUint32Property(AccessPointPropertyFlags)
|
||||
}
|
||||
|
|
|
@ -16,6 +16,8 @@ const (
|
|||
type ConnectionSettings map[string]map[string]interface{}
|
||||
|
||||
type Connection interface {
|
||||
GetPath() dbus.ObjectPath
|
||||
|
||||
// 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
|
||||
|
@ -34,6 +36,10 @@ type connection struct {
|
|||
dbusBase
|
||||
}
|
||||
|
||||
func (c *connection) GetPath() dbus.ObjectPath {
|
||||
return c.obj.Path()
|
||||
}
|
||||
|
||||
func (c *connection) GetSettings() ConnectionSettings {
|
||||
var settings map[string]map[string]dbus.Variant
|
||||
c.call(&settings, ConnectionGetSettings)
|
||||
|
|
|
@ -33,6 +33,8 @@ func DeviceFactory(objectPath dbus.ObjectPath) (Device, error) {
|
|||
}
|
||||
|
||||
type Device interface {
|
||||
GetPath() dbus.ObjectPath
|
||||
|
||||
// GetInterface gets the name of the device's control (and often data)
|
||||
// interface.
|
||||
GetInterface() string
|
||||
|
@ -73,6 +75,10 @@ type device struct {
|
|||
dbusBase
|
||||
}
|
||||
|
||||
func (d *device) GetPath() dbus.ObjectPath {
|
||||
return d.obj.Path()
|
||||
}
|
||||
|
||||
func (d *device) GetInterface() string {
|
||||
return d.getStringProperty(DevicePropertyInterface)
|
||||
}
|
||||
|
|
|
@ -11,6 +11,7 @@ const (
|
|||
NetworkManagerObjectPath = "/org/freedesktop/NetworkManager"
|
||||
|
||||
NetworkManagerGetDevices = NetworkManagerInterface + ".GetDevices"
|
||||
NetworkManagerActivateConnection = NetworkManagerInterface + ".ActivateConnection"
|
||||
NetworkManagerPropertyState = NetworkManagerInterface + ".State"
|
||||
NetworkManagerPropertyActiveConnection = NetworkManagerInterface + ".ActiveConnections"
|
||||
)
|
||||
|
@ -25,8 +26,12 @@ type NetworkManager interface {
|
|||
// management.
|
||||
GetState() NmState
|
||||
|
||||
// GetActiveConnections returns the active connection of network devices.
|
||||
GetActiveConnections() []ActiveConnection
|
||||
|
||||
// ActivateWirelessConnection requests activating access point to network device
|
||||
ActivateWirelessConnection(connection Connection, device Device, accessPoint AccessPoint) ActiveConnection
|
||||
|
||||
Subscribe() <-chan *dbus.Signal
|
||||
Unsubscribe()
|
||||
|
||||
|
@ -80,6 +85,12 @@ func (n *networkManager) GetActiveConnections() []ActiveConnection {
|
|||
return ac
|
||||
}
|
||||
|
||||
func (n *networkManager) ActivateWirelessConnection(c Connection, d Device, ap AccessPoint) ActiveConnection {
|
||||
var opath dbus.ObjectPath
|
||||
n.call(&opath, NetworkManagerActivateConnection, c.GetPath(), d.GetPath(), ap.GetPath())
|
||||
return nil
|
||||
}
|
||||
|
||||
func (n *networkManager) Subscribe() <-chan *dbus.Signal {
|
||||
if n.sigChan != nil {
|
||||
return n.sigChan
|
||||
|
|
|
@ -10,6 +10,7 @@ const (
|
|||
WirelessDeviceInterface = DeviceInterface + ".Wireless"
|
||||
|
||||
WirelessDeviceGetAccessPoints = WirelessDeviceInterface + ".GetAccessPoints"
|
||||
WirelessDeviceRequestScan = WirelessDeviceInterface + ".RequestScan"
|
||||
)
|
||||
|
||||
type WirelessDevice interface {
|
||||
|
@ -20,6 +21,8 @@ type WirelessDevice interface {
|
|||
// 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) {
|
||||
|
@ -48,6 +51,11 @@ func (d *wirelessDevice) GetAccessPoints() []AccessPoint {
|
|||
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()
|
||||
|
|
Reference in a new issue