Apollo 10.0
自动驾驶开放平台
apollo::cyber::Component< M0, NullType, NullType, NullType > 模板类 参考abstract

#include <component.h>

类 apollo::cyber::Component< M0, NullType, NullType, NullType > 继承关系图:
apollo::cyber::Component< M0, NullType, NullType, NullType > 的协作图:

Public 成员函数

 Component ()
 
 ~Component () override
 
bool Initialize (const ComponentConfig &config) override
 
bool Process (const std::shared_ptr< M0 > &msg)
 
- Public 成员函数 继承自 apollo::cyber::ComponentBase
virtual ~ComponentBase ()
 
virtual bool Initialize (const TimerComponentConfig &config)
 
virtual void Shutdown ()
 
template<typename T >
bool GetProtoConfig (T *config) const
 

额外继承的成员函数

- Public 类型 继承自 apollo::cyber::ComponentBase
template<typename M >
using Reader = cyber::Reader< M >
 
- Protected 成员函数 继承自 apollo::cyber::ComponentBase
virtual bool Init ()=0
 
virtual void Clear ()
 
const std::string & ConfigFilePath () const
 
void LoadConfigFiles (const ComponentConfig &config)
 
void LoadConfigFiles (const TimerComponentConfig &config)
 
- Protected 属性 继承自 apollo::cyber::ComponentBase
std::atomic< bool > is_shutdown_ = {false}
 
std::shared_ptr< Nodenode_ = nullptr
 
std::string config_file_path_ = ""
 
std::vector< std::shared_ptr< ReaderBase > > readers_
 

详细描述

template<typename M0>
class apollo::cyber::Component< M0, NullType, NullType, NullType >

在文件 component.h103 行定义.

构造及析构函数说明

◆ Component()

template<typename M0 >
apollo::cyber::Component< M0, NullType, NullType, NullType >::Component ( )
inline

在文件 component.h105 行定义.

105{}

◆ ~Component()

template<typename M0 >
apollo::cyber::Component< M0, NullType, NullType, NullType >::~Component ( )
inlineoverride

在文件 component.h106 行定义.

106{}

成员函数说明

◆ Initialize()

template<typename M0 >
bool apollo::cyber::Component< M0, NullType, NullType, NullType >::Initialize ( const ComponentConfig config)
overridevirtual

重载 apollo::cyber::ComponentBase .

在文件 component.h164 行定义.

165 {
166 node_.reset(new Node(config.name()));
167 LoadConfigFiles(config);
168
169 if (config.readers_size() < 1) {
170 AERROR << "Invalid config file: too few readers.";
171 return false;
172 }
173
174 if (!Init()) {
175 AERROR << "Component Init() failed.";
176 return false;
177 }
178
179 bool is_reality_mode = GlobalData::Instance()->IsRealityMode();
180
181 ReaderConfig reader_cfg;
182 reader_cfg.channel_name = config.readers(0).channel();
183 reader_cfg.qos_profile.CopyFrom(config.readers(0).qos_profile());
184 reader_cfg.pending_queue_size = config.readers(0).pending_queue_size();
185
186 auto role_attr = std::make_shared<proto::RoleAttributes>();
187 role_attr->set_node_name(config.name());
188 role_attr->set_channel_name(config.readers(0).channel());
189
190 std::weak_ptr<Component<M0>> self =
191 std::dynamic_pointer_cast<Component<M0>>(shared_from_this());
192 auto func = [self, role_attr](const std::shared_ptr<M0>& msg) {
193 auto start_time = Time::Now().ToMicrosecond();
194 auto ptr = self.lock();
195 if (ptr) {
196 ptr->Process(msg);
197 } else {
198 AERROR << "Component object has been destroyed.";
199 }
200 auto end_time = Time::Now().ToMicrosecond();
201 // sampling proc latency and cyber latency in microsecond
202 uint64_t process_start_time;
203 statistics::Statistics::Instance()->SamplingProcLatency<uint64_t>(
204 *role_attr, end_time - start_time);
205 if (statistics::Statistics::Instance()->GetProcStatus(
206 *role_attr, &process_start_time) &&
207 (start_time - process_start_time) > 0) {
208 statistics::Statistics::Instance()->SamplingCyberLatency(
209 *role_attr, start_time - process_start_time);
210 }
211 };
212
213 std::shared_ptr<Reader<M0>> reader = nullptr;
214
215 if (cyber_likely(is_reality_mode)) {
216 reader = node_->CreateReader<M0>(reader_cfg);
217 } else {
218 reader = node_->CreateReader<M0>(reader_cfg, func);
219 }
220
221 if (reader == nullptr) {
222 AERROR << "Component create reader failed.";
223 return false;
224 }
225 readers_.emplace_back(std::move(reader));
226
227 if (cyber_unlikely(!is_reality_mode)) {
228 return true;
229 }
230
231 data::VisitorConfig conf = {readers_[0]->ChannelId(),
232 readers_[0]->PendingQueueSize()};
233 auto dv = std::make_shared<data::DataVisitor<M0>>(conf);
234 croutine::RoutineFactory factory =
235 croutine::CreateRoutineFactory<M0>(func, dv);
236 auto sched = scheduler::Instance();
237 return sched->CreateTask(factory, node_->Name());
238}
Definition node.h:31
std::vector< std::shared_ptr< ReaderBase > > readers_
std::shared_ptr< Node > node_
void LoadConfigFiles(const ComponentConfig &config)
uint64_t ToMicrosecond() const
convert time to microsecond (us).
Definition time.cc:85
static Time Now()
get the current time.
Definition time.cc:57
#define cyber_likely(x)
Definition macros.h:29
#define cyber_unlikely(x)
Definition macros.h:30
#define AERROR
Definition log.h:44

◆ Process()

template<typename M0 >
bool apollo::cyber::Component< M0, NullType, NullType, NullType >::Process ( const std::shared_ptr< M0 > &  msg)

在文件 component.h144 行定义.

145 {
146 if (is_shutdown_.load()) {
147 return true;
148 }
149 return Proc(msg);
150}
std::atomic< bool > is_shutdown_

该类的文档由以下文件生成: