diff --git a/Connection.go b/Connection.go index 896a51c..c7d9339 100644 --- a/Connection.go +++ b/Connection.go @@ -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) diff --git a/NetworkManager.go b/NetworkManager.go index 34a657f..9bc385d 100644 --- a/NetworkManager.go +++ b/NetworkManager.go @@ -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 } diff --git a/Settings.go b/Settings.go index bb0a25d..2d94ec1 100644 --- a/Settings.go +++ b/Settings.go @@ -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) diff --git a/WirelessDevice.go b/WirelessDevice.go index 0cd1217..b496729 100644 --- a/WirelessDevice.go +++ b/WirelessDevice.go @@ -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 diff --git a/utils.go b/utils.go index 2be22a8..c03bdcc 100644 --- a/utils.go +++ b/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) }