From 0f534b9f7bd75904d6ad6a9dd045efc33c45911f Mon Sep 17 00:00:00 2001 From: Stephen Birarda Date: Fri, 17 Jul 2015 15:43:20 -0700 Subject: [PATCH] fixes for new read and NLPacketList --- assignment-client/src/AssignmentClientMonitor.cpp | 3 +-- .../src/avatars/AvatarMixerClientData.cpp | 4 +--- domain-server/src/DomainServer.cpp | 4 ++-- libraries/audio/src/InboundAudioStream.cpp | 9 ++------- libraries/avatars/src/AvatarHashMap.cpp | 4 ++-- libraries/networking/src/NLPacketList.cpp | 11 ++++++++++- libraries/networking/src/NLPacketList.h | 1 + libraries/networking/src/udt/PacketList.cpp | 12 ++++++++++-- libraries/networking/src/udt/PacketList.h | 5 ++--- 9 files changed, 31 insertions(+), 22 deletions(-) diff --git a/assignment-client/src/AssignmentClientMonitor.cpp b/assignment-client/src/AssignmentClientMonitor.cpp index ba2baad12b..d6082c3bc4 100644 --- a/assignment-client/src/AssignmentClientMonitor.cpp +++ b/assignment-client/src/AssignmentClientMonitor.cpp @@ -204,8 +204,7 @@ void AssignmentClientMonitor::checkSpares() { void AssignmentClientMonitor::handleChildStatusPacket(QSharedPointer packet) { // read out the sender ID - QUuid senderID = QUuid::fromRfc4122(QByteArray::fromRawData(packet->getPayload(), NUM_BYTES_RFC4122_UUID)); - packet->seek(NUM_BYTES_RFC4122_UUID); + QUuid senderID = QUuid::fromRfc4122(packet->read(NUM_BYTES_RFC4122_UUID)); auto nodeList = DependencyManager::get(); diff --git a/assignment-client/src/avatars/AvatarMixerClientData.cpp b/assignment-client/src/avatars/AvatarMixerClientData.cpp index de2e1ac143..fec51f76cb 100644 --- a/assignment-client/src/avatars/AvatarMixerClientData.cpp +++ b/assignment-client/src/avatars/AvatarMixerClientData.cpp @@ -15,9 +15,7 @@ int AvatarMixerClientData::parseData(NLPacket& packet) { // compute the offset to the data payload - QByteArray byteArray = QByteArray::fromRawData(packet.getPayload() + packet.pos(), - packet.bytesLeftToRead()); - return _avatar.parseDataFromBuffer(byteArray); + return _avatar.parseDataFromBuffer(packet.read(packet.bytesLeftToRead())); } bool AvatarMixerClientData::checkAndSetHasReceivedFirstPackets() { diff --git a/domain-server/src/DomainServer.cpp b/domain-server/src/DomainServer.cpp index 4aee260a20..c13de0449e 100644 --- a/domain-server/src/DomainServer.cpp +++ b/domain-server/src/DomainServer.cpp @@ -971,13 +971,13 @@ void DomainServer::sendDomainListToNode(const SharedNodePointer& node, const Hif // this data is at the beginning of each of the domain list packets QByteArray extendedHeader(NUM_DOMAIN_LIST_EXTENDED_HEADER_BYTES, 0); QDataStream extendedHeaderStream(&extendedHeader, QIODevice::WriteOnly); + + auto limitedNodeList = DependencyManager::get(); extendedHeaderStream << limitedNodeList->getSessionUUID(); extendedHeaderStream << node->getUUID(); extendedHeaderStream << (quint8) node->getCanAdjustLocks(); extendedHeaderStream << (quint8) node->getCanRez(); - - auto limitedNodeList = DependencyManager::get(); NLPacketList domainListPackets(PacketType::DomainList, extendedHeader); diff --git a/libraries/audio/src/InboundAudioStream.cpp b/libraries/audio/src/InboundAudioStream.cpp index deb12a6649..96515e007a 100644 --- a/libraries/audio/src/InboundAudioStream.cpp +++ b/libraries/audio/src/InboundAudioStream.cpp @@ -112,9 +112,7 @@ int InboundAudioStream::parseData(NLPacket& packet) { int networkSamples; // parse the info after the seq number and before the audio data (the stream properties) - int propertyBytes = parseStreamProperties(packet.getType(), - QByteArray::fromRawData(packet.getPayload() + packet.pos(), packet.bytesLeftToRead()), - networkSamples); + int propertyBytes = parseStreamProperties(packet.getType(), packet.read(packet.bytesLeftToRead()), networkSamples); packet.seek(packet.pos() + propertyBytes); // handle this packet based on its arrival status. @@ -133,10 +131,7 @@ int InboundAudioStream::parseData(NLPacket& packet) { if (packet.getType() == PacketType::SilentAudioFrame) { writeDroppableSilentSamples(networkSamples); } else { - int audioBytes = parseAudioData(packet.getType(), - QByteArray::fromRawData(packet.getPayload() + packet.pos(), - packet.bytesLeftToRead()), - networkSamples); + int audioBytes = parseAudioData(packet.getType(), packet.read(packet.bytesLeftToRead()), networkSamples); packet.seek(packet.pos() + audioBytes); } break; diff --git a/libraries/avatars/src/AvatarHashMap.cpp b/libraries/avatars/src/AvatarHashMap.cpp index 75465f0bc5..2540693088 100644 --- a/libraries/avatars/src/AvatarHashMap.cpp +++ b/libraries/avatars/src/AvatarHashMap.cpp @@ -55,8 +55,8 @@ void AvatarHashMap::processAvatarDataPacket(QSharedPointer packet, Sha while (packet->bytesLeftToRead()) { QUuid sessionUUID = QUuid::fromRfc4122(packet->read(NUM_BYTES_RFC4122_UUID)); - QByteArray byteArray = QByteArray::fromRawData(packet->getPayload() + packet->pos(), - packet->bytesLeftToRead()); + QByteArray byteArray = packet->read(packet->bytesLeftToRead()); + if (sessionUUID != _lastOwnerSessionUUID) { AvatarSharedPointer avatar = _avatarHash.value(sessionUUID); if (!avatar) { diff --git a/libraries/networking/src/NLPacketList.cpp b/libraries/networking/src/NLPacketList.cpp index 7ac9fe11c3..5f3770b4a4 100644 --- a/libraries/networking/src/NLPacketList.cpp +++ b/libraries/networking/src/NLPacketList.cpp @@ -13,7 +13,16 @@ #include "NLPacket.h" -NLPacketList::NLPacketList(PacketType::Value packetType) : PacketList(packetType) { +NLPacketList::NLPacketList(PacketType::Value packetType) : + PacketList(packetType) +{ + +} + +NLPacketList::NLPacketList(PacketType::Value packetType, const QByteArray& extendedHeader) : + PacketList(packetType, extendedHeader) +{ + } std::unique_ptr NLPacketList::createPacket() { diff --git a/libraries/networking/src/NLPacketList.h b/libraries/networking/src/NLPacketList.h index a1a483781d..57581e8e12 100644 --- a/libraries/networking/src/NLPacketList.h +++ b/libraries/networking/src/NLPacketList.h @@ -17,6 +17,7 @@ class NLPacketList : public PacketList { public: NLPacketList(PacketType::Value packetType); + NLPacketList(PacketType::Value packetType, const QByteArray& extendedHeader); private: NLPacketList(const NLPacketList& other) = delete; diff --git a/libraries/networking/src/udt/PacketList.cpp b/libraries/networking/src/udt/PacketList.cpp index 77a324f707..20f6971b83 100644 --- a/libraries/networking/src/udt/PacketList.cpp +++ b/libraries/networking/src/udt/PacketList.cpp @@ -18,11 +18,18 @@ PacketList::PacketList(PacketType::Value packetType) : _packetType(packetType) { + +} + +PacketList::PacketList(PacketType::Value packetType, const QByteArray& extendedHeader) : + _packetType(packetType), + _extendedHeader(extendedHeader) +{ QIODevice::open(WriteOnly); } void PacketList::startSegment() { - _segmentStartIndex = _currentPacket ? _currentPacket->pos() : 0; + _segmentStartIndex = _currentPacket ? _currentPacket->pos() : _extendedHeader.size(); } void PacketList::endSegment() { @@ -39,6 +46,7 @@ std::unique_ptr PacketList::createPacketWithExtendedHeader() { auto packet = createPacket(); if (!_extendedHeader.isEmpty()) { + qDebug() << "Writing a header of" << _extendedHeader.size(); // add the extended header to the front of the packet if (packet->write(_extendedHeader) == -1) { qDebug() << "Could not write extendedHeader in PacketList::createPacketWithExtendedHeader" @@ -89,7 +97,7 @@ qint64 PacketList::writeData(const char* data, qint64 maxSize) { newPacket->write(_currentPacket->getPayload() + _segmentStartIndex, segmentSize); // the current segment now starts at the beginning of the new packet - _segmentStartIndex = 0; + _segmentStartIndex = _extendedHeader.size(); // shrink the current payload to the actual size of the packet _currentPacket->setPayloadSize(_segmentStartIndex); diff --git a/libraries/networking/src/udt/PacketList.h b/libraries/networking/src/udt/PacketList.h index 0a1bdd080a..2e1413d66b 100644 --- a/libraries/networking/src/udt/PacketList.h +++ b/libraries/networking/src/udt/PacketList.h @@ -22,6 +22,7 @@ class PacketList : public QIODevice { Q_OBJECT public: PacketList(PacketType::Value packetType); + PacketList(PacketType::Value packetType, const QByteArray& extendedHeader); virtual bool isSequential() const { return true; } @@ -33,8 +34,6 @@ public: void closeCurrentPacket(bool shouldSendEmpty = false); - void setExtendedHeader(const QByteArray& extendedHeader) { _extendedHeader = extendedHeader; } - template qint64 readPrimitive(T* data); template qint64 writePrimitive(const T& data); protected: @@ -83,4 +82,4 @@ template std::unique_ptr PacketList::takeFront() { return std::unique_ptr(dynamic_cast(packet.release())); } -#endif // hifi_PacketList_h \ No newline at end of file +#endif // hifi_PacketList_h