Set client_id in LoadState(FromFile) (#1320)

master
gaschler 2018-07-23 16:42:44 +02:00 committed by GitHub
parent 5b35641881
commit 33fcc1a3de
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
6 changed files with 29 additions and 1 deletions

View File

@ -148,6 +148,11 @@ std::map<int, int> MapBuilderStub::LoadState(
LOG(FATAL) << "Not implemented"; LOG(FATAL) << "Not implemented";
} }
async_grpc::Client<handlers::LoadStateSignature> client(client_channel_); async_grpc::Client<handlers::LoadStateSignature> client(client_channel_);
{
proto::LoadStateRequest request;
request.set_client_id(client_id_);
CHECK(client.Write(request));
}
io::ProtoStreamDeserializer deserializer(reader); io::ProtoStreamDeserializer deserializer(reader);
// Request with the SerializationHeader proto is sent first. // Request with the SerializationHeader proto is sent first.
@ -188,6 +193,7 @@ std::map<int, int> MapBuilderStub::LoadStateFromFile(
const std::string& filename) { const std::string& filename) {
proto::LoadStateFromFileRequest request; proto::LoadStateFromFileRequest request;
request.set_file_path(filename); request.set_file_path(filename);
request.set_client_id(client_id_);
async_grpc::Client<handlers::LoadStateFromFileSignature> client( async_grpc::Client<handlers::LoadStateFromFileSignature> client(
client_channel_); client_channel_);
CHECK(client.Write(request)); CHECK(client.Write(request));

View File

@ -529,7 +529,7 @@ TEST_F(ClientServerTest, LocalSlam2DUplinkServerRestarting) {
server_->WaitForShutdown(); server_->WaitForShutdown();
} }
TEST_F(ClientServerTest, LoadState) { TEST_F(ClientServerTest, LoadStateAndDelete) {
InitializeRealServer(); InitializeRealServer();
server_->Start(); server_->Start();
InitializeStub(); InitializeStub();
@ -553,9 +553,17 @@ TEST_F(ClientServerTest, LoadState) {
int expected_trajectory_id = 0; int expected_trajectory_id = 0;
EXPECT_EQ(trajectory_remapping.size(), 1); EXPECT_EQ(trajectory_remapping.size(), 1);
EXPECT_EQ(trajectory_remapping.at(0), expected_trajectory_id); EXPECT_EQ(trajectory_remapping.at(0), expected_trajectory_id);
stub_->pose_graph()->RunFinalOptimization();
EXPECT_TRUE(stub_->pose_graph()->IsTrajectoryFrozen(expected_trajectory_id)); EXPECT_TRUE(stub_->pose_graph()->IsTrajectoryFrozen(expected_trajectory_id));
EXPECT_FALSE( EXPECT_FALSE(
stub_->pose_graph()->IsTrajectoryFinished(expected_trajectory_id)); stub_->pose_graph()->IsTrajectoryFinished(expected_trajectory_id));
for (const auto& entry : trajectory_remapping) {
int trajectory_id = entry.second;
stub_->pose_graph()->DeleteTrajectory(trajectory_id);
stub_->pose_graph()->RunFinalOptimization();
EXPECT_EQ(stub_->pose_graph()->GetTrajectoryStates().at(trajectory_id),
PoseGraphInterface::TrajectoryState::DELETED);
}
server_->Shutdown(); server_->Shutdown();
} }

View File

@ -33,6 +33,10 @@ void LoadStateFromFileHandler::OnRequest(
auto trajectory_remapping = auto trajectory_remapping =
GetContext<MapBuilderContextInterface>()->map_builder().LoadStateFromFile( GetContext<MapBuilderContextInterface>()->map_builder().LoadStateFromFile(
request.file_path()); request.file_path());
for (const auto& entry : trajectory_remapping) {
GetContext<MapBuilderContextInterface>()->RegisterClientIdForTrajectory(
request.client_id(), entry.second);
}
auto response = common::make_unique<proto::LoadStateFromFileResponse>(); auto response = common::make_unique<proto::LoadStateFromFileResponse>();
*response->mutable_trajectory_remapping() = ToProto(trajectory_remapping); *response->mutable_trajectory_remapping() = ToProto(trajectory_remapping);
Send(std::move(response)); Send(std::move(response));

View File

@ -34,6 +34,9 @@ void LoadStateHandler::OnRequest(const proto::LoadStateRequest& request) {
case proto::LoadStateRequest::kSerializationHeader: case proto::LoadStateRequest::kSerializationHeader:
reader_.AddProto(request.serialization_header()); reader_.AddProto(request.serialization_header());
break; break;
case proto::LoadStateRequest::kClientId:
client_id_ = request.client_id();
break;
default: default:
LOG(FATAL) << "Unhandled proto::LoadStateRequest case."; LOG(FATAL) << "Unhandled proto::LoadStateRequest case.";
} }
@ -43,6 +46,10 @@ void LoadStateHandler::OnReadsDone() {
auto trajectory_remapping = auto trajectory_remapping =
GetContext<MapBuilderContextInterface>()->map_builder().LoadState( GetContext<MapBuilderContextInterface>()->map_builder().LoadState(
&reader_, true); &reader_, true);
for (const auto& entry : trajectory_remapping) {
GetContext<MapBuilderContextInterface>()->RegisterClientIdForTrajectory(
client_id_, entry.second);
}
auto response = common::make_unique<proto::LoadStateResponse>(); auto response = common::make_unique<proto::LoadStateResponse>();
*response->mutable_trajectory_remapping() = ToProto(trajectory_remapping); *response->mutable_trajectory_remapping() = ToProto(trajectory_remapping);
Send(std::move(response)); Send(std::move(response));

View File

@ -37,6 +37,7 @@ class LoadStateHandler : public async_grpc::RpcHandler<LoadStateSignature> {
private: private:
io::InMemoryProtoStreamReader reader_; io::InMemoryProtoStreamReader reader_;
std::string client_id_;
}; };
} // namespace handlers } // namespace handlers

View File

@ -144,6 +144,7 @@ message LoadStateRequest {
oneof state_chunk { oneof state_chunk {
cartographer.mapping.proto.SerializedData serialized_data = 1; cartographer.mapping.proto.SerializedData serialized_data = 1;
cartographer.mapping.proto.SerializationHeader serialization_header = 2; cartographer.mapping.proto.SerializationHeader serialization_header = 2;
string client_id = 3;
} }
} }
@ -158,6 +159,7 @@ message LoadStateResponse {
message LoadStateFromFileRequest { message LoadStateFromFileRequest {
string file_path = 1; string file_path = 1;
string client_id = 2;
} }
message LoadStateFromFileResponse { message LoadStateFromFileResponse {