Apollo  6.0
Open source self driving car software
sub_listener.h
Go to the documentation of this file.
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 
34 namespace apollo {
35 namespace cyber {
36 namespace transport {
37 
38 class SubListener;
39 using SubListenerPtr = std::shared_ptr<SubListener>;
40 
41 class 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_
PlanningContext is the runtime context in planning. It is persistent across multiple frames...
Definition: atomic_hash_map.h:25
std::shared_ptr< SubListener > SubListenerPtr
Definition: sub_listener.h:39
std::function< void(uint64_t channel_id, const std::shared_ptr< std::string > &msg_str, const MessageInfo &msg_info)> NewMsgCallback
Definition: sub_listener.h:45
Definition: sub_listener.h:41
Definition: message_info.h:30
SubListener(const NewMsgCallback &callback)
void onSubscriptionMatched(eprosima::fastrtps::Subscriber *sub, eprosima::fastrtps::MatchingInfo &info)
void onNewDataMessage(eprosima::fastrtps::Subscriber *sub)