collator_interface.h
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 #ifndef CARTOGRAPHER_SENSOR_COLLATOR_INTERFACE_H_
00018 #define CARTOGRAPHER_SENSOR_COLLATOR_INTERFACE_H_
00019 
00020 #include <functional>
00021 #include <memory>
00022 #include <vector>
00023 
00024 #include "absl/container/flat_hash_set.h"
00025 #include "absl/types/optional.h"
00026 #include "cartographer/sensor/data.h"
00027 
00028 namespace cartographer {
00029 namespace sensor {
00030 
00031 class CollatorInterface {
00032  public:
00033   using Callback =
00034       std::function<void(const std::string&, std::unique_ptr<Data>)>;
00035 
00036   CollatorInterface() {}
00037   virtual ~CollatorInterface() {}
00038   CollatorInterface(const CollatorInterface&) = delete;
00039   CollatorInterface& operator=(const CollatorInterface&) = delete;
00040 
00041   // Adds a trajectory to produce sorted sensor output for. Calls 'callback'
00042   // for each collated sensor data.
00043   virtual void AddTrajectory(
00044       int trajectory_id,
00045       const absl::flat_hash_set<std::string>& expected_sensor_ids,
00046       const Callback& callback) = 0;
00047 
00048   // Marks 'trajectory_id' as finished.
00049   virtual void FinishTrajectory(int trajectory_id) = 0;
00050 
00051   // Adds 'data' for 'trajectory_id' to be collated. 'data' must contain valid
00052   // sensor data. Sensor packets with matching 'data.sensor_id_' must be added
00053   // in time order.
00054   virtual void AddSensorData(int trajectory_id, std::unique_ptr<Data> data) = 0;
00055 
00056   // Dispatches all queued sensor packets. May only be called once.
00057   // AddSensorData may not be called after Flush.
00058   virtual void Flush() = 0;
00059 
00060   // Must only be called if at least one unfinished trajectory exists. Returns
00061   // the ID of the trajectory that needs more data before CollatorInterface is
00062   // unblocked. Returns 'nullopt' for implementations that do not wait for a
00063   // particular trajectory.
00064   virtual absl::optional<int> GetBlockingTrajectoryId() const = 0;
00065 };
00066 
00067 }  // namespace sensor
00068 }  // namespace cartographer
00069 
00070 #endif  // CARTOGRAPHER_SENSOR_COLLATOR_INTERFACE_H_


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