unify the callback handlers
This commit is contained in:
parent
64140eb757
commit
d87fbcf25d
|
@ -17,7 +17,7 @@ QSacnUniverse::QSacnUniverse(QObject *parent, std::shared_ptr<sACN::Universe> un
|
|||
status_change_token = universe_->onStatusChange([this](DMX::Universe*){emit statusChanged();});
|
||||
|
||||
if (!universe->isEditable())
|
||||
list_change_token = universe_->onSourceListChange([this](){syncSources();});
|
||||
list_change_token = universe_->onSourceListChange([this](DMX::Universe*){syncSources();});
|
||||
|
||||
// set the status watchdog to update the status if the universe
|
||||
// isn't showing frequent activity
|
||||
|
|
|
@ -74,6 +74,7 @@ class Universe {
|
|||
protected:
|
||||
inline void doDataCallbacks() {do_callbacks_(cb_dataChange);} //!< Data Change Callbacks
|
||||
inline void doStatusCallbacks() {do_callbacks_(cb_statusChange);} //!< Status Change Callbacks
|
||||
void do_callbacks_(std::vector<std::weak_ptr<const std::function<void(Universe*)>>>&);
|
||||
|
||||
DimmerData null_start_data; //!< NULL Start Code data
|
||||
mutable std::shared_mutex mtx_data; //!< memory protect Null Start data
|
||||
|
@ -82,7 +83,6 @@ class Universe {
|
|||
|
||||
private:
|
||||
void rx_timeout_(bool add_now = false);
|
||||
void do_callbacks_(std::vector<std::weak_ptr<const std::function<void(Universe*)>>>&);
|
||||
|
||||
const int rx_timeout_period_;
|
||||
uint8_t status_; //!< the operating state of the universe
|
||||
|
|
|
@ -211,7 +211,7 @@ std::shared_ptr<Universe> Universe::addNewSource(const DATA::data_header&)
|
|||
* @param callback
|
||||
* @return
|
||||
*/
|
||||
std::shared_ptr<void> Universe::onSourceListChange(std::function<void()> callback)
|
||||
std::shared_ptr<void> Universe::onSourceListChange(const std::function<void(DMX::Universe*)> callback)
|
||||
{
|
||||
(void)callback;
|
||||
return nullptr;
|
||||
|
|
|
@ -68,7 +68,7 @@ public:
|
|||
virtual const std::vector<DATA::data_header> sources() const;
|
||||
virtual std::shared_ptr<Universe> sourceUniverse(const DATA::data_header&);
|
||||
virtual std::shared_ptr<Universe> addNewSource(const DATA::data_header&);
|
||||
virtual std::shared_ptr<void> onSourceListChange(std::function<void()>);
|
||||
virtual std::shared_ptr<void> onSourceListChange(const std::function<void(DMX::Universe*)>);
|
||||
virtual void setHoldLastLook(const bool);
|
||||
virtual bool getHoldLastLook() const;
|
||||
/**
|
||||
|
|
|
@ -157,11 +157,11 @@ void UniverseArbitrator::deleteSourceUniverse(const DATA::data_header& src)
|
|||
* @param cb
|
||||
* @return
|
||||
*/
|
||||
std::shared_ptr<void> UniverseArbitrator::onSourceListChange(std::function<void()> cb)
|
||||
std::shared_ptr<void> UniverseArbitrator::onSourceListChange(const std::function<void(DMX::Universe*)> cb)
|
||||
{
|
||||
std::unique_lock lk_ctl(mtx_control);
|
||||
// wrap the callback with a shared pointer
|
||||
auto sp = std::make_shared<std::function<void()>>(std::move(cb));
|
||||
auto sp = std::make_shared<std::function<void(DMX::Universe*)>>(std::move(cb));
|
||||
// add callback to list (as a weak pointer)
|
||||
cb_sourceListChange.push_back(sp);
|
||||
// return token that caller must keep throughout it's scope
|
||||
|
@ -169,27 +169,6 @@ std::shared_ptr<void> UniverseArbitrator::onSourceListChange(std::function<void(
|
|||
}
|
||||
|
||||
|
||||
/**
|
||||
* @brief UniverseArbitrator::doListChangeCallbacks
|
||||
*/
|
||||
void UniverseArbitrator::doListChangeCallbacks()
|
||||
{
|
||||
for (auto it = cb_sourceListChange.cbegin(); it != cb_sourceListChange.cend();)
|
||||
{
|
||||
if (auto sp = it->lock())
|
||||
{ // if the caller is still holding the token
|
||||
(*sp)();
|
||||
++it;
|
||||
}
|
||||
else
|
||||
{ // or remove the callback
|
||||
std::unique_lock lk_ctl(mtx_control);
|
||||
it = cb_sourceListChange.erase(it);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @brief UniverseArbitrator::isSyncronized
|
||||
* @return
|
||||
|
|
|
@ -79,12 +79,12 @@ public:
|
|||
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;
|
||||
std::shared_ptr<void> onSourceListChange(std::function<void()>) override;
|
||||
std::shared_ptr<void> onSourceListChange(const std::function<void(DMX::Universe*)>) override;
|
||||
virtual void setHoldLastLook(const bool) override;
|
||||
virtual bool getHoldLastLook() const override;
|
||||
|
||||
protected:
|
||||
void doListChangeCallbacks();
|
||||
inline void doListChangeCallbacks() {do_callbacks_(cb_sourceListChange);} //!< List Change Callbacks
|
||||
|
||||
// ACN::DMP::Component overrides
|
||||
virtual void rxDmpSetProperty(ACN::PDU::Message<ACN::DMP::Pdu>) override;
|
||||
|
@ -92,7 +92,7 @@ protected:
|
|||
private:
|
||||
std::unordered_map<DATA::data_header, std::shared_ptr<Universe>> sources_;
|
||||
std::vector<std::shared_ptr<void>> cb_tokens_; //!< source universe callback tokens
|
||||
std::vector<std::weak_ptr<std::function<void()>>> cb_sourceListChange; //!< list of calback functions
|
||||
std::vector<std::weak_ptr<const std::function<void(DMX::Universe*)>>> cb_sourceListChange; //!< list of calback functions
|
||||
|
||||
bool hold_last_look_;
|
||||
|
||||
|
|
Loading…
Reference in New Issue