changed default arguments for Node

changes how the default context is gotten and
adds an option for enabling/disabling intra
process comms
This commit is contained in:
William Woodall 2015-08-18 18:46:51 -07:00
parent 5568cc2326
commit fb4e836da0
4 changed files with 26 additions and 10 deletions

View file

@ -33,6 +33,13 @@ public:
}; };
DefaultContext::SharedPtr
get_global_default_context()
{
static DefaultContext::SharedPtr default_context = DefaultContext::make_shared();
return default_context;
}
} // namespace default_context } // namespace default_context
} // namespace contexts } // namespace contexts
} // namespace rclcpp } // namespace rclcpp

View file

@ -103,9 +103,11 @@ public:
RCLCPP_SMART_PTR_DEFINITIONS(Node); RCLCPP_SMART_PTR_DEFINITIONS(Node);
/* Create a node based on the node name. */ /* Create a node based on the node name. */
Node(const std::string & node_name); Node(const std::string & node_name, bool use_intra_process_comms = false);
/* Create a node based on the node name and a rclcpp::context::Context. */ /* Create a node based on the node name and a rclcpp::context::Context. */
Node(const std::string & node_name, rclcpp::context::Context::SharedPtr context); Node(
const std::string & node_name, rclcpp::context::Context::SharedPtr context,
bool use_intra_process_comms = false);
/* Get the name of the node. */ /* Get the name of the node. */
const std::string & const std::string &
@ -214,6 +216,8 @@ private:
size_t number_of_services_; size_t number_of_services_;
size_t number_of_clients_; size_t number_of_clients_;
bool use_intra_process_comms_;
mutable std::mutex mutex_; mutable std::mutex mutex_;
std::map<std::string, rclcpp::parameter::ParameterVariant> parameters_; std::map<std::string, rclcpp::parameter::ParameterVariant> parameters_;

View file

@ -39,15 +39,20 @@
using namespace rclcpp; using namespace rclcpp;
using namespace rclcpp::node; using namespace rclcpp::node;
using rclcpp::contexts::default_context::DefaultContext; Node::Node(const std::string & node_name, bool use_intra_process_comms)
: Node(
Node::Node(const std::string & node_name) node_name,
: Node(node_name, DefaultContext::make_shared()) rclcpp::contexts::default_context::get_global_default_context(),
use_intra_process_comms)
{} {}
Node::Node(const std::string & node_name, context::Context::SharedPtr context) Node::Node(
const std::string & node_name,
context::Context::SharedPtr context,
bool use_intra_process_comms)
: name_(node_name), context_(context), : name_(node_name), context_(context),
number_of_subscriptions_(0), number_of_timers_(0), number_of_services_(0) number_of_subscriptions_(0), number_of_timers_(0), number_of_services_(0),
use_intra_process_comms_(use_intra_process_comms)
{ {
size_t domain_id = 0; size_t domain_id = 0;
char * ros_domain_id = nullptr; char * ros_domain_id = nullptr;
@ -163,8 +168,7 @@ Node::create_subscription(
if (!subscriber_handle) { if (!subscriber_handle) {
// *INDENT-OFF* (prevent uncrustify from making unecessary indents here) // *INDENT-OFF* (prevent uncrustify from making unecessary indents here)
throw std::runtime_error( throw std::runtime_error(
std::string("could not create subscription: ") + std::string("could not create subscription: ") + rmw_get_error_string_safe());
rmw_get_error_string_safe());
// *INDENT-ON* // *INDENT-ON*
} }

View file

@ -27,6 +27,7 @@
#include <string.h> #include <string.h>
#include <thread> #include <thread>
#include <rmw/error_handling.h>
#include <rmw/macros.h> #include <rmw/macros.h>
#include <rmw/rmw.h> #include <rmw/rmw.h>