Skip to content

Commit

Permalink
Add enable_rosout into NodeOptions. (#900)
Browse files Browse the repository at this point in the history
* Add disable_rosout into NodeOptions.

Signed-off-by: Barry Xu <Barry.Xu@sony.com>

* Update comments

Signed-off-by: Barry Xu <Barry.Xu@sony.com>

* keep implementation consistency by using enable_rosout name

Signed-off-by: Barry Xu <Barry.Xu@sony.com>

* fix error comment

Signed-off-by: Barry Xu <Barry.Xu@sony.com>

* add test case for node options

Signed-off-by: Barry Xu <Barry.Xu@sony.com>

* fix source about copy value and reset rcl_node_options, add more test cases

Signed-off-by: Barry Xu <Barry.Xu@sony.com>
  • Loading branch information
Barry-Xu-2018 authored and hidmic committed Dec 3, 2019
1 parent e2efb76 commit e494b3e
Show file tree
Hide file tree
Showing 3 changed files with 66 additions and 0 deletions.
18 changes: 18 additions & 0 deletions rclcpp/include/rclcpp/node_options.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -152,6 +152,22 @@ class NodeOptions
NodeOptions &
use_global_arguments(bool use_global_arguments);

/// Return the enable_rosout flag.
RCLCPP_PUBLIC
bool
enable_rosout() const;

/// Set the enable_rosout flag, return this for parameter idiom.
/**
* If false this will cause the node not to use rosout logging.
*
* Defaults to true for now, as there are still some cases where it is
* desirable.
*/
RCLCPP_PUBLIC
NodeOptions &
enable_rosout(bool enable_rosout);

/// Return the use_intra_process_comms flag.
RCLCPP_PUBLIC
bool
Expand Down Expand Up @@ -312,6 +328,8 @@ class NodeOptions

bool use_global_arguments_ {true};

bool enable_rosout_ {true};

bool use_intra_process_comms_ {false};

bool start_parameter_services_ {true};
Expand Down
16 changes: 16 additions & 0 deletions rclcpp/src/rclcpp/node_options.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,7 @@ NodeOptions::operator=(const NodeOptions & other)
this->arguments_ = other.arguments_;
this->parameter_overrides_ = other.parameter_overrides_;
this->use_global_arguments_ = other.use_global_arguments_;
this->enable_rosout_ = other.enable_rosout_;
this->use_intra_process_comms_ = other.use_intra_process_comms_;
this->start_parameter_services_ = other.start_parameter_services_;
this->allocator_ = other.allocator_;
Expand All @@ -90,6 +91,7 @@ NodeOptions::get_rcl_node_options() const
node_options_->allocator = this->allocator_;
node_options_->use_global_arguments = this->use_global_arguments_;
node_options_->domain_id = this->get_domain_id_from_env();
node_options_->enable_rosout = this->enable_rosout_;

int c_argc = 0;
std::unique_ptr<const char *[]> c_argv;
Expand Down Expand Up @@ -198,6 +200,20 @@ NodeOptions::use_global_arguments(bool use_global_arguments)
return *this;
}

bool
NodeOptions::enable_rosout() const
{
return this->enable_rosout_;
}

NodeOptions &
NodeOptions::enable_rosout(bool enable_rosout)
{
this->node_options_.reset(); // reset node options to make it be recreated on next access.
this->enable_rosout_ = enable_rosout;
return *this;
}

bool
NodeOptions::use_intra_process_comms() const
{
Expand Down
32 changes: 32 additions & 0 deletions rclcpp/test/test_node_options.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -98,3 +98,35 @@ TEST(TestNodeOptions, bad_ros_args) {
options.get_rcl_node_options(),
rclcpp::exceptions::UnknownROSArgsError);
}

TEST(TestNodeOptions, enable_rosout) {
{
auto options = rclcpp::NodeOptions();
EXPECT_TRUE(options.enable_rosout());
EXPECT_TRUE(options.get_rcl_node_options()->enable_rosout);
}

{
auto options = rclcpp::NodeOptions().enable_rosout(false);
EXPECT_FALSE(options.enable_rosout());
EXPECT_FALSE(options.get_rcl_node_options()->enable_rosout);
}

{
auto options = rclcpp::NodeOptions().enable_rosout(true);
EXPECT_TRUE(options.enable_rosout());
EXPECT_TRUE(options.get_rcl_node_options()->enable_rosout);
}

{
auto options = rclcpp::NodeOptions();
EXPECT_TRUE(options.enable_rosout());
EXPECT_TRUE(options.get_rcl_node_options()->enable_rosout);
options.enable_rosout(false);
EXPECT_FALSE(options.enable_rosout());
EXPECT_FALSE(options.get_rcl_node_options()->enable_rosout);
options.enable_rosout(true);
EXPECT_TRUE(options.enable_rosout());
EXPECT_TRUE(options.get_rcl_node_options()->enable_rosout);
}
}

0 comments on commit e494b3e

Please sign in to comment.