From 91949acaa57ad8415986768935e398fb499d67a0 Mon Sep 17 00:00:00 2001 From: Albert Vaca Date: Mon, 9 Sep 2013 18:35:56 +0200 Subject: [PATCH] Refactor: Moved devicelinks and linkproviders to backends --- kded/CMakeLists.txt | 15 +++++++------- kded/{devicelinks => backends}/devicelink.cpp | 5 +++-- kded/{devicelinks => backends}/devicelink.h | 6 +++--- kded/backends/lan/CMakeLists.txt | 10 ++++++++++ .../lan}/landevicelink.cpp | 5 ++--- .../lan}/landevicelink.h | 5 ++--- .../lan}/lanlinkprovider.cpp | 20 +++++++++---------- .../lan}/lanlinkprovider.h | 2 +- kded/{ => backends/lan}/netaddress.h | 0 .../linkprovider.cpp | 3 ++- .../linkprovider.h | 0 kded/backends/loopback/CMakeLists.txt | 9 +++++++++ .../loopback}/loopbackdevicelink.cpp | 18 ++++++++++++----- .../loopback}/loopbackdevicelink.h | 2 +- .../loopback}/loopbacklinkprovider.cpp | 0 .../loopback}/loopbacklinkprovider.h | 5 ++--- kded/daemon.cpp | 6 +++--- kded/daemon.h | 4 ++-- kded/device.cpp | 4 ++-- 19 files changed, 73 insertions(+), 46 deletions(-) rename kded/{devicelinks => backends}/devicelink.cpp (96%) rename kded/{devicelinks => backends}/devicelink.h (97%) create mode 100644 kded/backends/lan/CMakeLists.txt rename kded/{devicelinks => backends/lan}/landevicelink.cpp (95%) rename kded/{devicelinks => backends/lan}/landevicelink.h (96%) rename kded/{linkproviders => backends/lan}/lanlinkprovider.cpp (93%) rename kded/{linkproviders => backends/lan}/lanlinkprovider.h (98%) rename kded/{ => backends/lan}/netaddress.h (100%) rename kded/{linkproviders => backends}/linkprovider.cpp (99%) rename kded/{linkproviders => backends}/linkprovider.h (100%) create mode 100644 kded/backends/loopback/CMakeLists.txt rename kded/{devicelinks => backends/loopback}/loopbackdevicelink.cpp (69%) rename kded/{devicelinks => backends/loopback}/loopbackdevicelink.h (97%) rename kded/{linkproviders => backends/loopback}/loopbacklinkprovider.cpp (100%) rename kded/{linkproviders => backends/loopback}/loopbacklinkprovider.h (93%) diff --git a/kded/CMakeLists.txt b/kded/CMakeLists.txt index c2926c58e..c6ecb2625 100644 --- a/kded/CMakeLists.txt +++ b/kded/CMakeLists.txt @@ -4,19 +4,19 @@ find_package (QJSON REQUIRED) find_package (QCA2 REQUIRED) include_directories( + ${KDE4_KIO_LIBS} ${QJSON_INCLUDE_DIR} ${QCA2_INCLUDE_DIR} ) +add_subdirectory(backends/lan) +add_subdirectory(backends/loopback) + set(kded_kdeconnect_SRCS + ${kded_kdeconnect_SRCS} - linkproviders/linkprovider.cpp - linkproviders/loopbacklinkprovider.cpp - linkproviders/lanlinkprovider.cpp - - devicelinks/devicelink.cpp - devicelinks/loopbackdevicelink.cpp - devicelinks/landevicelink.cpp + backends/linkprovider.cpp + backends/devicelink.cpp plugins/kdeconnectplugin.cpp plugins/pluginloader.cpp @@ -31,6 +31,7 @@ kde4_add_plugin(kded_kdeconnect ${kded_kdeconnect_SRCS}) target_link_libraries(kded_kdeconnect ${KDE4_KDECORE_LIBS} ${KDE4_KDEUI_LIBS} + ${KDE4_KIO_LIBS} ${QT_QTNETWORK_LIBRARY} ${QJSON_LIBRARIES} ${QCA2_LIBRARIES} diff --git a/kded/devicelinks/devicelink.cpp b/kded/backends/devicelink.cpp similarity index 96% rename from kded/devicelinks/devicelink.cpp rename to kded/backends/devicelink.cpp index c7a9d04a1..aaeb28926 100644 --- a/kded/devicelinks/devicelink.cpp +++ b/kded/backends/devicelink.cpp @@ -19,7 +19,7 @@ */ #include "devicelink.h" -#include "linkproviders/linkprovider.h" +#include "linkprovider.h" DeviceLink::DeviceLink(const QString& deviceId, LinkProvider* parent) : QObject(parent) @@ -27,4 +27,5 @@ DeviceLink::DeviceLink(const QString& deviceId, LinkProvider* parent) , mLinkProvider(parent) { //gcc complains if we don't add something to compile on a class with virtual functions -} \ No newline at end of file +} + diff --git a/kded/devicelinks/devicelink.h b/kded/backends/devicelink.h similarity index 97% rename from kded/devicelinks/devicelink.h rename to kded/backends/devicelink.h index 60cafa6f8..fb4571479 100644 --- a/kded/devicelinks/devicelink.h +++ b/kded/backends/devicelink.h @@ -23,9 +23,9 @@ #include +#include "../networkpackage.h" class NetworkPackage; -class Device; class LinkProvider; class DeviceLink @@ -38,7 +38,7 @@ public: const QString& deviceId() { return mDeviceId; } LinkProvider* provider() { return mLinkProvider; } - + virtual bool sendPackage(const NetworkPackage& np) = 0; Q_SIGNALS: @@ -47,7 +47,7 @@ Q_SIGNALS: private: QString mDeviceId; LinkProvider* mLinkProvider; - + }; #endif // DEVICELINK_H diff --git a/kded/backends/lan/CMakeLists.txt b/kded/backends/lan/CMakeLists.txt new file mode 100644 index 000000000..d30d8a069 --- /dev/null +++ b/kded/backends/lan/CMakeLists.txt @@ -0,0 +1,10 @@ + +set(kded_kdeconnect_SRCS + ${kded_kdeconnect_SRCS} + + backends/lan/lanlinkprovider.cpp + backends/lan/landevicelink.cpp + #landevicelinktransfer.cpp + + PARENT_SCOPE +) \ No newline at end of file diff --git a/kded/devicelinks/landevicelink.cpp b/kded/backends/lan/landevicelink.cpp similarity index 95% rename from kded/devicelinks/landevicelink.cpp rename to kded/backends/lan/landevicelink.cpp index 38fa110dc..4993b1f9a 100644 --- a/kded/devicelinks/landevicelink.cpp +++ b/kded/backends/lan/landevicelink.cpp @@ -24,8 +24,7 @@ #include #include -#include "linkproviders/linkprovider.h" -#include "networkpackage.h" +#include "../linkprovider.h" LanDeviceLink::LanDeviceLink(const QString& d, LinkProvider* a, QTcpSocket* socket) : DeviceLink(d, a) @@ -59,7 +58,7 @@ bool LanDeviceLink::sendPackage(const NetworkPackage& np) void LanDeviceLink::dataReceived() { - qDebug() << "LanDeviceLink dataReceived"; + //qDebug() << "LanDeviceLink dataReceived"; QByteArray data = mSocket->readAll(); QList packages = data.split('\n'); diff --git a/kded/devicelinks/landevicelink.h b/kded/backends/lan/landevicelink.h similarity index 96% rename from kded/devicelinks/landevicelink.h rename to kded/backends/lan/landevicelink.h index 82a73bcf7..9a2148bd8 100644 --- a/kded/devicelinks/landevicelink.h +++ b/kded/backends/lan/landevicelink.h @@ -23,11 +23,10 @@ #include #include -#include - -#include "devicelink.h" #include +#include "../devicelink.h" + class AvahiTcpLinkProvider; class LanDeviceLink diff --git a/kded/linkproviders/lanlinkprovider.cpp b/kded/backends/lan/lanlinkprovider.cpp similarity index 93% rename from kded/linkproviders/lanlinkprovider.cpp rename to kded/backends/lan/lanlinkprovider.cpp index 885605e01..9b84613cb 100644 --- a/kded/linkproviders/lanlinkprovider.cpp +++ b/kded/backends/lan/lanlinkprovider.cpp @@ -24,8 +24,7 @@ #include #include -#include "devicelinks/landevicelink.h" -#include "networkpackage.h" +#include "landevicelink.h" LanLinkProvider::LanLinkProvider() { @@ -57,7 +56,8 @@ void LanLinkProvider::onStop() //I'm in a new network, let's be polite and introduce myself void LanLinkProvider::onNetworkChange(QNetworkSession::State state) { - qDebug() << "onNetworkChange" << state; + Q_UNUSED(state); + //qDebug() << "onNetworkChange" << state; NetworkPackage np(""); NetworkPackage::createIdentityPackage(&np); np.set("tcpPort",tcpPort); @@ -84,13 +84,13 @@ void LanLinkProvider::newUdpConnection() NetworkPackage::createIdentityPackage(&np2); if (np->get("deviceId") == np2.get("deviceId")) { - qDebug() << "Ignoring my own broadcast"; + //qDebug() << "Ignoring my own broadcast"; return; } int tcpPort = np->get("tcpPort",port); - qDebug() << "Received Udp presentation from" << sender << "asking for a tcp connection on port " << tcpPort; + //qDebug() << "Received Udp presentation from" << sender << "asking for a tcp connection on port " << tcpPort; QTcpSocket* socket = new QTcpSocket(this); receivedIdentityPackages[socket].np = np; @@ -146,7 +146,7 @@ void LanLinkProvider::connected() //TODO: Use reverse connection too to preffer connecting a unstable device (a phone) to a stable device (a computer) if (success) { - qDebug() << "Handshaking done (i'm the existing device)"; + //qDebug() << "Handshaking done (i'm the existing device)"; connect(dl, SIGNAL(destroyed(QObject*)), this, SLOT(deviceLinkDestroyed(QObject*))); @@ -180,7 +180,7 @@ void LanLinkProvider::connected() //I'm the new device and this is the answer to my UDP introduction (no data received yet) void LanLinkProvider::newConnection() { - qDebug() << "LanLinkProvider newConnection"; + //qDebug() << "LanLinkProvider newConnection"; QTcpSocket* socket = mTcpServer->nextPendingConnection(); socket->setSocketOption(QAbstractSocket::KeepAliveOption, 1); @@ -203,7 +203,7 @@ void LanLinkProvider::dataReceived() QByteArray data = socket->readLine(); - qDebug() << "LanLinkProvider received reply:" << data; + //qDebug() << "LanLinkProvider received reply:" << data; NetworkPackage np(""); bool success = NetworkPackage::unserialize(data,&np); @@ -213,7 +213,7 @@ void LanLinkProvider::dataReceived() const QString& id = np.get("deviceId"); LanDeviceLink* dl = new LanDeviceLink(id, this, socket); - qDebug() << "Handshaking done (i'm the new device)"; + //qDebug() << "Handshaking done (i'm the new device)"; connect(dl, SIGNAL(destroyed(QObject*)), this, SLOT(deviceLinkDestroyed(QObject*))); @@ -241,7 +241,7 @@ void LanLinkProvider::dataReceived() void LanLinkProvider::deviceLinkDestroyed(QObject* uncastedDeviceLink) { - qDebug() << "deviceLinkDestroyed"; + //qDebug() << "deviceLinkDestroyed"; DeviceLink* deviceLink = (DeviceLink*)uncastedDeviceLink; const QString& id = deviceLink->deviceId(); diff --git a/kded/linkproviders/lanlinkprovider.h b/kded/backends/lan/lanlinkprovider.h similarity index 98% rename from kded/linkproviders/lanlinkprovider.h rename to kded/backends/lan/lanlinkprovider.h index ffada4914..7d7c49a1f 100644 --- a/kded/linkproviders/lanlinkprovider.h +++ b/kded/backends/lan/lanlinkprovider.h @@ -25,7 +25,7 @@ #include #include -#include "linkprovider.h" +#include "../linkprovider.h" #include "netaddress.h" class LanLinkProvider diff --git a/kded/netaddress.h b/kded/backends/lan/netaddress.h similarity index 100% rename from kded/netaddress.h rename to kded/backends/lan/netaddress.h diff --git a/kded/linkproviders/linkprovider.cpp b/kded/backends/linkprovider.cpp similarity index 99% rename from kded/linkproviders/linkprovider.cpp rename to kded/backends/linkprovider.cpp index 2ca4dbabc..1d6c0bf1c 100644 --- a/kded/linkproviders/linkprovider.cpp +++ b/kded/backends/linkprovider.cpp @@ -23,4 +23,5 @@ LinkProvider::LinkProvider() { //gcc complains if we don't add something to compile on a class with virtual functions -} \ No newline at end of file +} + diff --git a/kded/linkproviders/linkprovider.h b/kded/backends/linkprovider.h similarity index 100% rename from kded/linkproviders/linkprovider.h rename to kded/backends/linkprovider.h diff --git a/kded/backends/loopback/CMakeLists.txt b/kded/backends/loopback/CMakeLists.txt new file mode 100644 index 000000000..0fe90a7f3 --- /dev/null +++ b/kded/backends/loopback/CMakeLists.txt @@ -0,0 +1,9 @@ + +set(kded_kdeconnect_SRCS + ${kded_kdeconnect_SRCS} + + backends/loopback/loopbacklinkprovider.cpp + backends/loopback/loopbackdevicelink.cpp + + PARENT_SCOPE +) \ No newline at end of file diff --git a/kded/devicelinks/loopbackdevicelink.cpp b/kded/backends/loopback/loopbackdevicelink.cpp similarity index 69% rename from kded/devicelinks/loopbackdevicelink.cpp rename to kded/backends/loopback/loopbackdevicelink.cpp index cd19c919a..737e93cfe 100644 --- a/kded/devicelinks/loopbackdevicelink.cpp +++ b/kded/backends/loopback/loopbackdevicelink.cpp @@ -20,7 +20,7 @@ #include "loopbackdevicelink.h" -#include "linkproviders/loopbacklinkprovider.h" +#include "loopbacklinkprovider.h" LoopbackDeviceLink::LoopbackDeviceLink(const QString& deviceId, LoopbackLinkProvider* provider) : DeviceLink(deviceId, provider) @@ -28,12 +28,20 @@ LoopbackDeviceLink::LoopbackDeviceLink(const QString& deviceId, LoopbackLinkProv } -bool LoopbackDeviceLink::sendPackage(const NetworkPackage& toSend) +bool LoopbackDeviceLink::sendPackage(const NetworkPackage& input) { - NetworkPackage toReceive(""); - NetworkPackage::unserialize(toSend.serialize(), &toReceive); + qDebug() << "loopbacksendpackage"; + NetworkPackage output(""); + NetworkPackage::unserialize(input.serialize(), &output); - Q_EMIT receivedPackage(toReceive); + if (input.hasPayload()) { + //Loopback does not need payloadTransferInfo + QIODevice* device = input.payload(); + device->open(QIODevice::ReadOnly); + output.setPayload(device); + } + + Q_EMIT receivedPackage(output); return true; } diff --git a/kded/devicelinks/loopbackdevicelink.h b/kded/backends/loopback/loopbackdevicelink.h similarity index 97% rename from kded/devicelinks/loopbackdevicelink.h rename to kded/backends/loopback/loopbackdevicelink.h index 5372e347a..e0bbbe60c 100644 --- a/kded/devicelinks/loopbackdevicelink.h +++ b/kded/backends/loopback/loopbackdevicelink.h @@ -21,7 +21,7 @@ #ifndef LOOPBACKDEVICELINK_H #define LOOPBACKDEVICELINK_H -#include "devicelink.h" +#include "../devicelink.h" class LoopbackLinkProvider; diff --git a/kded/linkproviders/loopbacklinkprovider.cpp b/kded/backends/loopback/loopbacklinkprovider.cpp similarity index 100% rename from kded/linkproviders/loopbacklinkprovider.cpp rename to kded/backends/loopback/loopbacklinkprovider.cpp diff --git a/kded/linkproviders/loopbacklinkprovider.h b/kded/backends/loopback/loopbacklinkprovider.h similarity index 93% rename from kded/linkproviders/loopbacklinkprovider.h rename to kded/backends/loopback/loopbacklinkprovider.h index dd1343849..361e652a7 100644 --- a/kded/linkproviders/loopbacklinkprovider.h +++ b/kded/backends/loopback/loopbacklinkprovider.h @@ -21,9 +21,8 @@ #ifndef LOOPBACKLINKPROVIDER_H #define LOOPBACKLINKPROVIDER_H -#include "linkprovider.h" -#include "networkpackage.h" -#include "devicelinks/loopbackdevicelink.h" +#include "../linkprovider.h" +#include "loopbackdevicelink.h" class LoopbackLinkProvider : public LinkProvider diff --git a/kded/daemon.cpp b/kded/daemon.cpp index a69245d7b..82afac7b1 100644 --- a/kded/daemon.cpp +++ b/kded/daemon.cpp @@ -22,8 +22,8 @@ #include "networkpackage.h" -#include "linkproviders/lanlinkprovider.h" -#include "linkproviders/loopbacklinkprovider.h" +#include "backends/lan/lanlinkprovider.h" +#include "backends/loopback/loopbacklinkprovider.h" #include #include @@ -62,7 +62,7 @@ Daemon::Daemon(QObject *parent, const QList&) QCA::PublicKey publicKey = privateKey.toPublicKey(); config->group("myself").writeEntry("publicKey", publicKey.toPEM()); //TODO: Store key in a PEM file instead (use something like KStandardDirs::locate("appdata", "private.pem")) - + } //Debugging diff --git a/kded/daemon.h b/kded/daemon.h index 467df2e45..957557cc3 100644 --- a/kded/daemon.h +++ b/kded/daemon.h @@ -31,8 +31,8 @@ #include "device.h" #include "networkpackage.h" -#include "devicelinks/devicelink.h" -#include "linkproviders/linkprovider.h" +#include "backends/devicelink.h" +#include "backends/linkprovider.h" class Daemon : public KDEDModule diff --git a/kded/device.cpp b/kded/device.cpp index b67b3dafa..cd71bf6f1 100644 --- a/kded/device.cpp +++ b/kded/device.cpp @@ -14,8 +14,8 @@ #include "plugins/kdeconnectplugin.h" #include "plugins/pluginloader.h" -#include "devicelinks/devicelink.h" -#include "linkproviders/linkprovider.h" +#include "backends/devicelink.h" +#include "backends/linkprovider.h" #include "networkpackage.h" Device::Device(const QString& id)