Feature (contd.): Device Emulation - sort the device list returned by getDeviceList() RPC
This commit is contained in:
parent
cad62c1fd7
commit
dc28dfefd6
@ -457,3 +457,18 @@ void Device::sendArpRequest(PacketBuffer *pktBuf)
|
|||||||
qPrintable(QHostAddress(srcIp).toString()),
|
qPrintable(QHostAddress(srcIp).toString()),
|
||||||
qPrintable(QHostAddress(tgtIp).toString()));
|
qPrintable(QHostAddress(tgtIp).toString()));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
bool operator<(const DeviceKey &a1, const DeviceKey &a2)
|
||||||
|
{
|
||||||
|
int i = 0;
|
||||||
|
|
||||||
|
while (i < a1.size()) {
|
||||||
|
if (uchar(a1.at(i)) < uchar(a2.at(i)))
|
||||||
|
return true;
|
||||||
|
if (uchar(a1.at(i)) > uchar(a2.at(i)))
|
||||||
|
return false;
|
||||||
|
i++;
|
||||||
|
}
|
||||||
|
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
@ -29,7 +29,9 @@ along with this program. If not, see <http://www.gnu.org/licenses/>
|
|||||||
class DeviceManager;
|
class DeviceManager;
|
||||||
class PacketBuffer;
|
class PacketBuffer;
|
||||||
|
|
||||||
typedef QByteArray DeviceKey;
|
class DeviceKey: public QByteArray
|
||||||
|
{
|
||||||
|
};
|
||||||
|
|
||||||
class Device
|
class Device
|
||||||
{
|
{
|
||||||
@ -80,5 +82,6 @@ private: // data
|
|||||||
QHash<quint32, quint64> arpTable;
|
QHash<quint32, quint64> arpTable;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
bool operator<(const DeviceKey &a1, const DeviceKey &a2);
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
@ -25,6 +25,7 @@ along with this program. If not, see <http://www.gnu.org/licenses/>
|
|||||||
|
|
||||||
#include "../common/emulproto.pb.h"
|
#include "../common/emulproto.pb.h"
|
||||||
|
|
||||||
|
#include <QMap>
|
||||||
#include <qendian.h>
|
#include <qendian.h>
|
||||||
|
|
||||||
#define __STDC_FORMAT_MACROS
|
#define __STDC_FORMAT_MACROS
|
||||||
@ -138,7 +139,16 @@ int DeviceManager::deviceCount()
|
|||||||
void DeviceManager::getDeviceList(
|
void DeviceManager::getDeviceList(
|
||||||
OstProto::PortDeviceList *deviceList)
|
OstProto::PortDeviceList *deviceList)
|
||||||
{
|
{
|
||||||
|
// We want to return a sorted deviceList. However, deviceList_
|
||||||
|
// is a QHash (unsorted) instead of a QMap (sorted) because
|
||||||
|
// QHash is faster. So here we use a temporary QMap to sort the
|
||||||
|
// list that will be returned
|
||||||
|
QMap<DeviceKey, Device*> list;
|
||||||
foreach(Device *device, deviceList_) {
|
foreach(Device *device, deviceList_) {
|
||||||
|
list.insert(device->key(), device);
|
||||||
|
}
|
||||||
|
|
||||||
|
foreach(Device *device, list) {
|
||||||
OstEmul::Device *dev =
|
OstEmul::Device *dev =
|
||||||
deviceList->AddExtension(OstEmul::port_device);
|
deviceList->AddExtension(OstEmul::port_device);
|
||||||
device->getConfig(dev);
|
device->getConfig(dev);
|
||||||
|
Loading…
Reference in New Issue
Block a user