File indexing completed on 2024-04-14 04:51:53

0001 /**
0002  * SPDX-FileCopyrightText: 2015 Holger Kaelberer <holger.k@elberer.de>
0003  * SPDX-FileCopyrightText: 2019 Simon Redman <simon@ergotech.com>
0004  *
0005  * SPDX-License-Identifier: GPL-2.0-only OR GPL-3.0-only OR LicenseRef-KDE-Accepted-GPL
0006  */
0007 
0008 #include "testdevice.h"
0009 
0010 TestDevice::TestDevice(QObject *parent, const QString &id)
0011     : Device(parent, id)
0012     , sentPackets(0)
0013     , lastPacket(nullptr)
0014 {
0015 }
0016 
0017 TestDevice::~TestDevice()
0018 {
0019     delete lastPacket;
0020 }
0021 
0022 bool TestDevice::isReachable() const
0023 {
0024     return true;
0025 }
0026 
0027 bool TestDevice::sendPacket(NetworkPacket &np)
0028 {
0029     ++sentPackets;
0030     // copy packet manually to allow for inspection (can't use copy-constructor)
0031     deleteLastPacket();
0032     lastPacket = new NetworkPacket(np.type());
0033     Q_ASSERT(lastPacket);
0034     for (QVariantMap::ConstIterator iter = np.body().constBegin(); iter != np.body().constEnd(); iter++)
0035         lastPacket->set(iter.key(), iter.value());
0036     lastPacket->setPayload(np.payload(), np.payloadSize());
0037     return true;
0038 }
0039 
0040 #include "moc_testdevice.cpp"