kdeconnect-kde/tests/testdevice.cpp

39 lines
992 B
C++
Raw Permalink Normal View History

2019-06-05 03:42:06 +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
*
* 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"
TestDevice::TestDevice(QObject *parent, const QString &id)
: Device(parent, id)
2019-06-05 03:42:06 +01:00
, sentPackets(0)
, lastPacket(nullptr)
{
}
2019-06-05 03:42:06 +01:00
TestDevice::~TestDevice()
{
delete lastPacket;
}
bool TestDevice::isReachable() const
{
return true;
}
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);
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;
}