[OpenDocString] kdeconnect-kde (cpp)
loopbackdevicelink.cpp
LoopbackDeviceLink::LoopbackDeviceLink(const QString &deviceId, LoopbackLinkProvider *provider)
    : DeviceLink(deviceId, provider)
{
}
This creates a device link object in the loopback device list. The provider is used to manage the loopback link information for the device based on its internal state. By returning a pointer to a LoopbackLinkProvider object, this method allows the caller to manage the loopback link information for the device based on its internal state. By returning a pointer to a LoopbackLinkProvider object, this method allows the caller to manage the loopback link information, such as the current device id and provider for the device based on its internal state.
QString LoopbackDeviceLink::name()
{
    return QStringLiteral("LoopbackLink");
}
Returns the name of the loopback device link.
bool LoopbackDeviceLink::sendPacket(NetworkPacket &input)
{
    NetworkPacket output((QString()));
    NetworkPacket::unserialize(input.serialize(), &output);

    // LoopbackDeviceLink does not need deviceTransferInfo
    if (input.hasPayload()) {
        bool b = input.payload()->open(QIODevice::ReadOnly);
        Q_ASSERT(b);
        output.setPayload(input.payload(), input.payloadSize());
    }

    Q_EMIT receivedPacket(output);

    return true;
}
This sends a network packet to the loopback device link. It creates a new network packet from the input object, and unserializes the packet, and sets the payload on the output object. It returns true on the first successful attempt. If the payload is not possible, the function creates a read - only stream and opens it using the read-only mode.