104 lines
3.6 KiB
C++
104 lines
3.6 KiB
C++
/*
|
|
receiver.h
|
|
|
|
Copyright (c) 2020 Kevin Matz (kevin.matz@gmail.com)
|
|
|
|
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
of this software and associated documentation files (the "Software"), to deal
|
|
in the Software without restriction, including without limitation the rights
|
|
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
copies of the Software, and to permit persons to whom the Software is
|
|
furnished to do so, subject to the following conditions:
|
|
|
|
The above copyright notice and this permission notice shall be included in all
|
|
copies or substantial portions of the Software.
|
|
|
|
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
SOFTWARE.
|
|
*/
|
|
#pragma once
|
|
|
|
#include "rlp/component.h"
|
|
#include "data.h"
|
|
#include "extended.h"
|
|
#include "sacn.h"
|
|
#include "arbitratinguniverse.h"
|
|
|
|
#include <unordered_map>
|
|
#include <unordered_set>
|
|
#include <vector>
|
|
|
|
namespace sACN {
|
|
|
|
/**
|
|
* @brief \cite sACN 3.6 Receiver: A receiver is the intended target of
|
|
* information from a source.
|
|
*
|
|
* > A receiver may listen on multiple universes.
|
|
*
|
|
* > \cite sACN 6.2.3.4 Requirements for Merging and Arbitrating
|
|
* > The ability of devices to merge or arbitrate between multiple sources at
|
|
* > highest active priority shall be declared in user documentation for the
|
|
* > device.
|
|
*
|
|
* sACN::Receiver has the ability to arbitrate between multiple source.
|
|
*
|
|
* > \cite sACN If merging or arbitration is implemented, the maximum number of
|
|
* > sources which can be correctly handled shall be declared in user
|
|
* > documentation for the device.
|
|
*
|
|
* sACN::Receiver has a merge limit maximum constrained by device memory, not
|
|
* to excede 18,446,744,073,709,551,615 (2^64) sources on most platforms.
|
|
*
|
|
* > \cite sACN If merging or arbitration is implemented the algorithm used
|
|
* > shall be declared in user documentation for the device.
|
|
*
|
|
* sACN::Receiver accepts the highest priority universe with an rxRate above
|
|
* DMX::E111_DATA_LOSS_TIMEOUT as the dominant universe.
|
|
*
|
|
*/
|
|
class Receiver
|
|
: public virtual ACN::RLP::Component
|
|
{
|
|
public:
|
|
Receiver(UUID::uuid = UUID::uuid());
|
|
~Receiver();
|
|
|
|
virtual void subscribe(const uint16_t);
|
|
virtual void unsubscribe(const uint16_t);
|
|
Universe * universe(const uint16_t);
|
|
|
|
void discoveryStart();
|
|
void discoveryStop();
|
|
void onDiscovered(const std::function<void()>);
|
|
/// The listing of discovered universes.
|
|
std::unordered_set<EXTENDED::DISCOVERY::discoveredUniverse> discovered;
|
|
|
|
protected:
|
|
// 5 - E1.31 use of the ACN Root Layer Protocol
|
|
void dataReceiver(ACN::PDU::Message<ACN::RLP::Pdu>);
|
|
void extendedReceiver(ACN::PDU::Message<ACN::RLP::Pdu>);
|
|
|
|
// 6.2 E1.31 Data Packet Framing Layer
|
|
void dataFrameHandler(ACN::PDU::Message<DATA::Pdu>);
|
|
|
|
// 6.3 E1.31 Synchronization Packet Framing Layer
|
|
void syncFrameHandler(ACN::PDU::Message<EXTENDED::Pdu>);
|
|
|
|
// 6.4 E1.31 Universe Discovery Packet Framing Layer
|
|
void discoveryFrameHandler(ACN::PDU::Message<EXTENDED::Pdu>);
|
|
// 8 Universe Discovery Layer
|
|
void discoveryListHanlder(ACN::PDU::Message<EXTENDED::DISCOVERY::Pdu>);
|
|
|
|
private:
|
|
std::unordered_map<uint16_t, ArbitratingUniverse*> universes_;
|
|
std::vector<std::function<void()>> discoveryCallbacks_;
|
|
};
|
|
|
|
};
|