[OpenDocString] kdeconnect-kde (cpp)
testdevice.cpp
TestDevice::TestDevice(QObject *parent, const QString &id)
    : Device(parent, id)
    , sentPackets(0)
    , lastPacket(nullptr)
{
}
This constructs a device object and its sent packets and last packet.
TestDevice::~TestDevice()
{
    delete lastPacket;
}
This removes the last packet object upon destruction.
bool TestDevice::isReachable() const
{
    return true;
}
This implements checking if the device is reachable.
bool TestDevice::sendPacket(NetworkPacket &np)
{
    ++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++)
        lastPacket->set(iter.key(), iter.value());
    lastPacket->setPayload(np.payload(), np.payloadSize());
    return true;
}
This sends a network packet, and returns true on the first successful send. It creates a new last packet, sets all entries of the given network packet to its internal state and sets the payload of the last packet to the payload size.