From 0c9c85830ee1bf030b986911876760066cdba9c6 Mon Sep 17 00:00:00 2001 From: Kevin Matz Date: Fri, 9 Dec 2022 16:04:31 -0500 Subject: [PATCH] use dynamic casts if RTTI is an available feature --- protocol/esta/sacn/CMakeLists.txt | 1 + protocol/esta/sacn/arbitratinguniverse.cpp | 5 ++ protocol/esta/sacn/receiver.cpp | 64 ++++++++++++++++++---- protocol/esta/sacn/universe.cpp | 5 ++ protocol/esta/sacn/universesender.cpp | 6 ++ 5 files changed, 71 insertions(+), 10 deletions(-) diff --git a/protocol/esta/sacn/CMakeLists.txt b/protocol/esta/sacn/CMakeLists.txt index b62363f..5ca1485 100644 --- a/protocol/esta/sacn/CMakeLists.txt +++ b/protocol/esta/sacn/CMakeLists.txt @@ -1,6 +1,7 @@ project(${PROJECT_NAME}_sacn VERSION 0.3.1 LANGUAGES CXX) add_library(${PROJECT_NAME} SHARED) +configure_file(../../config.h.in config.h) target_sources(${PROJECT_NAME} PUBLIC diff --git a/protocol/esta/sacn/arbitratinguniverse.cpp b/protocol/esta/sacn/arbitratinguniverse.cpp index 4e93df6..7dcd9b1 100644 --- a/protocol/esta/sacn/arbitratinguniverse.cpp +++ b/protocol/esta/sacn/arbitratinguniverse.cpp @@ -24,6 +24,7 @@ #include "arbitratinguniverse.h" #include +#include "config.h" namespace sACN { @@ -151,7 +152,11 @@ void ArbitratingUniverse::deleteSourceUniverse(const DATA::data_header& src) */ void ArbitratingUniverse::dataChangedNotifier(DMX::Universe* dmx) { +#ifdef RTTI_ENABLED + auto sacn = dynamic_cast(dmx); +#else auto sacn = static_cast(dmx); +#endif auto universe = dominant_(); if (!universe) return; diff --git a/protocol/esta/sacn/receiver.cpp b/protocol/esta/sacn/receiver.cpp index 2ea719c..48869c2 100644 --- a/protocol/esta/sacn/receiver.cpp +++ b/protocol/esta/sacn/receiver.cpp @@ -22,6 +22,7 @@ SOFTWARE. */ +#include "config.h" #include "pdu.h" #include "receiver.h" @@ -137,7 +138,11 @@ void Receiver::dataReceiver(ACN::PDU::Message root) // a PDU::Block is guaranteed to have been instantiated, but if the input // stream failed, it will not list any PDU. OK to loop without checking // the state of the stream. +#ifdef RTTI_ENABLED + auto block = std::dynamic_pointer_cast>(root->data()); +#else auto block = std::static_pointer_cast>(root->data()); +#endif for(auto const &frame : *block->pdu) { /// > \cite sACN 6.2.1 E1.31 Data Packet: Vector @@ -168,7 +173,11 @@ void Receiver::extendedReceiver(ACN::PDU::Message root) // a PDU::Block is guaranteed to have been instantiated, but if the input // stream failed, it will not list any PDU. OK to loop without checking // the state of the stream. +#ifdef RTTI_ENABLED + auto block = std::dynamic_pointer_cast>(root->data()); +#else auto block = std::static_pointer_cast>(root->data()); +#endif for(auto const &frame : *block->pdu) { switch(frame->vector()) { @@ -196,10 +205,13 @@ void Receiver::extendedReceiver(ACN::PDU::Message root) * * Merging will be based on frame header. PDU data will be read as a block of * DMP PDUs and passed to the universe. - * */ void Receiver::dataFrameHandler(ACN::PDU::Message frame) { - auto metadata = std::static_pointer_cast(frame->header()); +#ifdef RTTI_ENABLED + auto metadata = std::dynamic_pointer_cast(frame->header()); +#else + auto metadata = std::static_pointer_cast(frame->header()); +#endif if (!universes_.count(metadata->universe)) return; // not subscribed to this universe @@ -263,11 +275,20 @@ void Receiver::dataFrameHandler(ACN::PDU::Message frame) { else { subscribe(metadata->sync_address); +#ifdef RTTI_ENABLED + auto block = std::dynamic_pointer_cast>(frame->data()); +#else auto block = std::static_pointer_cast>(frame->data()); +#endif if (!block->pdu->empty()) { +#ifdef RTTI_ENABLED + auto dmp = std::dynamic_pointer_cast(block->pdu->front()); + auto list = std::dynamic_pointer_cast(dmp->data()); +#else auto dmp = std::static_pointer_cast(block->pdu->front()); auto list = std::static_pointer_cast(dmp->data()); +#endif if (!list->properties.empty()) { const auto & [_, data] = list->properties.front(); @@ -293,7 +314,11 @@ void Receiver::dataFrameHandler(ACN::PDU::Message frame) { return; // too far out of sequence // PDU data will be a block of DMP +#ifdef RTTI_ENABLED + auto block = std::dynamic_pointer_cast>(frame->data()); +#else auto block = std::static_pointer_cast>(frame->data()); +#endif universe->setMetadata(metadata); universe->DmpReceiver(block); } @@ -305,7 +330,11 @@ void Receiver::dataFrameHandler(ACN::PDU::Message frame) { */ void Receiver::syncFrameHandler(ACN::PDU::Message frame) { +#ifdef RTTI_ENABLED + auto header = std::dynamic_pointer_cast(frame->header()); +#else auto header = std::static_pointer_cast(frame->header()); +#endif universes_.at(header->sync_address)->synchronize(header->sequence_number); } @@ -315,7 +344,11 @@ void Receiver::syncFrameHandler(ACN::PDU::Message frame) * @param frame */ void Receiver::discoveryFrameHandler(ACN::PDU::Message frame) { +#ifdef RTTI_ENABLED + auto block = std::dynamic_pointer_cast>(frame->data()); +#else auto block = std::static_pointer_cast>(frame->data()); +#endif for(auto const &pdu : *block->pdu) { /// > \cite sACN 8 Universe Discovery Layer @@ -339,14 +372,25 @@ void Receiver::discoveryFrameHandler(ACN::PDU::Message frame) { * @param pdu */ void Receiver::discoveryListHanlder(ACN::PDU::Message pdu) { - auto rlpHeader = std::static_pointer_cast - (pdu->parent()->parent()->header()); - auto frameHeader = std::static_pointer_cast - (pdu->parent()->header()); - auto header = std::static_pointer_cast - (pdu->header()); - auto data = std::static_pointer_cast - (pdu->data()); +#ifdef RTTI_ENABLED + auto rlpHeader = std::dynamic_pointer_cast + (pdu->parent()->parent()->header()); + auto frameHeader = std::dynamic_pointer_cast + (pdu->parent()->header()); + auto header = std::dynamic_pointer_cast + (pdu->header()); + auto data = std::dynamic_pointer_cast + (pdu->data()); +#else + auto rlpHeader = std::static_pointer_cast + (pdu->parent()->parent()->header()); + auto frameHeader = std::static_pointer_cast + (pdu->parent()->header()); + auto header = std::static_pointer_cast + (pdu->header()); + auto data = std::static_pointer_cast + (pdu->data()); +#endif // on the first page: if (header->page == 0) diff --git a/protocol/esta/sacn/universe.cpp b/protocol/esta/sacn/universe.cpp index 121a827..b28a929 100644 --- a/protocol/esta/sacn/universe.cpp +++ b/protocol/esta/sacn/universe.cpp @@ -22,6 +22,7 @@ SOFTWARE. */ +#include "config.h" #include "universe.h" namespace sACN { @@ -278,7 +279,11 @@ void Universe::rxDmpSetProperty(ACN::PDU::Message message) // only act on the first property pair in the data if (!message->data()) return; +#ifdef RTTI_ENABLED + auto set_data = std::dynamic_pointer_cast(message->data()); +#else auto set_data = std::static_pointer_cast(message->data()); +#endif if (set_data->properties.empty()) return; const auto& [range, data] = set_data->properties.front(); diff --git a/protocol/esta/sacn/universesender.cpp b/protocol/esta/sacn/universesender.cpp index 816edad..b3576ad 100644 --- a/protocol/esta/sacn/universesender.cpp +++ b/protocol/esta/sacn/universesender.cpp @@ -21,6 +21,8 @@ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */ + +#include "config.h" #include "universesender.h" #include "universe.h" #include "source.h" @@ -199,7 +201,11 @@ void UniverseSender::update_dmp_() std::unique_lock lk_ctl(mtx_control); // header segment +#ifdef RTTI_ENABLED + auto addrtyp = std::dynamic_pointer_cast(dmp_->header()); +#else auto addrtyp = std::static_pointer_cast(dmp_->header()); +#endif // property range ACN::DMP::Range pr(*addrtyp);