manage universes with shared pointers
This commit is contained in:
parent
15ad9a565b
commit
d3da663a44
|
@ -5,10 +5,13 @@
|
|||
* @param parent
|
||||
* @param universe
|
||||
*/
|
||||
QSacnUniverse::QSacnUniverse(QObject *parent, sACN::Universe *universe)
|
||||
QSacnUniverse::QSacnUniverse(QObject *parent, std::shared_ptr<sACN::Universe> universe)
|
||||
: QObject(parent)
|
||||
, universe_(universe)
|
||||
{
|
||||
if (!universe)
|
||||
return;
|
||||
|
||||
universe_->onData([this](DMX::Universe*) {
|
||||
emit changed();
|
||||
});
|
||||
|
|
|
@ -13,8 +13,8 @@ class QT_EXPORT QSacnUniverse
|
|||
{
|
||||
Q_OBJECT
|
||||
public:
|
||||
explicit QSacnUniverse(QObject *parent = nullptr,
|
||||
sACN::Universe *universe = nullptr);
|
||||
explicit QSacnUniverse(QObject *parent = nullptr,
|
||||
std::shared_ptr<sACN::Universe> universe = nullptr);
|
||||
|
||||
const QString description() const;
|
||||
uint16_t number() const;
|
||||
|
@ -37,6 +37,6 @@ signals:
|
|||
void changed();
|
||||
|
||||
private:
|
||||
sACN::Universe *universe_;
|
||||
std::shared_ptr<sACN::Universe> universe_;
|
||||
};
|
||||
Q_DECLARE_METATYPE(QSacnUniverse*)
|
||||
|
|
|
@ -41,8 +41,6 @@ ArbitratingUniverse::ArbitratingUniverse()
|
|||
*/
|
||||
ArbitratingUniverse::~ArbitratingUniverse()
|
||||
{
|
||||
for (auto& [_, universe] : sources_)
|
||||
delete universe;
|
||||
}
|
||||
|
||||
|
||||
|
@ -64,7 +62,7 @@ const std::vector<DATA::data_header> ArbitratingUniverse::sources() const
|
|||
* @param src
|
||||
* @return
|
||||
*/
|
||||
Universe* ArbitratingUniverse::sourceUniverse(const DATA::data_header &src)
|
||||
std::shared_ptr<Universe> ArbitratingUniverse::sourceUniverse(const DATA::data_header &src)
|
||||
{
|
||||
if (!hasSourceUniverse(src))
|
||||
newProvenance_(src);
|
||||
|
@ -79,9 +77,7 @@ Universe* ArbitratingUniverse::sourceUniverse(const DATA::data_header &src)
|
|||
*/
|
||||
bool ArbitratingUniverse::hasSourceUniverse(const DATA::data_header& src) const
|
||||
{
|
||||
if (sources_.count(src))
|
||||
return true;
|
||||
return false;
|
||||
return (sources_.count(src));
|
||||
}
|
||||
|
||||
|
||||
|
|
|
@ -84,9 +84,9 @@ public:
|
|||
double rxRate() override;
|
||||
|
||||
private:
|
||||
std::unordered_map<DATA::data_header, sACN::Universe*> sources_;
|
||||
std::unordered_map<DATA::data_header, std::shared_ptr<Universe>> sources_;
|
||||
|
||||
Universe* dominant_() const;
|
||||
std::shared_ptr<Universe> dominant_() const;
|
||||
void newProvenance_(const DATA::data_header&);
|
||||
};
|
||||
|
||||
|
|
|
@ -64,7 +64,7 @@ void Receiver::subscribe(const uint16_t num)
|
|||
{
|
||||
if (universes_.count(num))
|
||||
return;
|
||||
universes_.emplace(num, new ArbitratingUniverse());
|
||||
universes_.emplace(num, std::make_shared<ArbitratingUniverse>());
|
||||
universes_.at(num)->expectedUniverse = num;
|
||||
}
|
||||
|
||||
|
@ -76,10 +76,7 @@ void Receiver::subscribe(const uint16_t num)
|
|||
void Receiver::unsubscribe(const uint16_t num)
|
||||
{
|
||||
if (universes_.count(num))
|
||||
{
|
||||
delete universes_.at(num);
|
||||
universes_.erase(num);
|
||||
}
|
||||
universes_.erase(num);
|
||||
}
|
||||
|
||||
|
||||
|
@ -88,11 +85,11 @@ void Receiver::unsubscribe(const uint16_t num)
|
|||
* @param num
|
||||
* @return
|
||||
*/
|
||||
Universe * Receiver::universe(const uint16_t num)
|
||||
std::shared_ptr<Universe> Receiver::universe(const uint16_t num)
|
||||
{
|
||||
if (!universes_.count(num))
|
||||
return nullptr;
|
||||
return universes_.at(num);
|
||||
return std::static_pointer_cast<Universe>(universes_.at(num));
|
||||
}
|
||||
|
||||
|
||||
|
|
|
@ -71,7 +71,7 @@ public:
|
|||
|
||||
virtual void subscribe(const uint16_t);
|
||||
virtual void unsubscribe(const uint16_t);
|
||||
Universe * universe(const uint16_t);
|
||||
std::shared_ptr<Universe> universe(const uint16_t);
|
||||
|
||||
void discoveryStart();
|
||||
void discoveryStop();
|
||||
|
@ -96,7 +96,7 @@ protected:
|
|||
void discoveryListHanlder(ACN::PDU::Message<EXTENDED::DISCOVERY::Pdu>);
|
||||
|
||||
private:
|
||||
std::unordered_map<uint16_t, ArbitratingUniverse*> universes_;
|
||||
std::unordered_map<uint16_t, std::shared_ptr<ArbitratingUniverse>> universes_;
|
||||
std::vector<std::function<void()>> discoveryCallbacks_;
|
||||
};
|
||||
|
||||
|
|
|
@ -45,9 +45,6 @@ Source::~Source()
|
|||
{
|
||||
discovery_exitSignal_.set_value();
|
||||
discovery_worker_.join();
|
||||
|
||||
for (const auto & [_, univ] : universes_)
|
||||
delete univ;
|
||||
}
|
||||
|
||||
|
||||
|
@ -65,7 +62,7 @@ void Source::create(const uint16_t num)
|
|||
metadata->universe = num;
|
||||
|
||||
universes_mutext_.lock();
|
||||
universes_.emplace(num, new Universe(this));
|
||||
universes_.emplace(num, std::make_shared<Universe>(this));
|
||||
universes_[num]->setProvenance(metadata);
|
||||
universes_mutext_.unlock();
|
||||
}
|
||||
|
@ -84,7 +81,6 @@ void Source::terminate(const uint16_t num)
|
|||
auto metadata = universes_[num]->provenance();
|
||||
metadata->options.stream_terminated = true;
|
||||
universes_.at(num)->setProvenance(metadata);
|
||||
delete universes_.at(num);
|
||||
universes_.erase(num);
|
||||
universes_mutext_.unlock();
|
||||
}
|
||||
|
@ -211,7 +207,7 @@ void Source::sendExtendedFrame(const uint16_t vector,
|
|||
* @param num
|
||||
* @return
|
||||
*/
|
||||
Universe * Source::universe(const uint16_t num)
|
||||
std::shared_ptr<Universe> Source::universe(const uint16_t num)
|
||||
{
|
||||
if (!universes_.count(num))
|
||||
return nullptr;
|
||||
|
|
|
@ -53,7 +53,7 @@ public:
|
|||
|
||||
virtual void create(const uint16_t);
|
||||
virtual void terminate(const uint16_t);
|
||||
Universe * universe(const uint16_t);
|
||||
std::shared_ptr<Universe> universe(const uint16_t);
|
||||
|
||||
protected:
|
||||
virtual void discoveryAnnounce();
|
||||
|
@ -64,7 +64,7 @@ protected:
|
|||
const ACN::SDT::UDP::ipAddress&);
|
||||
|
||||
private:
|
||||
std::unordered_map <uint16_t, Universe *> universes_;
|
||||
std::unordered_map <uint16_t, std::shared_ptr<Universe>> universes_;
|
||||
mutable std::mutex universes_mutext_;
|
||||
|
||||
/// > \cite 6.3.2 E1.31 Synchronization Packet: Sequence Number
|
||||
|
|
Loading…
Reference in New Issue