diff --git a/ecal/core/include/ecal/ecal_publisher.h b/ecal/core/include/ecal/ecal_publisher.h index cc028f86e2..f48e94a84d 100644 --- a/ecal/core/include/ecal/ecal_publisher.h +++ b/ecal/core/include/ecal/ecal_publisher.h @@ -190,14 +190,14 @@ namespace eCAL bool ClearAttribute(const std::string& attr_name_); /** - * @brief Set the specific topic id. + * @brief Set the specific topic filter id. * - * @param id_ The topic id for subscriber side filtering (0 == no id). + * @param filter_id_ The topic id for subscriber side filtering (0 == no id). * * @return True if it succeeds, false if it fails. **/ ECAL_API_EXPORTED_MEMBER - bool SetID(long long id_); + bool SetID(long long filter_id_); /** * @brief Send a message to all subscribers. @@ -260,7 +260,7 @@ namespace eCAL * @return True if created, false if not. **/ ECAL_API_EXPORTED_MEMBER - bool IsCreated() const {return(m_created);} + bool IsCreated() const { return(m_datawriter != nullptr); } /** * @brief Query if the publisher is subscribed. @@ -312,10 +312,9 @@ namespace eCAL ECAL_API_EXPORTED_MEMBER std::string Dump(const std::string& indent_ = "") const; - protected: + private: // class members std::shared_ptr m_datawriter; - long long m_id; - bool m_created; + long long m_filter_id; }; } diff --git a/ecal/core/include/ecal/ecal_subscriber.h b/ecal/core/include/ecal/ecal_subscriber.h index 31120aaec1..fc498d5056 100644 --- a/ecal/core/include/ecal/ecal_subscriber.h +++ b/ecal/core/include/ecal/ecal_subscriber.h @@ -171,12 +171,12 @@ namespace eCAL /** * @brief Set a set of id's to prefiltering topics (see CPublisher::SetID). * - * @param id_set_ Set of id's. + * @param filter_ids_ Set of filter id's. * * @return True if it succeeds, false if it fails. **/ ECAL_API_EXPORTED_MEMBER - bool SetID(const std::set& id_set_); + bool SetID(const std::set& filter_ids_); /** * @brief Sets subscriber attribute. @@ -267,7 +267,7 @@ namespace eCAL * @return true if created, false if not. **/ ECAL_API_EXPORTED_MEMBER - bool IsCreated() const {return(m_created);} + bool IsCreated() const { return(m_datareader != nullptr); } /** * @brief Query if the subscriber is published. @@ -319,9 +319,8 @@ namespace eCAL ECAL_API_EXPORTED_MEMBER std::string Dump(const std::string& indent_ = "") const; - protected: + private: // class members std::shared_ptr m_datareader; - bool m_created; }; } diff --git a/ecal/core/src/cimpl/ecal_publisher_cimpl.cpp b/ecal/core/src/cimpl/ecal_publisher_cimpl.cpp index cec91d2776..cc32d00e35 100644 --- a/ecal/core/src/cimpl/ecal_publisher_cimpl.cpp +++ b/ecal/core/src/cimpl/ecal_publisher_cimpl.cpp @@ -1,6 +1,6 @@ /* ========================= eCAL LICENSE ================================= * - * Copyright (C) 2016 - 2019 Continental Corporation + * Copyright (C) 2016 - 2024 Continental Corporation * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. diff --git a/ecal/core/src/pubsub/ecal_publisher.cpp b/ecal/core/src/pubsub/ecal_publisher.cpp index 5dbd7736f6..68547633fc 100644 --- a/ecal/core/src/pubsub/ecal_publisher.cpp +++ b/ecal/core/src/pubsub/ecal_publisher.cpp @@ -40,8 +40,7 @@ namespace eCAL { CPublisher::CPublisher() : m_datawriter(nullptr), - m_id(0), - m_created(false) + m_filter_id(0) { } @@ -65,10 +64,9 @@ namespace eCAL **/ CPublisher::CPublisher(CPublisher&& rhs) noexcept : m_datawriter(std::move(rhs.m_datawriter)), - m_id(rhs.m_id), - m_created(rhs.m_created) + m_filter_id(rhs.m_filter_id) { - rhs.m_created = false; + rhs.m_datawriter = nullptr; } /** @@ -79,19 +77,18 @@ namespace eCAL // Call destroy, to clean up the current state, then afterwards move all elements Destroy(); - m_datawriter = std::move(rhs.m_datawriter); - m_id = rhs.m_id; - m_created = rhs.m_created; - - rhs.m_created = false; + m_datawriter = std::move(rhs.m_datawriter); + m_filter_id = rhs.m_filter_id; + + rhs.m_datawriter = nullptr; return *this; } bool CPublisher::Create(const std::string& topic_name_, const SDataTypeInformation& data_type_info_, const Publisher::Configuration& config_) { - if (m_created) return(false); - if (topic_name_.empty()) return(false); + if (m_datawriter != nullptr) return(false); + if (topic_name_.empty()) return(false); // create datawriter m_datawriter = std::make_shared(data_type_info_, BuildWriterAttributes(topic_name_, config_, GetTransportLayerConfiguration(), GetRegistrationConfiguration())); @@ -100,8 +97,7 @@ namespace eCAL g_pubgate()->Register(topic_name_, m_datawriter); // we made it :-) - m_created = true; - return(m_created); + return(true); } bool CPublisher::Create(const std::string& topic_name_) @@ -111,7 +107,7 @@ namespace eCAL bool CPublisher::Destroy() { - if(!m_created) return(false); + if (m_datawriter == nullptr) return(false); // unregister datawriter if(g_pubgate() != nullptr) g_pubgate()->Unregister(m_datawriter->GetTopicName(), m_datawriter); @@ -125,8 +121,6 @@ namespace eCAL m_datawriter.reset(); // we made it :-) - m_created = false; - return(true); } @@ -148,10 +142,10 @@ namespace eCAL return m_datawriter->ClearAttribute(attr_name_); } - bool CPublisher::SetID(long long id_) + bool CPublisher::SetID(long long filter_id_) { - m_id = id_; - return(true); + m_filter_id = filter_id_; + return true; } size_t CPublisher::Send(const void* const buf_, const size_t len_, const long long time_ /* = DEFAULT_TIME_ARGUMENT */) @@ -162,7 +156,7 @@ namespace eCAL size_t CPublisher::Send(CPayloadWriter& payload_, long long time_) { - if (!m_created) return(0); + if (m_datawriter == nullptr) return 0; // in an optimization case the // publisher can send an empty package @@ -177,7 +171,7 @@ namespace eCAL // send content via data writer layer const long long write_time = (time_ == DEFAULT_TIME_ARGUMENT) ? eCAL::Time::GetMicroSeconds() : time_; - const size_t written_bytes = m_datawriter->Write(payload_, write_time, m_id); + const size_t written_bytes = m_datawriter->Write(payload_, write_time, m_filter_id); // return number of bytes written return written_bytes; @@ -242,7 +236,6 @@ namespace eCAL out << indent_ << "----------------------" << '\n'; out << indent_ << " class CPublisher" << '\n'; out << indent_ << "----------------------" << '\n'; - out << indent_ << "m_created: " << m_created << '\n'; if((m_datawriter != nullptr) && m_datawriter->IsCreated()) out << indent_ << m_datawriter->Dump(" "); out << '\n'; diff --git a/ecal/core/src/pubsub/ecal_subscriber.cpp b/ecal/core/src/pubsub/ecal_subscriber.cpp index bb2340812f..f5ef6d50aa 100644 --- a/ecal/core/src/pubsub/ecal_subscriber.cpp +++ b/ecal/core/src/pubsub/ecal_subscriber.cpp @@ -36,8 +36,7 @@ namespace eCAL { CSubscriber::CSubscriber() : - m_datareader(nullptr), - m_created(false) + m_datareader(nullptr) { } @@ -57,10 +56,9 @@ namespace eCAL } CSubscriber::CSubscriber(CSubscriber&& rhs) noexcept : - m_datareader(std::move(rhs.m_datareader)), - m_created(rhs.m_created) + m_datareader(std::move(rhs.m_datareader)) { - rhs.m_created = false; + rhs.m_datareader = nullptr; } CSubscriber& CSubscriber::operator=(CSubscriber&& rhs) noexcept @@ -69,17 +67,16 @@ namespace eCAL Destroy(); m_datareader = std::move(rhs.m_datareader); - m_created = rhs.m_created; - rhs.m_created = false; + rhs.m_datareader = nullptr; return *this; } bool CSubscriber::Create(const std::string& topic_name_, const SDataTypeInformation& data_type_info_, const Subscriber::Configuration& config_) { - if (m_created) return(false); - if (topic_name_.empty()) return(false); + if (m_datareader != nullptr) return(false); + if (topic_name_.empty()) return(false); // create datareader m_datareader = std::make_shared(data_type_info_, BuildReaderAttributes(topic_name_, config_, GetPublisherConfiguration(), GetTransportLayerConfiguration(), GetRegistrationConfiguration())); @@ -88,8 +85,7 @@ namespace eCAL g_subgate()->Register(topic_name_, m_datareader); // we made it :-) - m_created = true; - return(m_created); + return(true); } bool CSubscriber::Create(const std::string& topic_name_) @@ -99,7 +95,7 @@ namespace eCAL bool CSubscriber::Destroy() { - if(!m_created) return(false); + if (m_datareader == nullptr) return(false); // remove receive callback RemReceiveCallback(); @@ -117,15 +113,13 @@ namespace eCAL m_datareader.reset(); // we made it :-) - m_created = false; - return(true); } - bool CSubscriber::SetID(const std::set& id_set_) + bool CSubscriber::SetID(const std::set& filter_ids_) { if (m_datareader == nullptr) return(false); - m_datareader->SetID(id_set_); + m_datareader->SetFilterIDs(filter_ids_); return(true); } @@ -143,7 +137,7 @@ namespace eCAL bool CSubscriber::ReceiveBuffer(std::string& buf_, long long* time_ /* = nullptr */, int rcv_timeout_ /* = 0 */) const { - if (!m_created) return(false); + if (m_datareader == nullptr) return(false); return(m_datareader->Read(buf_, time_, rcv_timeout_)); } @@ -219,7 +213,6 @@ namespace eCAL out << indent_ << "----------------------" << '\n'; out << indent_ << " class CSubscriber " << '\n'; out << indent_ << "----------------------" << '\n'; - out << indent_ << "m_created: " << m_created << '\n'; if((m_datareader != nullptr) && m_datareader->IsCreated()) out << indent_ << m_datareader->Dump(" "); out << '\n'; diff --git a/ecal/core/src/readwrite/ecal_reader.cpp b/ecal/core/src/readwrite/ecal_reader.cpp index fedd83e29f..ebf9d46195 100644 --- a/ecal/core/src/readwrite/ecal_reader.cpp +++ b/ecal/core/src/readwrite/ecal_reader.cpp @@ -267,9 +267,9 @@ namespace eCAL return(true); } - void CDataReader::SetID(const std::set& id_set_) + void CDataReader::SetFilterIDs(const std::set& filter_ids_) { - m_id_set = id_set_; + m_id_set = filter_ids_; } void CDataReader::ApplyPublication(const SPublicationInfo& publication_info_, const SDataTypeInformation& data_type_info_, const SLayerStates& pub_layer_states_) diff --git a/ecal/core/src/readwrite/ecal_reader.h b/ecal/core/src/readwrite/ecal_reader.h index 5c01ce4e86..32c0b271cc 100644 --- a/ecal/core/src/readwrite/ecal_reader.h +++ b/ecal/core/src/readwrite/ecal_reader.h @@ -79,7 +79,7 @@ namespace eCAL bool SetAttribute(const std::string& attr_name_, const std::string& attr_value_); bool ClearAttribute(const std::string& attr_name_); - void SetID(const std::set& id_set_); + void SetFilterIDs(const std::set& filter_ids_); void ApplyPublication(const SPublicationInfo& publication_info_, const SDataTypeInformation& data_type_info_, const SLayerStates& pub_layer_states_); void RemovePublication(const SPublicationInfo& publication_info_); diff --git a/ecal/core/src/readwrite/ecal_writer.cpp b/ecal/core/src/readwrite/ecal_writer.cpp index e4d9c3b5c3..9d6ceaca15 100644 --- a/ecal/core/src/readwrite/ecal_writer.cpp +++ b/ecal/core/src/readwrite/ecal_writer.cpp @@ -159,7 +159,7 @@ namespace eCAL return true; } - size_t CDataWriter::Write(CPayloadWriter& payload_, long long time_, long long id_) + size_t CDataWriter::Write(CPayloadWriter& payload_, long long time_, long long filter_id_) { // get payload buffer size (one time, to avoid multiple computations) const size_t payload_buf_size(payload_.GetSize()); @@ -186,7 +186,7 @@ namespace eCAL } // prepare counter and internal states - const size_t snd_hash = PrepareWrite(id_, payload_buf_size); + const size_t snd_hash = PrepareWrite(filter_id_, payload_buf_size); // did we write anything bool written(false); diff --git a/ecal/core/src/readwrite/ecal_writer.h b/ecal/core/src/readwrite/ecal_writer.h index fae877810e..14fffc4175 100644 --- a/ecal/core/src/readwrite/ecal_writer.h +++ b/ecal/core/src/readwrite/ecal_writer.h @@ -79,7 +79,7 @@ namespace eCAL bool Stop(); - size_t Write(CPayloadWriter& payload_, long long time_, long long id_); + size_t Write(CPayloadWriter& payload_, long long time_, long long filter_id_); bool SetDataTypeInformation(const SDataTypeInformation& topic_info_);