Skip to content

Commit

Permalink
eCAL::CSubscriber API configurable
Browse files Browse the repository at this point in the history
  • Loading branch information
rex-schilasky committed May 17, 2024
1 parent 2fb0bc2 commit 4123770
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 22 deletions.
24 changes: 14 additions & 10 deletions ecal/core/include/ecal/ecal_subscriber.h
Original file line number Diff line number Diff line change
@@ -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.
Expand Down Expand Up @@ -28,6 +28,7 @@
#include <ecal/ecal_callback.h>
#include <ecal/ecal_deprecate.h>
#include <ecal/ecal_os.h>
#include <ecal/ecal_subscriber_config.h>
#include <ecal/ecal_types.h>

#include <memory>
Expand Down Expand Up @@ -92,17 +93,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 CSubscriber(const std::string& topic_name_, const SDataTypeInformation& topic_info_);
ECAL_API CSubscriber(const std::string& topic_name_, const SDataTypeInformation& data_type_info_, const Subscriber::Configuration& config_ = {});

/**
* @brief Constructor.
*
* @param topic_name_ Unique topic name.
* @param topic_name_ Unique topic name.
* @param data_type_info_ Topic data type information (encoding, type, descriptor).
**/
ECAL_API explicit CSubscriber(const std::string& topic_name_);
ECAL_API explicit CSubscriber(const std::string& topic_name_, const Subscriber::Configuration& config_ = {});

/**
* @brief Destructor.
Expand Down Expand Up @@ -132,21 +135,22 @@ namespace eCAL
/**
* @brief Creates this object.
*
* @param topic_name_ Unique topic name.
* @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_);
ECAL_API bool Create(const std::string& topic_name_, const SDataTypeInformation& data_type_info_, const Subscriber::Configuration& config_ = {});

/**
* @brief Creates this object.
*
* @param topic_name_ Unique topic name.
* @param topic_info_ Topic information (encoding, type, descriptor)
*
* @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_);

/**
* @brief Destroys this object.
Expand Down
24 changes: 12 additions & 12 deletions ecal/core/src/pubsub/ecal_subscriber.cpp
Original file line number Diff line number Diff line change
@@ -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.
Expand Down Expand Up @@ -40,14 +40,14 @@ namespace eCAL
{
}

CSubscriber::CSubscriber(const std::string& topic_name_, const SDataTypeInformation& topic_info_)
CSubscriber::CSubscriber(const std::string& topic_name_, const SDataTypeInformation& data_type_info_, const Subscriber::Configuration& config_)
: CSubscriber()
{
CSubscriber::Create(topic_name_, topic_info_);
CSubscriber::Create(topic_name_, data_type_info_, config_);
}

CSubscriber::CSubscriber(const std::string& topic_name_)
: CSubscriber(topic_name_, SDataTypeInformation{})
CSubscriber::CSubscriber(const std::string& topic_name_, const Subscriber::Configuration& config_)
: CSubscriber(topic_name_, SDataTypeInformation{}, config_)
{}

CSubscriber::~CSubscriber()
Expand Down Expand Up @@ -75,18 +75,13 @@ namespace eCAL
return *this;
}

bool CSubscriber::Create(const std::string& topic_name_)
{
return Create(topic_name_, SDataTypeInformation{});
}

bool CSubscriber::Create(const std::string& topic_name_, const SDataTypeInformation& topic_info_)
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);

// create datareader
m_datareader = std::make_shared<CDataReader>(topic_name_, topic_info_);
m_datareader = std::make_shared<CDataReader>(topic_name_, data_type_info_);

// register datareader
g_subgate()->Register(topic_name_, m_datareader);
Expand All @@ -96,6 +91,11 @@ namespace eCAL
return(m_created);
}

bool CSubscriber::Create(const std::string& topic_name_)
{
return Create(topic_name_, SDataTypeInformation{});
}

bool CSubscriber::Destroy()
{
if(!m_created) return(false);
Expand Down

0 comments on commit 4123770

Please sign in to comment.