Apollo 10.0
自动驾驶开放平台
subscriber_listener.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 <memory>
20
21#include "cyber/base/macros.h"
22
23#include "fastdds/dds/subscriber/InstanceState.hpp"
24
25#include "fastdds/dds/topic/TopicDescription.hpp"
26
27#include "cyber/common/log.h"
29
30namespace apollo {
31namespace cyber {
32namespace service_discovery {
33
36 : callback_(callback) {}
37
39 std::lock_guard<std::mutex> lck(mutex_);
40 callback_ = nullptr;
41}
42
44 eprosima::fastdds::dds::DataReader* reader) {
45 RETURN_IF_NULL(callback_);
46
47 eprosima::fastdds::dds::SampleInfo m_info;
49 while (reader->take_next_sample(reinterpret_cast<void*>(&m), &m_info) ==
50 eprosima::fastrtps::types::ReturnCode_t::RETCODE_OK) {
51 if (m_info.valid_data) {
52 // parameter 1 and 2 are not used
53 callback_(std::make_shared<std::string>(m.data()), 0, msg_info_);
54 } else {
55 AERROR << "Remote writer for topic "
56 << reader->get_topicdescription()->get_name() << " is dead";
57 }
58 }
59}
60
62 eprosima::fastdds::dds::DataReader* reader,
63 const eprosima::fastdds::dds::SubscriptionMatchedStatus& info) {
64 (void)reader;
65 (void)info;
66}
67
68} // namespace service_discovery
69} // namespace cyber
70} // namespace apollo
SubscriberListener(const transport::rtps::subsciber_callback &callback)
void on_subscription_matched(eprosima::fastdds::dds::DataReader *reader, const eprosima::fastdds::dds::SubscriptionMatchedStatus &info) override
void on_data_available(eprosima::fastdds::dds::DataReader *reader) override
This class represents the structure UnderlayMessage defined by the user in the IDL file.
void data(const std::string &_data)
This function copies the value in member data
#define RETURN_IF_NULL(ptr)
Definition log.h:90
#define AERROR
Definition log.h:44
std::function< void(const std::shared_ptr< std::string > &msg_str, uint64_t channel_id, const MessageInfo &msg_info)> subsciber_callback
Definition common_type.h:30
class register implement
Definition arena_queue.h:37