HostDev: Refactor device list(s) ops
Use function(s) to hide the insertion/removal from multiple internal lists
This commit is contained in:
parent
e6592c03a2
commit
edd326fb24
@ -59,9 +59,6 @@ void DeviceManager::createHostDevices(void)
|
|||||||
if (!ifInfo)
|
if (!ifInfo)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
NullDevice bcastDevice(this);
|
|
||||||
bcastDevice.setMac(kBcastMac);
|
|
||||||
|
|
||||||
int count = ifInfo->ip4.size();
|
int count = ifInfo->ip4.size();
|
||||||
for (int i = 0; i < count; i++) {
|
for (int i = 0; i < count; i++) {
|
||||||
// XXX: Since we can't support multiple IPs with same mac,
|
// XXX: Since we can't support multiple IPs with same mac,
|
||||||
@ -82,10 +79,7 @@ void DeviceManager::createHostDevices(void)
|
|||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
hostDeviceList_.append(device);
|
hostDeviceList_.append(device);
|
||||||
deviceList_.insert(device->key(), device);
|
insertDevice(device->key(), device);
|
||||||
sortedDeviceList_.insert(device->key(), device);
|
|
||||||
|
|
||||||
bcastList_.insert(bcastDevice.key(), device);
|
|
||||||
qDebug("host(add): %s", qPrintable(device->config()));
|
qDebug("host(add): %s", qPrintable(device->config()));
|
||||||
|
|
||||||
break; // TODO: support multiple IPs with same mac
|
break; // TODO: support multiple IPs with same mac
|
||||||
@ -108,10 +102,7 @@ void DeviceManager::createHostDevices(void)
|
|||||||
ifInfo->ip6.at(i).prefixLength,
|
ifInfo->ip6.at(i).prefixLength,
|
||||||
ifInfo->ip6.at(i).gateway);
|
ifInfo->ip6.at(i).gateway);
|
||||||
hostDeviceList_.append(device);
|
hostDeviceList_.append(device);
|
||||||
deviceList_.insert(device->key(), device);
|
insertDevice(device->key(), device);
|
||||||
sortedDeviceList_.insert(device->key(), device);
|
|
||||||
|
|
||||||
bcastList_.insert(bcastDevice.key(), device);
|
|
||||||
qDebug("host(add): %s", qPrintable(device->config()));
|
qDebug("host(add): %s", qPrintable(device->config()));
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
@ -539,27 +530,19 @@ void DeviceManager::enumerateDevices(
|
|||||||
}
|
}
|
||||||
device = new EmulDevice(this);
|
device = new EmulDevice(this);
|
||||||
*device = dk;
|
*device = dk;
|
||||||
deviceList_.insert(dk.key(), device);
|
insertDevice(dk.key(), device);
|
||||||
sortedDeviceList_.insert(dk.key(), device);
|
|
||||||
|
|
||||||
dk.setMac(kBcastMac);
|
|
||||||
bcastList_.insert(dk.key(), device);
|
|
||||||
qDebug("enumerate(add): %p %s", device, qPrintable(device->config()));
|
qDebug("enumerate(add): %p %s", device, qPrintable(device->config()));
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case kDelete:
|
case kDelete:
|
||||||
device = deviceList_.take(dk.key());
|
device = deviceList_.value(dk.key());
|
||||||
if (!device) {
|
if (!device) {
|
||||||
qWarning("%s: error deleting device %s (NOTFOUND)",
|
qWarning("%s: error deleting device %s (NOTFOUND)",
|
||||||
__FUNCTION__, qPrintable(dk.config()));
|
__FUNCTION__, qPrintable(dk.config()));
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
qDebug("enumerate(del): %p %s", device, qPrintable(device->config()));
|
qDebug("enumerate(del): %p %s", device, qPrintable(device->config()));
|
||||||
delete device;
|
deleteDevice(dk.key());
|
||||||
sortedDeviceList_.take(dk.key()); // already freed above
|
|
||||||
|
|
||||||
dk.setMac(kBcastMac);
|
|
||||||
bcastList_.take(dk.key()); // device already freed above
|
|
||||||
break;
|
break;
|
||||||
|
|
||||||
default:
|
default:
|
||||||
@ -568,3 +551,32 @@ void DeviceManager::enumerateDevices(
|
|||||||
} // foreach device
|
} // foreach device
|
||||||
} // foreach vlan
|
} // foreach vlan
|
||||||
}
|
}
|
||||||
|
|
||||||
|
bool DeviceManager::insertDevice(DeviceKey key, Device *device)
|
||||||
|
{
|
||||||
|
deviceList_.insert(key, device);
|
||||||
|
sortedDeviceList_.insert(key, device);
|
||||||
|
|
||||||
|
NullDevice bcastDevice = *(static_cast<NullDevice*>(device));
|
||||||
|
bcastDevice.setMac(kBcastMac);
|
||||||
|
|
||||||
|
bcastList_.insert(bcastDevice.key(), device);
|
||||||
|
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
bool DeviceManager::deleteDevice(DeviceKey key)
|
||||||
|
{
|
||||||
|
Device *device = deviceList_.take(key);
|
||||||
|
if (!device)
|
||||||
|
return false;
|
||||||
|
sortedDeviceList_.take(key);
|
||||||
|
|
||||||
|
NullDevice bcastDevice = *(static_cast<NullDevice*>(device));
|
||||||
|
bcastDevice.setMac(kBcastMac);
|
||||||
|
bcastList_.take(bcastDevice.key());
|
||||||
|
|
||||||
|
delete device;
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
@ -71,6 +71,8 @@ private:
|
|||||||
void enumerateDevices(
|
void enumerateDevices(
|
||||||
const OstProto::DeviceGroup *deviceGroup,
|
const OstProto::DeviceGroup *deviceGroup,
|
||||||
Operation oper);
|
Operation oper);
|
||||||
|
bool insertDevice(DeviceKey key, Device *device);
|
||||||
|
bool deleteDevice(DeviceKey key);
|
||||||
|
|
||||||
AbstractPort *port_;
|
AbstractPort *port_;
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user