Apollo 10.0
自动驾驶开放平台
intra_transmitter.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_TRANSMITTER_INTRA_TRANSMITTER_H_
18#define CYBER_TRANSPORT_TRANSMITTER_INTRA_TRANSMITTER_H_
19
20#include <memory>
21#include <string>
22
23#include "cyber/common/log.h"
26
27namespace apollo {
28namespace cyber {
29namespace transport {
30
31template <typename M>
32class IntraTransmitter : public Transmitter<M> {
33 public:
34 using MessagePtr = std::shared_ptr<M>;
35
36 explicit IntraTransmitter(const RoleAttributes& attr);
37 virtual ~IntraTransmitter();
38
39 void Enable() override;
40 void Disable() override;
41
42 void Enable(const RoleAttributes& opposite_attr) override;
43 void Disable(const RoleAttributes& opposite_attr) override;
44
45 bool Transmit(const MessagePtr& msg, const MessageInfo& msg_info) override;
46
47 bool AcquireMessage(std::shared_ptr<M>& msg);
48
49 private:
50 uint64_t channel_id_;
51 IntraDispatcherPtr dispatcher_;
52};
53
54template <typename M>
55bool IntraTransmitter<M>::AcquireMessage(std::shared_ptr<M>& msg) {
56 return false;
57}
58
59template <typename M>
61 : Transmitter<M>(attr),
62 channel_id_(attr.channel_id()),
63 dispatcher_(nullptr) {}
64
65template <typename M>
69
70template <typename M>
71void IntraTransmitter<M>::Enable(const RoleAttributes& opposite_attr) {
72 (void)opposite_attr;
73 this->Enable();
74}
75
76template <typename M>
77void IntraTransmitter<M>::Disable(const RoleAttributes& opposite_attr) {
78 (void)opposite_attr;
79 this->Disable();
80}
81
82template <typename M>
84 if (!this->enabled_) {
85 dispatcher_ = IntraDispatcher::Instance();
86 this->enabled_ = true;
87 }
88}
89
90template <typename M>
92 if (this->enabled_) {
93 dispatcher_ = nullptr;
94 this->enabled_ = false;
95 }
96}
97
98template <typename M>
100 const MessageInfo& msg_info) {
101 if (!this->enabled_) {
102 ADEBUG << "not enable.";
103 return false;
104 }
105
106 dispatcher_->OnMessage(channel_id_, msg, msg_info);
107 return true;
108}
109
110} // namespace transport
111} // namespace cyber
112} // namespace apollo
113
114#endif // CYBER_TRANSPORT_TRANSMITTER_INTRA_TRANSMITTER_H_
IntraTransmitter(const RoleAttributes &attr)
bool Transmit(const MessagePtr &msg, const MessageInfo &msg_info) override
bool AcquireMessage(std::shared_ptr< M > &msg)
#define ADEBUG
Definition log.h:41
class register implement
Definition arena_queue.h:37