diff --git a/ecal/core/src/readwrite/ecal_writer.cpp b/ecal/core/src/readwrite/ecal_writer.cpp index 806dedab4a..6b77f7aa23 100644 --- a/ecal/core/src/readwrite/ecal_writer.cpp +++ b/ecal/core/src/readwrite/ecal_writer.cpp @@ -91,7 +91,7 @@ namespace eCAL { // initialize layer modes with configuration settings #if ECAL_CORE_TRANSPORT_UDP - m_writer.udp_mc_mode.requested = Config::GetPublisherUdpMulticastMode(); + m_writer.udp_mode.requested = Config::GetPublisherUdpMulticastMode(); #endif #if ECAL_CORE_TRANSPORT_SHM m_writer.shm_mode.requested = Config::GetPublisherShmMode(); @@ -146,7 +146,7 @@ namespace eCAL Register(false); // create udp multicast layer - SetUseUdpMC(m_writer.udp_mc_mode.requested); + SetUseUdpMC(m_writer.udp_mode.requested); // create shm layer SetUseShm(m_writer.shm_mode.requested); @@ -176,17 +176,17 @@ namespace eCAL // destroy udp multicast writer #if ECAL_CORE_TRANSPORT_UDP - m_writer.udp_mc.Destroy(); + m_writer.udp.reset(); #endif // destroy memory file writer #if ECAL_CORE_TRANSPORT_SHM - m_writer.shm.Destroy(); + m_writer.shm.reset(); #endif // destroy tcp writer #if ECAL_CORE_TRANSPORT_TCP - m_writer.tcp.Destroy(); + m_writer.tcp.reset(); #endif // reset defaults @@ -322,6 +322,8 @@ namespace eCAL bool CDataWriter::ShmSetBufferCount(size_t buffering_) { #if ECAL_CORE_TRANSPORT_SHM + if (!m_writer.shm) return false; + if (buffering_ < 1) { Logging::Log(log_level_error, m_topic_name + "::CDataWriter::ShmSetBufferCount minimal number of memory files is 1 !"); @@ -332,7 +334,7 @@ namespace eCAL // adapt number of used memory files if (m_created) { - m_writer.shm.SetBufferCount(buffering_); + m_writer.shm->SetBufferCount(buffering_); } return true; @@ -423,7 +425,7 @@ namespace eCAL const bool allow_zero_copy = m_zero_copy // zero copy mode activated by user && m_writer.shm_mode.activated // shm layer active - && !m_writer.udp_mc_mode.activated + && !m_writer.udp_mode.activated && !m_writer.tcp_mode.activated; // create a payload copy for all layer @@ -443,7 +445,7 @@ namespace eCAL // SHM //////////////////////////////////////////////////////////////////////////// #if ECAL_CORE_TRANSPORT_SHM - if (m_writer.shm_mode.activated) + if (m_writer.shm && m_writer.shm_mode.activated) { #ifndef NDEBUG // log it @@ -465,7 +467,7 @@ namespace eCAL wattr.acknowledge_timeout_ms = m_acknowledge_timeout_ms; // prepare send - if (m_writer.shm.PrepareWrite(wattr)) + if (m_writer.shm->PrepareWrite(wattr)) { // register new to update listening subscribers and rematch Register(true); @@ -476,7 +478,7 @@ namespace eCAL if (allow_zero_copy) { // write to shm layer (write content into the opened memory file without additional copy) - shm_sent = m_writer.shm.Write(payload_, wattr); + shm_sent = m_writer.shm->Write(payload_, wattr); } // multiple layer are active -> we make a copy and use that one else @@ -484,7 +486,7 @@ namespace eCAL // wrap the buffer into a payload object CBufferPayloadWriter payload_buf(m_payload_buffer.data(), m_payload_buffer.size()); // write to shm layer (write content into the opened memory file without additional copy) - shm_sent = m_writer.shm.Write(payload_buf, wattr); + shm_sent = m_writer.shm->Write(payload_buf, wattr); } m_writer.shm_mode.confirmed = true; @@ -509,7 +511,7 @@ namespace eCAL // UDP (MC) //////////////////////////////////////////////////////////////////////////// #if ECAL_CORE_TRANSPORT_UDP - if (m_writer.udp_mc_mode.activated) + if (m_writer.udp && m_writer.udp_mode.activated) { #ifndef NDEBUG // log it @@ -537,7 +539,7 @@ namespace eCAL wattr.loopback = loopback; // prepare send - if (m_writer.udp_mc.PrepareWrite(wattr)) + if (m_writer.udp->PrepareWrite(wattr)) { // register new to update listening subscribers and rematch Register(true); @@ -545,8 +547,8 @@ namespace eCAL } // write to udp multicast layer - udp_mc_sent = m_writer.udp_mc.Write(m_payload_buffer.data(), wattr); - m_writer.udp_mc_mode.confirmed = true; + udp_mc_sent = m_writer.udp->Write(m_payload_buffer.data(), wattr); + m_writer.udp_mode.confirmed = true; } written |= udp_mc_sent; @@ -568,7 +570,7 @@ namespace eCAL // TCP //////////////////////////////////////////////////////////////////////////// #if ECAL_CORE_TRANSPORT_TCP - if (m_writer.tcp_mode.activated) + if (m_writer.tcp && m_writer.tcp_mode.activated) { #ifndef NDEBUG // log it @@ -587,7 +589,7 @@ namespace eCAL wattr.time = time_; // write to tcp layer - tcp_sent = m_writer.tcp.Write(m_payload_buffer.data(), wattr); + tcp_sent = m_writer.tcp->Write(m_payload_buffer.data(), wattr); m_writer.tcp_mode.confirmed = true; } written |= tcp_sent; @@ -625,13 +627,13 @@ namespace eCAL // add a new local subscription #if ECAL_CORE_TRANSPORT_UDP - m_writer.udp_mc.AddLocConnection(local_info_.process_id, local_info_.topic_id, reader_par_); + if (m_writer.udp) m_writer.udp->AddLocConnection(local_info_.process_id, local_info_.topic_id, reader_par_); #endif #if ECAL_CORE_TRANSPORT_SHM - m_writer.shm.AddLocConnection(local_info_.process_id, local_info_.topic_id, reader_par_); + if (m_writer.shm) m_writer.shm->AddLocConnection(local_info_.process_id, local_info_.topic_id, reader_par_); #endif #if ECAL_CORE_TRANSPORT_TCP - m_writer.tcp.AddLocConnection(local_info_.process_id, local_info_.topic_id, reader_par_); + if (m_writer.tcp) m_writer.tcp->AddLocConnection(local_info_.process_id, local_info_.topic_id, reader_par_); #endif #ifndef NDEBUG @@ -650,13 +652,13 @@ namespace eCAL // remove a local subscription #if ECAL_CORE_TRANSPORT_UDP - m_writer.udp_mc.RemLocConnection(local_info_.process_id, local_info_.topic_id); + if (m_writer.udp) m_writer.udp->RemLocConnection(local_info_.process_id, local_info_.topic_id); #endif #if ECAL_CORE_TRANSPORT_SHM - m_writer.shm.RemLocConnection(local_info_.process_id, local_info_.topic_id); + if (m_writer.shm) m_writer.shm->RemLocConnection(local_info_.process_id, local_info_.topic_id); #endif #if ECAL_CORE_TRANSPORT_TCP - m_writer.tcp.RemLocConnection(local_info_.process_id, local_info_.topic_id); + if (m_writer.tcp) m_writer.tcp->RemLocConnection(local_info_.process_id, local_info_.topic_id); #endif #ifndef NDEBUG @@ -679,13 +681,13 @@ namespace eCAL // add a new external subscription #if ECAL_CORE_TRANSPORT_UDP - m_writer.udp_mc.AddExtConnection(external_info_.host_name, external_info_.process_id, external_info_.topic_id, reader_par_); + if (m_writer.udp) m_writer.udp->AddExtConnection(external_info_.host_name, external_info_.process_id, external_info_.topic_id, reader_par_); #endif #if ECAL_CORE_TRANSPORT_SHM - m_writer.shm.AddExtConnection(external_info_.host_name, external_info_.process_id, external_info_.topic_id, reader_par_); + if (m_writer.shm) m_writer.shm->AddExtConnection(external_info_.host_name, external_info_.process_id, external_info_.topic_id, reader_par_); #endif #if ECAL_CORE_TRANSPORT_TCP - m_writer.tcp.AddExtConnection(external_info_.host_name, external_info_.process_id, external_info_.topic_id, reader_par_); + if (m_writer.tcp) m_writer.tcp->AddExtConnection(external_info_.host_name, external_info_.process_id, external_info_.topic_id, reader_par_); #endif #ifndef NDEBUG @@ -704,13 +706,13 @@ namespace eCAL // remove external subscription #if ECAL_CORE_TRANSPORT_UDP - m_writer.udp_mc.RemExtConnection(external_info_.host_name, external_info_.process_id, external_info_.topic_id); + if (m_writer.udp) m_writer.udp->RemExtConnection(external_info_.host_name, external_info_.process_id, external_info_.topic_id); #endif #if ECAL_CORE_TRANSPORT_SHM - m_writer.shm.RemExtConnection(external_info_.host_name, external_info_.process_id, external_info_.topic_id); + if (m_writer.shm) m_writer.shm->RemExtConnection(external_info_.host_name, external_info_.process_id, external_info_.topic_id); #endif #if ECAL_CORE_TRANSPORT_TCP - m_writer.tcp.RemExtConnection(external_info_.host_name, external_info_.process_id, external_info_.topic_id); + if (m_writer.tcp) m_writer.tcp->RemExtConnection(external_info_.host_name, external_info_.process_id, external_info_.topic_id); #endif } @@ -815,36 +817,39 @@ namespace eCAL #if ECAL_CORE_TRANSPORT_UDP // udp multicast layer + if (m_writer.udp) { eCAL::Registration::TLayer udp_tlayer; udp_tlayer.type = tl_ecal_udp_mc; udp_tlayer.version = 1; - udp_tlayer.confirmed = m_writer.udp_mc_mode.confirmed; - udp_tlayer.par_layer.layer_par_udpmc = m_writer.udp_mc.GetConnectionParameter().layer_par_udpmc; + udp_tlayer.confirmed = m_writer.udp_mode.confirmed; + udp_tlayer.par_layer.layer_par_udpmc = m_writer.udp->GetConnectionParameter().layer_par_udpmc; ecal_reg_sample_topic.tlayer.push_back(udp_tlayer); } #endif #if ECAL_CORE_TRANSPORT_SHM // shm layer + if (m_writer.shm) { eCAL::Registration::TLayer shm_tlayer; shm_tlayer.type = tl_ecal_shm; shm_tlayer.version = 1; shm_tlayer.confirmed = m_writer.shm_mode.confirmed; - shm_tlayer.par_layer.layer_par_shm = m_writer.shm.GetConnectionParameter().layer_par_shm; + shm_tlayer.par_layer.layer_par_shm = m_writer.shm->GetConnectionParameter().layer_par_shm; ecal_reg_sample_topic.tlayer.push_back(shm_tlayer); } #endif #if ECAL_CORE_TRANSPORT_TCP // tcp layer + if (m_writer.tcp) { eCAL::Registration::TLayer tcp_tlayer; tcp_tlayer.type = tl_ecal_tcp; tcp_tlayer.version = 1; tcp_tlayer.confirmed = m_writer.tcp_mode.confirmed; - tcp_tlayer.par_layer.layer_par_tcp = m_writer.tcp.GetConnectionParameter().layer_par_tcp; + tcp_tlayer.par_layer.layer_par_tcp = m_writer.tcp->GetConnectionParameter().layer_par_tcp; ecal_reg_sample_topic.tlayer.push_back(tcp_tlayer); } #endif @@ -971,7 +976,7 @@ namespace eCAL void CDataWriter::SetUseUdpMC(TLayer::eSendMode mode_) { #if ECAL_CORE_TRANSPORT_UDP - m_writer.udp_mc_mode.requested = mode_; + m_writer.udp_mode.requested = mode_; if (!m_created) return; // log send mode @@ -981,20 +986,14 @@ namespace eCAL { case TLayer::eSendMode::smode_auto: case TLayer::eSendMode::smode_on: - if (m_writer.udp_mc.Create(m_host_name, m_topic_name, m_topic_id)) - { + m_writer.udp = std::make_unique(m_host_name, m_topic_name, m_topic_id); #ifndef NDEBUG - Logging::Log(log_level_debug4, m_topic_name + "::CDataWriter::Create::UDP_MC_WRITER - SUCCESS"); + Logging::Log(log_level_debug4, m_topic_name + "::CDataWriter::Create::UDP_MC_WRITER"); #endif - } - else - { - Logging::Log(log_level_error, m_topic_name + "::CDataWriter::Create::UDP_MC_WRITER - FAILED"); - } break; case TLayer::eSendMode::smode_none: case TLayer::eSendMode::smode_off: - m_writer.udp_mc.Destroy(); + m_writer.udp.reset(); break; } #endif // ECAL_CORE_TRANSPORT_UDP @@ -1013,20 +1012,14 @@ namespace eCAL { case TLayer::eSendMode::smode_auto: case TLayer::eSendMode::smode_on: - if (m_writer.shm.Create(m_host_name, m_topic_name, m_topic_id)) - { + m_writer.shm = std::make_unique(m_host_name, m_topic_name, m_topic_id); #ifndef NDEBUG - Logging::Log(log_level_debug4, m_topic_name + "::CDataWriter::Create::SHM_WRITER - SUCCESS"); + Logging::Log(log_level_debug4, m_topic_name + "::CDataWriter::Create::SHM_WRITER"); #endif - } - else - { - Logging::Log(log_level_error, m_topic_name + "::CDataWriter::Create::SHM_WRITER - FAILED"); - } break; case TLayer::eSendMode::smode_none: case TLayer::eSendMode::smode_off: - m_writer.shm.Destroy(); + m_writer.shm.reset(); break; } #endif // ECAL_CORE_TRANSPORT_SHM @@ -1045,20 +1038,14 @@ namespace eCAL { case TLayer::eSendMode::smode_auto: case TLayer::eSendMode::smode_on: - if (m_writer.tcp.Create(m_host_name, m_topic_name, m_topic_id)) - { + m_writer.tcp = std::make_unique(m_host_name, m_topic_name, m_topic_id); #ifndef NDEBUG - Logging::Log(log_level_debug4, m_topic_name + "::CDataWriter::Create::TCP_WRITER - SUCCESS"); + Logging::Log(log_level_debug4, m_topic_name + "::CDataWriter::Create::TCP_WRITER - SUCCESS"); #endif - } - else - { - Logging::Log(log_level_error, m_topic_name + "::CDataWriter::Create::TCP_WRITER - FAILED"); - } break; case TLayer::eSendMode::smode_none: case TLayer::eSendMode::smode_off: - m_writer.tcp.Destroy(); + m_writer.tcp.reset(); break; } #else // ECAL_CORE_TRANSPORT_TCP @@ -1069,13 +1056,13 @@ namespace eCAL bool CDataWriter::CheckWriterModes() { // if nothing is activated, we use defaults shm = auto, udp = auto - if ((m_writer.udp_mc_mode.requested == TLayer::smode_off) + if ((m_writer.udp_mode.requested == TLayer::smode_off) && (m_writer.shm_mode.requested == TLayer::smode_off) && (m_writer.tcp_mode.requested == TLayer::smode_off) ) { #if ECAL_CORE_TRANSPORT_UDP - m_writer.udp_mc_mode.requested = TLayer::smode_auto; + m_writer.udp_mode.requested = TLayer::smode_auto; #endif #if ECAL_CORE_TRANSPORT_SHM m_writer.shm_mode.requested = TLayer::smode_auto; @@ -1092,9 +1079,9 @@ namespace eCAL { bool new_local_layer(false); #if ECAL_CORE_TRANSPORT_UDP - if (m_writer.udp_mc_mode.requested != TLayer::smode_on) + if (m_writer.udp_mode.requested != TLayer::smode_on) { - m_writer.udp_mc_mode.requested = TLayer::smode_on; + m_writer.udp_mode.requested = TLayer::smode_on; new_local_layer = true; } #else @@ -1108,7 +1095,7 @@ namespace eCAL #endif if (new_local_layer) { - if (m_writer.udp_mc_mode.requested == TLayer::smode_on) + if (m_writer.udp_mode.requested == TLayer::smode_on) { Logging::Log(log_level_warning, m_topic_name + "::CDataWriter: Switched to udp for local communication."); SetUseUdpMC(TLayer::smode_on); @@ -1122,7 +1109,7 @@ namespace eCAL } if ( (m_writer.tcp_mode.requested == TLayer::smode_auto) - && (m_writer.udp_mc_mode.requested == TLayer::smode_auto) + && (m_writer.udp_mode.requested == TLayer::smode_auto) ) { Logging::Log(log_level_error, m_topic_name + "::CDataWriter::Send: TCP layer and UDP layer are both set to auto mode - Publication failed !"); @@ -1133,11 +1120,11 @@ namespace eCAL //////////////////////////////////////////////////////////////////////////// // UDP (MC) //////////////////////////////////////////////////////////////////////////// - if (((m_writer.udp_mc_mode.requested == TLayer::smode_auto) && m_ext_subscribed) - || (m_writer.udp_mc_mode.requested == TLayer::smode_on) + if (((m_writer.udp_mode.requested == TLayer::smode_auto) && m_ext_subscribed) + || (m_writer.udp_mode.requested == TLayer::smode_on) ) { - m_writer.udp_mc_mode.activated = true; + m_writer.udp_mode.activated = true; } #endif diff --git a/ecal/core/src/readwrite/ecal_writer.h b/ecal/core/src/readwrite/ecal_writer.h index 51b60dbc0b..f3f87b4789 100644 --- a/ecal/core/src/readwrite/ecal_writer.h +++ b/ecal/core/src/readwrite/ecal_writer.h @@ -48,6 +48,7 @@ #include "tcp/ecal_writer_tcp.h" #endif +#include #include #include #include @@ -198,18 +199,18 @@ namespace eCAL bool confirmed = false; }; - SWriterMode udp_mc_mode; + SWriterMode udp_mode; SWriterMode tcp_mode; SWriterMode shm_mode; #if ECAL_CORE_TRANSPORT_UDP - CDataWriterUdpMC udp_mc; + std::unique_ptr udp; #endif #if ECAL_CORE_TRANSPORT_SHM - CDataWriterSHM shm; + std::unique_ptr shm; #endif #if ECAL_CORE_TRANSPORT_TCP - CDataWriterTCP tcp; + std::unique_ptr tcp; #endif }; SWriter m_writer; diff --git a/ecal/core/src/readwrite/ecal_writer_base.h b/ecal/core/src/readwrite/ecal_writer_base.h index 40188b65b1..dfb8c00ceb 100644 --- a/ecal/core/src/readwrite/ecal_writer_base.h +++ b/ecal/core/src/readwrite/ecal_writer_base.h @@ -38,14 +38,10 @@ namespace eCAL class CDataWriterBase { public: - CDataWriterBase() : m_created(false) {}; virtual ~CDataWriterBase() = default; virtual SWriterInfo GetInfo() = 0; - virtual bool Create(const std::string& host_name_, const std::string& topic_name_, const std::string & topic_id_) = 0; - virtual bool Destroy() = 0; - virtual void AddLocConnection(const std::string& /*process_id_*/, const std::string& /*topic_id_*/, const std::string& /*conn_par_*/) {}; virtual void RemLocConnection(const std::string& /*process_id_*/, const std::string& /*topic_id_*/) {}; @@ -62,7 +58,5 @@ namespace eCAL std::string m_host_name; std::string m_topic_name; std::string m_topic_id; - - std::atomic m_created; }; } diff --git a/ecal/core/src/readwrite/shm/ecal_writer_shm.cpp b/ecal/core/src/readwrite/shm/ecal_writer_shm.cpp index 9ee4cd48df..ca8484d647 100644 --- a/ecal/core/src/readwrite/shm/ecal_writer_shm.cpp +++ b/ecal/core/src/readwrite/shm/ecal_writer_shm.cpp @@ -33,34 +33,10 @@ namespace eCAL { const std::string CDataWriterSHM::m_memfile_base_name = "ecal_"; - CDataWriterSHM::~CDataWriterSHM() + CDataWriterSHM::CDataWriterSHM(const std::string& host_name_, const std::string& topic_name_, const std::string& topic_id_) { - Destroy(); - } - - SWriterInfo CDataWriterSHM::GetInfo() - { - SWriterInfo info_; - - info_.name = "shm"; - info_.description = "Local shared memory data writer"; - - info_.has_mode_local = true; - info_.has_mode_cloud = false; - - info_.send_size_max = -1; - - return info_; - } - - bool CDataWriterSHM::Create(const std::string& /*host_name_*/, const std::string& topic_name_, const std::string & /*topic_id_*/) - { - if (m_created) return true; m_topic_name = topic_name_; - // init write index and create memory files - m_write_idx = 0; - // set attributes m_memory_file_attr.min_size = Config::GetMemfileMinsizeBytes(); m_memory_file_attr.reserve = Config::GetMemfileOverprovisioningPercentage(); @@ -68,21 +44,24 @@ namespace eCAL m_memory_file_attr.timeout_ack_ms = Config::GetMemfileAckTimeoutMs(); // initialize memory file buffer - m_created = SetBufferCount(m_buffer_count); - - return m_created; + SetBufferCount(m_buffer_count /*= 1*/); } - bool CDataWriterSHM::Destroy() + SWriterInfo CDataWriterSHM::GetInfo() { - if (!m_created) return true; - m_created = false; + SWriterInfo info_; - m_memory_file_vec.clear(); + info_.name = "shm"; + info_.description = "Local shared memory data writer"; - return true; - } + info_.has_mode_local = true; + info_.has_mode_cloud = false; + + info_.send_size_max = -1; + return info_; + } + bool CDataWriterSHM::SetBufferCount(size_t buffer_count_) { // no need to adapt anything @@ -128,8 +107,6 @@ namespace eCAL bool CDataWriterSHM::PrepareWrite(const SWriterAttr& attr_) { - if (!m_created) return false; - // false signals no rematching / exchanging of // connection parameters needed bool ret_state(false); @@ -155,8 +132,6 @@ namespace eCAL bool CDataWriterSHM::Write(CPayloadWriter& payload_, const SWriterAttr& attr_) { - if (!m_created) return false; - // write content const bool force_full_write(m_memory_file_vec.size() > 1); const bool sent = m_memory_file_vec[m_write_idx]->Write(payload_, attr_, force_full_write); @@ -170,8 +145,6 @@ namespace eCAL void CDataWriterSHM::AddLocConnection(const std::string& process_id_, const std::string& /*topic_id_*/, const std::string& /*conn_par_*/) { - if (!m_created) return; - for (auto& memory_file : m_memory_file_vec) { memory_file->Connect(process_id_); diff --git a/ecal/core/src/readwrite/shm/ecal_writer_shm.h b/ecal/core/src/readwrite/shm/ecal_writer_shm.h index d3081a5aa9..ddc5f4bc46 100644 --- a/ecal/core/src/readwrite/shm/ecal_writer_shm.h +++ b/ecal/core/src/readwrite/shm/ecal_writer_shm.h @@ -36,16 +36,10 @@ namespace eCAL class CDataWriterSHM : public CDataWriterBase { public: - CDataWriterSHM() = default; - ~CDataWriterSHM() override; + CDataWriterSHM(const std::string& host_name_, const std::string& topic_name_, const std::string& topic_id_); SWriterInfo GetInfo() override; - bool Create(const std::string& host_name_, const std::string& topic_name_, const std::string & topic_id_) override; - // this virtual function is called during construction/destruction, - // so, mark it as final to ensure that no derived classes override it. - bool Destroy() final; - bool SetBufferCount(size_t buffer_count_); bool PrepareWrite(const SWriterAttr& attr_) override; diff --git a/ecal/core/src/readwrite/tcp/ecal_writer_tcp.cpp b/ecal/core/src/readwrite/tcp/ecal_writer_tcp.cpp index 59dabf9586..85bb6234ab 100644 --- a/ecal/core/src/readwrite/tcp/ecal_writer_tcp.cpp +++ b/ecal/core/src/readwrite/tcp/ecal_writer_tcp.cpp @@ -21,11 +21,11 @@ * @brief tcp writer **/ +#include + #include "config/ecal_config_reader_hlp.h" #include "serialization/ecal_serialize_sample_payload.h" -#include - #include "ecal_writer_tcp.h" #include "ecal_tcp_pubsub_logger.h" @@ -38,31 +38,7 @@ namespace eCAL std::mutex CDataWriterTCP::g_tcp_writer_executor_mtx; std::shared_ptr CDataWriterTCP::g_tcp_writer_executor; - CDataWriterTCP::CDataWriterTCP() : m_port(0) - { - } - - CDataWriterTCP::~CDataWriterTCP() - { - Destroy(); - } - - SWriterInfo CDataWriterTCP::GetInfo() - { - SWriterInfo info_; - - info_.name = "tcp"; - info_.description = "tcp data writer"; - - info_.has_mode_local = true; - info_.has_mode_cloud = true; - - info_.send_size_max = -1; - - return info_; - } - - bool CDataWriterTCP::Create(const std::string& host_name_, const std::string& topic_name_, const std::string& topic_id_) + CDataWriterTCP::CDataWriterTCP(const std::string& host_name_, const std::string& topic_name_, const std::string& topic_id_) { { const std::lock_guard lock(g_tcp_writer_executor_mtx); @@ -80,19 +56,21 @@ namespace eCAL m_host_name = host_name_; m_topic_name = topic_name_; m_topic_id = topic_id_; - - return true; } - bool CDataWriterTCP::Destroy() + SWriterInfo CDataWriterTCP::GetInfo() { - if(!m_publisher) return true; + SWriterInfo info_; - // destroy publisher - m_publisher = nullptr; - m_port = 0; + info_.name = "tcp"; + info_.description = "tcp data writer"; - return true; + info_.has_mode_local = true; + info_.has_mode_cloud = true; + + info_.send_size_max = -1; + + return info_; } bool CDataWriterTCP::Write(const void* const buf_, const SWriterAttr& attr_) diff --git a/ecal/core/src/readwrite/tcp/ecal_writer_tcp.h b/ecal/core/src/readwrite/tcp/ecal_writer_tcp.h index ee90ff62c5..bd2cc4d66e 100644 --- a/ecal/core/src/readwrite/tcp/ecal_writer_tcp.h +++ b/ecal/core/src/readwrite/tcp/ecal_writer_tcp.h @@ -38,16 +38,10 @@ namespace eCAL class CDataWriterTCP : public CDataWriterBase { public: - CDataWriterTCP(); - ~CDataWriterTCP() override; + CDataWriterTCP(const std::string& host_name_, const std::string& topic_name_, const std::string& topic_id_); SWriterInfo GetInfo() override; - bool Create(const std::string& host_name_, const std::string& topic_name_, const std::string & topic_id_) override; - // this virtual function is called during construction/destruction, - // so, mark it as final to ensure that no derived classes override it. - bool Destroy() final; - bool Write(const void* buf_, const SWriterAttr& attr_) override; Registration::ConnectionPar GetConnectionParameter() override; @@ -59,6 +53,6 @@ namespace eCAL static std::shared_ptr g_tcp_writer_executor; std::shared_ptr m_publisher; - uint16_t m_port; + uint16_t m_port = 0; }; } diff --git a/ecal/core/src/readwrite/udp/ecal_writer_udp_mc.cpp b/ecal/core/src/readwrite/udp/ecal_writer_udp_mc.cpp index a53aba4408..60055517d3 100644 --- a/ecal/core/src/readwrite/udp/ecal_writer_udp_mc.cpp +++ b/ecal/core/src/readwrite/udp/ecal_writer_udp_mc.cpp @@ -21,42 +21,19 @@ * @brief udp data writer **/ -#include #include #include -#include -#include #include "ecal_writer_udp_mc.h" #include "io/udp/ecal_udp_configurations.h" #include "serialization/ecal_serialize_sample_payload.h" +#include + namespace eCAL { - CDataWriterUdpMC::~CDataWriterUdpMC() - { - Destroy(); - } - - SWriterInfo CDataWriterUdpMC::GetInfo() - { - SWriterInfo info_; - - info_.name = "udp"; - info_.description = "udp multicast data writer"; - - info_.has_mode_local = true; - info_.has_mode_cloud = true; - - info_.send_size_max = -1; - - return info_; - } - - bool CDataWriterUdpMC::Create(const std::string & host_name_, const std::string & topic_name_, const std::string & topic_id_) + CDataWriterUdpMC::CDataWriterUdpMC(const std::string& host_name_, const std::string& topic_name_, const std::string& topic_id_) { - if (m_created) return true; - m_host_name = host_name_; m_topic_name = topic_name_; m_topic_id = topic_id_; @@ -76,26 +53,25 @@ namespace eCAL // create udp/sample sender without activated loop-back attr.loopback = false; m_sample_sender_no_loopback = std::make_shared(attr); - - m_created = true; - return true; } - bool CDataWriterUdpMC::Destroy() + SWriterInfo CDataWriterUdpMC::GetInfo() { - if (!m_created) return true; + SWriterInfo info_; - m_sample_sender_loopback.reset(); - m_sample_sender_no_loopback.reset(); + info_.name = "udp"; + info_.description = "udp multicast data writer"; + + info_.has_mode_local = true; + info_.has_mode_cloud = true; - m_created = false; - return true; + info_.send_size_max = -1; + + return info_; } bool CDataWriterUdpMC::Write(const void* const buf_, const SWriterAttr& attr_) { - if (!m_created) return false; - // create new sample Payload::Sample ecal_sample; ecal_sample.cmd_type = eCmdType::bct_set_sample; diff --git a/ecal/core/src/readwrite/udp/ecal_writer_udp_mc.h b/ecal/core/src/readwrite/udp/ecal_writer_udp_mc.h index 9b9df24207..fc7d820ae2 100644 --- a/ecal/core/src/readwrite/udp/ecal_writer_udp_mc.h +++ b/ecal/core/src/readwrite/udp/ecal_writer_udp_mc.h @@ -35,15 +35,10 @@ namespace eCAL class CDataWriterUdpMC : public CDataWriterBase { public: - ~CDataWriterUdpMC() override; + CDataWriterUdpMC(const std::string& host_name_, const std::string& topic_name_, const std::string& topic_id_); SWriterInfo GetInfo() override; - bool Create(const std::string& host_name_, const std::string& topic_name_, const std::string & topic_id_) override; - // this virtual function is called during construction/destruction, - // so, mark it as final to ensure that no derived classes override it. - bool Destroy() final; - bool Write(const void* buf_, const SWriterAttr& attr_) override; protected: diff --git a/ecal/tests/cpp/util_test/src/util_gettopics.cpp b/ecal/tests/cpp/util_test/src/util_gettopics.cpp index 2665df9924..112234d018 100644 --- a/ecal/tests/cpp/util_test/src/util_gettopics.cpp +++ b/ecal/tests/cpp/util_test/src/util_gettopics.cpp @@ -21,6 +21,7 @@ #include +#include #include #include #include