Skip to content

Commit 1afda51

Browse files
committed
add get_domain_id method to rclcpp:Context.
Signed-off-by: Tomoya.Fujita <[email protected]>
1 parent bbf2c4c commit 1afda51

File tree

2 files changed

+16
-0
lines changed

2 files changed

+16
-0
lines changed

rclcpp/include/rclcpp/context.hpp

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -139,6 +139,11 @@ class Context : public std::enable_shared_from_this<Context>
139139
rclcpp::InitOptions
140140
get_init_options();
141141

142+
/// Return actual domain id.
143+
RCLCPP_PUBLIC
144+
size_t
145+
get_domain_id() const;
146+
142147
/// Return the shutdown reason, or empty string if not shutdown.
143148
/**
144149
* This function is thread-safe.

rclcpp/src/rclcpp/context.cpp

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -275,6 +275,17 @@ Context::get_init_options()
275275
return init_options_;
276276
}
277277

278+
size_t
279+
Context::get_domain_id() const
280+
{
281+
size_t domain_id;
282+
rcl_ret_t ret = rcl_context_get_domain_id(rcl_context_.get(), &domain_id);
283+
if (RCL_RET_OK != ret) {
284+
rclcpp::exceptions::throw_from_rcl_error(ret, "failed to get domain id from context");
285+
}
286+
return domain_id;
287+
}
288+
278289
std::string
279290
Context::shutdown_reason()
280291
{

0 commit comments

Comments
 (0)