mirror of
https://github.com/HifiExperiments/overte.git
synced 2025-08-04 05:04:44 +02:00
Add packet listeners to DatagramProcessor
This commit is contained in:
parent
74940a2132
commit
b1c09d71f7
2 changed files with 28 additions and 2 deletions
|
@ -23,11 +23,20 @@
|
|||
#include "DatagramProcessor.h"
|
||||
|
||||
DatagramProcessor::DatagramProcessor(QObject* parent) :
|
||||
QObject(parent)
|
||||
QObject(parent),
|
||||
_packetListenerMap()
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
void DatagramProcessor::registerPacketListener(Packet::Type type, QObject* object, QString methodName) {
|
||||
if (packetListenerMap.contains(type)) {
|
||||
qDebug() << "Warning: Registering a packet listener for packet type " << type
|
||||
<< " that will remove a previously registered listener";
|
||||
}
|
||||
packetListenerMap[type] = QPair<QObject*, QString>(object, methodName);
|
||||
}
|
||||
|
||||
void DatagramProcessor::processDatagrams() {
|
||||
PerformanceWarning warn(Menu::getInstance()->isOptionChecked(MenuOption::PipelineWarnings),
|
||||
"DatagramProcessor::processDatagrams()");
|
||||
|
@ -160,7 +169,20 @@ void DatagramProcessor::processDatagrams() {
|
|||
}
|
||||
break;
|
||||
default:
|
||||
nodeList->processNodeData(senderSockAddr, incomingPacket);
|
||||
//nodeList->processNodeData(senderSockAddr, incomingPacket);
|
||||
if (packetListenerMap.contains(incomingType)) {
|
||||
auto& listener = packetListenerMap[incomingType];
|
||||
NLPacket packet;
|
||||
bool success = QMetaObject::invokeMethod(listener.first, listener.second,
|
||||
Q_ARG(std::unique_ptr<NLPacket>, packet),
|
||||
Q_ARG(HifiSockAddr, senderSockAddr));
|
||||
if (!success) {
|
||||
qDebug() << "Error sending packet " << incomingType << " to listener: " << listener.first.name() << "::" << listener.second;
|
||||
}
|
||||
} else {
|
||||
QDebug() << "No listener found for packet type: " << incomingType;
|
||||
}
|
||||
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -27,10 +27,14 @@ public:
|
|||
void resetCounters() { _inPacketCount = 0; _outPacketCount = 0; _inByteCount = 0; _outByteCount = 0; }
|
||||
|
||||
void shutdown() { _isShuttingDown = true; }
|
||||
|
||||
void registerPacketListener(Packet::Type type, QObject* object, QString methodName);
|
||||
|
||||
public slots:
|
||||
void processDatagrams();
|
||||
|
||||
private:
|
||||
QMap<Packet::Type, QPair<QObject*, QString>> packetListenerMap;
|
||||
int _inPacketCount = 0;
|
||||
int _outPacketCount = 0;
|
||||
int _inByteCount = 0;
|
||||
|
|
Loading…
Reference in a new issue