Go to the documentation of this file.00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017 #include "cartographer/cloud/internal/handlers/write_state_handler.h"
00018
00019 #include "async_grpc/rpc_handler.h"
00020 #include "cartographer/cloud/internal/map_builder_context_interface.h"
00021 #include "cartographer/cloud/internal/map_builder_server.h"
00022 #include "cartographer/cloud/proto/map_builder_service.pb.h"
00023 #include "cartographer/io/internal/in_memory_proto_stream.h"
00024
00025 namespace cartographer {
00026 namespace cloud {
00027 namespace handlers {
00028
00029 void WriteStateHandler::OnRequest(const google::protobuf::Empty& request) {
00030 auto writer = GetWriter();
00031 io::ForwardingProtoStreamWriter proto_stream_writer(
00032 [writer](const google::protobuf::Message* proto) {
00033 if (!proto) {
00034 writer.WritesDone();
00035 return true;
00036 }
00037
00038 auto response = absl::make_unique<proto::WriteStateResponse>();
00039 if (proto->GetTypeName() ==
00040 "cartographer.mapping.proto.SerializationHeader") {
00041 response->mutable_header()->CopyFrom(*proto);
00042 } else if (proto->GetTypeName() ==
00043 "cartographer.mapping.proto.SerializedData") {
00044 response->mutable_serialized_data()->CopyFrom(*proto);
00045 } else {
00046 LOG(FATAL) << "Unsupported message type: " << proto->GetTypeName();
00047 }
00048 writer.Write(std::move(response));
00049 return true;
00050 });
00051 GetContext<MapBuilderContextInterface>()->map_builder().SerializeState(
00052 false, &proto_stream_writer);
00053 proto_stream_writer.Close();
00054 }
00055
00056 }
00057 }
00058 }