Apollo  6.0
Open source self driving car software
play_task_producer.h
Go to the documentation of this file.
1 /******************************************************************************
2  * Copyright 2018 The Apollo Authors. All Rights Reserved.
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 CYBER_TOOLS_CYBER_RECORDER_PLAYER_PLAY_TASK_PRODUCER_H_
18 #define CYBER_TOOLS_CYBER_RECORDER_PLAYER_PLAY_TASK_PRODUCER_H_
19 
20 #include <atomic>
21 #include <cstdint>
22 #include <map>
23 #include <memory>
24 #include <mutex>
25 #include <string>
26 #include <thread>
27 #include <unordered_map>
28 #include <vector>
29 
31 #include "cyber/node/node.h"
32 #include "cyber/node/writer.h"
36 
37 namespace apollo {
38 namespace cyber {
39 namespace record {
40 
42  public:
43  using NodePtr = std::shared_ptr<Node>;
44  using ThreadPtr = std::unique_ptr<std::thread>;
45  using TaskBufferPtr = std::shared_ptr<PlayTaskBuffer>;
46  using RecordReaderPtr = std::shared_ptr<RecordReader>;
47  using WriterPtr = std::shared_ptr<Writer<message::RawMessage>>;
48  using WriterMap = std::unordered_map<std::string, WriterPtr>;
49  using MessageTypeMap = std::unordered_map<std::string, std::string>;
50 
51  PlayTaskProducer(const TaskBufferPtr& task_buffer,
52  const PlayParam& play_param);
53  virtual ~PlayTaskProducer();
54 
55  bool Init();
56  void Start();
57  void Stop();
58 
59  const PlayParam& play_param() const { return play_param_; }
60  bool is_stopped() const { return is_stopped_.load(); }
61 
62  private:
63  bool ReadRecordInfo();
64  bool UpdatePlayParam();
65  bool CreateWriters();
66  void ThreadFunc();
67 
68  PlayParam play_param_;
69  TaskBufferPtr task_buffer_;
70  ThreadPtr produce_th_;
71 
72  std::atomic<bool> is_initialized_;
73  std::atomic<bool> is_stopped_;
74 
75  NodePtr node_;
76  WriterMap writers_;
77  MessageTypeMap msg_types_;
78  std::vector<RecordReaderPtr> record_readers_;
79 
80  uint64_t earliest_begin_time_;
81  uint64_t latest_end_time_;
82  uint64_t total_msg_num_;
83 
84  static const uint32_t kMinTaskBufferSize;
85  static const uint32_t kPreloadTimeSec;
86  static const uint64_t kSleepIntervalNanoSec;
87 };
88 
89 } // namespace record
90 } // namespace cyber
91 } // namespace apollo
92 
93 #endif // CYBER_TOOLS_CYBER_RECORDER_PLAYER_PLAY_TASK_PRODUCER_H_
std::shared_ptr< Writer< message::RawMessage > > WriterPtr
Definition: play_task_producer.h:47
PlanningContext is the runtime context in planning. It is persistent across multiple frames...
Definition: atomic_hash_map.h:25
Definition: play_task_producer.h:41
std::shared_ptr< PlayTaskBuffer > TaskBufferPtr
Definition: play_task_producer.h:45
std::shared_ptr< RecordReader > RecordReaderPtr
Definition: play_task_producer.h:46
std::unordered_map< std::string, WriterPtr > WriterMap
Definition: play_task_producer.h:48
Definition: play_param.h:29
std::unordered_map< std::string, std::string > MessageTypeMap
Definition: play_task_producer.h:49
bool is_stopped() const
Definition: play_task_producer.h:60
std::shared_ptr< Node > NodePtr
Definition: play_task_producer.h:43
std::unique_ptr< std::thread > ThreadPtr
Definition: play_task_producer.h:44
const PlayParam & play_param() const
Definition: play_task_producer.h:59
PlayTaskProducer(const TaskBufferPtr &task_buffer, const PlayParam &play_param)