Changeset View
Changeset View
Standalone View
Standalone View
core/backends/bluetooth/bluetoothlinkprovider.cpp
Show First 20 Lines • Show All 160 Lines • ▼ Show 20 Line(s) | |||||
161 | 161 | | |||
162 | //I'm the new device and the existing device sent me data. | 162 | //I'm the new device and the existing device sent me data. | ||
163 | void BluetoothLinkProvider::clientIdentityReceived() | 163 | void BluetoothLinkProvider::clientIdentityReceived() | ||
164 | { | 164 | { | ||
165 | QBluetoothSocket* socket = qobject_cast<QBluetoothSocket*>(sender()); | 165 | QBluetoothSocket* socket = qobject_cast<QBluetoothSocket*>(sender()); | ||
166 | if (!socket) return; | 166 | if (!socket) return; | ||
167 | 167 | | |||
168 | QByteArray identityArray; | 168 | QByteArray identityArray; | ||
169 | while (socket->bytesAvailable() > 0 || !identityArray.contains('\n')) { | 169 | | ||
170 | if (socket->property("identityArray").isValid()) { | ||||
171 | identityArray = socket->property("identityArray").toByteArray(); | ||||
172 | } | ||||
173 | | ||||
174 | while (!identityArray.contains('\n') && socket->bytesAvailable() > 0) { | ||||
170 | identityArray += socket->readAll(); | 175 | identityArray += socket->readAll(); | ||
171 | } | 176 | } | ||
177 | if (!identityArray.contains('\n')) { | ||||
178 | // This method will get retriggered when more data is available. | ||||
179 | socket->setProperty("identityArray", identityArray); | ||||
180 | return; | ||||
181 | } | ||||
182 | socket->setProperty("identityArray", QVariant()); | ||||
172 | 183 | | |||
173 | disconnect(socket, SIGNAL(readyRead()), this, SLOT(clientIdentityReceived())); | 184 | disconnect(socket, SIGNAL(readyRead()), this, SLOT(clientIdentityReceived())); | ||
174 | 185 | | |||
175 | NetworkPacket receivedPacket(""); | 186 | NetworkPacket receivedPacket(""); | ||
176 | bool success = NetworkPacket::unserialize(identityArray, &receivedPacket); | 187 | bool success = NetworkPacket::unserialize(identityArray, &receivedPacket); | ||
177 | 188 | | |||
178 | if (!success || receivedPacket.type() != PACKET_TYPE_IDENTITY) { | 189 | if (!success || receivedPacket.type() != PACKET_TYPE_IDENTITY) { | ||
179 | qCWarning(KDECONNECT_CORE) << "Not an identity packet"; | 190 | qCWarning(KDECONNECT_CORE) << "Not an identity packet"; | ||
▲ Show 20 Lines • Show All 63 Lines • ▼ Show 20 Line(s) | |||||
243 | 254 | | |||
244 | //I'm the existing device and this is the answer to my identity packet (data received) | 255 | //I'm the existing device and this is the answer to my identity packet (data received) | ||
245 | void BluetoothLinkProvider::serverDataReceived() | 256 | void BluetoothLinkProvider::serverDataReceived() | ||
246 | { | 257 | { | ||
247 | QBluetoothSocket* socket = qobject_cast<QBluetoothSocket*>(sender()); | 258 | QBluetoothSocket* socket = qobject_cast<QBluetoothSocket*>(sender()); | ||
248 | if (!socket) return; | 259 | if (!socket) return; | ||
249 | 260 | | |||
250 | QByteArray identityArray; | 261 | QByteArray identityArray; | ||
251 | while (socket->bytesAvailable() > 0 || !identityArray.contains('\n')) { | 262 | if (socket->property("identityArray").isValid()) { | ||
263 | identityArray = socket->property("identityArray").toByteArray(); | ||||
264 | } | ||||
265 | | ||||
266 | while (!identityArray.contains('\n') && socket->bytesAvailable() > 0) { | ||||
252 | identityArray += socket->readAll(); | 267 | identityArray += socket->readAll(); | ||
253 | } | 268 | } | ||
269 | if (!identityArray.contains('\n')) { | ||||
270 | // This method will get retriggered when more data is available. | ||||
271 | socket->setProperty("identityArray", identityArray); | ||||
272 | return; | ||||
273 | } | ||||
274 | socket->setProperty("identityArray", QVariant()); | ||||
254 | 275 | | |||
255 | disconnect(socket, SIGNAL(readyRead()), this, SLOT(serverDataReceived())); | 276 | disconnect(socket, SIGNAL(readyRead()), this, SLOT(serverDataReceived())); | ||
256 | disconnect(socket, SIGNAL(error(QBluetoothSocket::SocketError)), this, SLOT(connectError())); | 277 | disconnect(socket, SIGNAL(error(QBluetoothSocket::SocketError)), this, SLOT(connectError())); | ||
257 | 278 | | |||
258 | NetworkPacket receivedPacket(""); | 279 | NetworkPacket receivedPacket(""); | ||
259 | bool success = NetworkPacket::unserialize(identityArray, &receivedPacket); | 280 | bool success = NetworkPacket::unserialize(identityArray, &receivedPacket); | ||
260 | 281 | | |||
261 | if (!success || receivedPacket.type() != PACKET_TYPE_IDENTITY) { | 282 | if (!success || receivedPacket.type() != PACKET_TYPE_IDENTITY) { | ||
▲ Show 20 Lines • Show All 44 Lines • Show Last 20 Lines |