Apollo 11.0
自动驾驶开放平台
sub_listener.h
浏览该文件的文档.
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_TRANSPORT_RTPS_SUB_LISTENER_H_
18#define CYBER_TRANSPORT_RTPS_SUB_LISTENER_H_
19
20#include <functional>
21#include <iostream>
22#include <memory>
23#include <mutex>
24#include <string>
25
29#include "fastrtps/Domain.h"
30#include "fastrtps/subscriber/SampleInfo.h"
31#include "fastrtps/subscriber/Subscriber.h"
32#include "fastrtps/subscriber/SubscriberListener.h"
33
34namespace apollo {
35namespace cyber {
36namespace transport {
37
38class SubListener;
39using SubListenerPtr = std::shared_ptr<SubListener>;
40
41class SubListener : public eprosima::fastrtps::SubscriberListener {
42 public:
43 using NewMsgCallback = std::function<void(
44 uint64_t channel_id, const std::shared_ptr<std::string>& msg_str,
45 const MessageInfo& msg_info)>;
46
47 explicit SubListener(const NewMsgCallback& callback);
48 virtual ~SubListener();
49
50 void onNewDataMessage(eprosima::fastrtps::Subscriber* sub);
51 void onSubscriptionMatched(eprosima::fastrtps::Subscriber* sub,
52 eprosima::fastrtps::MatchingInfo& info); // NOLINT
53
54 private:
55 NewMsgCallback callback_;
56 MessageInfo msg_info_;
57 std::mutex mutex_;
58};
59
60} // namespace transport
61} // namespace cyber
62} // namespace apollo
63
64#endif // CYBER_TRANSPORT_RTPS_SUB_LISTENER_H_
std::function< void(uint64_t channel_id, const std::shared_ptr< std::string > &msg_str, const MessageInfo &msg_info)> NewMsgCallback
void onSubscriptionMatched(eprosima::fastrtps::Subscriber *sub, eprosima::fastrtps::MatchingInfo &info)
void onNewDataMessage(eprosima::fastrtps::Subscriber *sub)
std::shared_ptr< SubListener > SubListenerPtr
class register implement
Definition arena_queue.h:37