Set client_id in LoadState(FromFile) (#1320)
parent
5b35641881
commit
33fcc1a3de
|
@ -148,6 +148,11 @@ std::map<int, int> MapBuilderStub::LoadState(
|
|||
LOG(FATAL) << "Not implemented";
|
||||
}
|
||||
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);
|
||||
// Request with the SerializationHeader proto is sent first.
|
||||
|
@ -188,6 +193,7 @@ std::map<int, int> MapBuilderStub::LoadStateFromFile(
|
|||
const std::string& filename) {
|
||||
proto::LoadStateFromFileRequest request;
|
||||
request.set_file_path(filename);
|
||||
request.set_client_id(client_id_);
|
||||
async_grpc::Client<handlers::LoadStateFromFileSignature> client(
|
||||
client_channel_);
|
||||
CHECK(client.Write(request));
|
||||
|
|
|
@ -529,7 +529,7 @@ TEST_F(ClientServerTest, LocalSlam2DUplinkServerRestarting) {
|
|||
server_->WaitForShutdown();
|
||||
}
|
||||
|
||||
TEST_F(ClientServerTest, LoadState) {
|
||||
TEST_F(ClientServerTest, LoadStateAndDelete) {
|
||||
InitializeRealServer();
|
||||
server_->Start();
|
||||
InitializeStub();
|
||||
|
@ -553,9 +553,17 @@ TEST_F(ClientServerTest, LoadState) {
|
|||
int expected_trajectory_id = 0;
|
||||
EXPECT_EQ(trajectory_remapping.size(), 1);
|
||||
EXPECT_EQ(trajectory_remapping.at(0), expected_trajectory_id);
|
||||
stub_->pose_graph()->RunFinalOptimization();
|
||||
EXPECT_TRUE(stub_->pose_graph()->IsTrajectoryFrozen(expected_trajectory_id));
|
||||
EXPECT_FALSE(
|
||||
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();
|
||||
}
|
||||
|
||||
|
|
|
@ -33,6 +33,10 @@ void LoadStateFromFileHandler::OnRequest(
|
|||
auto trajectory_remapping =
|
||||
GetContext<MapBuilderContextInterface>()->map_builder().LoadStateFromFile(
|
||||
request.file_path());
|
||||
for (const auto& entry : trajectory_remapping) {
|
||||
GetContext<MapBuilderContextInterface>()->RegisterClientIdForTrajectory(
|
||||
request.client_id(), entry.second);
|
||||
}
|
||||
auto response = common::make_unique<proto::LoadStateFromFileResponse>();
|
||||
*response->mutable_trajectory_remapping() = ToProto(trajectory_remapping);
|
||||
Send(std::move(response));
|
||||
|
|
|
@ -34,6 +34,9 @@ void LoadStateHandler::OnRequest(const proto::LoadStateRequest& request) {
|
|||
case proto::LoadStateRequest::kSerializationHeader:
|
||||
reader_.AddProto(request.serialization_header());
|
||||
break;
|
||||
case proto::LoadStateRequest::kClientId:
|
||||
client_id_ = request.client_id();
|
||||
break;
|
||||
default:
|
||||
LOG(FATAL) << "Unhandled proto::LoadStateRequest case.";
|
||||
}
|
||||
|
@ -43,6 +46,10 @@ void LoadStateHandler::OnReadsDone() {
|
|||
auto trajectory_remapping =
|
||||
GetContext<MapBuilderContextInterface>()->map_builder().LoadState(
|
||||
&reader_, true);
|
||||
for (const auto& entry : trajectory_remapping) {
|
||||
GetContext<MapBuilderContextInterface>()->RegisterClientIdForTrajectory(
|
||||
client_id_, entry.second);
|
||||
}
|
||||
auto response = common::make_unique<proto::LoadStateResponse>();
|
||||
*response->mutable_trajectory_remapping() = ToProto(trajectory_remapping);
|
||||
Send(std::move(response));
|
||||
|
|
|
@ -37,6 +37,7 @@ class LoadStateHandler : public async_grpc::RpcHandler<LoadStateSignature> {
|
|||
|
||||
private:
|
||||
io::InMemoryProtoStreamReader reader_;
|
||||
std::string client_id_;
|
||||
};
|
||||
|
||||
} // namespace handlers
|
||||
|
|
|
@ -144,6 +144,7 @@ message LoadStateRequest {
|
|||
oneof state_chunk {
|
||||
cartographer.mapping.proto.SerializedData serialized_data = 1;
|
||||
cartographer.mapping.proto.SerializationHeader serialization_header = 2;
|
||||
string client_id = 3;
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -158,6 +159,7 @@ message LoadStateResponse {
|
|||
|
||||
message LoadStateFromFileRequest {
|
||||
string file_path = 1;
|
||||
string client_id = 2;
|
||||
}
|
||||
|
||||
message LoadStateFromFileResponse {
|
||||
|
|
Loading…
Reference in New Issue