[OpenDocString] kdeconnect-kde (cpp)
loopbacklinkprovider.cpp
LoopbackLinkProvider::LoopbackLinkProvider()
    : identityPacket(PACKET_TYPE_IDENTITY)
{
    NetworkPacket::createIdentityPacket(&identityPacket);
}
This constructor builds an identity packet of the given type.
LoopbackLinkProvider::~LoopbackLinkProvider()
{
}
This implements the loopback link provider interface.
void LoopbackLinkProvider::onNetworkChange()
{
    LoopbackDeviceLink *newLoopbackDeviceLink = new LoopbackDeviceLink(QStringLiteral("loopback"), this);
    Q_EMIT onConnectionReceived(identityPacket, newLoopbackDeviceLink);

    if (loopbackDeviceLink) {
        delete loopbackDeviceLink;
    }

    loopbackDeviceLink = newLoopbackDeviceLink;
}
This creates a loopback device link object and marks it for deletion. It removes the loopback device link object from the list of links.
void LoopbackLinkProvider::onStart()
{
    onNetworkChange();
}
This code is called when the LoopbackLinkProvider is starting. It is responsible for ensuring that the network state is updated.
void LoopbackLinkProvider::onStop()
{
    if (loopbackDeviceLink) {
        delete loopbackDeviceLink;
    }
}
This removes the loopback device link object upon stop.