Skip to content

Commit

Permalink
mon_cli fixed
Browse files Browse the repository at this point in the history
mon_tui fixed
ecal_clang fixed
samples (massive_pub_sub, monitoring_get_topics, monitoring_get_services, proto_dyn_json_rec, proto_dyn_rec, ping_client) fixed
descgate test fixed
ecal/cimpl/ecal_registration_cimpl.h Registration C API needs to be discussed (remove it or reimplement it id based instead name based)
  • Loading branch information
rex-schilasky committed Dec 4, 2024
1 parent 8341ba2 commit c5929d9
Show file tree
Hide file tree
Showing 14 changed files with 93 additions and 52 deletions.
11 changes: 1 addition & 10 deletions app/mon/mon_cli/src/ecal_mon_cli.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -351,20 +351,11 @@ void ProcProto(const std::string& topic_name, int msg_count)
// sleep 1000 ms
std::this_thread::sleep_for(std::chrono::milliseconds(1000));

// get topic type
eCAL::SDataTypeInformation topic_info;
eCAL::Registration::GetTopicDataTypeInformation(topic_name, topic_info);
if(topic_info.name.empty())
{
std::cout << "could not get type name for topic " << topic_name << std::endl;
return;
}

// create dynamic subscribers for receiving and decoding messages and assign callback
eCAL::protobuf::CDynamicSubscriber sub(topic_name);
std::atomic<int> cnt(msg_count);
auto msg_cb = [&cnt](const std::shared_ptr<google::protobuf::Message>& msg_) { if (cnt != 0) { std::cout << msg_->DebugString() << std::endl; if (cnt > 0) cnt--; } };
sub.AddReceiveCallback(std::bind(msg_cb, std::placeholders::_2));
sub.AddReceiveCallback(std::bind(msg_cb, std::placeholders::_3));

