NetworkMenu: don't query DBus properties of removed objects

Calling nm_access_point_get_ssid() in the handler of the
access-point-removed signal can result in DBus request, which will
then fail because the object was already removed at the server side.
Instead, use a difference function to retrieve the access point
object (the network), that compares directly by object identity.

https://bugzilla.gnome.org/show_bug.cgi?id=651378
This commit is contained in:
Giovanni Campagna 2011-10-14 16:46:52 +02:00 committed by Owen W. Taylor
parent d85a16589b
commit 552ae78557

View File

@ -1104,10 +1104,10 @@ NMDeviceWireless.prototype = {
let activeAp = this.device.active_access_point; let activeAp = this.device.active_access_point;
if (activeAp) { if (activeAp) {
let pos = this._findNetwork(activeAp); let res = this._findExistingNetwork(activeAp);
if (pos != -1) if (res != null)
this._activeNetwork = this._networks[pos]; this._activeNetwork = this._networks[res.network];
} }
// we don't refresh the view here, setActiveConnection will // we don't refresh the view here, setActiveConnection will
@ -1181,6 +1181,18 @@ NMDeviceWireless.prototype = {
return true; return true;
}, },
_findExistingNetwork: function(accessPoint) {
for (let i = 0; i < this._networks.length; i++) {
let apObj = this._networks[i];
for (let j = 0; j < apObj.accessPoints.length; j++) {
if (apObj.accessPoints[j] == accessPoint)
return { network: i, ap: j };
}
}
return null;
},
_findNetwork: function(accessPoint) { _findNetwork: function(accessPoint) {
if (accessPoint.get_ssid() == null) if (accessPoint.get_ssid() == null)
return -1; return -1;
@ -1273,22 +1285,15 @@ NMDeviceWireless.prototype = {
}, },
_accessPointRemoved: function(device, accessPoint) { _accessPointRemoved: function(device, accessPoint) {
let pos = this._findNetwork(accessPoint); let res = this._findExistingNetwork(accessPoint);
if (pos == -1) { if (res == null) {
log('Removing an access point that was never added'); log('Removing an access point that was never added');
return; return;
} }
let apObj = this._networks[pos]; let apObj = this._networks[res.network];
let i = apObj.accessPoints.indexOf(accessPoint); apObj.accessPoints.splice(res.ap, 1);
if (i == -1) {
log('Removing an access point that was never added');
return;
}
apObj.accessPoints.splice(i, 1);
if (apObj.accessPoints.length == 0) { if (apObj.accessPoints.length == 0) {
if (this._activeNetwork == apObj) if (this._activeNetwork == apObj)