From 5cf3ab281a592893a60800cc1a4ac869ca2ef854 Mon Sep 17 00:00:00 2001 From: Peter Newman Date: Fri, 12 Apr 2024 10:35:31 +0100 Subject: [PATCH] Add BrokerClientEntryRPT Inflator (cherry picked from commit 31c6af091fd9c0344436f2b94ca1e7335ae34dc7) --- libs/acn/BrokerClientEntryRPTInflator.cpp | 89 +++++++++++++++++++ libs/acn/BrokerClientEntryRPTInflator.h | 100 ++++++++++++++++++++++ 2 files changed, 189 insertions(+) create mode 100644 libs/acn/BrokerClientEntryRPTInflator.cpp create mode 100644 libs/acn/BrokerClientEntryRPTInflator.h diff --git a/libs/acn/BrokerClientEntryRPTInflator.cpp b/libs/acn/BrokerClientEntryRPTInflator.cpp new file mode 100644 index 000000000..6b1b2258b --- /dev/null +++ b/libs/acn/BrokerClientEntryRPTInflator.cpp @@ -0,0 +1,89 @@ +/* + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Library General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. + * + * BrokerClientEntryRPTInflator.cpp + * The Inflator for BrokerClientEntryRPT PDU + * Copyright (C) 2023 Peter Newman + */ + +#include +#include + +#include "ola/Logging.h" +#include "ola/acn/CID.h" +#include "ola/e133/E133Helper.h" +#include "ola/network/NetworkUtils.h" +#include "ola/rdm/UID.h" +#include "include/ola/strings/Format.h" +#include "libs/acn/BrokerClientEntryRPTInflator.h" + +namespace ola { +namespace acn { + +using ola::acn::CID; +using ola::network::NetworkToHost; +using ola::rdm::UID; +using ola::strings::IntToString; + +/** + * Set a BrokerClientEntryRPTHandler to run when receiving a Broker Client + * Entry RPT message. + * @param handler the callback to invoke when there is a Broker Client Entry + * RPT. + */ +void BrokerClientEntryRPTInflator::SetBrokerClientEntryRPTHandler( + BrokerClientEntryRPTHandler *handler) { + m_broker_client_entry_rpt_handler.reset(handler); +} + + +unsigned int BrokerClientEntryRPTInflator::InflatePDUBlock( + OLA_UNUSED HeaderSet *headers, + const uint8_t *data, + unsigned int len) { + broker_client_entry_rpt_pdu_data pdu_data; + if (len > sizeof(pdu_data)) { + OLA_WARN << "Got too much data, received " << len << " only expecting " + << sizeof(pdu_data); + return 0; + } + + memcpy(reinterpret_cast(&pdu_data), data, sizeof(pdu_data)); + + OLA_DEBUG << "Client Entry RPT from " << CID::FromData(pdu_data.client_cid) + << " (" << UID(pdu_data.client_uid) << ") of RPT Client Type " + << IntToString(pdu_data.rpt_client_type); + + ola::e133::E133RPTClientTypeCode client_type; + if (!ola::e133::IntToRPTClientType(pdu_data.rpt_client_type, &client_type)) { + OLA_WARN << "Unknown E1.33 RPT Client Type code " + << IntToString(pdu_data.rpt_client_type); + } + + BrokerClientEntryRPT client_entry(CID::FromData(pdu_data.client_cid), + UID(pdu_data.client_uid), + client_type, + CID::FromData(pdu_data.binding_cid)); + + if (m_broker_client_entry_rpt_handler.get()) { + m_broker_client_entry_rpt_handler->Run(headers, + client_entry); + } else { + OLA_WARN << "No Broker Client Entry RPT handler defined!"; + } + return sizeof(pdu_data); +} +} // namespace acn +} // namespace ola diff --git a/libs/acn/BrokerClientEntryRPTInflator.h b/libs/acn/BrokerClientEntryRPTInflator.h new file mode 100644 index 000000000..c7db73c4f --- /dev/null +++ b/libs/acn/BrokerClientEntryRPTInflator.h @@ -0,0 +1,100 @@ +/* + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Library General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. + * + * BrokerClientEntryRPTInflator.h + * Interface for the BrokerClientEntryRPTInflator class. + * Copyright (C) 2023 Peter Newman + */ + +#ifndef LIBS_ACN_BROKERCLIENTENTRYRPTINFLATOR_H_ +#define LIBS_ACN_BROKERCLIENTENTRYRPTINFLATOR_H_ + +#include "ola/Callback.h" +#include "ola/acn/ACNVectors.h" +#include "ola/e133/E133Enums.h" +#include "ola/rdm/UID.h" +#include "libs/acn/BaseInflator.h" + +namespace ola { +namespace acn { + +class BrokerClientEntryRPTInflator: public BaseInflator { + friend class BrokerClientEntryRPTInflatorTest; + + public: + struct BrokerClientEntryRPT { + BrokerClientEntryRPT(const ola::acn::CID &_client_cid, + const ola::rdm::UID &_client_uid, + ola::e133::E133RPTClientTypeCode _client_type_code, + const ola::acn::CID &_binding_cid) + : client_cid(_client_cid), + client_uid(_client_uid), + client_type_code(_client_type_code), + binding_cid(_binding_cid) { + } + ola::acn::CID client_cid; + ola::rdm::UID client_uid; + ola::e133::E133RPTClientTypeCode client_type_code; + ola::acn::CID binding_cid; + }; + + + // These are pointers so the callers don't have to pull in all the headers. + typedef ola::Callback2 BrokerClientEntryRPTHandler; + + BrokerClientEntryRPTInflator() + : BaseInflator() { + } + ~BrokerClientEntryRPTInflator() {} + + uint32_t Id() const { return ola::acn::CLIENT_PROTOCOL_RPT; } + + PACK( + struct broker_client_entry_rpt_pdu_data_s { + uint8_t client_cid[ola::acn::CID::CID_LENGTH]; + uint8_t client_uid[ola::rdm::UID::LENGTH]; + uint8_t rpt_client_type; + uint8_t binding_cid[ola::acn::CID::CID_LENGTH]; + }); + typedef struct broker_client_entry_rpt_pdu_data_s + broker_client_entry_rpt_pdu_data; + + void SetBrokerClientEntryRPTHandler(BrokerClientEntryRPTHandler *handler); + + protected: + // The 'header' is 0 bytes in length. + bool DecodeHeader(HeaderSet*, + const uint8_t*, + unsigned int, + unsigned int *bytes_used) { + *bytes_used = 0; + return true; + } + + void ResetHeaderField() {} // namespace noop + + unsigned int InflatePDUBlock(HeaderSet *headers, + const uint8_t *data, + unsigned int len); + + private: + std::auto_ptr m_broker_client_entry_rpt_handler; +}; +} // namespace acn +} // namespace ola +#endif // LIBS_ACN_BROKERCLIENTENTRYRPTINFLATOR_H_