Skip to content

Commit

Permalink
first draft new publisher config API
Browse files Browse the repository at this point in the history
  • Loading branch information
rex-schilasky committed Apr 23, 2024
1 parent 07bef0f commit 91b91f4
Show file tree
Hide file tree
Showing 22 changed files with 399 additions and 317 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
61 changes: 39 additions & 22 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 @@ -82,15 +114,17 @@ namespace eCAL
*
* @param topic_name_ Unique topic name.
* @param topic_info_ Topic 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& topic_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 @@ -122,10 +156,11 @@ namespace eCAL
*
* @param topic_name_ Unique topic name.
* @param topic_info_ Topic 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& topic_info_, const Config& config_ = {});

/**
* @brief Creates this object.
Expand Down Expand Up @@ -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
10 changes: 6 additions & 4 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 Down
8 changes: 5 additions & 3 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 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 Config& config_ = {})
{
return(CMsgPublisher<T>::Create(topic_name_, GetDataTypeInformation()));
return(CMsgPublisher<T>::Create(topic_name_, GetDataTypeInformation(), config_));
}

private:
Expand Down
8 changes: 5 additions & 3 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 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 Config& config_ = {})
{
return(CMsgPublisher<T>::Create(topic_name_, GetDataTypeInformation()));
return(CMsgPublisher<T>::Create(topic_name_, GetDataTypeInformation(), config_));
}

private:
Expand Down
7 changes: 4 additions & 3 deletions ecal/core/include/ecal/msg/protobuf/publisher.h
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,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_) : eCAL::CPublisher(topic_name_, CPublisher::GetDataTypeInformation())
explicit CPublisher(const std::string& topic_name_, const Config& config_ = {}) : eCAL::CPublisher(topic_name_, CPublisher::GetDataTypeInformation(), config_)
{
}

Expand Down Expand Up @@ -139,12 +139,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 Config& config_ = {})
{
return(eCAL::CPublisher::Create(topic_name_, GetDataTypeInformation()));
return(eCAL::CPublisher::Create(topic_name_, GetDataTypeInformation(), config_));
}

/**
Expand Down
11 changes: 7 additions & 4 deletions ecal/core/include/ecal/msg/publisher.h
Original file line number Diff line number Diff line change
Expand Up @@ -61,8 +61,9 @@ namespace eCAL
*
* @param topic_name_ Unique topic name.
* @param topic_info_ Struct that contains information of the datatype (name, encoding, description) of the topic.
* @param config_ Optional configuration parameters.
**/
CMsgPublisher(const std::string& topic_name_, const struct SDataTypeInformation& topic_info_) : CPublisher(topic_name_, topic_info_)
CMsgPublisher(const std::string& topic_name_, const struct SDataTypeInformation& topic_info_, const Config& config_ = {}) : CPublisher(topic_name_, topic_info_, config_)
{
}

Expand All @@ -71,8 +72,9 @@ namespace eCAL
* If no datatype information about the topic is available, this constructor can be used.
*
* @param topic_name_ Unique topic name.
* @param config_ Optional configuration parameters.
**/
explicit CMsgPublisher(const std::string& topic_name_) : CMsgPublisher(topic_name_, GetDataTypeInformation())
explicit CMsgPublisher(const std::string& topic_name_, const Config& config_ = {}) : CMsgPublisher(topic_name_, GetDataTypeInformation(), config_)
{
}

Expand Down Expand Up @@ -103,12 +105,13 @@ namespace eCAL
*
* @param topic_name_ Unique topic name.
* @param topic_info_ Associated datatype description.
* @param config_ Optional configuration parameters.
*
* @return True if it succeeds, false if it fails.
**/
bool Create(const std::string& topic_name_, const struct SDataTypeInformation& topic_info_)
bool Create(const std::string& topic_name_, const struct SDataTypeInformation& topic_info_, const Config& config_ = {})
{
return(CPublisher::Create(topic_name_, topic_info_));
return(CPublisher::Create(topic_name_, topic_info_, config_));
}

/**
Expand Down
7 changes: 4 additions & 3 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_) : CMsgPublisher<T>(topic_name_, GetDataTypeInformation())
explicit CPublisher(const std::string& topic_name_, const Config& config_ = {}) : CMsgPublisher<T>(topic_name_, GetDataTypeInformation(), config_)
{
}

Expand Down Expand Up @@ -88,12 +88,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 Config& config_ = {})
{
return(CMsgPublisher<T>::Create(topic_name_, GetDataTypeInformation()));
return(CMsgPublisher<T>::Create(topic_name_, GetDataTypeInformation(), config_));
}

private:
Expand Down
16 changes: 0 additions & 16 deletions ecal/core/src/cimpl/ecal_publisher_cimpl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -89,22 +89,6 @@ extern "C"
return(0);
}

ECALC_API int eCAL_Pub_ShareType(ECAL_HANDLE handle_, int state_)
{
if (handle_ == nullptr) return(0);
auto* pub = static_cast<eCAL::CPublisher*>(handle_);
pub->ShareType(state_ != 0);
return(1);
}

ECALC_API int eCAL_Pub_ShareDescription(ECAL_HANDLE handle_, int state_)
{
if (handle_ == nullptr) return(0);
auto* pub = static_cast<eCAL::CPublisher*>(handle_);
pub->ShareDescription(state_ != 0);
return(1);
}

ECALC_API int eCAL_Pub_SetID(ECAL_HANDLE handle_, long long id_)
{
if (handle_ == nullptr) return(0);
Expand Down
5 changes: 1 addition & 4 deletions ecal/core/src/pubsub/ecal_pubgate.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -60,10 +60,7 @@ namespace eCAL

// destroy all remaining publisher
const std::unique_lock<std::shared_timed_mutex> lock(m_topic_name_datawriter_sync);
for (auto iter = m_topic_name_datawriter_map.begin(); iter != m_topic_name_datawriter_map.end(); ++iter)
{
iter->second->Destroy();
}
m_topic_name_datawriter_map.clear();

m_created = false;
}
Expand Down
Loading

0 comments on commit 91b91f4

Please sign in to comment.