12 #ifndef hifi_ReceivedPacketProcessor_h
13 #define hifi_ReceivedPacketProcessor_h
15 #include <QtCore/QSharedPointer>
16 #include <QWaitCondition>
20 #include "GenericThread.h"
22 class ReceivedMessage;
28 static const uint64_t MAX_WAIT_TIME { 100 };
33 void queueReceivedPacket(QSharedPointer<ReceivedMessage> message, SharedNodePointer sendingNode);
39 bool isAlive(
const QUuid& nodeUUID)
const {
40 return _nodePacketCounts.contains(nodeUUID);
50 return _nodePacketCounts[nodeUUID] > 0;
56 float getIncomingPPS()
const {
return _incomingPPS.getAverage(); }
57 float getProcessedPPS()
const {
return _processedPPS.getAverage(); }
59 virtual void terminating()
override;
62 void nodeKilled(SharedNodePointer node);
68 virtual void processPacket(QSharedPointer<ReceivedMessage> message, SharedNodePointer sendingNode) = 0;
71 virtual bool process()
override;
74 virtual uint32_t
getMaxWait()
const {
return MAX_WAIT_TIME; }
86 std::list<NodeSharedReceivedMessagePair> _packets;
87 QHash<QUuid, int> _nodePacketCounts;
89 QWaitCondition _hasPackets;
90 QMutex _waitingOnPacketsMutex;
92 quint64 _lastWindowAt = 0;
93 int _lastWindowIncomingPackets = 0;
94 int _lastWindowProcessedPackets = 0;
95 SimpleMovingAverage _incomingPPS;
96 SimpleMovingAverage _processedPPS;
Definition: GenericThread.h:23
Generalized threaded processor for handling received inbound packets.
Definition: ReceivedPacketProcessor.h:25
virtual uint32_t getMaxWait() const
Determines the timeout of the wait when there are no packets to process. Default value is 100ms to al...
Definition: ReceivedPacketProcessor.h:74
virtual void processPacket(QSharedPointer< ReceivedMessage > message, SharedNodePointer sendingNode)=0
virtual void preProcess()
Override to do work before the packets processing loop. Default does nothing.
Definition: ReceivedPacketProcessor.h:77
int packetsToProcessCount() const
How many received packets waiting are to be processed.
Definition: ReceivedPacketProcessor.h:54
bool hasPacketsToProcess() const
Are there received packets waiting to be processed.
Definition: ReceivedPacketProcessor.h:36
virtual void postProcess()
Override to do work after the packets processing loop. Default does nothing.
Definition: ReceivedPacketProcessor.h:83
void queueReceivedPacket(QSharedPointer< ReceivedMessage > message, SharedNodePointer sendingNode)
Add packet from network receive thread to the processing queue.
Definition: ReceivedPacketProcessor.cpp:28
bool hasPacketsToProcessFrom(const QUuid &nodeUUID) const
Are there received packets waiting to be processed from a specified node.
Definition: ReceivedPacketProcessor.h:49
virtual void midProcess()
Override to do work inside the packet processing loop after a packet is processed....
Definition: ReceivedPacketProcessor.h:80
bool hasPacketsToProcessFrom(const SharedNodePointer &sendingNode) const
Are there received packets waiting to be processed from a specified node.
Definition: ReceivedPacketProcessor.h:44
bool isAlive(const QUuid &nodeUUID) const
Is a specified node still alive?
Definition: ReceivedPacketProcessor.h:39
virtual bool process() override
Implements generic processing behavior for this thread.
Definition: ReceivedPacketProcessor.cpp:39