write_state_handler.cc
Go to the documentation of this file.
1 /*
2  * Copyright 2018 The Cartographer Authors
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  * http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */
16 
18 
19 #include "async_grpc/rpc_handler.h"
22 #include "cartographer/cloud/proto/map_builder_service.pb.h"
24 
25 namespace cartographer {
26 namespace cloud {
27 namespace handlers {
28 
29 void WriteStateHandler::OnRequest(const google::protobuf::Empty& request) {
30  auto writer = GetWriter();
31  io::ForwardingProtoStreamWriter proto_stream_writer(
32  [writer](const google::protobuf::Message* proto) {
33  if (!proto) {
34  writer.WritesDone();
35  return true;
36  }
37 
38  auto response = common::make_unique<proto::WriteStateResponse>();
39  if (proto->GetTypeName() ==
40  "cartographer.mapping.proto.SerializationHeader") {
41  response->mutable_header()->CopyFrom(*proto);
42  } else if (proto->GetTypeName() ==
43  "cartographer.mapping.proto.SerializedData") {
44  response->mutable_serialized_data()->CopyFrom(*proto);
45  } else {
46  LOG(FATAL) << "Unsupported message type: " << proto->GetTypeName();
47  }
48  writer.Write(std::move(response));
49  return true;
50  });
51  GetContext<MapBuilderContextInterface>()->map_builder().SerializeState(
52  &proto_stream_writer);
53  proto_stream_writer.Close();
54 }
55 
56 } // namespace handlers
57 } // namespace cloud
58 } // namespace cartographer


cartographer
Author(s): The Cartographer Authors
autogenerated on Mon Feb 28 2022 22:00:59