Rename call methods for better understandable logic. Add additional call with no return value.
This commit is contained in:
parent
ab586e0f32
commit
a5d97dddcc
5 changed files with 19 additions and 15 deletions
|
@ -21,7 +21,7 @@ type Connection interface {
|
||||||
// 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
|
||||||
// separately using the GetSecrets() call.
|
// separately using the GetSecrets() callAndPanic.
|
||||||
GetSettings() ConnectionSettings
|
GetSettings() ConnectionSettings
|
||||||
|
|
||||||
MarshalJSON() ([]byte, error)
|
MarshalJSON() ([]byte, error)
|
||||||
|
@ -42,7 +42,7 @@ func (c *connection) GetPath() dbus.ObjectPath {
|
||||||
|
|
||||||
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.callAndPanic(&settings, ConnectionGetSettings)
|
||||||
|
|
||||||
rv := make(ConnectionSettings)
|
rv := make(ConnectionSettings)
|
||||||
|
|
||||||
|
|
|
@ -68,7 +68,7 @@ type networkManager struct {
|
||||||
func (n *networkManager) GetDevices() []Device {
|
func (n *networkManager) GetDevices() []Device {
|
||||||
var devicePaths []dbus.ObjectPath
|
var devicePaths []dbus.ObjectPath
|
||||||
|
|
||||||
n.call(&devicePaths, NetworkManagerGetDevices)
|
n.callAndPanic(&devicePaths, NetworkManagerGetDevices)
|
||||||
devices := make([]Device, len(devicePaths))
|
devices := make([]Device, len(devicePaths))
|
||||||
|
|
||||||
var err error
|
var err error
|
||||||
|
@ -85,7 +85,7 @@ func (n *networkManager) GetDevices() []Device {
|
||||||
func (n *networkManager) GetAllDevices() []Device {
|
func (n *networkManager) GetAllDevices() []Device {
|
||||||
var devicePaths []dbus.ObjectPath
|
var devicePaths []dbus.ObjectPath
|
||||||
|
|
||||||
n.call(&devicePaths, NetworkManagerGetAllDevices)
|
n.callAndPanic(&devicePaths, NetworkManagerGetAllDevices)
|
||||||
devices := make([]Device, len(devicePaths))
|
devices := make([]Device, len(devicePaths))
|
||||||
|
|
||||||
var err error
|
var err error
|
||||||
|
@ -120,7 +120,7 @@ func (n *networkManager) GetActiveConnections() []ActiveConnection {
|
||||||
|
|
||||||
func (n *networkManager) ActivateWirelessConnection(c Connection, d Device, ap AccessPoint) ActiveConnection {
|
func (n *networkManager) ActivateWirelessConnection(c Connection, d Device, ap AccessPoint) ActiveConnection {
|
||||||
var opath dbus.ObjectPath
|
var opath dbus.ObjectPath
|
||||||
n.call(&opath, NetworkManagerActivateConnection, c.GetPath(), d.GetPath(), ap.GetPath())
|
n.callAndPanic(&opath, NetworkManagerActivateConnection, c.GetPath(), d.GetPath(), ap.GetPath())
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -128,7 +128,7 @@ func (n *networkManager) AddAndActivateWirelessConnection(connection map[string]
|
||||||
var opath1 dbus.ObjectPath
|
var opath1 dbus.ObjectPath
|
||||||
var opath2 dbus.ObjectPath
|
var opath2 dbus.ObjectPath
|
||||||
|
|
||||||
err = n.callError2(&opath1, &opath2, NetworkManagerAddAndActivateConnection, connection, d.GetPath(), ap.GetPath())
|
err = n.callWithReturn2(&opath1, &opath2, NetworkManagerAddAndActivateConnection, connection, d.GetPath(), ap.GetPath())
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
|
@ -33,7 +33,7 @@ type settings struct {
|
||||||
func (s *settings) ListConnections() []Connection {
|
func (s *settings) ListConnections() []Connection {
|
||||||
var connectionPaths []dbus.ObjectPath
|
var connectionPaths []dbus.ObjectPath
|
||||||
|
|
||||||
s.call(&connectionPaths, SettingsListConnections)
|
s.callAndPanic(&connectionPaths, SettingsListConnections)
|
||||||
connections := make([]Connection, len(connectionPaths))
|
connections := make([]Connection, len(connectionPaths))
|
||||||
|
|
||||||
var err error
|
var err error
|
||||||
|
@ -49,7 +49,7 @@ func (s *settings) ListConnections() []Connection {
|
||||||
|
|
||||||
func (s *settings) AddConnection(settings ConnectionSettings) Connection {
|
func (s *settings) AddConnection(settings ConnectionSettings) Connection {
|
||||||
var path dbus.ObjectPath
|
var path dbus.ObjectPath
|
||||||
s.call(&path, SettingsAddConnection, settings)
|
s.callAndPanic(&path, SettingsAddConnection, settings)
|
||||||
con, err := NewConnection(path)
|
con, err := NewConnection(path)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
panic(err)
|
panic(err)
|
||||||
|
|
|
@ -37,7 +37,7 @@ type wirelessDevice struct {
|
||||||
func (d *wirelessDevice) GetAccessPoints() []AccessPoint {
|
func (d *wirelessDevice) GetAccessPoints() []AccessPoint {
|
||||||
var apPaths []dbus.ObjectPath
|
var apPaths []dbus.ObjectPath
|
||||||
|
|
||||||
d.call(&apPaths, WirelessDeviceGetAccessPoints)
|
d.callAndPanic(&apPaths, WirelessDeviceGetAccessPoints)
|
||||||
aps := make([]AccessPoint, len(apPaths))
|
aps := make([]AccessPoint, len(apPaths))
|
||||||
|
|
||||||
var err error
|
var err error
|
||||||
|
|
16
utils.go
16
utils.go
|
@ -30,19 +30,23 @@ func (d *dbusBase) init(iface string, objectPath dbus.ObjectPath) error {
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (d *dbusBase) call(value interface{}, method string, args ...interface{}) {
|
func (d *dbusBase) callAndPanic(value interface{}, method string, args ...interface{}) {
|
||||||
err := d.callError(value, method, args...)
|
err := d.callWithReturn(value, method, args...)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
panic(err)
|
panic(err)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func (d *dbusBase) callError(value interface{}, method string, args ...interface{}) error {
|
func (d *dbusBase) call(method string, args ...interface{}) error {
|
||||||
return d.obj.Call(method, 0, args...).Store(value)
|
return d.obj.Call(method, 0, args...).Err
|
||||||
}
|
}
|
||||||
|
|
||||||
func (d *dbusBase) callError2(value1 interface{}, value2 interface{}, method string, args ...interface{}) error {
|
func (d *dbusBase) callWithReturn(ret interface{}, method string, args ...interface{}) error {
|
||||||
return d.obj.Call(method, 0, args...).Store(value1, value2)
|
return d.obj.Call(method, 0, args...).Store(ret)
|
||||||
|
}
|
||||||
|
|
||||||
|
func (d *dbusBase) callWithReturn2(ret1 interface{}, ret2 interface{}, method string, args ...interface{}) error {
|
||||||
|
return d.obj.Call(method, 0, args...).Store(ret1, ret2)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (d *dbusBase) subscribe(iface, member string) {
|
func (d *dbusBase) subscribe(iface, member string) {
|
||||||
|
|
Reference in a new issue