@@ -40,9 +40,12 @@ namespace ROS2
40
40
41
41
m_spawnService = ros2Node->create_service <gazebo_msgs::srv::SpawnEntity>(
42
42
" spawn_entity" ,
43
- [this ](const SpawnEntityRequest request, SpawnEntityResponse response)
43
+ [this ](
44
+ const SpawnEntityServiceHandle service_handle,
45
+ const std::shared_ptr<rmw_request_id_t > header,
46
+ const SpawnEntityRequest request)
44
47
{
45
- SpawnEntity (request, response );
48
+ SpawnEntity (service_handle, header, request );
46
49
});
47
50
48
51
m_getSpawnPointInfoService = ros2Node->create_service <gazebo_msgs::srv::GetModelState>(
@@ -89,26 +92,31 @@ namespace ROS2
89
92
}
90
93
}
91
94
92
- void ROS2SpawnerComponent::SpawnEntity (const SpawnEntityRequest request, SpawnEntityResponse response)
95
+ void ROS2SpawnerComponent::SpawnEntity (
96
+ const SpawnEntityServiceHandle service_handle, const std::shared_ptr<rmw_request_id_t > header, const SpawnEntityRequest request)
93
97
{
94
98
AZStd::string spawnableName (request->name .c_str ());
95
99
AZStd::string spawnableNamespace (request->robot_namespace .c_str ());
96
100
AZStd::string spawnPointName (request->xml .c_str (), request->xml .size ());
97
101
102
+ SpawnEntityResponse response;
103
+
98
104
auto namespaceValidation = ROS2Names::ValidateNamespace (spawnableNamespace);
99
105
if (!namespaceValidation.IsSuccess ())
100
106
{
101
- response->success = false ;
102
- response->status_message = namespaceValidation.GetError ().data ();
107
+ response.success = false ;
108
+ response.status_message = namespaceValidation.GetError ().data ();
109
+ service_handle->send_response (*header, response);
103
110
return ;
104
111
}
105
112
106
113
auto spawnPoints = GetSpawnPoints ();
107
114
108
115
if (!m_controller.GetSpawnables ().contains (spawnableName))
109
116
{
110
- response->success = false ;
111
- response->status_message = " Could not find spawnable with given name: " + request->name ;
117
+ response.success = false ;
118
+ response.status_message = " Could not find spawnable with given name: " + request->name ;
119
+ service_handle->send_response (*header, response);
112
120
return ;
113
121
}
114
122
@@ -146,9 +154,14 @@ namespace ROS2
146
154
PreSpawn (id, view, transform, spawnableName, spawnableNamespace);
147
155
};
148
156
149
- spawner->SpawnAllEntities (m_tickets.at (spawnableName), optionalArgs);
157
+ optionalArgs.m_completionCallback = [service_handle, header](auto id, auto view)
158
+ {
159
+ SpawnEntityResponse response;
160
+ response.success = true ;
161
+ service_handle->send_response (*header, response);
162
+ };
150
163
151
- response-> success = true ;
164
+ spawner-> SpawnAllEntities (m_tickets. at (spawnableName), optionalArgs) ;
152
165
}
153
166
154
167
void ROS2SpawnerComponent::PreSpawn (
0 commit comments