Changeset View
Changeset View
Standalone View
Standalone View
core/backends/bluetooth/bluetoothdevicelink.cpp
Show First 20 Lines • Show All 42 Lines • ▼ Show 20 Line(s) | 34 | { | |||
---|---|---|---|---|---|
43 | connect(mBluetoothSocket, SIGNAL(disconnected()), this, SLOT(deleteLater())); | 43 | connect(mBluetoothSocket, SIGNAL(disconnected()), this, SLOT(deleteLater())); | ||
44 | } | 44 | } | ||
45 | 45 | | |||
46 | QString BluetoothDeviceLink::name() | 46 | QString BluetoothDeviceLink::name() | ||
47 | { | 47 | { | ||
48 | return "BluetoothLink"; // Should be same in both android and kde version | 48 | return "BluetoothLink"; // Should be same in both android and kde version | ||
49 | } | 49 | } | ||
50 | 50 | | |||
51 | bool BluetoothDeviceLink::sendPackage(NetworkPackage& np) | 51 | bool BluetoothDeviceLink::sendPacket(NetworkPacket& np) | ||
52 | { | 52 | { | ||
53 | if (np.hasPayload()) { | 53 | if (np.hasPayload()) { | ||
54 | qCWarning(KDECONNECT_CORE) << "Sending packages with payload over bluetooth not yet supported"; | 54 | qCWarning(KDECONNECT_CORE) << "Sending packets with payload over bluetooth not yet supported"; | ||
55 | /* | 55 | /* | ||
56 | BluetoothUploadJob* uploadJob = new BluetoothUploadJob(np.payload(), mBluetoothSocket->peerAddress(), this); | 56 | BluetoothUploadJob* uploadJob = new BluetoothUploadJob(np.payload(), mBluetoothSocket->peerAddress(), this); | ||
57 | np.setPayloadTransferInfo(uploadJob->transferInfo()); | 57 | np.setPayloadTransferInfo(uploadJob->transferInfo()); | ||
58 | uploadJob->start(); | 58 | uploadJob->start(); | ||
59 | */ | 59 | */ | ||
60 | } | 60 | } | ||
61 | int written = mSocketReader->write(np.serialize()); | 61 | int written = mSocketReader->write(np.serialize()); | ||
62 | return (written != -1); | 62 | return (written != -1); | ||
Show All 10 Lines | |||||
73 | bool BluetoothDeviceLink::linkShouldBeKeptAlive() { | 73 | bool BluetoothDeviceLink::linkShouldBeKeptAlive() { | ||
74 | return pairStatus() == Paired; | 74 | return pairStatus() == Paired; | ||
75 | } | 75 | } | ||
76 | 76 | | |||
77 | void BluetoothDeviceLink::dataReceived() | 77 | void BluetoothDeviceLink::dataReceived() | ||
78 | { | 78 | { | ||
79 | if (mSocketReader->bytesAvailable() == 0) return; | 79 | if (mSocketReader->bytesAvailable() == 0) return; | ||
80 | 80 | | |||
81 | const QByteArray serializedPackage = mSocketReader->readLine(); | 81 | const QByteArray serializedPacket = mSocketReader->readLine(); | ||
82 | 82 | | |||
83 | //qCDebug(KDECONNECT_CORE) << "BluetoothDeviceLink dataReceived" << package; | 83 | //qCDebug(KDECONNECT_CORE) << "BluetoothDeviceLink dataReceived" << packet; | ||
84 | 84 | | |||
85 | NetworkPackage package(QString::null); | 85 | NetworkPacket packet(QString::null); | ||
86 | NetworkPackage::unserialize(serializedPackage, &package); | 86 | NetworkPacket::unserialize(serializedPacket, &packet); | ||
87 | 87 | | |||
88 | if (package.type() == PACKAGE_TYPE_PAIR) { | 88 | if (packet.type() == PACKET_TYPE_PAIR) { | ||
89 | //TODO: Handle pair/unpair requests and forward them (to the pairing handler?) | 89 | //TODO: Handle pair/unpair requests and forward them (to the pairing handler?) | ||
90 | mPairingHandler->packageReceived(package); | 90 | mPairingHandler->packetReceived(packet); | ||
91 | return; | 91 | return; | ||
92 | } | 92 | } | ||
93 | 93 | | |||
94 | if (package.hasPayloadTransferInfo()) { | 94 | if (packet.hasPayloadTransferInfo()) { | ||
95 | BluetoothDownloadJob* downloadJob = new BluetoothDownloadJob(mBluetoothSocket->peerAddress(), | 95 | BluetoothDownloadJob* downloadJob = new BluetoothDownloadJob(mBluetoothSocket->peerAddress(), | ||
96 | package.payloadTransferInfo(), this); | 96 | packet.payloadTransferInfo(), this); | ||
97 | downloadJob->start(); | 97 | downloadJob->start(); | ||
98 | package.setPayload(downloadJob->payload(), package.payloadSize()); | 98 | packet.setPayload(downloadJob->payload(), packet.payloadSize()); | ||
99 | } | 99 | } | ||
100 | 100 | | |||
101 | Q_EMIT receivedPackage(package); | 101 | Q_EMIT receivedPacket(packet); | ||
102 | 102 | | |||
103 | if (mSocketReader->bytesAvailable() > 0) { | 103 | if (mSocketReader->bytesAvailable() > 0) { | ||
104 | QMetaObject::invokeMethod(this, "dataReceived", Qt::QueuedConnection); | 104 | QMetaObject::invokeMethod(this, "dataReceived", Qt::QueuedConnection); | ||
105 | } | 105 | } | ||
106 | } | 106 | } |