Skip to content

Commit

Permalink
New review corrections
Browse files Browse the repository at this point in the history
Signed-off-by: Javier Gil Aviles <[email protected]>
  • Loading branch information
Javgilavi committed Jan 24, 2025
1 parent fe4b668 commit 0cd2a24
Show file tree
Hide file tree
Showing 5 changed files with 41 additions and 43 deletions.
4 changes: 2 additions & 2 deletions sustainml_cpp/include/sustainml_cpp/types/types.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -2440,7 +2440,7 @@ class RequestType
* @param x Reference to the object RequestTypeImpl that will be copied.
*/
eProsima_user_DllExport RequestType& operator =(
const RequestTypeImpl* x);
const RequestTypeImpl& x);

/*!
* @brief Comparison operator.
Expand Down Expand Up @@ -2594,7 +2594,7 @@ class ResponseType
* @param x Reference to the object ResponseTypeImpl that will be copied.
*/
eProsima_user_DllExport ResponseType& operator =(
const ResponseTypeImpl* x);
const ResponseTypeImpl& x);

/*!
* @brief Comparison operator.
Expand Down
12 changes: 6 additions & 6 deletions sustainml_cpp/src/cpp/core/NodeImpl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -87,12 +87,12 @@ NodeImpl::NodeImpl(
req_res_ = new RequestReplier([this, name](void* input)
{
RequestTypeImpl* in = static_cast<RequestTypeImpl*>(input);
types::RequestType req;
req = in;

if (req.node_id() == static_cast<int32_t>(common::get_node_id_from_name(name)))
if (in->node_id() == static_cast<int32_t>(common::get_node_id_from_name(name)))
{
types::ResponseType res;
types::RequestType req;
req = *in;
req_res_listener_.on_configuration_request(req, res);
req_res_->write_res(res.get_impl());
}
Expand Down Expand Up @@ -120,12 +120,12 @@ NodeImpl::NodeImpl(
req_res_ = new RequestReplier([this, name](void* input)
{
RequestTypeImpl* in = static_cast<RequestTypeImpl*>(input);
types::RequestType req;
req = in;

if (req.node_id() == static_cast<int32_t>(common::get_node_id_from_name(name)))
if (in->node_id() == static_cast<int32_t>(common::get_node_id_from_name(name)))
{
types::ResponseType res;
types::RequestType req;
req = *in;
req_res_listener_.on_configuration_request(req, res);
req_res_->write_res(res.get_impl());
}
Expand Down
44 changes: 22 additions & 22 deletions sustainml_cpp/src/cpp/core/RequestReplier.cpp
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// Copyright 2023 Proyectos y Sistemas de Mantenimiento SL (eProsima).
// Copyright 2025 Proyectos y Sistemas de Mantenimiento SL (eProsima).
//
// 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 @@ -27,10 +27,10 @@ namespace sustainml {
namespace core {

RequestReplier::RequestReplier(
std::function<void(void*)> callback,
const char* topicw,
const char* topicr,
void* data)
std::function<void(void*)> callback,
const char* topicw,
const char* topicr,
void* data)
: callback_(callback)
, topicw_(topicw)
, topicr_(topicr)
Expand Down Expand Up @@ -58,15 +58,15 @@ RequestReplier::RequestReplier(
typeReq_.register_type(participant_);

// Create a Topics
if(std::string(topicw_) == "sustainml/request")
if (std::string(topicw_) == "sustainml/request")
{
topicR_= participant_->create_topic(topicr_, typeRes_.get_type_name(), TOPIC_QOS_DEFAULT);
topicW_= participant_->create_topic(topicw_, typeReq_.get_type_name(), TOPIC_QOS_DEFAULT);
topicR_ = participant_->create_topic(topicr_, typeRes_.get_type_name(), TOPIC_QOS_DEFAULT);
topicW_ = participant_->create_topic(topicw_, typeReq_.get_type_name(), TOPIC_QOS_DEFAULT);
}
else
{
topicR_= participant_->create_topic(topicr_, typeReq_.get_type_name(), TOPIC_QOS_DEFAULT);
topicW_= participant_->create_topic(topicw_, typeRes_.get_type_name(), TOPIC_QOS_DEFAULT);
topicR_ = participant_->create_topic(topicr_, typeReq_.get_type_name(), TOPIC_QOS_DEFAULT);
topicW_ = participant_->create_topic(topicw_, typeRes_.get_type_name(), TOPIC_QOS_DEFAULT);
}

// Configure DataReader QoS
Expand Down Expand Up @@ -96,19 +96,19 @@ RequestReplier::~RequestReplier()
}

void RequestReplier::write_res(
ResponseTypeImpl* res)
ResponseTypeImpl* res)
{
writer_->write(res);
}

void RequestReplier::write_req(
RequestTypeImpl* req)
RequestTypeImpl* req)
{
writer_->write(req);
}

RequestReplier::RequestReplyControlListener::RequestReplyControlListener(
RequestReplier* node)
RequestReplier* node)
: node_(node)
{

Expand All @@ -120,7 +120,7 @@ RequestReplier::RequestReplyControlListener::~RequestReplyControlListener()
}

void RequestReplier::RequestReplyControlListener::on_data_available(
eprosima::fastdds::dds::DataReader* reader)
eprosima::fastdds::dds::DataReader* reader)
{
// Create a data and SampleInfo instance
SampleInfo info;
Expand All @@ -136,27 +136,27 @@ void RequestReplier::RequestReplyControlListener::on_data_available(
}

void RequestReplier::RequestReplyControlListener::on_subscription_matched(
eprosima::fastdds::dds::DataReader* reader,
const eprosima::fastdds::dds::SubscriptionMatchedStatus& status)
eprosima::fastdds::dds::DataReader* reader,
const eprosima::fastdds::dds::SubscriptionMatchedStatus& status)
{

// New remote DataWriter discovered
if (status.current_count_change == 1)
{
matched_ = status.current_count;
std::cout << "Subscriber matched." << std::endl;
matched_ = status.current_count;
std::cout << "Subscriber matched." << std::endl;
}
// New remote DataWriter undiscovered
else if (status.current_count_change == -1)
{
matched_ = status.current_count;
std::cout << "Subscriber unmatched." << std::endl;
matched_ = status.current_count;
std::cout << "Subscriber unmatched." << std::endl;
}
// Non-valid option
else
{
std::cout << status.current_count_change
<< " is not a valid value for SubscriptionMatchedStatus current count change" << std::endl;
EPROSIMA_LOG_ERROR(RequestReplier, status.current_count_change
<< " is not a valid value for SubscriptionMatchedStatus current count change");
}
}

Expand Down
4 changes: 1 addition & 3 deletions sustainml_cpp/src/cpp/orchestrator/OrchestratorNode.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -118,12 +118,10 @@ OrchestratorNode::OrchestratorNode(
req_res_ = new core::RequestReplier([this](void* input)
{
ResponseTypeImpl* in = static_cast<ResponseTypeImpl*>(input);
types::ResponseType res;
res = in;

{
std::lock_guard<std::mutex> lock(this->mtx_);
this->res_ = res;
this->res_ = *in;
}
this->cv_.notify_all();
}, "sustainml/request", "sustainml/response", res_.get_impl());
Expand Down
20 changes: 10 additions & 10 deletions sustainml_cpp/src/cpp/types/types.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2171,11 +2171,11 @@ RequestType& RequestType::operator =(
}

RequestType& RequestType::operator =(
const RequestTypeImpl* x)
const RequestTypeImpl& x)
{
this->impl_->node_id() = x->node_id();
this->impl_->transaction_id() = x->transaction_id();
this->impl_->configuration() = x->configuration();
this->impl_->node_id() = x.node_id();
this->impl_->transaction_id() = x.transaction_id();
this->impl_->configuration() = x.configuration();
return *this;
}

Expand Down Expand Up @@ -2312,13 +2312,13 @@ ResponseType& ResponseType::operator =(
}

ResponseType& ResponseType::operator =(
const ResponseTypeImpl* x)
const ResponseTypeImpl& x)
{
this->impl_->node_id() = x->node_id();
this->impl_->transaction_id() = x->transaction_id();
this->impl_->success() = x->success();
this->impl_->err_code() = x->err_code();
this->impl_->configuration() = x->configuration();
this->impl_->node_id() = x.node_id();
this->impl_->transaction_id() = x.transaction_id();
this->impl_->success() = x.success();
this->impl_->err_code() = x.err_code();
this->impl_->configuration() = x.configuration();
return *this;
}

Expand Down

0 comments on commit 0cd2a24

Please sign in to comment.