Refactor callAndPanic to callWithReturnAndPanic
This commit is contained in:
parent
a165df46fa
commit
b9e95e8780
5 changed files with 15 additions and 15 deletions
|
@ -34,7 +34,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() callAndPanic.
|
||||
// separately using the GetSecrets() callWithReturnAndPanic.
|
||||
GetSettings() ConnectionSettings
|
||||
|
||||
MarshalJSON() ([]byte, error)
|
||||
|
@ -55,7 +55,7 @@ func (c *connection) GetPath() dbus.ObjectPath {
|
|||
|
||||
func (c *connection) GetSettings() ConnectionSettings {
|
||||
var settings map[string]map[string]dbus.Variant
|
||||
c.callAndPanic(&settings, ConnectionGetSettings)
|
||||
c.callWithReturnAndPanic(&settings, ConnectionGetSettings)
|
||||
|
||||
rv := make(ConnectionSettings)
|
||||
|
||||
|
|
|
@ -107,7 +107,7 @@ type networkManager struct {
|
|||
func (n *networkManager) GetDevices() []Device {
|
||||
var devicePaths []dbus.ObjectPath
|
||||
|
||||
n.callAndPanic(&devicePaths, NetworkManagerGetDevices)
|
||||
n.callWithReturnAndPanic(&devicePaths, NetworkManagerGetDevices)
|
||||
devices := make([]Device, len(devicePaths))
|
||||
|
||||
var err error
|
||||
|
@ -124,7 +124,7 @@ func (n *networkManager) GetDevices() []Device {
|
|||
func (n *networkManager) GetAllDevices() []Device {
|
||||
var devicePaths []dbus.ObjectPath
|
||||
|
||||
n.callAndPanic(&devicePaths, NetworkManagerGetAllDevices)
|
||||
n.callWithReturnAndPanic(&devicePaths, NetworkManagerGetAllDevices)
|
||||
devices := make([]Device, len(devicePaths))
|
||||
|
||||
var err error
|
||||
|
@ -159,7 +159,7 @@ func (n *networkManager) GetActiveConnections() []ActiveConnection {
|
|||
|
||||
func (n *networkManager) ActivateWirelessConnection(c Connection, d Device, ap AccessPoint) ActiveConnection {
|
||||
var opath dbus.ObjectPath
|
||||
n.callAndPanic(&opath, NetworkManagerActivateConnection, c.GetPath(), d.GetPath(), ap.GetPath())
|
||||
n.callWithReturnAndPanic(&opath, NetworkManagerActivateConnection, c.GetPath(), d.GetPath(), ap.GetPath())
|
||||
return nil
|
||||
}
|
||||
|
||||
|
|
|
@ -27,7 +27,7 @@ type Settings interface {
|
|||
// ListConnections gets list the saved network connections known to NetworkManager
|
||||
ListConnections() []Connection
|
||||
|
||||
// AddConnection callAndPanic new connection and save it to disk.
|
||||
// AddConnection callWithReturnAndPanic new connection and save it to disk.
|
||||
AddConnection(settings ConnectionSettings) Connection
|
||||
|
||||
// Save the hostname to persistent configuration.
|
||||
|
@ -49,7 +49,7 @@ type settings struct {
|
|||
func (s *settings) ListConnections() []Connection {
|
||||
var connectionPaths []dbus.ObjectPath
|
||||
|
||||
s.callAndPanic(&connectionPaths, SettingsListConnections)
|
||||
s.callWithReturnAndPanic(&connectionPaths, SettingsListConnections)
|
||||
connections := make([]Connection, len(connectionPaths))
|
||||
|
||||
var err error
|
||||
|
@ -65,7 +65,7 @@ func (s *settings) ListConnections() []Connection {
|
|||
|
||||
func (s *settings) AddConnection(settings ConnectionSettings) Connection {
|
||||
var path dbus.ObjectPath
|
||||
s.callAndPanic(&path, SettingsAddConnection, settings)
|
||||
s.callWithReturnAndPanic(&path, SettingsAddConnection, settings)
|
||||
con, err := NewConnection(path)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
|
|
|
@ -37,7 +37,7 @@ type wirelessDevice struct {
|
|||
func (d *wirelessDevice) GetAccessPoints() []AccessPoint {
|
||||
var apPaths []dbus.ObjectPath
|
||||
|
||||
d.callAndPanic(&apPaths, WirelessDeviceGetAccessPoints)
|
||||
d.callWithReturnAndPanic(&apPaths, WirelessDeviceGetAccessPoints)
|
||||
aps := make([]AccessPoint, len(apPaths))
|
||||
|
||||
var err error
|
||||
|
|
12
utils.go
12
utils.go
|
@ -30,17 +30,17 @@ func (d *dbusBase) init(iface string, objectPath dbus.ObjectPath) error {
|
|||
return nil
|
||||
}
|
||||
|
||||
func (d *dbusBase) callAndPanic(value interface{}, method string, args ...interface{}) {
|
||||
err := d.callWithReturn(value, method, args...)
|
||||
func (d *dbusBase) call(method string, args ...interface{}) error {
|
||||
return d.obj.Call(method, 0, args...).Err
|
||||
}
|
||||
|
||||
func (d *dbusBase) callWithReturnAndPanic(ret interface{}, method string, args ...interface{}) {
|
||||
err := d.callWithReturn(ret, method, args...)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
}
|
||||
|
||||
func (d *dbusBase) call(method string, args ...interface{}) error {
|
||||
return d.obj.Call(method, 0, args...).Err
|
||||
}
|
||||
|
||||
func (d *dbusBase) callWithReturn(ret interface{}, method string, args ...interface{}) error {
|
||||
return d.obj.Call(method, 0, args...).Store(ret)
|
||||
}
|
||||
|
|
Reference in a new issue