From a74f0ce69c76a229e23bad01f493cfd21676175b Mon Sep 17 00:00:00 2001 From: Michael Nolan Date: Fri, 6 Dec 2019 07:50:12 -0500 Subject: [PATCH] Add request ID to entity generation Add a request_id field to the GenerateEntity and EntityGenerated messages. When Scrimmage generates an entity at runtime, it will copy the request ID from the GenerateEntity message to the EntityGenerated message. This is to allow plugins that generate entities to be able to associate a GenerateEntity request with the entity that was generated in response --- include/scrimmage/simcontrol/SimControl.h | 3 ++- msgs/Event.proto | 2 ++ src/simcontrol/SimControl.cpp | 11 ++++++++--- 3 files changed, 12 insertions(+), 4 deletions(-) diff --git a/include/scrimmage/simcontrol/SimControl.h b/include/scrimmage/simcontrol/SimControl.h index bd2149ade6..82bf354d6c 100644 --- a/include/scrimmage/simcontrol/SimControl.h +++ b/include/scrimmage/simcontrol/SimControl.h @@ -212,7 +212,8 @@ class SimControl { * parameters. */ bool generate_entity(const int &ent_desc_id, - std::map ¶ms); + std::map ¶ms, + int request_id=0); /// @brief Get the pointer to the MissionParser instance. MissionParsePtr mp(); diff --git a/msgs/Event.proto b/msgs/Event.proto index ce28f7b5e3..40d2ff5831 100644 --- a/msgs/Event.proto +++ b/msgs/Event.proto @@ -26,6 +26,7 @@ message UserForcedExit { message EntityGenerated { int32 entity_id = 1; + int32 request_id = 2; } message EntityRemoved { @@ -44,4 +45,5 @@ message GenerateEntity { string entity_tag = 1; scrimmage_proto.State state = 2; repeated KeyValuePair entity_param = 3; + int32 request_id = 4; } diff --git a/src/simcontrol/SimControl.cpp b/src/simcontrol/SimControl.cpp index 5ac96db237..cc5ee283c8 100644 --- a/src/simcontrol/SimControl.cpp +++ b/src/simcontrol/SimControl.cpp @@ -269,11 +269,12 @@ bool SimControl::generate_entity(const int &ent_desc_id) { if (it_params == mp_->entity_descriptions().end()) { return false; } - return generate_entity(ent_desc_id, it_params->second); + return generate_entity(ent_desc_id, it_params->second, 0); } bool SimControl::generate_entity(const int &ent_desc_id, - std::map ¶ms) { + std::map ¶ms, + int request_id) { #if ENABLE_JSBSIM == 1 params["JSBSIM_ROOT"] = jsbsim_root_; #endif @@ -378,6 +379,7 @@ bool SimControl::generate_entity(const int &ent_desc_id, auto msg = std::make_shared>(); msg->data.set_entity_id(ent->id().id()); + msg->data.set_request_id(request_id); pub_ent_gen_->publish(msg); next_id_++; @@ -846,7 +848,10 @@ bool SimControl::start() { params[msg->data.entity_param(i).key()] = msg->data.entity_param(i).value(); } - if (not this->generate_entity(it_ent_desc_id->second, params)) { + int request_id = 0; + request_id = msg->data.request_id(); + + if (not this->generate_entity(it_ent_desc_id->second, params, request_id)) { cout << "Failed to generate entity with tag: " << msg->data.entity_tag() << endl; return;