Apollo 10.0
自动驾驶开放平台
routing_component.cc
浏览该文件的文档.
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
18
19#include <utility>
20
23
25
26namespace apollo {
27namespace routing {
28
30 RoutingConfig routing_conf;
32 << "Unable to load routing conf file: "
34
35 AINFO << "Config file: " << cyber::ComponentBase::ConfigFilePath()
36 << " is loaded.";
37
39 attr.set_channel_name(routing_conf.topic_config().routing_response_topic());
40 auto qos = attr.mutable_qos_profile();
42 qos->set_reliability(
44 qos->set_durability(
46 response_writer_ = node_->CreateWriter<routing::RoutingResponse>(attr);
47
49 attr_history.set_channel_name(
51 auto qos_history = attr_history.mutable_qos_profile();
52 qos_history->set_history(
54 qos_history->set_reliability(
56 qos_history->set_durability(
58
59 response_history_writer_ =
60 node_->CreateWriter<routing::RoutingResponse>(attr_history);
61 std::weak_ptr<RoutingComponent> self =
62 std::dynamic_pointer_cast<RoutingComponent>(shared_from_this());
63 timer_.reset(new ::apollo::cyber::Timer(
64 FLAGS_routing_response_history_interval_ms,
65 [self, this]() {
66 auto ptr = self.lock();
67 if (ptr) {
68 std::lock_guard<std::mutex> guard(this->mutex_);
69 if (this->response_ != nullptr) {
70 auto timestamp = apollo::cyber::Clock::NowInSeconds();
71 response_->mutable_header()->set_timestamp_sec(timestamp);
72 this->response_history_writer_->Write(*response_);
73 }
74 }
75 },
76 false));
77 timer_->Start();
78
79 return routing_.Init().ok() && routing_.Start().ok();
80}
81
83 const std::shared_ptr<routing::RoutingRequest>& request) {
84 auto response = std::make_shared<routing::RoutingResponse>();
85 if (!routing_.Process(request, response.get())) {
86 return false;
87 }
88 common::util::FillHeader(node_->Name(), response.get());
89 response_writer_->Write(response);
90 {
91 std::lock_guard<std::mutex> guard(mutex_);
92 response_ = std::move(response);
93 }
94 return true;
95}
96
97} // namespace routing
98} // namespace apollo
bool ok() const
check whether the return status is OK.
Definition status.h:67
static double NowInSeconds()
gets the current time in second.
Definition clock.cc:56
bool GetProtoConfig(T *config) const
const std::string & ConfigFilePath() const
std::shared_ptr< Node > node_
bool Proc(const std::shared_ptr< routing::RoutingRequest > &request) override
bool Process(const std::shared_ptr< routing::RoutingRequest > &routing_request, routing::RoutingResponse *const routing_response)
Definition routing.cc:129
apollo::common::Status Init()
module initialization function
Definition routing.cc:37
apollo::common::Status Start()
module start function
Definition routing.cc:48
#define ACHECK(cond)
Definition log.h:80
#define AINFO
Definition log.h:42
class register implement
Definition arena_queue.h:37
DECLARE_string(flagfile)
optional string routing_response_history_topic