Apollo 10.0
自动驾驶开放平台
monitor_logger.cc
浏览该文件的文档.
1/******************************************************************************
2 * Copyright 2017 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 *****************************************************************************/
17
18#include <memory>
19
20#include "absl/strings/str_cat.h"
21
22using ::apollo::cyber::Time;
23
24namespace apollo {
25namespace common {
26namespace monitor {
27
28MonitorLogger::MonitorLogger() {
29 const std::string node_name =
30 absl::StrCat("monitor_logger", Time::Now().ToNanosecond());
31 node_ = cyber::CreateNode(node_name);
32 if (node_ != nullptr) {
33 monitor_msg_writer_ =
34 node_->CreateWriter<MonitorMessage>("/apollo/monitor");
35 }
36}
37
39 const std::vector<MessageItem> &messages) const {
40 // compose a monitor message
41 if (messages.empty()) {
42 return;
43 }
44 MonitorMessage monitor_msg;
45
46 for (const auto &msg_item : messages) {
47 MonitorMessageItem *monitor_msg_item = monitor_msg.add_item();
48 monitor_msg_item->set_source(source);
49 monitor_msg_item->set_log_level(msg_item.first);
50 monitor_msg_item->set_msg(msg_item.second);
51 }
52
53 // publish monitor messages
54 DoPublish(&monitor_msg);
55}
56
57void MonitorLogger::DoPublish(MonitorMessage *message) const {
58 RETURN_IF_NULL(monitor_msg_writer_);
59 common::util::FillHeader("monitor", message);
60 monitor_msg_writer_->Write(*message);
61}
62
63} // namespace monitor
64} // namespace common
65} // namespace apollo
virtual void Publish(const MonitorMessageItem::MessageSource &source, const std::vector< MessageItem > &messages) const
Publish the messages.
static Time Now()
get the current time.
Definition time.cc:57
#define RETURN_IF_NULL(ptr)
Definition log.h:90
The class of MonitorLogger
std::unique_ptr< Node > CreateNode(const std::string &node_name, const std::string &name_space)
Definition cyber.cc:33
class register implement
Definition arena_queue.h:37