1
0
mirror of https://github.com/f4exb/sdrangel.git synced 2024-11-26 01:39:05 -05:00

UDP sink plugin: use messageing system to configure address and port

This commit is contained in:
f4exb 2017-08-23 02:17:54 +02:00
parent f07563500b
commit 9a1b60c6ec
2 changed files with 72 additions and 6 deletions

View File

@ -18,7 +18,8 @@
#include "udpsinkmsg.h" #include "udpsinkmsg.h"
#include "udpsinkudphandler.h" #include "udpsinkudphandler.h"
#include "util/messagequeue.h"
MESSAGE_CLASS_DEFINITION(UDPSinkUDPHandler::MsgUDPAddressAndPort, Message)
UDPSinkUDPHandler::UDPSinkUDPHandler() : UDPSinkUDPHandler::UDPSinkUDPHandler() :
m_dataSocket(0), m_dataSocket(0),
@ -38,6 +39,7 @@ UDPSinkUDPHandler::UDPSinkUDPHandler() :
m_feedbackMessageQueue(0) m_feedbackMessageQueue(0)
{ {
m_udpBuf = new udpBlk_t[m_minNbUDPFrames]; m_udpBuf = new udpBlk_t[m_minNbUDPFrames];
connect(&m_inputMessageQueue, SIGNAL(messageEnqueued()), this, SLOT(handleMessages()));
} }
UDPSinkUDPHandler::~UDPSinkUDPHandler() UDPSinkUDPHandler::~UDPSinkUDPHandler()
@ -56,17 +58,16 @@ void UDPSinkUDPHandler::start()
if (!m_dataConnected) if (!m_dataConnected)
{ {
connect(m_dataSocket, SIGNAL(readyRead()), this, SLOT(dataReadyRead()), Qt::QueuedConnection); // , Qt::QueuedConnection
if (m_dataSocket->bind(m_dataAddress, m_dataPort)) if (m_dataSocket->bind(m_dataAddress, m_dataPort))
{ {
qDebug("UDPSinkUDPHandler::start: bind data socket to %s:%d", m_dataAddress.toString().toStdString().c_str(), m_dataPort); qDebug("UDPSinkUDPHandler::start: bind data socket to %s:%d", m_dataAddress.toString().toStdString().c_str(), m_dataPort);
connect(m_dataSocket, SIGNAL(readyRead()), this, SLOT(dataReadyRead()), Qt::QueuedConnection); // , Qt::QueuedConnection
m_dataConnected = true; m_dataConnected = true;
} }
else else
{ {
qWarning("UDPSinkUDPHandler::start: cannot bind data port %d", m_dataPort); qWarning("UDPSinkUDPHandler::start: cannot bind data socket to %s:%d", m_dataAddress.toString().toStdString().c_str(), m_dataPort);
disconnect(m_dataSocket, SIGNAL(readyRead()), this, SLOT(dataReadyRead()));
m_dataConnected = false; m_dataConnected = false;
} }
} }
@ -188,6 +189,12 @@ void UDPSinkUDPHandler::advanceReadPointer(int nbBytes)
} }
void UDPSinkUDPHandler::configureUDPLink(const QString& address, quint16 port) void UDPSinkUDPHandler::configureUDPLink(const QString& address, quint16 port)
{
Message* msg = MsgUDPAddressAndPort::create(address, port);
m_inputMessageQueue.push(msg);
}
void UDPSinkUDPHandler::applyUDPLink(const QString& address, quint16 port)
{ {
qDebug("UDPSinkUDPHandler::configureUDPLink: %s:%d", address.toStdString().c_str(), port); qDebug("UDPSinkUDPHandler::configureUDPLink: %s:%d", address.toStdString().c_str(), port);
bool addressOK = m_dataAddress.setAddress(address); bool addressOK = m_dataAddress.setAddress(address);
@ -229,3 +236,33 @@ void UDPSinkUDPHandler::resizeBuffer(float sampleRate)
resetReadIndex(); resetReadIndex();
} }
void UDPSinkUDPHandler::handleMessages()
{
Message* message;
while ((message = m_inputMessageQueue.pop()) != 0)
{
if (handleMessage(*message))
{
delete message;
}
}
}
bool UDPSinkUDPHandler::handleMessage(const Message& cmd)
{
if (UDPSinkUDPHandler::MsgUDPAddressAndPort::match(cmd))
{
UDPSinkUDPHandler::MsgUDPAddressAndPort& notif = (UDPSinkUDPHandler::MsgUDPAddressAndPort&) cmd;
applyUDPLink(notif.getAddress(), notif.getPort());
return true;
}
else
{
return false;
}
}

View File

@ -23,8 +23,8 @@
#include <QMutex> #include <QMutex>
#include "dsp/dsptypes.h" #include "dsp/dsptypes.h"
#include "util/message.h"
class MessageQueue; #include "util/messagequeue.h"
class UDPSinkUDPHandler : public QObject class UDPSinkUDPHandler : public QObject
{ {
@ -61,10 +61,35 @@ public slots:
void dataReadyRead(); void dataReadyRead();
private: private:
class MsgUDPAddressAndPort : public Message {
MESSAGE_CLASS_DECLARATION
public:
const QString& getAddress() const { return m_address; }
quint16 getPort() const { return m_port; }
static MsgUDPAddressAndPort* create(QString address, quint16 port)
{
return new MsgUDPAddressAndPort(address, port);
}
private:
QString m_address;
quint16 m_port;
MsgUDPAddressAndPort(QString address, quint16 port) :
Message(),
m_address(address),
m_port(port)
{ }
};
typedef char (udpBlk_t)[m_udpBlockSize]; typedef char (udpBlk_t)[m_udpBlockSize];
void moveData(char *blk); void moveData(char *blk);
void advanceReadPointer(int nbBytes); void advanceReadPointer(int nbBytes);
void applyUDPLink(const QString& address, quint16 port);
bool handleMessage(const Message& message);
QUdpSocket *m_dataSocket; QUdpSocket *m_dataSocket;
QHostAddress m_dataAddress; QHostAddress m_dataAddress;
@ -83,6 +108,10 @@ private:
int m_rwDelta; int m_rwDelta;
float m_d; float m_d;
MessageQueue *m_feedbackMessageQueue; MessageQueue *m_feedbackMessageQueue;
MessageQueue m_inputMessageQueue;
private slots:
void handleMessages();
}; };