wrap the subscribed universes with a class that has convenient signals and slots.
This commit is contained in:
parent
0c6eb37e38
commit
e49ba6c53f
|
@ -16,6 +16,7 @@ add_library(${PROJECT_NAME} STATIC
|
|||
qsacnnode_global.h
|
||||
qsacnnode.cpp
|
||||
qsacnnode.h
|
||||
qsacnuniversewrapper.h
|
||||
)
|
||||
|
||||
target_link_libraries(${PROJECT_NAME} PUBLIC Qt${QT_VERSION_MAJOR}::Network ESTA)
|
||||
|
|
|
@ -25,6 +25,7 @@ void QSacnNode::subscribe(const uint16_t num)
|
|||
return;
|
||||
qDebug() << "Subscribing to universe" << QString::number(num);
|
||||
Receiver::subscribe(num);
|
||||
wrappers_.insert(num, new QSacnUniverseWrapper(this, Receiver::universe(num)));
|
||||
joinMulticastGroup(IPv4MulticastAddress(num));
|
||||
}
|
||||
|
||||
|
@ -35,6 +36,7 @@ void QSacnNode::unsubscribe(const uint16_t num)
|
|||
return;
|
||||
qDebug() << "Unsubscribing from universe " << QString::number(num);
|
||||
leaveMulticastGroup(IPv4MulticastAddress(num));
|
||||
delete wrappers_.take(num);
|
||||
Receiver::unsubscribe(num);
|
||||
}
|
||||
|
||||
|
|
|
@ -2,8 +2,10 @@
|
|||
#define QSACNNODE_H
|
||||
|
||||
#include "qsacnnode_global.h"
|
||||
#include "qsacnuniversewrapper.h"
|
||||
#include "../../sacn/node.h"
|
||||
|
||||
#include <QHash>
|
||||
#include <QHostAddress>
|
||||
#include <QUdpSocket>
|
||||
#include <QUuid>
|
||||
|
@ -33,7 +35,7 @@ class QT_EXPORT QSacnNode
|
|||
Q_OBJECT
|
||||
|
||||
public:
|
||||
QSacnNode(QObject *parent = nullptr, QUuid = QUuid::createUuid());
|
||||
explicit QSacnNode(QObject *parent = nullptr, QUuid = QUuid::createUuid());
|
||||
virtual void subscribe(const uint16_t universe = 1);
|
||||
virtual void unsubscribe(const uint16_t);
|
||||
|
||||
|
@ -43,6 +45,8 @@ signals:
|
|||
private:
|
||||
void UdpStreamHandler();
|
||||
void emitFound(std::shared_ptr<EXTENDED::DISCOVERY::DiscoveredUniverse>);
|
||||
|
||||
QHash<uint16_t, QSacnUniverseWrapper*> wrappers_;
|
||||
};
|
||||
|
||||
} // namespace SACN
|
||||
|
|
|
@ -0,0 +1,75 @@
|
|||
#ifndef QSACNUNIVERSEWRAPPER_H
|
||||
#define QSACNUNIVERSEWRAPPER_H
|
||||
|
||||
#include <QObject>
|
||||
#include <QTime>
|
||||
#include <QTimer>
|
||||
|
||||
#include "../../sacn/universe.h"
|
||||
|
||||
namespace SACN {
|
||||
|
||||
class QSacnUniverseWrapper
|
||||
: public QObject
|
||||
{
|
||||
Q_OBJECT
|
||||
public:
|
||||
friend DMX::Universe; // permit callback to access the private notifier
|
||||
explicit QSacnUniverseWrapper(QObject *parent = nullptr,
|
||||
Universe *universe = nullptr)
|
||||
: QObject(parent)
|
||||
, universe_(universe)
|
||||
, refreshTimer_(new QTimer(this))
|
||||
, lastRecieved_(QTime())
|
||||
{
|
||||
universe_->onData(std::bind(&QSacnUniverseWrapper::dataChangedNotifier,
|
||||
this, std::placeholders::_1));
|
||||
};
|
||||
|
||||
public slots:
|
||||
void setDescription(std::string desc)
|
||||
{
|
||||
universe_->source()->setDescription(desc);
|
||||
}
|
||||
void setOptions(uint8_t o)
|
||||
{
|
||||
universe_->source()->setOptions(o);
|
||||
}
|
||||
void setPriority(uint8_t p)
|
||||
{
|
||||
universe_->source()->setPriority(p);
|
||||
}
|
||||
void setSyncAddress(uint16_t a)
|
||||
{
|
||||
universe_->source()->setSyncAddress(a);
|
||||
}
|
||||
void setValue (const uint16_t addr, const uint8_t level)
|
||||
{
|
||||
universe_->DMX::Universe::setValue(addr, level);
|
||||
}
|
||||
void setValue (const uint16_t addr, const uint16_t size,
|
||||
const uint8_t* profile)
|
||||
{
|
||||
universe_->DMX::Universe::setValue(addr, size, profile);
|
||||
}
|
||||
|
||||
|
||||
signals:
|
||||
void changed(SACN::Universe*);
|
||||
|
||||
protected:
|
||||
void dataChangedNotifier(DMX::Universe* universe = nullptr)
|
||||
{
|
||||
Q_UNUSED(universe)
|
||||
lastRecieved_ = QTime::currentTime();
|
||||
emit changed(universe_);
|
||||
};
|
||||
|
||||
private:
|
||||
SACN::Universe *universe_;
|
||||
QTimer *refreshTimer_;
|
||||
QTime lastRecieved_;
|
||||
};
|
||||
|
||||
} // SACN namespace
|
||||
#endif // QSACNUNIVERSEWRAPPER_H
|
Loading…
Reference in New Issue