Skip to content

Commit

Permalink
convert to template
Browse files Browse the repository at this point in the history
Signed-off-by: Nicola Loi <[email protected]>
  • Loading branch information
nicolaloi committed Oct 23, 2024
1 parent 4ba1a8c commit c8d667f
Showing 1 changed file with 26 additions and 18 deletions.
44 changes: 26 additions & 18 deletions rosbag2_transport/src/rosbag2_transport/player.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -298,7 +298,9 @@ class PlayerImpl
void configure_play_until_timestamp();
bool shall_stop_at_timestamp(const rcutils_time_point_value_t & msg_timestamp) const;

void print_status(const char status) const;
template<char status>
void print_status() const;
void check_and_print_status() const;
void print_running_status() const;
void print_paused_status() const;
void print_delayed_status() const;
Expand Down Expand Up @@ -630,11 +632,7 @@ void PlayerImpl::stop()
playback_thread_.join();
}
}
if (clock_->is_paused()) {
print_paused_status();
} else {
print_running_status();
}
check_and_print_status();
}

void PlayerImpl::pause()
Expand Down Expand Up @@ -675,11 +673,7 @@ bool PlayerImpl::set_rate(double rate)
} else {
RCLCPP_WARN_STREAM(owner_->get_logger(), "Failed to set rate to invalid value " << rate);
}
if (clock_->is_paused()) {
print_paused_status();
} else {
print_running_status();
}
check_and_print_status();
return ok;
}

Expand Down Expand Up @@ -1571,33 +1565,47 @@ const rosbag2_transport::PlayOptions & PlayerImpl::get_play_options()
return play_options_;
}

inline void PlayerImpl::print_status(const char status) const
template<char status>
void PlayerImpl::print_status() const
{
static_assert(status == 'R' || status == 'P' || status == 'D',
"Invalid status character");
double current_time_secs = RCUTILS_NS_TO_S(static_cast<double>(clock_->now()));
double progress_secs = current_time_secs - starting_time_secs_;
printf(" Bag Time %13.6f Duration %.6f/%.6f [%c] \r",
current_time_secs, progress_secs, duration_secs_, status);
fflush(stdout);
}

inline void PlayerImpl::print_running_status() const
void PlayerImpl::check_and_print_status() const
{
if (!disable_progress_bar_) {
if (clock_->is_paused()) {
print_status<'P'>();
} else {
print_status<'R'>();
}
}
}

void PlayerImpl::print_running_status() const
{
if (!disable_progress_bar_) {
print_status('R');
print_status<'R'>();
}
}

inline void PlayerImpl::print_paused_status() const
void PlayerImpl::print_paused_status() const
{
if (!disable_progress_bar_) {
print_status('P');
print_status<'P'>();
}
}

inline void PlayerImpl::print_delayed_status() const
void PlayerImpl::print_delayed_status() const
{
if (!disable_progress_bar_) {
print_status('D');
print_status<'D'>();
}
}

Expand Down

0 comments on commit c8d667f

Please sign in to comment.