2021-08-24 18:10:20 -04:00
|
|
|
/*
|
|
|
|
mergeproxyuniverse.h
|
|
|
|
|
|
|
|
Copyright (c) 2021 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 "universe.h"
|
|
|
|
|
|
|
|
#include <memory>
|
|
|
|
#include <unordered_map>
|
|
|
|
|
2021-08-28 09:01:33 -04:00
|
|
|
namespace sACN {
|
2021-08-24 18:10:20 -04:00
|
|
|
|
|
|
|
/**
|
2021-08-29 00:58:57 -04:00
|
|
|
* @brief Priority based selection of multiple source universes
|
|
|
|
*
|
2021-08-28 09:01:33 -04:00
|
|
|
*
|
2021-08-28 12:54:26 -04:00
|
|
|
* > \cite sACN 6.2.3.1 Multiple Sources at Highest Priority
|
|
|
|
* >
|
2021-08-28 15:28:52 -04:00
|
|
|
* > It is possible for there to be multiple sources, all transmitting data
|
|
|
|
* > at the highest currently active priority for a given universe. When this
|
|
|
|
* > occurs, receivers must handle these sources in some way.
|
2021-08-29 00:58:57 -04:00
|
|
|
*
|
|
|
|
* If multiple universes with highest priority are recieved, the universe
|
2022-12-06 14:50:20 -05:00
|
|
|
* recieved most recently will be given dominance.
|
2021-08-29 00:58:57 -04:00
|
|
|
*
|
|
|
|
* > \cite sACN 6.2.3.2 Note on Merge and Arbitration Algorithms
|
|
|
|
* >
|
|
|
|
* > A process which selects between candidate sources based on some
|
|
|
|
* > additional selection criterion is called arbitration.
|
|
|
|
*
|
|
|
|
* The universe with the highest priority will be determined to be the
|
2022-12-06 14:50:20 -05:00
|
|
|
* dominant source.
|
2021-08-24 18:10:20 -04:00
|
|
|
*/
|
2021-08-28 15:28:52 -04:00
|
|
|
class ArbitratingUniverse
|
2021-08-28 09:01:33 -04:00
|
|
|
: public sACN::Universe
|
2021-08-24 18:10:20 -04:00
|
|
|
{
|
|
|
|
public:
|
2021-08-28 15:28:52 -04:00
|
|
|
ArbitratingUniverse();
|
|
|
|
~ArbitratingUniverse();
|
2021-08-24 18:10:20 -04:00
|
|
|
|
2021-09-04 17:28:00 -04:00
|
|
|
uint16_t expectedUniverse; ///< Expected universe number
|
|
|
|
|
2021-09-10 16:26:31 -04:00
|
|
|
void setHoldLastLook(const bool);
|
|
|
|
bool getHoldLastLook() const;
|
|
|
|
|
2021-08-24 18:10:20 -04:00
|
|
|
// Source universes:
|
2021-08-28 14:47:30 -04:00
|
|
|
void deleteSourceUniverse(const DATA::data_header&);
|
2021-08-24 18:10:20 -04:00
|
|
|
void dataChangedNotifier(DMX::Universe* universe);
|
|
|
|
|
|
|
|
// SACN::Universe overrides:
|
2021-08-28 14:47:30 -04:00
|
|
|
void set(std::shared_ptr<ACN::DMP::Pdu>, std::shared_ptr<DATA::data_header>) override;
|
2022-11-22 23:27:25 -05:00
|
|
|
virtual uint8_t status() override;
|
2021-09-10 12:00:50 -04:00
|
|
|
|
2022-12-08 10:12:25 -05:00
|
|
|
std::shared_ptr<DATA::data_header> metadata() override;
|
2022-12-08 17:52:24 -05:00
|
|
|
void setMetadata(std::shared_ptr<DATA::data_header>) override {};
|
2021-09-10 12:00:50 -04:00
|
|
|
|
2021-09-10 12:48:33 -04:00
|
|
|
bool isSyncronized() override;
|
2021-08-29 01:12:11 -04:00
|
|
|
void synchronize(uint8_t = 0) override;
|
2021-09-10 12:00:50 -04:00
|
|
|
|
2021-09-03 17:37:12 -04:00
|
|
|
bool isEditable() const override;
|
2021-09-10 12:00:50 -04:00
|
|
|
|
2021-09-10 12:48:33 -04:00
|
|
|
uint16_t activeSlots() override;
|
2021-08-24 18:10:20 -04:00
|
|
|
|
2021-09-10 12:00:50 -04:00
|
|
|
// api for poly-source universes
|
|
|
|
const std::vector<DATA::data_header> sources() const override;
|
|
|
|
std::shared_ptr<Universe> sourceUniverse(const DATA::data_header&) override;
|
|
|
|
std::shared_ptr<Universe> addNewSource(const DATA::data_header&) override;
|
2021-09-11 09:44:16 -04:00
|
|
|
std::shared_ptr<void> onSourceListChange(std::function<void()>) override;
|
2021-09-10 12:00:50 -04:00
|
|
|
|
2021-08-24 18:10:20 -04:00
|
|
|
// DMX::Universe Overrides:
|
2021-09-10 12:48:33 -04:00
|
|
|
uint8_t slot(const uint16_t) override;
|
2021-08-24 18:10:20 -04:00
|
|
|
double rxRate() override;
|
|
|
|
|
2021-09-11 09:44:16 -04:00
|
|
|
protected:
|
|
|
|
void doListChangeCallbacks();
|
|
|
|
|
2021-08-24 18:10:20 -04:00
|
|
|
private:
|
2021-09-11 09:44:16 -04:00
|
|
|
std::unordered_map<DATA::data_header, std::shared_ptr<Universe>> sources_;
|
|
|
|
std::vector<std::shared_ptr<void>> source_data_tokens; //!< source universe data change tokens
|
|
|
|
std::vector<std::weak_ptr<std::function<void()>>> cb_sourceListChange; //!< list of calback functions
|
|
|
|
|
2022-12-02 13:06:22 -05:00
|
|
|
std::vector<std::shared_ptr<void>> source_status_tokens; //!< source universe data change tokens
|
|
|
|
|
2021-09-11 09:44:16 -04:00
|
|
|
bool HoldLastLook;
|
2021-08-24 18:10:20 -04:00
|
|
|
|
2021-09-11 09:44:16 -04:00
|
|
|
std::shared_ptr<Universe> dominant_();
|
2022-11-20 15:22:51 -05:00
|
|
|
void purge_stale_sources_(std::unordered_map<DATA::data_header, uint> * = nullptr);
|
2021-09-11 09:44:16 -04:00
|
|
|
bool hasSourceUniverse(const DATA::data_header&) const;
|
2021-08-24 18:10:20 -04:00
|
|
|
};
|
|
|
|
|
|
|
|
} // SACN namespace
|