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 { | type AccessPoint interface { | ||||||
|  | 	GetPath() dbus.ObjectPath | ||||||
|  | 
 | ||||||
| 	// GetFlags gets flags describing the capabilities of the access point. | 	// GetFlags gets flags describing the capabilities of the access point. | ||||||
| 	GetFlags() uint32 | 	GetFlags() uint32 | ||||||
| 
 | 
 | ||||||
|  | @ -65,6 +67,10 @@ type accessPoint struct { | ||||||
| 	dbusBase | 	dbusBase | ||||||
| } | } | ||||||
| 
 | 
 | ||||||
|  | func (a *accessPoint) GetPath() dbus.ObjectPath { | ||||||
|  | 	return a.obj.Path() | ||||||
|  | } | ||||||
|  | 
 | ||||||
| func (a *accessPoint) GetFlags() uint32 { | func (a *accessPoint) GetFlags() uint32 { | ||||||
| 	return a.getUint32Property(AccessPointPropertyFlags) | 	return a.getUint32Property(AccessPointPropertyFlags) | ||||||
| } | } | ||||||
|  |  | ||||||
|  | @ -16,6 +16,8 @@ const ( | ||||||
| type ConnectionSettings map[string]map[string]interface{} | type ConnectionSettings map[string]map[string]interface{} | ||||||
| 
 | 
 | ||||||
| type Connection interface { | type Connection interface { | ||||||
|  | 	GetPath() dbus.ObjectPath | ||||||
|  | 
 | ||||||
| 	// GetSettings gets the settings maps describing this network configuration. | 	// GetSettings gets the settings maps describing this network configuration. | ||||||
| 	// This will never include any secrets required for connection to the | 	// This will never include any secrets required for connection to the | ||||||
| 	// network, as those are often protected. Secrets must be requested | 	// network, as those are often protected. Secrets must be requested | ||||||
|  | @ -34,6 +36,10 @@ type connection struct { | ||||||
| 	dbusBase | 	dbusBase | ||||||
| } | } | ||||||
| 
 | 
 | ||||||
|  | func (c *connection) GetPath() dbus.ObjectPath { | ||||||
|  | 	return c.obj.Path() | ||||||
|  | } | ||||||
|  | 
 | ||||||
| func (c *connection) GetSettings() ConnectionSettings { | func (c *connection) GetSettings() ConnectionSettings { | ||||||
| 	var settings map[string]map[string]dbus.Variant | 	var settings map[string]map[string]dbus.Variant | ||||||
| 	c.call(&settings, ConnectionGetSettings) | 	c.call(&settings, ConnectionGetSettings) | ||||||
|  |  | ||||||
|  | @ -33,6 +33,8 @@ func DeviceFactory(objectPath dbus.ObjectPath) (Device, error) { | ||||||
| } | } | ||||||
| 
 | 
 | ||||||
| type Device interface { | type Device interface { | ||||||
|  | 	GetPath() dbus.ObjectPath | ||||||
|  | 
 | ||||||
| 	// GetInterface gets the name of the device's control (and often data) | 	// GetInterface gets the name of the device's control (and often data) | ||||||
| 	// interface. | 	// interface. | ||||||
| 	GetInterface() string | 	GetInterface() string | ||||||
|  | @ -73,6 +75,10 @@ type device struct { | ||||||
| 	dbusBase | 	dbusBase | ||||||
| } | } | ||||||
| 
 | 
 | ||||||
|  | func (d *device) GetPath() dbus.ObjectPath { | ||||||
|  | 	return d.obj.Path() | ||||||
|  | } | ||||||
|  | 
 | ||||||
| func (d *device) GetInterface() string { | func (d *device) GetInterface() string { | ||||||
| 	return d.getStringProperty(DevicePropertyInterface) | 	return d.getStringProperty(DevicePropertyInterface) | ||||||
| } | } | ||||||
|  |  | ||||||
|  | @ -11,6 +11,7 @@ const ( | ||||||
| 	NetworkManagerObjectPath = "/org/freedesktop/NetworkManager" | 	NetworkManagerObjectPath = "/org/freedesktop/NetworkManager" | ||||||
| 
 | 
 | ||||||
| 	NetworkManagerGetDevices               = NetworkManagerInterface + ".GetDevices" | 	NetworkManagerGetDevices               = NetworkManagerInterface + ".GetDevices" | ||||||
|  | 	NetworkManagerActivateConnection       = NetworkManagerInterface + ".ActivateConnection" | ||||||
| 	NetworkManagerPropertyState            = NetworkManagerInterface + ".State" | 	NetworkManagerPropertyState            = NetworkManagerInterface + ".State" | ||||||
| 	NetworkManagerPropertyActiveConnection = NetworkManagerInterface + ".ActiveConnections" | 	NetworkManagerPropertyActiveConnection = NetworkManagerInterface + ".ActiveConnections" | ||||||
| ) | ) | ||||||
|  | @ -25,8 +26,12 @@ type NetworkManager interface { | ||||||
| 	// management. | 	// management. | ||||||
| 	GetState() NmState | 	GetState() NmState | ||||||
| 
 | 
 | ||||||
|  | 	// GetActiveConnections returns the active connection of network devices. | ||||||
| 	GetActiveConnections() []ActiveConnection | 	GetActiveConnections() []ActiveConnection | ||||||
| 
 | 
 | ||||||
|  | 	// ActivateWirelessConnection requests activating access point to network device | ||||||
|  | 	ActivateWirelessConnection(connection Connection, device Device, accessPoint AccessPoint) ActiveConnection | ||||||
|  | 
 | ||||||
| 	Subscribe() <-chan *dbus.Signal | 	Subscribe() <-chan *dbus.Signal | ||||||
| 	Unsubscribe() | 	Unsubscribe() | ||||||
| 
 | 
 | ||||||
|  | @ -80,6 +85,12 @@ func (n *networkManager) GetActiveConnections() []ActiveConnection { | ||||||
| 	return ac | 	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 { | func (n *networkManager) Subscribe() <-chan *dbus.Signal { | ||||||
| 	if n.sigChan != nil { | 	if n.sigChan != nil { | ||||||
| 		return n.sigChan | 		return n.sigChan | ||||||
|  |  | ||||||
|  | @ -10,6 +10,7 @@ const ( | ||||||
| 	WirelessDeviceInterface = DeviceInterface + ".Wireless" | 	WirelessDeviceInterface = DeviceInterface + ".Wireless" | ||||||
| 
 | 
 | ||||||
| 	WirelessDeviceGetAccessPoints = WirelessDeviceInterface + ".GetAccessPoints" | 	WirelessDeviceGetAccessPoints = WirelessDeviceInterface + ".GetAccessPoints" | ||||||
|  | 	WirelessDeviceRequestScan     = WirelessDeviceInterface + ".RequestScan" | ||||||
| ) | ) | ||||||
| 
 | 
 | ||||||
| type WirelessDevice interface { | type WirelessDevice interface { | ||||||
|  | @ -20,6 +21,8 @@ type WirelessDevice interface { | ||||||
| 	// To retrieve a list of all access points (including hidden ones) use the | 	// To retrieve a list of all access points (including hidden ones) use the | ||||||
| 	// GetAllAccessPoints() method. | 	// GetAllAccessPoints() method. | ||||||
| 	GetAccessPoints() []AccessPoint | 	GetAccessPoints() []AccessPoint | ||||||
|  | 
 | ||||||
|  | 	RequestScan() | ||||||
| } | } | ||||||
| 
 | 
 | ||||||
| func NewWirelessDevice(objectPath dbus.ObjectPath) (WirelessDevice, error) { | func NewWirelessDevice(objectPath dbus.ObjectPath) (WirelessDevice, error) { | ||||||
|  | @ -48,6 +51,11 @@ func (d *wirelessDevice) GetAccessPoints() []AccessPoint { | ||||||
| 	return aps | 	return aps | ||||||
| } | } | ||||||
| 
 | 
 | ||||||
|  | func (d *wirelessDevice) RequestScan() { | ||||||
|  | 	var options map[string]interface{} | ||||||
|  | 	d.obj.Call(WirelessDeviceRequestScan, 0, options).Store() | ||||||
|  | } | ||||||
|  | 
 | ||||||
| func (d *wirelessDevice) MarshalJSON() ([]byte, error) { | func (d *wirelessDevice) MarshalJSON() ([]byte, error) { | ||||||
| 	m := d.device.marshalMap() | 	m := d.device.marshalMap() | ||||||
| 	m["AccessPoints"] = d.GetAccessPoints() | 	m["AccessPoints"] = d.GetAccessPoints() | ||||||
|  |  | ||||||
		Reference in a new issue