Rename call methods for better understandable logic. Add additional call with no return value.

This commit is contained in:
Christian Müller 2019-05-15 17:38:20 +02:00
parent ab586e0f32
commit a5d97dddcc
5 changed files with 19 additions and 15 deletions

View file

@ -21,7 +21,7 @@ type Connection interface {
// 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
// separately using the GetSecrets() call.
// separately using the GetSecrets() callAndPanic.
GetSettings() ConnectionSettings
MarshalJSON() ([]byte, error)
@ -42,7 +42,7 @@ func (c *connection) GetPath() dbus.ObjectPath {
func (c *connection) GetSettings() ConnectionSettings {
var settings map[string]map[string]dbus.Variant
c.call(&settings, ConnectionGetSettings)
c.callAndPanic(&settings, ConnectionGetSettings)
rv := make(ConnectionSettings)

View file

@ -68,7 +68,7 @@ type networkManager struct {
func (n *networkManager) GetDevices() []Device {
var devicePaths []dbus.ObjectPath
n.call(&devicePaths, NetworkManagerGetDevices)
n.callAndPanic(&devicePaths, NetworkManagerGetDevices)
devices := make([]Device, len(devicePaths))
var err error
@ -85,7 +85,7 @@ func (n *networkManager) GetDevices() []Device {
func (n *networkManager) GetAllDevices() []Device {
var devicePaths []dbus.ObjectPath
n.call(&devicePaths, NetworkManagerGetAllDevices)
n.callAndPanic(&devicePaths, NetworkManagerGetAllDevices)
devices := make([]Device, len(devicePaths))
var err error
@ -120,7 +120,7 @@ func (n *networkManager) GetActiveConnections() []ActiveConnection {
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())
n.callAndPanic(&opath, NetworkManagerActivateConnection, c.GetPath(), d.GetPath(), ap.GetPath())
return nil
}
@ -128,7 +128,7 @@ func (n *networkManager) AddAndActivateWirelessConnection(connection map[string]
var opath1 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 {
return
}

View file

@ -33,7 +33,7 @@ type settings struct {
func (s *settings) ListConnections() []Connection {
var connectionPaths []dbus.ObjectPath
s.call(&connectionPaths, SettingsListConnections)
s.callAndPanic(&connectionPaths, SettingsListConnections)
connections := make([]Connection, len(connectionPaths))
var err error
@ -49,7 +49,7 @@ func (s *settings) ListConnections() []Connection {
func (s *settings) AddConnection(settings ConnectionSettings) Connection {
var path dbus.ObjectPath
s.call(&path, SettingsAddConnection, settings)
s.callAndPanic(&path, SettingsAddConnection, settings)
con, err := NewConnection(path)
if err != nil {
panic(err)

View file

@ -37,7 +37,7 @@ type wirelessDevice struct {
func (d *wirelessDevice) GetAccessPoints() []AccessPoint {
var apPaths []dbus.ObjectPath
d.call(&apPaths, WirelessDeviceGetAccessPoints)
d.callAndPanic(&apPaths, WirelessDeviceGetAccessPoints)
aps := make([]AccessPoint, len(apPaths))
var err error

View file

@ -30,19 +30,23 @@ func (d *dbusBase) init(iface string, objectPath dbus.ObjectPath) error {
return nil
}
func (d *dbusBase) call(value interface{}, method string, args ...interface{}) {
err := d.callError(value, method, args...)
func (d *dbusBase) callAndPanic(value interface{}, method string, args ...interface{}) {
err := d.callWithReturn(value, method, args...)
if err != nil {
panic(err)
}
}
func (d *dbusBase) callError(value interface{}, method string, args ...interface{}) error {
return d.obj.Call(method, 0, args...).Store(value)
func (d *dbusBase) call(method string, args ...interface{}) error {
return d.obj.Call(method, 0, args...).Err
}
func (d *dbusBase) callError2(value1 interface{}, value2 interface{}, method string, args ...interface{}) error {
return d.obj.Call(method, 0, args...).Store(value1, value2)
func (d *dbusBase) callWithReturn(ret interface{}, method string, args ...interface{}) error {
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) {