write_state_handler.cc
Go to the documentation of this file.
00001 /*
00002  * Copyright 2018 The Cartographer Authors
00003  *
00004  * Licensed under the Apache License, Version 2.0 (the "License");
00005  * you may not use this file except in compliance with the License.
00006  * You may obtain a copy of the License at
00007  *
00008  *      http://www.apache.org/licenses/LICENSE-2.0
00009  *
00010  * Unless required by applicable law or agreed to in writing, software
00011  * distributed under the License is distributed on an "AS IS" BASIS,
00012  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
00013  * See the License for the specific language governing permissions and
00014  * limitations under the License.
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       /*include_unfinished_submaps=*/false, &proto_stream_writer);
00053   proto_stream_writer.Close();
00054 }
00055 
00056 }  // namespace handlers
00057 }  // namespace cloud
00058 }  // namespace cartographer


cartographer
Author(s): The Cartographer Authors
autogenerated on Thu May 9 2019 02:27:36