Changeset View
Changeset View
Standalone View
Standalone View
core/backends/lan/landevicelink.cpp
Show First 20 Lines • Show All 76 Lines • ▼ Show 20 Line(s) | 64 | { | |||
---|---|---|---|---|---|
77 | return addr; | 77 | return addr; | ||
78 | } | 78 | } | ||
79 | 79 | | |||
80 | QString LanDeviceLink::name() | 80 | QString LanDeviceLink::name() | ||
81 | { | 81 | { | ||
82 | return QStringLiteral("LanLink"); // Should be same in both android and kde version | 82 | return QStringLiteral("LanLink"); // Should be same in both android and kde version | ||
83 | } | 83 | } | ||
84 | 84 | | |||
85 | bool LanDeviceLink::sendPackage(NetworkPackage& np) | 85 | bool LanDeviceLink::sendPacket(NetworkPacket& np) | ||
86 | { | 86 | { | ||
87 | if (np.hasPayload()) { | 87 | if (np.hasPayload()) { | ||
88 | np.setPayloadTransferInfo(sendPayload(np)->transferInfo()); | 88 | np.setPayloadTransferInfo(sendPayload(np)->transferInfo()); | ||
89 | } | 89 | } | ||
90 | 90 | | |||
91 | int written = m_socketLineReader->write(np.serialize()); | 91 | int written = m_socketLineReader->write(np.serialize()); | ||
92 | 92 | | |||
93 | //Actually we can't detect if a package is received or not. We keep TCP | 93 | //Actually we can't detect if a packet is received or not. We keep TCP | ||
94 | //"ESTABLISHED" connections that look legit (return true when we use them), | 94 | //"ESTABLISHED" connections that look legit (return true when we use them), | ||
95 | //but that are actually broken (until keepalive detects that they are down). | 95 | //but that are actually broken (until keepalive detects that they are down). | ||
96 | return (written != -1); | 96 | return (written != -1); | ||
97 | } | 97 | } | ||
98 | 98 | | |||
99 | UploadJob* LanDeviceLink::sendPayload(const NetworkPackage& np) | 99 | UploadJob* LanDeviceLink::sendPayload(const NetworkPacket& np) | ||
100 | { | 100 | { | ||
101 | UploadJob* job = new UploadJob(np.payload(), deviceId()); | 101 | UploadJob* job = new UploadJob(np.payload(), deviceId()); | ||
102 | job->start(); | 102 | job->start(); | ||
103 | return job; | 103 | return job; | ||
104 | } | 104 | } | ||
105 | 105 | | |||
106 | void LanDeviceLink::dataReceived() | 106 | void LanDeviceLink::dataReceived() | ||
107 | { | 107 | { | ||
108 | if (m_socketLineReader->bytesAvailable() == 0) return; | 108 | if (m_socketLineReader->bytesAvailable() == 0) return; | ||
109 | 109 | | |||
110 | const QByteArray serializedPackage = m_socketLineReader->readLine(); | 110 | const QByteArray serializedPacket = m_socketLineReader->readLine(); | ||
111 | NetworkPackage package(QString::null); | 111 | NetworkPacket packet(QString::null); | ||
112 | NetworkPackage::unserialize(serializedPackage, &package); | 112 | NetworkPacket::unserialize(serializedPacket, &packet); | ||
113 | 113 | | |||
114 | //qCDebug(KDECONNECT_CORE) << "LanDeviceLink dataReceived" << serializedPackage; | 114 | //qCDebug(KDECONNECT_CORE) << "LanDeviceLink dataReceived" << serializedPacket; | ||
115 | 115 | | |||
116 | if (package.type() == PACKAGE_TYPE_PAIR) { | 116 | if (packet.type() == PACKET_TYPE_PAIR) { | ||
117 | //TODO: Handle pair/unpair requests and forward them (to the pairing handler?) | 117 | //TODO: Handle pair/unpair requests and forward them (to the pairing handler?) | ||
118 | qobject_cast<LanLinkProvider*>(provider())->incomingPairPackage(this, package); | 118 | qobject_cast<LanLinkProvider*>(provider())->incomingPairPacket(this, packet); | ||
119 | return; | 119 | return; | ||
120 | } | 120 | } | ||
121 | 121 | | |||
122 | if (package.hasPayloadTransferInfo()) { | 122 | if (packet.hasPayloadTransferInfo()) { | ||
123 | //qCDebug(KDECONNECT_CORE) << "HasPayloadTransferInfo"; | 123 | //qCDebug(KDECONNECT_CORE) << "HasPayloadTransferInfo"; | ||
124 | QVariantMap transferInfo = package.payloadTransferInfo(); | 124 | QVariantMap transferInfo = packet.payloadTransferInfo(); | ||
125 | //FIXME: The next two lines shouldn't be needed! Why are they here? | 125 | //FIXME: The next two lines shouldn't be needed! Why are they here? | ||
126 | transferInfo.insert(QStringLiteral("useSsl"), true); | 126 | transferInfo.insert(QStringLiteral("useSsl"), true); | ||
127 | transferInfo.insert(QStringLiteral("deviceId"), deviceId()); | 127 | transferInfo.insert(QStringLiteral("deviceId"), deviceId()); | ||
128 | DownloadJob* job = new DownloadJob(m_socketLineReader->peerAddress(), transferInfo); | 128 | DownloadJob* job = new DownloadJob(m_socketLineReader->peerAddress(), transferInfo); | ||
129 | job->start(); | 129 | job->start(); | ||
130 | package.setPayload(job->getPayload(), package.payloadSize()); | 130 | packet.setPayload(job->getPayload(), packet.payloadSize()); | ||
131 | } | 131 | } | ||
132 | 132 | | |||
133 | Q_EMIT receivedPackage(package); | 133 | Q_EMIT receivedPacket(packet); | ||
134 | 134 | | |||
135 | if (m_socketLineReader->bytesAvailable() > 0) { | 135 | if (m_socketLineReader->bytesAvailable() > 0) { | ||
136 | QMetaObject::invokeMethod(this, "dataReceived", Qt::QueuedConnection); | 136 | QMetaObject::invokeMethod(this, "dataReceived", Qt::QueuedConnection); | ||
137 | } | 137 | } | ||
138 | 138 | | |||
139 | } | 139 | } | ||
140 | 140 | | |||
141 | void LanDeviceLink::userRequestsPair() | 141 | void LanDeviceLink::userRequestsPair() | ||
Show All 37 Lines |