Skip to content

Commit c5b630b

Browse files
authored
check request header for intraprocess (#139)
* check request header for intraprocess * set request header intraprocess to false in execute_service
1 parent fbc29c9 commit c5b630b

File tree

3 files changed

+8
-2
lines changed

3 files changed

+8
-2
lines changed

rclcpp/include/rclcpp/experimental/service_intra_process.hpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -160,6 +160,7 @@ class ServiceIntraProcess : public ServiceIntraProcessBase
160160
// we are overloading the rmw_request_id semantics to provide the intra process client ID.
161161
auto req_id = std::make_shared<rmw_request_id_t>();
162162
req_id->sequence_number = intra_process_client_id;
163+
req_id->from_intra_process = true;
163164

164165
SharedResponse response = any_callback_.dispatch(serv_handle, req_id, std::move(typed_request));
165166

rclcpp/include/rclcpp/service.hpp

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -545,8 +545,12 @@ class Service
545545
void
546546
send_response(rmw_request_id_t & req_id, typename ServiceT::Response & response)
547547
{
548-
if (use_intra_process_)
549-
{
548+
if (!use_intra_process_ && req_id.from_intra_process) {
549+
throw std::invalid_argument(
550+
"intraprocess request incompatible with non-intraprocess service");
551+
}
552+
553+
if (use_intra_process_ && req_id.from_intra_process) {
550554
auto intra_response = std::make_shared<typename ServiceT::Response>(response);
551555
// The sequence number here is used as a proxy for the intra-process client ID
552556
service_intra_process_->send_response(req_id.sequence_number, intra_response);

rclcpp/src/rclcpp/executor.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -673,6 +673,7 @@ void
673673
Executor::execute_service(rclcpp::ServiceBase::SharedPtr service)
674674
{
675675
auto request_header = service->create_request_header();
676+
request_header->from_intra_process = false;
676677
std::shared_ptr<void> request = service->create_request();
677678
take_and_do_error_handling(
678679
"taking a service server request from service",

0 commit comments

Comments
 (0)