collator.h
Go to the documentation of this file.
1 /*
2  * Copyright 2016 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 
17 #ifndef CARTOGRAPHER_SENSOR_COLLATOR_H_
18 #define CARTOGRAPHER_SENSOR_COLLATOR_H_
19 
20 #include <functional>
21 #include <memory>
22 #include <unordered_map>
23 #include <unordered_set>
24 #include <vector>
25 
28 
29 namespace cartographer {
30 namespace sensor {
31 
32 class Collator {
33  public:
34  using Callback = std::function<void(const string&, std::unique_ptr<Data>)>;
35 
36  Collator() {}
37 
38  Collator(const Collator&) = delete;
39  Collator& operator=(const Collator&) = delete;
40 
41  // Adds a trajectory to produce sorted sensor output for. Calls 'callback'
42  // for each collated sensor data.
43  void AddTrajectory(int trajectory_id,
44  const std::unordered_set<string>& expected_sensor_ids,
45  Callback callback);
46 
47  // Marks 'trajectory_id' as finished.
48  void FinishTrajectory(int trajectory_id);
49 
50  // Adds 'data' for 'trajectory_id' to be collated. 'data' must contain valid
51  // sensor data. Sensor packets with matching 'sensor_id' must be added in time
52  // order.
53  void AddSensorData(int trajectory_id, const string& sensor_id,
54  std::unique_ptr<Data> data);
55 
56  // Dispatches all queued sensor packets. May only be called once.
57  // AddSensorData may not be called after Flush.
58  void Flush();
59 
60  // Must only be called if at least one unfinished trajectory exists. Returns
61  // the ID of the trajectory that needs more data before the Collator is
62  // unblocked.
63  int GetBlockingTrajectoryId() const;
64 
65  private:
66  // Queue keys are a pair of trajectory ID and sensor identifier.
68 
69  // Map of trajectory ID to all associated QueueKeys.
70  std::unordered_map<int, std::vector<QueueKey>> queue_keys_;
71 };
72 
73 } // namespace sensor
74 } // namespace cartographer
75 
76 #endif // CARTOGRAPHER_SENSOR_COLLATOR_H_
std::function< void(const string &, std::unique_ptr< Data >)> Callback
Definition: collator.h:34
OrderedMultiQueue queue_
Definition: collator.h:67
std::unordered_map< int, std::vector< QueueKey > > queue_keys_
Definition: collator.h:70
Collator & operator=(const Collator &)=delete
void AddTrajectory(int trajectory_id, const std::unordered_set< string > &expected_sensor_ids, Callback callback)
Definition: collator.cc:22
void AddSensorData(int trajectory_id, const string &sensor_id, std::unique_ptr< Data > data)
Definition: collator.cc:42
void FinishTrajectory(int trajectory_id)
Definition: collator.cc:36
int GetBlockingTrajectoryId() const
Definition: collator.cc:49


cartographer
Author(s):
autogenerated on Wed Jun 5 2019 21:57:58