Refactor: Moved devicelinks and linkproviders to backends
This commit is contained in:
parent
e1c749e33d
commit
91949acaa5
19 changed files with 73 additions and 46 deletions
|
@ -4,19 +4,19 @@ find_package (QJSON REQUIRED)
|
||||||
find_package (QCA2 REQUIRED)
|
find_package (QCA2 REQUIRED)
|
||||||
|
|
||||||
include_directories(
|
include_directories(
|
||||||
|
${KDE4_KIO_LIBS}
|
||||||
${QJSON_INCLUDE_DIR}
|
${QJSON_INCLUDE_DIR}
|
||||||
${QCA2_INCLUDE_DIR}
|
${QCA2_INCLUDE_DIR}
|
||||||
)
|
)
|
||||||
|
|
||||||
|
add_subdirectory(backends/lan)
|
||||||
|
add_subdirectory(backends/loopback)
|
||||||
|
|
||||||
set(kded_kdeconnect_SRCS
|
set(kded_kdeconnect_SRCS
|
||||||
|
${kded_kdeconnect_SRCS}
|
||||||
|
|
||||||
linkproviders/linkprovider.cpp
|
backends/linkprovider.cpp
|
||||||
linkproviders/loopbacklinkprovider.cpp
|
backends/devicelink.cpp
|
||||||
linkproviders/lanlinkprovider.cpp
|
|
||||||
|
|
||||||
devicelinks/devicelink.cpp
|
|
||||||
devicelinks/loopbackdevicelink.cpp
|
|
||||||
devicelinks/landevicelink.cpp
|
|
||||||
|
|
||||||
plugins/kdeconnectplugin.cpp
|
plugins/kdeconnectplugin.cpp
|
||||||
plugins/pluginloader.cpp
|
plugins/pluginloader.cpp
|
||||||
|
@ -31,6 +31,7 @@ kde4_add_plugin(kded_kdeconnect ${kded_kdeconnect_SRCS})
|
||||||
target_link_libraries(kded_kdeconnect
|
target_link_libraries(kded_kdeconnect
|
||||||
${KDE4_KDECORE_LIBS}
|
${KDE4_KDECORE_LIBS}
|
||||||
${KDE4_KDEUI_LIBS}
|
${KDE4_KDEUI_LIBS}
|
||||||
|
${KDE4_KIO_LIBS}
|
||||||
${QT_QTNETWORK_LIBRARY}
|
${QT_QTNETWORK_LIBRARY}
|
||||||
${QJSON_LIBRARIES}
|
${QJSON_LIBRARIES}
|
||||||
${QCA2_LIBRARIES}
|
${QCA2_LIBRARIES}
|
||||||
|
|
|
@ -19,7 +19,7 @@
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#include "devicelink.h"
|
#include "devicelink.h"
|
||||||
#include "linkproviders/linkprovider.h"
|
#include "linkprovider.h"
|
||||||
|
|
||||||
DeviceLink::DeviceLink(const QString& deviceId, LinkProvider* parent)
|
DeviceLink::DeviceLink(const QString& deviceId, LinkProvider* parent)
|
||||||
: QObject(parent)
|
: QObject(parent)
|
||||||
|
@ -28,3 +28,4 @@ DeviceLink::DeviceLink(const QString& deviceId, LinkProvider* parent)
|
||||||
{
|
{
|
||||||
//gcc complains if we don't add something to compile on a class with virtual functions
|
//gcc complains if we don't add something to compile on a class with virtual functions
|
||||||
}
|
}
|
||||||
|
|
|
@ -23,9 +23,9 @@
|
||||||
|
|
||||||
#include <QObject>
|
#include <QObject>
|
||||||
|
|
||||||
|
#include "../networkpackage.h"
|
||||||
|
|
||||||
class NetworkPackage;
|
class NetworkPackage;
|
||||||
class Device;
|
|
||||||
class LinkProvider;
|
class LinkProvider;
|
||||||
|
|
||||||
class DeviceLink
|
class DeviceLink
|
10
kded/backends/lan/CMakeLists.txt
Normal file
10
kded/backends/lan/CMakeLists.txt
Normal file
|
@ -0,0 +1,10 @@
|
||||||
|
|
||||||
|
set(kded_kdeconnect_SRCS
|
||||||
|
${kded_kdeconnect_SRCS}
|
||||||
|
|
||||||
|
backends/lan/lanlinkprovider.cpp
|
||||||
|
backends/lan/landevicelink.cpp
|
||||||
|
#landevicelinktransfer.cpp
|
||||||
|
|
||||||
|
PARENT_SCOPE
|
||||||
|
)
|
|
@ -24,8 +24,7 @@
|
||||||
#include <netinet/in.h>
|
#include <netinet/in.h>
|
||||||
#include <netinet/tcp.h>
|
#include <netinet/tcp.h>
|
||||||
|
|
||||||
#include "linkproviders/linkprovider.h"
|
#include "../linkprovider.h"
|
||||||
#include "networkpackage.h"
|
|
||||||
|
|
||||||
LanDeviceLink::LanDeviceLink(const QString& d, LinkProvider* a, QTcpSocket* socket)
|
LanDeviceLink::LanDeviceLink(const QString& d, LinkProvider* a, QTcpSocket* socket)
|
||||||
: DeviceLink(d, a)
|
: DeviceLink(d, a)
|
||||||
|
@ -59,7 +58,7 @@ bool LanDeviceLink::sendPackage(const NetworkPackage& np)
|
||||||
|
|
||||||
void LanDeviceLink::dataReceived()
|
void LanDeviceLink::dataReceived()
|
||||||
{
|
{
|
||||||
qDebug() << "LanDeviceLink dataReceived";
|
//qDebug() << "LanDeviceLink dataReceived";
|
||||||
|
|
||||||
QByteArray data = mSocket->readAll();
|
QByteArray data = mSocket->readAll();
|
||||||
QList<QByteArray> packages = data.split('\n');
|
QList<QByteArray> packages = data.split('\n');
|
|
@ -23,11 +23,10 @@
|
||||||
|
|
||||||
#include <QObject>
|
#include <QObject>
|
||||||
#include <QString>
|
#include <QString>
|
||||||
#include <qthread.h>
|
|
||||||
|
|
||||||
#include "devicelink.h"
|
|
||||||
#include <QTcpSocket>
|
#include <QTcpSocket>
|
||||||
|
|
||||||
|
#include "../devicelink.h"
|
||||||
|
|
||||||
class AvahiTcpLinkProvider;
|
class AvahiTcpLinkProvider;
|
||||||
|
|
||||||
class LanDeviceLink
|
class LanDeviceLink
|
|
@ -24,8 +24,7 @@
|
||||||
#include <QTcpServer>
|
#include <QTcpServer>
|
||||||
#include <QUdpSocket>
|
#include <QUdpSocket>
|
||||||
|
|
||||||
#include "devicelinks/landevicelink.h"
|
#include "landevicelink.h"
|
||||||
#include "networkpackage.h"
|
|
||||||
|
|
||||||
LanLinkProvider::LanLinkProvider()
|
LanLinkProvider::LanLinkProvider()
|
||||||
{
|
{
|
||||||
|
@ -57,7 +56,8 @@ void LanLinkProvider::onStop()
|
||||||
//I'm in a new network, let's be polite and introduce myself
|
//I'm in a new network, let's be polite and introduce myself
|
||||||
void LanLinkProvider::onNetworkChange(QNetworkSession::State state)
|
void LanLinkProvider::onNetworkChange(QNetworkSession::State state)
|
||||||
{
|
{
|
||||||
qDebug() << "onNetworkChange" << state;
|
Q_UNUSED(state);
|
||||||
|
//qDebug() << "onNetworkChange" << state;
|
||||||
NetworkPackage np("");
|
NetworkPackage np("");
|
||||||
NetworkPackage::createIdentityPackage(&np);
|
NetworkPackage::createIdentityPackage(&np);
|
||||||
np.set("tcpPort",tcpPort);
|
np.set("tcpPort",tcpPort);
|
||||||
|
@ -84,13 +84,13 @@ void LanLinkProvider::newUdpConnection()
|
||||||
NetworkPackage::createIdentityPackage(&np2);
|
NetworkPackage::createIdentityPackage(&np2);
|
||||||
|
|
||||||
if (np->get<QString>("deviceId") == np2.get<QString>("deviceId")) {
|
if (np->get<QString>("deviceId") == np2.get<QString>("deviceId")) {
|
||||||
qDebug() << "Ignoring my own broadcast";
|
//qDebug() << "Ignoring my own broadcast";
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
int tcpPort = np->get<int>("tcpPort",port);
|
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);
|
QTcpSocket* socket = new QTcpSocket(this);
|
||||||
receivedIdentityPackages[socket].np = np;
|
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)
|
//TODO: Use reverse connection too to preffer connecting a unstable device (a phone) to a stable device (a computer)
|
||||||
if (success) {
|
if (success) {
|
||||||
|
|
||||||
qDebug() << "Handshaking done (i'm the existing device)";
|
//qDebug() << "Handshaking done (i'm the existing device)";
|
||||||
|
|
||||||
connect(dl, SIGNAL(destroyed(QObject*)),
|
connect(dl, SIGNAL(destroyed(QObject*)),
|
||||||
this, SLOT(deviceLinkDestroyed(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)
|
//I'm the new device and this is the answer to my UDP introduction (no data received yet)
|
||||||
void LanLinkProvider::newConnection()
|
void LanLinkProvider::newConnection()
|
||||||
{
|
{
|
||||||
qDebug() << "LanLinkProvider newConnection";
|
//qDebug() << "LanLinkProvider newConnection";
|
||||||
|
|
||||||
QTcpSocket* socket = mTcpServer->nextPendingConnection();
|
QTcpSocket* socket = mTcpServer->nextPendingConnection();
|
||||||
socket->setSocketOption(QAbstractSocket::KeepAliveOption, 1);
|
socket->setSocketOption(QAbstractSocket::KeepAliveOption, 1);
|
||||||
|
@ -203,7 +203,7 @@ void LanLinkProvider::dataReceived()
|
||||||
|
|
||||||
QByteArray data = socket->readLine();
|
QByteArray data = socket->readLine();
|
||||||
|
|
||||||
qDebug() << "LanLinkProvider received reply:" << data;
|
//qDebug() << "LanLinkProvider received reply:" << data;
|
||||||
|
|
||||||
NetworkPackage np("");
|
NetworkPackage np("");
|
||||||
bool success = NetworkPackage::unserialize(data,&np);
|
bool success = NetworkPackage::unserialize(data,&np);
|
||||||
|
@ -213,7 +213,7 @@ void LanLinkProvider::dataReceived()
|
||||||
const QString& id = np.get<QString>("deviceId");
|
const QString& id = np.get<QString>("deviceId");
|
||||||
LanDeviceLink* dl = new LanDeviceLink(id, this, socket);
|
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*)),
|
connect(dl, SIGNAL(destroyed(QObject*)),
|
||||||
this, SLOT(deviceLinkDestroyed(QObject*)));
|
this, SLOT(deviceLinkDestroyed(QObject*)));
|
||||||
|
@ -241,7 +241,7 @@ void LanLinkProvider::dataReceived()
|
||||||
|
|
||||||
void LanLinkProvider::deviceLinkDestroyed(QObject* uncastedDeviceLink)
|
void LanLinkProvider::deviceLinkDestroyed(QObject* uncastedDeviceLink)
|
||||||
{
|
{
|
||||||
qDebug() << "deviceLinkDestroyed";
|
//qDebug() << "deviceLinkDestroyed";
|
||||||
|
|
||||||
DeviceLink* deviceLink = (DeviceLink*)uncastedDeviceLink;
|
DeviceLink* deviceLink = (DeviceLink*)uncastedDeviceLink;
|
||||||
const QString& id = deviceLink->deviceId();
|
const QString& id = deviceLink->deviceId();
|
|
@ -25,7 +25,7 @@
|
||||||
#include <QTcpServer>
|
#include <QTcpServer>
|
||||||
#include <QUdpSocket>
|
#include <QUdpSocket>
|
||||||
|
|
||||||
#include "linkprovider.h"
|
#include "../linkprovider.h"
|
||||||
#include "netaddress.h"
|
#include "netaddress.h"
|
||||||
|
|
||||||
class LanLinkProvider
|
class LanLinkProvider
|
|
@ -24,3 +24,4 @@ LinkProvider::LinkProvider()
|
||||||
{
|
{
|
||||||
//gcc complains if we don't add something to compile on a class with virtual functions
|
//gcc complains if we don't add something to compile on a class with virtual functions
|
||||||
}
|
}
|
||||||
|
|
9
kded/backends/loopback/CMakeLists.txt
Normal file
9
kded/backends/loopback/CMakeLists.txt
Normal file
|
@ -0,0 +1,9 @@
|
||||||
|
|
||||||
|
set(kded_kdeconnect_SRCS
|
||||||
|
${kded_kdeconnect_SRCS}
|
||||||
|
|
||||||
|
backends/loopback/loopbacklinkprovider.cpp
|
||||||
|
backends/loopback/loopbackdevicelink.cpp
|
||||||
|
|
||||||
|
PARENT_SCOPE
|
||||||
|
)
|
|
@ -20,7 +20,7 @@
|
||||||
|
|
||||||
#include "loopbackdevicelink.h"
|
#include "loopbackdevicelink.h"
|
||||||
|
|
||||||
#include "linkproviders/loopbacklinkprovider.h"
|
#include "loopbacklinkprovider.h"
|
||||||
|
|
||||||
LoopbackDeviceLink::LoopbackDeviceLink(const QString& deviceId, LoopbackLinkProvider* provider)
|
LoopbackDeviceLink::LoopbackDeviceLink(const QString& deviceId, LoopbackLinkProvider* provider)
|
||||||
: DeviceLink(deviceId, 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("");
|
qDebug() << "loopbacksendpackage";
|
||||||
NetworkPackage::unserialize(toSend.serialize(), &toReceive);
|
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;
|
return true;
|
||||||
}
|
}
|
|
@ -21,7 +21,7 @@
|
||||||
#ifndef LOOPBACKDEVICELINK_H
|
#ifndef LOOPBACKDEVICELINK_H
|
||||||
#define LOOPBACKDEVICELINK_H
|
#define LOOPBACKDEVICELINK_H
|
||||||
|
|
||||||
#include "devicelink.h"
|
#include "../devicelink.h"
|
||||||
|
|
||||||
class LoopbackLinkProvider;
|
class LoopbackLinkProvider;
|
||||||
|
|
|
@ -21,9 +21,8 @@
|
||||||
#ifndef LOOPBACKLINKPROVIDER_H
|
#ifndef LOOPBACKLINKPROVIDER_H
|
||||||
#define LOOPBACKLINKPROVIDER_H
|
#define LOOPBACKLINKPROVIDER_H
|
||||||
|
|
||||||
#include "linkprovider.h"
|
#include "../linkprovider.h"
|
||||||
#include "networkpackage.h"
|
#include "loopbackdevicelink.h"
|
||||||
#include "devicelinks/loopbackdevicelink.h"
|
|
||||||
|
|
||||||
class LoopbackLinkProvider
|
class LoopbackLinkProvider
|
||||||
: public LinkProvider
|
: public LinkProvider
|
|
@ -22,8 +22,8 @@
|
||||||
|
|
||||||
#include "networkpackage.h"
|
#include "networkpackage.h"
|
||||||
|
|
||||||
#include "linkproviders/lanlinkprovider.h"
|
#include "backends/lan/lanlinkprovider.h"
|
||||||
#include "linkproviders/loopbacklinkprovider.h"
|
#include "backends/loopback/loopbacklinkprovider.h"
|
||||||
|
|
||||||
#include <QUuid>
|
#include <QUuid>
|
||||||
#include <QDBusConnection>
|
#include <QDBusConnection>
|
||||||
|
|
|
@ -31,8 +31,8 @@
|
||||||
|
|
||||||
#include "device.h"
|
#include "device.h"
|
||||||
#include "networkpackage.h"
|
#include "networkpackage.h"
|
||||||
#include "devicelinks/devicelink.h"
|
#include "backends/devicelink.h"
|
||||||
#include "linkproviders/linkprovider.h"
|
#include "backends/linkprovider.h"
|
||||||
|
|
||||||
class Daemon
|
class Daemon
|
||||||
: public KDEDModule
|
: public KDEDModule
|
||||||
|
|
|
@ -14,8 +14,8 @@
|
||||||
|
|
||||||
#include "plugins/kdeconnectplugin.h"
|
#include "plugins/kdeconnectplugin.h"
|
||||||
#include "plugins/pluginloader.h"
|
#include "plugins/pluginloader.h"
|
||||||
#include "devicelinks/devicelink.h"
|
#include "backends/devicelink.h"
|
||||||
#include "linkproviders/linkprovider.h"
|
#include "backends/linkprovider.h"
|
||||||
#include "networkpackage.h"
|
#include "networkpackage.h"
|
||||||
|
|
||||||
Device::Device(const QString& id)
|
Device::Device(const QString& id)
|
||||||
|
|
Loading…
Reference in a new issue