Skip to content

Commit

Permalink
publisher config separated
Browse files Browse the repository at this point in the history
  • Loading branch information
rex-schilasky committed May 2, 2024
1 parent 991179d commit 010bbdf
Show file tree
Hide file tree
Showing 28 changed files with 159 additions and 101 deletions.
1 change: 1 addition & 0 deletions ecal/core/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -195,6 +195,7 @@ endif()
if(ECAL_CORE_PUBLISHER)
set(ecal_pub_src
src/pubsub/ecal_publisher.cpp
src/pubsub/ecal_publisher_config.cpp
src/pubsub/ecal_pubgate.cpp
src/pubsub/ecal_pubgate.h
)
Expand Down
45 changes: 5 additions & 40 deletions ecal/core/include/ecal/ecal_publisher.h
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@
#include <ecal/ecal_deprecate.h>
#include <ecal/ecal_os.h>
#include <ecal/ecal_payload_writer.h>
#include <ecal/ecal_tlayer.h>
#include <ecal/ecal_publisher_config.h>
#include <ecal/ecal_types.h>

#include <chrono>
Expand Down Expand Up @@ -70,42 +70,7 @@ namespace eCAL
class CPublisher
{
public:

ECAL_API static constexpr long long DEFAULT_TIME_ARGUMENT = -1; /*!< Use DEFAULT_TIME_ARGUMENT in the `Send()` function to let eCAL determine the send timestamp */

struct ECAL_API SHMConfig
{
TLayer::eSendMode send_mode = TLayer::smode_auto; //!< shm layer send mode (default auto)
bool zero_copy_mode = false; //!< enable zero copy shared memory transport mode
int acknowledge_timeout_ms = 0; /*!< force connected subscribers to send acknowledge event after processing the message
the publisher send call is blocked on this event with this timeout (0 == no handshake) */
size_t memfile_min_size_bytes = 4096; //!< default memory file size for new publisher
size_t memfile_reserve_percent = 50; //!< dynamic file size reserve before recreating memory file if topic size changes
size_t memfile_buffer_count = 1; //!< maximum number of used buffers (needs to be greater than 1, default = 1)
};

struct ECAL_API UDPConfig
{
TLayer::eSendMode send_mode = TLayer::smode_auto; //!< udp layer send mode (default auto)
int sndbuf_size_bytes = (5*1024*1024); //!< udp send buffer size in bytes (default 5MB)
};

struct ECAL_API TCPConfig
{
TLayer::eSendMode send_mode = TLayer::smode_off; //!< tcp layer send mode (default off)
};

struct ECAL_API Config
{
Config();

SHMConfig shm;
UDPConfig udp;
TCPConfig tcp;

bool share_topic_type = true;
bool share_topic_description = true;
};
ECAL_API static constexpr long long DEFAULT_TIME_ARGUMENT = -1; /*!< Use DEFAULT_TIME_ARGUMENT in the `Send()` function to let eCAL determine the send timestamp */

/**
* @brief Constructor.
Expand All @@ -119,15 +84,15 @@ namespace eCAL
* @param data_type_info_ Topic data type information (encoding, type, descriptor).
* @param config_ Optional configuration parameters.
**/
ECAL_API CPublisher(const std::string& topic_name_, const SDataTypeInformation& data_type_info_, const Config& config_ = {});
ECAL_API CPublisher(const std::string& topic_name_, const SDataTypeInformation& data_type_info_, const PubConfig& config_ = {});

/**
* @brief Constructor.
*
* @param topic_name_ Unique topic name.
* @param config_ Optional configuration parameters.
**/
ECAL_API explicit CPublisher(const std::string& topic_name_, const Config& config_ = {});
ECAL_API explicit CPublisher(const std::string& topic_name_, const PubConfig& config_ = {});

/**
* @brief Destructor.
Expand Down Expand Up @@ -163,7 +128,7 @@ namespace eCAL
*
* @return True if it succeeds, false if it fails.
**/
ECAL_API bool Create(const std::string& topic_name_, const SDataTypeInformation& data_type_info_, const Config& config_ = {});
ECAL_API bool Create(const std::string& topic_name_, const SDataTypeInformation& data_type_info_, const PubConfig& config_ = {});

/**
* @brief Creates this object.
Expand Down
64 changes: 64 additions & 0 deletions ecal/core/include/ecal/ecal_publisher_config.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
/* ========================= eCAL LICENSE =================================
*
* Copyright (C) 2016 - 2019 Continental Corporation
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*
* ========================= eCAL LICENSE =================================
*/

/**
* @file ecal_publisher_config.h
* @brief eCAL publisher configuration
**/

#pragma once

#include <ecal/ecal_tlayer.h>

namespace eCAL
{
struct ECAL_API SHMPubConfig
{
TLayer::eSendMode send_mode = TLayer::smode_auto; //!< shm layer send mode (default auto)
bool zero_copy_mode = false; //!< enable zero copy shared memory transport mode
int acknowledge_timeout_ms = 0; /*!< force connected subscribers to send acknowledge event after processing the message
the publisher send call is blocked on this event with this timeout (0 == no handshake) */
size_t memfile_min_size_bytes = 4096; //!< default memory file size for new publisher
size_t memfile_reserve_percent = 50; //!< dynamic file size reserve before recreating memory file if topic size changes
size_t memfile_buffer_count = 1; //!< maximum number of used buffers (needs to be greater than 1, default = 1)
};

struct ECAL_API UDPPubConfig
{
TLayer::eSendMode send_mode = TLayer::smode_auto; //!< udp layer send mode (default auto)
int sndbuf_size_bytes = (5*1024*1024); //!< udp send buffer size in bytes (default 5MB)
};

struct ECAL_API TCPPubConfig
{
TLayer::eSendMode send_mode = TLayer::smode_off; //!< tcp layer send mode (default off)
};

struct ECAL_API PubConfig
{
PubConfig();

SHMPubConfig shm;
UDPPubConfig udp;
TCPPubConfig tcp;

bool share_topic_type = true;
bool share_topic_description = true;
};
}
2 changes: 1 addition & 1 deletion ecal/core/include/ecal/msg/protobuf/dynamic_publisher.h
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ namespace eCAL
* @param msg_ Protobuf message object.
* @param config_ Optional configuration parameters.
**/
CDynamicPublisher(const std::string& topic_name_, const std::shared_ptr<google::protobuf::Message>& msg_, const eCAL::CPublisher::Config& config_ = {})
CDynamicPublisher(const std::string& topic_name_, const std::shared_ptr<google::protobuf::Message>& msg_, const eCAL::PubConfig& config_ = {})
: CMsgPublisher<google::protobuf::Message>(topic_name_, GetTopicInformationFromMessage(msg_.get()), config_)
, m_msg{ msg_ } {}

Expand Down
4 changes: 2 additions & 2 deletions ecal/core/include/ecal/msg/protobuf/publisher.h
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,7 @@ namespace eCAL
// where the vtable is not created yet, or it's destructed.
// Probably we can handle the Message publishers differently. One message publisher class and then one class for payloads and getting type
// descriptor information.
explicit CPublisher(const std::string& topic_name_, const eCAL::CPublisher::Config& config_ = {}) : eCAL::CPublisher(topic_name_, CPublisher::GetDataTypeInformation(), config_)
explicit CPublisher(const std::string& topic_name_, const eCAL::PubConfig& config_ = {}) : eCAL::CPublisher(topic_name_, CPublisher::GetDataTypeInformation(), config_)
{
}

Expand Down Expand Up @@ -144,7 +144,7 @@ namespace eCAL
*
* @return True if it succeeds, false if it fails.
**/
bool Create(const std::string& topic_name_, const eCAL::CPublisher::Config& config_ = {})
bool Create(const std::string& topic_name_, const eCAL::PubConfig& config_ = {})
{
return(eCAL::CPublisher::Create(topic_name_, GetDataTypeInformation(), config_));
}
Expand Down
6 changes: 3 additions & 3 deletions ecal/core/include/ecal/msg/publisher.h
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ namespace eCAL
* @param data_type_info_ Topic data type information (encoding, type, descriptor).
* @param config_ Optional configuration parameters.
**/
CMsgPublisher(const std::string& topic_name_, const struct SDataTypeInformation& data_type_info_, const Config& config_ = {}) : CPublisher(topic_name_, data_type_info_, config_)
CMsgPublisher(const std::string& topic_name_, const struct SDataTypeInformation& data_type_info_, const PubConfig& config_ = {}) : CPublisher(topic_name_, data_type_info_, config_)
{
}

Expand All @@ -74,7 +74,7 @@ namespace eCAL
* @param topic_name_ Unique topic name.
* @param config_ Optional configuration parameters.
**/
explicit CMsgPublisher(const std::string& topic_name_, const Config& config_ = {}) : CMsgPublisher(topic_name_, GetDataTypeInformation(), config_)
explicit CMsgPublisher(const std::string& topic_name_, const PubConfig& config_ = {}) : CMsgPublisher(topic_name_, GetDataTypeInformation(), config_)
{
}

Expand Down Expand Up @@ -109,7 +109,7 @@ namespace eCAL
*
* @return True if it succeeds, false if it fails.
**/
bool Create(const std::string& topic_name_, const struct SDataTypeInformation& data_type_info_, const Config& config_ = {})
bool Create(const std::string& topic_name_, const struct SDataTypeInformation& data_type_info_, const PubConfig& config_ = {})
{
return(CPublisher::Create(topic_name_, data_type_info_, config_));
}
Expand Down
4 changes: 2 additions & 2 deletions ecal/core/include/ecal/msg/string/publisher.h
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ namespace eCAL

// call the function via its class because it's a virtual function that is called in constructor/destructor,-
// where the vtable is not created yet, or it's destructed.
explicit CPublisher(const std::string& topic_name_, const eCAL::CPublisher::Config& config_ = {}) : CMsgPublisher<T>(topic_name_, GetDataTypeInformation(), config_)
explicit CPublisher(const std::string& topic_name_, const eCAL::PubConfig& config_ = {}) : CMsgPublisher<T>(topic_name_, GetDataTypeInformation(), config_)
{
}

Expand Down Expand Up @@ -92,7 +92,7 @@ namespace eCAL
*
* @return True if it succeeds, false if it fails.
**/
bool Create(const std::string& topic_name_, const eCAL::CPublisher::Config& config_ = {})
bool Create(const std::string& topic_name_, const eCAL::PubConfig& config_ = {})
{
return(CMsgPublisher<T>::Create(topic_name_, GetDataTypeInformation(), config_));
}
Expand Down
27 changes: 3 additions & 24 deletions ecal/core/src/pubsub/ecal_publisher.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -35,27 +35,6 @@

namespace eCAL
{
CPublisher::Config::Config() :
share_topic_type(eCAL::Config::IsTopicTypeSharingEnabled()),
share_topic_description(eCAL::Config::IsTopicDescriptionSharingEnabled())
{
// shm config
shm.send_mode = eCAL::Config::GetPublisherShmMode();
shm.zero_copy_mode = eCAL::Config::IsMemfileZerocopyEnabled();
shm.acknowledge_timeout_ms = eCAL::Config::GetMemfileAckTimeoutMs();

shm.memfile_min_size_bytes = eCAL::Config::GetMemfileMinsizeBytes();
shm.memfile_reserve_percent = eCAL::Config::GetMemfileOverprovisioningPercentage();
shm.memfile_buffer_count = eCAL::Config::GetMemfileBufferCount();

// udp config
udp.send_mode = eCAL::Config::GetPublisherUdpMulticastMode();
udp.sndbuf_size_bytes = eCAL::Config::GetUdpMulticastSndBufSizeBytes();

// tcp config
tcp.send_mode = eCAL::Config::GetPublisherTcpMode();
}

CPublisher::CPublisher() :
m_datawriter(nullptr),
m_id(0),
Expand All @@ -64,13 +43,13 @@ namespace eCAL
{
}

CPublisher::CPublisher(const std::string& topic_name_, const SDataTypeInformation& data_type_info_, const Config& config_)
CPublisher::CPublisher(const std::string& topic_name_, const SDataTypeInformation& data_type_info_, const PubConfig& config_)
: CPublisher()
{
CPublisher::Create(topic_name_, data_type_info_, config_);
}

CPublisher::CPublisher(const std::string& topic_name_, const Config& config_)
CPublisher::CPublisher(const std::string& topic_name_, const PubConfig& config_)
: CPublisher(topic_name_, SDataTypeInformation{}, config_)
{}

Expand Down Expand Up @@ -111,7 +90,7 @@ namespace eCAL
return *this;
}

bool CPublisher::Create(const std::string& topic_name_, const SDataTypeInformation& data_type_info_, const Config& config_)
bool CPublisher::Create(const std::string& topic_name_, const SDataTypeInformation& data_type_info_, const PubConfig& config_)
{
if (m_created) return(false);
if (topic_name_.empty()) return(false);
Expand Down
49 changes: 49 additions & 0 deletions ecal/core/src/pubsub/ecal_publisher_config.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
/* ========================= eCAL LICENSE =================================
*
* Copyright (C) 2016 - 2019 Continental Corporation
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*
* ========================= eCAL LICENSE =================================
*/

/**
* @brief eCAL publisher configuration
**/

#include <ecal/ecal_config.h>
#include <ecal/ecal_publisher_config.h>

namespace eCAL
{
PubConfig::PubConfig() :
share_topic_type(eCAL::Config::IsTopicTypeSharingEnabled()),
share_topic_description(eCAL::Config::IsTopicDescriptionSharingEnabled())
{
// shm config
shm.send_mode = eCAL::Config::GetPublisherShmMode();
shm.zero_copy_mode = eCAL::Config::IsMemfileZerocopyEnabled();
shm.acknowledge_timeout_ms = eCAL::Config::GetMemfileAckTimeoutMs();

shm.memfile_min_size_bytes = eCAL::Config::GetMemfileMinsizeBytes();
shm.memfile_reserve_percent = eCAL::Config::GetMemfileOverprovisioningPercentage();
shm.memfile_buffer_count = eCAL::Config::GetMemfileBufferCount();

// udp config
udp.send_mode = eCAL::Config::GetPublisherUdpMulticastMode();
udp.sndbuf_size_bytes = eCAL::Config::GetUdpMulticastSndBufSizeBytes();

// tcp config
tcp.send_mode = eCAL::Config::GetPublisherTcpMode();
}
}
2 changes: 1 addition & 1 deletion ecal/core/src/readwrite/ecal_writer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ namespace std

namespace eCAL
{
CDataWriter::CDataWriter(const std::string& topic_name_, const SDataTypeInformation& topic_info_, const CPublisher::Config& config_) :
CDataWriter::CDataWriter(const std::string& topic_name_, const SDataTypeInformation& topic_info_, const PubConfig& config_) :
m_host_name(Process::GetHostName()),
m_host_group_name(Process::GetHostGroupName()),
m_pid(Process::GetProcessID()),
Expand Down
6 changes: 3 additions & 3 deletions ecal/core/src/readwrite/ecal_writer.h
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@
#include <cstddef>
#include <ecal/ecal_callback.h>
#include <ecal/ecal_payload_writer.h>
#include <ecal/ecal_publisher.h>
#include <ecal/ecal_publisher_config.h>
#include <ecal/ecal_tlayer.h>
#include <ecal/ecal_types.h>
#include <tuple>
Expand Down Expand Up @@ -85,7 +85,7 @@ namespace eCAL
}
};

CDataWriter(const std::string& topic_name_, const SDataTypeInformation& topic_info_, const CPublisher::Config& config_ = {});
CDataWriter(const std::string& topic_name_, const SDataTypeInformation& topic_info_, const PubConfig& config_ = {});
~CDataWriter();

bool SetDataTypeInformation(const SDataTypeInformation& topic_info_);
Expand Down Expand Up @@ -148,7 +148,7 @@ namespace eCAL
SDataTypeInformation m_topic_info;
std::map<std::string, std::string> m_attr;
size_t m_topic_size;
CPublisher::Config m_config;
PubConfig m_config;

std::vector<char> m_payload_buffer;

Expand Down
2 changes: 1 addition & 1 deletion ecal/core/src/readwrite/shm/ecal_writer_shm.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ namespace eCAL
{
const std::string CDataWriterSHM::m_memfile_base_name = "ecal_";

CDataWriterSHM::CDataWriterSHM(const std::string& /*host_name_*/, const std::string& topic_name_, const std::string& /*topic_id_*/, const CPublisher::SHMConfig& shm_config_) :
CDataWriterSHM::CDataWriterSHM(const std::string& /*host_name_*/, const std::string& topic_name_, const std::string& /*topic_id_*/, const SHMPubConfig& shm_config_) :
m_config(shm_config_)
{
m_topic_name = topic_name_;
Expand Down
6 changes: 3 additions & 3 deletions ecal/core/src/readwrite/shm/ecal_writer_shm.h
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@

#pragma once

#include <ecal/ecal_publisher.h>
#include <ecal/ecal_publisher_config.h>

#include "readwrite/ecal_writer_base.h"
#include "io/shm/ecal_memfile_sync.h"
Expand All @@ -38,7 +38,7 @@ namespace eCAL
class CDataWriterSHM : public CDataWriterBase
{
public:
CDataWriterSHM(const std::string& host_name_, const std::string& topic_name_, const std::string& topic_id_, const CPublisher::SHMConfig& shm_config_);
CDataWriterSHM(const std::string& host_name_, const std::string& topic_name_, const std::string& topic_id_, const SHMPubConfig& shm_config_);

SWriterInfo GetInfo() override;

Expand All @@ -53,7 +53,7 @@ namespace eCAL
Registration::ConnectionPar GetConnectionParameter() override;

protected:
CPublisher::SHMConfig m_config;
SHMPubConfig m_config;

size_t m_write_idx = 0;
std::vector<std::shared_ptr<CSyncMemoryFile>> m_memory_file_vec;
Expand Down
Loading

0 comments on commit 010bbdf

Please sign in to comment.