introduce unsubscribing from universes
This commit is contained in:
parent
104d5526bc
commit
bbc3cb5592
|
@ -38,13 +38,24 @@ EspReceiver::EspReceiver()
|
|||
std::placeholders::_1));
|
||||
}
|
||||
|
||||
void EspReceiver::subscribe(uint16_t num) {
|
||||
void EspReceiver::subscribe(const uint16_t num) {
|
||||
if (universe(num)) // already subscribed
|
||||
return;
|
||||
ESP_LOGI(TAG, "Subscribing to universe # %d", num);
|
||||
Receiver::subscribe(num);
|
||||
// listen multicast; works for unicast too
|
||||
udp.listenMulticast(IPv4MulticastAddress(num),
|
||||
ACN_SDT_MULTICAST_PORT);
|
||||
}
|
||||
|
||||
void EspReceiver::unsubscribe(const uint16_t num) {
|
||||
if (!universe(num)) // not subscribed
|
||||
return;
|
||||
ESP_LOGI(TAG, "Unubscribing from universe # %d", num);
|
||||
Receiver::unsubscribe(num);
|
||||
// AsyncUDP has no way to unsubscribe IGMP?
|
||||
}
|
||||
|
||||
void EspReceiver::udpHandler(AsyncUDPPacket udp) {
|
||||
// Expecting IANA registered Session Data Transport traffic
|
||||
if (!udp.localPort() == ACN_SDT_MULTICAST_PORT)
|
||||
|
|
|
@ -55,7 +55,8 @@ class EspReceiver
|
|||
{
|
||||
public:
|
||||
EspReceiver();
|
||||
void subscribe(uint16_t universe = 1);
|
||||
virtual void subscribe(const uint16_t universe = 1);
|
||||
virtual void unsubscribe(const uint16_t);
|
||||
|
||||
private:
|
||||
AsyncUDP udp; // AsyncUDP
|
||||
|
|
|
@ -27,12 +27,15 @@
|
|||
|
||||
namespace SACN {
|
||||
|
||||
void Receiver::subscribe(const uint16_t universe) {
|
||||
if (universes_.count(universe))
|
||||
return;
|
||||
universes_.emplace(universe, new SACN::Universe());
|
||||
void Receiver::subscribe(const uint16_t num) {
|
||||
if (!universes_.count(num))
|
||||
universes_.emplace(num, new SACN::Universe());
|
||||
}
|
||||
|
||||
void Receiver::unsubscribe(const uint16_t num) {
|
||||
if (universes_.count(num))
|
||||
universes_.erase(num);
|
||||
}
|
||||
|
||||
SACN::Universe * Receiver::universe(uint16_t universe) {
|
||||
if (universes_.count(universe))
|
||||
|
|
|
@ -34,7 +34,8 @@ class Receiver
|
|||
{
|
||||
public:
|
||||
Receiver() {};
|
||||
void subscribe(const uint16_t universe);
|
||||
virtual void subscribe(const uint16_t);
|
||||
virtual void unsubscribe(const uint16_t);
|
||||
SACN::Universe * universe(uint16_t universe);
|
||||
|
||||
protected:
|
||||
|
|
Loading…
Reference in New Issue