Skip to content

Commit

Permalink
Lint
Browse files Browse the repository at this point in the history
Signed-off-by: Michael Carroll <michael@openrobotics.org>
  • Loading branch information
mjcarroll committed Apr 10, 2023
1 parent e8eab41 commit 388712d
Showing 1 changed file with 20 additions and 19 deletions.
39 changes: 20 additions & 19 deletions rmw_fastrtps_shared_cpp/src/rmw_wait.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -54,8 +54,9 @@ bool has_triggered_condition(
for (size_t i = 0; i < guard_conditions->guard_condition_count; ++i) {
void * data = guard_conditions->guard_conditions[i];
auto guard_condition = static_cast<eprosima::fastdds::dds::GuardCondition *>(data);
if (guard_condition->get_trigger_value())
if (guard_condition->get_trigger_value()) {
return true;
}
}
}

Expand All @@ -64,13 +65,14 @@ bool has_triggered_condition(
auto event = static_cast<rmw_event_t *>(events->events[i]);
auto custom_event_info = static_cast<CustomEventInfo *>(event->data);
if (custom_event_info->get_listener()->get_statuscondition().get_trigger_value() ||
custom_event_info->get_listener()->get_event_guard(event->event_type).get_trigger_value())
custom_event_info->get_listener()->get_event_guard(event->event_type).get_trigger_value())
{
return true;
}
}
}

if (subscriptions)
{
if (subscriptions) {
for (size_t i = 0; i < subscriptions->subscriber_count; ++i) {
void * data = subscriptions->subscribers[i];
auto custom_subscriber_info = static_cast<CustomSubscriberInfo *>(data);
Expand All @@ -83,8 +85,7 @@ bool has_triggered_condition(
}
}

if (clients)
{
if (clients) {
for (size_t i = 0; i < clients->client_count; ++i) {
void * data = clients->clients[i];
auto custom_client_info = static_cast<CustomClientInfo *>(data);
Expand All @@ -97,8 +98,7 @@ bool has_triggered_condition(
}
}

if (services)
{
if (services) {
for (size_t i = 0; i < services->service_count; ++i) {
void * data = services->services[i];
auto custom_service_info = static_cast<CustomServiceInfo *>(data);
Expand Down Expand Up @@ -144,20 +144,19 @@ __rmw_wait(
/// Check if any conditions are already true before waiting,
/// allowing us to skip some work of attaching/detaching
bool skip_wait = has_triggered_condition(
subscriptions, guard_conditions, services, clients, events);
subscriptions, guard_conditions, services, clients, events);
bool wait_result = true;
std::vector<eprosima::fastdds::dds::Condition*> attached_conditions;
std::vector<eprosima::fastdds::dds::Condition *> attached_conditions;

if (!skip_wait)
{
if (!skip_wait) {
// In the case that a wait is needed (no triggered conditions), gather the conditions
// to be added to the waitset.
if (subscriptions) {
for (size_t i = 0; i < subscriptions->subscriber_count; ++i) {
void * data = subscriptions->subscribers[i];
auto custom_subscriber_info = static_cast<CustomSubscriberInfo *>(data);
attached_conditions.push_back(
&custom_subscriber_info->data_reader_->get_statuscondition());
&custom_subscriber_info->data_reader_->get_statuscondition());
}
}

Expand Down Expand Up @@ -187,7 +186,7 @@ __rmw_wait(
&custom_event_info->get_listener()->get_statuscondition());
attached_conditions.push_back(
&custom_event_info->get_listener()->get_event_guard(event->event_type));
}
}
}

if (guard_conditions) {
Expand All @@ -201,24 +200,26 @@ __rmw_wait(
// Attach all of the conditions to the wait set.
// \TODO(mjcarroll) When upstream has the ability to attach a vector of conditions,
// switch to that API
for (auto & condition: attached_conditions)
for (auto & condition : attached_conditions) {
fastdds_wait_set->attach_condition(*condition);
}

Duration_t timeout = (wait_timeout) ?
Duration_t{static_cast<int32_t>(wait_timeout->sec),
static_cast<uint32_t>(wait_timeout->nsec)} : eprosima::fastrtps::c_TimeInfinite;
Duration_t{static_cast<int32_t>(wait_timeout->sec),
static_cast<uint32_t>(wait_timeout->nsec)} : eprosima::fastrtps::c_TimeInfinite;

eprosima::fastdds::dds::ConditionSeq triggered_conditions;
ReturnCode_t ret_code = fastdds_wait_set->wait(
triggered_conditions,
timeout);
wait_result = (ret_code == ReturnCode_t::RETCODE_OK);
wait_result = (ret_code == ReturnCode_t::RETCODE_OK);

// Detach all of the conditions from the wait set.
// \TODO(mjcarroll) When upstream has the ability to detach a vector of conditions,
// switch to that API
for (auto & condition: attached_conditions)
for (auto & condition : attached_conditions) {
fastdds_wait_set->detach_condition(*condition);
}
}

// Check the results of the wait, and mark ready entities accordingly.
Expand Down

0 comments on commit 388712d

Please sign in to comment.