2019-06-05 03:42:06 +01:00
|
|
|
/**
|
2020-08-17 10:48:10 +01:00
|
|
|
* SPDX-FileCopyrightText: 2015 Holger Kaelberer <holger.k@elberer.de>
|
|
|
|
* SPDX-FileCopyrightText: 2019 Simon Redman <simon@ergotech.com>
|
2019-06-05 03:42:06 +01:00
|
|
|
*
|
2020-08-17 10:48:10 +01:00
|
|
|
* SPDX-License-Identifier: GPL-2.0-only OR GPL-3.0-only OR LicenseRef-KDE-Accepted-GPL
|
2019-06-05 03:42:06 +01:00
|
|
|
*/
|
|
|
|
|
|
|
|
#include "testdevice.h"
|
|
|
|
|
2022-09-10 22:23:52 +01:00
|
|
|
TestDevice::TestDevice(QObject *parent, const QString &id)
|
|
|
|
: Device(parent, id)
|
2019-06-05 03:42:06 +01:00
|
|
|
, sentPackets(0)
|
|
|
|
, lastPacket(nullptr)
|
2022-09-10 22:23:52 +01:00
|
|
|
{
|
|
|
|
}
|
2019-06-05 03:42:06 +01:00
|
|
|
|
|
|
|
TestDevice::~TestDevice()
|
|
|
|
{
|
|
|
|
delete lastPacket;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool TestDevice::isReachable() const
|
|
|
|
{
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2022-09-10 22:23:52 +01:00
|
|
|
bool TestDevice::sendPacket(NetworkPacket &np)
|
2019-06-05 03:42:06 +01:00
|
|
|
{
|
|
|
|
++sentPackets;
|
|
|
|
// copy packet manually to allow for inspection (can't use copy-constructor)
|
|
|
|
deleteLastPacket();
|
|
|
|
lastPacket = new NetworkPacket(np.type());
|
|
|
|
Q_ASSERT(lastPacket);
|
2022-09-10 22:23:52 +01:00
|
|
|
for (QVariantMap::ConstIterator iter = np.body().constBegin(); iter != np.body().constEnd(); iter++)
|
2019-06-05 03:42:06 +01:00
|
|
|
lastPacket->set(iter.key(), iter.value());
|
|
|
|
lastPacket->setPayload(np.payload(), np.payloadSize());
|
|
|
|
return true;
|
|
|
|
}
|