// enter main loop
while(eCAL::Ok() && (cnt != 0))
Expand Down
4 changes: 2 additions & 2 deletions app/mon/mon_plugins/protobuf_reflection/src/plugin_widget.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ PluginWidget::PluginWidget(const QString& topic_name, const QString& topic_type,
ui_.publish_timestamp_warning_label->setVisible(false);

// Add eCAL Callbacks
subscriber_.AddReceiveCallback(std::bind(&PluginWidget::onProtoMessageCallback, this, std::placeholders::_2, std::placeholders::_3));
subscriber_.AddReceiveCallback(std::bind(&PluginWidget::onProtoMessageCallback, this, std::placeholders::_3, std::placeholders::_4));
subscriber_.AddErrorCallback(std::bind(&PluginWidget::onProtoErrorCallback, this, std::placeholders::_1));

// Button connections
Expand Down Expand Up @@ -319,7 +319,7 @@ void PluginWidget::onUpdate()
void PluginWidget::onResume()
{
// Add eCAL Callbacks
subscriber_.AddReceiveCallback(std::bind(&PluginWidget::onProtoMessageCallback, this, std::placeholders::_2, std::placeholders::_3));
subscriber_.AddReceiveCallback(std::bind(&PluginWidget::onProtoMessageCallback, this, std::placeholders::_3, std::placeholders::_4));
subscriber_.AddErrorCallback(std::bind(&PluginWidget::onProtoErrorCallback, this, std::placeholders::_1));
}

Expand Down
2 changes: 1 addition & 1 deletion app/mon/mon_plugins/signals_plotting/src/plugin_widget.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ PluginWidget::PluginWidget(const QString& topic_name, const QString& topic_type,
ui_.publish_timestamp_warning_label->setVisible(false);

// Add eCAL Callbacks
subscriber_.AddReceiveCallback(std::bind(&PluginWidget::onProtoMessageCallback, this, std::placeholders::_2, std::placeholders::_3));
subscriber_.AddReceiveCallback(std::bind(&PluginWidget::onProtoMessageCallback, this, std::placeholders::_3, std::placeholders::_4));
subscriber_.AddErrorCallback(std::bind(&PluginWidget::onProtoErrorCallback, this, std::placeholders::_1));

// Button connections
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ class ProtoMessageVisualizationViewModel : public MessageVisualizationViewModel
: subscriber{topic}
{
using namespace std::placeholders;
subscriber.AddReceiveCallback(std::bind(&ProtoMessageVisualizationViewModel::OnMessage, this, _2, _3));
subscriber.AddReceiveCallback(std::bind(&ProtoMessageVisualizationViewModel::OnMessage, this, _3, _4));
}

ProtectedMessage message() const
Expand Down
4 changes: 4 additions & 0 deletions ecal/core/include/ecal/cimpl/ecal_registration_cimpl.h
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,8 @@
#include <ecal/ecal_os.h>
#include <ecal/ecalc_types.h>

#if 0 // TODO: We have to rethink this API.

#ifdef __cplusplus
extern "C"
{
Expand Down Expand Up @@ -174,3 +176,5 @@ extern "C"
#endif /*__cplusplus*/

#endif /*ecal_registration_cimpl_h_included*/

#endif
4 changes: 4 additions & 0 deletions ecal/core/src/cimpl/ecal_registration_cimpl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,8 @@
* @brief eCAL registration c interface
**/

#if 0 // TODO: We have to rethink this API.

#include <ecal/ecal.h>
#include <ecal/cimpl/ecal_registration_cimpl.h>

Expand Down Expand Up @@ -177,3 +179,5 @@ extern "C"
return 0;
}
}

#endif
Original file line number Diff line number Diff line change
Expand Up @@ -187,7 +187,7 @@ int main(int argc, char** argv)
num_pub = pub_ids.size();
for (const auto& id : pub_ids)
{
eCAL::Registration::SQualityTopicInfo topic_info;
eCAL::SDataTypeInformation topic_info;
eCAL::Registration::GetPublisherInfo(id, topic_info);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,15 +38,17 @@ int main(int argc, char **argv)
{
// GetServices
{
std::set<eCAL::Registration::SServiceMethodId> service_method_id_set;

std::map<eCAL::Registration::SServiceMethod, eCAL::SServiceMethodInformation> service_info_map;

start_time = std::chrono::steady_clock::now();
for (run = 0; run < runs; ++run)
{
eCAL::Registration::GetServices(service_info_map);
service_method_id_set = eCAL::Registration::GetServiceIDs();
}

auto num_services = service_info_map.size();
auto num_services = service_method_id_set.size();
auto diff_time = std::chrono::duration_cast<std::chrono::milliseconds>(std::chrono::steady_clock::now() - start_time);
std::cout << "GetServices : " << static_cast<double>(diff_time.count()) / runs << " ms" << " (" << num_services << " services)" << std::endl;
std::cout << std::endl;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,15 +38,17 @@ int main(int argc, char **argv)
{
// GetTopics
{
std::map<std::string, eCAL::SDataTypeInformation> topic_info_map;
std::set<eCAL::Registration::STopicId> topic_id_pub_set;
std::set<eCAL::Registration::STopicId> topic_id_sub_set;

start_time = std::chrono::steady_clock::now();
for (run = 0; run < runs; ++run)
{
eCAL::Registration::GetTopics(topic_info_map);
topic_id_pub_set = eCAL::Registration::GetPublisherIDs();
topic_id_sub_set = eCAL::Registration::GetSubscriberIDs();
}

auto num_topics = topic_info_map.size();
auto num_topics = topic_id_pub_set.size() + topic_id_sub_set.size();
auto diff_time = std::chrono::duration_cast<std::chrono::milliseconds>(std::chrono::steady_clock::now() - start_time);
std::cout << "GetTopics : " << static_cast<double>(diff_time.count()) / runs << " ms" << " (" << num_topics << " topics)" << std::endl;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,9 +25,9 @@

const std::string MESSAGE_NAME("person");

void ProtoMsgCallback(const char* topic_name_, const std::string& msg_, long long /*time_*/, long long /*clock_*/, long long /*id_*/)
void ProtoMsgCallback(const eCAL::Registration::STopicId& topic_id_, const std::string& msg_)
{
std::cout << topic_name_ << " : " << msg_ << std::endl;
std::cout << topic_id_.topic_name << " : " << msg_ << std::endl;
std::cout << std::endl;
}

Expand All @@ -38,7 +38,7 @@ int main(int argc, char **argv)

// create dynamic subscribers for receiving and decoding messages
eCAL::protobuf::CDynamicJSONSubscriber sub(MESSAGE_NAME);
sub.AddReceiveCallback(ProtoMsgCallback);
sub.AddReceiveCallback(std::bind(ProtoMsgCallback, std::placeholders::_1, std::placeholders::_3));

// enter main loop
while(eCAL::Ok())
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -270,9 +270,9 @@ void ProcProtoMsg(const google::protobuf::Message& msg_, const std::string& pref
}
}

void ProtoMsgCallback(const char* topic_name_, const std::shared_ptr<google::protobuf::Message>& msg_)
void ProtoMsgCallback(const eCAL::Registration::STopicId& topic_id_, const std::shared_ptr<google::protobuf::Message>& msg_)
{
ProcProtoMsg(*msg_, topic_name_);
ProcProtoMsg(*msg_, topic_id_.topic_name);
std::cout << std::endl;
}

Expand All @@ -283,7 +283,7 @@ int main(int argc, char **argv)

// create dynamic subscribers for receiving and decoding messages
eCAL::protobuf::CDynamicSubscriber sub(MESSAGE_NAME);
sub.AddReceiveCallback(std::bind(ProtoMsgCallback, std::placeholders::_1, std::placeholders::_2));
sub.AddReceiveCallback(std::bind(ProtoMsgCallback, std::placeholders::_1, std::placeholders::_3));

// enter main loop
while(eCAL::Ok())
Expand Down
26 changes: 18 additions & 8 deletions ecal/samples/cpp/services/ping_client_dyn/src/ping_client_dyn.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -48,18 +48,28 @@ int main(int argc, char **argv)

// get service method type names
std::string req_type;
std::string req_desc;
std::string resp_type;
if (!eCAL::Registration::GetServiceTypeNames(service_name, method_name, req_type, resp_type))
std::string resp_desc;
auto service_ids = eCAL::Registration::GetServiceIDs();
bool service_info_found(false);
for (const auto& service_id : service_ids)
{
throw std::runtime_error("Could not get service type names !");
if ((service_id.service_name == service_name) && (service_id.method_name == method_name))
{
eCAL::SServiceMethodInformation service_method_info;
eCAL::Registration::GetServiceInfo(service_id, service_method_info);
req_type = service_method_info.request_type.name;
req_desc = service_method_info.request_type.descriptor;
resp_type = service_method_info.response_type.name;
resp_desc = service_method_info.response_type.descriptor;
service_info_found = true;
break;
}
}

// get service method type descriptions
std::string req_desc;
std::string resp_desc;
if (!eCAL::Registration::GetServiceDescription(service_name, method_name, req_desc, resp_desc))
if (!service_info_found)
{
throw std::runtime_error("Could not get service type descriptions !");
throw std::runtime_error("Could not get service type names and service type descriptions!");
}

// create dynamic protobuf message decoder to create request and response message objects
Expand Down
20 changes: 10 additions & 10 deletions ecal/tests/cpp/descgate_test/src/descgate_getentities.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -146,15 +146,15 @@ TEST(core_cpp_descgate, PublisherQualities)
{
for (const auto& id : id_set)
{
eCAL::Registration::SQualityTopicInfo quality_info;
bool found = desc_gate.GetPublisherInfo(id, quality_info);
eCAL::SDataTypeInformation topic_info;
bool found = desc_gate.GetPublisherInfo(id, topic_info);
EXPECT_TRUE(found);
if (found)
{
std::string tname = id.topic_name;
EXPECT_EQ(tname + "-tdatatype.name", quality_info.info.name);
EXPECT_EQ(tname + "-tdatatype.encoding", quality_info.info.encoding);
EXPECT_EQ(tname + "-tdatatype.descriptor", quality_info.info.descriptor);
EXPECT_EQ(tname + "-tdatatype.name", topic_info.name);
EXPECT_EQ(tname + "-tdatatype.encoding", topic_info.encoding);
EXPECT_EQ(tname + "-tdatatype.descriptor", topic_info.descriptor);
}
}
}
Expand Down Expand Up @@ -229,15 +229,15 @@ TEST(core_cpp_descgate, SubscriberQualities)
{
for (const auto& id : id_set)
{
eCAL::Registration::SQualityTopicInfo quality_info;
bool found = desc_gate.GetSubscriberInfo(id, quality_info);
eCAL::SDataTypeInformation topic_info;
bool found = desc_gate.GetSubscriberInfo(id, topic_info);
EXPECT_TRUE(found);
if (found)
{
std::string tname = id.topic_name;
EXPECT_EQ(tname + "-tdatatype.name", quality_info.info.name);
EXPECT_EQ(tname + "-tdatatype.encoding", quality_info.info.encoding);
EXPECT_EQ(tname + "-tdatatype.descriptor", quality_info.info.descriptor);
EXPECT_EQ(tname + "-tdatatype.name", topic_info.name);
EXPECT_EQ(tname + "-tdatatype.encoding", topic_info.encoding);
EXPECT_EQ(tname + "-tdatatype.descriptor", topic_info.descriptor);
}
}
}
Expand Down
44 changes: 36 additions & 8 deletions lang/python/core/src/ecal_clang.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -30,14 +30,39 @@
#include <vector>
#include <functional>

static char* str_malloc(const std::string& buf_s_)
namespace
{
void* cbuf = malloc(buf_s_.size());
if(cbuf != nullptr)
char* str_malloc(const std::string& buf_s_)
{
memcpy(cbuf, buf_s_.data(), buf_s_.size());
void* cbuf = malloc(buf_s_.size());
if (cbuf != nullptr)
{
memcpy(cbuf, buf_s_.data(), buf_s_.size());
}
return(static_cast<char*>(cbuf));
}

bool GetTopicDataTypeInformation(const char* topic_name_, eCAL::SDataTypeInformation& topic_info_)
{
// try to find topic name in publisher set
for (const auto& pub_id : eCAL::Registration::GetPublisherIDs())
{
if (pub_id.topic_name == topic_name_)
{
return eCAL::Registration::GetPublisherInfo(pub_id, topic_info_);
}
}
// try to find topic name in subscriber set
const auto& sub_ids = eCAL::Registration::GetSubscriberIDs();
for (const auto& sub_id : sub_ids)
{
if (sub_id.topic_name == topic_name_)
{
return eCAL::Registration::GetSubscriberInfo(sub_id, topic_info_);
}
}
return false;
}
return(static_cast<char*>(cbuf));
}

/****************************************/
Expand Down Expand Up @@ -176,7 +201,8 @@ void ecal_enable_loopback(const int state_)
bool ecal_get_type_name(const char* topic_name_, const char** topic_type_, int* topic_type_len_)
{
eCAL::SDataTypeInformation topic_info;
bool ret = eCAL::Registration::GetTopicDataTypeInformation(topic_name_, topic_info);
// get the first matching topic type information for the given topic name found in either the publisher or subscriber id set !
bool ret = GetTopicDataTypeInformation(topic_name_, topic_info);
if(ret)
{
std::string topic_type_s = topic_info.name;
Expand Down Expand Up @@ -204,7 +230,8 @@ bool ecal_get_type_name(const char* topic_name_, const char** topic_type_, int*
bool ecal_get_type_encoding(const char* topic_name_, const char** topic_encoding_, int* topic_encoding_len_)
{
eCAL::SDataTypeInformation topic_info;
bool ret = eCAL::Registration::GetTopicDataTypeInformation(topic_name_, topic_info);
// get the first matching topic type information for the given topic name found in either the publisher or subscriber id set !
bool ret = GetTopicDataTypeInformation(topic_name_, topic_info);
if (ret)
{
std::string topic_encoding_s = topic_info.encoding;
Expand Down Expand Up @@ -232,7 +259,8 @@ bool ecal_get_type_encoding(const char* topic_name_, const char** topic_encoding
bool ecal_get_description(const char* topic_name_, const char** topic_desc_, int* topic_desc_len_)
{
eCAL::SDataTypeInformation topic_info;
bool ret = eCAL::Registration::GetTopicDataTypeInformation(topic_name_, topic_info);
// get the first matching topic type information for the given topic name found in either the publisher or subscriber id set !
bool ret = GetTopicDataTypeInformation(topic_name_, topic_info);
if(ret)
{
std::string topic_desc_s = topic_info.descriptor;
Expand Down

0 comments on commit c5929d9

Please sign in to comment.