Apollo 10.0
自动驾驶开放平台
receiver.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_RECEIVER_RECEIVER_H_
18#define CYBER_TRANSPORT_RECEIVER_RECEIVER_H_
19
20#include <functional>
21#include <memory>
22
26
27namespace apollo {
28namespace cyber {
29namespace transport {
30
31template <typename M>
32class Receiver : public Endpoint {
33 public:
34 using MessagePtr = std::shared_ptr<M>;
35 using MessageListener = std::function<void(
36 const MessagePtr&, const MessageInfo&, const RoleAttributes&)>;
37
38 Receiver(const RoleAttributes& attr, const MessageListener& msg_listener);
39 virtual ~Receiver();
40
41 virtual void Enable() = 0;
42 virtual void Disable() = 0;
43 virtual void Enable(const RoleAttributes& opposite_attr) = 0;
44 virtual void Disable(const RoleAttributes& opposite_attr) = 0;
45
46 protected:
47 void OnNewMessage(const MessagePtr& msg, const MessageInfo& msg_info);
48
50};
51
52template <typename M>
54 const MessageListener& msg_listener)
55 : Endpoint(attr), msg_listener_(msg_listener) {}
56
57template <typename M>
59
60template <typename M>
62 const MessageInfo& msg_info) {
63 if (msg_listener_ != nullptr) {
64 msg_listener_(msg, msg_info, attr_);
65 }
66}
67
68} // namespace transport
69} // namespace cyber
70} // namespace apollo
71
72#endif // CYBER_TRANSPORT_RECEIVER_RECEIVER_H_
virtual void Enable(const RoleAttributes &opposite_attr)=0
virtual void Disable(const RoleAttributes &opposite_attr)=0
Receiver(const RoleAttributes &attr, const MessageListener &msg_listener)
Definition receiver.h:53
void OnNewMessage(const MessagePtr &msg, const MessageInfo &msg_info)
Definition receiver.h:61
std::function< void(const MessagePtr &, const MessageInfo &, const RoleAttributes &)> MessageListener
Definition receiver.h:36
std::shared_ptr< M > MessagePtr
Definition receiver.h:34
class register implement
Definition arena_queue.h:37