2022-12-11 14:55:05 -05:00
|
|
|
/*
|
2022-12-11 15:58:28 -05:00
|
|
|
sacn/universemerger.cpp
|
2022-12-11 14:55:05 -05:00
|
|
|
|
|
|
|
Copyright (c) 2022 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.
|
|
|
|
*/
|
|
|
|
|
2022-12-11 15:58:28 -05:00
|
|
|
#include "universemerger.h"
|
2022-12-11 14:55:05 -05:00
|
|
|
|
|
|
|
|
|
|
|
namespace sACN {
|
|
|
|
|
2022-12-11 15:58:28 -05:00
|
|
|
UniverseMerger::UniverseMerger()
|
2022-12-11 14:55:05 -05:00
|
|
|
: Universe()
|
|
|
|
{
|
2022-12-11 16:13:10 -05:00
|
|
|
Universe::metadata()->source_name = "HTP Merged Universe";
|
2022-12-11 14:55:05 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2022-12-11 16:48:06 -05:00
|
|
|
/**
|
|
|
|
* @brief MergingUniverse::addSource
|
|
|
|
* @param universe
|
|
|
|
*/
|
|
|
|
void UniverseMerger::addSource(std::shared_ptr<Universe> universe)
|
|
|
|
{
|
|
|
|
sources_.push_back(universe);
|
2022-12-11 16:48:42 -05:00
|
|
|
|
|
|
|
cb_tokens_.push_back(universe->onDataChange(
|
|
|
|
[this](DMX::Universe*){doDataCallbacks();}));
|
|
|
|
cb_tokens_.push_back(universe->onStatusChange(
|
|
|
|
[this](DMX::Universe*){doStatusCallbacks();}));
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @brief UniverseMerger::clear
|
|
|
|
*/
|
|
|
|
void UniverseMerger::clear()
|
|
|
|
{
|
|
|
|
sources_.clear();
|
|
|
|
cb_tokens_.clear();
|
2022-12-11 16:48:06 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2022-12-11 14:55:05 -05:00
|
|
|
/**
|
|
|
|
* @brief MergingUniverse::age
|
|
|
|
* @return The minimum age of the souce universes.
|
|
|
|
*/
|
2022-12-11 15:58:28 -05:00
|
|
|
long UniverseMerger::age() const
|
2022-12-11 14:55:05 -05:00
|
|
|
{
|
|
|
|
if (sources_.empty())
|
|
|
|
return 0;
|
|
|
|
|
|
|
|
std::vector<uint16_t> ages;
|
|
|
|
ages.reserve(sources_.size());
|
|
|
|
for (const auto& universe: sources_)
|
|
|
|
ages.push_back(universe->age());
|
|
|
|
|
|
|
|
return *std::min_element(ages.begin(), ages.end());
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @brief MergingUniverse::rxRate
|
|
|
|
* @return The maximum rxRate of the source universes.
|
|
|
|
*/
|
2022-12-11 15:58:28 -05:00
|
|
|
double UniverseMerger::rxRate()
|
2022-12-11 14:55:05 -05:00
|
|
|
{
|
|
|
|
if (sources_.empty())
|
|
|
|
return -1;
|
|
|
|
|
|
|
|
std::vector<uint16_t> rates;
|
|
|
|
rates.reserve(sources_.size());
|
|
|
|
for (const auto& universe: sources_)
|
|
|
|
rates.push_back(universe->rxRate());
|
|
|
|
|
|
|
|
return *std::max_element(rates.begin(), rates.end());
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2022-12-11 15:58:28 -05:00
|
|
|
uint8_t UniverseMerger::status() const
|
2022-12-11 14:55:05 -05:00
|
|
|
{
|
|
|
|
if (sources_.empty())
|
|
|
|
return DMX_NULL;
|
|
|
|
|
|
|
|
std::vector<uint16_t> states;
|
|
|
|
states.reserve(sources_.size());
|
|
|
|
for (const auto& universe: sources_)
|
|
|
|
{
|
|
|
|
switch (universe->status()) {
|
|
|
|
case DMX_NULL:
|
|
|
|
continue;
|
|
|
|
case DMX_ACTIVE:
|
|
|
|
return DMX_ACTIVE;
|
|
|
|
default:
|
|
|
|
states.push_back(universe->status());
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (states.empty())
|
|
|
|
return DMX_NULL;
|
|
|
|
|
|
|
|
return *std::min_element(states.begin(), states.end());
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @brief MergingUniverse::slot
|
|
|
|
* @param address
|
|
|
|
* @return An HTP merge of the source slot values.
|
|
|
|
*/
|
2022-12-11 15:58:28 -05:00
|
|
|
uint8_t UniverseMerger::slot(const uint16_t address) const
|
2022-12-11 14:55:05 -05:00
|
|
|
{
|
|
|
|
if (sources_.empty())
|
|
|
|
return 0;
|
|
|
|
|
|
|
|
std::vector<uint16_t> values;
|
|
|
|
values.reserve(sources_.size());
|
|
|
|
for (const auto& universe: sources_)
|
|
|
|
values.push_back(universe->slot(address));
|
|
|
|
|
|
|
|
return *std::max_element(values.begin(), values.end());
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @brief MergingUniverse::activeSlots
|
|
|
|
* @return The largest activeSlots values of the sources.
|
|
|
|
*/
|
2022-12-11 15:58:28 -05:00
|
|
|
uint16_t UniverseMerger::activeSlots() const
|
2022-12-11 14:55:05 -05:00
|
|
|
{
|
|
|
|
if (sources_.empty())
|
|
|
|
return 0;
|
|
|
|
|
|
|
|
std::vector<uint16_t> sizes;
|
|
|
|
sizes.reserve(sources_.size());
|
|
|
|
for (const auto& universe: sources_)
|
|
|
|
sizes.push_back(universe->activeSlots());
|
|
|
|
|
|
|
|
return *std::max_element(sizes.begin(), sizes.end());
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2022-12-11 15:58:28 -05:00
|
|
|
std::shared_ptr<DATA::data_header> UniverseMerger::metadata() const
|
2022-12-11 14:55:05 -05:00
|
|
|
{
|
|
|
|
if (sources_.size() == 1)
|
|
|
|
return sources_.front()->metadata();
|
|
|
|
|
2022-12-11 16:46:11 -05:00
|
|
|
return Universe::metadata();
|
2022-12-11 14:55:05 -05:00
|
|
|
}
|
|
|
|
|
2022-12-11 21:24:27 -05:00
|
|
|
|
|
|
|
/**
|
|
|
|
* @brief UniverseMerger::sources
|
|
|
|
* @return
|
|
|
|
*/
|
|
|
|
const std::vector<DATA::data_header> UniverseMerger::sources() const
|
|
|
|
{
|
|
|
|
std::vector<DATA::data_header> metas;
|
|
|
|
metas.reserve(sources_.size());
|
|
|
|
for (const auto & universe: sources_)
|
|
|
|
metas.push_back(*universe->metadata());
|
|
|
|
return metas;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2022-12-11 14:55:05 -05:00
|
|
|
} // namespace sACN
|