Skip to content

Commit

Permalink
new publisher config API first draft
Browse files Browse the repository at this point in the history
  • Loading branch information
rex-schilasky committed Apr 23, 2024
1 parent 5ecb809 commit 22d15d1
Show file tree
Hide file tree
Showing 23 changed files with 428 additions and 362 deletions.
20 changes: 0 additions & 20 deletions ecal/core/include/ecal/cimpl/ecal_publisher_cimpl.h
Original file line number Diff line number Diff line change
Expand Up @@ -89,26 +89,6 @@ extern "C"
**/
ECALC_API int eCAL_Pub_ClearAttribute(ECAL_HANDLE handle_, const char* attr_name_, int attr_name_len_);

/**
* @brief Share topic type.
*
* @param handle_ Publisher handle.
* @param state_ Set type share mode (none zero == share type).
*
* @return None zero if succeeded.
**/
ECALC_API int eCAL_Pub_ShareType(ECAL_HANDLE handle_, int state_);

/**
* @brief Share topic description.
*
* @param handle_ Publisher handle.
* @param state_ Set description share mode (none zero == share description).
*
* @return None zero if succeeded.
**/
ECALC_API int eCAL_Pub_ShareDescription(ECAL_HANDLE handle_, int state_);

/**
* @brief Set the specific topic id.
*
Expand Down
73 changes: 45 additions & 28 deletions ecal/core/include/ecal/ecal_publisher.h
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +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_types.h>

#include <chrono>
Expand Down Expand Up @@ -70,7 +71,38 @@ namespace eCAL
{
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 */
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
long long 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) */
long 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)
};

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;
};

/**
* @brief Constructor.
Expand All @@ -80,17 +112,19 @@ namespace eCAL
/**
* @brief Constructor.
*
* @param topic_name_ Unique topic name.
* @param topic_info_ Topic information (encoding, type, descriptor)
* @param topic_name_ Unique topic name.
* @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& topic_info_);
ECAL_API CPublisher(const std::string& topic_name_, const SDataTypeInformation& data_type_info_, const Config& config_ = {});

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

/**
* @brief Destructor.
Expand Down Expand Up @@ -120,12 +154,13 @@ namespace eCAL
/**
* @brief Creates this object.
*
* @param topic_name_ Unique topic name.
* @param topic_info_ Topic information (encoding, type, descriptor)
* @param topic_name_ Unique topic name.
* @param data_type_info_ Topic data type information (encoding, type, descriptor).
* @param config_ Optional configuration parameters.
*
* @return True if it succeeds, false if it fails.
**/
ECAL_API bool Create(const std::string& topic_name_, const SDataTypeInformation& topic_info_);
ECAL_API bool Create(const std::string& topic_name_, const SDataTypeInformation& data_type_info_, const Config& config_ = {});

/**
* @brief Creates this object.
Expand All @@ -146,11 +181,11 @@ namespace eCAL
/**
* @brief Setup topic information.
*
* @param topic_info_ Topic information attributes.
* @param data_type_info_ Topic data type information attributes.
*
* @return True if it succeeds, false if it fails.
**/
ECAL_API bool SetDataTypeInformation(const SDataTypeInformation& topic_info_);
ECAL_API bool SetDataTypeInformation(const SDataTypeInformation& data_type_info_);

/**
* @brief Sets publisher attribute.
Expand All @@ -172,24 +207,6 @@ namespace eCAL
**/
ECAL_API bool ClearAttribute(const std::string& attr_name_);

/**
* @brief Share topic type.
*
* @param state_ Set type share mode (true == share type).
*
* @return True if it succeeds, false if it fails.
**/
ECAL_API bool ShareType(bool state_ = true);

/**
* @brief Share topic description.
*
* @param state_ Set description share mode (true == share description).
*
* @return True if it succeeds, false if it fails.
**/
ECAL_API bool ShareDescription(bool state_ = true);

