Refactor: Moved devicelinks and linkproviders to backends

This commit is contained in:
Albert Vaca 2013-09-09 18:35:56 +02:00
parent e1c749e33d
commit 91949acaa5
19 changed files with 73 additions and 46 deletions

View file

@ -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}

View file

@ -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
}
}

View file

@ -23,9 +23,9 @@
#include <QObject>
#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

View file

@ -0,0 +1,10 @@
set(kded_kdeconnect_SRCS
${kded_kdeconnect_SRCS}
backends/lan/lanlinkprovider.cpp
backends/lan/landevicelink.cpp
#landevicelinktransfer.cpp
PARENT_SCOPE
)

View file

@ -24,8 +24,7 @@
#include <netinet/in.h>
#include <netinet/tcp.h>
#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<QByteArray> packages = data.split('\n');

View file

@ -23,11 +23,10 @@
#include <QObject>
#include <QString>
#include <qthread.h>
#include "devicelink.h"
#include <QTcpSocket>
#include "../devicelink.h"
class AvahiTcpLinkProvider;
class LanDeviceLink

View file

@ -24,8 +24,7 @@
#include <QTcpServer>
#include <QUdpSocket>
#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<QString>("deviceId") == np2.get<QString>("deviceId")) {
qDebug() << "Ignoring my own broadcast";
//qDebug() << "Ignoring my own broadcast";
return;
}
int tcpPort = np->get<int>("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<QString>("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();

View file

@ -25,7 +25,7 @@
#include <QTcpServer>
#include <QUdpSocket>
#include "linkprovider.h"
#include "../linkprovider.h"
#include "netaddress.h"
class LanLinkProvider

View file

@ -23,4 +23,5 @@
LinkProvider::LinkProvider()
{
//gcc complains if we don't add something to compile on a class with virtual functions
}
}

View file

@ -0,0 +1,9 @@
set(kded_kdeconnect_SRCS
${kded_kdeconnect_SRCS}
backends/loopback/loopbacklinkprovider.cpp
backends/loopback/loopbackdevicelink.cpp
PARENT_SCOPE
)

View file

@ -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;
}

View file

@ -21,7 +21,7 @@
#ifndef LOOPBACKDEVICELINK_H
#define LOOPBACKDEVICELINK_H
#include "devicelink.h"
#include "../devicelink.h"
class LoopbackLinkProvider;

View file

@ -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

View file

@ -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 <QUuid>
#include <QDBusConnection>
@ -62,7 +62,7 @@ Daemon::Daemon(QObject *parent, const QList<QVariant>&)
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

View file

@ -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

View file

@ -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)