From 41686e32af803c9d11e237dc87b13cfc7390e123 Mon Sep 17 00:00:00 2001 From: Kevin Matz Date: Thu, 2 Sep 2021 13:17:47 -0400 Subject: [PATCH] publicly indicate if universe is tx or rx --- protocols/sacn/universe.cpp | 28 ++++++++++++++++++++-------- protocols/sacn/universe.h | 2 ++ 2 files changed, 22 insertions(+), 8 deletions(-) diff --git a/protocols/sacn/universe.cpp b/protocols/sacn/universe.cpp index 06b30c4..aff551d 100644 --- a/protocols/sacn/universe.cpp +++ b/protocols/sacn/universe.cpp @@ -161,12 +161,25 @@ void Universe::setProvenance(std::shared_ptr source) */ bool Universe::isSyncronized() const { - return (sync_data_ != nullptr); + return (!sync_data_); }; +/** + * @brief Universe::isEditable + * @return + */ +bool Universe::isEditable() const +{ + return (source_); +} + + void Universe::setValue (const uint16_t address, const uint8_t value) { + if (!isEditable()) + return; + // address valid? if (address < 1 || address > null_start_data.size()) return; @@ -190,6 +203,9 @@ void Universe::setValue (const uint16_t address, const uint8_t value) void Universe::setValue (const uint16_t start, const uint16_t footprint, const uint8_t* data) { + if (!isEditable()) + return; + // start and footprint valid? if (start < 1 || start + footprint >= null_start_data.size()) return; @@ -328,8 +344,8 @@ void Universe::sACNsend() const */ void Universe::tx_loop_() { - // rx universes, by definition, won't have a source set - if (!source_) + // rx universes, by definition, don't need to tx. + if (!isEditable()) return; // run at least 1 loop @@ -401,11 +417,7 @@ void Universe::tx_loop_() // sleep before the next cycle if (enable) - { - mtx.lock(); - tx_request_.wait_for(mtx, sleep); - mtx.unlock(); - } + tx_request_.wait_for(mtx, sleep); } } diff --git a/protocols/sacn/universe.h b/protocols/sacn/universe.h index 9ac5b96..5462834 100644 --- a/protocols/sacn/universe.h +++ b/protocols/sacn/universe.h @@ -58,6 +58,8 @@ public: virtual bool isSyncronized() const; virtual void synchronize(uint8_t = 0); + bool isEditable() const; + // DMX::Universe overrides void setValue (const uint16_t address, const uint8_t value) override; void setValue (const uint16_t start, const uint16_t footprint,