/**
* @brief Set the specific topic id.
*
Expand Down
1 change: 1 addition & 0 deletions ecal/core/include/ecal/ecal_tlayer.h
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@ namespace eCAL
smode_auto
};

// TODO: Do weed need this ?
/**
* @brief eCAL transport layer state struct.
**/
Expand Down
20 changes: 11 additions & 9 deletions ecal/core/include/ecal/msg/capnproto/publisher.h
Original file line number Diff line number Diff line change
Expand Up @@ -99,9 +99,10 @@ namespace eCAL
* @brief Constructor.
*
* @param topic_name_ Unique topic name.
* @param config_ Optional configuration parameters.
**/
CPublisher(const std::string& topic_name_)
: eCAL::CPublisher(topic_name_, GetDataTypeInformation())
CPublisher(const std::string& topic_name_, const eCAL::CPublisher::Config& config_ = {})
: eCAL::CPublisher(topic_name_, GetDataTypeInformation(), config_)
, builder(std::make_unique<capnp::MallocMessageBuilder>())
, root_builder(builder->initRoot<message_type>())
{
Expand Down Expand Up @@ -145,12 +146,13 @@ namespace eCAL
* @brief Creates this object.
*
* @param topic_name_ Unique topic name.
* @param config_ Optional configuration parameters.
*
* @return True if it succeeds, false if it fails.
**/
bool Create(const std::string& topic_name_)
bool Create(const std::string& topic_name_, const eCAL::CPublisher::Config& config_ = {})
{
return(eCAL::CPublisher::Create(topic_name_, GetDataTypeInformation()));
return(eCAL::CPublisher::Create(topic_name_, GetDataTypeInformation(), config_));
}

typename message_type::Builder GetBuilder()
Expand All @@ -172,11 +174,11 @@ namespace eCAL
**/
SDataTypeInformation GetDataTypeInformation() const
{
SDataTypeInformation topic_info;
topic_info.encoding = eCAL::capnproto::EncodingAsString();
topic_info.name = eCAL::capnproto::TypeAsString<message_type>();
topic_info.descriptor = eCAL::capnproto::SchemaAsString<message_type>();
return topic_info;
SDataTypeInformation data_type_info;
data_type_info.encoding = eCAL::capnproto::EncodingAsString();
data_type_info.name = eCAL::capnproto::TypeAsString<message_type>();
data_type_info.descriptor = eCAL::capnproto::SchemaAsString<message_type>();
return data_type_info;
}

std::unique_ptr<capnp::MallocMessageBuilder> builder;
Expand Down
14 changes: 8 additions & 6 deletions ecal/core/include/ecal/msg/flatbuffers/publisher.h
Original file line number Diff line number Diff line change
Expand Up @@ -51,8 +51,9 @@ namespace eCAL
* @brief Constructor.
*
* @param topic_name_ Unique topic name.
* @param config_ Optional configuration parameters.
**/
CPublisher(const std::string& topic_name_) : CMsgPublisher<T>(topic_name_, GetDataTypeInformation())
CPublisher(const std::string& topic_name_, const eCAL::CPublisher::Config& config_ = {}) : CMsgPublisher<T>(topic_name_, GetDataTypeInformation(), config_)
{
}

Expand Down Expand Up @@ -80,12 +81,13 @@ namespace eCAL
* @brief Creates this object.
*
* @param topic_name_ Unique topic name.
* @param config_ Optional configuration parameters.
*
* @return True if it succeeds, false if it fails.
**/
bool Create(const std::string& topic_name_)
bool Create(const std::string& topic_name_, const eCAL::CPublisher::Config& config_ = {})
{
return(CMsgPublisher<T>::Create(topic_name_, GetDataTypeInformation()));
return(CMsgPublisher<T>::Create(topic_name_, GetDataTypeInformation(), config_));
}

private:
Expand All @@ -96,10 +98,10 @@ namespace eCAL
**/
SDataTypeInformation GetDataTypeInformation() const override
{
SDataTypeInformation topic_info;
topic_info.encoding = "flatb";
SDataTypeInformation data_type_info;
data_type_info.encoding = "flatb";
// empty type, empty descriptor
return topic_info;
return data_type_info;
}

/**
Expand Down
14 changes: 8 additions & 6 deletions ecal/core/include/ecal/msg/messagepack/publisher.h
Original file line number Diff line number Diff line change
Expand Up @@ -54,8 +54,9 @@ namespace eCAL
* @brief Constructor.
*
* @param topic_name_ Unique topic name.
* @param config_ Optional configuration parameters.
**/
CPublisher(const std::string& topic_name_) : CMsgPublisher<T>(topic_name_, GetDataTypeInformation())
CPublisher(const std::string& topic_name_, const eCAL::CPublisher::Config& config_ = {}) : CMsgPublisher<T>(topic_name_, GetDataTypeInformation(), config_)
{
}

Expand Down Expand Up @@ -83,12 +84,13 @@ namespace eCAL
* @brief Creates this object.
*
* @param topic_name_ Unique topic name.
* @param config_ Optional configuration parameters.
*
* @return True if it succeeds, false if it fails.
**/
bool Create(const std::string& topic_name_)
bool Create(const std::string& topic_name_, const eCAL::CPublisher::Config& config_ = {})
{
return(CMsgPublisher<T>::Create(topic_name_, GetDataTypeInformation()));
return(CMsgPublisher<T>::Create(topic_name_, GetDataTypeInformation(), config_));
}

private:
Expand All @@ -99,10 +101,10 @@ namespace eCAL
**/
SDataTypeInformation GetDataTypeInformation() const override
{
SDataTypeInformation topic_info;
topic_info.encoding = "mpack";
SDataTypeInformation data_type_info;
data_type_info.encoding = "mpack";
// empty descriptor, empty descriptor
return topic_info;
return data_type_info;
}

/**
Expand Down
15 changes: 8 additions & 7 deletions ecal/core/include/ecal/msg/protobuf/dynamic_publisher.h
Original file line number Diff line number Diff line change
Expand Up @@ -60,9 +60,10 @@ namespace eCAL
*
* @param topic_name_ Unique topic name.
* @param msg_ Protobuf message object.
* @param config_ Optional configuration parameters.
**/
CDynamicPublisher(const std::string& topic_name_, const std::shared_ptr<google::protobuf::Message>& msg_)
: CMsgPublisher<google::protobuf::Message>(topic_name_, GetTopicInformationFromMessage(msg_.get()))
CDynamicPublisher(const std::string& topic_name_, const std::shared_ptr<google::protobuf::Message>& msg_, const eCAL::CPublisher::Config& config_ = {})
: CMsgPublisher<google::protobuf::Message>(topic_name_, GetTopicInformationFromMessage(msg_.get()), config_)
, m_msg{ msg_ } {}

/**
Expand Down Expand Up @@ -140,11 +141,11 @@ namespace eCAL
assert(msg_ptr_);
if(msg_ptr_ == nullptr) return SDataTypeInformation();

SDataTypeInformation topic_info;
topic_info.encoding = "proto";
topic_info.name = msg_ptr_->GetTypeName();
topic_info.descriptor = GetDescriptorFromMessage(msg_ptr_);
return topic_info;
SDataTypeInformation data_type_info;
data_type_info.encoding = "proto";
data_type_info.name = msg_ptr_->GetTypeName();
data_type_info.descriptor = GetDescriptorFromMessage(msg_ptr_);
return data_type_info;
}

static std::string GetDescriptorFromMessage(const google::protobuf::Message* msg_ptr_)
Expand Down
18 changes: 10 additions & 8 deletions ecal/core/include/ecal/msg/protobuf/publisher.h
Original file line number Diff line number Diff line change
Expand Up @@ -100,13 +100,14 @@ namespace eCAL
* @brief Constructor.
*
* @param topic_name_ Unique topic name.
* @param config_ Optional configuration parameters.
**/

// 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.
// 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_) : eCAL::CPublisher(topic_name_, CPublisher::GetDataTypeInformation())
explicit CPublisher(const std::string& topic_name_, const eCAL::CPublisher::Config& config_ = {}) : eCAL::CPublisher(topic_name_, CPublisher::GetDataTypeInformation(), config_)
{
}

Expand Down Expand Up @@ -139,12 +140,13 @@ namespace eCAL
* @brief Creates this object.
*
* @param topic_name_ Unique topic name.
* @param config_ Optional configuration parameters.
*
* @return True if it succeeds, false if it fails.
**/
bool Create(const std::string& topic_name_)
bool Create(const std::string& topic_name_, const eCAL::CPublisher::Config& config_ = {})
{
return(eCAL::CPublisher::Create(topic_name_, GetDataTypeInformation()));
return(eCAL::CPublisher::Create(topic_name_, GetDataTypeInformation(), config_));
}

/**
Expand All @@ -170,12 +172,12 @@ namespace eCAL
**/
struct SDataTypeInformation GetDataTypeInformation() const
{
struct SDataTypeInformation topic_info;
struct SDataTypeInformation data_type_info;
static T msg{};
topic_info.encoding = "proto";
topic_info.name = msg.GetTypeName();
topic_info.descriptor = protobuf::GetProtoMessageDescription(msg);
return topic_info;
data_type_info.encoding = "proto";
data_type_info.name = msg.GetTypeName();
data_type_info.descriptor = protobuf::GetProtoMessageDescription(msg);
return data_type_info;
}

};
Expand Down
Loading

0 comments on commit 22d15d1

Please sign in to comment.