add_odometry_data_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/add_odometry_data_handler.h"
00018 
00019 #include "absl/memory/memory.h"
00020 #include "async_grpc/rpc_handler.h"
00021 #include "cartographer/cloud/internal/map_builder_context_interface.h"
00022 #include "cartographer/cloud/internal/sensor/serialization.h"
00023 #include "cartographer/cloud/proto/map_builder_service.pb.h"
00024 #include "cartographer/sensor/internal/dispatchable.h"
00025 #include "cartographer/sensor/odometry_data.h"
00026 #include "google/protobuf/empty.pb.h"
00027 
00028 namespace cartographer {
00029 namespace cloud {
00030 namespace handlers {
00031 
00032 void AddOdometryDataHandler::OnSensorData(
00033     const proto::AddOdometryDataRequest& request) {
00034   // The 'BlockingQueue' returned by 'sensor_data_queue()' is already
00035   // thread-safe. Therefore it suffices to get an unsynchronized reference to
00036   // the 'MapBuilderContext'.
00037   GetUnsynchronizedContext<MapBuilderContextInterface>()->EnqueueSensorData(
00038       request.sensor_metadata().trajectory_id(),
00039       sensor::MakeDispatchable(request.sensor_metadata().sensor_id(),
00040                                sensor::FromProto(request.odometry_data())));
00041 
00042   // The 'BlockingQueue' in 'LocalTrajectoryUploader' is thread-safe.
00043   // Therefore it suffices to get an unsynchronized reference to the
00044   // 'MapBuilderContext'.
00045   if (GetUnsynchronizedContext<MapBuilderContextInterface>()
00046           ->local_trajectory_uploader()) {
00047     auto sensor_data = absl::make_unique<proto::SensorData>();
00048     *sensor_data->mutable_sensor_metadata() = request.sensor_metadata();
00049     *sensor_data->mutable_odometry_data() = request.odometry_data();
00050     GetUnsynchronizedContext<MapBuilderContextInterface>()
00051         ->local_trajectory_uploader()
00052         ->EnqueueSensorData(std::move(sensor_data));
00053   }
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:35