mirror of
https://github.com/overte-org/overte.git
synced 2025-08-06 16:36:54 +02:00
add O_OBJECT macros to appropriate classes, fix PacketList errors
This commit is contained in:
parent
302e502d84
commit
f2a198dfdd
5 changed files with 50 additions and 48 deletions
|
@ -39,7 +39,7 @@
|
||||||
#include "Node.h"
|
#include "Node.h"
|
||||||
#include "NLPacket.h"
|
#include "NLPacket.h"
|
||||||
#include "PacketHeaders.h"
|
#include "PacketHeaders.h"
|
||||||
#include "PacketList.h"
|
#include "NLPacketList.h"
|
||||||
#include "UUIDHasher.h"
|
#include "UUIDHasher.h"
|
||||||
|
|
||||||
const int MAX_PACKET_SIZE = 1450;
|
const int MAX_PACKET_SIZE = 1450;
|
||||||
|
@ -69,7 +69,6 @@ Q_DECLARE_METATYPE(SharedNodePointer)
|
||||||
using namespace tbb;
|
using namespace tbb;
|
||||||
typedef std::pair<QUuid, SharedNodePointer> UUIDNodePair;
|
typedef std::pair<QUuid, SharedNodePointer> UUIDNodePair;
|
||||||
typedef concurrent_unordered_map<QUuid, SharedNodePointer, UUIDHasher> NodeHash;
|
typedef concurrent_unordered_map<QUuid, SharedNodePointer, UUIDHasher> NodeHash;
|
||||||
using NLPacketList = PacketList<NLPacket>;
|
|
||||||
|
|
||||||
typedef quint8 PingType_t;
|
typedef quint8 PingType_t;
|
||||||
namespace PingType {
|
namespace PingType {
|
||||||
|
|
|
@ -15,23 +15,24 @@
|
||||||
#include "Packet.h"
|
#include "Packet.h"
|
||||||
|
|
||||||
class NLPacket : public Packet {
|
class NLPacket : public Packet {
|
||||||
|
Q_OBJECT
|
||||||
public:
|
public:
|
||||||
static std::unique_ptr<NLPacket> create(PacketType::Value type, int64_t size = -1);
|
static std::unique_ptr<NLPacket> create(PacketType::Value type, int64_t size = -1);
|
||||||
// Provided for convenience, try to limit use
|
// Provided for convenience, try to limit use
|
||||||
static std::unique_ptr<NLPacket> createCopy(const std::unique_ptr<NLPacket>& other);
|
static std::unique_ptr<NLPacket> createCopy(const std::unique_ptr<NLPacket>& other);
|
||||||
|
|
||||||
static int64_t localHeaderSize(PacketType::Value type);
|
static int64_t localHeaderSize(PacketType::Value type);
|
||||||
static int64_t maxPayloadSize(PacketType::Value type);
|
static int64_t maxPayloadSize(PacketType::Value type);
|
||||||
|
|
||||||
virtual qint64 totalHeadersSize() const; // Cumulated size of all the headers
|
virtual qint64 totalHeadersSize() const; // Cumulated size of all the headers
|
||||||
virtual qint64 localHeaderSize() const; // Current level's header size
|
virtual qint64 localHeaderSize() const; // Current level's header size
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
NLPacket(PacketType::Value type, int64_t size);
|
NLPacket(PacketType::Value type, int64_t size);
|
||||||
NLPacket(NLPacket& other);
|
NLPacket(NLPacket& other);
|
||||||
|
|
||||||
void setSourceUuid(QUuid sourceUuid);
|
void setSourceUuid(QUuid sourceUuid);
|
||||||
void setConnectionUuid(QUuid connectionUuid);
|
void setConnectionUuid(QUuid connectionUuid);
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif // hifi_NLPacket_h
|
#endif // hifi_NLPacket_h
|
||||||
|
|
|
@ -1,5 +1,5 @@
|
||||||
//
|
//
|
||||||
// PacketList.cpp
|
// NLPacketList.cpp
|
||||||
// libraries/networking/src
|
// libraries/networking/src
|
||||||
//
|
//
|
||||||
// Created by Stephen Birarda on 07/06/15.
|
// Created by Stephen Birarda on 07/06/15.
|
||||||
|
@ -9,19 +9,19 @@
|
||||||
// See the accompanying file LICENSE or http://www.apache.org/licenses/LICENSE-2.0.html
|
// See the accompanying file LICENSE or http://www.apache.org/licenses/LICENSE-2.0.html
|
||||||
//
|
//
|
||||||
|
|
||||||
#include "PacketList.h"
|
#include "NLPacketList.h"
|
||||||
|
|
||||||
#include <QDebug>
|
#include <QDebug>
|
||||||
|
|
||||||
template <typename T> PacketList<T>::PacketList(PacketType::Value packetType) :
|
NLPacketList::NLPacketList(PacketType::Value packetType) :
|
||||||
_packetType(packetType)
|
_packetType(packetType)
|
||||||
{
|
{
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
template <typename T> std::unique_ptr<T> PacketList<T>::createPacketWithExtendedHeader() {
|
std::unique_ptr<NLPacket> NLPacketList::createPacketWithExtendedHeader() {
|
||||||
// use the static create method to create a new packet
|
// use the static create method to create a new packet
|
||||||
auto packet = T::create(_packetType);
|
auto packet = NLPacket::create(_packetType);
|
||||||
|
|
||||||
// add the extended header to the front of the packet
|
// add the extended header to the front of the packet
|
||||||
if (packet->write(_extendedHeader) == -1) {
|
if (packet->write(_extendedHeader) == -1) {
|
||||||
|
@ -32,16 +32,16 @@ template <typename T> std::unique_ptr<T> PacketList<T>::createPacketWithExtended
|
||||||
return packet;
|
return packet;
|
||||||
}
|
}
|
||||||
|
|
||||||
template <typename T> qint64 PacketList<T>::writeData(const char* data, qint64 maxSize) {
|
qint64 NLPacketList::writeData(const char* data, qint64 maxSize) {
|
||||||
if (!_currentPacket) {
|
if (!_currentPacket) {
|
||||||
// we don't have a current packet, time to set one up
|
// we don't have a current packet, time to set one up
|
||||||
_currentPacket = createPacketWithExtendedHeader();
|
_currentPacket = createPacketWithExtendedHeader();
|
||||||
}
|
}
|
||||||
|
|
||||||
// check if this block of data can fit into the currentPacket
|
// check if this block of data can fit into the currentPacket
|
||||||
if (maxSize <= _currentPacket.size()) {
|
if (maxSize <= _currentPacket->bytesAvailable()) {
|
||||||
// it fits, just write it to the current packet
|
// it fits, just write it to the current packet
|
||||||
_currentPacket.write(data, maxSize);
|
_currentPacket->write(data, maxSize);
|
||||||
|
|
||||||
// return the number of bytes written
|
// return the number of bytes written
|
||||||
return maxSize;
|
return maxSize;
|
||||||
|
@ -56,9 +56,9 @@ template <typename T> qint64 PacketList<T>::writeData(const char* data, qint64 m
|
||||||
// We need to try and pull the first part of the segment out to our new packet
|
// We need to try and pull the first part of the segment out to our new packet
|
||||||
|
|
||||||
// check now to see if this is an unsupported write
|
// check now to see if this is an unsupported write
|
||||||
int numBytesToEnd = _currentPacket.size() - _segmentStartIndex;
|
int numBytesToEnd = _currentPacket->bytesAvailable();
|
||||||
|
|
||||||
if ((newPacket.size() - numBytesToEnd) < maxSize) {
|
if ((newPacket->size() - numBytesToEnd) < maxSize) {
|
||||||
// this is an unsupported case - the segment is bigger than the size of an individual packet
|
// this is an unsupported case - the segment is bigger than the size of an individual packet
|
||||||
// but the PacketList is not going to be sent ordered
|
// but the PacketList is not going to be sent ordered
|
||||||
qDebug() << "Error in PacketList::writeData - attempted to write a segment to an unordered packet that is"
|
qDebug() << "Error in PacketList::writeData - attempted to write a segment to an unordered packet that is"
|
||||||
|
@ -67,23 +67,23 @@ template <typename T> qint64 PacketList<T>::writeData(const char* data, qint64 m
|
||||||
}
|
}
|
||||||
|
|
||||||
// copy from currentPacket where the segment started to the beginning of the newPacket
|
// copy from currentPacket where the segment started to the beginning of the newPacket
|
||||||
newPacket.write(_currentPacket->getPayload() + _segmentStartIndex, numBytesToEnd);
|
newPacket->write(_currentPacket->getPayload() + _segmentStartIndex, numBytesToEnd);
|
||||||
|
|
||||||
// the current segment now starts at the beginning of the new packet
|
// the current segment now starts at the beginning of the new packet
|
||||||
_segmentStartIndex = 0;
|
_segmentStartIndex = 0;
|
||||||
|
|
||||||
// shrink the current payload to the actual size of the packet
|
// shrink the current payload to the actual size of the packet
|
||||||
_currentPacket.setSizeUsed(_segmentStartIndex);
|
_currentPacket->setSizeUsed(_segmentStartIndex);
|
||||||
}
|
}
|
||||||
|
|
||||||
// move the current packet to our list of packets
|
// move the current packet to our list of packets
|
||||||
_packets.insert(std::move(_currentPacket));
|
_packets.push_back(std::move(_currentPacket));
|
||||||
|
|
||||||
// write the data to the newPacket
|
// write the data to the newPacket
|
||||||
newPacket.write(data, maxSize);
|
newPacket->write(data, maxSize);
|
||||||
|
|
||||||
// set our current packet to the new packet
|
// swap our current packet with the new packet
|
||||||
_currentPacket = newPacket;
|
_currentPacket.swap(newPacket);
|
||||||
|
|
||||||
// return the number of bytes written to the new packet
|
// return the number of bytes written to the new packet
|
||||||
return maxSize;
|
return maxSize;
|
||||||
|
@ -91,11 +91,11 @@ template <typename T> qint64 PacketList<T>::writeData(const char* data, qint64 m
|
||||||
// we're an ordered PacketList - let's fit what we can into the current packet and then put the leftover
|
// we're an ordered PacketList - let's fit what we can into the current packet and then put the leftover
|
||||||
// into a new packet
|
// into a new packet
|
||||||
|
|
||||||
int numBytesToEnd = _currentPacket.size() - _currentPacket.sizeUsed();
|
int numBytesToEnd = _currentPacket->bytesAvailable();
|
||||||
_currentPacket->write(data, numBytesToEnd);
|
_currentPacket->write(data, numBytesToEnd);
|
||||||
|
|
||||||
// move the current packet to our list of packets
|
// move the current packet to our list of packets
|
||||||
_packets.insert(std::move(_currentPacket));
|
_packets.push_back(std::move(_currentPacket));
|
||||||
|
|
||||||
// recursively call our writeData method for the remaining data to write to a new packet
|
// recursively call our writeData method for the remaining data to write to a new packet
|
||||||
return numBytesToEnd + writeData(data + numBytesToEnd, maxSize - numBytesToEnd);
|
return numBytesToEnd + writeData(data + numBytesToEnd, maxSize - numBytesToEnd);
|
||||||
|
@ -103,8 +103,8 @@ template <typename T> qint64 PacketList<T>::writeData(const char* data, qint64 m
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
template <typename T> void PacketList<T>::closeCurrentPacket() {
|
void NLPacketList::closeCurrentPacket() {
|
||||||
// move the current packet to our list of packets
|
// move the current packet to our list of packets
|
||||||
_packets.insert(std::move(_currentPacket));
|
_packets.push_back(std::move(_currentPacket));
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,5 +1,5 @@
|
||||||
//
|
//
|
||||||
// PacketList.h
|
// NLPacketList.h
|
||||||
// libraries/networking/src
|
// libraries/networking/src
|
||||||
//
|
//
|
||||||
// Created by Stephen Birarda on 07/06/15.
|
// Created by Stephen Birarda on 07/06/15.
|
||||||
|
@ -9,60 +9,61 @@
|
||||||
// See the accompanying file LICENSE or http://www.apache.org/licenses/LICENSE-2.0.html
|
// See the accompanying file LICENSE or http://www.apache.org/licenses/LICENSE-2.0.html
|
||||||
//
|
//
|
||||||
|
|
||||||
#ifndef hifi_PacketList_h
|
#ifndef hifi_NLPacketList_h
|
||||||
#define hifi_PacketList_h
|
#define hifi_NLPacketList_h
|
||||||
|
|
||||||
#include <QIODevice>
|
#include <QtCore/QIODevice>
|
||||||
|
|
||||||
#include "PacketHeaders.h"
|
#include "PacketHeaders.h"
|
||||||
|
|
||||||
template <typename T> class PacketList : public QIODevice {
|
#include "NLPacket.h"
|
||||||
|
|
||||||
|
class NLPacketList : public QIODevice {
|
||||||
|
Q_OBJECT
|
||||||
public:
|
public:
|
||||||
PacketList(PacketType::Value packetType);
|
NLPacketList(PacketType::Value packetType);
|
||||||
|
|
||||||
virtual bool isSequential() const { return true; }
|
virtual bool isSequential() const { return true; }
|
||||||
|
|
||||||
void startSegment() { _segmentStartIndex = _currentPacket->payload().pos(); }
|
void startSegment() { _segmentStartIndex = _currentPacket->pos(); }
|
||||||
void endSegment() { _segmentStartIndex = -1; }
|
void endSegment() { _segmentStartIndex = -1; }
|
||||||
|
|
||||||
int getNumPackets() const { return _packets.size() + (_currentPacket ? 1 : 0); }
|
int getNumPackets() const { return _packets.size() + (_currentPacket ? 1 : 0); }
|
||||||
|
|
||||||
void getCurrentPacketCapacity() const { return _currentPacket->bytesAvailable(); }
|
|
||||||
|
|
||||||
void closeCurrentPacket();
|
void closeCurrentPacket();
|
||||||
|
|
||||||
void setExtendedHeader(const QByteArray& extendedHeader) { _extendedHeader = extendedHeader; }
|
void setExtendedHeader(const QByteArray& extendedHeader) { _extendedHeader = extendedHeader; }
|
||||||
|
|
||||||
template<typename U> qint64 readPrimitive(U* data);
|
template<typename T> qint64 readPrimitive(T* data);
|
||||||
template<typename U> qint64 writePrimitive(const U& data);
|
template<typename T> qint64 writePrimitive(const T& data);
|
||||||
protected:
|
protected:
|
||||||
virtual qint64 writeData(const char* data, qint64 maxSize);
|
virtual qint64 writeData(const char* data, qint64 maxSize);
|
||||||
virtual qint64 readData(char* data, qint64 maxSize) { return 0; }
|
virtual qint64 readData(char* data, qint64 maxSize) { return 0; }
|
||||||
|
|
||||||
private:
|
private:
|
||||||
PacketList(const PacketList& other) = delete;
|
NLPacketList(const NLPacketList& other) = delete;
|
||||||
PacketList& operator=(const PacketList& other) = delete;
|
NLPacketList& operator=(const NLPacketList& other) = delete;
|
||||||
|
|
||||||
std::unique_ptr<T> createPacketWithExtendedHeader();
|
std::unique_ptr<NLPacket> createPacketWithExtendedHeader();
|
||||||
|
|
||||||
PacketType::Value _packetType;
|
PacketType::Value _packetType;
|
||||||
bool _isOrdered = false;
|
bool _isOrdered = false;
|
||||||
|
|
||||||
std::unique_ptr<T> _currentPacket;
|
std::unique_ptr<NLPacket> _currentPacket;
|
||||||
std::list<std::unique_ptr<T>> _packets;
|
std::list<std::unique_ptr<NLPacket>> _packets;
|
||||||
|
|
||||||
int _segmentStartIndex = -1;
|
int _segmentStartIndex = -1;
|
||||||
|
|
||||||
QByteArray _extendedHeader;
|
QByteArray _extendedHeader;
|
||||||
};
|
};
|
||||||
|
|
||||||
template <typename T> template <typename U> qint64 PacketList<T>::readPrimitive(U* data) {
|
template <typename T> qint64 NLPacketList::readPrimitive(T* data) {
|
||||||
return QIODevice::read(reinterpret_cast<char*>(data), sizeof(U));
|
return QIODevice::read(reinterpret_cast<char*>(data), sizeof(T));
|
||||||
}
|
}
|
||||||
|
|
||||||
template <typename T> template <typename U> qint64 PacketList<T>::writePrimitive(const U& data) {
|
template <typename T> qint64 NLPacketList::writePrimitive(const T& data) {
|
||||||
static_assert(!std::is_pointer<U>::value, "U must not be a pointer");
|
static_assert(!std::is_pointer<T>::value, "T must not be a pointer");
|
||||||
return QIODevice::write(reinterpret_cast<const char*>(&data), sizeof(U));
|
return QIODevice::write(reinterpret_cast<const char*>(&data), sizeof(T));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -19,6 +19,7 @@
|
||||||
#include "PacketHeaders.h"
|
#include "PacketHeaders.h"
|
||||||
|
|
||||||
class Packet : public QIODevice {
|
class Packet : public QIODevice {
|
||||||
|
Q_OBJECT
|
||||||
public:
|
public:
|
||||||
using SequenceNumber = uint16_t;
|
using SequenceNumber = uint16_t;
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue